From 9536952f0cb20eeeeed2c4302e5828ab922430b3 Mon Sep 17 00:00:00 2001 From: Tristan Russell Date: Tue, 22 Jul 2025 09:47:20 -0400 Subject: [PATCH] feat: Initial Commit --- .clangd | 6 ++++++ main.cu | 41 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+) create mode 100644 .clangd create mode 100644 main.cu diff --git a/.clangd b/.clangd new file mode 100644 index 0000000..31209a5 --- /dev/null +++ b/.clangd @@ -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 diff --git a/main.cu b/main.cu new file mode 100644 index 0000000..1cbe9a0 --- /dev/null +++ b/main.cu @@ -0,0 +1,41 @@ +#include + +__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; +}