diff --git a/tests/hellocuda/.gitignore b/tests/hellocuda/.gitignore new file mode 100644 index 0000000..8559f47 --- /dev/null +++ b/tests/hellocuda/.gitignore @@ -0,0 +1,2 @@ +hellocuda +*.seer diff --git a/tests/hellocuda/Makefile b/tests/hellocuda/Makefile new file mode 100644 index 0000000..3a15eed --- /dev/null +++ b/tests/hellocuda/Makefile @@ -0,0 +1,10 @@ +.PHONY: all +all: hellocuda + +hellocuda: hellocuda.cu + /usr/local/cuda-12.2/bin/nvcc -g -G hellocuda.cu -o hellocuda + +.PHONY: clean +clean: + rm -f hellocuda hellocuda.o + diff --git a/tests/hellocuda/hellocuda.cu b/tests/hellocuda/hellocuda.cu new file mode 100644 index 0000000..1d678f7 --- /dev/null +++ b/tests/hellocuda/hellocuda.cu @@ -0,0 +1,27 @@ +#include "stdio.h" + +__global__ void add(int a, int b, int *c) { + *c = a + b; +} + +int main() { + + int a,b,c; + int* dev_c; + + a=3; + b=4; + + cudaMalloc((void**)&dev_c, sizeof(int)); + + add<<<1,1>>>(a,b,dev_c); + + cudaMemcpy(&c, dev_c, sizeof(int), cudaMemcpyDeviceToHost); + + printf("%d + %d is %d\n", a, b, c); + + cudaFree(dev_c); + + return 0; +} + diff --git a/tests/hellocuda/hellocuda.cu-orig b/tests/hellocuda/hellocuda.cu-orig new file mode 100644 index 0000000..2d45bd9 --- /dev/null +++ b/tests/hellocuda/hellocuda.cu-orig @@ -0,0 +1,47 @@ +#include +#include + +// Simple 8-bit bit reversal Compute test + +#define N 256 + +__global__ void bitreverse (void *data) { + + unsigned int *idata = (unsigned int*)data; + extern __shared__ int array[]; + + array[threadIdx.x] = idata[threadIdx.x]; + + array[threadIdx.x] = ((0xf0f0f0f0 & array[threadIdx.x]) >> 4) | ((0x0f0f0f0f & array[threadIdx.x]) << 4); + array[threadIdx.x] = ((0xcccccccc & array[threadIdx.x]) >> 2) | ((0x33333333 & array[threadIdx.x]) << 2); + array[threadIdx.x] = ((0xaaaaaaaa & array[threadIdx.x]) >> 1) | ((0x55555555 & array[threadIdx.x]) << 1); + + idata[threadIdx.x] = array[threadIdx.x]; +} + +int main(void) { + + void* d = NULL; + int i; + unsigned int idata[N], odata[N]; + + for (i = 0; i < N; i++) { + idata[i] = (unsigned int)i; + } + + cudaMalloc((void**)&d, sizeof(int)*N); + cudaMemcpy(d, idata, sizeof(int)*N, cudaMemcpyHostToDevice); + + bitreverse<<<1, N, N*sizeof(int)>>>(d); + + cudaMemcpy(odata, d, sizeof(int)*N, cudaMemcpyDeviceToHost); + + for (i = 0; i < N; i++) { + printf("%u -> %u\n", idata[i], odata[i]); + } + + cudaFree((void*)d); + + return 0; +} +