feat: Initial Commit
This commit is contained in:
commit
9536952f0c
|
@ -0,0 +1,6 @@
|
||||||
|
CompileFlags:
|
||||||
|
Add:
|
||||||
|
- --cuda-path=/opt/cuda
|
||||||
|
- --cuda-gpu-arch=sm_89 # Replace XX with your actual GPU architecture, e.g., 86
|
||||||
|
- -I/opt/cuda/include
|
||||||
|
- -L/opt/cuda/lib64
|
|
@ -0,0 +1,41 @@
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
__global__ void cuda_hello(int* number, int* out) {
|
||||||
|
*out = *number;
|
||||||
|
for(int i = 0; i < 255; i++) {
|
||||||
|
*out += 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
int *number, *out;
|
||||||
|
int *d_number, *d_out;
|
||||||
|
number = (int*)malloc(sizeof(int));
|
||||||
|
out = (int*)malloc(sizeof(int));
|
||||||
|
|
||||||
|
*number = 22;
|
||||||
|
*out = 0;
|
||||||
|
|
||||||
|
cudaMalloc((void**)&d_number, sizeof(int));
|
||||||
|
cudaMemcpy(d_number, number, sizeof(int), cudaMemcpyHostToDevice);
|
||||||
|
cudaMalloc((void**)&d_out, sizeof(int));
|
||||||
|
cudaMemcpy(d_out, out, sizeof(int), cudaMemcpyHostToDevice);
|
||||||
|
|
||||||
|
|
||||||
|
cuda_hello<<<1,1>>>(d_number, d_out);
|
||||||
|
|
||||||
|
cudaDeviceSynchronize();
|
||||||
|
|
||||||
|
cudaMemcpy(out, d_out, sizeof(int), cudaMemcpyDeviceToHost);
|
||||||
|
|
||||||
|
cudaFree(d_number);
|
||||||
|
cudaFree(d_out);
|
||||||
|
|
||||||
|
|
||||||
|
printf("Number: %i\n", *out);
|
||||||
|
|
||||||
|
free(number);
|
||||||
|
free(out);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
Loading…
Reference in New Issue