mirror of
https://github.com/epasveer/seer.git
synced 2026-08-29 16:40:42 +08:00
Add test program for cuda.
This commit is contained in:
@@ -0,0 +1,2 @@
|
||||
hellocuda
|
||||
*.seer
|
||||
@@ -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
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,47 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
// 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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user