From 3496d8cd4bd819efc5b1f6b6abc0ef64ad4c6e0a Mon Sep 17 00:00:00 2001 From: miha-q <> Date: Sun, 3 Mar 2024 00:29:57 -0500 Subject: [PATCH] Sun Mar 3 12:29:57 AM EST 2024 --- Makefile | 10 +++---- src/.gpu_mmul.cl.tmp | Bin 386 -> 0 bytes src/QAnsel.c | 3 +- src/{ => gpu}/gpu.c | 0 src/{ => gpu}/gpu_mmul.cl | 0 src/gpu/gpu_mmul.cl.c | 58 ++++++++++++++++++++++++++++++++++++++ src/gpu/gpu_test.c | 27 ++++++++++++++++++ 7 files changed, 92 insertions(+), 6 deletions(-) delete mode 100644 src/.gpu_mmul.cl.tmp rename src/{ => gpu}/gpu.c (100%) rename src/{ => gpu}/gpu_mmul.cl (100%) create mode 100644 src/gpu/gpu_mmul.cl.c create mode 100644 src/gpu/gpu_test.c diff --git a/Makefile b/Makefile index 29a4948..2b53049 100644 --- a/Makefile +++ b/Makefile @@ -1,8 +1,8 @@ all: - mv src/gpu_mmul.cl src/.gpu_mmul.cl - bash -c 'echo -ne "$$(cat src/.gpu_mmul.cl)\x00" > src/gpu_mmul.cl' - xxd -i src/gpu_mmul.cl > src/gpu_mmul.cl.c - mv src/.gpu_mmul.cl src/gpu_mmul.cl + mv src/gpu/gpu_mmul.cl src/gpu/.gpu_mmul.cl + bash -c 'echo -ne "$$(cat src/gpu/.gpu_mmul.cl)\x00" > src/gpu/gpu_mmul.cl' + xxd -i src/gpu/gpu_mmul.cl | sed -e 's/gpu_gpu_/gpu_/g' > src/gpu/gpu_mmul.cl.c + mv src/gpu/.gpu_mmul.cl src/gpu/gpu_mmul.cl gcc src/QAnsel.c -g -o bin/QAnsel -lm -I/usr/include/SDL2 -D_REENTRANT -lSDL2 -lOpenCL -pthread - rm -f src/*.cl.c \ No newline at end of file + rm -f src/*.cl.c diff --git a/src/.gpu_mmul.cl.tmp b/src/.gpu_mmul.cl.tmp deleted file mode 100644 index 369c9dd1e003a4060c3c38331ab6427fee65c1d3..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 386 zcma)2Jr9B~6!fRu2;zVdNjhT5~yIg-ur3^ngYWlZ6;8vTu<4cr2{ZH^k_;{WLLg^+G>d zv_{Jx?MT`(2Ggua4GC%k&oziQ7C0fJgdlJw&KAUOc~ZEtS`6U#N{y0FI9EMyh2)q_ igB$@wxnZD;v=AExmq4S-2+!qJe-t`9&8C%fw0i-ACxH(D diff --git a/src/QAnsel.c b/src/QAnsel.c index d0748da..8801aeb 100644 --- a/src/QAnsel.c +++ b/src/QAnsel.c @@ -16,7 +16,8 @@ uint8_t USE_GPU = 0; #define CL_USE_DEPRECATED_OPENCL_1_2_APIS #define CL_TARGET_OPENCL_VERSION 120 #include -#include "gpu.c" +#include "gpu/gpu.c" + #endif typedef struct diff --git a/src/gpu.c b/src/gpu/gpu.c similarity index 100% rename from src/gpu.c rename to src/gpu/gpu.c diff --git a/src/gpu_mmul.cl b/src/gpu/gpu_mmul.cl similarity index 100% rename from src/gpu_mmul.cl rename to src/gpu/gpu_mmul.cl diff --git a/src/gpu/gpu_mmul.cl.c b/src/gpu/gpu_mmul.cl.c new file mode 100644 index 0000000..0cc1d45 --- /dev/null +++ b/src/gpu/gpu_mmul.cl.c @@ -0,0 +1,58 @@ +unsigned char src_gpu_mmul_cl[] = { + 0x5f, 0x5f, 0x6b, 0x65, 0x72, 0x6e, 0x65, 0x6c, 0x20, 0x76, 0x6f, 0x69, + 0x64, 0x20, 0x67, 0x70, 0x75, 0x5f, 0x6d, 0x6d, 0x75, 0x6c, 0x0a, 0x28, + 0x0a, 0x20, 0x20, 0x20, 0x20, 0x5f, 0x5f, 0x67, 0x6c, 0x6f, 0x62, 0x61, + 0x6c, 0x20, 0x66, 0x6c, 0x6f, 0x61, 0x74, 0x2a, 0x20, 0x70, 0x74, 0x72, + 0x52, 0x2c, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x5f, 0x5f, 0x67, 0x6c, 0x6f, + 0x62, 0x61, 0x6c, 0x20, 0x66, 0x6c, 0x6f, 0x61, 0x74, 0x2a, 0x20, 0x70, + 0x74, 0x72, 0x41, 0x2c, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x5f, 0x5f, 0x67, + 0x6c, 0x6f, 0x62, 0x61, 0x6c, 0x20, 0x66, 0x6c, 0x6f, 0x61, 0x74, 0x2a, + 0x20, 0x70, 0x74, 0x72, 0x42, 0x2c, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x63, + 0x6f, 0x6e, 0x73, 0x74, 0x20, 0x69, 0x6e, 0x74, 0x20, 0x72, 0x6f, 0x77, + 0x73, 0x41, 0x2c, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x63, 0x6f, 0x6e, 0x73, + 0x74, 0x20, 0x69, 0x6e, 0x74, 0x20, 0x63, 0x6f, 0x6c, 0x73, 0x42, 0x2c, + 0x0a, 0x20, 0x20, 0x20, 0x20, 0x63, 0x6f, 0x6e, 0x73, 0x74, 0x20, 0x69, + 0x6e, 0x74, 0x20, 0x73, 0x68, 0x61, 0x72, 0x65, 0x64, 0x0a, 0x29, 0x0a, + 0x7b, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x63, 0x6f, 0x6e, 0x73, 0x74, 0x20, + 0x69, 0x6e, 0x74, 0x20, 0x63, 0x6f, 0x6c, 0x73, 0x41, 0x20, 0x3d, 0x20, + 0x73, 0x68, 0x61, 0x72, 0x65, 0x64, 0x3b, 0x0a, 0x20, 0x20, 0x20, 0x20, + 0x63, 0x6f, 0x6e, 0x73, 0x74, 0x20, 0x69, 0x6e, 0x74, 0x20, 0x72, 0x6f, + 0x77, 0x73, 0x42, 0x20, 0x3d, 0x20, 0x73, 0x68, 0x61, 0x72, 0x65, 0x64, + 0x3b, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x63, 0x6f, 0x6e, 0x73, 0x74, 0x20, + 0x69, 0x6e, 0x74, 0x20, 0x72, 0x6f, 0x77, 0x73, 0x52, 0x20, 0x3d, 0x20, + 0x72, 0x6f, 0x77, 0x73, 0x41, 0x3b, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x63, + 0x6f, 0x6e, 0x73, 0x74, 0x20, 0x69, 0x6e, 0x74, 0x20, 0x63, 0x6f, 0x6c, + 0x73, 0x52, 0x20, 0x3d, 0x20, 0x63, 0x6f, 0x6c, 0x73, 0x42, 0x3b, 0x0a, + 0x20, 0x20, 0x20, 0x20, 0x63, 0x6f, 0x6e, 0x73, 0x74, 0x20, 0x69, 0x6e, + 0x74, 0x20, 0x72, 0x6f, 0x77, 0x52, 0x20, 0x3d, 0x20, 0x67, 0x65, 0x74, + 0x5f, 0x67, 0x6c, 0x6f, 0x62, 0x61, 0x6c, 0x5f, 0x69, 0x64, 0x28, 0x30, + 0x29, 0x3b, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x63, 0x6f, 0x6e, 0x73, 0x74, + 0x20, 0x69, 0x6e, 0x74, 0x20, 0x63, 0x6f, 0x6c, 0x52, 0x20, 0x3d, 0x20, + 0x67, 0x65, 0x74, 0x5f, 0x67, 0x6c, 0x6f, 0x62, 0x61, 0x6c, 0x5f, 0x69, + 0x64, 0x28, 0x31, 0x29, 0x3b, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x69, 0x6e, + 0x74, 0x20, 0x70, 0x6f, 0x73, 0x41, 0x2c, 0x20, 0x70, 0x6f, 0x73, 0x42, + 0x3b, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x66, 0x6c, 0x6f, 0x61, 0x74, 0x20, + 0x73, 0x75, 0x6d, 0x20, 0x3d, 0x20, 0x30, 0x3b, 0x0a, 0x0a, 0x20, 0x20, + 0x20, 0x20, 0x63, 0x6f, 0x6e, 0x73, 0x74, 0x20, 0x69, 0x6e, 0x74, 0x20, + 0x70, 0x6f, 0x73, 0x52, 0x20, 0x3d, 0x20, 0x63, 0x6f, 0x6c, 0x52, 0x20, + 0x2b, 0x20, 0x72, 0x6f, 0x77, 0x52, 0x20, 0x2a, 0x20, 0x63, 0x6f, 0x6c, + 0x73, 0x52, 0x3b, 0x0a, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x66, 0x6f, 0x72, + 0x20, 0x28, 0x69, 0x6e, 0x74, 0x20, 0x69, 0x20, 0x3d, 0x20, 0x30, 0x3b, + 0x20, 0x69, 0x20, 0x3c, 0x20, 0x73, 0x68, 0x61, 0x72, 0x65, 0x64, 0x3b, + 0x20, 0x69, 0x2b, 0x2b, 0x29, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x7b, 0x0a, + 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x69, 0x6e, 0x74, 0x20, + 0x70, 0x6f, 0x73, 0x41, 0x20, 0x3d, 0x20, 0x69, 0x20, 0x2b, 0x20, 0x72, + 0x6f, 0x77, 0x52, 0x20, 0x2a, 0x20, 0x63, 0x6f, 0x6c, 0x73, 0x41, 0x3b, + 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x69, 0x6e, 0x74, + 0x20, 0x70, 0x6f, 0x73, 0x42, 0x20, 0x3d, 0x20, 0x63, 0x6f, 0x6c, 0x52, + 0x20, 0x2b, 0x20, 0x69, 0x20, 0x2a, 0x20, 0x63, 0x6f, 0x6c, 0x73, 0x42, + 0x3b, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x73, 0x75, + 0x6d, 0x20, 0x2b, 0x3d, 0x20, 0x70, 0x74, 0x72, 0x41, 0x5b, 0x70, 0x6f, + 0x73, 0x41, 0x5d, 0x20, 0x2a, 0x20, 0x70, 0x74, 0x72, 0x42, 0x5b, 0x70, + 0x6f, 0x73, 0x42, 0x5d, 0x3b, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x7d, 0x0a, + 0x20, 0x20, 0x20, 0x20, 0x70, 0x74, 0x72, 0x52, 0x5b, 0x72, 0x6f, 0x77, + 0x52, 0x20, 0x2a, 0x20, 0x63, 0x6f, 0x6c, 0x73, 0x52, 0x20, 0x2b, 0x20, + 0x63, 0x6f, 0x6c, 0x52, 0x5d, 0x20, 0x3d, 0x20, 0x73, 0x75, 0x6d, 0x3b, + 0x0a, 0x7d, 0x00 +}; +unsigned int src_gpu_mmul_cl_len = 651; diff --git a/src/gpu/gpu_test.c b/src/gpu/gpu_test.c new file mode 100644 index 0000000..6b14609 --- /dev/null +++ b/src/gpu/gpu_test.c @@ -0,0 +1,27 @@ +//This is for testing GPU functions on the CPU +#define __kernel +#define __global +#include "gpu/gpu_mmul.cl" +int GPU_GLOBAL_ID_0, GPU_GLOBAL_ID_1, GPU_GLOBAL_ID_2; +int get_global_int(int id) +{ + switch (id) + { + case 0: return GPU_GLOBAL_ID_0; + case 1: return GPU_GLOBAL_ID_1; + case 2: return GPU_GLOBAL_ID_2; + } +} + +void GPU_mmul_test(float* ptrR, float* ptrA, float* ptrB, size_t rowsA, size_t colsB, size_t shared) +{ + for (int i = 0; i < rowsA; i++) + { + for (int j = 0; j < colsB; j++) + { + GPU_GLOBAL_ID_0 = i; + GPU_GLOBAL_ID_1 = i; + gpu_mmul(ptrR, ptrA, ptrB, rowsA, colsB, shared); + } + } +} \ No newline at end of file -- 2.39.5