feat: Initial Commit

This commit is contained in:
Tristan Russell 2025-07-22 09:47:20 -04:00
commit 9536952f0c
Signed by: tristanr
GPG Key ID: 4495C92911DF04CA
2 changed files with 47 additions and 0 deletions

6
.clangd Normal file
View File

@ -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

41
main.cu Normal file
View File

@ -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;
}