From da973be545d6da3b2d42023f96bcfd79f751eba9 Mon Sep 17 00:00:00 2001 From: Mitja Felicijan Date: Thu, 22 Jan 2026 13:09:29 +0100 Subject: Add CUDA grammar --- tests/test.cu | 26 ++++++++++++++++++++++++++ tests/test.cuh | 19 +++++++++++++++++++ 2 files changed, 45 insertions(+) create mode 100644 tests/test.cu create mode 100644 tests/test.cuh (limited to 'tests') diff --git a/tests/test.cu b/tests/test.cu new file mode 100644 index 0000000..9bd49d4 --- /dev/null +++ b/tests/test.cu @@ -0,0 +1,26 @@ +#include + +__global__ void vectorAdd(const float *A, const float *B, float *C, int numElements) { + int i = blockDim.x * blockIdx.x + threadIdx.x; + if (i < numElements) { + C[i] = A[i] + B[i]; + } +} + +__device__ int get_thread_id() { + return threadIdx.x; +} + +__host__ void init_vectors(float *A, float *B, int n) { + for (int i = 0; i < n; ++i) { + A[i] = rand() / (float)RAND_MAX; + B[i] = rand() / (float)RAND_MAX; + } +} + +int main(void) { + int numElements = 50000; + size_t size = numElements * sizeof(float); + printf("[Vector addition of %d elements]\n", numElements); + return 0; +} diff --git a/tests/test.cuh b/tests/test.cuh new file mode 100644 index 0000000..895f183 --- /dev/null +++ b/tests/test.cuh @@ -0,0 +1,19 @@ +#ifndef TEST_CUH +#define TEST_CUH + +struct Point { + float x; + float y; + float z; +}; + +class Dim3 { +public: + int x; + int y; + int z; +}; + +__device__ void device_func() {} + +#endif -- cgit v1.2.3