From 961dc65a8f1bce4dbcb02d44b714903ee49f86d2 Mon Sep 17 00:00:00 2001 From: Uzair Mohammed Date: Thu, 12 Dec 2024 01:31:08 -0800 Subject: [PATCH] Cleaned up code --- vecadd_cpu.cpp | 6 +++--- vecadd_gpu_1t.cu | 6 +++--- vecadd_gpu_256t.cu | 6 +++--- vecadd_gpu_256t_mb.cu | 7 +++---- vecadd_gpu_256t_mb_prefetch.cu | 7 +++---- 5 files changed, 15 insertions(+), 17 deletions(-) diff --git a/vecadd_cpu.cpp b/vecadd_cpu.cpp index 0807046..9911309 100644 --- a/vecadd_cpu.cpp +++ b/vecadd_cpu.cpp @@ -9,7 +9,7 @@ void add(int n, float *x, float *y) { } int main(void) { - int N = 1 << 29; // Setting problem size to 1<<29 (536,870,912 elements) + int N = 1 << 29; float *x = new float[N]; float *y = new float[N]; @@ -20,10 +20,10 @@ int main(void) { y[i] = 2.0f; } - // Timer starts before the add function call + // Start chrono timer auto start_time = std::chrono::high_resolution_clock::now(); - // Run kernel on the elements on the CPU + // Run kernel on N << 29 elements on the CPU add(N, x, y); // Timer ends after the add function call diff --git a/vecadd_gpu_1t.cu b/vecadd_gpu_1t.cu index 5e83d59..e444f85 100644 --- a/vecadd_gpu_1t.cu +++ b/vecadd_gpu_1t.cu @@ -1,6 +1,6 @@ -#include #include #include +#include // function to add the elements of two arrays __global__ void add(int n, float *x, float *y) { @@ -9,7 +9,7 @@ __global__ void add(int n, float *x, float *y) { } int main(void) { - int N = 1 << 29; // Setting problem size to 1<<29 (536,870,912 elements) + int N = 1 << 29; float *x, *y; @@ -40,4 +40,4 @@ int main(void) { cudaFree(y); return 0; -} \ No newline at end of file +} diff --git a/vecadd_gpu_256t.cu b/vecadd_gpu_256t.cu index 090be88..5480e44 100644 --- a/vecadd_gpu_256t.cu +++ b/vecadd_gpu_256t.cu @@ -1,6 +1,6 @@ -#include #include #include +#include // function to add the elements of two arrays __global__ void add(int n, float *x, float *y) { @@ -11,7 +11,7 @@ __global__ void add(int n, float *x, float *y) { } int main(void) { - int N = 1 << 29; // Setting problem size to 1<<29 (536,870,912 elements) + int N = 1 << 29; float *x, *y; @@ -42,4 +42,4 @@ int main(void) { cudaFree(y); return 0; -} \ No newline at end of file +} diff --git a/vecadd_gpu_256t_mb.cu b/vecadd_gpu_256t_mb.cu index c34e260..fcd48e2 100644 --- a/vecadd_gpu_256t_mb.cu +++ b/vecadd_gpu_256t_mb.cu @@ -1,6 +1,6 @@ -#include #include #include +#include // function to add the elements of two arrays __global__ void add(int n, float *x, float *y) { @@ -11,7 +11,7 @@ __global__ void add(int n, float *x, float *y) { } int main(void) { - int N = 1 << 29; // Setting problem size to 1<<29 (536,870,912 elements) + int N = 1 << 29; float *x, *y; @@ -30,7 +30,6 @@ int main(void) { // Number of blocks in the grid int numberOfBlocks = (N + threadsPerBlock - 1) / threadsPerBlock; - // Print out the number of thread blocks std::cout << "Number of thread blocks: " << numberOfBlocks << std::endl; // Run kernel on the elements on the GPU with multiple blocks and threads @@ -50,4 +49,4 @@ int main(void) { cudaFree(y); return 0; -} \ No newline at end of file +} diff --git a/vecadd_gpu_256t_mb_prefetch.cu b/vecadd_gpu_256t_mb_prefetch.cu index ef6721c..6a1f709 100644 --- a/vecadd_gpu_256t_mb_prefetch.cu +++ b/vecadd_gpu_256t_mb_prefetch.cu @@ -1,6 +1,6 @@ -#include #include #include +#include // function to add the elements of two arrays __global__ void add(int n, float *x, float *y) { @@ -11,7 +11,7 @@ __global__ void add(int n, float *x, float *y) { } int main(void) { - int N = 1 << 29; // Setting problem size to 1<<29 (536,870,912 elements) + int N = 1 << 29; float *x, *y; @@ -35,7 +35,6 @@ int main(void) { // Number of blocks in the grid int numberOfBlocks = (N + threadsPerBlock - 1) / threadsPerBlock; - // Print out the number of thread blocks std::cout << "Number of thread blocks: " << numberOfBlocks << std::endl; // Run kernel on the elements on the GPU with multiple blocks and threads @@ -55,4 +54,4 @@ int main(void) { cudaFree(y); return 0; -} \ No newline at end of file +}