From ebeb0fbb178e85f596726f28760dc1d9c337351e Mon Sep 17 00:00:00 2001 From: Anton Ljungdahl Date: Thu, 26 Sep 2024 22:32:58 +0200 Subject: [PATCH] hello gpu world --- build.bat | 19 +++++++++++++++++++ src/cuda_entry_point.cu | 19 +++++++++++++++++++ src/kernels.h | 5 +++++ src/main.c | 17 +++++++++++++++++ timeBuild.ctm | Bin 0 -> 148 bytes 5 files changed, 60 insertions(+) create mode 100644 build.bat create mode 100644 src/cuda_entry_point.cu create mode 100644 src/kernels.h create mode 100644 src/main.c create mode 100644 timeBuild.ctm diff --git a/build.bat b/build.bat new file mode 100644 index 0000000..a36d58b --- /dev/null +++ b/build.bat @@ -0,0 +1,19 @@ +@echo off + +ctime -begin timeBuild.ctm + +@rem /WX /W4 /wd4201 /wd4100 /wd4189 /wd4244 /wd4127 /wd4456 +set CommonCompilerFlags="/nologo /Zi /FC" +set CudaSources=../src/cuda_entry_point.cu +set Sources=../src/main.c + +IF NOT EXIST .\build mkdir .\build +pushd .\build +nvcc -Xcompiler %CommonCompilerFlags% -o program.exe %Sources% %CudaSources% +set LastError=%ERRORLEVEL% +popd + +ctime -end timeBuild.ctm %LastError% +IF NOT %LastError%==0 GOTO :end + +:end diff --git a/src/cuda_entry_point.cu b/src/cuda_entry_point.cu new file mode 100644 index 0000000..517bb6c --- /dev/null +++ b/src/cuda_entry_point.cu @@ -0,0 +1,19 @@ +#include + +#define no_name_mangle extern "C" + + + +__global__ void hello_from_GPU() { + printf("HELLO FROM GPUUUU"); +} + + + +no_name_mangle void cuda_entry_point() { + + hello_from_GPU<<<1, 1>>>(); + + + cudaDeviceSynchronize(); +} diff --git a/src/kernels.h b/src/kernels.h new file mode 100644 index 0000000..b7899cf --- /dev/null +++ b/src/kernels.h @@ -0,0 +1,5 @@ + + + +// Forward declarations +void cuda_entry_point(); diff --git a/src/main.c b/src/main.c new file mode 100644 index 0000000..c66a48a --- /dev/null +++ b/src/main.c @@ -0,0 +1,17 @@ +#include + +#include "kernels.h" + + + +int main() { + + cuda_entry_point(); + + + printf("hello"); + + + return 0; +} + diff --git a/timeBuild.ctm b/timeBuild.ctm new file mode 100644 index 0000000000000000000000000000000000000000..b2cd111d4bbe92e61deb089de5c55311840e9804 GIT binary patch literal 148 zcmcC7j63z~jI@q}z->lG1_p-HKzyZI$qU412C}CE1uL!xU3G@?cLT*9t1I0C@j>eI zfLQp_);<>~e-4m8n}6Lr7~dbHK6={%7=ISfP^WpXPl5O#^S5v^Fx=95b_d4)&(6RA E0Em$$xBvhE literal 0 HcmV?d00001