|
Download cpp/cpp-simd-003.jsonl from winapiadmin/tinycodinglm: direct link, hf CLI and curl.
- Browser
- Download file 2.58 kB
-
https://huggingface.co/datasets/winapiadmin/tinycodinglm/resolve/d517dc97f4cfcf6f6f9b7fafc368554f077178b3/cpp/cpp-simd-003.jsonl
- Command line
-
hf download hf://datasets/winapiadmin/tinycodinglm@d517dc97f4cfcf6f6f9b7fafc368554f077178b3/cpp/cpp-simd-003.jsonl
-
curl -L -o cpp-simd-003.jsonl https://huggingface.co/datasets/winapiadmin/tinycodinglm/resolve/d517dc97f4cfcf6f6f9b7fafc368554f077178b3/cpp/cpp-simd-003.jsonl
2.58 kB
| {"type": "session", "harness": "opencode", "id": "cpp-simd-003", "name": "C++26 SIMD math operations"} | |
| {"type": "message", "message": {"role": "system", "content": "You are an expert software engineer and technical assistant. You provide accurate, detailed, and practical answers. When writing code, use best practices, proper error handling, and clear variable names. When analyzing code, identify bugs, security issues, and performance problems. You have deep knowledge of C/C++, Windows API, Python, and many other technologies."}} | |
| {"type": "message", "message": {"role": "user", "content": "Show SIMD math operations for scientific computing"}} | |
| {"type": "message", "message": {"role": "assistant", "content": "**SIMD Math Operations:**\n\n**1. Vector Math (sin, cos, exp):**\n```cpp\n#include <simd>\n#include <simd_math>\n\nvoid compute_trig(const float* angles, float* results, size_t n) {\n size_t i = 0;\n for (; i + 8 <= n; i += 8) {\n std::simd<float, 8> v(angles + i);\n std::simd<float, 8> sin_vals = sin(v); // SIMD sin\n std::simd<float, 8> cos_vals = cos(v); // SIMD cos\n // Combine: sin^2 + cos^2 = 1\n auto sum = sin_vals * sin_vals + cos_vals * cos_vals;\n sum.copy_to(results + i);\n }\n}\n```\n\n**2. Matrix Multiply:**\n```cpp\n#include <simd>\n\nvoid matmul_4x4(const float* A, const float* B, float* C) {\n for (int i = 0; i < 4; ++i) {\n std::simd<float, 4> row;\n for (int k = 0; k < 4; ++k) {\n std::simd<float, 4> b_row(B + k * 4);\n row += A[i * 4 + k] * b_row;\n }\n row.copy_to(C + i * 4);\n }\n}\n```\n\n**3. Dot Product with Reduction:**\n```cpp\nfloat dot_product(const float* a, const float* b, size_t n) {\n std::simd<float, 4> sum = 0.0f;\n size_t i = 0;\n \n for (; i + 4 <= n; i += 4) {\n std::simd<float, 4> va(a + i);\n std::simd<float, 4> vb(b + i);\n sum += va * vb;\n }\n \n // Horizontal sum\n float result = 0;\n for (size_t j = 0; j < 4; ++j) result += sum[j];\n \n // Handle remainder\n for (; i < n; ++i) result += a[i] * b[i];\n return result;\n}\n```\n\n**4. Statistical Functions:**\n```cpp\n// SIMD mean\nfloat mean(const float* data, size_t n) {\n std::simd<float, 4> sum = 0.0f;\n size_t i = 0;\n \n for (; i + 4 <= n; i += 4) {\n sum += std::simd<float, 4>(data + i);\n }\n \n float result = 0;\n for (size_t j = 0; j < 4; ++j) result += sum[j];\n for (; i < n; ++i) result += data[i];\n return result / n;\n}\n```"}} | |