diff --git a/documents/references.md b/documents/references.md index e67f5be24437497c162ed4fe737da6756ca71795..a4ebe1197796da661c20e1001a4541cc8e1e527e 100644 --- a/documents/references.md +++ b/documents/references.md @@ -74,6 +74,11 @@ Various references used in project. ### Intro CUDA Tutorial <https://cuda-tutorial.readthedocs.io/en/latest/tutorials/tutorial01/> +### CUDA Error Checking +* Original way I learned CUDA has a memcheck - <https://stackoverflow.com/a/18413921> +* More on using it - <https://stackoverflow.com/a/27278218> +* Official Docs - <https://docs.nvidia.com/cuda/cuda-memcheck/index.html> + ## Other ### Manipulating Image Pixels diff --git a/part_0/image.cu b/part_0/image.cu index 874b1ea1261007b482fb195014ebc5d6a39761f8..f35579c4141bbb33af4d92c4cd94099e6f9306cd 100644 --- a/part_0/image.cu +++ b/part_0/image.cu @@ -92,7 +92,7 @@ __global__ void cuda_alternating_pixels(unsigned long total_pixels, unsigned lon pixel_index += (chunk_size * chunk_counter); // Only proceed if GPU thread corresponds to a pixel in the image. Ignore all extra threads. - if (pixel_index <= total_pixels) { + if (pixel_index < total_pixels) { // Manipulate pixel data based on index. if (pixel_index % 2 == 0) { @@ -124,7 +124,7 @@ __global__ void cuda_alternating_blocks(unsigned long total_pixels, unsigned lon pixel_index += (chunk_size * chunk_counter); // Only proceed if GPU thread corresponds to a pixel in the image. Ignore all extra threads. - if (pixel_index <= total_pixels) { + if (pixel_index < total_pixels) { // Calculate if falls under black or white pixel block. int row = pixel_index / image_width; @@ -167,7 +167,7 @@ __global__ void cuda_increase_red(unsigned long total_pixels, unsigned long chun pixel_index += (chunk_size * chunk_counter); // Only proceed if GPU thread corresponds to a pixel in the image. Ignore all extra threads. - if (pixel_index <= total_pixels) { + if (pixel_index < total_pixels) { // Calculate new pixel colors. float red = pixel_arr[pixel_index].r + 0.1f; @@ -205,7 +205,7 @@ __global__ void cuda_increase_green(unsigned long total_pixels, unsigned long ch pixel_index += (chunk_size * chunk_counter); // Only proceed if GPU thread corresponds to a pixel in the image. Ignore all extra threads. - if (pixel_index <= total_pixels) { + if (pixel_index < total_pixels) { // Calculate new pixel colors. float red = pixel_arr[pixel_index].r - 0.1f; @@ -243,7 +243,7 @@ __global__ void cuda_increase_blue(unsigned long total_pixels, unsigned long chu pixel_index += (chunk_size * chunk_counter); // Only proceed if GPU thread corresponds to a pixel in the image. Ignore all extra threads. - if (pixel_index <= total_pixels) { + if (pixel_index < total_pixels) { // Calculate new pixel colors. float red = pixel_arr[pixel_index].r - 0.1f; @@ -717,7 +717,7 @@ void Image::compute() { cudaMemcpy(pixel_arr, gpu_pixel_arr, pixel_struct_byte_count, cudaMemcpyDeviceToHost); save(); - // Retrieve results. + // // Retrieve results. cudaMemcpy(pixel_arr, gpu_pixel_arr, pixel_struct_byte_count, cudaMemcpyDeviceToHost); cudaFree(gpu_pixel_arr); delete[] pixel_arr_orig; diff --git a/part_0/makefile b/part_0/makefile index 85404c9c0a3d11d73de90e8331493db25fbbac65..16b7f1c4f769964fc5c3b8bebb0ca5b48d8b2e97 100644 --- a/part_0/makefile +++ b/part_0/makefile @@ -29,8 +29,13 @@ run: $(TARGET) @./$(TARGET) $(ARGS) -# Compile target if dependencies update. Then run. +# Compile target if dependencies update. Then run with valgrind. valgrind: $(TARGET) # @rm ./logs/vg/* # valgrind --leak-check=full --log-file=./logs/vg/vg.%p ./$(TARGET) $(ARGS) valgrind --leak-check=full ./$(TARGET) $(ARGS) + + +# Compile target if dependencies update. Then run with cuda-memcheck. +memcheck: $(TARGET) + cuda-memcheck --leak-check full ./$(TARGET) $(ARGS) diff --git a/part_1/makefile b/part_1/makefile index 85404c9c0a3d11d73de90e8331493db25fbbac65..16b7f1c4f769964fc5c3b8bebb0ca5b48d8b2e97 100644 --- a/part_1/makefile +++ b/part_1/makefile @@ -29,8 +29,13 @@ run: $(TARGET) @./$(TARGET) $(ARGS) -# Compile target if dependencies update. Then run. +# Compile target if dependencies update. Then run with valgrind. valgrind: $(TARGET) # @rm ./logs/vg/* # valgrind --leak-check=full --log-file=./logs/vg/vg.%p ./$(TARGET) $(ARGS) valgrind --leak-check=full ./$(TARGET) $(ARGS) + + +# Compile target if dependencies update. Then run with cuda-memcheck. +memcheck: $(TARGET) + cuda-memcheck --leak-check full ./$(TARGET) $(ARGS)