From 51a8923eb33ad53a36271b1e0b3489d033178337 Mon Sep 17 00:00:00 2001 From: Brett Weiland Date: Thu, 9 May 2024 01:27:55 -0500 Subject: will push to unison --- .gdb_history | 42 ++++++++++++++++++++++++++++++++++++++++++ bruh | Bin 17896 -> 0 bytes build/main.o | Bin 0 -> 32680 bytes kernel.cu | 18 ++++++++++++++++++ main.c | 23 ----------------------- main.cu | 41 +++++++++++++++++++++++++++++++++++++---- makefile | 10 +++++++--- 7 files changed, 104 insertions(+), 30 deletions(-) delete mode 100755 bruh create mode 100644 build/main.o create mode 100644 kernel.cu delete mode 100644 main.c diff --git a/.gdb_history b/.gdb_history index 2f823ae..9cf0bf1 100644 --- a/.gdb_history +++ b/.gdb_history @@ -12,3 +12,45 @@ x *=image.data print image context quit +quit +break main.c:27 +exit +break main.cu:27 +r +context +exit() +exit +ls +break main.cu:27 +r +print image +print image.data +print *image.data +print (uint32_t)image.data +print (uint32_t)*image.data +x 0x55555561a140 +print (uint32_t&)*image.data +print (uint32_t)*image.data +print (image.data +print image.data +x 0x55555561a140 +hexdump 0x55555561a140 +aquit +quit +break main.cu:27 +r +print image.data +print (uint32_t*)image.data +print *((uint32_t*)image.data) +print/x *((uint32_t*)image.data) +next +print/x *((uint32_t*)image.data) +print image +quit +break main.cu:27 +r +print image +next +print image +hexdump 0x55555561a140 +quit diff --git a/bruh b/bruh deleted file mode 100755 index e25e187..0000000 Binary files a/bruh and /dev/null differ diff --git a/build/main.o b/build/main.o new file mode 100644 index 0000000..7add5ec Binary files /dev/null and b/build/main.o differ diff --git a/kernel.cu b/kernel.cu new file mode 100644 index 0000000..c00056a --- /dev/null +++ b/kernel.cu @@ -0,0 +1,18 @@ +#include +#include +#include +#include "include/helper_math.h" + +__global__ void test_image(uint8_t *image) { + int2 unnormalized_coordinates = make_int2(blockDim.x, blockDim.y) * make_int2(blockIdx.x, blockIdx.y) + make_int2(threadIdx.x, threadIdx.y); + int2 img_res = make_int2(blockDim.x, blockDim.y) * make_int2(gridDim.x, gridDim.y); + size_t img_index = (unnormalized_coordinates.y * img_res.y) + unnormalized_coordinates.x; + //uint8_t pixel_val = (img_index / (img_res.x * img_res.y)) * 255; + uint8_t pixel_val = 0xff; + //if(img_index == 1) printf("%i\n", img_index); + print(img_index) + image[img_index] = 0xff; + image[img_index+1] = pixel_val; + image[img_index+2] = pixel_val; + image[img_index+3] = 0xff; +} diff --git a/main.c b/main.c deleted file mode 100644 index b5dda5c..0000000 --- a/main.c +++ /dev/null @@ -1,23 +0,0 @@ -#include -#include "raylib.h" - -int main() { - const int size_x = 1920; - const int size_y = 1080; - Image image = GenImageColor(size_x, size_y, BLUE); - - InitWindow(size_x, size_y, "cuda teseteroni"); - - - - - if(!IsWindowFullscreen()) ToggleFullscreen(); - - while(!WindowShouldClose()) { - BeginDrawing(); - DrawTexture(LoadTextureFromImage(image), 0, 0, WHITE); - EndDrawing(); - } - - return 0; -} diff --git a/main.cu b/main.cu index 9063a8f..2b1b180 100644 --- a/main.cu +++ b/main.cu @@ -1,6 +1,39 @@ -#include "include/helper_math.h" -__global__ void random_noise(double **image) { - int2 unnormalized_coordinates = make_int2(blockDim.x, blockDim.y) * make_int2(blockIdx.x, blockIdx.y) + make_int2(threadIdx.x, threadIdx.y); - int2 img_res = make_int2(blockDim.x, blockDim.y) * make_int2(gridDim.x, gridDim.y);//could move out of kernel for performance boost +#include +#include +#include +#include + +#include "raylib.h" + +__global__ void test_image(uint8_t *image); + +int main() { + const int size_x = 100; + const int size_y = 100; + uint8_t *image_d; + Image image = GenImageColor(size_x, size_y, BLUE); + SetTraceLogLevel(LOG_ERROR); + + InitWindow(size_x, size_y, "cuda teseteroni"); + + cudaMalloc((void **)&image_d, 100 * 100 * 4); + test_image<<<1, dim3(3,3)>>>(image_d); + cudaDeviceSynchronize(); + //for(;;); + //if(!IsWindowFullscreen()) ToggleFullscreen(); + + while(!WindowShouldClose()) { + cudaMemcpy(image.data, (void **)image_d, 100 * 100 * 4, cudaMemcpyDeviceToHost); + //memset(image.data, (int32_t)0x0000ff, 100 * 100 * 4); + BeginDrawing(); + DrawTexture(LoadTextureFromImage(image), 0, 0, WHITE); + EndDrawing(); + } + + + + + + return 0; } diff --git a/makefile b/makefile index c2e4c4e..b733c07 100644 --- a/makefile +++ b/makefile @@ -1,9 +1,13 @@ LIBS = -lraylib -lGL -lm -lpthread -ldl -lrt -lX11 $CC = gcc +INC = -I /opt/cuda/include make: - $(CC) $(LIBS) main.c -o build/main.o - nvcc --compile main.cu -o build/kernel.o - gcc -o indigo_worlds main.o kernel.o + nvcc $(LIBS) $(INC) --debug -c main.cu -o build/main.o + nvcc --device-debug --compile kernel.cu -o build/kernel.o + nvcc $(LIBS) -o build/indigo_worlds build/main.o build/kernel.o + +run: + build/indigo_worlds clean: rm -r build/* -- cgit v1.2.3