From 43d148729b2a8148eab7caccf317b2d7b8d2066f Mon Sep 17 00:00:00 2001 From: Noah Perret Date: Tue, 11 Aug 2026 11:17:43 +0200 Subject: [PATCH 01/27] UMA for matrix mult opencl --- .../benchmark_library.h | 5 - .../cpu_functions/cpu_functions.h | 1 + .../matrix_multiplication_bench/main.cpp | 248 ++++++++++-------- .../opencl/opencl_common.cpp | 109 ++++---- 4 files changed, 196 insertions(+), 167 deletions(-) diff --git a/gpu4s_benchmark/matrix_multiplication_bench/benchmark_library.h b/gpu4s_benchmark/matrix_multiplication_bench/benchmark_library.h index 655b419b..5bc099b8 100644 --- a/gpu4s_benchmark/matrix_multiplication_bench/benchmark_library.h +++ b/gpu4s_benchmark/matrix_multiplication_bench/benchmark_library.h @@ -48,8 +48,3 @@ struct GraficObject : public GraficCommon { }; // --- Specefic overload of benchmarking function --- - // #define UNIFIED_MEMORY -#ifdef UNIFIED_MEMORY - void device_unified_memory_init_copy(GraficCommon* device_object, bench_t* &A, bench_t* &B, bench_t* &C, unsigned int buff_size, char input_file_A[100],char input_file_B[100]); - void copy_memory_unified_to_host(GraficCommon* device_object, bench_t* &d_C, unsigned int buff_size); -#endif \ No newline at end of file diff --git a/gpu4s_benchmark/matrix_multiplication_bench/cpu_functions/cpu_functions.h b/gpu4s_benchmark/matrix_multiplication_bench/cpu_functions/cpu_functions.h index 9688694d..f8f1161a 100644 --- a/gpu4s_benchmark/matrix_multiplication_bench/cpu_functions/cpu_functions.h +++ b/gpu4s_benchmark/matrix_multiplication_bench/cpu_functions/cpu_functions.h @@ -106,6 +106,7 @@ struct BenchmarkParameters{ char input_file_B[100] = ""; char output_file[100] = ""; bool profiling_clock = false; + bool unified_memory = false; }; void matrix_multiplication(const bench_t* A, const bench_t* B, bench_t* C,const unsigned int n, const unsigned int m, const unsigned int w ); diff --git a/gpu4s_benchmark/matrix_multiplication_bench/main.cpp b/gpu4s_benchmark/matrix_multiplication_bench/main.cpp index e8c337cd..20fc6cf8 100644 --- a/gpu4s_benchmark/matrix_multiplication_bench/main.cpp +++ b/gpu4s_benchmark/matrix_multiplication_bench/main.cpp @@ -28,50 +28,71 @@ int main(int argc, char *argv[]) { exit(-1); } + /////////////////////////////////////////////////////////////////////////////////////////////// // VARIABLES /////////////////////////////////////////////////////////////////////////////////////////////// // linearizable versions of matrix unsigned int size_matrix = arguments_parameters->size * arguments_parameters->size; // A input matrix - unsigned int size_A = arguments_parameters->size * arguments_parameters->size; - unsigned int mem_size_A = sizeof(bench_t) * size_A; - #ifndef UNIFIED_MEMORY - bench_t* A = (bench_t*) malloc(mem_size_A); - #endif + unsigned int mem_size = sizeof(bench_t) * size_matrix; + bench_t* A = NULL; // B input matrix - unsigned int size_B = arguments_parameters->size * arguments_parameters->size; - unsigned int mem_size_B = sizeof(bench_t) * size_B; - #ifndef UNIFIED_MEMORY - bench_t* B = (bench_t*) malloc(mem_size_B); - #endif + bench_t* B = NULL; // C matrix - unsigned int size_C = arguments_parameters->size * arguments_parameters->size; - unsigned int mem_size_C = sizeof(bench_t) * size_C; - bench_t* h_C = (bench_t*) malloc(mem_size_C); - bench_t* d_C = (bench_t*) malloc(mem_size_C); + bench_t* d_C = NULL; + bench_t* h_C = (bench_t*) malloc(mem_size); // auxiliar matrix for compare the output - bench_t* h_C_output = (bench_t*) malloc(mem_size_C);; + bench_t* h_C_output = (bench_t*) malloc(mem_size);; // comparation result bool result = false; + // init devices char + char device[100] = ""; + + // base object init + GraficCommon*matrix_bench = (GraficCommon*)malloc(sizeof(GraficObject)); + + // --- 1. init bench --- + init(matrix_bench, 0,arguments_parameters->gpu, device); + // Update profiling clock mode + matrix_bench->profiling_clock = arguments_parameters->profiling_clock; + + // --- 2. init memory --- + device_memory_init(matrix_bench, size_matrix, size_matrix, size_matrix); + + if (arguments_parameters->unified_memory) + { + #ifdef UMA_COMPATIBILITY + // map the buffzer to the gpu + cpu take the lead + get_unified_memory_pointers(matrix_bench, A, B, d_C, mem_size); + #else + fprintf(stderr, "\033[1;31merror:\033[0m This framework is not compatible with unified memory. Please remove the -u arg!\n"); + exit(-1); + #endif + } else + { + // normale malloc + A = (bench_t*) malloc(mem_size); + B = (bench_t*) malloc(mem_size); + d_C = (bench_t*) malloc(mem_size); + } + /////////////////////////////////////////////////////////////////////////////////////////////// // DATA INIT /////////////////////////////////////////////////////////////////////////////////////////////// if (strlen(arguments_parameters->input_file_A) == 0) { - // inicialice A matrix - #ifndef UNIFIED_MEMORY + // inicialice A matrix for (int i=0; isize; i++){ for (int j=0; jsize; j++){ #ifdef INT A[i*arguments_parameters->size+j] = rand() % (NUMBER_BASE * 100); - #else A[i*arguments_parameters->size+j] = (bench_t)rand()/(bench_t)(RAND_MAX/NUMBER_BASE); #endif } } - // iniciate B matrix + // iniciate B matrix for (int i=0; isize; i++){ for (int j=0; jsize; j++){ #ifdef INT @@ -81,153 +102,138 @@ int main(int argc, char *argv[]) #endif } } - // iniciate C matrix - for (int i=0; isize; i++){ - for (int j=0; jsize; j++){ - h_C[i*arguments_parameters->size+j] = 0; - d_C[i*arguments_parameters->size+j] = 0; - - } - } - #endif } else { // load data - #ifndef UNIFIED_MEMORY - get_double_hexadecimal_values(arguments_parameters->input_file_A, A,size_A); - get_double_hexadecimal_values(arguments_parameters->input_file_B, B,size_B); - #endif + get_double_hexadecimal_values(arguments_parameters->input_file_A, A,size_matrix); + get_double_hexadecimal_values(arguments_parameters->input_file_B, B,size_matrix); //get_values_file(input_file, A, B); + } - // iniciate C matrix - for (int i=0; isize; i++){ - for (int j=0; jsize; j++){ - h_C[i*arguments_parameters->size+j] = 0; - d_C[i*arguments_parameters->size+j] = 0; - - } + // reset C matrix + for (int i=0; isize; i++){ + for (int j=0; jsize; j++){ + h_C[i*arguments_parameters->size+j] = 0; + d_C[i*arguments_parameters->size+j] = 0; } } /////////////////////////////////////////////////////////////////////////////////////////////// // CODE BENCKMARK /////////////////////////////////////////////////////////////////////////////////////////////// - - // base object init - GraficCommon*matrix_bench = (GraficCommon*)malloc(sizeof(GraficObject)); - // init devices - char device[100] = ""; - init(matrix_bench, 0,arguments_parameters->gpu, device); if (!arguments_parameters->csv_format_timestamp && !arguments_parameters->csv_format && !arguments_parameters->mute_messages ){ printf("Using device: %s\n", device); } - // Update profiling clock mode - matrix_bench->profiling_clock = arguments_parameters->profiling_clock; - - // If android and opencl force profiling clock - #ifdef PROFILING_CLOCK - matrix_bench->profiling_clock = true; - #endif - // init memory - device_memory_init(matrix_bench, size_matrix, size_matrix, size_matrix); - - #ifdef UNIFIED_MEMORY - bench_t *A, *B, *C; - //init and iniciate the buffer - device_unified_memory_init_copy(matrix_bench, A, B, C, arguments_parameters->size,arguments_parameters->input_file_A,arguments_parameters->input_file_B); - #else + if(arguments_parameters->unified_memory) + { + #ifdef UMA_COMPATIBILITY + // give GPU control to ptr + sync_unified_memory_to_device(matrix_bench, A, B, d_C); + #endif + } + else + { // copy memory to device - copy_memory_to_device(matrix_bench, A, B, arguments_parameters->size * arguments_parameters->size, arguments_parameters->size * arguments_parameters->size); - #endif + copy_memory_to_device(matrix_bench, A, B, size_matrix, size_matrix); + } + // execute kernel execute_kernel(matrix_bench, arguments_parameters->size, arguments_parameters->size,arguments_parameters-> size); - // copy memory to host - #ifdef UNIFIED_MEMORY - copy_memory_unified_to_host(matrix_bench, d_C, mem_size_C); - #else + if (arguments_parameters->unified_memory) + { + #ifdef UMA_COMPATIBILITY + // Copy back ptr + sync_unified_memory_to_host(matrix_bench, d_C, mem_size); + #endif + } else + { + // copy memory to host copy_memory_to_host(matrix_bench, d_C, size_matrix); - #endif - + } + // get time if (arguments_parameters->print_timing || arguments_parameters->csv_format || arguments_parameters->csv_format_timestamp) { get_elapsed_time(matrix_bench, arguments_parameters->csv_format, arguments_parameters->csv_format_timestamp, get_timestamp()); } + + // print buffer if (arguments_parameters->print_output) { #ifdef INT - for (int i=0; isize; i++){ - for (int j=0; jsize; j++){ - printf("%d ", d_C[i*arguments_parameters->size+j]); - - } - } + for (int i=0; isize; i++){ + for (int j=0; jsize; j++){ + printf("%d ", d_C[i*arguments_parameters->size+j]); + } + } #else - for (int i=0; isize; i++){ - for (int j=0; jsize; j++){ - printf("%f ", d_C[i*arguments_parameters->size+j]); - - } - printf("\n"); - } + for (int i=0; isize; i++){ + for (int j=0; jsize; j++){ + printf("%f ", d_C[i*arguments_parameters->size+j]); + } + printf("\n"); + } #endif + } - + // export gpu buffer + if (arguments_parameters->export_results_gpu) + { + print_double_hexadecimal_values(GPU_FILE, d_C, size_matrix); + //set_values_file(output_file, d_C, size); } + //check if error if (arguments_parameters->verification) { Clock cpuKernelCLK; cpuKernelCLK.start(); matrix_multiplication(A, B, h_C, arguments_parameters->size, arguments_parameters->size, arguments_parameters->size); cpuKernelCLK.end(); + if (arguments_parameters->print_timing) { printf("CPU Time %.0f milliseconds\n", cpuKernelCLK.getElapsedMS()); } + if (arguments_parameters->print_output) { - #ifdef INT - for (int i=0; isize; i++){ - for (int j=0; jsize; j++){ - printf("%d ", h_C[i*arguments_parameters->size+j]); - - } - printf("\n"); - } - #else - for (int i=0; isize; i++){ - for (int j=0; jsize; j++){ - printf("%f ", h_C[i*arguments_parameters->size+j]); - - } - printf("\n"); - } - #endif + #ifdef INT + for (int i=0; isize; i++){ + for (int j=0; jsize; j++){ + printf("%d ", h_C[i*arguments_parameters->size+j]); + } + printf("\n"); + } + #else + for (int i=0; isize; i++){ + for (int j=0; jsize; j++){ + printf("%f ", h_C[i*arguments_parameters->size+j]); + } + printf("\n"); + } + #endif } - result = compare_vectors(h_C, d_C, size_C); + + result = compare_vectors(h_C, d_C, size_matrix); if (result){ printf("OK\n"); } + if (arguments_parameters->export_results){ //set_values_file(output_file, d_C, size); - print_double_hexadecimal_values(GPU_FILE, d_C, size_C); - print_double_hexadecimal_values(CPU_FILE, h_C, size_C); + print_double_hexadecimal_values(GPU_FILE, d_C, size_matrix); + print_double_hexadecimal_values(CPU_FILE, h_C, size_matrix); } } - if (arguments_parameters->export_results_gpu) - { - print_double_hexadecimal_values(GPU_FILE, d_C, size_C); - //set_values_file(output_file, d_C, size); - } /////////////////////////////////////////////////////////////////////////////////////////////// // CLEAN MEMORY /////////////////////////////////////////////////////////////////////////////////////////////// @@ -236,11 +242,16 @@ int main(int argc, char *argv[]) free(arguments_parameters); // free object memory free(matrix_bench); - free(A); - free(B); + + if (!arguments_parameters->unified_memory) { + free(A); + free(B); + free(d_C); + } + free(h_C); - free(d_C); -return 0; + free(h_C_output); + return 0; } @@ -260,7 +271,8 @@ void print_usage(const char * appName) printf(" -d: selects GPU\n"); printf(" -f: mutes all print\n"); printf(" -h: print help information\n"); - printf(" -p: clock profilling \n"); + printf(" -p: clock profilling\n"); + printf(" -u: enable unified memory (ANDROID/JETSON)\n"); } void init_arguments(BenchmarkParameters* arguments_parameters){ @@ -274,7 +286,15 @@ void init_arguments(BenchmarkParameters* arguments_parameters){ arguments_parameters->csv_format = false; arguments_parameters->mute_messages = false; arguments_parameters->csv_format_timestamp = false; - arguments_parameters->profiling_clock = false; + arguments_parameters->unified_memory = false; + + // If android and opencl force profiling clock + #ifdef PROFILING_CLOCK + arguments_parameters->profiling_clock = true; + #else + arguments_parameters->profiling_clock = false; + #endif + // --- Properly clear character arrays --- arguments_parameters->input_file_A[0] = '\0'; arguments_parameters->input_file_B[0] = '\0'; @@ -312,7 +332,7 @@ int arguments_handler(int argc, char ** argv, BenchmarkParameters* arguments_par break; case 's' : args +=1; arguments_parameters->size = atoi(argv[args]);break; case 'p' : arguments_parameters->profiling_clock = true;break; - default: print_usage(argv[0]); return ERROR_ARGUMENTS; + case 'u' : arguments_parameters->unified_memory = true;break; } } diff --git a/gpu4s_benchmark/matrix_multiplication_bench/opencl/opencl_common.cpp b/gpu4s_benchmark/matrix_multiplication_bench/opencl/opencl_common.cpp index c0a4d4e5..ada4a1ab 100644 --- a/gpu4s_benchmark/matrix_multiplication_bench/opencl/opencl_common.cpp +++ b/gpu4s_benchmark/matrix_multiplication_bench/opencl/opencl_common.cpp @@ -96,61 +96,63 @@ void copy_memory_to_device(GraficCommon* device_object, bench_t* h_A, bench_t* h deviceObj->h2d_elapsed_time = h2dCLK.getElapsedNS(); } -#ifdef UNIFIED_MEMORY -void device_unified_memory_init_copy(GraficCommon* device_object, bench_t* &A, bench_t* &B, bench_t* &C, unsigned int buff_size, char input_file_A[100], char input_file_B[100]){ + + + +/** + * @brief + * + * @param device_object + * @param A + * @param B + * @param C + * @param memSize + */ +void get_unified_memory_pointers(GraficCommon* device_object, bench_t* &A, bench_t* &B, bench_t* &C, unsigned int memSize){ GraficObject* deviceObj = static_cast(device_object); - unsigned int squared_buff_size = buff_size * buff_size; - unsigned int mem_size = squared_buff_size * sizeof(bench_t); + Clock mapCLK; - h2dCLK.start(); - //--- Aquire the pointer of buffer from graphic card --- + mapCLK.start(); + + //--- Allocate and check space of pointer for graphic card --- A = (bench_t*)deviceObj->queue->enqueueMapBuffer( - *deviceObj->d_A, CL_TRUE, CL_MAP_WRITE, 0, mem_size); + *deviceObj->d_A, CL_TRUE, CL_MAP_WRITE, 0, memSize); B = (bench_t*)deviceObj->queue->enqueueMapBuffer( - *deviceObj->d_B, CL_TRUE, CL_MAP_WRITE, 0, mem_size); + *deviceObj->d_B, CL_TRUE, CL_MAP_WRITE, 0, memSize); C = (bench_t*)deviceObj->queue->enqueueMapBuffer( - *deviceObj->d_C, CL_TRUE, CL_MAP_WRITE, 0, mem_size); - h2dCLK.end(); + *deviceObj->d_C, CL_TRUE, CL_MAP_WRITE, 0, memSize); - h2dTotal += h2dCLK.getElapsedNS(); - - if (strlen(input_file_A) == 0) - { - - // --- Initialize the buffer --- - for (int i = 0; i < buff_size; i++) - for (int j = 0; j < buff_size; j++) - A[i*buff_size+j] = (bench_t)rand()/(bench_t)(RAND_MAX/NUMBER_BASE); - - for (int i = 0; i < buff_size; i++) - for (int j = 0; j < buff_size; j++) - B[i*buff_size+j] = (bench_t)rand()/(bench_t)(RAND_MAX/NUMBER_BASE); - - for (int i = 0; i < buff_size; i++) - for (int j = 0; j < buff_size; j++) - C[i*buff_size+j] = 0; - - } else - { - get_double_hexadecimal_values(input_file_A, A,mem_size); - get_double_hexadecimal_values(input_file_B, B,mem_size); - } + mapCLK.end(); + deviceObj->h2d_elapsed_time = mapCLK.getElapsedNS(); +} - h2dCLK.start(); - // --- Unmap the buffers for GPU kernel --- - deviceObj->queue->enqueueUnmapMemObject(*deviceObj->d_A, A, NULL, deviceObj->evt_copyA); - deviceObj->queue->enqueueUnmapMemObject(*deviceObj->d_B, B, NULL, deviceObj->evt_copyB); - deviceObj->queue->enqueueUnmapMemObject(*deviceObj->d_C, C, NULL, deviceObj->evt_copyC); - +/** + * @brief + * + * @param device_object + * @param A + * @param B + * @param C + */ +void sync_unified_memory_to_device(GraficCommon* device_object, bench_t* &A, bench_t* &B, bench_t* &C){ + GraficObject* deviceObj = static_cast(device_object); + Clock mapCLK; - deviceObj->queue->finish(); - h2dCLK.end(); + mapCLK.start(); - h2dTotal += h2dCLK.getElapsedNS(); + // --- Unmap the buffers for GPU kernel --- + deviceObj->queue->enqueueUnmapMemObject( + *deviceObj->d_A, A, NULL, deviceObj->evt_copyA); + deviceObj->queue->enqueueUnmapMemObject( + *deviceObj->d_B, B, NULL, deviceObj->evt_copyB); + deviceObj->queue->enqueueUnmapMemObject( + *deviceObj->d_C, C, NULL, deviceObj->evt_copyC); + + mapCLK.end(); + + deviceObj->h2d_elapsed_time += mapCLK.getElapsedNS(); } -#endif - @@ -176,19 +178,30 @@ void copy_memory_to_host(GraficCommon* device_object, bench_t* h_C, int size){ deviceObj->d2h_elapsed_time = d2hCLK.getElapsedNS(); } -#ifdef UNIFIED_MEMORY -void copy_memory_unified_to_host(GraficCommon* device_object, bench_t* &d_C, unsigned int buff_size){ +/** + * @brief + * + * @param device_object + * @param d_C + * @param buff_size + */ +void sync_unified_memory_to_host(GraficCommon* device_object, bench_t* &d_C, unsigned int buff_size){ GraficObject* deviceObj = static_cast(device_object); + Clock d2hCLK; d2hCLK.start(); // Map the output buffer to d_C pointer - d_C = (bench_t*)deviceObj->queue->enqueueMapBuffer(*deviceObj->d_C, CL_TRUE, CL_MAP_READ, 0, buff_size, NULL, deviceObj->evt_copyC); + d_C = (bench_t*)deviceObj->queue->enqueueMapBuffer( + *deviceObj->d_C, CL_TRUE, CL_MAP_READ, 0, buff_size, NULL, deviceObj->evt_copyC); deviceObj->queue->finish(); d2hCLK.end(); + + // store the hd2h time + deviceObj->d2h_elapsed_time = d2hCLK.getElapsedNS(); } -#endif + float get_elapsed_time(GraficCommon* device_object, bool csv_format, bool csv_format_timestamp, long int current_time){ GraficObject* deviceObj = static_cast(device_object); From 52861af6bdb5825370089ededdb1dd1d13866c84 Mon Sep 17 00:00:00 2001 From: Noah Perret Date: Tue, 11 Aug 2026 12:26:11 +0200 Subject: [PATCH 02/27] rename common file inside framework --- gpu4s_benchmark/LRN_bench/CMakeLists.txt | 8 +- .../LRN_bench/cpu_functions/cpu_functions.h | 1 + gpu4s_benchmark/LRN_bench/main.cpp | 15 +- ...pencl_common.cpp => lib_opencl_common.cpp} | 2 +- gpu4s_benchmark/cifar_10/CMakeLists.txt | 8 +- .../cifar_10/cpu_functions/cpu_functions.h | 1 + gpu4s_benchmark/cifar_10/main.cpp | 15 +- ...pencl_common.cpp => lib_opencl_common.cpp} | 2 +- .../cifar_10_multiple/CMakeLists.txt | 8 +- .../cpu_functions/cpu_functions.h | 1 + gpu4s_benchmark/cifar_10_multiple/main.cpp | 15 +- ...pencl_common.cpp => lib_opencl_common.cpp} | 2 +- gpu4s_benchmark/common/benchmark_common.h | 28 +- gpu4s_benchmark/common/opencl_common.hpp | 8 + .../convolution_2D_bench/CMakeLists.txt | 8 +- .../cpu_functions/cpu_functions.h | 1 + gpu4s_benchmark/convolution_2D_bench/main.cpp | 15 +- ...pencl_common.cpp => lib_opencl_common.cpp} | 2 +- gpu4s_benchmark/correlation_2D/CMakeLists.txt | 8 +- .../cpu_functions/cpu_functions.h | 1 + gpu4s_benchmark/correlation_2D/main.cpp | 15 +- ...pencl_common.cpp => lib_opencl_common.cpp} | 2 +- .../cpu_functions/cpu_functions.h | 3 +- .../fast_fourier_transform_2D_bench/main.cpp | 15 +- .../CMakeLists.txt | 12 +- .../cpu_functions/cpu_functions.h | 5 +- .../fast_fourier_transform_bench/main.cpp | 15 +- ...pencl_common.cpp => lib_opencl_common.cpp} | 2 +- .../CMakeLists.txt | 12 +- .../cpu_functions/cpu_functions.h | 1 + .../main.cpp | 15 +- ...pencl_common.cpp => lib_opencl_common.cpp} | 2 +- .../cpu_functions/cpu_functions.h | 1 + .../finite_impulse_response_filter/main.cpp | 15 +- ...pencl_common.cpp => lib_opencl_common.cpp} | 2 +- .../CMakeLists.txt | 12 +- .../matrix_multiplication_bench/main.cpp | 41 ++- ...pencl_common.cpp => lib_opencl_common.cpp} | 13 +- .../CMakeLists.txt | 12 +- .../cpu_functions/cpu_functions.h | 1 + .../matrix_multiplication_bench_fp16/main.cpp | 15 +- ...pencl_common.cpp => lib_opencl_common.cpp} | 2 +- .../CMakeLists.txt | 12 +- .../cpu_functions/cpu_functions.h | 1 + .../main.cpp | 15 +- ...pencl_common.cpp => lib_opencl_common.cpp} | 2 +- .../max_pooling_bench/CMakeLists.txt | 8 +- .../cpu_functions/cpu_functions.h | 1 + gpu4s_benchmark/max_pooling_bench/main.cpp | 15 +- ...pencl_common.cpp => lib_opencl_common.cpp} | 2 +- .../cpu_functions/cpu_functions.h | 1 + .../memory_bandwidth_bench/main.cpp | 15 +- gpu4s_benchmark/relu_bench/CMakeLists.txt | 8 +- .../relu_bench/cpu_functions/cpu_functions.h | 1 + gpu4s_benchmark/relu_bench/main.cpp | 243 ++++++++++-------- ...pencl_common.cpp => lib_opencl_common.cpp} | 2 +- gpu4s_benchmark/softmax_bench/CMakeLists.txt | 12 +- .../cpu_functions/cpu_functions.h | 1 + gpu4s_benchmark/softmax_bench/main.cpp | 15 +- ...pencl_common.cpp => lib_opencl_common.cpp} | 2 +- .../cpu_functions/cpu_functions.h | 1 + gpu4s_benchmark/wavelet_transform/main.cpp | 15 +- 62 files changed, 462 insertions(+), 272 deletions(-) rename gpu4s_benchmark/LRN_bench/opencl/{opencl_common.cpp => lib_opencl_common.cpp} (99%) rename gpu4s_benchmark/cifar_10/opencl/{opencl_common.cpp => lib_opencl_common.cpp} (99%) rename gpu4s_benchmark/cifar_10_multiple/opencl/{opencl_common.cpp => lib_opencl_common.cpp} (99%) create mode 100644 gpu4s_benchmark/common/opencl_common.hpp rename gpu4s_benchmark/convolution_2D_bench/opencl/{opencl_common.cpp => lib_opencl_common.cpp} (99%) rename gpu4s_benchmark/correlation_2D/opencl/{opencl_common.cpp => lib_opencl_common.cpp} (99%) rename gpu4s_benchmark/fast_fourier_transform_bench/opencl/{opencl_common.cpp => lib_opencl_common.cpp} (98%) rename gpu4s_benchmark/fast_fourier_transform_window_bench/opencl/{opencl_common.cpp => lib_opencl_common.cpp} (98%) rename gpu4s_benchmark/finite_impulse_response_filter/opencl/{opencl_common.cpp => lib_opencl_common.cpp} (84%) rename gpu4s_benchmark/matrix_multiplication_bench/opencl/{opencl_common.cpp => lib_opencl_common.cpp} (95%) rename gpu4s_benchmark/matrix_multiplication_bench_fp16/opencl/{opencl_common.cpp => lib_opencl_common.cpp} (99%) rename gpu4s_benchmark/matrix_multiplication_tensor_bench/opencl/{opencl_common.cpp => lib_opencl_common.cpp} (98%) rename gpu4s_benchmark/max_pooling_bench/opencl/{opencl_common.cpp => lib_opencl_common.cpp} (99%) rename gpu4s_benchmark/relu_bench/opencl/{opencl_common.cpp => lib_opencl_common.cpp} (99%) rename gpu4s_benchmark/softmax_bench/opencl/{opencl_common.cpp => lib_opencl_common.cpp} (99%) diff --git a/gpu4s_benchmark/LRN_bench/CMakeLists.txt b/gpu4s_benchmark/LRN_bench/CMakeLists.txt index 92eaca7a..f894ac3a 100644 --- a/gpu4s_benchmark/LRN_bench/CMakeLists.txt +++ b/gpu4s_benchmark/LRN_bench/CMakeLists.txt @@ -43,7 +43,7 @@ if(ANDROID) compile_target(${PROJECT_NAME}_opencl BENCH_DIR ${CMAKE_SOURCE_DIR} SOURCES_FILES opencl/lib_opencl.cpp - opencl/opencl_common.cpp + opencl/lib_opencl_common.cpp COMPILE_DEFS OPENCL CL_HPP_TARGET_OPENCL_VERSION=${OPENCL_VERSION} @@ -56,7 +56,7 @@ if(ANDROID) compile_target(${PROJECT_NAME}_opencl_opt BENCH_DIR ${CMAKE_SOURCE_DIR} SOURCES_FILES opencl/lib_opencl_opt.cpp - opencl/opencl_common.cpp + opencl/lib_opencl_common.cpp COMPILE_DEFS OPENCL CL_HPP_TARGET_OPENCL_VERSION=${OPENCL_VERSION} @@ -108,7 +108,7 @@ if(NOT ANDROID) compile_target(${PROJECT_NAME}_opencl BENCH_DIR ${CMAKE_SOURCE_DIR} SOURCES_FILES opencl/lib_opencl.cpp - opencl/opencl_common.cpp + opencl/lib_opencl_common.cpp COMPILE_DEFS OPENCL CL_HPP_TARGET_OPENCL_VERSION=${OPENCL_VERSION} @@ -121,7 +121,7 @@ if(NOT ANDROID) compile_target(${PROJECT_NAME}_opencl_opt BENCH_DIR ${CMAKE_SOURCE_DIR} SOURCES_FILES opencl/lib_opencl_opt.cpp - opencl/opencl_common.cpp + opencl/lib_opencl_common.cpp COMPILE_DEFS OPENCL CL_HPP_TARGET_OPENCL_VERSION=${OPENCL_VERSION} diff --git a/gpu4s_benchmark/LRN_bench/cpu_functions/cpu_functions.h b/gpu4s_benchmark/LRN_bench/cpu_functions/cpu_functions.h index 45599631..a4b17f00 100644 --- a/gpu4s_benchmark/LRN_bench/cpu_functions/cpu_functions.h +++ b/gpu4s_benchmark/LRN_bench/cpu_functions/cpu_functions.h @@ -57,6 +57,7 @@ struct BenchmarkParameters{ bool mute_messages = false; bool csv_format_timestamp = false; bool profiling_clock = false; + bool unified_memory = false; char input_file_A[100] = ""; char input_file_B[100] = ""; }; diff --git a/gpu4s_benchmark/LRN_bench/main.cpp b/gpu4s_benchmark/LRN_bench/main.cpp index d68c409e..6919d4af 100644 --- a/gpu4s_benchmark/LRN_bench/main.cpp +++ b/gpu4s_benchmark/LRN_bench/main.cpp @@ -116,7 +116,7 @@ int main(int argc, char *argv[]){ lrn_bench->profiling_clock = arguments_parameters->profiling_clock; // If android and opencl force profiling clock - #ifdef PROFILING_CLOCK + #ifdef FORCE_PROFILING_CLOCK lrn_bench->profiling_clock = true; #endif @@ -232,7 +232,8 @@ void print_usage(const char * appName) printf(" -x: prints the timing of the validation. Only the sequential time of the application will be displayed\n"); printf(" -f: mutes all print\n"); printf(" -h: print help information\n"); - printf(" -p: clock profilling \n"); + printf(" -p: clock profilling\n"); + printf(" -u: enable unified memory (ANDROID/JETSON)\n"); } void init_arguments(BenchmarkParameters* arguments_parameters){ @@ -247,7 +248,14 @@ void init_arguments(BenchmarkParameters* arguments_parameters){ arguments_parameters->csv_format = false; arguments_parameters->mute_messages = false; arguments_parameters->csv_format_timestamp = false; - arguments_parameters->profiling_clock = false; + arguments_parameters->unified_memory = false; + + // If android and opencl force profiling clock + #ifdef FORCE_PROFILING_CLOCK + arguments_parameters->profiling_clock = true; + #else + arguments_parameters->profiling_clock = false; + #endif } @@ -277,6 +285,7 @@ int arguments_handler(int argc, char ** argv, BenchmarkParameters* arguments_par strcpy(arguments_parameters->input_file_A,argv[args]); case 's' : args +=1; arguments_parameters->size = atol(argv[args]);break; case 'p' : arguments_parameters->profiling_clock = true;break; + case 'u' : arguments_parameters->unified_memory = true;break; default: print_usage(argv[0]); return ERROR_ARGUMENTS; } diff --git a/gpu4s_benchmark/LRN_bench/opencl/opencl_common.cpp b/gpu4s_benchmark/LRN_bench/opencl/lib_opencl_common.cpp similarity index 99% rename from gpu4s_benchmark/LRN_bench/opencl/opencl_common.cpp rename to gpu4s_benchmark/LRN_bench/opencl/lib_opencl_common.cpp index a71284f6..650528fa 100644 --- a/gpu4s_benchmark/LRN_bench/opencl/opencl_common.cpp +++ b/gpu4s_benchmark/LRN_bench/opencl/lib_opencl_common.cpp @@ -1,5 +1,5 @@ /** * ==================================================================== - * @file opencl_common.cpp (./LRN_bench) + * @file lib_opencl_common.cpp (./LRN_bench) * @brief Common OpenCL platform initialization, device setup, * profiling timer evaluation, and generic cleanup routines. * @paragraph License diff --git a/gpu4s_benchmark/cifar_10/CMakeLists.txt b/gpu4s_benchmark/cifar_10/CMakeLists.txt index 351bd971..83efdde5 100644 --- a/gpu4s_benchmark/cifar_10/CMakeLists.txt +++ b/gpu4s_benchmark/cifar_10/CMakeLists.txt @@ -42,7 +42,7 @@ if(ANDROID) compile_target(${PROJECT_NAME}_opencl BENCH_DIR ${CMAKE_SOURCE_DIR} SOURCES_FILES opencl/lib_opencl.cpp - opencl/opencl_common.cpp + opencl/lib_opencl_common.cpp COMPILE_DEFS OPENCL CL_HPP_TARGET_OPENCL_VERSION=${OPENCL_VERSION} @@ -56,7 +56,7 @@ if(ANDROID) compile_target(${PROJECT_NAME}_opencl_opt BENCH_DIR ${CMAKE_SOURCE_DIR} SOURCES_FILES opencl/lib_opencl_opt.cpp - opencl/opencl_common.cpp + opencl/lib_opencl_common.cpp COMPILE_DEFS OPENCL CL_HPP_TARGET_OPENCL_VERSION=${OPENCL_VERSION} @@ -109,7 +109,7 @@ if(NOT ANDROID) compile_target(${PROJECT_NAME}_opencl BENCH_DIR ${CMAKE_SOURCE_DIR} SOURCES_FILES opencl/lib_opencl.cpp - opencl/opencl_common.cpp + opencl/lib_opencl_common.cpp COMPILE_DEFS OPENCL CL_HPP_TARGET_OPENCL_VERSION=${OPENCL_VERSION} @@ -122,7 +122,7 @@ if(NOT ANDROID) compile_target(${PROJECT_NAME}_opencl_opt BENCH_DIR ${CMAKE_SOURCE_DIR} SOURCES_FILES opencl/lib_opencl_opt.cpp - opencl/opencl_common.cpp + opencl/lib_opencl_common.cpp COMPILE_DEFS OPENCL CL_HPP_TARGET_OPENCL_VERSION=${OPENCL_VERSION} diff --git a/gpu4s_benchmark/cifar_10/cpu_functions/cpu_functions.h b/gpu4s_benchmark/cifar_10/cpu_functions/cpu_functions.h index 7ffeda3d..3c777199 100644 --- a/gpu4s_benchmark/cifar_10/cpu_functions/cpu_functions.h +++ b/gpu4s_benchmark/cifar_10/cpu_functions/cpu_functions.h @@ -55,6 +55,7 @@ struct BenchmarkParameters{ bool mute_messages = false; bool csv_format_timestamp = false; bool profiling_clock = false; + bool unified_memory = false; char input_file_A[100] = ""; char input_file_B[100] = ""; char output_file[100] = ""; diff --git a/gpu4s_benchmark/cifar_10/main.cpp b/gpu4s_benchmark/cifar_10/main.cpp index 1821c64e..727b5469 100644 --- a/gpu4s_benchmark/cifar_10/main.cpp +++ b/gpu4s_benchmark/cifar_10/main.cpp @@ -185,7 +185,7 @@ int main(int argc, char *argv[]){ cifar10_bench->profiling_clock = arguments_parameters->profiling_clock; // If android and opencl force profiling clock - #ifdef PROFILING_CLOCK + #ifdef FORCE_PROFILING_CLOCK cifar10_bench->profiling_clock = true; #endif @@ -310,7 +310,8 @@ void print_usage(const char * appName) printf(" -d: selects GPU\n"); printf(" -f: mutes all print\n"); printf(" -h: print help information\n"); - printf(" -p: clock profilling \n"); + printf(" -p: clock profilling\n"); + printf(" -u: enable unified memory (ANDROID/JETSON)\n"); } void init_arguments(BenchmarkParameters* arguments_parameters){ @@ -324,7 +325,14 @@ void init_arguments(BenchmarkParameters* arguments_parameters){ arguments_parameters->csv_format = false; arguments_parameters->mute_messages = false; arguments_parameters->csv_format_timestamp = false; - arguments_parameters->profiling_clock = false; + arguments_parameters->unified_memory = false; + + // If android and opencl force profiling clock + #ifdef FORCE_PROFILING_CLOCK + arguments_parameters->profiling_clock = true; + #else + arguments_parameters->profiling_clock = false; + #endif } int arguments_handler(int argc, char ** argv, BenchmarkParameters* arguments_parameters){ @@ -347,6 +355,7 @@ int arguments_handler(int argc, char ** argv, BenchmarkParameters* arguments_par strcpy(arguments_parameters->input_file_B,argv[args]); break; case 'p' : arguments_parameters->profiling_clock = true;break; + case 'u' : arguments_parameters->unified_memory = true;break; // specific case 'i' : args +=1; strcpy(arguments_parameters->input_file_A,argv[args]); diff --git a/gpu4s_benchmark/cifar_10/opencl/opencl_common.cpp b/gpu4s_benchmark/cifar_10/opencl/lib_opencl_common.cpp similarity index 99% rename from gpu4s_benchmark/cifar_10/opencl/opencl_common.cpp rename to gpu4s_benchmark/cifar_10/opencl/lib_opencl_common.cpp index a869945d..de73abb3 100644 --- a/gpu4s_benchmark/cifar_10/opencl/opencl_common.cpp +++ b/gpu4s_benchmark/cifar_10/opencl/lib_opencl_common.cpp @@ -1,5 +1,5 @@ /** * ==================================================================== - * @file opencl_common.cpp (./cifar_10) + * @file lib_opencl_common.cpp (./cifar_10) * @brief Common OpenCL platform initialization, device setup, * profiling timer evaluation, and generic cleanup routines. * @paragraph License diff --git a/gpu4s_benchmark/cifar_10_multiple/CMakeLists.txt b/gpu4s_benchmark/cifar_10_multiple/CMakeLists.txt index 046bfca7..f9cde043 100644 --- a/gpu4s_benchmark/cifar_10_multiple/CMakeLists.txt +++ b/gpu4s_benchmark/cifar_10_multiple/CMakeLists.txt @@ -47,7 +47,7 @@ if(ANDROID) compile_target(${PROJECT_NAME}_opencl BENCH_DIR ${CMAKE_SOURCE_DIR} SOURCES_FILES opencl/lib_opencl.cpp - opencl/opencl_common.cpp + opencl/lib_opencl_common.cpp COMPILE_DEFS OPENCL NUMBER_OF_STREAMS=${NSTREAMS} @@ -62,7 +62,7 @@ if(ANDROID) compile_target(${PROJECT_NAME}_opencl_opt BENCH_DIR ${CMAKE_SOURCE_DIR} SOURCES_FILES opencl/lib_opencl_opt.cpp - opencl/opencl_common.cpp + opencl/lib_opencl_common.cpp COMPILE_DEFS OPENCL NUMBER_OF_STREAMS=${NSTREAMS} @@ -116,7 +116,7 @@ if(NOT ANDROID) compile_target(${PROJECT_NAME}_opencl BENCH_DIR ${CMAKE_SOURCE_DIR} SOURCES_FILES opencl/lib_opencl.cpp - opencl/opencl_common.cpp + opencl/lib_opencl_common.cpp COMPILE_DEFS OPENCL NUMBER_OF_STREAMS=${NSTREAMS} @@ -130,7 +130,7 @@ if(NOT ANDROID) compile_target(${PROJECT_NAME}_opencl_opt BENCH_DIR ${CMAKE_SOURCE_DIR} SOURCES_FILES opencl/lib_opencl_opt.cpp - opencl/opencl_common.cpp + opencl/lib_opencl_common.cpp COMPILE_DEFS OPENCL NUMBER_OF_STREAMS=${NSTREAMS} diff --git a/gpu4s_benchmark/cifar_10_multiple/cpu_functions/cpu_functions.h b/gpu4s_benchmark/cifar_10_multiple/cpu_functions/cpu_functions.h index d50e3835..25bd7803 100644 --- a/gpu4s_benchmark/cifar_10_multiple/cpu_functions/cpu_functions.h +++ b/gpu4s_benchmark/cifar_10_multiple/cpu_functions/cpu_functions.h @@ -56,6 +56,7 @@ struct BenchmarkParameters{ bool mute_messages = false; bool csv_format_timestamp = false; bool profiling_clock = false; + bool unified_memory = false; char input_file_A[100] = ""; char input_file_B[100] = ""; char output_file[100] = ""; diff --git a/gpu4s_benchmark/cifar_10_multiple/main.cpp b/gpu4s_benchmark/cifar_10_multiple/main.cpp index c909d03d..b0b71972 100644 --- a/gpu4s_benchmark/cifar_10_multiple/main.cpp +++ b/gpu4s_benchmark/cifar_10_multiple/main.cpp @@ -197,7 +197,7 @@ int main(int argc, char *argv[]){ cifar10_bench->profiling_clock = arguments_parameters->profiling_clock; // If android and opencl force profiling clock - #ifdef PROFILING_CLOCK + #ifdef FORCE_PROFILING_CLOCK cifar10_bench->profiling_clock = true; #endif @@ -335,7 +335,8 @@ void print_usage(const char * appName) printf(" -x: prints the timing of the validation. Only the sequential time of the application will be displayed\n"); printf(" -f: mutes all print\n"); printf(" -h: print help information\n"); - printf(" -p: clock profilling \n"); + printf(" -p: clock profilling\n"); + printf(" -u: enable unified memory (ANDROID/JETSON)\n"); } void init_arguments(BenchmarkParameters* arguments_parameters){ @@ -350,7 +351,14 @@ void init_arguments(BenchmarkParameters* arguments_parameters){ arguments_parameters->csv_format = false; arguments_parameters->mute_messages = false; arguments_parameters->csv_format_timestamp = false; - arguments_parameters->profiling_clock = false; + arguments_parameters->unified_memory = false; + + // If android and opencl force profiling clock + #ifdef FORCE_PROFILING_CLOCK + arguments_parameters->profiling_clock = true; + #else + arguments_parameters->profiling_clock = false; + #endif } int arguments_handler(int argc, char ** argv, BenchmarkParameters* arguments_parameters){ @@ -385,6 +393,7 @@ int arguments_handler(int argc, char ** argv, BenchmarkParameters* arguments_par break; case 's' : args +=1; arguments_parameters->size = atoi(argv[args]);break; case 'p' : arguments_parameters->profiling_clock = true;break; + case 'u' : arguments_parameters->unified_memory = true;break; default: print_usage(argv[0]); return ERROR_ARGUMENTS; } diff --git a/gpu4s_benchmark/cifar_10_multiple/opencl/opencl_common.cpp b/gpu4s_benchmark/cifar_10_multiple/opencl/lib_opencl_common.cpp similarity index 99% rename from gpu4s_benchmark/cifar_10_multiple/opencl/opencl_common.cpp rename to gpu4s_benchmark/cifar_10_multiple/opencl/lib_opencl_common.cpp index 1968745b..eb8ec6e4 100644 --- a/gpu4s_benchmark/cifar_10_multiple/opencl/opencl_common.cpp +++ b/gpu4s_benchmark/cifar_10_multiple/opencl/lib_opencl_common.cpp @@ -1,5 +1,5 @@ /** * ==================================================================== - * @file opencl_common.cpp (./cifar_10_multiple) + * @file lib_opencl_common.cpp (./cifar_10_multiple) * @brief Common OpenCL platform initialization, device setup, * profiling timer evaluation, and generic cleanup routines. * @paragraph License diff --git a/gpu4s_benchmark/common/benchmark_common.h b/gpu4s_benchmark/common/benchmark_common.h index 3e1bd6c3..43681a40 100644 --- a/gpu4s_benchmark/common/benchmark_common.h +++ b/gpu4s_benchmark/common/benchmark_common.h @@ -48,12 +48,14 @@ //CPU part #endif -// --- profiling mangement --- +// --- UMA + profiling mangement --- #if defined(ANDROID) && defined(OPENCL) - #define PROFILING_CLOCK + #define FORCE_PROFILING_CLOCK + #define UMA_COMPATIBILITY #endif + // ======= Commmon variable ======= // --- Core Data Types --- #ifdef INT @@ -107,10 +109,11 @@ struct GraficCommon{ #else // --- CPU variable --- #endif - float h2d_elapsed_time; - float elapsed_time; - float d2h_elapsed_time; - bool profiling_clock = false; + // --- clock profiling --- + float h2d_elapsed_time = 0.0f; + float d2h_elapsed_time = 0.0f; + float elapsed_time = 0.0f; + bool profiling_clock = false; }; @@ -156,3 +159,16 @@ float get_elapsed_time(GraficCommon *device_object, bool csv_format, bool csv_fo // Standard clean prototype used by every the benchmarks void clean(GraficCommon *device_object); + + +// --- UMA memory function --- +#ifdef UMA_COMPATIBILITY + // --- 2 buffer --- + void get_unified_memory_pointers(GraficCommon* device_object, bench_t* &A, bench_t* &B, unsigned int memSize); + void sync_unified_memory_to_device(GraficCommon* device_object, bench_t* &A, bench_t* &B); + + // --- 3 buffer --- + void get_unified_memory_pointers(GraficCommon* device_object, bench_t* &A, bench_t* &B, bench_t* &C, unsigned int memSize); + void sync_unified_memory_to_device(GraficCommon* device_object, bench_t* &A, bench_t* &B, bench_t* &C); + void sync_unified_memory_to_host(GraficCommon* device_object, bench_t* &d_C, unsigned int buff_size); +#endif \ No newline at end of file diff --git a/gpu4s_benchmark/common/opencl_common.hpp b/gpu4s_benchmark/common/opencl_common.hpp new file mode 100644 index 00000000..cd5dd82e --- /dev/null +++ b/gpu4s_benchmark/common/opencl_common.hpp @@ -0,0 +1,8 @@ +/** * ==================================================================== + * @file lib_opencl_common.h + * @brief Shared data structures, macros, and universal helpers + * for hardware acceleration benchmarks. + * @paragraph License + * ESA-PL Strong Copyleft – v2.5 + * ======================================================================= */ +#pragma once \ No newline at end of file diff --git a/gpu4s_benchmark/convolution_2D_bench/CMakeLists.txt b/gpu4s_benchmark/convolution_2D_bench/CMakeLists.txt index b1fdf731..456d0e19 100644 --- a/gpu4s_benchmark/convolution_2D_bench/CMakeLists.txt +++ b/gpu4s_benchmark/convolution_2D_bench/CMakeLists.txt @@ -43,7 +43,7 @@ if(ANDROID) compile_target(${PROJECT_NAME}_opencl BENCH_DIR ${CMAKE_SOURCE_DIR} SOURCES_FILES opencl/lib_opencl.cpp - opencl/opencl_common.cpp + opencl/lib_opencl_common.cpp COMPILE_DEFS OPENCL CL_HPP_TARGET_OPENCL_VERSION=${OPENCL_VERSION} @@ -57,7 +57,7 @@ if(ANDROID) compile_target(${PROJECT_NAME}_opencl_opt BENCH_DIR ${CMAKE_SOURCE_DIR} SOURCES_FILES opencl/lib_opencl_opt.cpp - opencl/opencl_common.cpp + opencl/lib_opencl_common.cpp COMPILE_DEFS OPENCL CL_HPP_TARGET_OPENCL_VERSION=${OPENCL_VERSION} @@ -110,7 +110,7 @@ if(NOT ANDROID) compile_target(${PROJECT_NAME}_opencl BENCH_DIR ${CMAKE_SOURCE_DIR} SOURCES_FILES opencl/lib_opencl.cpp - opencl/opencl_common.cpp + opencl/lib_opencl_common.cpp COMPILE_DEFS OPENCL CL_HPP_TARGET_OPENCL_VERSION=${OPENCL_VERSION} @@ -123,7 +123,7 @@ if(NOT ANDROID) compile_target(${PROJECT_NAME}_opencl_opt BENCH_DIR ${CMAKE_SOURCE_DIR} SOURCES_FILES opencl/lib_opencl_opt.cpp - opencl/opencl_common.cpp + opencl/lib_opencl_common.cpp COMPILE_DEFS OPENCL CL_HPP_TARGET_OPENCL_VERSION=${OPENCL_VERSION} diff --git a/gpu4s_benchmark/convolution_2D_bench/cpu_functions/cpu_functions.h b/gpu4s_benchmark/convolution_2D_bench/cpu_functions/cpu_functions.h index e6e13240..2001ccb9 100644 --- a/gpu4s_benchmark/convolution_2D_bench/cpu_functions/cpu_functions.h +++ b/gpu4s_benchmark/convolution_2D_bench/cpu_functions/cpu_functions.h @@ -55,6 +55,7 @@ struct BenchmarkParameters{ bool csv_format_timestamp = false; int kernel_size = -1; bool profiling_clock = false; + bool unified_memory = false; char input_file_A[100] = ""; char input_file_B[100] = ""; char output_file[100] = ""; diff --git a/gpu4s_benchmark/convolution_2D_bench/main.cpp b/gpu4s_benchmark/convolution_2D_bench/main.cpp index c26d28a2..a9ed1384 100644 --- a/gpu4s_benchmark/convolution_2D_bench/main.cpp +++ b/gpu4s_benchmark/convolution_2D_bench/main.cpp @@ -137,7 +137,7 @@ int main(int argc, char *argv[]){ conv_bench->profiling_clock = arguments_parameters->profiling_clock; // If android and opencl force profiling clock - #ifdef PROFILING_CLOCK + #ifdef FORCE_PROFILING_CLOCK conv_bench->profiling_clock = true; #endif @@ -259,7 +259,8 @@ void print_usage(const char * appName) printf(" -d: selects GPU\n"); printf(" -f: mutes all print\n"); printf(" -h: print help information\n"); - printf(" -p: clock profilling \n"); + printf(" -p: clock profilling\n"); + printf(" -u: enable unified memory (ANDROID/JETSON)\n"); } void init_arguments(BenchmarkParameters* arguments_parameters){ @@ -274,7 +275,14 @@ void init_arguments(BenchmarkParameters* arguments_parameters){ arguments_parameters->csv_format = false; arguments_parameters->mute_messages = false; arguments_parameters->csv_format_timestamp = false; - arguments_parameters->profiling_clock = false; + arguments_parameters->unified_memory = false; + + // If android and opencl force profiling clock + #ifdef FORCE_PROFILING_CLOCK + arguments_parameters->profiling_clock = true; + #else + arguments_parameters->profiling_clock = false; + #endif } int arguments_handler(int argc, char ** argv, BenchmarkParameters* arguments_parameters){ @@ -306,6 +314,7 @@ int arguments_handler(int argc, char ** argv, BenchmarkParameters* arguments_par break; case 's' : args +=1; arguments_parameters->size = atoi(argv[args]);break; case 'p' : arguments_parameters->profiling_clock = true;break; + case 'u' : arguments_parameters->unified_memory = true;break; case 'k' : args +=1; arguments_parameters->kernel_size = atoi(argv[args]);break; default: print_usage(argv[0]); return ERROR_ARGUMENTS; } diff --git a/gpu4s_benchmark/convolution_2D_bench/opencl/opencl_common.cpp b/gpu4s_benchmark/convolution_2D_bench/opencl/lib_opencl_common.cpp similarity index 99% rename from gpu4s_benchmark/convolution_2D_bench/opencl/opencl_common.cpp rename to gpu4s_benchmark/convolution_2D_bench/opencl/lib_opencl_common.cpp index 830ddc12..fbf69ebb 100644 --- a/gpu4s_benchmark/convolution_2D_bench/opencl/opencl_common.cpp +++ b/gpu4s_benchmark/convolution_2D_bench/opencl/lib_opencl_common.cpp @@ -1,5 +1,5 @@ /** * ==================================================================== - * @file opencl_common.cpp (./convolution_2D_bench) + * @file lib_opencl_common.cpp (./convolution_2D_bench) * @brief Common OpenCL platform initialization, device setup, * profiling timer evaluation, and generic cleanup routines. * @paragraph License diff --git a/gpu4s_benchmark/correlation_2D/CMakeLists.txt b/gpu4s_benchmark/correlation_2D/CMakeLists.txt index be5724e0..dae7b951 100644 --- a/gpu4s_benchmark/correlation_2D/CMakeLists.txt +++ b/gpu4s_benchmark/correlation_2D/CMakeLists.txt @@ -41,7 +41,7 @@ if(ANDROID) compile_target(${PROJECT_NAME}_opencl BENCH_DIR ${CMAKE_SOURCE_DIR} SOURCES_FILES opencl/lib_opencl.cpp - opencl/opencl_common.cpp + opencl/lib_opencl_common.cpp COMPILE_DEFS OPENCL CL_HPP_TARGET_OPENCL_VERSION=${OPENCL_VERSION} @@ -55,7 +55,7 @@ if(ANDROID) compile_target(${PROJECT_NAME}_opencl_opt BENCH_DIR ${CMAKE_SOURCE_DIR} SOURCES_FILES opencl/lib_opencl_opt.cpp - opencl/opencl_common.cpp + opencl/lib_opencl_common.cpp COMPILE_DEFS OPENCL CL_HPP_TARGET_OPENCL_VERSION=${OPENCL_VERSION} @@ -108,7 +108,7 @@ if(NOT ANDROID) compile_target(${PROJECT_NAME}_opencl BENCH_DIR ${CMAKE_SOURCE_DIR} SOURCES_FILES opencl/lib_opencl.cpp - opencl/opencl_common.cpp + opencl/lib_opencl_common.cpp COMPILE_DEFS OPENCL CL_HPP_TARGET_OPENCL_VERSION=${OPENCL_VERSION} @@ -121,7 +121,7 @@ if(NOT ANDROID) compile_target(${PROJECT_NAME}_opencl_opt BENCH_DIR ${CMAKE_SOURCE_DIR} SOURCES_FILES opencl/lib_opencl_opt.cpp - opencl/opencl_common.cpp + opencl/lib_opencl_common.cpp COMPILE_DEFS OPENCL CL_HPP_TARGET_OPENCL_VERSION=${OPENCL_VERSION} diff --git a/gpu4s_benchmark/correlation_2D/cpu_functions/cpu_functions.h b/gpu4s_benchmark/correlation_2D/cpu_functions/cpu_functions.h index 99a7d4a5..91207969 100644 --- a/gpu4s_benchmark/correlation_2D/cpu_functions/cpu_functions.h +++ b/gpu4s_benchmark/correlation_2D/cpu_functions/cpu_functions.h @@ -58,6 +58,7 @@ struct BenchmarkParameters{ bool mute_messages = false; bool csv_format_timestamp = false; bool profiling_clock = false; + bool unified_memory = false; char input_file_A[100] = ""; char input_file_B[100] = ""; char output_file[100] = ""; diff --git a/gpu4s_benchmark/correlation_2D/main.cpp b/gpu4s_benchmark/correlation_2D/main.cpp index e5c38626..7f17ee27 100644 --- a/gpu4s_benchmark/correlation_2D/main.cpp +++ b/gpu4s_benchmark/correlation_2D/main.cpp @@ -139,7 +139,7 @@ int main(int argc, char *argv[]){ correlation_bench->profiling_clock = arguments_parameters->profiling_clock; // If android and opencl force profiling clock - #ifdef PROFILING_CLOCK + #ifdef FORCE_PROFILING_CLOCK correlation_bench->profiling_clock = true; #endif @@ -226,7 +226,8 @@ void print_usage(const char * appName) printf(" -d: selects GPU\n"); printf(" -f: mutes all print\n"); printf(" -h: print help information\n"); - printf(" -p: clock profilling \n"); + printf(" -p: clock profilling\n"); + printf(" -u: enable unified memory (ANDROID/JETSON)\n"); } void init_arguments(BenchmarkParameters* arguments_parameters){ @@ -241,7 +242,14 @@ void init_arguments(BenchmarkParameters* arguments_parameters){ arguments_parameters->csv_format = false; arguments_parameters->mute_messages = false; arguments_parameters->csv_format_timestamp = false; - arguments_parameters->profiling_clock = false; + arguments_parameters->unified_memory = false; + + // If android and opencl force profiling clock + #ifdef FORCE_PROFILING_CLOCK + arguments_parameters->profiling_clock = true; + #else + arguments_parameters->profiling_clock = false; + #endif } int arguments_handler(int argc, char ** argv, BenchmarkParameters* arguments_parameters){ @@ -273,6 +281,7 @@ int arguments_handler(int argc, char ** argv, BenchmarkParameters* arguments_par break; case 's' : args +=1; arguments_parameters->size = atoi(argv[args]);break; case 'p' : arguments_parameters->profiling_clock = true;break; + case 'u' : arguments_parameters->unified_memory = true;break; default: print_usage(argv[0]); return ERROR_ARGUMENTS; } diff --git a/gpu4s_benchmark/correlation_2D/opencl/opencl_common.cpp b/gpu4s_benchmark/correlation_2D/opencl/lib_opencl_common.cpp similarity index 99% rename from gpu4s_benchmark/correlation_2D/opencl/opencl_common.cpp rename to gpu4s_benchmark/correlation_2D/opencl/lib_opencl_common.cpp index 088083c4..bf77a344 100644 --- a/gpu4s_benchmark/correlation_2D/opencl/opencl_common.cpp +++ b/gpu4s_benchmark/correlation_2D/opencl/lib_opencl_common.cpp @@ -1,5 +1,5 @@ /** * ==================================================================== - * @file opencl_common.cpp (./correlation_2D) + * @file lib_opencl_common.cpp (./correlation_2D) * @brief Common OpenCL platform initialization, device setup, * profiling timer evaluation, and generic cleanup routines. * @paragraph License diff --git a/gpu4s_benchmark/fast_fourier_transform_2D_bench/cpu_functions/cpu_functions.h b/gpu4s_benchmark/fast_fourier_transform_2D_bench/cpu_functions/cpu_functions.h index 211a3ca1..3fd51c54 100644 --- a/gpu4s_benchmark/fast_fourier_transform_2D_bench/cpu_functions/cpu_functions.h +++ b/gpu4s_benchmark/fast_fourier_transform_2D_bench/cpu_functions/cpu_functions.h @@ -45,7 +45,8 @@ struct BenchmarkParameters{ char input_file[100] = ""; char output_file[100] = ""; - bool profiling_clock = false;}; + bool profiling_clock = false; + bool unified_memory = false;}; bool FFT2D(COMPLEX **c,int n,int dir, COMPLEX **exit); bool compare_vectors(COMPLEX **host, COMPLEX **device, int64_t size); diff --git a/gpu4s_benchmark/fast_fourier_transform_2D_bench/main.cpp b/gpu4s_benchmark/fast_fourier_transform_2D_bench/main.cpp index 6e99e3c6..397098fb 100644 --- a/gpu4s_benchmark/fast_fourier_transform_2D_bench/main.cpp +++ b/gpu4s_benchmark/fast_fourier_transform_2D_bench/main.cpp @@ -96,7 +96,7 @@ int main(int argc, char *argv[]){ fft_bench->profiling_clock = arguments_parameters->profiling_clock; // If android and opencl force profiling clock - #ifdef PROFILING_CLOCK + #ifdef FORCE_PROFILING_CLOCK fft_bench->profiling_clock = true; #endif @@ -196,7 +196,8 @@ void print_usage(const char * appName) printf(" -q: prints input\n"); printf(" -d: selects GPU\n"); printf(" -h: print help information\n"); - printf(" -p: clock profilling \n"); + printf(" -p: clock profilling\n"); + printf(" -u: enable unified memory (ANDROID/JETSON)\n"); } void init_arguments(BenchmarkParameters* arguments_parameters){ @@ -211,7 +212,14 @@ void init_arguments(BenchmarkParameters* arguments_parameters){ arguments_parameters->csv_format = false; arguments_parameters->mute_messages = false; arguments_parameters->csv_format_timestamp = false; - arguments_parameters->profiling_clock = false; + arguments_parameters->unified_memory = false; + + // If android and opencl force profiling clock + #ifdef FORCE_PROFILING_CLOCK + arguments_parameters->profiling_clock = true; + #else + arguments_parameters->profiling_clock = false; + #endif } @@ -241,6 +249,7 @@ int arguments_handler(int argc, char ** argv, BenchmarkParameters* arguments_par break; case 's' : args +=1; arguments_parameters->size = atol(argv[args]);break; case 'p' : arguments_parameters->profiling_clock = true;break; + case 'u' : arguments_parameters->unified_memory = true;break; default: print_usage(argv[0]); return ERROR_ARGUMENTS; } diff --git a/gpu4s_benchmark/fast_fourier_transform_bench/CMakeLists.txt b/gpu4s_benchmark/fast_fourier_transform_bench/CMakeLists.txt index f491999b..23f6b29c 100644 --- a/gpu4s_benchmark/fast_fourier_transform_bench/CMakeLists.txt +++ b/gpu4s_benchmark/fast_fourier_transform_bench/CMakeLists.txt @@ -43,7 +43,7 @@ if(ANDROID) compile_target(${PROJECT_NAME}_opencl BENCH_DIR ${CMAKE_SOURCE_DIR} SOURCES_FILES opencl/lib_opencl.cpp - opencl/opencl_common.cpp + opencl/lib_opencl_common.cpp COMPILE_DEFS OPENCL CL_HPP_TARGET_OPENCL_VERSION=${OPENCL_VERSION} @@ -56,7 +56,7 @@ if(ANDROID) compile_target(${PROJECT_NAME}_opencl_opt BENCH_DIR ${CMAKE_SOURCE_DIR} SOURCES_FILES opencl/lib_opencl_opt.cpp - opencl/opencl_common.cpp + opencl/lib_opencl_common.cpp COMPILE_DEFS OPENCL CL_HPP_TARGET_OPENCL_VERSION=${OPENCL_VERSION} @@ -72,7 +72,7 @@ if(ANDROID) compile_target(${PROJECT_NAME}_opencl_lib BENCH_DIR ${CMAKE_SOURCE_DIR} SOURCES_FILES opencl/lib_opencl_lib.cpp - opencl/opencl_common.cpp + opencl/lib_opencl_common.cpp COMPILE_DEFS OPENCL OPENCL VKFFT_BACKEND=3 @@ -151,7 +151,7 @@ if(NOT ANDROID) compile_target(${PROJECT_NAME}_opencl BENCH_DIR ${CMAKE_SOURCE_DIR} SOURCES_FILES opencl/lib_opencl.cpp - opencl/opencl_common.cpp + opencl/lib_opencl_common.cpp COMPILE_DEFS OPENCL CL_HPP_TARGET_OPENCL_VERSION=${OPENCL_VERSION} @@ -164,7 +164,7 @@ if(NOT ANDROID) compile_target(${PROJECT_NAME}_opencl_opt BENCH_DIR ${CMAKE_SOURCE_DIR} SOURCES_FILES opencl/lib_opencl_opt.cpp - opencl/opencl_common.cpp + opencl/lib_opencl_common.cpp COMPILE_DEFS OPENCL CL_HPP_TARGET_OPENCL_VERSION=${OPENCL_VERSION} @@ -178,7 +178,7 @@ if(NOT ANDROID) compile_target(${PROJECT_NAME}_opencl_lib BENCH_DIR ${CMAKE_SOURCE_DIR} SOURCES_FILES opencl/lib_opencl_lib.cpp - opencl/opencl_common.cpp + opencl/lib_opencl_common.cpp COMPILE_DEFS OPENCL OPENCL VKFFT_BACKEND=3 diff --git a/gpu4s_benchmark/fast_fourier_transform_bench/cpu_functions/cpu_functions.h b/gpu4s_benchmark/fast_fourier_transform_bench/cpu_functions/cpu_functions.h index 5db5159d..f4eebe77 100644 --- a/gpu4s_benchmark/fast_fourier_transform_bench/cpu_functions/cpu_functions.h +++ b/gpu4s_benchmark/fast_fourier_transform_bench/cpu_functions/cpu_functions.h @@ -57,8 +57,9 @@ struct BenchmarkParameters{ bool csv_format_timestamp = false; char input_file[100] = ""; char output_file[100] = ""; - - bool profiling_clock = false;}; + bool profiling_clock = false; + bool unified_memory = false; +}; void fft_function(bench_t* data,int64_t nn); bool compare_vectors(const bench_t* host,const bench_t* device, const int64_t size); diff --git a/gpu4s_benchmark/fast_fourier_transform_bench/main.cpp b/gpu4s_benchmark/fast_fourier_transform_bench/main.cpp index 238124bb..4f89b5ab 100644 --- a/gpu4s_benchmark/fast_fourier_transform_bench/main.cpp +++ b/gpu4s_benchmark/fast_fourier_transform_bench/main.cpp @@ -97,7 +97,7 @@ int main(int argc, char *argv[]){ fft_bench->profiling_clock = arguments_parameters->profiling_clock; // If android and opencl force profiling clock - #ifdef PROFILING_CLOCK + #ifdef FORCE_PROFILING_CLOCK fft_bench->profiling_clock = true; #endif @@ -199,7 +199,8 @@ void print_usage(const char * appName) printf(" -d: selects GPU\n"); printf(" -f: mutes all print\n"); printf(" -h: print help information\n"); - printf(" -p: clock profilling \n"); + printf(" -p: clock profilling\n"); + printf(" -u: enable unified memory (ANDROID/JETSON)\n"); } void init_arguments(BenchmarkParameters* arguments_parameters){ @@ -214,7 +215,14 @@ void init_arguments(BenchmarkParameters* arguments_parameters){ arguments_parameters->csv_format = false; arguments_parameters->mute_messages = false; arguments_parameters->csv_format_timestamp = false; - arguments_parameters->profiling_clock = false; + arguments_parameters->unified_memory = false; + + // If android and opencl force profiling clock + #ifdef FORCE_PROFILING_CLOCK + arguments_parameters->profiling_clock = true; + #else + arguments_parameters->profiling_clock = false; + #endif } int arguments_handler(int argc, char ** argv, BenchmarkParameters* arguments_parameters){ @@ -243,6 +251,7 @@ int arguments_handler(int argc, char ** argv, BenchmarkParameters* arguments_par break; case 's' : args +=1; arguments_parameters->size = atoi(argv[args]);break; case 'p' : arguments_parameters->profiling_clock = true;break; + case 'u' : arguments_parameters->unified_memory = true;break; default: print_usage(argv[0]); return ERROR_ARGUMENTS; } diff --git a/gpu4s_benchmark/fast_fourier_transform_bench/opencl/opencl_common.cpp b/gpu4s_benchmark/fast_fourier_transform_bench/opencl/lib_opencl_common.cpp similarity index 98% rename from gpu4s_benchmark/fast_fourier_transform_bench/opencl/opencl_common.cpp rename to gpu4s_benchmark/fast_fourier_transform_bench/opencl/lib_opencl_common.cpp index e185f8af..395eb1e2 100644 --- a/gpu4s_benchmark/fast_fourier_transform_bench/opencl/opencl_common.cpp +++ b/gpu4s_benchmark/fast_fourier_transform_bench/opencl/lib_opencl_common.cpp @@ -1,5 +1,5 @@ /** * ==================================================================== - * @file opencl_common.cpp (./fast_fourier_transform_bench) + * @file lib_opencl_common.cpp (./fast_fourier_transform_bench) * @brief Common OpenCL platform initialization, device setup, * profiling timer evaluation, and generic cleanup routines. * @paragraph License diff --git a/gpu4s_benchmark/fast_fourier_transform_window_bench/CMakeLists.txt b/gpu4s_benchmark/fast_fourier_transform_window_bench/CMakeLists.txt index 68613973..5ab5786c 100644 --- a/gpu4s_benchmark/fast_fourier_transform_window_bench/CMakeLists.txt +++ b/gpu4s_benchmark/fast_fourier_transform_window_bench/CMakeLists.txt @@ -43,7 +43,7 @@ if(ANDROID) compile_target(${PROJECT_NAME}_opencl BENCH_DIR ${CMAKE_SOURCE_DIR} SOURCES_FILES opencl/lib_opencl.cpp - opencl/opencl_common.cpp + opencl/lib_opencl_common.cpp COMPILE_DEFS OPENCL CL_HPP_TARGET_OPENCL_VERSION=${OPENCL_VERSION} @@ -56,7 +56,7 @@ if(ANDROID) compile_target(${PROJECT_NAME}_opencl_opt BENCH_DIR ${CMAKE_SOURCE_DIR} SOURCES_FILES opencl/lib_opencl_opt.cpp - opencl/opencl_common.cpp + opencl/lib_opencl_common.cpp COMPILE_DEFS OPENCL CL_HPP_TARGET_OPENCL_VERSION=${OPENCL_VERSION} @@ -71,7 +71,7 @@ if(ANDROID) compile_target(${PROJECT_NAME}_opencl_lib BENCH_DIR ${CMAKE_SOURCE_DIR} SOURCES_FILES opencl/lib_opencl_lib.cpp - opencl/opencl_common.cpp + opencl/lib_opencl_common.cpp COMPILE_DEFS OPENCL OPENCL VKFFT_BACKEND=3 @@ -148,7 +148,7 @@ if(NOT ANDROID) compile_target(${PROJECT_NAME}_opencl BENCH_DIR ${CMAKE_SOURCE_DIR} SOURCES_FILES opencl/lib_opencl.cpp - opencl/opencl_common.cpp + opencl/lib_opencl_common.cpp COMPILE_DEFS OPENCL CL_HPP_TARGET_OPENCL_VERSION=${OPENCL_VERSION} @@ -161,7 +161,7 @@ if(NOT ANDROID) compile_target(${PROJECT_NAME}_opencl_opt BENCH_DIR ${CMAKE_SOURCE_DIR} SOURCES_FILES opencl/lib_opencl_opt.cpp - opencl/opencl_common.cpp + opencl/lib_opencl_common.cpp COMPILE_DEFS OPENCL CL_HPP_TARGET_OPENCL_VERSION=${OPENCL_VERSION} @@ -175,7 +175,7 @@ if(NOT ANDROID) compile_target(${PROJECT_NAME}_opencl_lib BENCH_DIR ${CMAKE_SOURCE_DIR} SOURCES_FILES opencl/lib_opencl_lib.cpp - opencl/opencl_common.cpp + opencl/lib_opencl_common.cpp COMPILE_DEFS OPENCL OPENCL VKFFT_BACKEND=3 diff --git a/gpu4s_benchmark/fast_fourier_transform_window_bench/cpu_functions/cpu_functions.h b/gpu4s_benchmark/fast_fourier_transform_window_bench/cpu_functions/cpu_functions.h index 705c0885..f1cab975 100644 --- a/gpu4s_benchmark/fast_fourier_transform_window_bench/cpu_functions/cpu_functions.h +++ b/gpu4s_benchmark/fast_fourier_transform_window_bench/cpu_functions/cpu_functions.h @@ -57,6 +57,7 @@ struct BenchmarkParameters{ bool mute_messages = false; bool csv_format_timestamp = false; bool profiling_clock = false; + bool unified_memory = false; char input_file_A[100] = ""; char input_file_B[100] = ""; }; diff --git a/gpu4s_benchmark/fast_fourier_transform_window_bench/main.cpp b/gpu4s_benchmark/fast_fourier_transform_window_bench/main.cpp index 1e0f7756..257de2d6 100644 --- a/gpu4s_benchmark/fast_fourier_transform_window_bench/main.cpp +++ b/gpu4s_benchmark/fast_fourier_transform_window_bench/main.cpp @@ -97,7 +97,7 @@ int main(int argc, char *argv[]){ fft_bench->profiling_clock = arguments_parameters->profiling_clock; // If android and opencl force profiling clock - #ifdef PROFILING_CLOCK + #ifdef FORCE_PROFILING_CLOCK fft_bench->profiling_clock = true; #endif @@ -201,7 +201,8 @@ void print_usage(const char * appName) printf(" -q: prints input\n"); printf(" -d: selects GPU\n"); printf(" -h: print help information\n"); - printf(" -p: clock profilling \n"); + printf(" -p: clock profilling\n"); + printf(" -u: enable unified memory (ANDROID/JETSON)\n"); } void init_arguments(BenchmarkParameters* arguments_parameters){ @@ -217,7 +218,14 @@ void init_arguments(BenchmarkParameters* arguments_parameters){ arguments_parameters->csv_format = false; arguments_parameters->mute_messages = false; arguments_parameters->csv_format_timestamp = false; - arguments_parameters->profiling_clock = false; + arguments_parameters->unified_memory = false; + + // If android and opencl force profiling clock + #ifdef FORCE_PROFILING_CLOCK + arguments_parameters->profiling_clock = true; + #else + arguments_parameters->profiling_clock = false; + #endif } @@ -250,6 +258,7 @@ int arguments_handler(int argc, char ** argv, BenchmarkParameters* arguments_par break; case 's' : args +=1; arguments_parameters->size = atol(argv[args]);break; case 'p' : arguments_parameters->profiling_clock = true;break; + case 'u' : arguments_parameters->unified_memory = true;break; default: print_usage(argv[0]); return ERROR_ARGUMENTS; } diff --git a/gpu4s_benchmark/fast_fourier_transform_window_bench/opencl/opencl_common.cpp b/gpu4s_benchmark/fast_fourier_transform_window_bench/opencl/lib_opencl_common.cpp similarity index 98% rename from gpu4s_benchmark/fast_fourier_transform_window_bench/opencl/opencl_common.cpp rename to gpu4s_benchmark/fast_fourier_transform_window_bench/opencl/lib_opencl_common.cpp index 5943dea9..22e1e03f 100644 --- a/gpu4s_benchmark/fast_fourier_transform_window_bench/opencl/opencl_common.cpp +++ b/gpu4s_benchmark/fast_fourier_transform_window_bench/opencl/lib_opencl_common.cpp @@ -1,5 +1,5 @@ /** * ==================================================================== - * @file opencl_common.cpp (./fast_fourier_transform_window_bench) + * @file lib_opencl_common.cpp (./fast_fourier_transform_window_bench) * @brief Common OpenCL platform initialization, device setup, * profiling timer evaluation, and generic cleanup routines. * @paragraph License diff --git a/gpu4s_benchmark/finite_impulse_response_filter/cpu_functions/cpu_functions.h b/gpu4s_benchmark/finite_impulse_response_filter/cpu_functions/cpu_functions.h index 3b411473..486220c4 100644 --- a/gpu4s_benchmark/finite_impulse_response_filter/cpu_functions/cpu_functions.h +++ b/gpu4s_benchmark/finite_impulse_response_filter/cpu_functions/cpu_functions.h @@ -55,6 +55,7 @@ struct BenchmarkParameters{ bool csv_format_timestamp = false; int kernel_size = 3; bool profiling_clock = false; + bool unified_memory = false; char input_file_A[100] = ""; char input_file_B[100] = ""; char output_file[100] = ""; diff --git a/gpu4s_benchmark/finite_impulse_response_filter/main.cpp b/gpu4s_benchmark/finite_impulse_response_filter/main.cpp index be06f772..dd1f1257 100644 --- a/gpu4s_benchmark/finite_impulse_response_filter/main.cpp +++ b/gpu4s_benchmark/finite_impulse_response_filter/main.cpp @@ -133,7 +133,7 @@ int main(int argc, char *argv[]) fir_bench->profiling_clock = arguments_parameters->profiling_clock; // If android and opencl force profiling clock - #ifdef PROFILING_CLOCK + #ifdef FORCE_PROFILING_CLOCK fir_bench->profiling_clock = true; #endif @@ -244,7 +244,8 @@ void print_usage(const char * appName) printf(" -d: selects GPU\n"); printf(" -f: mutes all print\n"); printf(" -h: print help information\n"); - printf(" -p: clock profilling \n"); + printf(" -p: clock profilling\n"); + printf(" -u: enable unified memory (ANDROID/JETSON)\n"); } void init_arguments(BenchmarkParameters* arguments_parameters){ @@ -259,7 +260,14 @@ void init_arguments(BenchmarkParameters* arguments_parameters){ arguments_parameters->csv_format = false; arguments_parameters->mute_messages = false; arguments_parameters->csv_format_timestamp = false; - arguments_parameters->profiling_clock = false; + arguments_parameters->unified_memory = false; + + // If android and opencl force profiling clock + #ifdef FORCE_PROFILING_CLOCK + arguments_parameters->profiling_clock = true; + #else + arguments_parameters->profiling_clock = false; + #endif } int arguments_handler(int argc, char ** argv, BenchmarkParameters* arguments_parameters){ @@ -294,6 +302,7 @@ int arguments_handler(int argc, char ** argv, BenchmarkParameters* arguments_par break; case 's' : args +=1; arguments_parameters->size = atoi(argv[args]);break; case 'p' : arguments_parameters->profiling_clock = true;break; + case 'u' : arguments_parameters->unified_memory = true;break; case 'k' : args +=1; arguments_parameters->kernel_size = atoi(argv[args]);break; default: print_usage(argv[0]); return ERROR_ARGUMENTS; } diff --git a/gpu4s_benchmark/finite_impulse_response_filter/opencl/opencl_common.cpp b/gpu4s_benchmark/finite_impulse_response_filter/opencl/lib_opencl_common.cpp similarity index 84% rename from gpu4s_benchmark/finite_impulse_response_filter/opencl/opencl_common.cpp rename to gpu4s_benchmark/finite_impulse_response_filter/opencl/lib_opencl_common.cpp index 6d81ba82..72085dae 100644 --- a/gpu4s_benchmark/finite_impulse_response_filter/opencl/opencl_common.cpp +++ b/gpu4s_benchmark/finite_impulse_response_filter/opencl/lib_opencl_common.cpp @@ -1,5 +1,5 @@ /** * ==================================================================== - * @file opencl_common.cpp (./finite_impulse_response_filter) + * @file lib_opencl_common.cpp (./finite_impulse_response_filter) * @brief Common OpenCL platform initialization, device setup, * profiling timer evaluation, and generic cleanup routines. * @paragraph License diff --git a/gpu4s_benchmark/matrix_multiplication_bench/CMakeLists.txt b/gpu4s_benchmark/matrix_multiplication_bench/CMakeLists.txt index a186179d..1a238c52 100644 --- a/gpu4s_benchmark/matrix_multiplication_bench/CMakeLists.txt +++ b/gpu4s_benchmark/matrix_multiplication_bench/CMakeLists.txt @@ -41,7 +41,7 @@ if(ANDROID) compile_target(${PROJECT_NAME}_opencl BENCH_DIR ${CMAKE_SOURCE_DIR} SOURCES_FILES opencl/lib_opencl.cpp - opencl/opencl_common.cpp + opencl/lib_opencl_common.cpp COMPILE_DEFS OPENCL CL_HPP_TARGET_OPENCL_VERSION=${OPENCL_VERSION} @@ -54,7 +54,7 @@ if(ANDROID) compile_target(${PROJECT_NAME}_opencl_opt BENCH_DIR ${CMAKE_SOURCE_DIR} SOURCES_FILES opencl/lib_opencl_opt.cpp - opencl/opencl_common.cpp + opencl/lib_opencl_common.cpp COMPILE_DEFS OPENCL CL_HPP_TARGET_OPENCL_VERSION=${OPENCL_VERSION} @@ -70,7 +70,7 @@ if(ANDROID) compile_target(${PROJECT_NAME}_opencl_lib BENCH_DIR ${CMAKE_SOURCE_DIR} SOURCES_FILES opencl/lib_opencl_lib.cpp - opencl/opencl_common.cpp + opencl/lib_opencl_common.cpp COMPILE_DEFS OPENCL CL_HPP_TARGET_OPENCL_VERSION=${OPENCL_VERSION} @@ -144,7 +144,7 @@ if(NOT ANDROID) compile_target(${PROJECT_NAME}_opencl BENCH_DIR ${CMAKE_SOURCE_DIR} SOURCES_FILES opencl/lib_opencl.cpp - opencl/opencl_common.cpp + opencl/lib_opencl_common.cpp COMPILE_DEFS OPENCL CL_HPP_TARGET_OPENCL_VERSION=${OPENCL_VERSION} @@ -157,7 +157,7 @@ if(NOT ANDROID) compile_target(${PROJECT_NAME}_opencl_opt BENCH_DIR ${CMAKE_SOURCE_DIR} SOURCES_FILES opencl/lib_opencl_opt.cpp - opencl/opencl_common.cpp + opencl/lib_opencl_common.cpp COMPILE_DEFS OPENCL CL_HPP_TARGET_OPENCL_VERSION=${OPENCL_VERSION} @@ -171,7 +171,7 @@ if(NOT ANDROID) compile_target(${PROJECT_NAME}_opencl_lib BENCH_DIR ${CMAKE_SOURCE_DIR} SOURCES_FILES opencl/lib_opencl_lib.cpp - opencl/opencl_common.cpp + opencl/lib_opencl_common.cpp COMPILE_DEFS OPENCL CL_HPP_TARGET_OPENCL_VERSION=${OPENCL_VERSION} diff --git a/gpu4s_benchmark/matrix_multiplication_bench/main.cpp b/gpu4s_benchmark/matrix_multiplication_bench/main.cpp index 20fc6cf8..5430a399 100644 --- a/gpu4s_benchmark/matrix_multiplication_bench/main.cpp +++ b/gpu4s_benchmark/matrix_multiplication_bench/main.cpp @@ -28,38 +28,34 @@ int main(int argc, char *argv[]) { exit(-1); } - /////////////////////////////////////////////////////////////////////////////////////////////// // VARIABLES /////////////////////////////////////////////////////////////////////////////////////////////// // linearizable versions of matrix unsigned int size_matrix = arguments_parameters->size * arguments_parameters->size; - // A input matrix unsigned int mem_size = sizeof(bench_t) * size_matrix; + // A input matrix bench_t* A = NULL; // B input matrix bench_t* B = NULL; - // C matrix + // C output matrix bench_t* d_C = NULL; bench_t* h_C = (bench_t*) malloc(mem_size); - // auxiliar matrix for compare the output - bench_t* h_C_output = (bench_t*) malloc(mem_size);; - // comparation result - bool result = false; // init devices char char device[100] = ""; - // base object init + // main object init GraficCommon*matrix_bench = (GraficCommon*)malloc(sizeof(GraficObject)); - // --- 1. init bench --- + // --- 1. Init Device & Context --- init(matrix_bench, 0,arguments_parameters->gpu, device); // Update profiling clock mode matrix_bench->profiling_clock = arguments_parameters->profiling_clock; - // --- 2. init memory --- + // --- 2. Allocate Device Memory --- device_memory_init(matrix_bench, size_matrix, size_matrix, size_matrix); + // --- 3. Allocate Host Pointers --- if (arguments_parameters->unified_memory) { #ifdef UMA_COMPATIBILITY @@ -126,17 +122,15 @@ int main(int argc, char *argv[]) printf("Using device: %s\n", device); } - + // copy memory to device if(arguments_parameters->unified_memory) { #ifdef UMA_COMPATIBILITY - // give GPU control to ptr sync_unified_memory_to_device(matrix_bench, A, B, d_C); #endif } else { - // copy memory to device copy_memory_to_device(matrix_bench, A, B, size_matrix, size_matrix); } @@ -144,7 +138,7 @@ int main(int argc, char *argv[]) // execute kernel execute_kernel(matrix_bench, arguments_parameters->size, arguments_parameters->size,arguments_parameters-> size); - + // copy memory to host if (arguments_parameters->unified_memory) { #ifdef UMA_COMPATIBILITY @@ -153,7 +147,6 @@ int main(int argc, char *argv[]) #endif } else { - // copy memory to host copy_memory_to_host(matrix_bench, d_C, size_matrix); } @@ -164,7 +157,7 @@ int main(int argc, char *argv[]) get_elapsed_time(matrix_bench, arguments_parameters->csv_format, arguments_parameters->csv_format_timestamp, get_timestamp()); } - // print buffer + // print output buffer if (arguments_parameters->print_output) { #ifdef INT @@ -222,12 +215,14 @@ int main(int argc, char *argv[]) #endif } - result = compare_vectors(h_C, d_C, size_matrix); - if (result){ + + if (compare_vectors(h_C, d_C, size_matrix)) + { printf("OK\n"); } - if (arguments_parameters->export_results){ + if (arguments_parameters->export_results) + { //set_values_file(output_file, d_C, size); print_double_hexadecimal_values(GPU_FILE, d_C, size_matrix); print_double_hexadecimal_values(CPU_FILE, h_C, size_matrix); @@ -239,18 +234,18 @@ int main(int argc, char *argv[]) /////////////////////////////////////////////////////////////////////////////////////////////// // clean device memory clean(matrix_bench); - free(arguments_parameters); // free object memory free(matrix_bench); + free(arguments_parameters); - if (!arguments_parameters->unified_memory) { + if (!arguments_parameters->unified_memory) + { free(A); free(B); free(d_C); } free(h_C); - free(h_C_output); return 0; } @@ -289,7 +284,7 @@ void init_arguments(BenchmarkParameters* arguments_parameters){ arguments_parameters->unified_memory = false; // If android and opencl force profiling clock - #ifdef PROFILING_CLOCK + #ifdef FORCE_PROFILING_CLOCK arguments_parameters->profiling_clock = true; #else arguments_parameters->profiling_clock = false; diff --git a/gpu4s_benchmark/matrix_multiplication_bench/opencl/opencl_common.cpp b/gpu4s_benchmark/matrix_multiplication_bench/opencl/lib_opencl_common.cpp similarity index 95% rename from gpu4s_benchmark/matrix_multiplication_bench/opencl/opencl_common.cpp rename to gpu4s_benchmark/matrix_multiplication_bench/opencl/lib_opencl_common.cpp index ada4a1ab..d806e03d 100644 --- a/gpu4s_benchmark/matrix_multiplication_bench/opencl/opencl_common.cpp +++ b/gpu4s_benchmark/matrix_multiplication_bench/opencl/lib_opencl_common.cpp @@ -1,5 +1,5 @@ /** * ==================================================================== - * @file opencl_common.cpp (./matrix_multiplication_bench) + * @file lib_opencl_common.cpp (./matrix_multiplication_bench) * @brief Common OpenCL platform initialization, device setup, * profiling timer evaluation, and generic cleanup routines. * @paragraph License @@ -97,10 +97,9 @@ void copy_memory_to_device(GraficCommon* device_object, bench_t* h_A, bench_t* h } - - /** - * @brief + * @brief Maps device memory buffers into the host's virtual address space, + * granting the CPU direct write access to the shared memory. * * @param device_object * @param A @@ -128,7 +127,8 @@ void get_unified_memory_pointers(GraficCommon* device_object, bench_t* &A, bench } /** - * @brief + * @brief Give CPU control of the shared memory back to the GPU, + * ensuring the device has exclusive access to the buffers * * @param device_object * @param A @@ -179,7 +179,8 @@ void copy_memory_to_host(GraficCommon* device_object, bench_t* h_C, int size){ } /** - * @brief +* @brief Synchronizes the output memory back to the host, +* give CPU direct access to the GPU's results. * * @param device_object * @param d_C diff --git a/gpu4s_benchmark/matrix_multiplication_bench_fp16/CMakeLists.txt b/gpu4s_benchmark/matrix_multiplication_bench_fp16/CMakeLists.txt index d6cf0bb2..e222df6b 100644 --- a/gpu4s_benchmark/matrix_multiplication_bench_fp16/CMakeLists.txt +++ b/gpu4s_benchmark/matrix_multiplication_bench_fp16/CMakeLists.txt @@ -33,7 +33,7 @@ if(ANDROID) compile_target(${PROJECT_NAME}_opencl BENCH_DIR ${CMAKE_SOURCE_DIR} SOURCES_FILES opencl/lib_opencl.cpp - opencl/opencl_common.cpp + opencl/lib_opencl_common.cpp COMPILE_DEFS OPENCL CL_HPP_TARGET_OPENCL_VERSION=${OPENCL_VERSION} @@ -46,7 +46,7 @@ if(ANDROID) compile_target(${PROJECT_NAME}_opencl_opt BENCH_DIR ${CMAKE_SOURCE_DIR} SOURCES_FILES opencl/lib_opencl_opt.cpp - opencl/opencl_common.cpp + opencl/lib_opencl_common.cpp COMPILE_DEFS OPENCL CL_HPP_TARGET_OPENCL_VERSION=${OPENCL_VERSION} @@ -62,7 +62,7 @@ if(ANDROID) compile_target(${PROJECT_NAME}_opencl_lib BENCH_DIR ${CMAKE_SOURCE_DIR} SOURCES_FILES opencl/lib_opencl_lib.cpp - opencl/opencl_common.cpp + opencl/lib_opencl_common.cpp COMPILE_DEFS OPENCL CL_HPP_TARGET_OPENCL_VERSION=${OPENCL_VERSION} @@ -85,7 +85,7 @@ if(NOT ANDROID) compile_target(${PROJECT_NAME}_opencl BENCH_DIR ${CMAKE_SOURCE_DIR} SOURCES_FILES opencl/lib_opencl.cpp - opencl/opencl_common.cpp + opencl/lib_opencl_common.cpp COMPILE_DEFS OPENCL CL_HPP_TARGET_OPENCL_VERSION=${OPENCL_VERSION} @@ -99,7 +99,7 @@ if(NOT ANDROID) compile_target(${PROJECT_NAME}_opencl_opt BENCH_DIR ${CMAKE_SOURCE_DIR} SOURCES_FILES opencl/lib_opencl_opt.cpp - opencl/opencl_common.cpp + opencl/lib_opencl_common.cpp COMPILE_DEFS OPENCL CL_HPP_TARGET_OPENCL_VERSION=${OPENCL_VERSION} @@ -114,7 +114,7 @@ if(NOT ANDROID) compile_target(${PROJECT_NAME}_opencl_lib BENCH_DIR ${CMAKE_SOURCE_DIR} SOURCES_FILES opencl/lib_opencl_lib.cpp - opencl/opencl_common.cpp + opencl/lib_opencl_common.cpp COMPILE_DEFS OPENCL CL_HPP_TARGET_OPENCL_VERSION=${OPENCL_VERSION} diff --git a/gpu4s_benchmark/matrix_multiplication_bench_fp16/cpu_functions/cpu_functions.h b/gpu4s_benchmark/matrix_multiplication_bench_fp16/cpu_functions/cpu_functions.h index bf097b4c..96be7a36 100644 --- a/gpu4s_benchmark/matrix_multiplication_bench_fp16/cpu_functions/cpu_functions.h +++ b/gpu4s_benchmark/matrix_multiplication_bench_fp16/cpu_functions/cpu_functions.h @@ -50,6 +50,7 @@ struct BenchmarkParameters{ char input_file_B[100] = ""; char output_file[100] = ""; bool profiling_clock = false; + bool unified_memory = false; }; void matrix_multiplication(const bench_t* A, const bench_t* B, bench_t* C,const unsigned int n, const unsigned int m, const unsigned int w ); diff --git a/gpu4s_benchmark/matrix_multiplication_bench_fp16/main.cpp b/gpu4s_benchmark/matrix_multiplication_bench_fp16/main.cpp index bc22db2a..5fe64fb1 100644 --- a/gpu4s_benchmark/matrix_multiplication_bench_fp16/main.cpp +++ b/gpu4s_benchmark/matrix_multiplication_bench_fp16/main.cpp @@ -120,7 +120,7 @@ int main(int argc, char *argv[]){ matrix_benck->profiling_clock = arguments_parameters->profiling_clock; // If android and opencl force profiling clock - #ifdef PROFILING_CLOCK + #ifdef FORCE_PROFILING_CLOCK matrix_benck->profiling_clock = true; #endif @@ -241,7 +241,8 @@ void print_usage(const char * appName) printf(" -d: selects GPU\n"); printf(" -f: mutes all print\n"); printf(" -h: print help information\n"); - printf(" -p: clock profilling \n"); + printf(" -p: clock profilling\n"); + printf(" -u: enable unified memory (ANDROID/JETSON)\n"); } void init_arguments(BenchmarkParameters* arguments_parameters){ @@ -255,7 +256,14 @@ void init_arguments(BenchmarkParameters* arguments_parameters){ arguments_parameters->csv_format = false; arguments_parameters->mute_messages = false; arguments_parameters->csv_format_timestamp = false; - arguments_parameters->profiling_clock = false; + arguments_parameters->unified_memory = false; + + // If android and opencl force profiling clock + #ifdef FORCE_PROFILING_CLOCK + arguments_parameters->profiling_clock = true; + #else + arguments_parameters->profiling_clock = false; + #endif // --- Properly clear character arrays --- arguments_parameters->input_file_A[0] = '\0'; arguments_parameters->input_file_B[0] = '\0'; @@ -293,6 +301,7 @@ int arguments_handler(int argc, char ** argv, BenchmarkParameters* arguments_par break; case 's' : args +=1; arguments_parameters->size = atoi(argv[args]);break; case 'p' : arguments_parameters->profiling_clock = true;break; + case 'u' : arguments_parameters->unified_memory = true;break; default: print_usage(argv[0]); return ERROR_ARGUMENTS; } diff --git a/gpu4s_benchmark/matrix_multiplication_bench_fp16/opencl/opencl_common.cpp b/gpu4s_benchmark/matrix_multiplication_bench_fp16/opencl/lib_opencl_common.cpp similarity index 99% rename from gpu4s_benchmark/matrix_multiplication_bench_fp16/opencl/opencl_common.cpp rename to gpu4s_benchmark/matrix_multiplication_bench_fp16/opencl/lib_opencl_common.cpp index 57c9479b..868f25ba 100644 --- a/gpu4s_benchmark/matrix_multiplication_bench_fp16/opencl/opencl_common.cpp +++ b/gpu4s_benchmark/matrix_multiplication_bench_fp16/opencl/lib_opencl_common.cpp @@ -1,5 +1,5 @@ /** * ==================================================================== - * @file opencl_common.cpp (./matrix_multiplication_bench_fp16) + * @file lib_opencl_common.cpp (./matrix_multiplication_bench_fp16) * @brief Common OpenCL platform initialization, device setup, * profiling timer evaluation, and generic cleanup routines. * @paragraph License diff --git a/gpu4s_benchmark/matrix_multiplication_tensor_bench/CMakeLists.txt b/gpu4s_benchmark/matrix_multiplication_tensor_bench/CMakeLists.txt index 8892b899..5a39c380 100644 --- a/gpu4s_benchmark/matrix_multiplication_tensor_bench/CMakeLists.txt +++ b/gpu4s_benchmark/matrix_multiplication_tensor_bench/CMakeLists.txt @@ -33,7 +33,7 @@ if(ANDROID) compile_target(${PROJECT_NAME}_opencl BENCH_DIR ${CMAKE_SOURCE_DIR} SOURCES_FILES opencl/lib_opencl.cpp - opencl/opencl_common.cpp + opencl/lib_opencl_common.cpp COMPILE_DEFS OPENCL CL_HPP_TARGET_OPENCL_VERSION=${OPENCL_VERSION} @@ -46,7 +46,7 @@ if(ANDROID) compile_target(${PROJECT_NAME}_opencl_opt BENCH_DIR ${CMAKE_SOURCE_DIR} SOURCES_FILES opencl/lib_opencl_opt.cpp - opencl/opencl_common.cpp + opencl/lib_opencl_common.cpp COMPILE_DEFS OPENCL CL_HPP_TARGET_OPENCL_VERSION=${OPENCL_VERSION} @@ -62,7 +62,7 @@ if(ANDROID) compile_target(${PROJECT_NAME}_opencl_lib BENCH_DIR ${CMAKE_SOURCE_DIR} SOURCES_FILES opencl/lib_opencl_lib.cpp - opencl/opencl_common.cpp + opencl/lib_opencl_common.cpp COMPILE_DEFS OPENCL CL_HPP_TARGET_OPENCL_VERSION=${OPENCL_VERSION} @@ -85,7 +85,7 @@ if(NOT ANDROID) compile_target(${PROJECT_NAME}_opencl BENCH_DIR ${CMAKE_SOURCE_DIR} SOURCES_FILES opencl/lib_opencl.cpp - opencl/opencl_common.cpp + opencl/lib_opencl_common.cpp COMPILE_DEFS OPENCL CL_HPP_TARGET_OPENCL_VERSION=${OPENCL_VERSION} @@ -98,7 +98,7 @@ if(NOT ANDROID) compile_target(${PROJECT_NAME}_opencl_opt BENCH_DIR ${CMAKE_SOURCE_DIR} SOURCES_FILES opencl/lib_opencl_opt.cpp - opencl/opencl_common.cpp + opencl/lib_opencl_common.cpp COMPILE_DEFS OPENCL CL_HPP_TARGET_OPENCL_VERSION=${OPENCL_VERSION} @@ -112,7 +112,7 @@ if(NOT ANDROID) compile_target(${PROJECT_NAME}_opencl_lib BENCH_DIR ${CMAKE_SOURCE_DIR} SOURCES_FILES opencl/lib_opencl_lib.cpp - opencl/opencl_common.cpp + opencl/lib_opencl_common.cpp COMPILE_DEFS OPENCL CL_HPP_TARGET_OPENCL_VERSION=${OPENCL_VERSION} diff --git a/gpu4s_benchmark/matrix_multiplication_tensor_bench/cpu_functions/cpu_functions.h b/gpu4s_benchmark/matrix_multiplication_tensor_bench/cpu_functions/cpu_functions.h index f121fed1..bfcab9c1 100644 --- a/gpu4s_benchmark/matrix_multiplication_tensor_bench/cpu_functions/cpu_functions.h +++ b/gpu4s_benchmark/matrix_multiplication_tensor_bench/cpu_functions/cpu_functions.h @@ -53,6 +53,7 @@ struct BenchmarkParameters{ char input_file_B[100] = ""; char output_file[100] = ""; bool profiling_clock = false; + bool unified_memory = false; }; void matrix_multiplication(const bench_t* A, const bench_t* B, bench_t* C,const unsigned int n, const unsigned int m, const unsigned int w ); diff --git a/gpu4s_benchmark/matrix_multiplication_tensor_bench/main.cpp b/gpu4s_benchmark/matrix_multiplication_tensor_bench/main.cpp index 69c4bce3..d54dc2c3 100644 --- a/gpu4s_benchmark/matrix_multiplication_tensor_bench/main.cpp +++ b/gpu4s_benchmark/matrix_multiplication_tensor_bench/main.cpp @@ -119,7 +119,7 @@ int main(int argc, char *argv[]){ matrix_benck->profiling_clock = arguments_parameters->profiling_clock; // If android and opencl force profiling clock - #ifdef PROFILING_CLOCK + #ifdef FORCE_PROFILING_CLOCK matrix_benck->profiling_clock = true; #endif @@ -239,7 +239,8 @@ void print_usage(const char * appName) printf(" -d: selects GPU\n"); printf(" -f: mutes all print\n"); printf(" -h: print help information\n"); - printf(" -p: clock profilling \n"); + printf(" -p: clock profilling\n"); + printf(" -u: enable unified memory (ANDROID/JETSON)\n"); } void init_arguments(BenchmarkParameters* arguments_parameters){ @@ -253,7 +254,14 @@ void init_arguments(BenchmarkParameters* arguments_parameters){ arguments_parameters->csv_format = false; arguments_parameters->mute_messages = false; arguments_parameters->csv_format_timestamp = false; - arguments_parameters->profiling_clock = false; + arguments_parameters->unified_memory = false; + + // If android and opencl force profiling clock + #ifdef FORCE_PROFILING_CLOCK + arguments_parameters->profiling_clock = true; + #else + arguments_parameters->profiling_clock = false; + #endif // --- Properly clear character arrays --- arguments_parameters->input_file_A[0] = '\0'; arguments_parameters->input_file_B[0] = '\0'; @@ -291,6 +299,7 @@ int arguments_handler(int argc, char ** argv, BenchmarkParameters* arguments_par break; case 's' : args +=1; arguments_parameters->size = atoi(argv[args]);break; case 'p' : arguments_parameters->profiling_clock = true;break; + case 'u' : arguments_parameters->unified_memory = true;break; default: print_usage(argv[0]); return ERROR_ARGUMENTS; } diff --git a/gpu4s_benchmark/matrix_multiplication_tensor_bench/opencl/opencl_common.cpp b/gpu4s_benchmark/matrix_multiplication_tensor_bench/opencl/lib_opencl_common.cpp similarity index 98% rename from gpu4s_benchmark/matrix_multiplication_tensor_bench/opencl/opencl_common.cpp rename to gpu4s_benchmark/matrix_multiplication_tensor_bench/opencl/lib_opencl_common.cpp index e2623a68..9a68d7dc 100644 --- a/gpu4s_benchmark/matrix_multiplication_tensor_bench/opencl/opencl_common.cpp +++ b/gpu4s_benchmark/matrix_multiplication_tensor_bench/opencl/lib_opencl_common.cpp @@ -1,5 +1,5 @@ /** * ==================================================================== - * @file opencl_common.cpp (./matrix_multiplication_tensor_bench) + * @file lib_opencl_common.cpp (./matrix_multiplication_tensor_bench) * @brief Common OpenCL platform initialization, device setup, * profiling timer evaluation, and generic cleanup routines. * @paragraph License diff --git a/gpu4s_benchmark/max_pooling_bench/CMakeLists.txt b/gpu4s_benchmark/max_pooling_bench/CMakeLists.txt index 8b3057a9..b21634f6 100644 --- a/gpu4s_benchmark/max_pooling_bench/CMakeLists.txt +++ b/gpu4s_benchmark/max_pooling_bench/CMakeLists.txt @@ -42,7 +42,7 @@ if(ANDROID) compile_target(${PROJECT_NAME}_opencl BENCH_DIR ${CMAKE_SOURCE_DIR} SOURCES_FILES opencl/lib_opencl.cpp - opencl/opencl_common.cpp + opencl/lib_opencl_common.cpp COMPILE_DEFS OPENCL CL_HPP_TARGET_OPENCL_VERSION=${OPENCL_VERSION} @@ -55,7 +55,7 @@ if(ANDROID) compile_target(${PROJECT_NAME}_opencl_opt BENCH_DIR ${CMAKE_SOURCE_DIR} SOURCES_FILES opencl/lib_opencl_opt.cpp - opencl/opencl_common.cpp + opencl/lib_opencl_common.cpp COMPILE_DEFS OPENCL CL_HPP_TARGET_OPENCL_VERSION=${OPENCL_VERSION} @@ -108,7 +108,7 @@ if(NOT ANDROID) compile_target(${PROJECT_NAME}_opencl BENCH_DIR ${CMAKE_SOURCE_DIR} SOURCES_FILES opencl/lib_opencl.cpp - opencl/opencl_common.cpp + opencl/lib_opencl_common.cpp COMPILE_DEFS OPENCL CL_HPP_TARGET_OPENCL_VERSION=${OPENCL_VERSION} @@ -121,7 +121,7 @@ if(NOT ANDROID) compile_target(${PROJECT_NAME}_opencl_opt BENCH_DIR ${CMAKE_SOURCE_DIR} SOURCES_FILES opencl/lib_opencl_opt.cpp - opencl/opencl_common.cpp + opencl/lib_opencl_common.cpp COMPILE_DEFS OPENCL CL_HPP_TARGET_OPENCL_VERSION=${OPENCL_VERSION} diff --git a/gpu4s_benchmark/max_pooling_bench/cpu_functions/cpu_functions.h b/gpu4s_benchmark/max_pooling_bench/cpu_functions/cpu_functions.h index 3f529132..f853920f 100644 --- a/gpu4s_benchmark/max_pooling_bench/cpu_functions/cpu_functions.h +++ b/gpu4s_benchmark/max_pooling_bench/cpu_functions/cpu_functions.h @@ -57,6 +57,7 @@ struct BenchmarkParameters{ bool mute_messages = false; bool csv_format_timestamp = false; bool profiling_clock = false; + bool unified_memory = false; char input_file_A[100] = ""; char input_file_B[100] = ""; }; diff --git a/gpu4s_benchmark/max_pooling_bench/main.cpp b/gpu4s_benchmark/max_pooling_bench/main.cpp index 92cec9ff..870aa9ba 100644 --- a/gpu4s_benchmark/max_pooling_bench/main.cpp +++ b/gpu4s_benchmark/max_pooling_bench/main.cpp @@ -118,7 +118,7 @@ int main(int argc, char *argv[]){ max_bench->profiling_clock = arguments_parameters->profiling_clock; // If android and opencl force profiling clock - #ifdef PROFILING_CLOCK + #ifdef FORCE_PROFILING_CLOCK max_bench->profiling_clock = true; #endif @@ -242,7 +242,8 @@ void print_usage(const char * appName) printf(" -x: prints the timing of the validation. Only the sequential time of the application will be displayed\n"); printf(" -f: mutes all print\n"); printf(" -h: print help information\n"); - printf(" -p: clock profilling \n"); + printf(" -p: clock profilling\n"); + printf(" -u: enable unified memory (ANDROID/JETSON)\n"); } void init_arguments(BenchmarkParameters* arguments_parameters){ @@ -257,7 +258,14 @@ void init_arguments(BenchmarkParameters* arguments_parameters){ arguments_parameters->csv_format = false; arguments_parameters->mute_messages = false; arguments_parameters->csv_format_timestamp = false; - arguments_parameters->profiling_clock = false; + arguments_parameters->unified_memory = false; + + // If android and opencl force profiling clock + #ifdef FORCE_PROFILING_CLOCK + arguments_parameters->profiling_clock = true; + #else + arguments_parameters->profiling_clock = false; + #endif } int arguments_handler(int argc, char ** argv, BenchmarkParameters* arguments_parameters){ @@ -289,6 +297,7 @@ int arguments_handler(int argc, char ** argv, BenchmarkParameters* arguments_par break; case 's' : args +=1; arguments_parameters->size = atoi(argv[args]);break; case 'p' : arguments_parameters->profiling_clock = true;break; + case 'u' : arguments_parameters->unified_memory = true;break; case 'l' : args +=1; arguments_parameters->stride = atoi(argv[args]);break; default: print_usage(argv[0]); return ERROR_ARGUMENTS; } diff --git a/gpu4s_benchmark/max_pooling_bench/opencl/opencl_common.cpp b/gpu4s_benchmark/max_pooling_bench/opencl/lib_opencl_common.cpp similarity index 99% rename from gpu4s_benchmark/max_pooling_bench/opencl/opencl_common.cpp rename to gpu4s_benchmark/max_pooling_bench/opencl/lib_opencl_common.cpp index fc19ba57..49d4ac6d 100644 --- a/gpu4s_benchmark/max_pooling_bench/opencl/opencl_common.cpp +++ b/gpu4s_benchmark/max_pooling_bench/opencl/lib_opencl_common.cpp @@ -1,5 +1,5 @@ /** * ==================================================================== - * @file opencl_common.cpp (./max_pooling_bench) + * @file lib_opencl_common.cpp (./max_pooling_bench) * @brief Common OpenCL platform initialization, device setup, * profiling timer evaluation, and generic cleanup routines. * @paragraph License diff --git a/gpu4s_benchmark/memory_bandwidth_bench/cpu_functions/cpu_functions.h b/gpu4s_benchmark/memory_bandwidth_bench/cpu_functions/cpu_functions.h index 7f3ac7d0..13e36601 100644 --- a/gpu4s_benchmark/memory_bandwidth_bench/cpu_functions/cpu_functions.h +++ b/gpu4s_benchmark/memory_bandwidth_bench/cpu_functions/cpu_functions.h @@ -53,6 +53,7 @@ struct BenchmarkParameters{ char input_file_B[100] = ""; char output_file[100] = ""; bool profiling_clock = false; + bool unified_memory = false; }; void matrix_multiplication(const bench_t* A, const bench_t* B, bench_t* C,const unsigned int n, const unsigned int m, const unsigned int w ); diff --git a/gpu4s_benchmark/memory_bandwidth_bench/main.cpp b/gpu4s_benchmark/memory_bandwidth_bench/main.cpp index 869e679f..2a2d373d 100644 --- a/gpu4s_benchmark/memory_bandwidth_bench/main.cpp +++ b/gpu4s_benchmark/memory_bandwidth_bench/main.cpp @@ -99,7 +99,7 @@ int main(int argc, char *argv[]) mem_bench->profiling_clock = arguments_parameters->profiling_clock; // If android and opencl force profiling clock - #ifdef PROFILING_CLOCK + #ifdef FORCE_PROFILING_CLOCK mem_bench->profiling_clock = true; #endif @@ -205,7 +205,8 @@ void print_usage(const char * appName) printf(" -d: selects GPU\n"); printf(" -f: mutes all print\n"); printf(" -h: print help information\n"); - printf(" -p: clock profilling \n"); + printf(" -p: clock profilling\n"); + printf(" -u: enable unified memory (ANDROID/JETSON)\n"); } void init_arguments(BenchmarkParameters* arguments_parameters){ @@ -219,7 +220,14 @@ void init_arguments(BenchmarkParameters* arguments_parameters){ arguments_parameters->csv_format = false; arguments_parameters->mute_messages = false; arguments_parameters->csv_format_timestamp = false; - arguments_parameters->profiling_clock = false; + arguments_parameters->unified_memory = false; + + // If android and opencl force profiling clock + #ifdef FORCE_PROFILING_CLOCK + arguments_parameters->profiling_clock = true; + #else + arguments_parameters->profiling_clock = false; + #endif // --- Properly clear character arrays --- arguments_parameters->input_file_A[0] = '\0'; arguments_parameters->input_file_B[0] = '\0'; @@ -257,6 +265,7 @@ int arguments_handler(int argc, char ** argv, BenchmarkParameters* arguments_par break; case 's' : args +=1; arguments_parameters->size = atoi(argv[args]);break; case 'p' : arguments_parameters->profiling_clock = true;break; + case 'u' : arguments_parameters->unified_memory = true;break; default: print_usage(argv[0]); return ERROR_ARGUMENTS; } diff --git a/gpu4s_benchmark/relu_bench/CMakeLists.txt b/gpu4s_benchmark/relu_bench/CMakeLists.txt index 11dc3eab..e820a2a1 100644 --- a/gpu4s_benchmark/relu_bench/CMakeLists.txt +++ b/gpu4s_benchmark/relu_bench/CMakeLists.txt @@ -44,7 +44,7 @@ if(ANDROID) compile_target(${PROJECT_NAME}_opencl BENCH_DIR ${CMAKE_SOURCE_DIR} SOURCES_FILES opencl/lib_opencl.cpp - opencl/opencl_common.cpp + opencl/lib_opencl_common.cpp COMPILE_DEFS OPENCL CL_HPP_TARGET_OPENCL_VERSION=${OPENCL_VERSION} @@ -57,7 +57,7 @@ if(ANDROID) compile_target(${PROJECT_NAME}_opencl_opt BENCH_DIR ${CMAKE_SOURCE_DIR} SOURCES_FILES opencl/lib_opencl_opt.cpp - opencl/opencl_common.cpp + opencl/lib_opencl_common.cpp COMPILE_DEFS OPENCL CL_HPP_TARGET_OPENCL_VERSION=${OPENCL_VERSION} @@ -108,7 +108,7 @@ if(NOT ANDROID) compile_target(${PROJECT_NAME}_opencl BENCH_DIR ${CMAKE_SOURCE_DIR} SOURCES_FILES opencl/lib_opencl.cpp - opencl/opencl_common.cpp + opencl/lib_opencl_common.cpp COMPILE_DEFS OPENCL CL_HPP_TARGET_OPENCL_VERSION=${OPENCL_VERSION} @@ -121,7 +121,7 @@ if(NOT ANDROID) compile_target(${PROJECT_NAME}_opencl_opt BENCH_DIR ${CMAKE_SOURCE_DIR} SOURCES_FILES opencl/lib_opencl_opt.cpp - opencl/opencl_common.cpp + opencl/lib_opencl_common.cpp COMPILE_DEFS OPENCL CL_HPP_TARGET_OPENCL_VERSION=${OPENCL_VERSION} diff --git a/gpu4s_benchmark/relu_bench/cpu_functions/cpu_functions.h b/gpu4s_benchmark/relu_bench/cpu_functions/cpu_functions.h index 8d69877e..ff8ddbab 100644 --- a/gpu4s_benchmark/relu_bench/cpu_functions/cpu_functions.h +++ b/gpu4s_benchmark/relu_bench/cpu_functions/cpu_functions.h @@ -57,6 +57,7 @@ struct BenchmarkParameters{ bool mute_messages = false; bool csv_format_timestamp = false; bool profiling_clock = false; + bool unified_memory = false; char input_file_A[100] = ""; char input_file_B[100] = ""; }; diff --git a/gpu4s_benchmark/relu_bench/main.cpp b/gpu4s_benchmark/relu_bench/main.cpp index a2ed08ba..c65b3c0e 100644 --- a/gpu4s_benchmark/relu_bench/main.cpp +++ b/gpu4s_benchmark/relu_bench/main.cpp @@ -32,20 +32,44 @@ int main(int argc, char *argv[]){ // VARIABLES /////////////////////////////////////////////////////////////////////////////////////////////// // linearizable versions of matrix - unsigned int size_matrix =arguments_parameters->size * arguments_parameters->size; + unsigned int size_matrix = arguments_parameters->size * arguments_parameters->size; + unsigned int mem_size = sizeof(bench_t) * size_matrix; // A input matrix - unsigned int size_A = arguments_parameters->size * arguments_parameters->size; - unsigned int mem_size_A = sizeof(bench_t) * size_A; - #ifndef UNIFIED_MEMORY - bench_t* A = (bench_t*) malloc(mem_size_A); - #endif + bench_t* A = NULL; // B input matrix - unsigned int size_B = arguments_parameters->size * arguments_parameters->size; - unsigned int mem_size_B = sizeof(bench_t) * size_B; - bench_t* h_B = (bench_t*) malloc(mem_size_B); - bench_t* d_B = (bench_t*) malloc(mem_size_B); - // comparation result - bool result = false; + bench_t* h_B = NULL; + bench_t* d_B = (bench_t*) malloc(mem_size); + // init devices + char device[100] = ""; + + // main object init + GraficCommon*relu_bench = (GraficCommon*)malloc(sizeof(GraficObject)); + + // --- 1. Init Device & Context --- + init(relu_bench, 0,arguments_parameters->gpu, device); + // Update profiling clock mode + relu_bench->profiling_clock = arguments_parameters->profiling_clock; + + // --- 2. Allocate Device Memory --- + device_memory_init(relu_bench, arguments_parameters->size * arguments_parameters->size, arguments_parameters->size * arguments_parameters->size); + + // --- 3. Allocate Host Pointers --- + if (arguments_parameters->unified_memory) + { + #ifdef UMA_COMPATIBILITY + // map the buffer to the gpu + cpu take the lead + get_unified_memory_pointers(relu_bench, A, d_B, mem_size); + #else + fprintf(stderr, "\033[1;31merror:\033[0m This framework is not compatible with unified memory. Please remove the -u arg!\n"); + exit(-1); + #endif + } else + { + // normale malloc + A = (bench_t*) malloc(mem_size); + h_B = (bench_t*) malloc(mem_size); + } + /////////////////////////////////////////////////////////////////////////////////////////////// // DATA INIT /////////////////////////////////////////////////////////////////////////////////////////////// @@ -57,36 +81,27 @@ int main(int argc, char *argv[]){ for (int j=0; jsize; j++){ #ifdef INT A[i*arguments_parameters->size+j] = rand() % (NUMBER_BASE * 100); - #else A[i*arguments_parameters->size+j] = (double)rand()/RAND_MAX*2.0-1.0; #endif } } - // iniciate B matrix - for (int i=0; isize; i++){ - for (int j=0; jsize; j++){ - h_B[i*arguments_parameters->size+j] = 0; - d_B[i*arguments_parameters->size+j] = 0; - } - } #endif } else { - // load data TODO - /*get_double_hexadecimal_values(input_file_A, A,size_A); - get_double_hexadecimal_values(input_file_B, B,size_B); - - // iniciate C matrix - for (int i=0; iinput_file_A, A,size_matrix); } + + // reset B matrix + for (int i=0; isize; i++){ + for (int j=0; jsize; j++){ + h_B[i*arguments_parameters->size+j] = 0; + d_B[i*arguments_parameters->size+j] = 0; + } + } + // print input // if (arguments_parameters->print_input) // { @@ -101,127 +116,117 @@ int main(int argc, char *argv[]){ // printf("\n"); // } // printf("\n\n"); - // } - - /////////////////////////////////////////////////////////////////////////////////////////////// // CODE BENCKMARK /////////////////////////////////////////////////////////////////////////////////////////////// - - // base object init - GraficCommon*relu_bench = (GraficCommon*)malloc(sizeof(GraficObject)); - // init devices - char device[100] = ""; - init(relu_bench, 0,arguments_parameters->gpu, device); if (!arguments_parameters->csv_format_timestamp && !arguments_parameters->csv_format && !arguments_parameters->mute_messages ){ printf("Using device: %s\n", device); } - // Update profiling clock mode - relu_bench->profiling_clock = arguments_parameters->profiling_clock; - - // If android and opencl force profiling clock - #ifdef PROFILING_CLOCK - relu_bench->profiling_clock = true; - #endif - - // init memory - device_memory_init(relu_bench, arguments_parameters->size * arguments_parameters->size, arguments_parameters->size * arguments_parameters->size); - - #ifdef UNIFIED_MEMORY - bench_t *A, *B; - //init and iniciate the buffer - device_unified_memory_init_copy(relu_bench, A, B, arguments_parameters->size,arguments_parameters->input_file_A,arguments_parameters->input_file_B); - #else // copy memory to device - copy_memory_to_device(relu_bench, A, arguments_parameters->size * arguments_parameters->size); - #endif + if(arguments_parameters->unified_memory) + { + #ifdef UMA_COMPATIBILITY + sync_unified_memory_to_device(relu_bench, A, d_B); + #endif + } + else + { + copy_memory_to_device(relu_bench, A, size_matrix); + } // execute kernel execute_kernel(relu_bench, arguments_parameters->size, arguments_parameters->size, arguments_parameters->size); // copy memory to host - #ifdef UNIFIED_MEMORY - copy_memory_unified_to_host(relu_bench, d_B, mem_size_B); - #else - copy_memory_to_host(relu_bench, d_B, size_matrix); - #endif + if (arguments_parameters->unified_memory) + { + #ifdef UMA_COMPATIBILITY + sync_unified_memory_to_host(relu_bench, d_B, mem_size); + #endif + } else + { + copy_memory_to_host(relu_bench, d_B, size_matrix); + } + // get time if (arguments_parameters->print_timing || arguments_parameters->csv_format || arguments_parameters->csv_format_timestamp) { get_elapsed_time(relu_bench, arguments_parameters->csv_format, arguments_parameters->csv_format_timestamp, get_timestamp()); } + + // print output buffer if (arguments_parameters->print_output) { #ifdef INT - for (int i=0; isize; i++){ - for (int j=0; jsize; j++){ - printf("%d ", d_B[i*arguments_parameters->size+j]); - - } - printf("\n"); - } + for (int i=0; isize; i++){ + for (int j=0; jsize; j++){ + printf("%d ", d_B[i*arguments_parameters->size+j]); + } + printf("\n"); + } #else - for (int i=0; isize; i++){ - for (int j=0; jsize; j++){ - printf("%f ", d_B[i*arguments_parameters->size+j]); - - } - printf("\n"); - } + for (int i=0; isize; i++){ + for (int j=0; jsize; j++){ + printf("%f ", d_B[i*arguments_parameters->size+j]); + } + printf("\n"); + } #endif + } - + // export gpu buffer + if (arguments_parameters->export_results_gpu) + { + print_double_hexadecimal_values(GPU_FILE, d_B, size_matrix); } - - + //check if error if (arguments_parameters->verification) { Clock cpuKernelCLK; cpuKernelCLK.start(); relu(A,h_B, arguments_parameters->size); cpuKernelCLK.end(); + if (arguments_parameters->print_timing) { printf("CPU Time %.0f milliseconds\n",cpuKernelCLK.getElapsedMS()); } + if (arguments_parameters->print_output) { - #ifdef INT - for (int i=0; isize; i++){ - for (int j=0; jsize; j++){ - printf("%d ", h_B[i*arguments_parameters->size+j]); - - } - printf("\n"); - } - #else - for (int i=0; isize; i++){ - for (int j=0; jsize; j++){ - printf("%f ", h_B[i*arguments_parameters->size+j]); - - } - printf("\n"); - } - #endif + #ifdef INT + for (int i=0; isize; i++){ + for (int j=0; jsize; j++){ + printf("%d ", h_B[i*arguments_parameters->size+j]); + } + printf("\n"); + } + #else + for (int i=0; isize; i++){ + for (int j=0; jsize; j++){ + printf("%f ", h_B[i*arguments_parameters->size+j]); + } + printf("\n"); + } + #endif } - result = compare_vectors(h_B, d_B, size_B); - if (result){ + + if (compare_vectors(h_B, d_B, size_matrix)) + { printf("OK\n"); } - if (arguments_parameters->export_results){ - print_double_hexadecimal_values(GPU_FILE, d_B, size_B); - print_double_hexadecimal_values(CPU_FILE, h_B, size_B); + + if (arguments_parameters->export_results) + { + print_double_hexadecimal_values(GPU_FILE, d_B, size_matrix); + print_double_hexadecimal_values(CPU_FILE, h_B, size_matrix); } } - if (arguments_parameters->export_results_gpu) - { - print_double_hexadecimal_values(GPU_FILE, d_B, size_B); - } /////////////////////////////////////////////////////////////////////////////////////////////// // CLEAN MEMORY /////////////////////////////////////////////////////////////////////////////////////////////// @@ -230,10 +235,15 @@ int main(int argc, char *argv[]){ // free object memory free(relu_bench); free(arguments_parameters); - free(A); - free(h_B); + + if (!arguments_parameters->unified_memory) + { + free(A); + free(h_B); + } + free(d_B); -return 0; + return 0; } @@ -249,7 +259,14 @@ void init_arguments(BenchmarkParameters* arguments_parameters){ arguments_parameters->csv_format = false; arguments_parameters->mute_messages = false; arguments_parameters->csv_format_timestamp = false; - arguments_parameters->profiling_clock = false; + arguments_parameters->unified_memory = false; + + // If android and opencl force profiling clock + #ifdef FORCE_PROFILING_CLOCK + arguments_parameters->profiling_clock = true; + #else + arguments_parameters->profiling_clock = false; + #endif } // Arguments part @@ -270,7 +287,8 @@ void print_usage(const char * appName) printf(" -d: selects GPU\n"); printf(" -f: mutes all print\n"); printf(" -h: print help information\n"); - printf(" -p: clock profilling \n"); + printf(" -p: clock profilling\n"); + printf(" -u: enable unified memory (ANDROID/JETSON)\n"); } @@ -303,6 +321,7 @@ int arguments_handler(int argc, char ** argv, BenchmarkParameters* arguments_par break; case 's' : args +=1; arguments_parameters->size = atoi(argv[args]);break; case 'p' : arguments_parameters->profiling_clock = true;break; + case 'u' : arguments_parameters->unified_memory = true;break; default: print_usage(argv[0]); return ERROR_ARGUMENTS; } diff --git a/gpu4s_benchmark/relu_bench/opencl/opencl_common.cpp b/gpu4s_benchmark/relu_bench/opencl/lib_opencl_common.cpp similarity index 99% rename from gpu4s_benchmark/relu_bench/opencl/opencl_common.cpp rename to gpu4s_benchmark/relu_bench/opencl/lib_opencl_common.cpp index d742a8ff..c3e04dca 100644 --- a/gpu4s_benchmark/relu_bench/opencl/opencl_common.cpp +++ b/gpu4s_benchmark/relu_bench/opencl/lib_opencl_common.cpp @@ -1,5 +1,5 @@ /** * ==================================================================== - * @file opencl_common.cpp (./relu_bench) + * @file lib_opencl_common.cpp (./relu_bench) * @brief Common OpenCL platform initialization, device setup, * profiling timer evaluation, and generic cleanup routines. * @paragraph License diff --git a/gpu4s_benchmark/softmax_bench/CMakeLists.txt b/gpu4s_benchmark/softmax_bench/CMakeLists.txt index a5e1ddf6..2be96c19 100644 --- a/gpu4s_benchmark/softmax_bench/CMakeLists.txt +++ b/gpu4s_benchmark/softmax_bench/CMakeLists.txt @@ -39,7 +39,7 @@ if(ANDROID) compile_target(${PROJECT_NAME}_opencl BENCH_DIR ${CMAKE_SOURCE_DIR} SOURCES_FILES opencl/lib_opencl.cpp - opencl/opencl_common.cpp + opencl/lib_opencl_common.cpp COMPILE_DEFS OPENCL CL_HPP_TARGET_OPENCL_VERSION=${OPENCL_VERSION} @@ -52,7 +52,7 @@ if(ANDROID) compile_target(${PROJECT_NAME}_opencl_opt BENCH_DIR ${CMAKE_SOURCE_DIR} SOURCES_FILES opencl/lib_opencl_opt.cpp - opencl/opencl_common.cpp + opencl/lib_opencl_common.cpp COMPILE_DEFS OPENCL CL_HPP_TARGET_OPENCL_VERSION=${OPENCL_VERSION} @@ -65,7 +65,7 @@ if(ANDROID) compile_target(${PROJECT_NAME}_opencl_lib BENCH_DIR ${CMAKE_SOURCE_DIR} SOURCES_FILES opencl/lib_opencl_lib.cpp - opencl/opencl_common.cpp + opencl/lib_opencl_common.cpp COMPILE_DEFS OPENCL CL_HPP_TARGET_OPENCL_VERSION=${OPENCL_VERSION} @@ -117,7 +117,7 @@ if(NOT ANDROID) compile_target(${PROJECT_NAME}_opencl BENCH_DIR ${CMAKE_SOURCE_DIR} SOURCES_FILES opencl/lib_opencl.cpp - opencl/opencl_common.cpp + opencl/lib_opencl_common.cpp COMPILE_DEFS OPENCL CL_HPP_TARGET_OPENCL_VERSION=${OPENCL_VERSION} @@ -130,7 +130,7 @@ if(NOT ANDROID) compile_target(${PROJECT_NAME}_opencl_opt BENCH_DIR ${CMAKE_SOURCE_DIR} SOURCES_FILES opencl/lib_opencl_opt.cpp - opencl/opencl_common.cpp + opencl/lib_opencl_common.cpp COMPILE_DEFS OPENCL CL_HPP_TARGET_OPENCL_VERSION=${OPENCL_VERSION} @@ -143,7 +143,7 @@ if(NOT ANDROID) compile_target(${PROJECT_NAME}_opencl_lib BENCH_DIR ${CMAKE_SOURCE_DIR} SOURCES_FILES opencl/lib_opencl_lib.cpp - opencl/opencl_common.cpp + opencl/lib_opencl_common.cpp COMPILE_DEFS OPENCL CL_HPP_TARGET_OPENCL_VERSION=${OPENCL_VERSION} diff --git a/gpu4s_benchmark/softmax_bench/cpu_functions/cpu_functions.h b/gpu4s_benchmark/softmax_bench/cpu_functions/cpu_functions.h index 85e87a1a..456535ab 100644 --- a/gpu4s_benchmark/softmax_bench/cpu_functions/cpu_functions.h +++ b/gpu4s_benchmark/softmax_bench/cpu_functions/cpu_functions.h @@ -58,6 +58,7 @@ struct BenchmarkParameters{ bool mute_messages = false; bool csv_format_timestamp = false; bool profiling_clock = false; + bool unified_memory = false; char input_file_A[100] = ""; char input_file_B[100] = ""; }; diff --git a/gpu4s_benchmark/softmax_bench/main.cpp b/gpu4s_benchmark/softmax_bench/main.cpp index a9da02fe..ed4c3182 100644 --- a/gpu4s_benchmark/softmax_bench/main.cpp +++ b/gpu4s_benchmark/softmax_bench/main.cpp @@ -115,7 +115,7 @@ int main(int argc, char *argv[]){ softmax_bench->profiling_clock = arguments_parameters->profiling_clock; // If android and opencl force profiling clock - #ifdef PROFILING_CLOCK + #ifdef FORCE_PROFILING_CLOCK softmax_bench->profiling_clock = true; #endif @@ -236,7 +236,8 @@ void print_usage(const char * appName) printf(" -i: pass input data and the result and compares\n"); printf(" -d: selects GPU\n"); printf(" -h: print help information\n"); - printf(" -p: clock profilling \n"); + printf(" -p: clock profilling\n"); + printf(" -u: enable unified memory (ANDROID/JETSON)\n"); } void init_arguments(BenchmarkParameters* arguments_parameters){ @@ -251,7 +252,14 @@ void init_arguments(BenchmarkParameters* arguments_parameters){ arguments_parameters->csv_format = false; arguments_parameters->mute_messages = false; arguments_parameters->csv_format_timestamp = false; - arguments_parameters->profiling_clock = false; + arguments_parameters->unified_memory = false; + + // If android and opencl force profiling clock + #ifdef FORCE_PROFILING_CLOCK + arguments_parameters->profiling_clock = true; + #else + arguments_parameters->profiling_clock = false; + #endif } @@ -284,6 +292,7 @@ int arguments_handler(int argc, char ** argv, BenchmarkParameters* arguments_par break; case 's' : args +=1; arguments_parameters->size = atoi(argv[args]);break; case 'p' : arguments_parameters->profiling_clock = true;break; + case 'u' : arguments_parameters->unified_memory = true;break; default: print_usage(argv[0]); return ERROR_ARGUMENTS; } diff --git a/gpu4s_benchmark/softmax_bench/opencl/opencl_common.cpp b/gpu4s_benchmark/softmax_bench/opencl/lib_opencl_common.cpp similarity index 99% rename from gpu4s_benchmark/softmax_bench/opencl/opencl_common.cpp rename to gpu4s_benchmark/softmax_bench/opencl/lib_opencl_common.cpp index 79e07fee..764b1394 100644 --- a/gpu4s_benchmark/softmax_bench/opencl/opencl_common.cpp +++ b/gpu4s_benchmark/softmax_bench/opencl/lib_opencl_common.cpp @@ -1,5 +1,5 @@ /** * ==================================================================== - * @file opencl_common.cpp (./softmax_bench) + * @file lib_opencl_common.cpp (./softmax_bench) * @brief Common OpenCL platform initialization, device setup, * profiling timer evaluation, and generic cleanup routines. * @paragraph License diff --git a/gpu4s_benchmark/wavelet_transform/cpu_functions/cpu_functions.h b/gpu4s_benchmark/wavelet_transform/cpu_functions/cpu_functions.h index 694d6fc3..1e82c7a7 100644 --- a/gpu4s_benchmark/wavelet_transform/cpu_functions/cpu_functions.h +++ b/gpu4s_benchmark/wavelet_transform/cpu_functions/cpu_functions.h @@ -62,6 +62,7 @@ struct BenchmarkParameters{ bool mute_messages = false; bool csv_format_timestamp = false; bool profiling_clock = false; + bool unified_memory = false; char input_file_A[100] = ""; char input_file_B[100] = ""; }; diff --git a/gpu4s_benchmark/wavelet_transform/main.cpp b/gpu4s_benchmark/wavelet_transform/main.cpp index eb0766a7..1c043f7f 100644 --- a/gpu4s_benchmark/wavelet_transform/main.cpp +++ b/gpu4s_benchmark/wavelet_transform/main.cpp @@ -115,7 +115,7 @@ int main(int argc, char *argv[]){ wavelet_bench->profiling_clock = arguments_parameters->profiling_clock; // If android and opencl force profiling clock - #ifdef PROFILING_CLOCK + #ifdef FORCE_PROFILING_CLOCK wavelet_bench->profiling_clock = true; #endif @@ -223,7 +223,8 @@ void print_usage(const char * appName) printf(" -d: selects GPU\n"); printf(" -f: mutes all print\n"); printf(" -h: print help information\n"); - printf(" -p: clock profilling \n"); + printf(" -p: clock profilling\n"); + printf(" -u: enable unified memory (ANDROID/JETSON)\n"); } void init_arguments(BenchmarkParameters* arguments_parameters){ @@ -238,7 +239,14 @@ void init_arguments(BenchmarkParameters* arguments_parameters){ arguments_parameters->csv_format = false; arguments_parameters->mute_messages = false; arguments_parameters->csv_format_timestamp = false; - arguments_parameters->profiling_clock = false; + arguments_parameters->unified_memory = false; + + // If android and opencl force profiling clock + #ifdef FORCE_PROFILING_CLOCK + arguments_parameters->profiling_clock = true; + #else + arguments_parameters->profiling_clock = false; + #endif } int arguments_handler(int argc, char ** argv, BenchmarkParameters* arguments_parameters){ @@ -270,6 +278,7 @@ int arguments_handler(int argc, char ** argv, BenchmarkParameters* arguments_par break; case 's' : args +=1; arguments_parameters->size = atoi(argv[args]);break; case 'p' : arguments_parameters->profiling_clock = true;break; + case 'u' : arguments_parameters->unified_memory = true;break; default: print_usage(argv[0]); return ERROR_ARGUMENTS; } From 6de109db11a3a785deab059849c6798a5b244a9c Mon Sep 17 00:00:00 2001 From: Noah Perret Date: Tue, 11 Aug 2026 18:04:33 +0200 Subject: [PATCH 03/27] refactor main for relu + create a common for opencl UMA --- gpu4s_benchmark/common/benchmark_common.h | 2 +- gpu4s_benchmark/common/opencl_common.hpp | 109 +++++++++++++++- .../opencl/lib_opencl_common.cpp | 122 +++++------------- gpu4s_benchmark/relu_bench/main.cpp | 10 +- .../relu_bench/opencl/lib_opencl_common.cpp | 94 +++++--------- 5 files changed, 181 insertions(+), 156 deletions(-) diff --git a/gpu4s_benchmark/common/benchmark_common.h b/gpu4s_benchmark/common/benchmark_common.h index 43681a40..fdd28059 100644 --- a/gpu4s_benchmark/common/benchmark_common.h +++ b/gpu4s_benchmark/common/benchmark_common.h @@ -170,5 +170,5 @@ void clean(GraficCommon *device_object); // --- 3 buffer --- void get_unified_memory_pointers(GraficCommon* device_object, bench_t* &A, bench_t* &B, bench_t* &C, unsigned int memSize); void sync_unified_memory_to_device(GraficCommon* device_object, bench_t* &A, bench_t* &B, bench_t* &C); - void sync_unified_memory_to_host(GraficCommon* device_object, bench_t* &d_C, unsigned int buff_size); + void sync_unified_memory_to_host(GraficCommon* device_object, bench_t* &d_output, unsigned int memSize); #endif \ No newline at end of file diff --git a/gpu4s_benchmark/common/opencl_common.hpp b/gpu4s_benchmark/common/opencl_common.hpp index cd5dd82e..91bf07d5 100644 --- a/gpu4s_benchmark/common/opencl_common.hpp +++ b/gpu4s_benchmark/common/opencl_common.hpp @@ -5,4 +5,111 @@ * @paragraph License * ESA-PL Strong Copyleft – v2.5 * ======================================================================= */ -#pragma once \ No newline at end of file +#pragma once +#include "benchmark_common.h" + +// ============ global opencl function ============ +// nothing for now + + + +#ifdef UMA_COMPATIBILITY +// ============ UMA struct ============ + +/** + * @brief Encapsulates a mapping association between a host pointer address, + * an OpenCL device buffer, and an event handle. + * + */ +struct BufferMapCL { + bench_t** hostBuffer; /**< Pointer to the host-side memory pointer address */ + cl::Buffer* deviceBuffer; /**< Pointer to the OpenCL device buffer object */ + cl::Event* deviceEvent; /**< Pointer to the OpenCL device event object used for profiling timing */ +}; + +// ============ UMA function ============ + +/** + * @brief Maps device memory buffers into the host's virtual address space, + * granting the CPU direct write access to the shared memory. + * + * @tparam MapCL + * @param device_object + * @param memSize + * @param mapCL + */ +template +inline void map_unified_memory(GraficCommon* device_object, unsigned memSize, MapCL... mapCL) { + GraficObject* deviceObj = static_cast(device_object); + Clock mapCLK; + mapCLK.start(); + + // --- C++17 Fold Expression Unrolled at compile-time --- + // For each MapCL map host buffer to devcie buffer + ((*(mapCL.hostBuffer) = static_cast( + deviceObj->queue->enqueueMapBuffer( + *(mapCL.deviceBuffer), CL_TRUE, CL_MAP_WRITE, 0, memSize, nullptr, mapCL.deviceEvent) + )), ...); + + // equivalent but less optimized + // for (const auto& item : { mapCL... }) { + // *(item.host_buffer) = static_cast( + // deviceObj->queue->enqueueMapBuffer(*(item.device_clBuffer), CL_TRUE, CL_MAP_WRITE, 0, memSize) + // ); + // } + + mapCLK.end(); + deviceObj->h2d_elapsed_time = mapCLK.getElapsedNS(); +} + +/** + * @brief Give CPU control of the shared memory back to the GPU, + * ensuring the device has exclusive access to the buffers + * + * @tparam MapCL + * @param device_object + * @param mapCL + */ +template +inline void unmap_unified_memory(GraficCommon* device_object, MapCL... mapCL) { + GraficObject* deviceObj = static_cast(device_object); + Clock unmapCLK; + unmapCLK.start(); + + // --- C++17 Fold Expression Unrolled at compile-time --- + // For each MapCL unmap host buffer to devcie buffer + ((deviceObj->queue->enqueueUnmapMemObject( + *(mapCL.deviceBuffer), mapCL.hostBuffer, NULL, mapCL.deviceEvent) + ), ...); + + unmapCLK.end(); + deviceObj->d2h_elapsed_time = unmapCLK.getElapsedNS(); +} + +/** + * @brief Synchronizes the output memory back to the host, + * give CPU direct access to the GPU's results. + * + * @tparam device_object + * @param d_C + * @param buff_size + */ +template +inline void map_unified_memory_to_host(GraficCommon* device_object, unsigned memSize, MapCL... mapCL) { + GraficObject* deviceObj = static_cast(device_object); + Clock mapCLK; + mapCLK.start(); + + // --- C++17 Fold Expression Unrolled at compile-time --- + // For each MapCL map host buffer to devcie buffer + ((*(mapCL.hostBuffer) = static_cast( + deviceObj->queue->enqueueMapBuffer( + *(mapCL.deviceBuffer), CL_TRUE, CL_MAP_WRITE, 0, memSize, nullptr, mapCL.deviceEvent) + )), ...); + + mapCLK.end(); + deviceObj->d2h_elapsed_time += mapCLK.getElapsedNS(); +} +#endif + + diff --git a/gpu4s_benchmark/matrix_multiplication_bench/opencl/lib_opencl_common.cpp b/gpu4s_benchmark/matrix_multiplication_bench/opencl/lib_opencl_common.cpp index d806e03d..a8902dbb 100644 --- a/gpu4s_benchmark/matrix_multiplication_bench/opencl/lib_opencl_common.cpp +++ b/gpu4s_benchmark/matrix_multiplication_bench/opencl/lib_opencl_common.cpp @@ -6,7 +6,7 @@ * ESA-PL Strong Copyleft – v2.5 * ======================================================================= */ #include "../benchmark_library.h" -#include "../cpu_functions/cpu_functions.h" +#include "../../common/opencl_common.hpp" #include void init(GraficCommon* device_object, char* device_name){ @@ -65,7 +65,6 @@ bool device_memory_init(GraficCommon* device_object, unsigned int size_a_matrix, } - void copy_memory_to_device(GraficCommon* device_object, bench_t* h_A, bench_t* h_B, unsigned int size_a, unsigned int size_b){ GraficObject* deviceObj = static_cast(device_object); // host -> device @@ -96,66 +95,6 @@ void copy_memory_to_device(GraficCommon* device_object, bench_t* h_A, bench_t* h deviceObj->h2d_elapsed_time = h2dCLK.getElapsedNS(); } - -/** - * @brief Maps device memory buffers into the host's virtual address space, - * granting the CPU direct write access to the shared memory. - * - * @param device_object - * @param A - * @param B - * @param C - * @param memSize - */ -void get_unified_memory_pointers(GraficCommon* device_object, bench_t* &A, bench_t* &B, bench_t* &C, unsigned int memSize){ - GraficObject* deviceObj = static_cast(device_object); - Clock mapCLK; - - mapCLK.start(); - - //--- Allocate and check space of pointer for graphic card --- - A = (bench_t*)deviceObj->queue->enqueueMapBuffer( - *deviceObj->d_A, CL_TRUE, CL_MAP_WRITE, 0, memSize); - B = (bench_t*)deviceObj->queue->enqueueMapBuffer( - *deviceObj->d_B, CL_TRUE, CL_MAP_WRITE, 0, memSize); - C = (bench_t*)deviceObj->queue->enqueueMapBuffer( - *deviceObj->d_C, CL_TRUE, CL_MAP_WRITE, 0, memSize); - - mapCLK.end(); - - deviceObj->h2d_elapsed_time = mapCLK.getElapsedNS(); -} - -/** - * @brief Give CPU control of the shared memory back to the GPU, - * ensuring the device has exclusive access to the buffers - * - * @param device_object - * @param A - * @param B - * @param C - */ -void sync_unified_memory_to_device(GraficCommon* device_object, bench_t* &A, bench_t* &B, bench_t* &C){ - GraficObject* deviceObj = static_cast(device_object); - Clock mapCLK; - - mapCLK.start(); - - // --- Unmap the buffers for GPU kernel --- - deviceObj->queue->enqueueUnmapMemObject( - *deviceObj->d_A, A, NULL, deviceObj->evt_copyA); - deviceObj->queue->enqueueUnmapMemObject( - *deviceObj->d_B, B, NULL, deviceObj->evt_copyB); - deviceObj->queue->enqueueUnmapMemObject( - *deviceObj->d_C, C, NULL, deviceObj->evt_copyC); - - mapCLK.end(); - - deviceObj->h2d_elapsed_time += mapCLK.getElapsedNS(); -} - - - void copy_memory_to_host(GraficCommon* device_object, bench_t* h_C, int size){ GraficObject* deviceObj = static_cast(device_object); // device -> host @@ -178,32 +117,6 @@ void copy_memory_to_host(GraficCommon* device_object, bench_t* h_C, int size){ deviceObj->d2h_elapsed_time = d2hCLK.getElapsedNS(); } -/** -* @brief Synchronizes the output memory back to the host, -* give CPU direct access to the GPU's results. - * - * @param device_object - * @param d_C - * @param buff_size - */ -void sync_unified_memory_to_host(GraficCommon* device_object, bench_t* &d_C, unsigned int buff_size){ - GraficObject* deviceObj = static_cast(device_object); - Clock d2hCLK; - - d2hCLK.start(); - // Map the output buffer to d_C pointer - d_C = (bench_t*)deviceObj->queue->enqueueMapBuffer( - *deviceObj->d_C, CL_TRUE, CL_MAP_READ, 0, buff_size, NULL, deviceObj->evt_copyC); - - - deviceObj->queue->finish(); - d2hCLK.end(); - - // store the hd2h time - deviceObj->d2h_elapsed_time = d2hCLK.getElapsedNS(); -} - - float get_elapsed_time(GraficCommon* device_object, bool csv_format, bool csv_format_timestamp, long int current_time){ GraficObject* deviceObj = static_cast(device_object); deviceObj->evt_copyC->wait(); // wait @@ -257,3 +170,36 @@ void clean(GraficCommon* device_object){ delete deviceObj->evt_copyB; delete deviceObj->evt_copyC; } + +#ifdef UMA_COMPATIBILITY +// ====== UMA function ====== +void get_unified_memory_pointers(GraficCommon* device_object, bench_t* &A, bench_t* &B, bench_t* &C, unsigned int memSize){ + GraficObject* deviceObj = static_cast(device_object); + // --- Call the openCL common function --- + map_unified_memory(device_object, memSize, + BufferMapCL{&A, deviceObj->d_A, nullptr}, + BufferMapCL{&B, deviceObj->d_B, nullptr}, + BufferMapCL{&C, deviceObj->d_C, nullptr} + ); +} + +void sync_unified_memory_to_device(GraficCommon* device_object, bench_t* &A, bench_t* &B, bench_t* &C){ + GraficObject* deviceObj = static_cast(device_object); + // --- Call the openCL common function --- + unmap_unified_memory(device_object, + BufferMapCL{&A, deviceObj->d_A, deviceObj->evt_copyA}, + BufferMapCL{&B, deviceObj->d_B, deviceObj->evt_copyB}, + BufferMapCL{&C, deviceObj->d_C, nullptr} + ); +} + + +void sync_unified_memory_to_host(GraficCommon* device_object, bench_t* &d_output, unsigned int memSize){ + GraficObject* deviceObj = static_cast(device_object); + // --- Call the openCL common function --- + map_unified_memory_to_host(device_object, memSize, + BufferMapCL{&d_output, deviceObj->d_C, deviceObj->evt_copyC} + ); +} + +#endif \ No newline at end of file diff --git a/gpu4s_benchmark/relu_bench/main.cpp b/gpu4s_benchmark/relu_bench/main.cpp index c65b3c0e..2fd019b5 100644 --- a/gpu4s_benchmark/relu_bench/main.cpp +++ b/gpu4s_benchmark/relu_bench/main.cpp @@ -37,8 +37,8 @@ int main(int argc, char *argv[]){ // A input matrix bench_t* A = NULL; // B input matrix - bench_t* h_B = NULL; - bench_t* d_B = (bench_t*) malloc(mem_size); + bench_t* d_B = NULL; + bench_t* h_B = (bench_t*) malloc(mem_size); // init devices char device[100] = ""; @@ -67,7 +67,7 @@ int main(int argc, char *argv[]){ { // normale malloc A = (bench_t*) malloc(mem_size); - h_B = (bench_t*) malloc(mem_size); + d_B = (bench_t*) malloc(mem_size); } /////////////////////////////////////////////////////////////////////////////////////////////// @@ -239,10 +239,10 @@ int main(int argc, char *argv[]){ if (!arguments_parameters->unified_memory) { free(A); - free(h_B); + free(d_B); } - free(d_B); + free(h_B); return 0; } diff --git a/gpu4s_benchmark/relu_bench/opencl/lib_opencl_common.cpp b/gpu4s_benchmark/relu_bench/opencl/lib_opencl_common.cpp index c3e04dca..76d0b94d 100644 --- a/gpu4s_benchmark/relu_bench/opencl/lib_opencl_common.cpp +++ b/gpu4s_benchmark/relu_bench/opencl/lib_opencl_common.cpp @@ -6,6 +6,8 @@ * ESA-PL Strong Copyleft – v2.5 * ======================================================================= */ #include "../benchmark_library.h" +#include "../../common/opencl_common.hpp" + void init(GraficCommon* device_object, char* device_name){ init(device_object, 0,0, device_name); @@ -80,54 +82,6 @@ void copy_memory_to_device(GraficCommon* device_object, bench_t* h_A, unsigned i deviceObj->h2d_elapsed_time = h2dCLK.getElapsedNS(); } -#ifdef UNIFIED_MEMORY -void device_unified_memory_init_copy(GraficCommon* device_object, bench_t* &A, bench_t* &B, unsigned int buff_size, char input_file_A[100],char input_file_B[100]){ - GraficObject* deviceObj = static_cast(device_object); - unsigned int squared_buff_size = buff_size * buff_size; - unsigned int mem_size = squared_buff_size * sizeof(bench_t); - - h2dCLK.start(); - //--- Aquire the pointer of buffer from graphic card --- - A = (bench_t*)deviceObj->queue->enqueueMapBuffer( - *deviceObj->d_A, CL_TRUE, CL_MAP_WRITE, 0, mem_size); - B = (bench_t*)deviceObj->queue->enqueueMapBuffer( - *deviceObj->d_B, CL_TRUE, CL_MAP_WRITE, 0, mem_size); - h2dCLK.end(); - - h2dTotal += h2dCLK.getElapsedNS(); - - if (strlen(input_file_A) == 0) - { - - // --- Initialize the buffer --- - for (int i = 0; i < buff_size; i++) - for (int j = 0; j < buff_size; j++) - A[i*buff_size+j] = (bench_t)rand()/(bench_t)(RAND_MAX*2.0-1.0); - - for (int i = 0; i < buff_size; i++) - for (int j = 0; j < buff_size; j++) - B[i*buff_size+j] = 0; - - } else - { - get_double_hexadecimal_values(input_file_A, A,mem_size); - get_double_hexadecimal_values(input_file_B, B,mem_size); - } - - - h2dCLK.start(); - // --- Unmap the buffers for GPU kernel --- - deviceObj->queue->enqueueUnmapMemObject(*deviceObj->d_A, A, NULL, deviceObj->evt_copyA); - deviceObj->queue->enqueueUnmapMemObject(*deviceObj->d_B, B, NULL, deviceObj->evt_copyB); - - - deviceObj->queue->finish(); - h2dCLK.end(); - - h2dTotal += h2dCLK.getElapsedNS(); -} -#endif - void copy_memory_to_host(GraficCommon* device_object, bench_t* h_C, int size){ GraficObject* deviceObj = static_cast(device_object); @@ -151,19 +105,6 @@ void copy_memory_to_host(GraficCommon* device_object, bench_t* h_C, int size){ deviceObj->d2h_elapsed_time = d2hCLK.getElapsedNS(); } -#ifdef UNIFIED_MEMORY - void copy_memory_unified_to_host(GraficCommon* device_object, bench_t* &d_B, unsigned int buff_size){ - GraficObject* deviceObj = static_cast(device_object); - - d2hCLK.start(); - // Map the output buffer to d_C pointer - d_B = (bench_t*)deviceObj->queue->enqueueMapBuffer(*deviceObj->d_B, CL_TRUE, CL_MAP_READ, 0, buff_size, NULL, deviceObj->evt_copyB); - - - deviceObj->queue->finish(); - d2hCLK.end(); - } -#endif float get_elapsed_time(GraficCommon* device_object, bool csv_format, bool csv_format_timestamp, long int current_time){ GraficObject* deviceObj = static_cast(device_object); @@ -219,3 +160,34 @@ void clean(GraficCommon* device_object){ delete deviceObj->evt_copyA; delete deviceObj->evt_copyB; } + +#ifdef UMA_COMPATIBILITY +// ====== UMA function ====== +void get_unified_memory_pointers(GraficCommon* device_object, bench_t* &A, bench_t* &B, unsigned int memSize){ + GraficObject* deviceObj = static_cast(device_object); + // --- Call the openCL common function --- + map_unified_memory(device_object, memSize, + BufferMapCL{&A, deviceObj->d_A, nullptr}, + BufferMapCL{&B, deviceObj->d_B, nullptr} + ); +} + +void sync_unified_memory_to_device(GraficCommon* device_object, bench_t* &A, bench_t* &B){ + GraficObject* deviceObj = static_cast(device_object); + // --- Call the openCL common function --- + unmap_unified_memory(device_object, + BufferMapCL{&A, deviceObj->d_A, deviceObj->evt_copyA}, + BufferMapCL{&B, deviceObj->d_B, nullptr} + ); +} + + +void sync_unified_memory_to_host(GraficCommon* device_object, bench_t* &d_output, unsigned int memSize){ + GraficObject* deviceObj = static_cast(device_object); + // --- Call the openCL common function --- + map_unified_memory_to_host(device_object, memSize, + BufferMapCL{&d_output, deviceObj->d_B, deviceObj->evt_copyB} + ); +} + +#endif From 06db52b99410f1e1f0fe4392dfd40b4f99cc5b97 Mon Sep 17 00:00:00 2001 From: Noah Perret Date: Wed, 12 Aug 2026 13:26:15 +0200 Subject: [PATCH 04/27] add cl check for unmap and map fucntion --- doc.md | 10 +- gpu4s_benchmark/cifar_10/benchmark_library.h | 5 + gpu4s_benchmark/cifar_10/main.cpp | 199 +++++++++++------- .../cifar_10/opencl/lib_opencl_common.cpp | 48 ++++- .../cifar_10_multiple/benchmark_library.h | 6 + gpu4s_benchmark/cifar_10_multiple/main.cpp | 193 ++++++++++------- .../opencl/lib_opencl_common.cpp | 49 ++++- gpu4s_benchmark/common/opencl_common.hpp | 78 +++++-- .../matrix_multiplication_bench/main.cpp | 4 +- 9 files changed, 414 insertions(+), 178 deletions(-) diff --git a/doc.md b/doc.md index a838291b..5ff8dab2 100644 --- a/doc.md +++ b/doc.md @@ -278,6 +278,15 @@ cmake -B build-android \ -DANDROID_ABI=arm64-v8a \ -DANDROID_PLATFORM=android-21 +cmake --build build-android + +adb push ./build-android/bin/* /data/local/tmp/ +adb shell chmod 755 /data/local/tmp/* + + +./data/local/tmp/ + + cmake --build build-android --target cpu cmake --build build-android --target openmp openmp-opt cl opencl-opt ``` @@ -288,7 +297,6 @@ cmake --build build-android --target openmp openmp-opt cl opencl-opt adb push ./build-android/bin/* /data/local/tmp/ adb shell chmod 755 /data/local/tmp/* adb shell /data/local/tmp/matrix_mult_opencl -s 1024 -t -v -./data/local/tmp/ ``` i=1; while [ "$i" -le 100 ]; do ./data/local/tmp/matrix_mult_opencl_opt -s 512 -c >> /data/local/tmp/results_512.csv; i=$((i + 1)); done; echo "Done!" diff --git a/gpu4s_benchmark/cifar_10/benchmark_library.h b/gpu4s_benchmark/cifar_10/benchmark_library.h index f3a1c583..488fd76d 100644 --- a/gpu4s_benchmark/cifar_10/benchmark_library.h +++ b/gpu4s_benchmark/cifar_10/benchmark_library.h @@ -119,3 +119,8 @@ struct GraficObject : public GraficCommon { bool device_memory_init(GraficCommon* device_object, unsigned int input_data, unsigned int output_data, unsigned int kernel_1, unsigned int kernel_2, unsigned int stride_1, unsigned int stride_2, unsigned int neurons_dense_1, unsigned int neurons_dense_2); void copy_memory_to_device(GraficCommon* device_object, bench_t* input_data, bench_t* kernel_1_data, bench_t* kernel_2_data, bench_t* weights_1 ,bench_t* weights_2,unsigned int input , unsigned int kernel_size_1, unsigned int kernel_size_2, unsigned int weights_1_size, unsigned int weights_2_size); void execute_kernel(GraficCommon* device_object, unsigned int input_data, unsigned int output_data, unsigned int kernel_1, unsigned int kernel_2, unsigned int stride_1, unsigned int stride_2, unsigned int neurons_dense_1, unsigned int neurons_dense_2); + +#ifdef UMA_COMPATIBILITY +void get_unified_memory_pointers(GraficCommon* device_object,bench_t* &input_data, unsigned int input_mem_size,bench_t* &kernel_1, bench_t* &kernel_2, unsigned int kernel_mem_size, bench_t* &weights_1, unsigned int weights_1_mem_size, bench_t* &weights_2, unsigned int weights_2_mem_size, bench_t* &d_output, unsigned int output_mem_size); +void sync_unified_memory_to_device(GraficCommon* device_object, bench_t* &input_data, bench_t* &kernel_1, bench_t* &kernel_2, bench_t* &weights_1, bench_t* &weights_2, bench_t* &d_output); +#endif \ No newline at end of file diff --git a/gpu4s_benchmark/cifar_10/main.cpp b/gpu4s_benchmark/cifar_10/main.cpp index 727b5469..95b8f602 100644 --- a/gpu4s_benchmark/cifar_10/main.cpp +++ b/gpu4s_benchmark/cifar_10/main.cpp @@ -28,7 +28,6 @@ bench_t RandomNumber(); int main(int argc, char *argv[]){ // random init - //srand (time(NULL)); srand (21121993); /////////////////////////////////////////////////////////////////////////////////////////////// // Arguments @@ -43,32 +42,33 @@ int main(int argc, char *argv[]){ // VARIABLES /////////////////////////////////////////////////////////////////////////////////////////////// // linearizable versions of matrix - unsigned int size_matrix =CIFAR_10_INPUT * CIFAR_10_INPUT; + unsigned int size_matrix = CIFAR_10_INPUT * CIFAR_10_INPUT; // A input matrix unsigned int size_A = CIFAR_10_INPUT * CIFAR_10_INPUT; unsigned int mem_size_A = sizeof(bench_t) * size_A; - bench_t* input_data = (bench_t*) malloc(mem_size_A); + bench_t* input_data = NULL; // B output matrix unsigned int size_B = CIFAR_10_INPUT * CIFAR_10_INPUT; unsigned int mem_size_B = sizeof(bench_t) * size_B; - bench_t* d_output = (bench_t*) malloc(mem_size_B); + bench_t* d_output = NULL; // kernel matrix 1 unsigned int size_k_1 = KERNEL_CON_1 * KERNEL_CON_2; unsigned int mem_size_k_1 = sizeof(bench_t) * size_k_1; - bench_t* kernel_1 = (bench_t*) malloc(mem_size_k_1); + bench_t* kernel_1 = NULL; // kernel matrix 2 unsigned int size_k_2 = KERNEL_CON_2 * KERNEL_CON_2; unsigned int mem_size_k_2 = sizeof(bench_t) * size_k_2; - bench_t* kernel_2 = (bench_t*) malloc(mem_size_k_2); + bench_t* kernel_2 = NULL; // weights 1 unsigned int size_w_1 = DENSE_1 * (((CIFAR_10_INPUT / STRIDE_1)/STRIDE_2)*((CIFAR_10_INPUT / STRIDE_1)/STRIDE_2)); unsigned int mem_size_w_1 = sizeof(bench_t) * size_w_1; - bench_t* weights_1 = (bench_t*) malloc(mem_size_w_1); + bench_t* weights_1 = NULL; // weights 1 unsigned int size_w_2 = DENSE_1 * DENSE_2; unsigned int mem_size_w_2 = sizeof(bench_t) * size_w_2; - bench_t* weights_2 = (bench_t*) malloc(mem_size_w_2); + bench_t* weights_2 = NULL; // Outputs + unsigned int mem_size_output = sizeof(bench_t) * CIFAR_10_OUTPUT; const unsigned int size_pooling_1 = CIFAR_10_INPUT / STRIDE_1; const unsigned int size_pooling_2 = size_pooling_1 / STRIDE_2; bench_t* conv_1_output = (bench_t*) malloc ( CIFAR_10_INPUT * CIFAR_10_INPUT * sizeof(bench_t*)); @@ -78,9 +78,48 @@ int main(int argc, char *argv[]){ bench_t* dense_layer_1_output = (bench_t*) malloc ( DENSE_1 * sizeof(bench_t)); bench_t* dense_layer_2_output = (bench_t*) malloc ( DENSE_2 * sizeof(bench_t)); bench_t* output_data = (bench_t*) malloc ( DENSE_2 * sizeof(bench_t)); + // init devices + char device[100] = ""; + + // main object init + GraficCommon*cifar10_bench = (GraficCommon*)malloc(sizeof(GraficObject)); + + // --- 1. Init Device & Context --- + init(cifar10_bench, 0, arguments_parameters->gpu, device); + + // Update profiling clock mode + cifar10_bench->profiling_clock = arguments_parameters->profiling_clock; + + // --- 2. Allocate Device Memory --- + bool mem_result = device_memory_init(cifar10_bench, CIFAR_10_INPUT, CIFAR_10_OUTPUT, KERNEL_CON_1, KERNEL_CON_2, STRIDE_1, STRIDE_2, DENSE_1, DENSE_2); + if (!mem_result) + { + printf("ERROR MEMORY INIT\n"); + exit(-1); + } + + // --- 3. Allocate Host Pointers --- + if (arguments_parameters->unified_memory) + { + #ifdef UMA_COMPATIBILITY + // map the buffzer to the gpu + cpu take the lead + get_unified_memory_pointers(cifar10_bench,input_data, mem_size_A,kernel_1, kernel_2, mem_size_k_1,weights_1, mem_size_w_1,weights_2, mem_size_w_2,d_output, mem_size_output); + #else + fprintf(stderr, "\033[1;31merror:\033[0m This framework is not compatible with unified memory. Please remove the -u arg!\n"); + exit(-1); + #endif + } else + { + // normale malloc + input_data = (bench_t*) malloc(mem_size_A); + kernel_1 = (bench_t*) malloc(mem_size_k_1); + kernel_2 = (bench_t*) malloc(mem_size_k_2); + weights_1 = (bench_t*) malloc(mem_size_w_1); + weights_2 = (bench_t*) malloc(mem_size_w_2); + d_output = (bench_t*) malloc(mem_size_B); + } + - // comparation result - bool result = false; /////////////////////////////////////////////////////////////////////////////////////////////// // DATA INIT /////////////////////////////////////////////////////////////////////////////////////////////// @@ -90,14 +129,13 @@ int main(int argc, char *argv[]){ for (int i=0; iprint_input) - { - printf("%f ", input_data[i*CIFAR_10_INPUT+j]); - } + input_data[i*CIFAR_10_INPUT+j] = (bench_t)rand()/(bench_t)(RAND_MAX/NUMBER_BASE); + if (arguments_parameters->print_input) + { + printf("%f ", input_data[i*CIFAR_10_INPUT+j]); + } #endif } @@ -107,7 +145,6 @@ int main(int argc, char *argv[]){ printf("\n"); } // reseed por compasion reasons - //srand (time(NULL)); srand (21121993); // inicialice kernel 1 for (int i=0; igpu, device); if (!arguments_parameters->csv_format_timestamp && !arguments_parameters->csv_format && !arguments_parameters->mute_messages ){ printf("Using device: %s\n", device); } - // Update profiling clock mode - cifar10_bench->profiling_clock = arguments_parameters->profiling_clock; - - // If android and opencl force profiling clock - #ifdef FORCE_PROFILING_CLOCK - cifar10_bench->profiling_clock = true; - #endif - - // init memory - bool mem_result = true; - mem_result = device_memory_init(cifar10_bench, CIFAR_10_INPUT, CIFAR_10_OUTPUT, KERNEL_CON_1, KERNEL_CON_2, STRIDE_1, STRIDE_2, DENSE_1, DENSE_2); - if (!mem_result) + // copy memory to device + if(arguments_parameters->unified_memory) { - printf("ERROR MEMORY INIT\n"); - exit(-1); + #ifdef UMA_COMPATIBILITY + sync_unified_memory_to_device(cifar10_bench, input_data, kernel_1, kernel_2, weights_1, weights_2, d_output); + #endif } - // copy memory to device - copy_memory_to_device(cifar10_bench, input_data, kernel_1, kernel_2, weights_1, weights_2, CIFAR_10_INPUT, KERNEL_CON_1, KERNEL_CON_2, size_w_1, size_w_2); + else + { + copy_memory_to_device(cifar10_bench, input_data, kernel_1, kernel_2, weights_1, weights_2, CIFAR_10_INPUT, KERNEL_CON_1, KERNEL_CON_2, size_w_1, size_w_2); + } + // execute kernel execute_kernel(cifar10_bench, CIFAR_10_INPUT, CIFAR_10_OUTPUT, KERNEL_CON_1, KERNEL_CON_2, STRIDE_1, STRIDE_2, DENSE_1, DENSE_2); + // copy memory to host - copy_memory_to_host(cifar10_bench, d_output, CIFAR_10_OUTPUT); + if (arguments_parameters->unified_memory) + { + #ifdef UMA_COMPATIBILITY + sync_unified_memory_to_host(cifar10_bench, d_output, mem_size_output); + #endif + } else + { + copy_memory_to_host(cifar10_bench, d_output, CIFAR_10_OUTPUT); + } // get time if (arguments_parameters->print_timing || arguments_parameters->csv_format || arguments_parameters->csv_format_timestamp) { get_elapsed_time(cifar10_bench, arguments_parameters->csv_format, arguments_parameters->csv_format_timestamp, get_timestamp()); } + + // print output buffer if (arguments_parameters->print_output) { #ifdef INT - for (int i=0; iexport_results_gpu) + { + print_double_hexadecimal_values(GPU_FILE, d_output, size_B); + } + + + //check for error if (arguments_parameters->verification) { Clock cpuKernelCLK; cpuKernelCLK.start(); cifar10(output_data, conv_1_output, pooling_1_output, conv_2_output, pooling_2_output, dense_layer_1_output, dense_layer_2_output, input_data, kernel_1, kernel_2, weights_1 , weights_2, CIFAR_10_INPUT, CIFAR_10_OUTPUT, KERNEL_CON_1, KERNEL_CON_2, STRIDE_1,STRIDE_2, DENSE_1, DENSE_2); cpuKernelCLK.end(); + if (arguments_parameters->print_timing) { printf("CPU Time %.0f milliseconds\n", cpuKernelCLK.getElapsedMS()); } + if (arguments_parameters->print_output) { - #ifdef INT - for (int i=0; iexport_results){ print_double_hexadecimal_values(GPU_FILE, d_output, CIFAR_10_OUTPUT); print_double_hexadecimal_values(CPU_FILE, output_data, CIFAR_10_OUTPUT); } - } - - - if (arguments_parameters->export_results_gpu) - { - print_double_hexadecimal_values(GPU_FILE, d_output, size_B); - } - /////////////////////////////////////////////////////////////////////////////////////////////// // CLEAN MEMORY /////////////////////////////////////////////////////////////////////////////////////////////// @@ -276,12 +312,17 @@ int main(int argc, char *argv[]){ // free object memory free(arguments_parameters); free(cifar10_bench); - free(input_data); - free(d_output); - free(kernel_1); - free(kernel_2); - free(weights_1); - free(weights_2); + + if (!arguments_parameters->unified_memory) + { + free(input_data); + free(d_output); + free(kernel_1); + free(kernel_2); + free(weights_1); + free(weights_2); + } + free(conv_1_output); free(pooling_1_output); free(conv_2_output); diff --git a/gpu4s_benchmark/cifar_10/opencl/lib_opencl_common.cpp b/gpu4s_benchmark/cifar_10/opencl/lib_opencl_common.cpp index de73abb3..9396d27a 100644 --- a/gpu4s_benchmark/cifar_10/opencl/lib_opencl_common.cpp +++ b/gpu4s_benchmark/cifar_10/opencl/lib_opencl_common.cpp @@ -6,6 +6,7 @@ * ESA-PL Strong Copyleft – v2.5 * ======================================================================= */ #include "../benchmark_library.h" +#include "../../common/opencl_common.hpp" #include void init(GraficCommon* device_object, char* device_name){ @@ -297,4 +298,49 @@ GraficObject* deviceObj = static_cast(device_object); delete deviceObj->dense_layer_2_output; delete deviceObj->output_data; delete deviceObj->sum_ouput; -} \ No newline at end of file +} + +#ifdef UMA_COMPATIBILITY +// ====== UMA function ====== +void get_unified_memory_pointers(GraficCommon* device_object,bench_t* &input_data, unsigned int input_mem_size,bench_t* &kernel_1, bench_t* &kernel_2, unsigned int kernel_mem_size, bench_t* &weights_1, unsigned int weights_1_mem_size, bench_t* &weights_2, unsigned int weights_2_mem_size, bench_t* &d_output, unsigned int output_mem_size){ + GraficObject* deviceObj = static_cast(device_object); + // --- Call the openCL common function --- + map_unified_memory(device_object, input_mem_size, + BufferMapCL{&input_data, deviceObj->input_data, nullptr}); + + map_unified_memory(device_object, kernel_mem_size, + BufferMapCL{&kernel_1, deviceObj->kernel_1, nullptr}, + BufferMapCL{&kernel_2, deviceObj->kernel_2, nullptr}); + + map_unified_memory(device_object, weights_1_mem_size, + BufferMapCL{&weights_1, deviceObj->dense_layer_1_weights, nullptr}); + + map_unified_memory(device_object, weights_2_mem_size, + BufferMapCL{&weights_2, deviceObj->dense_layer_2_weights, nullptr}); + + map_unified_memory(device_object, output_mem_size, + BufferMapCL{&d_output, deviceObj->output_data, nullptr}); +} + +void sync_unified_memory_to_device(GraficCommon* device_object, bench_t* &input_data, bench_t* &kernel_1, bench_t* &kernel_2, bench_t* &weights_1, bench_t* &weights_2, bench_t* &d_output){ + GraficObject* deviceObj = static_cast(device_object); + // --- Call the openCL common function --- + unmap_unified_memory(device_object, + BufferMapCL{&input_data, deviceObj->input_data, deviceObj->evt_copyIN}, + BufferMapCL{&kernel_1, deviceObj->kernel_1, deviceObj->evt_copyK1}, + BufferMapCL{&kernel_2, deviceObj->kernel_2, deviceObj->evt_copyK2}, + BufferMapCL{&weights_1, deviceObj->dense_layer_1_weights, deviceObj->evt_copyW1}, + BufferMapCL{&weights_2, deviceObj->dense_layer_2_weights, deviceObj->evt_copyW2}, + BufferMapCL{&d_output, deviceObj->output_data, nullptr} + ); +} + +void sync_unified_memory_to_host(GraficCommon* device_object, bench_t* &d_output, unsigned int memSize){ + GraficObject* deviceObj = static_cast(device_object); + // --- Call the openCL common function --- + map_unified_memory_to_host(device_object, memSize, + BufferMapCL{&d_output, deviceObj->output_data, deviceObj->evt_copyOut} + ); +} + +#endif \ No newline at end of file diff --git a/gpu4s_benchmark/cifar_10_multiple/benchmark_library.h b/gpu4s_benchmark/cifar_10_multiple/benchmark_library.h index 4716ecaa..f8e69b8f 100644 --- a/gpu4s_benchmark/cifar_10_multiple/benchmark_library.h +++ b/gpu4s_benchmark/cifar_10_multiple/benchmark_library.h @@ -118,3 +118,9 @@ bool device_memory_init(GraficCommon* device_object, unsigned int input_data, un void copy_memory_to_device(GraficCommon* device_object, bench_t* input_data, bench_t* kernel_1_data, bench_t* kernel_2_data, bench_t* weights_1 ,bench_t* weights_2,unsigned int input , unsigned int kernel_size_1, unsigned int kernel_size_2, unsigned int weights_1_size, unsigned int weights_2_size, unsigned int number_of_images); void execute_kernel(GraficCommon* device_object, unsigned int input_data, unsigned int output_data, unsigned int kernel_1, unsigned int kernel_2, unsigned int stride_1, unsigned int stride_2, unsigned int neurons_dense_1, unsigned int neurons_dense_2, unsigned int number_of_images); void copy_memory_to_host(GraficCommon* device_object, bench_t* h_C, int size, unsigned int number_of_images); + + +#ifdef UMA_COMPATIBILITY +void get_unified_memory_pointers(GraficCommon* device_object,bench_t* &input_data, unsigned int input_mem_size,bench_t* &kernel_1, bench_t* &kernel_2, unsigned int kernel_mem_size, bench_t* &weights_1, unsigned int weights_1_mem_size, bench_t* &weights_2, unsigned int weights_2_mem_size, bench_t* &d_output, unsigned int output_mem_size); +void sync_unified_memory_to_device(GraficCommon* device_object, bench_t* &input_data, bench_t* &kernel_1, bench_t* &kernel_2, bench_t* &weights_1, bench_t* &weights_2, bench_t* &d_output); +#endif \ No newline at end of file diff --git a/gpu4s_benchmark/cifar_10_multiple/main.cpp b/gpu4s_benchmark/cifar_10_multiple/main.cpp index b0b71972..6368adda 100644 --- a/gpu4s_benchmark/cifar_10_multiple/main.cpp +++ b/gpu4s_benchmark/cifar_10_multiple/main.cpp @@ -49,28 +49,29 @@ int main(int argc, char *argv[]){ // A input matrix unsigned int size_A = CIFAR_10_INPUT * CIFAR_10_INPUT * arguments_parameters->size; unsigned int mem_size_A = sizeof(bench_t) * size_A; - bench_t* input_data = (bench_t*) malloc(mem_size_A); + bench_t* input_data = NULL; // B output matrix - unsigned int size_B = CIFAR_10_OUTPUT * CIFAR_10_OUTPUT * arguments_parameters->size; + unsigned int size_B = CIFAR_10_OUTPUT * arguments_parameters->size; unsigned int mem_size_B = sizeof(bench_t) * size_B; - bench_t* d_output = (bench_t*) malloc(mem_size_B); + bench_t* d_output = NULL; // kernel matrix 1 unsigned int size_k_1 = KERNEL_CON_1 * KERNEL_CON_2; unsigned int mem_size_k_1 = sizeof(bench_t) * size_k_1; - bench_t* kernel_1 = (bench_t*) malloc(mem_size_k_1); + bench_t* kernel_1 = NULL; // kernel matrix 2 unsigned int size_k_2 = KERNEL_CON_2 * KERNEL_CON_2; unsigned int mem_size_k_2 = sizeof(bench_t) * size_k_2; - bench_t* kernel_2 = (bench_t*) malloc(mem_size_k_2); + bench_t* kernel_2 = NULL; // weights 1 unsigned int size_w_1 = DENSE_1 * (((CIFAR_10_INPUT / STRIDE_1)/STRIDE_2)*((CIFAR_10_INPUT / STRIDE_1)/STRIDE_2)); unsigned int mem_size_w_1 = sizeof(bench_t) * size_w_1; - bench_t* weights_1 = (bench_t*) malloc(mem_size_w_1); + bench_t* weights_1 = NULL; // weights 1 unsigned int size_w_2 = DENSE_1 * DENSE_2; unsigned int mem_size_w_2 = sizeof(bench_t) * size_w_2; - bench_t* weights_2 = (bench_t*) malloc(mem_size_w_2); + bench_t* weights_2 = NULL; // Outputs + unsigned int mem_size_output = sizeof(bench_t) * CIFAR_10_OUTPUT * arguments_parameters->size; const unsigned int size_pooling_1 = CIFAR_10_INPUT / STRIDE_1; const unsigned int size_pooling_2 = size_pooling_1 / STRIDE_2; bench_t* conv_1_output = (bench_t*) malloc ( CIFAR_10_INPUT * CIFAR_10_INPUT * sizeof(bench_t*)); @@ -80,9 +81,48 @@ int main(int argc, char *argv[]){ bench_t* dense_layer_1_output = (bench_t*) malloc ( DENSE_1 * sizeof(bench_t)); bench_t* dense_layer_2_output = (bench_t*) malloc ( DENSE_2 * sizeof(bench_t)); bench_t* output_data = (bench_t*) malloc ( DENSE_2 * sizeof(bench_t) * arguments_parameters->size); + // init devices + char device[100] = ""; + + // main object init + GraficCommon*cifar10_bench = (GraficCommon*)malloc(sizeof(GraficObject)); - // comparation result - bool result = false; + // --- 1. Init Device & Context --- + init(cifar10_bench, 0, arguments_parameters->gpu, device); + + // Update profiling clock mode + cifar10_bench->profiling_clock = arguments_parameters->profiling_clock; + + // --- 2. Allocate Device Memory --- + bool mem_result = device_memory_init(cifar10_bench, CIFAR_10_INPUT, CIFAR_10_OUTPUT, KERNEL_CON_1, KERNEL_CON_2, STRIDE_1, STRIDE_2, DENSE_1, DENSE_2, arguments_parameters->size); + if (!mem_result) + { + printf("ERROR MEMORY INIT\n"); + exit(-1); + } + + // --- 3. Allocate Host Pointers --- + if (arguments_parameters->unified_memory) + { + #ifdef UMA_COMPATIBILITY + // map the buffzer to the gpu + cpu take the lead + get_unified_memory_pointers(cifar10_bench,input_data, mem_size_A,kernel_1, kernel_2, mem_size_k_1,weights_1, mem_size_w_1,weights_2, mem_size_w_2,d_output, mem_size_output); + #else + fprintf(stderr, "\033[1;31merror:\033[0m This framework is not compatible with unified memory. Please remove the -u arg!\n"); + exit(-1); + #endif + } else + { + // normale malloc + input_data = (bench_t*) malloc(mem_size_A); + kernel_1 = (bench_t*) malloc(mem_size_k_1); + kernel_2 = (bench_t*) malloc(mem_size_k_2); + weights_1 = (bench_t*) malloc(mem_size_w_1); + weights_2 = (bench_t*) malloc(mem_size_w_2); + d_output = (bench_t*) malloc(mem_size_B); + } + + /////////////////////////////////////////////////////////////////////////////////////////////// // DATA INIT /////////////////////////////////////////////////////////////////////////////////////////////// @@ -120,7 +160,6 @@ int main(int argc, char *argv[]){ printf("\n"); } // reseed por compasion reasons - //srand (time(NULL)); srand (21121993); // inicialice kernel 1 for (int i=0; igpu, device); if (!arguments_parameters->csv_format_timestamp && !arguments_parameters->csv_format && !arguments_parameters->mute_messages ){ printf("Using device: %s\n", device); } - // Update profiling clock mode - cifar10_bench->profiling_clock = arguments_parameters->profiling_clock; - // If android and opencl force profiling clock - #ifdef FORCE_PROFILING_CLOCK - cifar10_bench->profiling_clock = true; - #endif - - - // init memory - bool mem_result = true; - mem_result = device_memory_init(cifar10_bench, CIFAR_10_INPUT, CIFAR_10_OUTPUT, KERNEL_CON_1, KERNEL_CON_2, STRIDE_1, STRIDE_2, DENSE_1, DENSE_2, arguments_parameters->size); - if (!mem_result) + // copy memory to device + if(arguments_parameters->unified_memory) { - printf("ERROR MEMORY INIT\n"); - exit(-1); + #ifdef UMA_COMPATIBILITY + sync_unified_memory_to_device(cifar10_bench, input_data, kernel_1, kernel_2, weights_1, weights_2, d_output); + #endif } - // copy memory to device - copy_memory_to_device(cifar10_bench, input_data, kernel_1, kernel_2, weights_1, weights_2, CIFAR_10_INPUT, KERNEL_CON_1, KERNEL_CON_2, size_w_1, size_w_2, arguments_parameters->size); + else + { + copy_memory_to_device(cifar10_bench, input_data, kernel_1, kernel_2, weights_1, weights_2, CIFAR_10_INPUT, KERNEL_CON_1, KERNEL_CON_2, size_w_1, size_w_2, arguments_parameters->size); + } + // execute kernel execute_kernel(cifar10_bench, CIFAR_10_INPUT, CIFAR_10_OUTPUT, KERNEL_CON_1, KERNEL_CON_2, STRIDE_1, STRIDE_2, DENSE_1, DENSE_2, arguments_parameters->size); - // copy memory to host - copy_memory_to_host(cifar10_bench, d_output, CIFAR_10_OUTPUT, arguments_parameters->size); + + // copy memory to host + if (arguments_parameters->unified_memory) + { + #ifdef UMA_COMPATIBILITY + sync_unified_memory_to_host(cifar10_bench, d_output, mem_size_output); + #endif + } else + { + // copy memory to host + copy_memory_to_host(cifar10_bench, d_output, CIFAR_10_OUTPUT, arguments_parameters->size); + } + // get time if (arguments_parameters->print_timing || arguments_parameters->csv_format || arguments_parameters->csv_format_timestamp) { get_elapsed_time(cifar10_bench, arguments_parameters->csv_format, arguments_parameters->csv_format_timestamp, get_timestamp()); } + + // print output buffer if (arguments_parameters->print_output) { #ifdef INT - for (int i=0; i < arguments_parameters->size; ++i){ - for (int j=0; jsize; ++i){ + for (int j=0; jsize; ++i){ - for (int j=0; jsize; ++i){ + for (int j=0; jexport_results_gpu) + { + print_double_hexadecimal_values(GPU_FILE, d_output, size_B); } - + //check for error if (arguments_parameters->verification) { Clock cpuKernelCLK; cpuKernelCLK.start(); cifar10(output_data, conv_1_output, pooling_1_output, conv_2_output, pooling_2_output, dense_layer_1_output, dense_layer_2_output, input_data, kernel_1, kernel_2, weights_1 , weights_2, CIFAR_10_INPUT, CIFAR_10_OUTPUT, KERNEL_CON_1, KERNEL_CON_2, STRIDE_1,STRIDE_2, DENSE_1, DENSE_2, arguments_parameters->size); cpuKernelCLK.end(); + if (arguments_parameters->print_timing) { printf("CPU Time %.0f milliseconds\n", cpuKernelCLK.getElapsedMS()); } + if (arguments_parameters->print_output) { #ifdef INT - for (int i=0; i < arguments_parameters->size; ++i){ - for (int j=0; jsize; ++i){ + for (int j=0; jsize; ++i){ - for (int j=0; jsize; ++i){ + for (int j=0; jsize)){ printf("OK\n"); } + if (arguments_parameters->export_results){ - print_double_hexadecimal_values(GPU_FILE, d_output, CIFAR_10_OUTPUT); - print_double_hexadecimal_values(CPU_FILE, output_data, CIFAR_10_OUTPUT); + print_double_hexadecimal_values(GPU_FILE, d_output, CIFAR_10_OUTPUT * arguments_parameters->size); + print_double_hexadecimal_values(CPU_FILE, output_data, CIFAR_10_OUTPUT * arguments_parameters->size); } } - - - if (arguments_parameters->export_results_gpu) - { - print_double_hexadecimal_values(GPU_FILE, d_output, size_B); - } /////////////////////////////////////////////////////////////////////////////////////////////// // CLEAN MEMORY /////////////////////////////////////////////////////////////////////////////////////////////// @@ -299,12 +341,17 @@ int main(int argc, char *argv[]){ // free object memory free(arguments_parameters); free(cifar10_bench); - free(input_data); - free(d_output); - free(kernel_1); - free(kernel_2); - free(weights_1); - free(weights_2); + + if (!arguments_parameters->unified_memory) + { + free(input_data); + free(d_output); + free(kernel_1); + free(kernel_2); + free(weights_1); + free(weights_2); + } + free(conv_1_output); free(pooling_1_output); free(conv_2_output); diff --git a/gpu4s_benchmark/cifar_10_multiple/opencl/lib_opencl_common.cpp b/gpu4s_benchmark/cifar_10_multiple/opencl/lib_opencl_common.cpp index eb8ec6e4..fb265136 100644 --- a/gpu4s_benchmark/cifar_10_multiple/opencl/lib_opencl_common.cpp +++ b/gpu4s_benchmark/cifar_10_multiple/opencl/lib_opencl_common.cpp @@ -6,6 +6,7 @@ * ESA-PL Strong Copyleft – v2.5 * ======================================================================= */ #include "../benchmark_library.h" +#include "../../common/opencl_common.hpp" #include void init(GraficCommon* device_object, char* device_name){ @@ -103,7 +104,7 @@ bool device_memory_init(GraficCommon* device_object, unsigned int input_data, un if (err != CL_SUCCESS) return false; // dense 1 weights - deviceObj->dense_layer_1_weights = new cl::Buffer(*deviceObj->context,CL_MEM_READ_ONLY ,weights_layer_1 * sizeof(bench_t)); + deviceObj->dense_layer_1_weights = new cl::Buffer(*deviceObj->context,CL_MEM_READ_ONLY ,weights_layer_1 * sizeof(bench_t), nullptr, &err); if (err != CL_SUCCESS) return false; // dense 1 output @@ -293,3 +294,49 @@ void clean(GraficCommon* device_object){ delete deviceObj->output_data; delete deviceObj->sum_ouput; } + + +#ifdef UMA_COMPATIBILITY +// ====== UMA function ====== +void get_unified_memory_pointers(GraficCommon* device_object,bench_t* &input_data, unsigned int input_mem_size,bench_t* &kernel_1, bench_t* &kernel_2, unsigned int kernel_mem_size, bench_t* &weights_1, unsigned int weights_1_mem_size, bench_t* &weights_2, unsigned int weights_2_mem_size, bench_t* &d_output, unsigned int output_mem_size){ + GraficObject* deviceObj = static_cast(device_object); + // --- Call the openCL common function --- + map_unified_memory(device_object, input_mem_size, + BufferMapCL{&input_data, deviceObj->input_data, nullptr}); + + map_unified_memory(device_object, kernel_mem_size, + BufferMapCL{&kernel_1, deviceObj->kernel_1, nullptr}, + BufferMapCL{&kernel_2, deviceObj->kernel_2, nullptr}); + + map_unified_memory(device_object, weights_1_mem_size, + BufferMapCL{&weights_1, deviceObj->dense_layer_1_weights, nullptr}); + + map_unified_memory(device_object, weights_2_mem_size, + BufferMapCL{&weights_2, deviceObj->dense_layer_2_weights, nullptr}); + + map_unified_memory(device_object, output_mem_size, + BufferMapCL{&d_output, deviceObj->output_data, nullptr}); +} + +void sync_unified_memory_to_device(GraficCommon* device_object, bench_t* &input_data, bench_t* &kernel_1, bench_t* &kernel_2, bench_t* &weights_1, bench_t* &weights_2, bench_t* &d_output){ + GraficObject* deviceObj = static_cast(device_object); + // --- Call the openCL common function --- + unmap_unified_memory(device_object, + BufferMapCL{&input_data, deviceObj->input_data, deviceObj->evt_copyIN}, + BufferMapCL{&kernel_1, deviceObj->kernel_1, deviceObj->evt_copyK1}, + BufferMapCL{&kernel_2, deviceObj->kernel_2, deviceObj->evt_copyK2}, + BufferMapCL{&weights_1, deviceObj->dense_layer_1_weights, deviceObj->evt_copyW1}, + BufferMapCL{&weights_2, deviceObj->dense_layer_2_weights, deviceObj->evt_copyW2}, + BufferMapCL{&d_output, deviceObj->output_data, nullptr} + ); +} + +void sync_unified_memory_to_host(GraficCommon* device_object, bench_t* &d_output, unsigned int memSize){ + GraficObject* deviceObj = static_cast(device_object); + // --- Call the openCL common function --- + map_unified_memory_to_host(device_object, memSize, + BufferMapCL{&d_output, deviceObj->output_data, deviceObj->evt_copyOut} + ); +} + +#endif \ No newline at end of file diff --git a/gpu4s_benchmark/common/opencl_common.hpp b/gpu4s_benchmark/common/opencl_common.hpp index 91bf07d5..ae506c8c 100644 --- a/gpu4s_benchmark/common/opencl_common.hpp +++ b/gpu4s_benchmark/common/opencl_common.hpp @@ -27,6 +27,14 @@ struct BufferMapCL { cl::Event* deviceEvent; /**< Pointer to the OpenCL device event object used for profiling timing */ }; +inline bool openclError(cl_int err, const char* txt){ + if (err != CL_SUCCESS) { + fprintf(stderr, "%s (OpenCL error code %d)\n", txt, err); + return true; // Error detected + } + return false; +} + // ============ UMA function ============ /** @@ -42,24 +50,29 @@ template inline void map_unified_memory(GraficCommon* device_object, unsigned memSize, MapCL... mapCL) { GraficObject* deviceObj = static_cast(device_object); Clock mapCLK; + cl_int err = CL_SUCCESS; + cl_int lastErr = CL_SUCCESS; + mapCLK.start(); // --- C++17 Fold Expression Unrolled at compile-time --- // For each MapCL map host buffer to devcie buffer - ((*(mapCL.hostBuffer) = static_cast( - deviceObj->queue->enqueueMapBuffer( - *(mapCL.deviceBuffer), CL_TRUE, CL_MAP_WRITE, 0, memSize, nullptr, mapCL.deviceEvent) - )), ...); - - // equivalent but less optimized - // for (const auto& item : { mapCL... }) { - // *(item.host_buffer) = static_cast( - // deviceObj->queue->enqueueMapBuffer(*(item.device_clBuffer), CL_TRUE, CL_MAP_WRITE, 0, memSize) - // ); - // } + (( + *(mapCL.hostBuffer) = static_cast( + deviceObj->queue->enqueueMapBuffer( + *(mapCL.deviceBuffer), CL_TRUE, CL_MAP_WRITE, 0, memSize, nullptr, mapCL.deviceEvent, &lastErr + ) + ), + // Update err to not miss an error + (lastErr != CL_SUCCESS ? err = lastErr : CL_SUCCESS) + ), ...); + + if (openclError(err, "Failed to map buffer!")) return; mapCLK.end(); - deviceObj->h2d_elapsed_time = mapCLK.getElapsedNS(); + + // store the hd2h time + deviceObj->h2d_elapsed_time += mapCLK.getElapsedNS(); } /** @@ -74,16 +87,27 @@ template inline void unmap_unified_memory(GraficCommon* device_object, MapCL... mapCL) { GraficObject* deviceObj = static_cast(device_object); Clock unmapCLK; + cl_int err = CL_SUCCESS; + cl_int lastErr = CL_SUCCESS; + unmapCLK.start(); // --- C++17 Fold Expression Unrolled at compile-time --- // For each MapCL unmap host buffer to devcie buffer - ((deviceObj->queue->enqueueUnmapMemObject( - *(mapCL.deviceBuffer), mapCL.hostBuffer, NULL, mapCL.deviceEvent) + (( + deviceObj->queue->enqueueUnmapMemObject( + *(mapCL.deviceBuffer), *(mapCL.hostBuffer), NULL, mapCL.deviceEvent, &lastErr + ), + // Update err to not miss an error + (lastErr != CL_SUCCESS ? err = lastErr : CL_SUCCESS) ), ...); + if (openclError(err, "Failed to unmap buffer!")) return; + unmapCLK.end(); - deviceObj->d2h_elapsed_time = unmapCLK.getElapsedNS(); + + // store the h2d time + deviceObj->h2d_elapsed_time += unmapCLK.getElapsedNS(); } /** @@ -98,18 +122,32 @@ template inline void map_unified_memory_to_host(GraficCommon* device_object, unsigned memSize, MapCL... mapCL) { GraficObject* deviceObj = static_cast(device_object); Clock mapCLK; + cl_int err = CL_SUCCESS; + cl_int lastErr = CL_SUCCESS; + mapCLK.start(); // --- C++17 Fold Expression Unrolled at compile-time --- // For each MapCL map host buffer to devcie buffer - ((*(mapCL.hostBuffer) = static_cast( - deviceObj->queue->enqueueMapBuffer( - *(mapCL.deviceBuffer), CL_TRUE, CL_MAP_WRITE, 0, memSize, nullptr, mapCL.deviceEvent) - )), ...); + (( + *(mapCL.hostBuffer) = static_cast( + deviceObj->queue->enqueueMapBuffer( + *(mapCL.deviceBuffer), CL_TRUE, CL_MAP_READ, 0, memSize, nullptr, mapCL.deviceEvent, &lastErr + ) + ), + // Update err to not miss an error + (lastErr != CL_SUCCESS ? err = lastErr : CL_SUCCESS) + ), ...); + + if (openclError(err, "Failed to map buffer!")) return; mapCLK.end(); - deviceObj->d2h_elapsed_time += mapCLK.getElapsedNS(); + + // store the d2h time + deviceObj->d2h_elapsed_time = mapCLK.getElapsedNS(); } #endif + + diff --git a/gpu4s_benchmark/matrix_multiplication_bench/main.cpp b/gpu4s_benchmark/matrix_multiplication_bench/main.cpp index 5430a399..8e654b5e 100644 --- a/gpu4s_benchmark/matrix_multiplication_bench/main.cpp +++ b/gpu4s_benchmark/matrix_multiplication_bench/main.cpp @@ -142,7 +142,6 @@ int main(int argc, char *argv[]) if (arguments_parameters->unified_memory) { #ifdef UMA_COMPATIBILITY - // Copy back ptr sync_unified_memory_to_host(matrix_bench, d_C, mem_size); #endif } else @@ -183,7 +182,7 @@ int main(int argc, char *argv[]) //set_values_file(output_file, d_C, size); } - //check if error + //check for error if (arguments_parameters->verification) { Clock cpuKernelCLK; @@ -227,7 +226,6 @@ int main(int argc, char *argv[]) print_double_hexadecimal_values(GPU_FILE, d_C, size_matrix); print_double_hexadecimal_values(CPU_FILE, h_C, size_matrix); } - } /////////////////////////////////////////////////////////////////////////////////////////////// // CLEAN MEMORY From 4881a8788d42edabf8c4ea833130ff2ef6e09654 Mon Sep 17 00:00:00 2001 From: Noah Perret Date: Wed, 12 Aug 2026 15:55:57 +0200 Subject: [PATCH 05/27] fix main.cpp cifar_10_mutiple --- .../LRN_bench/opencl/lib_opencl_common.cpp | 13 +-- .../cifar_10/opencl/lib_opencl_common.cpp | 36 ++------ .../cifar_10_multiple/benchmark_library.h | 2 - gpu4s_benchmark/cifar_10_multiple/main.cpp | 91 +++++++++---------- .../opencl/lib_opencl_common.cpp | 86 ++---------------- gpu4s_benchmark/common/opencl_common.hpp | 28 +++--- .../opencl/lib_opencl_common.cpp | 19 +--- .../opencl/lib_opencl_common.cpp | 31 ++----- .../opencl/lib_opencl_lib.cpp | 6 +- .../opencl/lib_opencl_common.cpp | 13 +-- .../opencl/lib_opencl_common.cpp | 13 +-- .../opencl/lib_opencl.cpp | 18 +--- .../opencl/lib_opencl_common.cpp | 18 +--- .../opencl/lib_opencl_common.cpp | 19 +--- .../opencl/lib_opencl_lib.cpp | 6 +- .../opencl/lib_opencl_common.cpp | 19 +--- .../opencl/lib_opencl_common.cpp | 12 +-- .../opencl/lib_opencl.cpp | 12 +-- .../relu_bench/opencl/lib_opencl_common.cpp | 12 +-- .../opencl/lib_opencl_common.cpp | 17 +--- .../wavelet_transform/opencl/lib_opencl.cpp | 24 +---- 21 files changed, 114 insertions(+), 381 deletions(-) diff --git a/gpu4s_benchmark/LRN_bench/opencl/lib_opencl_common.cpp b/gpu4s_benchmark/LRN_bench/opencl/lib_opencl_common.cpp index 650528fa..dce82144 100644 --- a/gpu4s_benchmark/LRN_bench/opencl/lib_opencl_common.cpp +++ b/gpu4s_benchmark/LRN_bench/opencl/lib_opencl_common.cpp @@ -6,6 +6,7 @@ * ESA-PL Strong Copyleft – v2.5 * ======================================================================= */ #include "../benchmark_library.h" +#include "../../common/opencl_common.hpp" void init(GraficCommon* device_object, char* device_name){ init(device_object, 0,0, device_name); @@ -66,11 +67,7 @@ void copy_memory_to_device(GraficCommon* device_object, bench_t* h_A, unsigned i h2dCLK.start(); cl_int err = deviceObj->queue->enqueueWriteBuffer(*deviceObj->d_A,CL_TRUE,0,sizeof(bench_t)*size_a, h_A, NULL, deviceObj->evt_copyA); - if (err != CL_SUCCESS) - { - fprintf(stderr, "Failed to copy vector A from host to device (OpenCL error code %d)!\n", err); - return; - } + if (openclError("Failed to copy vector A from host to device", err)) return; // Clock profilling end h2dCLK.end(); @@ -89,11 +86,7 @@ void copy_memory_to_host(GraficCommon* device_object, bench_t* h_C, int size){ d2hCLK.start(); cl_int err = deviceObj->queue->enqueueReadBuffer(*deviceObj->d_B, CL_TRUE, 0, sizeof(bench_t)*size, h_C, NULL, deviceObj->evt_copyB); - if (err != CL_SUCCESS) - { - fprintf(stderr, "Failed to copy vector B from device to host (OpenCL error code %d)!\n", err); - return; - } + if (openclError("Failed to copy vector B from device to host", err)) return; // Clock profilling end d2hCLK.end(); diff --git a/gpu4s_benchmark/cifar_10/opencl/lib_opencl_common.cpp b/gpu4s_benchmark/cifar_10/opencl/lib_opencl_common.cpp index 9396d27a..0b3f0af8 100644 --- a/gpu4s_benchmark/cifar_10/opencl/lib_opencl_common.cpp +++ b/gpu4s_benchmark/cifar_10/opencl/lib_opencl_common.cpp @@ -131,41 +131,21 @@ void copy_memory_to_device(GraficCommon* device_object, bench_t* input_data, ben // input data cl_int err = deviceObj->queue->enqueueWriteBuffer(*deviceObj->input_data,CL_TRUE,0,sizeof(bench_t)* input * input, input_data, NULL, deviceObj->evt_copyIN); - if (err != CL_SUCCESS) - { - fprintf(stderr, "Failed to copy input_data from host to device (OpenCL error code %d)!\n", err); - return; - } + if (openclError("Failed to copy input_data from host to device", err)) return; // kernels err = deviceObj->queue->enqueueWriteBuffer(*deviceObj->kernel_1,CL_TRUE,0,sizeof(bench_t)* kernel_size_1 * kernel_size_1, kernel_1_data, NULL, deviceObj->evt_copyK1); - if (err != CL_SUCCESS) - { - fprintf(stderr, "Failed to copy kernel_1 from host to device (OpenCL error code %d)!\n", err); - return; - } + if (openclError("Failed to copy kernel_1 from host to device", err)) return; err = deviceObj->queue->enqueueWriteBuffer(*deviceObj->kernel_2,CL_TRUE,0,sizeof(bench_t)* kernel_size_2 * kernel_size_2, kernel_2_data, NULL, deviceObj->evt_copyK2); - if (err != CL_SUCCESS) - { - fprintf(stderr, "Failed to copy kernel_2 from host to device (OpenCL error code %d)!\n", err); - return; - } + if (openclError("Failed to copy kernel_2 from host to device", err)) return; // dense layer err = deviceObj->queue->enqueueWriteBuffer(*deviceObj->dense_layer_1_weights,CL_TRUE,0,sizeof(bench_t)* weights_1_size, weights_1, NULL, deviceObj->evt_copyW1); - if (err != CL_SUCCESS) - { - fprintf(stderr, "Failed to copy dense_layer_1_weights from host to device (OpenCL error code %d)!\n", err); - return; - } + if (openclError("Failed to copy dense_layer_1_weights from host to device", err)) return; err = deviceObj->queue->enqueueWriteBuffer(*deviceObj->dense_layer_2_weights,CL_TRUE,0,sizeof(bench_t)* weights_2_size, weights_2, NULL, deviceObj->evt_copyW2); - if (err != CL_SUCCESS) - { - fprintf(stderr, "Failed to copy dense_layer_2 from host to device (OpenCL error code %d)!\n", err); - return; - } + if (openclError("Failed to copy dense_layer_2 from host to device", err)) return; // Clock profilling end h2dCLK.end(); @@ -185,11 +165,7 @@ void copy_memory_to_host(GraficCommon* device_object, bench_t* h_C, int size){ d2hCLK.start(); cl_int err = deviceObj->queue->enqueueReadBuffer(*deviceObj->output_data, CL_TRUE, 0, sizeof(bench_t)*size, h_C, NULL, deviceObj->evt_copyOut); - if (err != CL_SUCCESS) - { - fprintf(stderr, "Failed to copy vector output_data from device to host (OpenCL error code %d)!\n", err); - return; - } + if (openclError("Failed to copy vector output_data from device to host", err)) return; //deviceObj->queue->enqueueReadBuffer(*deviceObj->conv_2_output,CL_TRUE,0,sizeof(bench_t)*16*16,h_C, NULL, deviceObj->evt_copyOut); // Clock profilling end diff --git a/gpu4s_benchmark/cifar_10_multiple/benchmark_library.h b/gpu4s_benchmark/cifar_10_multiple/benchmark_library.h index f8e69b8f..bf999154 100644 --- a/gpu4s_benchmark/cifar_10_multiple/benchmark_library.h +++ b/gpu4s_benchmark/cifar_10_multiple/benchmark_library.h @@ -121,6 +121,4 @@ void copy_memory_to_host(GraficCommon* device_object, bench_t* h_C, int size, un #ifdef UMA_COMPATIBILITY -void get_unified_memory_pointers(GraficCommon* device_object,bench_t* &input_data, unsigned int input_mem_size,bench_t* &kernel_1, bench_t* &kernel_2, unsigned int kernel_mem_size, bench_t* &weights_1, unsigned int weights_1_mem_size, bench_t* &weights_2, unsigned int weights_2_mem_size, bench_t* &d_output, unsigned int output_mem_size); -void sync_unified_memory_to_device(GraficCommon* device_object, bench_t* &input_data, bench_t* &kernel_1, bench_t* &kernel_2, bench_t* &weights_1, bench_t* &weights_2, bench_t* &d_output); #endif \ No newline at end of file diff --git a/gpu4s_benchmark/cifar_10_multiple/main.cpp b/gpu4s_benchmark/cifar_10_multiple/main.cpp index 6368adda..683a01ef 100644 --- a/gpu4s_benchmark/cifar_10_multiple/main.cpp +++ b/gpu4s_benchmark/cifar_10_multiple/main.cpp @@ -38,40 +38,41 @@ int main(int argc, char *argv[]){ /////////////////////////////////////////////////////////////////////////////////////////////// BenchmarkParameters *arguments_parameters = (BenchmarkParameters *)malloc(sizeof(BenchmarkParameters)); int resolution = arguments_handler(argc,argv,arguments_parameters); - if (resolution == ERROR_ARGUMENTS){ + if (resolution == ERROR_ARGUMENTS) + { exit(-1); } + /////////////////////////////////////////////////////////////////////////////////////////////// // VARIABLES /////////////////////////////////////////////////////////////////////////////////////////////// // linearizable versions of matrix - unsigned int size_matrix =CIFAR_10_INPUT * CIFAR_10_INPUT * arguments_parameters->size; + unsigned int size_matrix = CIFAR_10_INPUT * CIFAR_10_INPUT * arguments_parameters->size; // A input matrix unsigned int size_A = CIFAR_10_INPUT * CIFAR_10_INPUT * arguments_parameters->size; unsigned int mem_size_A = sizeof(bench_t) * size_A; - bench_t* input_data = NULL; + bench_t* input_data = (bench_t*) malloc(mem_size_A); // B output matrix - unsigned int size_B = CIFAR_10_OUTPUT * arguments_parameters->size; + unsigned int size_B = CIFAR_10_OUTPUT * CIFAR_10_OUTPUT * arguments_parameters->size; unsigned int mem_size_B = sizeof(bench_t) * size_B; - bench_t* d_output = NULL; + bench_t* d_output = (bench_t*) malloc(mem_size_B); // kernel matrix 1 unsigned int size_k_1 = KERNEL_CON_1 * KERNEL_CON_2; unsigned int mem_size_k_1 = sizeof(bench_t) * size_k_1; - bench_t* kernel_1 = NULL; + bench_t* kernel_1 = (bench_t*) malloc(mem_size_k_1); // kernel matrix 2 unsigned int size_k_2 = KERNEL_CON_2 * KERNEL_CON_2; unsigned int mem_size_k_2 = sizeof(bench_t) * size_k_2; - bench_t* kernel_2 = NULL; + bench_t* kernel_2 = (bench_t*) malloc(mem_size_k_2); // weights 1 unsigned int size_w_1 = DENSE_1 * (((CIFAR_10_INPUT / STRIDE_1)/STRIDE_2)*((CIFAR_10_INPUT / STRIDE_1)/STRIDE_2)); unsigned int mem_size_w_1 = sizeof(bench_t) * size_w_1; - bench_t* weights_1 = NULL; + bench_t* weights_1 = (bench_t*) malloc(mem_size_w_1); // weights 1 unsigned int size_w_2 = DENSE_1 * DENSE_2; unsigned int mem_size_w_2 = sizeof(bench_t) * size_w_2; - bench_t* weights_2 = NULL; + bench_t* weights_2 = (bench_t*) malloc(mem_size_w_2); // Outputs - unsigned int mem_size_output = sizeof(bench_t) * CIFAR_10_OUTPUT * arguments_parameters->size; const unsigned int size_pooling_1 = CIFAR_10_INPUT / STRIDE_1; const unsigned int size_pooling_2 = size_pooling_1 / STRIDE_2; bench_t* conv_1_output = (bench_t*) malloc ( CIFAR_10_INPUT * CIFAR_10_INPUT * sizeof(bench_t*)); @@ -81,15 +82,14 @@ int main(int argc, char *argv[]){ bench_t* dense_layer_1_output = (bench_t*) malloc ( DENSE_1 * sizeof(bench_t)); bench_t* dense_layer_2_output = (bench_t*) malloc ( DENSE_2 * sizeof(bench_t)); bench_t* output_data = (bench_t*) malloc ( DENSE_2 * sizeof(bench_t) * arguments_parameters->size); - // init devices + // init devices char char device[100] = ""; // main object init GraficCommon*cifar10_bench = (GraficCommon*)malloc(sizeof(GraficObject)); // --- 1. Init Device & Context --- - init(cifar10_bench, 0, arguments_parameters->gpu, device); - + init(cifar10_bench, 0,arguments_parameters->gpu, device); // Update profiling clock mode cifar10_bench->profiling_clock = arguments_parameters->profiling_clock; @@ -101,12 +101,13 @@ int main(int argc, char *argv[]){ exit(-1); } + // --- 3. Allocate Host Pointers --- if (arguments_parameters->unified_memory) { #ifdef UMA_COMPATIBILITY // map the buffzer to the gpu + cpu take the lead - get_unified_memory_pointers(cifar10_bench,input_data, mem_size_A,kernel_1, kernel_2, mem_size_k_1,weights_1, mem_size_w_1,weights_2, mem_size_w_2,d_output, mem_size_output); + //get_unified_memory_pointers(//...); #else fprintf(stderr, "\033[1;31merror:\033[0m This framework is not compatible with unified memory. Please remove the -u arg!\n"); exit(-1); @@ -114,14 +115,10 @@ int main(int argc, char *argv[]){ } else { // normale malloc - input_data = (bench_t*) malloc(mem_size_A); - kernel_1 = (bench_t*) malloc(mem_size_k_1); - kernel_2 = (bench_t*) malloc(mem_size_k_2); - weights_1 = (bench_t*) malloc(mem_size_w_1); - weights_2 = (bench_t*) malloc(mem_size_w_2); - d_output = (bench_t*) malloc(mem_size_B); + ///... to ne fill } - + + /////////////////////////////////////////////////////////////////////////////////////////////// // DATA INIT @@ -225,13 +222,12 @@ int main(int argc, char *argv[]){ if (!arguments_parameters->csv_format_timestamp && !arguments_parameters->csv_format && !arguments_parameters->mute_messages ){ printf("Using device: %s\n", device); } - // copy memory to device if(arguments_parameters->unified_memory) { #ifdef UMA_COMPATIBILITY - sync_unified_memory_to_device(cifar10_bench, input_data, kernel_1, kernel_2, weights_1, weights_2, d_output); + //sync_unified_memory_to_device(//to be fill; #endif } else @@ -247,14 +243,14 @@ int main(int argc, char *argv[]){ if (arguments_parameters->unified_memory) { #ifdef UMA_COMPATIBILITY - sync_unified_memory_to_host(cifar10_bench, d_output, mem_size_output); + //sync_unified_memory_to_host(// to be fill); #endif } else { - // copy memory to host - copy_memory_to_host(cifar10_bench, d_output, CIFAR_10_OUTPUT, arguments_parameters->size); - } + copy_memory_to_host(cifar10_bench, d_output, CIFAR_10_OUTPUT, arguments_parameters->size); + } + // get time if (arguments_parameters->print_timing || arguments_parameters->csv_format || arguments_parameters->csv_format_timestamp) { @@ -265,13 +261,13 @@ int main(int argc, char *argv[]){ if (arguments_parameters->print_output) { #ifdef INT - for (int i=0; i < arguments_parameters->size; ++i){ - for (int j=0; jsize; ++i){ + for (int j=0; jsize; ++i){ for (int j=0; jexport_results_gpu) { print_double_hexadecimal_values(GPU_FILE, d_output, size_B); + //set_values_file(output_file, d_C, size); } - //check for error + if (arguments_parameters->verification) { Clock cpuKernelCLK; @@ -322,15 +319,14 @@ int main(int argc, char *argv[]){ printf("\n"); #endif } - - - if (compare_vectors(output_data, d_output, CIFAR_10_OUTPUT * arguments_parameters->size)){ + + if (compare_vectors(output_data, d_output, CIFAR_10_OUTPUT)){ printf("OK\n"); } if (arguments_parameters->export_results){ - print_double_hexadecimal_values(GPU_FILE, d_output, CIFAR_10_OUTPUT * arguments_parameters->size); - print_double_hexadecimal_values(CPU_FILE, output_data, CIFAR_10_OUTPUT * arguments_parameters->size); + print_double_hexadecimal_values(GPU_FILE, d_output, CIFAR_10_OUTPUT); + print_double_hexadecimal_values(CPU_FILE, output_data, CIFAR_10_OUTPUT); } } /////////////////////////////////////////////////////////////////////////////////////////////// @@ -341,17 +337,12 @@ int main(int argc, char *argv[]){ // free object memory free(arguments_parameters); free(cifar10_bench); - - if (!arguments_parameters->unified_memory) - { - free(input_data); - free(d_output); - free(kernel_1); - free(kernel_2); - free(weights_1); - free(weights_2); - } - + free(input_data); + free(d_output); + free(kernel_1); + free(kernel_2); + free(weights_1); + free(weights_2); free(conv_1_output); free(pooling_1_output); free(conv_2_output); @@ -458,4 +449,4 @@ int arguments_handler(int argc, char ** argv, BenchmarkParameters* arguments_par bench_t RandomNumber() { return ((bench_t(rand()) / bench_t(RAND_MAX)) * (MAX_VALUE - MIN_VALUE)) + MIN_VALUE; -} +} \ No newline at end of file diff --git a/gpu4s_benchmark/cifar_10_multiple/opencl/lib_opencl_common.cpp b/gpu4s_benchmark/cifar_10_multiple/opencl/lib_opencl_common.cpp index fb265136..6c3dbc81 100644 --- a/gpu4s_benchmark/cifar_10_multiple/opencl/lib_opencl_common.cpp +++ b/gpu4s_benchmark/cifar_10_multiple/opencl/lib_opencl_common.cpp @@ -139,41 +139,21 @@ void copy_memory_to_device(GraficCommon* device_object, bench_t* input_data, ben // input data cl_int err = deviceObj->queue->enqueueWriteBuffer(*deviceObj->input_data,CL_TRUE,0,sizeof(bench_t)* input * input * number_of_images, input_data, NULL, deviceObj->evt_copyIN); - if (err != CL_SUCCESS) - { - fprintf(stderr, "Failed to copy input_data from host to device (OpenCL error code %d)!\n", err); - return; - } + if (openclError("Failed to copy input_data from host to device", err)) return; // kernels err = deviceObj->queue->enqueueWriteBuffer(*deviceObj->kernel_1,CL_TRUE,0,sizeof(bench_t)* kernel_size_1 * kernel_size_1, kernel_1_data, NULL, deviceObj->evt_copyK1); - if (err != CL_SUCCESS) - { - fprintf(stderr, "Failed to copy kernel_1 from host to device (OpenCL error code %d)!\n", err); - return; - } + if (openclError("Failed to copy kernel_1 from host to device", err)) return; err = deviceObj->queue->enqueueWriteBuffer(*deviceObj->kernel_2,CL_TRUE,0,sizeof(bench_t)* kernel_size_2 * kernel_size_2, kernel_2_data, NULL, deviceObj->evt_copyK2); - if (err != CL_SUCCESS) - { - fprintf(stderr, "Failed to copy kernel_2 from host to device (OpenCL error code %d)!\n", err); - return; - } + if (openclError("Failed to copy kernel_2 from host to device", err)) return; // dense layer err = deviceObj->queue->enqueueWriteBuffer(*deviceObj->dense_layer_1_weights,CL_TRUE,0,sizeof(bench_t)* weights_1_size, weights_1, NULL, deviceObj->evt_copyW1); - if (err != CL_SUCCESS) - { - fprintf(stderr, "Failed to copy dense_layer_1_weights from host to device (OpenCL error code %d)!\n", err); - return; - } + if (openclError("Failed to copy dense_layer_1_weights from host to device", err)) return; err = deviceObj->queue->enqueueWriteBuffer(*deviceObj->dense_layer_2_weights,CL_TRUE,0,sizeof(bench_t)* weights_2_size, weights_2, NULL, deviceObj->evt_copyW2); - if (err != CL_SUCCESS) - { - fprintf(stderr, "Failed to copy dense_layer_2 from host to device (OpenCL error code %d)!\n", err); - return; - } + if (openclError("Failed to copy dense_layer_2 from host to device", err)) return; // Clock profilling end h2dCLK.end(); @@ -183,8 +163,6 @@ void copy_memory_to_device(GraficCommon* device_object, bench_t* input_data, ben } - - void copy_memory_to_host(GraficCommon* device_object, bench_t* h_C, int size, unsigned int number_of_images){ GraficObject* deviceObj = static_cast(device_object); // device -> host @@ -194,11 +172,7 @@ void copy_memory_to_host(GraficCommon* device_object, bench_t* h_C, int size, un d2hCLK.start(); cl_int err = deviceObj->queue->enqueueReadBuffer(*deviceObj->output_data, CL_TRUE, 0, sizeof(bench_t)*size*number_of_images, h_C, NULL, deviceObj->evt_copyOut); - if (err != CL_SUCCESS) - { - fprintf(stderr, "Failed to copy vector output_data from device to host (OpenCL error code %d)!\n", err); - return; - } + if (openclError("Failed to copy vector output_data from device to host", err)) return; //deviceObj->queue->enqueueReadBuffer(*deviceObj->conv_2_output,CL_TRUE,0,sizeof(bench_t)*16*16,h_C, NULL, deviceObj->evt_copyOut); // Clock profilling end @@ -293,50 +267,4 @@ void clean(GraficCommon* device_object){ delete deviceObj->dense_layer_2_output; delete deviceObj->output_data; delete deviceObj->sum_ouput; -} - - -#ifdef UMA_COMPATIBILITY -// ====== UMA function ====== -void get_unified_memory_pointers(GraficCommon* device_object,bench_t* &input_data, unsigned int input_mem_size,bench_t* &kernel_1, bench_t* &kernel_2, unsigned int kernel_mem_size, bench_t* &weights_1, unsigned int weights_1_mem_size, bench_t* &weights_2, unsigned int weights_2_mem_size, bench_t* &d_output, unsigned int output_mem_size){ - GraficObject* deviceObj = static_cast(device_object); - // --- Call the openCL common function --- - map_unified_memory(device_object, input_mem_size, - BufferMapCL{&input_data, deviceObj->input_data, nullptr}); - - map_unified_memory(device_object, kernel_mem_size, - BufferMapCL{&kernel_1, deviceObj->kernel_1, nullptr}, - BufferMapCL{&kernel_2, deviceObj->kernel_2, nullptr}); - - map_unified_memory(device_object, weights_1_mem_size, - BufferMapCL{&weights_1, deviceObj->dense_layer_1_weights, nullptr}); - - map_unified_memory(device_object, weights_2_mem_size, - BufferMapCL{&weights_2, deviceObj->dense_layer_2_weights, nullptr}); - - map_unified_memory(device_object, output_mem_size, - BufferMapCL{&d_output, deviceObj->output_data, nullptr}); -} - -void sync_unified_memory_to_device(GraficCommon* device_object, bench_t* &input_data, bench_t* &kernel_1, bench_t* &kernel_2, bench_t* &weights_1, bench_t* &weights_2, bench_t* &d_output){ - GraficObject* deviceObj = static_cast(device_object); - // --- Call the openCL common function --- - unmap_unified_memory(device_object, - BufferMapCL{&input_data, deviceObj->input_data, deviceObj->evt_copyIN}, - BufferMapCL{&kernel_1, deviceObj->kernel_1, deviceObj->evt_copyK1}, - BufferMapCL{&kernel_2, deviceObj->kernel_2, deviceObj->evt_copyK2}, - BufferMapCL{&weights_1, deviceObj->dense_layer_1_weights, deviceObj->evt_copyW1}, - BufferMapCL{&weights_2, deviceObj->dense_layer_2_weights, deviceObj->evt_copyW2}, - BufferMapCL{&d_output, deviceObj->output_data, nullptr} - ); -} - -void sync_unified_memory_to_host(GraficCommon* device_object, bench_t* &d_output, unsigned int memSize){ - GraficObject* deviceObj = static_cast(device_object); - // --- Call the openCL common function --- - map_unified_memory_to_host(device_object, memSize, - BufferMapCL{&d_output, deviceObj->output_data, deviceObj->evt_copyOut} - ); -} - -#endif \ No newline at end of file +} \ No newline at end of file diff --git a/gpu4s_benchmark/common/opencl_common.hpp b/gpu4s_benchmark/common/opencl_common.hpp index ae506c8c..2c42fba6 100644 --- a/gpu4s_benchmark/common/opencl_common.hpp +++ b/gpu4s_benchmark/common/opencl_common.hpp @@ -9,8 +9,13 @@ #include "benchmark_common.h" // ============ global opencl function ============ -// nothing for now - +inline bool openclError(const char* txt, const cl_int err){ + if (err != CL_SUCCESS) { + fprintf(stderr, "%s (OpenCL error code %d)\n", txt, err); + return true; // Error detected + } + return false; +} #ifdef UMA_COMPATIBILITY @@ -26,15 +31,6 @@ struct BufferMapCL { cl::Buffer* deviceBuffer; /**< Pointer to the OpenCL device buffer object */ cl::Event* deviceEvent; /**< Pointer to the OpenCL device event object used for profiling timing */ }; - -inline bool openclError(cl_int err, const char* txt){ - if (err != CL_SUCCESS) { - fprintf(stderr, "%s (OpenCL error code %d)\n", txt, err); - return true; // Error detected - } - return false; -} - // ============ UMA function ============ /** @@ -67,7 +63,7 @@ inline void map_unified_memory(GraficCommon* device_object, unsigned memSize, Ma (lastErr != CL_SUCCESS ? err = lastErr : CL_SUCCESS) ), ...); - if (openclError(err, "Failed to map buffer!")) return; + if (openclError("Failed to map buffer!", err)) return; mapCLK.end(); @@ -95,14 +91,14 @@ inline void unmap_unified_memory(GraficCommon* device_object, MapCL... mapCL) { // --- C++17 Fold Expression Unrolled at compile-time --- // For each MapCL unmap host buffer to devcie buffer (( - deviceObj->queue->enqueueUnmapMemObject( - *(mapCL.deviceBuffer), *(mapCL.hostBuffer), NULL, mapCL.deviceEvent, &lastErr + lastErr = deviceObj->queue->enqueueUnmapMemObject( + *(mapCL.deviceBuffer), *(mapCL.hostBuffer), NULL, mapCL.deviceEvent ), // Update err to not miss an error (lastErr != CL_SUCCESS ? err = lastErr : CL_SUCCESS) ), ...); - if (openclError(err, "Failed to unmap buffer!")) return; + if (openclError("Failed to unmap buffer!", err)) return; unmapCLK.end(); @@ -139,7 +135,7 @@ inline void map_unified_memory_to_host(GraficCommon* device_object, unsigned mem (lastErr != CL_SUCCESS ? err = lastErr : CL_SUCCESS) ), ...); - if (openclError(err, "Failed to map buffer!")) return; + if (openclError("Failed to map buffer!", err)) return; mapCLK.end(); diff --git a/gpu4s_benchmark/convolution_2D_bench/opencl/lib_opencl_common.cpp b/gpu4s_benchmark/convolution_2D_bench/opencl/lib_opencl_common.cpp index fbf69ebb..5217c49d 100644 --- a/gpu4s_benchmark/convolution_2D_bench/opencl/lib_opencl_common.cpp +++ b/gpu4s_benchmark/convolution_2D_bench/opencl/lib_opencl_common.cpp @@ -6,6 +6,7 @@ * ESA-PL Strong Copyleft – v2.5 * ======================================================================= */ #include "../benchmark_library.h" +#include "../../common/opencl_common.hpp" void init(GraficCommon* device_object, char* device_name){ init(device_object, 0,0, device_name); @@ -68,18 +69,10 @@ void copy_memory_to_device(GraficCommon* device_object, bench_t* h_A, bench_t* k h2dCLK.start(); cl_int err = deviceObj->queue->enqueueWriteBuffer(*deviceObj->d_A,CL_TRUE,0,sizeof(bench_t)*size_a, h_A, NULL, deviceObj->evt_copyA); - if (err != CL_SUCCESS) - { - fprintf(stderr, "Failed to copy vector A from host to device (OpenCL error code %d)!\n", err); - return; - } + if (openclError("Failed to copy vector A from host to device", err)) return; err = deviceObj->queue->enqueueWriteBuffer(*deviceObj->kernel,CL_TRUE,0,sizeof(bench_t)*size_b, kernel, NULL, deviceObj->evt_copyB); - if (err != CL_SUCCESS) - { - fprintf(stderr, "Failed to copy vector B from host to device (OpenCL error code %d)!\n", err); - return; - } + if (openclError("Failed to copy vector B from host to device", err)) return; // Clock profilling end h2dCLK.end(); @@ -98,11 +91,7 @@ void copy_memory_to_host(GraficCommon* device_object, bench_t* h_C, int size){ d2hCLK.start(); cl_int err = deviceObj->queue->enqueueReadBuffer(*deviceObj->d_B, CL_TRUE, 0, sizeof(bench_t)*size, h_C, NULL, deviceObj->evt_copyC); - if (err != CL_SUCCESS) - { - fprintf(stderr, "Failed to copy vector B from device to host (OpenCL error code %d)!\n", err); - return; - } + if (openclError("Failed to copy vector B from device to host", err)) return; // Clock profilling end d2hCLK.end(); diff --git a/gpu4s_benchmark/correlation_2D/opencl/lib_opencl_common.cpp b/gpu4s_benchmark/correlation_2D/opencl/lib_opencl_common.cpp index bf77a344..4debf73f 100644 --- a/gpu4s_benchmark/correlation_2D/opencl/lib_opencl_common.cpp +++ b/gpu4s_benchmark/correlation_2D/opencl/lib_opencl_common.cpp @@ -6,6 +6,7 @@ * ESA-PL Strong Copyleft – v2.5 * ======================================================================= */ #include "../benchmark_library.h" +#include "../../common/opencl_common.hpp" #include void init(GraficCommon* device_object, char* device_name){ @@ -90,18 +91,10 @@ void copy_memory_to_device(GraficCommon* device_object, bench_t* h_A, unsigned i h2dCLK.start(); cl_int err = deviceObj->queue->enqueueWriteBuffer(*deviceObj->d_A,CL_TRUE,0,sizeof(bench_t)*size_a, h_A, NULL, deviceObj->evt_copyA); - if (err != CL_SUCCESS) - { - fprintf(stderr, "Failed to copy vector A from host to device (OpenCL error code %d)!\n", err); - return; - } + if (openclError("Failed to copy vector A from host to device", err)) return; err = deviceObj->queue->enqueueWriteBuffer(*deviceObj->d_B,CL_TRUE,0,sizeof(bench_t)*size_b, h_B, NULL, deviceObj->evt_copyB); - if (err != CL_SUCCESS) - { - fprintf(stderr, "Failed to copy vector B from host to device (OpenCL error code %d)!\n", err); - return; - } + if (openclError("Failed to copy vector B from host to device", err)) return; // Clock profilling end h2dCLK.end(); @@ -122,23 +115,11 @@ void copy_memory_to_host(GraficCommon* device_object, result_bench_t* h_R){ result_bench_t acumulate_value_a_b; result_bench_t acumulate_value_b_b; cl_int err = deviceObj->queue->enqueueReadBuffer(*deviceObj->acumulate_value_a_a,CL_TRUE,0,sizeof(result_bench_t),&acumulate_value_a_a, NULL, deviceObj->evt_copyAA); - if (err != CL_SUCCESS) - { - fprintf(stderr, "Failed to copy vector acumulate_value_a_a from device to host (OpenCL error code %d)!\n", err); - return; - } + if (openclError("Failed to copy vector acumulate_value_a_a from device to host", err)) return; err = deviceObj->queue->enqueueReadBuffer(*deviceObj->acumulate_value_a_b,CL_TRUE,0,sizeof(result_bench_t),&acumulate_value_a_b, NULL, deviceObj->evt_copyAB); - if (err != CL_SUCCESS) - { - fprintf(stderr, "Failed to copy vector acumulate_value_a_b from device to host (OpenCL error code %d)!\n", err); - return; - } + if (openclError("Failed to copy vector acumulate_value_a_b from device to host", err)) return; err = deviceObj->queue->enqueueReadBuffer(*deviceObj->acumulate_value_b_b,CL_TRUE,0,sizeof(result_bench_t),&acumulate_value_b_b, NULL, deviceObj->evt_copyBB); - if (err != CL_SUCCESS) - { - fprintf(stderr, "Failed to copy vector acumulate_value_b_b from device to host (OpenCL error code %d)!\n", err); - return; - } + if (openclError("Failed to copy vector acumulate_value_b_b from device to host", err)) return; deviceObj->evt_copyBB->wait(); *h_R = (result_bench_t)(acumulate_value_a_b / (result_bench_t)(sqrt(acumulate_value_a_a * acumulate_value_b_b))); diff --git a/gpu4s_benchmark/fast_fourier_transform_2D_bench/opencl/lib_opencl_lib.cpp b/gpu4s_benchmark/fast_fourier_transform_2D_bench/opencl/lib_opencl_lib.cpp index 051f20e9..b0f367bd 100644 --- a/gpu4s_benchmark/fast_fourier_transform_2D_bench/opencl/lib_opencl_lib.cpp +++ b/gpu4s_benchmark/fast_fourier_transform_2D_bench/opencl/lib_opencl_lib.cpp @@ -150,11 +150,7 @@ void copy_memory_to_host(GraficCommon* device_object, COMPLEX **h_B, int64_t siz d2hCLK.start(); cl_int err = deviceObj->queue->enqueueReadBuffer(*deviceObj->d_B, CL_TRUE, 0, sizeof(bench_t)*size*size * 2, h_signal, NULL, deviceObj->evt_copyBr); - if (err != CL_SUCCESS) - { - fprintf(stderr, "Failed to copy vector B from device to host (OpenCL error code %d)!\n", err); - return; - } + if (openclError("Failed to copy vector B from device to host", err)) return; // Clock profilling end d2hCLK.end(); diff --git a/gpu4s_benchmark/fast_fourier_transform_bench/opencl/lib_opencl_common.cpp b/gpu4s_benchmark/fast_fourier_transform_bench/opencl/lib_opencl_common.cpp index 395eb1e2..78346b63 100644 --- a/gpu4s_benchmark/fast_fourier_transform_bench/opencl/lib_opencl_common.cpp +++ b/gpu4s_benchmark/fast_fourier_transform_bench/opencl/lib_opencl_common.cpp @@ -6,6 +6,7 @@ * ESA-PL Strong Copyleft – v2.5 * ======================================================================= */ #include "../benchmark_library.h" +#include "../../common/opencl_common.hpp" void init(GraficCommon* device_object, char* device_name){ init(device_object, 0,0, device_name); @@ -67,11 +68,7 @@ void copy_memory_to_device(GraficCommon* device_object, bench_t* h_B,int64_t siz h2dCLK.start(); cl_int err = deviceObj->queue->enqueueWriteBuffer(*deviceObj->d_B,CL_TRUE,0,sizeof(bench_t)*size, h_B, NULL, deviceObj->evt_copyB); - if (err != CL_SUCCESS) - { - fprintf(stderr, "Failed to copy data vector B from host to device (OpenCL error code %d)!\n", err); - return; - } + if (openclError("Failed to copy data vector B from host to device", err)) return; // Clock profilling end h2dCLK.end(); @@ -89,11 +86,7 @@ void copy_memory_to_host(GraficCommon* device_object, bench_t* h_B, int64_t size d2hCLK.start(); cl_int err = deviceObj->queue->enqueueReadBuffer(*deviceObj->d_Br, CL_TRUE, 0, sizeof(bench_t)*size, h_B, NULL, deviceObj->evt_copyBr); - if (err != CL_SUCCESS) - { - fprintf(stderr, "Failed to copy vector B from device to host (OpenCL error code %d)!\n", err); - return; - } + if (openclError("Failed to copy vector B from device to host", err)) return; // Clock profilling end d2hCLK.end(); diff --git a/gpu4s_benchmark/fast_fourier_transform_window_bench/opencl/lib_opencl_common.cpp b/gpu4s_benchmark/fast_fourier_transform_window_bench/opencl/lib_opencl_common.cpp index 22e1e03f..fe17e59f 100644 --- a/gpu4s_benchmark/fast_fourier_transform_window_bench/opencl/lib_opencl_common.cpp +++ b/gpu4s_benchmark/fast_fourier_transform_window_bench/opencl/lib_opencl_common.cpp @@ -6,6 +6,7 @@ * ESA-PL Strong Copyleft – v2.5 * ======================================================================= */ #include "../benchmark_library.h" +#include "../../common/opencl_common.hpp" void init(GraficCommon* device_object, char* device_name){ init(device_object, 0,0, device_name); @@ -66,11 +67,7 @@ void copy_memory_to_device(GraficCommon* device_object, bench_t* h_A,int64_t siz h2dCLK.start(); cl_int err = deviceObj->queue->enqueueWriteBuffer(*deviceObj->d_A,CL_TRUE,0,sizeof(bench_t)*size, h_A, NULL, deviceObj->evt_copyB); - if (err != CL_SUCCESS) - { - fprintf(stderr, "Failed to copy data vector A from host to device (OpenCL error code %d)!\n", err); - return; - } + if (openclError("Failed to copy data vector A from host to device", err)) return; // Clock profilling end h2dCLK.end(); @@ -89,11 +86,7 @@ void copy_memory_to_host(GraficCommon* device_object, bench_t* h_B, int64_t size d2hCLK.start(); cl_int err = deviceObj->queue->enqueueReadBuffer(*deviceObj->d_B, CL_TRUE, 0, sizeof(bench_t)*size, h_B, NULL, deviceObj->evt_copyBr); - if (err != CL_SUCCESS) - { - fprintf(stderr, "Failed to copy vector B from device to host (OpenCL error code %d)!\n", err); - return; - } + if (openclError("Failed to copy vector B from device to host", err)) return; // Clock profilling end d2hCLK.end(); diff --git a/gpu4s_benchmark/finite_impulse_response_filter/opencl/lib_opencl.cpp b/gpu4s_benchmark/finite_impulse_response_filter/opencl/lib_opencl.cpp index 51f06bb5..67968540 100644 --- a/gpu4s_benchmark/finite_impulse_response_filter/opencl/lib_opencl.cpp +++ b/gpu4s_benchmark/finite_impulse_response_filter/opencl/lib_opencl.cpp @@ -67,18 +67,10 @@ void copy_memory_to_device(GraficCommon* device_object, bench_t* h_A, bench_t* k h2dCLK.start(); cl_int err = deviceObj->queue->enqueueWriteBuffer(*deviceObj->d_A,CL_TRUE,0,sizeof(bench_t)*size_a, h_A, NULL, deviceObj->evt_copyA); - if (err != CL_SUCCESS) - { - fprintf(stderr, "Failed to copy data vector B from host to device (OpenCL error code %d)!\n", err); - return; - } + if (openclError("Failed to copy data vector B from host to device", err)) return; err = deviceObj->queue->enqueueWriteBuffer(*deviceObj->kernel,CL_TRUE,0,sizeof(bench_t)*size_b, kernel, NULL, deviceObj->evt_copyB); - if (err != CL_SUCCESS) - { - fprintf(stderr, "Failed to copy kernel data from host to device (OpenCL error code %d)!\n", err); - return; - } + if (openclError("Failed to copy kernel data from host to device", err)) return; // Clock profilling end h2dCLK.end(); @@ -153,11 +145,7 @@ void copy_memory_to_host(GraficCommon* device_object, bench_t* h_C, int size){ d2hCLK.start(); cl_int err = deviceObj->queue->enqueueReadBuffer(*deviceObj->d_B, CL_TRUE, 0, sizeof(bench_t)*size, h_C, NULL, deviceObj->evt_copyC); - if (err != CL_SUCCESS) - { - fprintf(stderr, "Failed to copy vector B from device to host (OpenCL error code %d)!\n", err); - return; - } + if (openclError("Failed to copy vector B from device to host", err)) return; // Clock profilling end d2hCLK.end(); diff --git a/gpu4s_benchmark/matrix_multiplication_bench/opencl/lib_opencl_common.cpp b/gpu4s_benchmark/matrix_multiplication_bench/opencl/lib_opencl_common.cpp index a8902dbb..0773302a 100644 --- a/gpu4s_benchmark/matrix_multiplication_bench/opencl/lib_opencl_common.cpp +++ b/gpu4s_benchmark/matrix_multiplication_bench/opencl/lib_opencl_common.cpp @@ -74,19 +74,11 @@ void copy_memory_to_device(GraficCommon* device_object, bench_t* h_A, bench_t* h h2dCLK.start(); cl_int err = deviceObj->queue->enqueueWriteBuffer(*deviceObj->d_A,CL_TRUE,0,sizeof(bench_t)*size_a, h_A, NULL, deviceObj->evt_copyA); - if (err != CL_SUCCESS) - { - fprintf(stderr, "Failed to copy vector A from host to device (OpenCL error code %d)!\n", err); - return; - } + if (openclError("Failed to copy vector A from host to device", err)) return; // Enqueue writing host memory h_B to device buffer d_B err = deviceObj->queue->enqueueWriteBuffer(*deviceObj->d_B,CL_TRUE,0,sizeof(bench_t)*size_b, h_B, NULL, deviceObj->evt_copyB); - if (err != CL_SUCCESS) - { - fprintf(stderr, "Failed to copy vector B from host to device (OpenCL error code %d)!\n", err); - return; - } + if (openclError("Failed to copy vector B from host to device", err)) return; // Clock profilling end h2dCLK.end(); @@ -104,11 +96,7 @@ void copy_memory_to_host(GraficCommon* device_object, bench_t* h_C, int size){ d2hCLK.start(); cl_int err = deviceObj->queue->enqueueReadBuffer(*deviceObj->d_C, CL_TRUE, 0, sizeof(bench_t)*size, h_C, NULL, deviceObj->evt_copyC); - if (err != CL_SUCCESS) - { - fprintf(stderr, "Failed to copy vector C from device to host (OpenCL error code %d)!\n", err); - return; - } + if (openclError("Failed to copy vector C from device to host", err)) return; // Clock profilling end d2hCLK.end(); diff --git a/gpu4s_benchmark/matrix_multiplication_bench_fp16/opencl/lib_opencl_common.cpp b/gpu4s_benchmark/matrix_multiplication_bench_fp16/opencl/lib_opencl_common.cpp index 868f25ba..3831724e 100644 --- a/gpu4s_benchmark/matrix_multiplication_bench_fp16/opencl/lib_opencl_common.cpp +++ b/gpu4s_benchmark/matrix_multiplication_bench_fp16/opencl/lib_opencl_common.cpp @@ -6,6 +6,7 @@ * ESA-PL Strong Copyleft – v2.5 * ======================================================================= */ #include "../benchmark_library.h" +#include "../../common/opencl_common.hpp" #ifdef FLOAT16 cl::Kernel kernel_fp32_to_fp16; @@ -105,19 +106,11 @@ void copy_memory_to_device(GraficCommon* device_object, bench_t* h_A, bench_t* h // copy memory host -> device cl_int err = deviceObj->queue->enqueueWriteBuffer(*deviceObj->d_A,CL_TRUE,0,sizeof(bench_t)*size_a, h_A, NULL, deviceObj->evt_copyA); - if (err != CL_SUCCESS) - { - fprintf(stderr, "Failed to copy vector A from host to device (OpenCL error code %d)!\n", err); - return; - } + if (openclError("Failed to copy vector A from host to device", err)) return; // Enqueue writing host memory h_B to device buffer d_B err = deviceObj->queue->enqueueWriteBuffer(*deviceObj->d_B,CL_TRUE,0,sizeof(bench_t)*size_b, h_B, NULL, deviceObj->evt_copyB); - if (err != CL_SUCCESS) - { - fprintf(stderr, "Failed to copy vector B from host to device (OpenCL error code %d)!\n", err); - return; - } + if (openclError("Failed to copy vector B from host to device", err)) return; #ifdef FLOAT16 // --- Conver tto FP16 --- @@ -155,11 +148,7 @@ void copy_memory_to_host(GraficCommon* device_object, bench_t* h_C, int size){ #endif cl_int err = deviceObj->queue->enqueueReadBuffer(*deviceObj->d_C, CL_TRUE, 0, sizeof(bench_t)*size, h_C, NULL, deviceObj->evt_copyC); - if (err != CL_SUCCESS) - { - fprintf(stderr, "Failed to copy vector C from device to host (OpenCL error code %d)!\n", err); - return; - } + if (openclError("Failed to copy vector C from device to host", err)) return; // Clock profilling end d2hCLK.end(); diff --git a/gpu4s_benchmark/matrix_multiplication_bench_fp16/opencl/lib_opencl_lib.cpp b/gpu4s_benchmark/matrix_multiplication_bench_fp16/opencl/lib_opencl_lib.cpp index f509c6c4..34a4d3a1 100644 --- a/gpu4s_benchmark/matrix_multiplication_bench_fp16/opencl/lib_opencl_lib.cpp +++ b/gpu4s_benchmark/matrix_multiplication_bench_fp16/opencl/lib_opencl_lib.cpp @@ -44,11 +44,7 @@ void copy_memory_to_host(GraficCommon* device_object, bench_t* h_C, int size){ d2hCLK.start(); cl_int err = deviceObj->queue->enqueueReadBuffer(*deviceObj->d_C, CL_TRUE, 0, sizeof(bench_t)*size, h_C, NULL, deviceObj->evt_copyC); - if (err != CL_SUCCESS) - { - fprintf(stderr, "Failed to copy vector C from device to host (OpenCL error code %d)!\n", err); - return; - } + if (openclError("Failed to copy vector C from device to host", err)) return; // Clock profilling end d2hCLK.end(); diff --git a/gpu4s_benchmark/matrix_multiplication_tensor_bench/opencl/lib_opencl_common.cpp b/gpu4s_benchmark/matrix_multiplication_tensor_bench/opencl/lib_opencl_common.cpp index 9a68d7dc..8240dbbf 100644 --- a/gpu4s_benchmark/matrix_multiplication_tensor_bench/opencl/lib_opencl_common.cpp +++ b/gpu4s_benchmark/matrix_multiplication_tensor_bench/opencl/lib_opencl_common.cpp @@ -6,6 +6,7 @@ * ESA-PL Strong Copyleft – v2.5 * ======================================================================= */ #include "../benchmark_library.h" +#include "../../common/opencl_common.hpp" void init(GraficCommon* device_object, char* device_name){ init(device_object, 0,0, device_name); @@ -76,19 +77,11 @@ void copy_memory_to_device(GraficCommon* device_object, bench_t* h_A, bench_t* h // copy memory host -> device cl_int err = deviceObj->queue->enqueueWriteBuffer(*deviceObj->d_A,CL_TRUE,0,sizeof(bench_t)*size_a, h_A, NULL, deviceObj->evt_copyA); - if (err != CL_SUCCESS) - { - fprintf(stderr, "Failed to copy vector A from host to device (OpenCL error code %d)!\n", err); - return; - } + if (openclError("Failed to copy vector A from host to device", err)) return; // Enqueue writing host memory h_B to device buffer d_B err = deviceObj->queue->enqueueWriteBuffer(*deviceObj->d_B,CL_TRUE,0,sizeof(bench_t)*size_b, h_B, NULL, deviceObj->evt_copyB); - if (err != CL_SUCCESS) - { - fprintf(stderr, "Failed to copy vector B from host to device (OpenCL error code %d)!\n", err); - return; - } + if (openclError("Failed to copy vector B from host to device", err)) return; // Clock profilling end h2dCLK.end(); @@ -107,11 +100,7 @@ void copy_memory_to_host(GraficCommon* device_object, bench_t* h_C, int size){ d2hCLK.start(); cl_int err = deviceObj->queue->enqueueReadBuffer(*deviceObj->d_C, CL_TRUE, 0, sizeof(bench_t)*size, h_C, NULL, deviceObj->evt_copyC); - if (err != CL_SUCCESS) - { - fprintf(stderr, "Failed to copy vector C from device to host (OpenCL error code %d)!\n", err); - return; - } + if (openclError("Failed to copy vector C from device to host", err)) return; // Clock profilling end d2hCLK.end(); diff --git a/gpu4s_benchmark/max_pooling_bench/opencl/lib_opencl_common.cpp b/gpu4s_benchmark/max_pooling_bench/opencl/lib_opencl_common.cpp index 49d4ac6d..78b1792a 100644 --- a/gpu4s_benchmark/max_pooling_bench/opencl/lib_opencl_common.cpp +++ b/gpu4s_benchmark/max_pooling_bench/opencl/lib_opencl_common.cpp @@ -68,11 +68,7 @@ void copy_memory_to_device(GraficCommon* device_object, bench_t* h_A, unsigned i // Enqueue writing host memory h_A to device buffer d_A cl_int err = deviceObj->queue->enqueueWriteBuffer(*deviceObj->d_A,CL_TRUE,0,sizeof(bench_t)*size_a, h_A, NULL, deviceObj->evt_copyA); - if (err != CL_SUCCESS) - { - fprintf(stderr, "Failed to copy vector A from host to device (OpenCL error code %d)!\n", err); - return; - } + if (openclError("Failed to copy vector A from host to device", err)) return; // Clock profilling end h2dCLK.end(); @@ -90,11 +86,7 @@ void copy_memory_to_host(GraficCommon* device_object, bench_t* h_C, int size){ d2hCLK.start(); cl_int err = deviceObj->queue->enqueueReadBuffer(*deviceObj->d_B, CL_TRUE, 0, sizeof(bench_t)*size, h_C, NULL, deviceObj->evt_copyB); - if (err != CL_SUCCESS) - { - fprintf(stderr, "Failed to copy vector B from device to host (OpenCL error code %d)!\n", err); - return; - } + if (openclError("Failed to copy vector B from device to host", err)) return; // Clock profilling end d2hCLK.end(); diff --git a/gpu4s_benchmark/memory_bandwidth_bench/opencl/lib_opencl.cpp b/gpu4s_benchmark/memory_bandwidth_bench/opencl/lib_opencl.cpp index ac572476..18f01313 100644 --- a/gpu4s_benchmark/memory_bandwidth_bench/opencl/lib_opencl.cpp +++ b/gpu4s_benchmark/memory_bandwidth_bench/opencl/lib_opencl.cpp @@ -64,11 +64,7 @@ void copy_memory_to_device(GraficCommon* device_object, bench_t* h_A, unsigned i // Enqueue writing host memory h_A to device buffer d_A cl_int err = deviceObj->queue->enqueueWriteBuffer(*deviceObj->d_A,CL_TRUE,0,sizeof(bench_t)*size_a, h_A, NULL, deviceObj->evt_copyA); - if (err != CL_SUCCESS) - { - fprintf(stderr, "Failed to copy vector A from host to device (OpenCL error code %d)!\n", err); - return; - } + if (openclError("Failed to copy vector A from host to device", err)) return; // Clock profilling end h2dCLK.end(); @@ -106,11 +102,7 @@ void copy_memory_to_host(GraficCommon* device_object, bench_t* h_C, int size){ d2hCLK.start(); cl_int err = deviceObj->queue->enqueueReadBuffer(*deviceObj->d_B, CL_TRUE, 0, sizeof(bench_t)*size, h_C, NULL, deviceObj->evt_copyC); - if (err != CL_SUCCESS) - { - fprintf(stderr, "Failed to copy vector B from device to host (OpenCL error code %d)!\n", err); - return; - } + if (openclError("Failed to copy vector B from device to host", err)) return; // Clock profilling end d2hCLK.end(); diff --git a/gpu4s_benchmark/relu_bench/opencl/lib_opencl_common.cpp b/gpu4s_benchmark/relu_bench/opencl/lib_opencl_common.cpp index 76d0b94d..538d06f6 100644 --- a/gpu4s_benchmark/relu_bench/opencl/lib_opencl_common.cpp +++ b/gpu4s_benchmark/relu_bench/opencl/lib_opencl_common.cpp @@ -69,11 +69,7 @@ void copy_memory_to_device(GraficCommon* device_object, bench_t* h_A, unsigned i // Enqueue writing host memory h_A to device buffer d_A cl_int err = deviceObj->queue->enqueueWriteBuffer(*deviceObj->d_A,CL_TRUE,0,sizeof(bench_t)*size_a, h_A, NULL, deviceObj->evt_copyA); - if (err != CL_SUCCESS) - { - fprintf(stderr, "Failed to copy vector A from host to device (OpenCL error code %d)!\n", err); - return; - } + if (openclError("Failed to copy vector A from host to device", err)) return; // Clock profilling end h2dCLK.end(); @@ -92,11 +88,7 @@ void copy_memory_to_host(GraficCommon* device_object, bench_t* h_C, int size){ d2hCLK.start(); cl_int err = deviceObj->queue->enqueueReadBuffer(*deviceObj->d_B, CL_TRUE, 0, sizeof(bench_t)*size, h_C, NULL, deviceObj->evt_copyB); - if (err != CL_SUCCESS) - { - fprintf(stderr, "Failed to copy vector B from device to host (OpenCL error code %d)!\n", err); - return; - } + if (openclError("Failed to copy vector B from device to host", err)) return; // Clock profilling end d2hCLK.end(); diff --git a/gpu4s_benchmark/softmax_bench/opencl/lib_opencl_common.cpp b/gpu4s_benchmark/softmax_bench/opencl/lib_opencl_common.cpp index 764b1394..6df6d3f4 100644 --- a/gpu4s_benchmark/softmax_bench/opencl/lib_opencl_common.cpp +++ b/gpu4s_benchmark/softmax_bench/opencl/lib_opencl_common.cpp @@ -6,6 +6,7 @@ * ESA-PL Strong Copyleft – v2.5 * ======================================================================= */ #include "../benchmark_library.h" +#include "../../common/opencl_common.hpp" void init(GraficCommon* device_object, char* device_name){ init(device_object, 0,0, device_name); @@ -71,11 +72,7 @@ void copy_memory_to_device(GraficCommon* device_object, bench_t* h_A, unsigned i // Enqueue writing host memory h_A to device buffer d_A cl_int err = deviceObj->queue->enqueueWriteBuffer(*deviceObj->d_A,CL_TRUE,0,sizeof(bench_t)*size_a, h_A, NULL, deviceObj->evt_copyA); - if (err != CL_SUCCESS) - { - fprintf(stderr, "Failed to copy vector A from host to device (OpenCL error code %d)!\n", err); - return; - } + if (openclError("Failed to copy vector A from host to device", err)) return; // Clock profilling end h2dCLK.end(); @@ -96,15 +93,7 @@ void copy_memory_to_host(GraficCommon* device_object, bench_t* h_C, int size){ cl_int err = deviceObj->queue->enqueueReadBuffer(*deviceObj->d_B, CL_TRUE, 0, sizeof(bench_t)*size, h_C, NULL, deviceObj->evt_copyB); - if (err != CL_SUCCESS) - { - fprintf(stderr, "Failed to copy vector B from device to host (OpenCL error code %d)!\n", err); - - - return; - - - } + if (openclError("Failed to copy vector B from device to host", err)) return; // Clock profilling end d2hCLK.end(); diff --git a/gpu4s_benchmark/wavelet_transform/opencl/lib_opencl.cpp b/gpu4s_benchmark/wavelet_transform/opencl/lib_opencl.cpp index 6612b30d..43988395 100644 --- a/gpu4s_benchmark/wavelet_transform/opencl/lib_opencl.cpp +++ b/gpu4s_benchmark/wavelet_transform/opencl/lib_opencl.cpp @@ -78,28 +78,16 @@ void copy_memory_to_device(GraficCommon* device_object, bench_t* h_A, unsigned i h2dCLK.start(); cl_int err = deviceObj->queue->enqueueWriteBuffer(*deviceObj->d_A,CL_TRUE,0,sizeof(bench_t)*size_a, h_A, NULL, deviceObj->evt_copyA); - if (err != CL_SUCCESS) - { - fprintf(stderr, "Failed to copy vector A from host to device (OpenCL error code %d)!\n", err); - return; - } + if (openclError("Failed to copy vector A from host to device", err)) return; #ifdef INT // if int don't add the copy of the filters #else err = deviceObj->queue->enqueueWriteBuffer(*deviceObj->low_filter,CL_TRUE,0,sizeof(bench_t)*LOWPASSFILTERSIZE, lowpass_filter, NULL, deviceObj->evt_copyB); - if (err != CL_SUCCESS) - { - fprintf(stderr, "Failed to copy low_filter from host to device (OpenCL error code %d)!\n", err); - return; - } + if (openclError("Failed to copy low_filter from host to device", err)) return; err = deviceObj->queue->enqueueWriteBuffer(*deviceObj->high_filter,CL_TRUE,0,sizeof(bench_t)*HIGHPASSFILTERSIZE, highpass_filter, NULL, deviceObj->evt_copyC); - if (err != CL_SUCCESS) - { - fprintf(stderr, "Failed to copy high_filter from host to device (OpenCL error code %d)!\n", err); - return; - } + if (openclError("Failed to copy high_filter from host to device", err)) return; #endif // Clock profilling end @@ -196,11 +184,7 @@ void copy_memory_to_host(GraficCommon* device_object, bench_t* h_C, int size){ d2hCLK.start(); cl_int err = deviceObj->queue->enqueueReadBuffer(*deviceObj->d_B, CL_TRUE, 0, sizeof(bench_t)*size, h_C, NULL, deviceObj->evt_copyC); - if (err != CL_SUCCESS) - { - fprintf(stderr, "Failed to copy vector B from device to host (OpenCL error code %d)!\n", err); - return; - } + if (openclError("Failed to copy vector B from device to host", err)) return; // Clock profilling end d2hCLK.end(); From 057bcc70646f01cee3de53471556ce5d31f0462a Mon Sep 17 00:00:00 2001 From: Noah Perret Date: Thu, 13 Aug 2026 11:44:13 +0200 Subject: [PATCH 06/27] first UMA for 2D FFT --- .../benchmark_library.h | 11 +- .../fast_fourier_transform_2D_bench/main.cpp | 174 +++++++++++------- .../opencl/lib_opencl_lib.cpp | 101 ++++++++-- 3 files changed, 198 insertions(+), 88 deletions(-) diff --git a/gpu4s_benchmark/fast_fourier_transform_2D_bench/benchmark_library.h b/gpu4s_benchmark/fast_fourier_transform_2D_bench/benchmark_library.h index 64c10e35..65541e89 100644 --- a/gpu4s_benchmark/fast_fourier_transform_2D_bench/benchmark_library.h +++ b/gpu4s_benchmark/fast_fourier_transform_2D_bench/benchmark_library.h @@ -39,8 +39,8 @@ struct GraficObject : public GraficCommon { #endif #elif OPENCL // OpenCL PART + cl::Event *evt_copyA; cl::Event *evt_copyB; - cl::Event *evt_copyBr; cl::Event *evt; cl::Buffer *d_A; cl::Buffer *d_B; @@ -54,6 +54,13 @@ struct GraficObject : public GraficCommon { // --- Specefic overload of benchmarking function --- bool device_memory_init(GraficCommon* device_object, int64_t size_b_matrix); -void copy_memory_to_device(GraficCommon* device_object, COMPLEX **h_B,int64_t size); +void copy_memory_to_device(GraficCommon* device_object, COMPLEX **h_A,int64_t size); void execute_kernel(GraficCommon* device_object, int64_t n); void copy_memory_to_host(GraficCommon* device_object, COMPLEX **h_B, int64_t size); + + +#ifdef UMA_COMPATIBILITY +void get_unified_memory_pointers(GraficCommon* device_object, COMPLEX** &A, COMPLEX** &B, int64_t memSize); +void sync_unified_memory_to_device(GraficCommon* device_object, COMPLEX** &A, COMPLEX** &B, int64_t memSize); +void sync_unified_memory_to_host(GraficCommon* device_object, COMPLEX** &d_output, int64_t memSize); +#endif \ No newline at end of file diff --git a/gpu4s_benchmark/fast_fourier_transform_2D_bench/main.cpp b/gpu4s_benchmark/fast_fourier_transform_2D_bench/main.cpp index 397098fb..0ec21bbd 100644 --- a/gpu4s_benchmark/fast_fourier_transform_2D_bench/main.cpp +++ b/gpu4s_benchmark/fast_fourier_transform_2D_bench/main.cpp @@ -22,39 +22,70 @@ int main(int argc, char *argv[]){ /////////////////////////////////////////////////////////////////////////////////////////////// // Arguments /////////////////////////////////////////////////////////////////////////////////////////////// - int64_t size_A = 0; BenchmarkParameters *arguments_parameters = (BenchmarkParameters *)malloc(sizeof(BenchmarkParameters)); int resolution = arguments_handler(argc,argv,arguments_parameters); - if (resolution == ERROR_ARGUMENTS){ + if (resolution == ERROR_ARGUMENTS) + { exit(-1); } /////////////////////////////////////////////////////////////////////////////////////////////// // VARIABLES /////////////////////////////////////////////////////////////////////////////////////////////// // A input vector - size_A = arguments_parameters->size; + int64_t size_A = arguments_parameters->size; + int64_t mem_size = sizeof(COMPLEX*) * size_A; COMPLEX **A = (COMPLEX **)malloc(arguments_parameters->size * sizeof(COMPLEX*)); - for(int64_t i = 0; i < arguments_parameters->size; ++i) A[i] = (COMPLEX *)malloc(arguments_parameters->size * sizeof(COMPLEX)); + for(int64_t i = 0; i < arguments_parameters->size; ++i) A[i] = NULL; + + COMPLEX **d_B = (COMPLEX **)malloc(arguments_parameters->size * sizeof(COMPLEX*)); + for(int64_t i = 0; i < arguments_parameters->size; ++i) d_B[i] = NULL; COMPLEX **h_B = (COMPLEX **)malloc(arguments_parameters->size * sizeof(COMPLEX*)); - for(int64_t i = 0; i < arguments_parameters->size; ++i){ h_B[i] = (COMPLEX *)malloc(arguments_parameters->size * sizeof(COMPLEX));} + for(int64_t i = 0; i < arguments_parameters->size; ++i) h_B[i] = (COMPLEX *)malloc(arguments_parameters->size * sizeof(COMPLEX)); + + // init devices + char device[100] = ""; + + // main object init + GraficCommon* fft_bench = (GraficCommon*)malloc(sizeof(GraficObject)); + + // --- 1. Init Device & Context --- + init(fft_bench, 0,arguments_parameters->gpu, device); + // Update profiling clock mode + fft_bench->profiling_clock = arguments_parameters->profiling_clock; + + // --- 2. Allocate Device Memory --- + device_memory_init(fft_bench, size_A); + + // --- 3. Allocate Host Pointers --- + if (arguments_parameters->unified_memory) + { + #ifdef UMA_COMPATIBILITY + // map the buffzer to the gpu + cpu take the lead + get_unified_memory_pointers(fft_bench, A, d_B, size_A); + #else + fprintf(stderr, "\033[1;31merror:\033[0m This framework is not compatible with unified memory. Please remove the -u arg!\n"); + exit(-1); + #endif + } else + { + // normale malloc + A = (COMPLEX **)malloc(arguments_parameters->size * sizeof(COMPLEX*)); + for(int64_t i = 0; i < arguments_parameters->size; ++i) A[i] = (COMPLEX *)malloc(arguments_parameters->size * sizeof(COMPLEX)); + + d_B = (COMPLEX **)malloc(arguments_parameters->size * sizeof(COMPLEX*)); + for(int64_t i = 0; i < arguments_parameters->size; ++i) d_B[i] = (COMPLEX *)malloc(arguments_parameters->size * sizeof(COMPLEX)); + } - COMPLEX **d_B = (COMPLEX **)malloc(arguments_parameters->size * sizeof(COMPLEX*)); - for(int64_t i = 0; i < arguments_parameters->size; ++i){ d_B[i] = (COMPLEX *)malloc(arguments_parameters->size * sizeof(COMPLEX));} - // comparation result - bool result = false; /////////////////////////////////////////////////////////////////////////////////////////////// // DATA INIT /////////////////////////////////////////////////////////////////////////////////////////////// if (strlen(arguments_parameters->input_file) == 0) { // inicialice A matrix - for (int i=0; isize; ++i) - { - for (int j=0; jsize; ++j) - { - + for (int i=0; isize; ++i){ + for (int j=0; jsize; ++j){ A[i][j].x = (bench_t)rand()/(bench_t)(RAND_MAX/NUMBER_BASE); A[i][j].y = 0; @@ -66,10 +97,10 @@ int main(int argc, char *argv[]){ h_B[i][j].y = A[i][j].y; } - if (arguments_parameters->print_input) - { - printf("\n"); - } + // if (arguments_parameters->print_input) + // { + // printf("\n"); + // } } } @@ -82,86 +113,93 @@ int main(int argc, char *argv[]){ /////////////////////////////////////////////////////////////////////////////////////////////// // CODE BENCKMARK /////////////////////////////////////////////////////////////////////////////////////////////// - // copy A to B - // base object init - GraficCommon* fft_bench = (GraficCommon*)malloc(sizeof(GraficObject)); - // init devices - char device[100] = ""; - init(fft_bench, 0,arguments_parameters->gpu, device); - if (!arguments_parameters->csv_format_timestamp && !arguments_parameters->csv_format && !arguments_parameters->mute_messages ){ + if (!arguments_parameters->csv_format_timestamp && !arguments_parameters->csv_format && !arguments_parameters->mute_messages ) + { printf("Using device: %s\n", device); } - // Update profiling clock mode - fft_bench->profiling_clock = arguments_parameters->profiling_clock; - - // If android and opencl force profiling clock - #ifdef FORCE_PROFILING_CLOCK - fft_bench->profiling_clock = true; - #endif - - // init memory - device_memory_init(fft_bench, size_A); // copy memory to device - copy_memory_to_device(fft_bench, A, size_A); + if(arguments_parameters->unified_memory) + { + #ifdef UMA_COMPATIBILITY + sync_unified_memory_to_device(fft_bench, A, d_B, size_A); + #endif + } else + { + copy_memory_to_device(fft_bench, A, size_A); + } + // execute kernel - //Fix: add a static cast so the compiler select the right overload function - execute_kernel(fft_bench, static_cast(arguments_parameters->size)); + execute_kernel(fft_bench, size_A); + // copy memory to host - copy_memory_to_host(fft_bench, d_B, arguments_parameters->size); + if (arguments_parameters->unified_memory) + { + #ifdef UMA_COMPATIBILITY + sync_unified_memory_to_host(fft_bench, d_B, size_A); + #endif + } else + { + copy_memory_to_host(fft_bench, d_B, arguments_parameters->size); + } // get time if (arguments_parameters->print_timing || arguments_parameters->csv_format || arguments_parameters->csv_format_timestamp) { get_elapsed_time(fft_bench, arguments_parameters->csv_format, arguments_parameters->csv_format_timestamp, get_timestamp()); } + + // print output buffer if (arguments_parameters->print_output) { - for (int i=0; isize; ++i) - { - for (int j=0; jsize; ++j) - { - printf("%f %f,",d_B[i][j].x, d_B[i][j].y); - } - printf("\n"); - } + for (int i=0; isize; ++i){ + for (int j=0; jsize; ++j){ + printf("%f %f,",d_B[i][j].x, d_B[i][j].y); + } + printf("\n"); + } + } + + // export gpu buffer + if (arguments_parameters->export_results_gpu) + { + //print_double_hexadecimal_values(GPU_FILE, d_B, size_B); } + //check for error if (arguments_parameters->verification) { Clock cpuKernelCLK; cpuKernelCLK.start(); - FFT2D(A,arguments_parameters->size,arguments_parameters->size,h_B); + FFT2D(A, size_A, size_A, h_B); cpuKernelCLK.end(); + if (arguments_parameters->print_timing) { printf("CPU Time %.0f milliseconds\n", cpuKernelCLK.getElapsedMS()); } + if (arguments_parameters->print_output) { //result = compare_vectors(h_B, d_B, size_A); - for (int i=0; isize; ++i) - { - for (int j=0; jsize; ++j) - { - printf("%f %f,",h_B[i][j].x, h_B[i][j].y); + for (int i=0; isize; ++i){ + for (int j=0; jsize; ++j){ + printf("%f %f,",h_B[i][j].x, h_B[i][j].y); } - printf("\n"); + printf("\n"); } } - result = compare_vectors(h_B, d_B, size_A); - if (result){ + + if (compare_vectors(h_B, d_B, size_A)) + { printf("OK\n"); } - if (arguments_parameters->export_results){ + + if (arguments_parameters->export_results) + { //print_double_hexadecimal_values(GPU_FILE, d_B, size_B); //print_double_hexadecimal_values(CPU_FILE, h_B, size_B); } - - } - if (arguments_parameters->export_results_gpu) - { - //print_double_hexadecimal_values(GPU_FILE, d_B, size_B); } /////////////////////////////////////////////////////////////////////////////////////////////// // CLEAN MEMORY @@ -171,16 +209,20 @@ int main(int argc, char *argv[]){ // free object memory free(fft_bench); free(arguments_parameters); - free(A); - free(d_B); + + if (!arguments_parameters->unified_memory) + { + free(A); + free(d_B); + } + free(h_B); -return 0; + return 0; } // Arguments part - void print_usage(const char * appName) { printf("Usage: %s -s Size [-w] [-v] [-e] [-o] [-t] [-c] [-d] [-i input_file_A_MATRIX ] \n", appName); diff --git a/gpu4s_benchmark/fast_fourier_transform_2D_bench/opencl/lib_opencl_lib.cpp b/gpu4s_benchmark/fast_fourier_transform_2D_bench/opencl/lib_opencl_lib.cpp index b0f367bd..a2ad0c15 100644 --- a/gpu4s_benchmark/fast_fourier_transform_2D_bench/opencl/lib_opencl_lib.cpp +++ b/gpu4s_benchmark/fast_fourier_transform_2D_bench/opencl/lib_opencl_lib.cpp @@ -1,6 +1,7 @@ // OpenCL lib code #include #include "../benchmark_library.h" +#include "../../common/opencl_common.hpp" #include "vkFFT.h" void init(GraficCommon* device_object, char* device_name){ @@ -34,8 +35,8 @@ void init(GraficCommon* device_object, int platform ,int device, char* device_na // events deviceObj->evt = new cl::Event; + deviceObj->evt_copyA = new cl::Event; deviceObj->evt_copyB = new cl::Event; - deviceObj->evt_copyBr = new cl::Event; } bool device_memory_init(GraficCommon* device_object, int64_t size){ @@ -52,7 +53,7 @@ bool device_memory_init(GraficCommon* device_object, int64_t size){ return true; } -void copy_memory_to_device(GraficCommon *device_object, COMPLEX **h_B,int64_t size){ +void copy_memory_to_device(GraficCommon *device_object, COMPLEX **h_A,int64_t size){ GraficObject* deviceObj = static_cast(device_object); // --- init --- bench_t *h_signal = (bench_t *)malloc(sizeof(bench_t) * size * size * 2); @@ -60,8 +61,8 @@ void copy_memory_to_device(GraficCommon *device_object, COMPLEX **h_B,int64_t si { for (int j=0; j device - deviceObj->queue->enqueueWriteBuffer(*deviceObj->d_A,CL_TRUE,0,sizeof(bench_t)*size*size*2, h_signal, NULL, deviceObj->evt_copyB); + deviceObj->queue->enqueueWriteBuffer(*deviceObj->d_A,CL_TRUE,0,sizeof(bench_t)*size*size*2, h_signal, NULL, deviceObj->evt_copyA); // Clock profilling end h2dCLK.end(); @@ -149,7 +150,7 @@ void copy_memory_to_host(GraficCommon* device_object, COMPLEX **h_B, int64_t siz // Clock profilling start d2hCLK.start(); - cl_int err = deviceObj->queue->enqueueReadBuffer(*deviceObj->d_B, CL_TRUE, 0, sizeof(bench_t)*size*size * 2, h_signal, NULL, deviceObj->evt_copyBr); + cl_int err = deviceObj->queue->enqueueReadBuffer(*deviceObj->d_B, CL_TRUE, 0, sizeof(bench_t)*size*size * 2, h_signal, NULL, deviceObj->evt_copyB); if (openclError("Failed to copy vector B from device to host", err)) return; // Clock profilling end @@ -158,20 +159,18 @@ void copy_memory_to_host(GraficCommon* device_object, COMPLEX **h_B, int64_t siz // store the hd2h time deviceObj->d2h_elapsed_time = d2hCLK.getElapsedNS(); - for (int i=0; i(device_object); - deviceObj->evt_copyBr->wait(); + deviceObj->evt_copyB->wait(); float elapsed_h_d = 0, elapsed = 0, elapsed_d_h = 0; @@ -182,9 +181,9 @@ float get_elapsed_time(GraficCommon* device_object, bool csv_format, bool csv_fo elapsed = deviceObj->elapsed_time; elapsed_d_h = deviceObj->d2h_elapsed_time; }else{ - elapsed_h_d = deviceObj->evt_copyB->getProfilingInfo() - deviceObj->evt_copyB->getProfilingInfo(); + elapsed_h_d = deviceObj->evt_copyA->getProfilingInfo() - deviceObj->evt_copyA->getProfilingInfo(); //printf("Elapsed time Host->Device: %.10f \n", elapsed / 1000000.0); - elapsed_d_h = deviceObj->evt_copyBr->getProfilingInfo() - deviceObj->evt_copyBr->getProfilingInfo(); + elapsed_d_h = deviceObj->evt_copyB->getProfilingInfo() - deviceObj->evt_copyB->getProfilingInfo(); //printf("Elapsed time Device->Host: %.10f \n", ); elapsed = deviceObj->elapsed_time; } @@ -207,12 +206,74 @@ float get_elapsed_time(GraficCommon* device_object, bool csv_format, bool csv_fo void clean(GraficCommon* device_object){ GraficObject* deviceObj = static_cast(device_object); // pointers clean - //delete deviceObj->context; - //delete deviceObj->queue; // pointer to memory delete deviceObj->d_A; delete deviceObj->d_B; delete deviceObj->evt; + delete deviceObj->evt_copyA; delete deviceObj->evt_copyB; - delete deviceObj->evt_copyBr; -} \ No newline at end of file +} + + +#ifdef UMA_COMPATIBILITY +// ====== UMA function ====== +void get_unified_memory_pointers(GraficCommon* device_object, COMPLEX** &A, COMPLEX** &B, int64_t memSize){ + GraficObject* deviceObj = static_cast(device_object); + int64_t flatSize = sizeof(bench_t) * memSize * memSize * 2; + + // Map temp flat buffer + bench_t* tmp_flat_A = nullptr; + bench_t* tmp_flat_B = nullptr; + + // --- Call the openCL common function --- + map_unified_memory(device_object, flatSize, + BufferMapCL{&tmp_flat_A, deviceObj->d_A, nullptr}, + BufferMapCL{&tmp_flat_B, deviceObj->d_B, nullptr} + ); + + // --- Cast back to bench_t --- + COMPLEX* flat_A = (COMPLEX*)tmp_flat_A; + COMPLEX* flat_B = (COMPLEX*)tmp_flat_B; + + // --- 2D -> 1D --- + //Connect ptr 2D array to the flat ptr + for (int i = 0; i < memSize; ++i){ + A[i] = flat_A + (i * memSize); + B[i] = flat_B + (i * memSize); + } +} + +void sync_unified_memory_to_device(GraficCommon* device_object, COMPLEX** &A, COMPLEX** &B, int64_t memSize){ + GraficObject* deviceObj = static_cast(device_object); + + bench_t* tmp_flat_A = (bench_t*)A[0]; + bench_t* tmp_flat_B = (bench_t*)B[0]; + + // --- Call the openCL common function --- + unmap_unified_memory(device_object, + BufferMapCL{&tmp_flat_A, deviceObj->d_A, deviceObj->evt_copyA}, + BufferMapCL{&tmp_flat_B, deviceObj->d_B, nullptr} + ); +} + + +void sync_unified_memory_to_host(GraficCommon* device_object, COMPLEX** &d_output, int64_t memSize){ + GraficObject* deviceObj = static_cast(device_object); + int64_t flatSize = sizeof(bench_t) * memSize * memSize * 2; + + bench_t* tmp_flat_B = nullptr; + + // --- Call the openCL common function --- + map_unified_memory_to_host(device_object, flatSize, + BufferMapCL{&tmp_flat_B, deviceObj->d_B, deviceObj->evt_copyB} + ); + + // --- Cast back to bench_t --- + COMPLEX* flat_B = (COMPLEX*)tmp_flat_B; + + // Reconnect the 2D pointer array to the newly mapped output memory + for (int i = 0; i < memSize; ++i){ + d_output[i] = flat_B + (i * memSize); + } +} +#endif \ No newline at end of file From dee328b2841fca981a9c33e51d9f65967acef6da Mon Sep 17 00:00:00 2001 From: Noah Perret Date: Thu, 13 Aug 2026 12:28:01 +0200 Subject: [PATCH 07/27] implementation of UMA in FFT bench --- .../fast_fourier_transform_bench/main.cpp | 143 +++++++++++------- .../opencl/lib_opencl_common.cpp | 31 ++++ .../opencl/lib_opencl_lib.cpp | 2 +- 3 files changed, 123 insertions(+), 53 deletions(-) diff --git a/gpu4s_benchmark/fast_fourier_transform_bench/main.cpp b/gpu4s_benchmark/fast_fourier_transform_bench/main.cpp index 4f89b5ab..647230a6 100644 --- a/gpu4s_benchmark/fast_fourier_transform_bench/main.cpp +++ b/gpu4s_benchmark/fast_fourier_transform_bench/main.cpp @@ -24,31 +24,56 @@ int main(int argc, char *argv[]){ BenchmarkParameters *arguments_parameters = (BenchmarkParameters *)malloc(sizeof(BenchmarkParameters)); int resolution = arguments_handler(argc,argv,arguments_parameters); - if (resolution == ERROR_ARGUMENTS){ + if (resolution == ERROR_ARGUMENTS) + { exit(-1); } /////////////////////////////////////////////////////////////////////////////////////////////// // VARIABLES /////////////////////////////////////////////////////////////////////////////////////////////// // A input vector - int64_t size_A = arguments_parameters->size; - int64_t mem_size_A = sizeof(bench_t) * size_A; - bench_t* A = (bench_t*) malloc(mem_size_A); - - int64_t size_B = arguments_parameters->size; - int64_t mem_size_B = sizeof(bench_t) * size_B; - bench_t* h_B = (bench_t*) malloc(mem_size_B); - bench_t* d_B = (bench_t*) malloc(mem_size_B); + int64_t size = arguments_parameters->size; + int64_t mem_size = sizeof(bench_t) * size; + bench_t* A = (bench_t*) malloc(mem_size); + bench_t* d_B = nullptr; + bench_t* h_B = (bench_t*) malloc(mem_size); bench_t aux_value = 0; - // comparation result - bool result = false; + char device[100] = ""; + + // main object init + GraficCommon*fft_bench = (GraficCommon*)malloc(sizeof(GraficObject)); + + // --- 1. Init Device & Context --- + init(fft_bench, 0,arguments_parameters->gpu, device); + // Update profiling clock mode + fft_bench->profiling_clock = arguments_parameters->profiling_clock; + + // --- 2. Allocate Device Memory --- + device_memory_init(fft_bench, size); + + // --- 3. Allocate Host Pointers --- + if (arguments_parameters->unified_memory) + { + #ifdef UMA_COMPATIBILITY + // map the buffzer to the gpu + cpu take the lead + get_unified_memory_pointers(fft_bench, d_B, mem_size); + #else + fprintf(stderr, "\033[1;31merror:\033[0m This framework is not compatible with unified memory. Please remove the -u arg!\n"); + exit(-1); + #endif + } else + { + // normale malloc + d_B = (bench_t*) malloc(mem_size); + } + /////////////////////////////////////////////////////////////////////////////////////////////// // DATA INIT /////////////////////////////////////////////////////////////////////////////////////////////// if (strlen(arguments_parameters->input_file) == 0) { // inicialice A matrix - for (int i=0; iinput_file, A,size_A); + get_double_hexadecimal_values(arguments_parameters->input_file, A, size); } /////////////////////////////////////////////////////////////////////////////////////////////// // CODE BENCKMARK /////////////////////////////////////////////////////////////////////////////////////////////// // copy A to B - for (unsigned int i = 0; i < size_A; ++i) + for (unsigned int i = 0; i < size; ++i) { h_B[i] = A[i]; d_B[i] = A[i]; } - // base object init - GraficCommon*fft_bench = (GraficCommon*)malloc(sizeof(GraficObject)); - // init devices - char device[100] = ""; - init(fft_bench, 0,arguments_parameters->gpu, device); + if (!arguments_parameters->csv_format_timestamp && !arguments_parameters->csv_format && !arguments_parameters->mute_messages ){ printf("Using device: %s\n", device); } - // Update profiling clock mode - fft_bench->profiling_clock = arguments_parameters->profiling_clock; - - // If android and opencl force profiling clock - #ifdef FORCE_PROFILING_CLOCK - fft_bench->profiling_clock = true; - #endif - // init memory - device_memory_init(fft_bench, size_B); // copy memory to device - copy_memory_to_device(fft_bench, d_B, size_B); + if(arguments_parameters->unified_memory) + { + #ifdef UMA_COMPATIBILITY + sync_unified_memory_to_device(fft_bench, d_B); + #endif + } + else + { + copy_memory_to_device(fft_bench, d_B, size); + } + // execute kernel - //FIX: cast the size to select the good protytpe - execute_kernel(fft_bench, (int64_t)arguments_parameters->size>>1); + execute_kernel(fft_bench, size>>1); + // copy memory to host - copy_memory_to_host(fft_bench, d_B, size_B); + if (arguments_parameters->unified_memory) + { + #ifdef UMA_COMPATIBILITY + sync_unified_memory_to_host(fft_bench, d_B, mem_size); + #endif + } else + { + copy_memory_to_host(fft_bench, d_B, size); + + } // get time if (arguments_parameters->print_timing || arguments_parameters->csv_format || arguments_parameters->csv_format_timestamp) { get_elapsed_time(fft_bench, arguments_parameters->csv_format, arguments_parameters->csv_format_timestamp, get_timestamp()); } + + // print output buffer if (arguments_parameters->print_output) { - for (int i=0; iexport_results_gpu) + { + print_double_hexadecimal_values(GPU_FILE, d_B, size); + } + //check for error if (arguments_parameters->verification) { Clock cpuKernelCLK; @@ -144,41 +180,44 @@ int main(int argc, char *argv[]){ } if (arguments_parameters->print_output) { - for (int i=0; iexport_results){ - print_double_hexadecimal_values(GPU_FILE, d_B, size_B); - print_double_hexadecimal_values(CPU_FILE, h_B, size_B); + if (arguments_parameters->export_results) + { + print_double_hexadecimal_values(GPU_FILE, d_B, size); + print_double_hexadecimal_values(CPU_FILE, h_B, size); } } - if (arguments_parameters->export_results_gpu) - { - print_double_hexadecimal_values(GPU_FILE, d_B, size_B); - } /////////////////////////////////////////////////////////////////////////////////////////////// // CLEAN MEMORY /////////////////////////////////////////////////////////////////////////////////////////////// // clean device memory clean(fft_bench); - free(arguments_parameters); // free object memory free(fft_bench); - free(A); - free(d_B); + free(arguments_parameters); + + if (!arguments_parameters->unified_memory) + { + free(A); + free(d_B); + } + free(h_B); -return 0; + return 0; } diff --git a/gpu4s_benchmark/fast_fourier_transform_bench/opencl/lib_opencl_common.cpp b/gpu4s_benchmark/fast_fourier_transform_bench/opencl/lib_opencl_common.cpp index 78346b63..31c23a48 100644 --- a/gpu4s_benchmark/fast_fourier_transform_bench/opencl/lib_opencl_common.cpp +++ b/gpu4s_benchmark/fast_fourier_transform_bench/opencl/lib_opencl_common.cpp @@ -147,3 +147,34 @@ void clean(GraficCommon* device_object){ delete deviceObj->evt_copyB; delete deviceObj->evt_copyBr; } + + + +#ifdef UMA_COMPATIBILITY +// ====== UMA function ====== +void get_unified_memory_pointers(GraficCommon* device_object, bench_t* &A, unsigned int memSize){ + GraficObject* deviceObj = static_cast(device_object); + // --- Call the openCL common function --- + map_unified_memory(device_object, memSize, + BufferMapCL{&A, deviceObj->d_B, nullptr} + ); +} + +void sync_unified_memory_to_device(GraficCommon* device_object, bench_t* &A){ + GraficObject* deviceObj = static_cast(device_object); + // --- Call the openCL common function --- + unmap_unified_memory(device_object, + BufferMapCL{&A, deviceObj->d_B, deviceObj->evt_copyB} + ); +} + + +void sync_unified_memory_to_host(GraficCommon* device_object, bench_t* &d_output, unsigned int memSize){ + GraficObject* deviceObj = static_cast(device_object); + // --- Call the openCL common function --- + map_unified_memory_to_host(device_object, memSize, + BufferMapCL{&d_output, deviceObj->d_Br, deviceObj->evt_copyBr} + ); +} + +#endif \ No newline at end of file diff --git a/gpu4s_benchmark/fast_fourier_transform_bench/opencl/lib_opencl_lib.cpp b/gpu4s_benchmark/fast_fourier_transform_bench/opencl/lib_opencl_lib.cpp index 9303b5c1..0abf881e 100644 --- a/gpu4s_benchmark/fast_fourier_transform_bench/opencl/lib_opencl_lib.cpp +++ b/gpu4s_benchmark/fast_fourier_transform_bench/opencl/lib_opencl_lib.cpp @@ -66,7 +66,7 @@ float get_elapsed_time(GraficCommon* device_object, bool csv_format, bool csv_fo }else{ elapsed_h_d = deviceObj->evt_copyB->getProfilingInfo() - deviceObj->evt_copyB->getProfilingInfo(); //printf("Elapsed time Host->Device: %.10f \n", elapsed / 1000000.0); - + elapsed = deviceObj->elapsed_time; //printf("Elapsed time kernel: %.10f \n", elapsed / 1000000.0); elapsed_d_h = deviceObj->evt_copyBr->getProfilingInfo() - deviceObj->evt_copyBr->getProfilingInfo(); From 2d41e22b60ecb96567d9fa55f3e7c15759d3df66 Mon Sep 17 00:00:00 2001 From: Noah Perret Date: Thu, 13 Aug 2026 13:15:54 +0200 Subject: [PATCH 08/27] add UMA on fft windows bench --- .../benchmark_library.h | 2 +- .../main.cpp | 118 ++++++++++++------ .../opencl/lib_opencl_common.cpp | 43 +++++-- .../opencl/lib_opencl_lib.cpp | 9 +- 4 files changed, 121 insertions(+), 51 deletions(-) diff --git a/gpu4s_benchmark/fast_fourier_transform_window_bench/benchmark_library.h b/gpu4s_benchmark/fast_fourier_transform_window_bench/benchmark_library.h index 750d4f13..6a4f79f0 100644 --- a/gpu4s_benchmark/fast_fourier_transform_window_bench/benchmark_library.h +++ b/gpu4s_benchmark/fast_fourier_transform_window_bench/benchmark_library.h @@ -33,8 +33,8 @@ struct GraficObject : public GraficCommon { #endif #elif OPENCL // OpenCL PART + cl::Event *evt_copyA; cl::Event *evt_copyB; - cl::Event *evt_copyBr; cl::Event *evt; cl::Event *evt_end; cl::Buffer *d_A; diff --git a/gpu4s_benchmark/fast_fourier_transform_window_bench/main.cpp b/gpu4s_benchmark/fast_fourier_transform_window_bench/main.cpp index 257de2d6..511da054 100644 --- a/gpu4s_benchmark/fast_fourier_transform_window_bench/main.cpp +++ b/gpu4s_benchmark/fast_fourier_transform_window_bench/main.cpp @@ -24,7 +24,8 @@ int main(int argc, char *argv[]){ BenchmarkParameters *arguments_parameters = (BenchmarkParameters *)malloc(sizeof(BenchmarkParameters)); int resolution = arguments_handler(argc,argv,arguments_parameters); - if (resolution == ERROR_ARGUMENTS){ + if (resolution == ERROR_ARGUMENTS) + { exit(-1); } /////////////////////////////////////////////////////////////////////////////////////////////// @@ -33,24 +34,52 @@ int main(int argc, char *argv[]){ // A input vector int64_t size_A = arguments_parameters->size; int64_t mem_size_A = sizeof(bench_t) * size_A; - bench_t* A = (bench_t*) malloc(mem_size_A); + bench_t* A = nullptr; // B output vector int64_t size_B = ((arguments_parameters->size - arguments_parameters->window) + 1) * arguments_parameters->window; int64_t mem_size_B = sizeof(bench_t) * size_B; + bench_t* d_B = nullptr; bench_t* h_B = (bench_t*) malloc(mem_size_B); - bench_t* d_B = (bench_t*) malloc(mem_size_B); - bench_t aux_value = 0; - // comparation result - bool result = false; + // init devices + char device[100] = ""; + + // main object init + GraficCommon*fft_bench = (GraficCommon*)malloc(sizeof(GraficObject)); + + // --- 1. Init Device & Context --- + init(fft_bench, 0,arguments_parameters->gpu, device); + // Update profiling clock mode + fft_bench->profiling_clock = arguments_parameters->profiling_clock; + + // --- 2. Allocate Device Memory --- + device_memory_init(fft_bench, size_A ,size_B); + + + // --- 3. Allocate Host Pointers --- + if (arguments_parameters->unified_memory) + { + #ifdef UMA_COMPATIBILITY + // map the buffzer to the gpu + cpu take the lead + get_unified_memory_pointers(fft_bench, A, mem_size_A); + #else + fprintf(stderr, "\033[1;31merror:\033[0m This framework is not compatible with unified memory. Please remove the -u arg!\n"); + exit(-1); + #endif + } else + { + // normale malloc + A = (bench_t*) malloc(mem_size_A); + d_B = (bench_t*) malloc(mem_size_B); + } + /////////////////////////////////////////////////////////////////////////////////////////////// // DATA INIT /////////////////////////////////////////////////////////////////////////////////////////////// if (strlen(arguments_parameters->input_file_A) == 0) { - // inicialice A matrix - for (int i=0; igpu, device); if (!arguments_parameters->csv_format_timestamp && !arguments_parameters->csv_format && !arguments_parameters->mute_messages ){ printf("Using device: %s\n", device); } - - // Update profiling clock mode - fft_bench->profiling_clock = arguments_parameters->profiling_clock; - - // If android and opencl force profiling clock - #ifdef FORCE_PROFILING_CLOCK - fft_bench->profiling_clock = true; - #endif - // init memory - device_memory_init(fft_bench, size_A ,size_B); // copy memory to device - copy_memory_to_device(fft_bench, A, size_A); + if(arguments_parameters->unified_memory) + { + #ifdef UMA_COMPATIBILITY + sync_unified_memory_to_device(fft_bench, A); + #endif + } + else + { + copy_memory_to_device(fft_bench, A, size_A); + } + // execute kernel execute_kernel(fft_bench, arguments_parameters->window, arguments_parameters->size>>1); + // copy memory to host - copy_memory_to_host(fft_bench, d_B, size_B); + if (arguments_parameters->unified_memory) + { + #ifdef UMA_COMPATIBILITY + sync_unified_memory_to_host(fft_bench, d_B, size_B); + #endif + } else + { + copy_memory_to_host(fft_bench, d_B, size_B); + } + // get time if (arguments_parameters->print_timing || arguments_parameters->csv_format || arguments_parameters->csv_format_timestamp) { get_elapsed_time(fft_bench, arguments_parameters->csv_format, arguments_parameters->csv_format_timestamp, get_timestamp()); } + + // print output buffer if (arguments_parameters->print_output) { for (int i=0; iexport_results_gpu) + { + print_double_hexadecimal_values(GPU_FILE, d_B, size_B); + } + //check for error if (arguments_parameters->verification) { Clock cpuKernelCLK; cpuKernelCLK.start(); fft_function(A ,h_B , arguments_parameters->window ,arguments_parameters->size>>1); cpuKernelCLK.end(); + if (arguments_parameters->print_timing) { printf("CPU Time %.1f milliseconds\n", cpuKernelCLK.getElapsedMS()); } + if (arguments_parameters->print_output) { for (int i=0; iexport_results){ print_double_hexadecimal_values(GPU_FILE, d_B, size_B); print_double_hexadecimal_values(CPU_FILE, h_B, size_B); } } - if (arguments_parameters->export_results_gpu) - { - print_double_hexadecimal_values(GPU_FILE, d_B, size_B); - } /////////////////////////////////////////////////////////////////////////////////////////////// // CLEAN MEMORY /////////////////////////////////////////////////////////////////////////////////////////////// @@ -176,8 +211,11 @@ int main(int argc, char *argv[]){ // free object memory free(fft_bench); free(arguments_parameters); - free(A); - free(d_B); + if (!arguments_parameters->unified_memory) + { + free(A); + free(d_B); + } free(h_B); return 0; } diff --git a/gpu4s_benchmark/fast_fourier_transform_window_bench/opencl/lib_opencl_common.cpp b/gpu4s_benchmark/fast_fourier_transform_window_bench/opencl/lib_opencl_common.cpp index fe17e59f..44f6d0ef 100644 --- a/gpu4s_benchmark/fast_fourier_transform_window_bench/opencl/lib_opencl_common.cpp +++ b/gpu4s_benchmark/fast_fourier_transform_window_bench/opencl/lib_opencl_common.cpp @@ -40,8 +40,8 @@ void init(GraficCommon* device_object, int platform ,int device, char* device_na // events deviceObj->evt = new cl::Event; deviceObj->evt_end = new cl::Event; + deviceObj->evt_copyA = new cl::Event; deviceObj->evt_copyB = new cl::Event; - deviceObj->evt_copyBr = new cl::Event; } bool device_memory_init(GraficCommon* device_object, int64_t size_a_array, int64_t size_b_array){ @@ -66,7 +66,7 @@ void copy_memory_to_device(GraficCommon* device_object, bench_t* h_A,int64_t siz // Clock profilling start h2dCLK.start(); - cl_int err = deviceObj->queue->enqueueWriteBuffer(*deviceObj->d_A,CL_TRUE,0,sizeof(bench_t)*size, h_A, NULL, deviceObj->evt_copyB); + cl_int err = deviceObj->queue->enqueueWriteBuffer(*deviceObj->d_A,CL_TRUE,0,sizeof(bench_t)*size, h_A, NULL, deviceObj->evt_copyA); if (openclError("Failed to copy data vector A from host to device", err)) return; // Clock profilling end @@ -85,7 +85,7 @@ void copy_memory_to_host(GraficCommon* device_object, bench_t* h_B, int64_t size // Clock profilling start d2hCLK.start(); - cl_int err = deviceObj->queue->enqueueReadBuffer(*deviceObj->d_B, CL_TRUE, 0, sizeof(bench_t)*size, h_B, NULL, deviceObj->evt_copyBr); + cl_int err = deviceObj->queue->enqueueReadBuffer(*deviceObj->d_B, CL_TRUE, 0, sizeof(bench_t)*size, h_B, NULL, deviceObj->evt_copyB); if (openclError("Failed to copy vector B from device to host", err)) return; // Clock profilling end @@ -98,7 +98,7 @@ void copy_memory_to_host(GraficCommon* device_object, bench_t* h_B, int64_t size __attribute__((weak)) float get_elapsed_time(GraficCommon* device_object, bool csv_format, bool csv_format_timestamp, long int current_time){ GraficObject* deviceObj = static_cast(device_object); - deviceObj->evt_copyBr->wait(); + deviceObj->evt_copyB->wait(); float elapsed_h_d = 0, elapsed = 0, elapsed_d_h = 0; @@ -109,11 +109,11 @@ float get_elapsed_time(GraficCommon* device_object, bool csv_format, bool csv_fo elapsed = deviceObj->elapsed_time; elapsed_d_h = deviceObj->d2h_elapsed_time; }else{ - elapsed_h_d = deviceObj->evt_copyB->getProfilingInfo() - deviceObj->evt_copyB->getProfilingInfo(); + elapsed_h_d = deviceObj->evt_copyA->getProfilingInfo() - deviceObj->evt_copyA->getProfilingInfo(); //printf("Elapsed time Host->Device: %.10f \n", elapsed / 1000000.0); elapsed = deviceObj->evt_end->getProfilingInfo() - deviceObj->evt->getProfilingInfo(); //printf("Elapsed time kernel: %.10f \n", elapsed / 1000000.0); - elapsed_d_h = deviceObj->evt_copyBr->getProfilingInfo() - deviceObj->evt_copyBr->getProfilingInfo(); + elapsed_d_h = deviceObj->evt_copyB->getProfilingInfo() - deviceObj->evt_copyB->getProfilingInfo(); //printf("Elapsed time Device->Host: %.10f \n", ); } @@ -141,6 +141,35 @@ void clean(GraficCommon* device_object){ delete deviceObj->d_B; delete deviceObj->evt; delete deviceObj->evt_end; + delete deviceObj->evt_copyA; delete deviceObj->evt_copyB; - delete deviceObj->evt_copyBr; } + +#ifdef UMA_COMPATIBILITY +// ====== UMA function ====== +void get_unified_memory_pointers(GraficCommon* device_object, bench_t* &A, unsigned int memSize){ + GraficObject* deviceObj = static_cast(device_object); + // --- Call the openCL common function --- + map_unified_memory(device_object, memSize, + BufferMapCL{&A, deviceObj->d_A, nullptr} + ); +} + +void sync_unified_memory_to_device(GraficCommon* device_object, bench_t* &A){ + GraficObject* deviceObj = static_cast(device_object); + // --- Call the openCL common function --- + unmap_unified_memory(device_object, + BufferMapCL{&A, deviceObj->d_A, deviceObj->evt_copyA} + ); +} + + +void sync_unified_memory_to_host(GraficCommon* device_object, bench_t* &d_output, unsigned int memSize){ + GraficObject* deviceObj = static_cast(device_object); + // --- Call the openCL common function --- + map_unified_memory_to_host(device_object, memSize, + BufferMapCL{&d_output, deviceObj->d_B, deviceObj->evt_copyB} + ); +} + +#endif \ No newline at end of file diff --git a/gpu4s_benchmark/fast_fourier_transform_window_bench/opencl/lib_opencl_lib.cpp b/gpu4s_benchmark/fast_fourier_transform_window_bench/opencl/lib_opencl_lib.cpp index 221439dc..3a343f3c 100644 --- a/gpu4s_benchmark/fast_fourier_transform_window_bench/opencl/lib_opencl_lib.cpp +++ b/gpu4s_benchmark/fast_fourier_transform_window_bench/opencl/lib_opencl_lib.cpp @@ -67,7 +67,7 @@ void execute_kernel(GraficCommon* device_object, int64_t window, int64_t size){ float get_elapsed_time(GraficCommon* device_object, bool csv_format, bool csv_format_timestamp, long int current_time){ GraficObject* deviceObj = static_cast(device_object); - deviceObj->evt_copyBr->wait(); + deviceObj->evt_copyB->wait(); float elapsed_h_d = 0, elapsed = 0, elapsed_d_h = 0; @@ -78,10 +78,13 @@ float get_elapsed_time(GraficCommon* device_object, bool csv_format, bool csv_fo elapsed = deviceObj->elapsed_time; elapsed_d_h = deviceObj->d2h_elapsed_time; }else{ - elapsed_h_d = deviceObj->evt_copyB->getProfilingInfo() - deviceObj->evt_copyB->getProfilingInfo(); + elapsed_h_d = deviceObj->evt_copyA->getProfilingInfo() - deviceObj->evt_copyA->getProfilingInfo(); //printf("Elapsed time Host->Device: %.10f \n", elapsed / 1000000.0); + + elapsed = deviceObj->elapsed_time; //printf("Elapsed time kernel: %.10f \n", elapsed / 1000000.0); - elapsed_d_h = deviceObj->evt_copyBr->getProfilingInfo() - deviceObj->evt_copyBr->getProfilingInfo(); + + elapsed_d_h = deviceObj->evt_copyB->getProfilingInfo() - deviceObj->evt_copyB->getProfilingInfo(); //printf("Elapsed time Device->Host: %.10f \n", ); } From 3803ef5c394a325ddb4a9db86bfca4a7cbca45a7 Mon Sep 17 00:00:00 2001 From: Noah Perret Date: Thu, 13 Aug 2026 13:19:18 +0200 Subject: [PATCH 09/27] small fix for previous UMA refactor --- gpu4s_benchmark/cifar_10_multiple/main.cpp | 3 +- .../cifar_10_multiple/opencl/lib_opencl.cpp | 4 +- .../opencl/lib_opencl_opt.cpp | 2 +- gpu4s_benchmark/common/benchmark_common.h | 4 + gpu4s_benchmark/common/opencl_common.hpp | 5 +- gpu4s_benchmark/convolution_2D_bench/main.cpp | 228 ++++++++++-------- .../opencl/lib_opencl_common.cpp | 35 +++ gpu4s_benchmark/correlation_2D/main.cpp | 130 ++++++---- .../opencl/lib_opencl_common.cpp | 63 ++++- .../fast_fourier_transform_bench/main.cpp | 1 - .../matrix_multiplication_bench/main.cpp | 6 +- 11 files changed, 330 insertions(+), 151 deletions(-) diff --git a/gpu4s_benchmark/cifar_10_multiple/main.cpp b/gpu4s_benchmark/cifar_10_multiple/main.cpp index 683a01ef..685d3ce1 100644 --- a/gpu4s_benchmark/cifar_10_multiple/main.cpp +++ b/gpu4s_benchmark/cifar_10_multiple/main.cpp @@ -320,7 +320,7 @@ int main(int argc, char *argv[]){ #endif } - if (compare_vectors(output_data, d_output, CIFAR_10_OUTPUT)){ + if (compare_vectors(output_data, d_output, CIFAR_10_OUTPUT * arguments_parameters->size)){ printf("OK\n"); } @@ -329,6 +329,7 @@ int main(int argc, char *argv[]){ print_double_hexadecimal_values(CPU_FILE, output_data, CIFAR_10_OUTPUT); } } + /////////////////////////////////////////////////////////////////////////////////////////////// // CLEAN MEMORY /////////////////////////////////////////////////////////////////////////////////////////////// diff --git a/gpu4s_benchmark/cifar_10_multiple/opencl/lib_opencl.cpp b/gpu4s_benchmark/cifar_10_multiple/opencl/lib_opencl.cpp index e9809c60..f46088d9 100644 --- a/gpu4s_benchmark/cifar_10_multiple/opencl/lib_opencl.cpp +++ b/gpu4s_benchmark/cifar_10_multiple/opencl/lib_opencl.cpp @@ -252,9 +252,7 @@ void execute_kernel(GraficCommon* device_object, unsigned int input_data, unsign softmax_end_kernel.setArg(2,neurons_dense_2); softmax_end_kernel.setArg(3, position * output_data); - deviceObj->queue->enqueueNDRangeKernel(softmax_end_kernel,cl::NullRange,global,local, NULL, NULL); - deviceObj->queue->enqueueWriteBuffer(*deviceObj->sum_ouput,CL_TRUE,0,sizeof(bench_t), 0, NULL,NULL); - + deviceObj->queue->enqueueNDRangeKernel(softmax_end_kernel,cl::NullRange,global,local, NULL, NULL); } //FIX : GPU profiling use opencl marker diff --git a/gpu4s_benchmark/cifar_10_multiple/opencl/lib_opencl_opt.cpp b/gpu4s_benchmark/cifar_10_multiple/opencl/lib_opencl_opt.cpp index 593f498a..e5a15711 100644 --- a/gpu4s_benchmark/cifar_10_multiple/opencl/lib_opencl_opt.cpp +++ b/gpu4s_benchmark/cifar_10_multiple/opencl/lib_opencl_opt.cpp @@ -317,7 +317,7 @@ void execute_kernel(GraficCommon* device_object, unsigned int input_data, unsign kernel_add.setArg(2,neurons_dense_2/2); kernel_add.setArg(3,stream * neurons_dense_2); queues[stream].enqueueNDRangeKernel(kernel_add,cl::NullRange,global,local, NULL, NULL); - + //soft max if((neurons_dense_2) <= BLOCK_SIZE) { diff --git a/gpu4s_benchmark/common/benchmark_common.h b/gpu4s_benchmark/common/benchmark_common.h index fdd28059..f42c9fb8 100644 --- a/gpu4s_benchmark/common/benchmark_common.h +++ b/gpu4s_benchmark/common/benchmark_common.h @@ -163,6 +163,10 @@ void clean(GraficCommon *device_object); // --- UMA memory function --- #ifdef UMA_COMPATIBILITY + // --- 1 buffer --- + void get_unified_memory_pointers(GraficCommon* device_object, bench_t* &A, unsigned int memSize); + void sync_unified_memory_to_device(GraficCommon* device_object, bench_t* &A); + // --- 2 buffer --- void get_unified_memory_pointers(GraficCommon* device_object, bench_t* &A, bench_t* &B, unsigned int memSize); void sync_unified_memory_to_device(GraficCommon* device_object, bench_t* &A, bench_t* &B); diff --git a/gpu4s_benchmark/common/opencl_common.hpp b/gpu4s_benchmark/common/opencl_common.hpp index 2c42fba6..0eb6042f 100644 --- a/gpu4s_benchmark/common/opencl_common.hpp +++ b/gpu4s_benchmark/common/opencl_common.hpp @@ -65,6 +65,7 @@ inline void map_unified_memory(GraficCommon* device_object, unsigned memSize, Ma if (openclError("Failed to map buffer!", err)) return; + deviceObj->queue->finish(); mapCLK.end(); // store the hd2h time @@ -100,6 +101,7 @@ inline void unmap_unified_memory(GraficCommon* device_object, MapCL... mapCL) { if (openclError("Failed to unmap buffer!", err)) return; + deviceObj->queue->finish(); unmapCLK.end(); // store the h2d time @@ -135,8 +137,9 @@ inline void map_unified_memory_to_host(GraficCommon* device_object, unsigned mem (lastErr != CL_SUCCESS ? err = lastErr : CL_SUCCESS) ), ...); - if (openclError("Failed to map buffer!", err)) return; + if (openclError("Failed to map buffer to host!", err)) return; + deviceObj->queue->finish(); mapCLK.end(); // store the d2h time diff --git a/gpu4s_benchmark/convolution_2D_bench/main.cpp b/gpu4s_benchmark/convolution_2D_bench/main.cpp index a9ed1384..e049de51 100644 --- a/gpu4s_benchmark/convolution_2D_bench/main.cpp +++ b/gpu4s_benchmark/convolution_2D_bench/main.cpp @@ -21,32 +21,58 @@ int main(int argc, char *argv[]){ /////////////////////////////////////////////////////////////////////////////////////////////// // Arguments /////////////////////////////////////////////////////////////////////////////////////////////// - BenchmarkParameters *arguments_parameters = (BenchmarkParameters *)malloc(sizeof(BenchmarkParameters)); int resolution = arguments_handler(argc,argv,arguments_parameters); - if (resolution == ERROR_ARGUMENTS){ + if (resolution == ERROR_ARGUMENTS) + { exit(-1); } /////////////////////////////////////////////////////////////////////////////////////////////// // VARIABLES /////////////////////////////////////////////////////////////////////////////////////////////// // linearizable versions of matrix - unsigned int size_matrix =arguments_parameters->size * arguments_parameters->size; + unsigned int size_matrix = arguments_parameters->size * arguments_parameters->size; // A input matrix - unsigned int size_A = arguments_parameters->size * arguments_parameters->size; - unsigned int mem_size_A = sizeof(bench_t) * size_A; - bench_t* A = (bench_t*) malloc(mem_size_A); - // B input matrix - unsigned int size_B = arguments_parameters->size * arguments_parameters->size; - unsigned int mem_size_B = sizeof(bench_t) * size_B; - bench_t* h_B = (bench_t*) malloc(mem_size_B); - bench_t* d_B = (bench_t*) malloc(mem_size_B); + unsigned int mem_size = sizeof(bench_t) * size_matrix; + bench_t* A = NULL; // kernel matrix - unsigned int size_k = arguments_parameters->kernel_size * arguments_parameters->kernel_size ; - unsigned int mem_size_k = sizeof(bench_t) * size_k; - bench_t* kernel = (bench_t*) malloc(mem_size_k); - // comparation result - bool result = false; + bench_t* kernel = NULL; + // B input matrix + bench_t* d_B = NULL; + bench_t* h_B = (bench_t*) malloc(mem_size); + // init devices + char device[100] = ""; + + // main object init + GraficCommon*conv_bench = (GraficCommon*)malloc(sizeof(GraficObject)); + + // --- 1. Init Device & Context --- + init(conv_bench, 0,arguments_parameters->gpu, device); + + // Update profiling clock mode + conv_bench->profiling_clock = arguments_parameters->profiling_clock; + + // --- 2. Allocate Device Memory --- + device_memory_init(conv_bench, size_matrix, size_matrix, size_matrix); + + // --- 3. Allocate Host Pointers --- + if (arguments_parameters->unified_memory) + { + #ifdef UMA_COMPATIBILITY + // map the buffzer to the gpu + cpu take the lead + get_unified_memory_pointers(conv_bench, A, kernel, d_B, mem_size); + #else + fprintf(stderr, "\033[1;31merror:\033[0m This framework is not compatible with unified memory. Please remove the -u arg!\n"); + exit(-1); + #endif + } else + { + // normale malloc + A = (bench_t*) malloc(mem_size); + kernel = (bench_t*) malloc(mem_size); + d_B = (bench_t*) malloc(mem_size); + } + /////////////////////////////////////////////////////////////////////////////////////////////// // DATA INIT /////////////////////////////////////////////////////////////////////////////////////////////// @@ -56,29 +82,30 @@ int main(int argc, char *argv[]){ for (int i=0; isize; i++){ for (int j=0; jsize; j++){ #ifdef INT - A[i*arguments_parameters->size+j] = rand() % (NUMBER_BASE * 100); - + A[i*arguments_parameters->size+j] = rand() % (NUMBER_BASE * 100); #else - A[i*arguments_parameters->size+j] = (bench_t)rand()/(bench_t)(RAND_MAX/NUMBER_BASE); + A[i*arguments_parameters->size+j] = (bench_t)rand()/(bench_t)(RAND_MAX/NUMBER_BASE); #endif } } - // iniciate B matrix + + // iniciate kernel matrix + for (int i=0; i < size_matrix; ++i) + { + #ifdef INT + kernel[i] = rand() % (NUMBER_BASE * 100); + #else + kernel[i] = (bench_t)rand()/(bench_t)(RAND_MAX/NUMBER_BASE); + #endif + } + + // reset B matrix for (int i=0; isize; i++){ for (int j=0; jsize; j++){ h_B[i*arguments_parameters->size+j] = 0; d_B[i*arguments_parameters->size+j] = 0; } } - // iniciate kernel matrix - for (int i=0; i < size_k; ++i) - { - #ifdef INT - kernel[i] = rand() % (NUMBER_BASE * 100); - #else - kernel[i] = (bench_t)rand()/(bench_t)(RAND_MAX/NUMBER_BASE); - #endif - } } else { @@ -95,6 +122,7 @@ int main(int argc, char *argv[]){ } }*/ } + // print input if (arguments_parameters->print_input) { @@ -109,7 +137,7 @@ int main(int argc, char *argv[]){ printf("\n"); } printf("\n\n"); - for (int i=0; i < size_k; ++i) + for (int i=0; i < size_matrix; ++i) { #ifdef INT printf("%d ",kernel[i]); @@ -118,111 +146,114 @@ int main(int argc, char *argv[]){ #endif } printf("\n\n"); - } /////////////////////////////////////////////////////////////////////////////////////////////// // CODE BENCKMARK /////////////////////////////////////////////////////////////////////////////////////////////// - - // base object init - GraficCommon*conv_bench = (GraficCommon*)malloc(sizeof(GraficObject)); - // init devices - char device[100] = ""; - init(conv_bench, 0,arguments_parameters->gpu, device); if (!arguments_parameters->csv_format_timestamp && !arguments_parameters->csv_format && !arguments_parameters->mute_messages ){ printf("Using device: %s\n", device); } - - // Update profiling clock mode - conv_bench->profiling_clock = arguments_parameters->profiling_clock; - - // If android and opencl force profiling clock - #ifdef FORCE_PROFILING_CLOCK - conv_bench->profiling_clock = true; - #endif - // init memory - device_memory_init(conv_bench, arguments_parameters->size * arguments_parameters->size, arguments_parameters->size * arguments_parameters->size, size_k); // copy memory to device - copy_memory_to_device(conv_bench, A, kernel, arguments_parameters->size * arguments_parameters->size, size_k); + if(arguments_parameters->unified_memory) + { + #ifdef UMA_COMPATIBILITY + sync_unified_memory_to_device(conv_bench, A, kernel, d_B); + #endif + } + else + { + copy_memory_to_device(conv_bench, A, kernel, size_matrix, size_matrix); + } + // execute kernel execute_kernel(conv_bench, arguments_parameters->size, arguments_parameters->size, arguments_parameters->size, arguments_parameters->kernel_size); + + // copy memory to host - copy_memory_to_host(conv_bench, d_B, size_matrix); + if (arguments_parameters->unified_memory) + { + #ifdef UMA_COMPATIBILITY + sync_unified_memory_to_host(conv_bench, d_B, mem_size); + #endif + } else + { + copy_memory_to_host(conv_bench, d_B, size_matrix); + } // get time if (arguments_parameters->print_timing || arguments_parameters->csv_format || arguments_parameters->csv_format_timestamp) { get_elapsed_time(conv_bench, arguments_parameters->csv_format, arguments_parameters->csv_format_timestamp, get_timestamp()); } + + // print output buffer if (arguments_parameters->print_output) { #ifdef INT - for (int i=0; isize; i++){ - for (int j=0; jsize; j++){ - printf("%d ", d_B[i*arguments_parameters->size+j]); - - } - printf("\n"); - } + for (int i=0; isize; i++){ + for (int j=0; jsize; j++){ + printf("%d ", d_B[i*arguments_parameters->size+j]); + + } + printf("\n"); + } #else - for (int i=0; isize; i++){ - for (int j=0; jsize; j++){ - printf("%f ", d_B[i*arguments_parameters->size+j]); - - } - printf("\n"); - } + for (int i=0; isize; i++){ + for (int j=0; jsize; j++){ + printf("%f ", d_B[i*arguments_parameters->size+j]); + } + printf("\n"); + } #endif - - } + // export gpu buffer + if (arguments_parameters->export_results_gpu) + { + print_double_hexadecimal_values(GPU_FILE, d_B, size_matrix); + } - + //check for error if (arguments_parameters->verification) { Clock cpuKernelCLK; cpuKernelCLK.start(); matrix_convolution(A,kernel,h_B,arguments_parameters->size,arguments_parameters->kernel_size); cpuKernelCLK.end(); + if (arguments_parameters->print_timing) { printf("CPU Time %.0f milliseconds\n", cpuKernelCLK.getElapsedMS()); } + if (arguments_parameters->print_output) { - #ifdef INT - for (int i=0; isize; i++){ - for (int j=0; jsize; j++){ - printf("%d ", h_B[i*arguments_parameters->size+j]); - - } - printf("\n"); - } - #else - for (int i=0; isize; i++){ - for (int j=0; jsize; j++){ - printf("%f ", h_B[i*arguments_parameters->size+j]); - - } - printf("\n"); - } - #endif + #ifdef INT + for (int i=0; isize; i++){ + for (int j=0; jsize; j++){ + printf("%d ", h_B[i*arguments_parameters->size+j]); + } + printf("\n"); + } + #else + for (int i=0; isize; i++){ + for (int j=0; jsize; j++){ + printf("%f ", h_B[i*arguments_parameters->size+j]); + } + printf("\n"); + } + #endif } - result = compare_vectors(h_B, d_B, size_B); - if (result){ + + if (compare_vectors(h_B, d_B, size_matrix)){ printf("OK\n"); } + if (arguments_parameters->export_results){ - print_double_hexadecimal_values(GPU_FILE, d_B, size_B); - print_double_hexadecimal_values(CPU_FILE, h_B, size_B); + print_double_hexadecimal_values(GPU_FILE, d_B, size_matrix); + print_double_hexadecimal_values(CPU_FILE, h_B, size_matrix); } - - } - if (arguments_parameters->export_results_gpu) - { - print_double_hexadecimal_values(GPU_FILE, d_B, size_B); } /////////////////////////////////////////////////////////////////////////////////////////////// // CLEAN MEMORY @@ -232,16 +263,21 @@ int main(int argc, char *argv[]){ // free object memory free(arguments_parameters); free(conv_bench); - free(A); - free(kernel); + + if (!arguments_parameters->unified_memory) + { + free(A); + free(kernel); + free(d_B); + } + + free(h_B); - free(d_B); return 0; } // Arguments part - void print_usage(const char * appName) { printf("Usage: %s -s Size -k [-v] [-e] [-o] [-t] [-d] [-i input_file_A_MATRIX input_file_B_MATRIX] \n", appName); diff --git a/gpu4s_benchmark/convolution_2D_bench/opencl/lib_opencl_common.cpp b/gpu4s_benchmark/convolution_2D_bench/opencl/lib_opencl_common.cpp index 5217c49d..c50f5aaa 100644 --- a/gpu4s_benchmark/convolution_2D_bench/opencl/lib_opencl_common.cpp +++ b/gpu4s_benchmark/convolution_2D_bench/opencl/lib_opencl_common.cpp @@ -153,3 +153,38 @@ void clean(GraficCommon* device_object){ delete deviceObj->evt_copyB; delete deviceObj->evt_copyC; } + + + +#ifdef UMA_COMPATIBILITY +// ====== UMA function ====== +void get_unified_memory_pointers(GraficCommon* device_object, bench_t* &A, bench_t* &B, bench_t* &C, unsigned int memSize){ + GraficObject* deviceObj = static_cast(device_object); + // --- Call the openCL common function --- + map_unified_memory(device_object, memSize, + BufferMapCL{&A, deviceObj->d_A, nullptr}, + BufferMapCL{&B, deviceObj->kernel, nullptr}, + BufferMapCL{&C, deviceObj->d_B, nullptr} + ); +} + +void sync_unified_memory_to_device(GraficCommon* device_object, bench_t* &A, bench_t* &B, bench_t* &C){ + GraficObject* deviceObj = static_cast(device_object); + // --- Call the openCL common function --- + unmap_unified_memory(device_object, + BufferMapCL{&A, deviceObj->d_A, deviceObj->evt_copyA}, + BufferMapCL{&B, deviceObj->kernel, deviceObj->evt}, + BufferMapCL{&C, deviceObj->d_B, nullptr} + ); +} + + +void sync_unified_memory_to_host(GraficCommon* device_object, bench_t* &d_output, unsigned int memSize){ + GraficObject* deviceObj = static_cast(device_object); + // --- Call the openCL common function --- + map_unified_memory_to_host(device_object, memSize, + BufferMapCL{&d_output, deviceObj->d_B, deviceObj->evt_copyB} + ); +} + +#endif \ No newline at end of file diff --git a/gpu4s_benchmark/correlation_2D/main.cpp b/gpu4s_benchmark/correlation_2D/main.cpp index 7f17ee27..635da386 100644 --- a/gpu4s_benchmark/correlation_2D/main.cpp +++ b/gpu4s_benchmark/correlation_2D/main.cpp @@ -22,7 +22,8 @@ int main(int argc, char *argv[]){ /////////////////////////////////////////////////////////////////////////////////////////////// BenchmarkParameters *arguments_parameters = (BenchmarkParameters *)malloc(sizeof(BenchmarkParameters)); int resolution = arguments_handler(argc,argv,arguments_parameters); - if (resolution == ERROR_ARGUMENTS){ + if (resolution == ERROR_ARGUMENTS) + { exit(-1); } /////////////////////////////////////////////////////////////////////////////////////////////// @@ -33,21 +34,48 @@ int main(int argc, char *argv[]){ // VARIABLES /////////////////////////////////////////////////////////////////////////////////////////////// // linearizable versions of matrix - unsigned int size_matrix =arguments_parameters->size * arguments_parameters->size; + unsigned int size_matrix =arguments_parameters->size * arguments_parameters->size; // A input matrix - unsigned int size_A = arguments_parameters->size * arguments_parameters->size; - unsigned int mem_size_A = sizeof(bench_t) * size_A; - bench_t* A = (bench_t*) malloc(mem_size_A); + unsigned int mem_size = sizeof(bench_t) * size_matrix; + bench_t* A = NULL; // B input matrix - unsigned int size_B = arguments_parameters->size * arguments_parameters->size ; - unsigned int mem_size_B = sizeof(bench_t) * size_B; - bench_t* B = (bench_t*) malloc(mem_size_B); + bench_t* B = NULL; // Correaltion Value alwais is a float number + result_bench_t* d_R = NULL; result_bench_t* h_R = (result_bench_t*) malloc(sizeof(result_bench_t)); - result_bench_t* d_R = (result_bench_t*) malloc(sizeof(result_bench_t)); - - // comparation result - bool result = false; + // init devices + char device[100] = ""; + + // main object init + GraficCommon*correlation_bench = (GraficCommon*)malloc(sizeof(GraficObject)); + + // --- 1. Init Device & Context --- + init(correlation_bench, 0,arguments_parameters->gpu, device); + // Update profiling clock mode + correlation_bench->profiling_clock = arguments_parameters->profiling_clock; + + // --- 2. Allocate Device Memory --- + device_memory_init(correlation_bench, size_matrix, size_matrix ); + + // --- 3. Allocate Host Pointers --- + if (arguments_parameters->unified_memory) + { + #ifdef UMA_COMPATIBILITY + // map the buffzer to the gpu + cpu take the lead + get_unified_memory_pointers(correlation_bench, A, B, d_R, mem_size); + #else + fprintf(stderr, "\033[1;31merror:\033[0m This framework is not compatible with unified memory. Please remove the -u arg!\n"); + exit(-1); + #endif + } else + { + // normale malloc + A = (bench_t*) malloc(mem_size); + B = (bench_t*) malloc(mem_size); + d_R = (result_bench_t*) malloc(sizeof(result_bench_t)); + } + + /////////////////////////////////////////////////////////////////////////////////////////////// // DATA INIT /////////////////////////////////////////////////////////////////////////////////////////////// @@ -75,7 +103,7 @@ int main(int argc, char *argv[]){ #endif } } - // iniciate C Values + // iniciate R Values *h_R = 0; *d_R = 0; @@ -125,72 +153,85 @@ int main(int argc, char *argv[]){ /////////////////////////////////////////////////////////////////////////////////////////////// // CODE BENCKMARK /////////////////////////////////////////////////////////////////////////////////////////////// - - // base object init - GraficCommon*correlation_bench = (GraficCommon*)malloc(sizeof(GraficObject)); - // init devices - char device[100] = ""; - init(correlation_bench, 0,arguments_parameters->gpu, device); if (!arguments_parameters->csv_format_timestamp && !arguments_parameters->csv_format && !arguments_parameters->mute_messages ){ printf("Using device: %s\n", device); } - // Update profiling clock mode - correlation_bench->profiling_clock = arguments_parameters->profiling_clock; - - // If android and opencl force profiling clock - #ifdef FORCE_PROFILING_CLOCK - correlation_bench->profiling_clock = true; - #endif - - // init memory - device_memory_init(correlation_bench, size_A , size_B ); // copy memory to device - copy_memory_to_device(correlation_bench, A, size_A, B, size_B ); + if(arguments_parameters->unified_memory) + { + #ifdef UMA_COMPATIBILITY + sync_unified_memory_to_device(correlation_bench, A, B, d_R); + #endif + } + else + { + copy_memory_to_device(correlation_bench, A, size_matrix, B, size_matrix ); + } + // execute kernel execute_kernel(correlation_bench, arguments_parameters->size); + // copy memory to host - copy_memory_to_host(correlation_bench, d_R); + if (arguments_parameters->unified_memory) + { + #ifdef UMA_COMPATIBILITY + sync_unified_memory_to_host(correlation_bench, d_R, sizeof(result_bench_t)); + #endif + } else + { + copy_memory_to_host(correlation_bench, d_R); + } + // get time if (arguments_parameters->print_timing || arguments_parameters->csv_format || arguments_parameters->csv_format_timestamp) { get_elapsed_time(correlation_bench, arguments_parameters->csv_format, arguments_parameters->csv_format_timestamp, get_timestamp()); } + + // print output buffer if (arguments_parameters->print_output) { printf("%f ", *d_R); printf("\n"); } - + + // export gpu buffer + if (arguments_parameters->export_results_gpu) + { + print_double_hexadecimal_values(GPU_FILE, d_R, 1); + } + + //check for error if (arguments_parameters->verification) { Clock cpuKernelCLK; cpuKernelCLK.start(); correlation_2D(A,B, h_R ,arguments_parameters->size); cpuKernelCLK.end(); + if (arguments_parameters->print_timing) { printf("CPU Time %.0f milliseconds\n", cpuKernelCLK.getElapsedMS()); } + if (arguments_parameters->print_output) { printf("%f ", *h_R); printf("\n"); } - result = compare_values(h_R, d_R); - if (result){ + + + if (compare_values(h_R, d_R)) + { printf("OK\n"); } + if (arguments_parameters->export_results){ print_double_hexadecimal_values(GPU_FILE, d_R, 1); print_double_hexadecimal_values(CPU_FILE, h_R, 1); } - - } - if (arguments_parameters->export_results_gpu) - { - print_double_hexadecimal_values(GPU_FILE, d_R, 1); } /////////////////////////////////////////////////////////////////////////////////////////////// // CLEAN MEMORY @@ -200,10 +241,15 @@ int main(int argc, char *argv[]){ // free object memory free(correlation_bench); free(arguments_parameters); - free(A); - free(B); + + if (!arguments_parameters->unified_memory) + { + free(A); + free(B); + free(d_R); + } + free(h_R); - free(d_R); return 0; } diff --git a/gpu4s_benchmark/correlation_2D/opencl/lib_opencl_common.cpp b/gpu4s_benchmark/correlation_2D/opencl/lib_opencl_common.cpp index 4debf73f..e7b81ab1 100644 --- a/gpu4s_benchmark/correlation_2D/opencl/lib_opencl_common.cpp +++ b/gpu4s_benchmark/correlation_2D/opencl/lib_opencl_common.cpp @@ -105,15 +105,15 @@ void copy_memory_to_device(GraficCommon* device_object, bench_t* h_A, unsigned i void copy_memory_to_host(GraficCommon* device_object, result_bench_t* h_R){ GraficObject* deviceObj = static_cast(device_object); + result_bench_t acumulate_value_a_a; + result_bench_t acumulate_value_a_b; + result_bench_t acumulate_value_b_b; // device -> host Clock d2hCLK; // Clock profilling start d2hCLK.start(); - result_bench_t acumulate_value_a_a; - result_bench_t acumulate_value_a_b; - result_bench_t acumulate_value_b_b; cl_int err = deviceObj->queue->enqueueReadBuffer(*deviceObj->acumulate_value_a_a,CL_TRUE,0,sizeof(result_bench_t),&acumulate_value_a_a, NULL, deviceObj->evt_copyAA); if (openclError("Failed to copy vector acumulate_value_a_a from device to host", err)) return; err = deviceObj->queue->enqueueReadBuffer(*deviceObj->acumulate_value_a_b,CL_TRUE,0,sizeof(result_bench_t),&acumulate_value_a_b, NULL, deviceObj->evt_copyAB); @@ -187,3 +187,60 @@ void clean(GraficCommon* device_object){ delete deviceObj->evt_copyAB; delete deviceObj->evt_copyAA; } + + +#ifdef UMA_COMPATIBILITY +// ====== UMA function ====== +void get_unified_memory_pointers(GraficCommon* device_object, bench_t* &A, bench_t* &B, bench_t* &C, unsigned int memSize){ + GraficObject* deviceObj = static_cast(device_object); + + // --- Call the openCL common function --- + map_unified_memory(device_object, memSize, + BufferMapCL{&A, deviceObj->d_A, nullptr}, + BufferMapCL{&B, deviceObj->d_B, nullptr} + ); + + bench_t* tmp_dR = nullptr; + map_unified_memory(device_object, sizeof(result_bench_t), + BufferMapCL{&tmp_dR, deviceObj->d_R, nullptr} + ); + C = (result_bench_t*)tmp_dR; +} + +void sync_unified_memory_to_device(GraficCommon* device_object, bench_t* &A, bench_t* &B, bench_t* &C){ + GraficObject* deviceObj = static_cast(device_object); + + bench_t* tmp_dR = (bench_t*)C; + + // --- Call the openCL common function --- + unmap_unified_memory(device_object, + BufferMapCL{&A, deviceObj->d_A, deviceObj->evt_copyA}, + BufferMapCL{&B, deviceObj->d_B, deviceObj->evt_copyB}, + BufferMapCL{&tmp_dR, deviceObj->d_R, nullptr} + ); +} + + +void sync_unified_memory_to_host(GraficCommon* device_object, bench_t* &d_output, unsigned int memSize){ + GraficObject* deviceObj = static_cast(device_object); + + bench_t* tmp_aa = nullptr; + bench_t* tmp_ab = nullptr; + bench_t* tmp_bb = nullptr; + + // --- Call the openCL common function --- + map_unified_memory_to_host(device_object, sizeof(result_bench_t), + BufferMapCL{&tmp_aa, deviceObj->acumulate_value_a_a, deviceObj->evt_copyAA}, + BufferMapCL{&tmp_ab, deviceObj->acumulate_value_a_b, deviceObj->evt_copyAB}, + BufferMapCL{&tmp_bb, deviceObj->acumulate_value_b_b, deviceObj->evt_copyBB} + ); + + // --- Cast back to bench_t --- + result_bench_t a_a = *((result_bench_t*)tmp_aa); + result_bench_t a_b = *((result_bench_t*)tmp_ab); + result_bench_t b_b = *((result_bench_t*)tmp_bb); + + // Compute the result + *d_output = (result_bench_t)(a_b / (result_bench_t)(sqrt(a_a * b_b))); +} +#endif \ No newline at end of file diff --git a/gpu4s_benchmark/fast_fourier_transform_bench/main.cpp b/gpu4s_benchmark/fast_fourier_transform_bench/main.cpp index 647230a6..8f9b443b 100644 --- a/gpu4s_benchmark/fast_fourier_transform_bench/main.cpp +++ b/gpu4s_benchmark/fast_fourier_transform_bench/main.cpp @@ -139,7 +139,6 @@ int main(int argc, char *argv[]){ } else { copy_memory_to_host(fft_bench, d_B, size); - } // get time diff --git a/gpu4s_benchmark/matrix_multiplication_bench/main.cpp b/gpu4s_benchmark/matrix_multiplication_bench/main.cpp index 8e654b5e..ee8aa539 100644 --- a/gpu4s_benchmark/matrix_multiplication_bench/main.cpp +++ b/gpu4s_benchmark/matrix_multiplication_bench/main.cpp @@ -35,11 +35,11 @@ int main(int argc, char *argv[]) unsigned int size_matrix = arguments_parameters->size * arguments_parameters->size; unsigned int mem_size = sizeof(bench_t) * size_matrix; // A input matrix - bench_t* A = NULL; + bench_t* A = nullptr; // B input matrix - bench_t* B = NULL; + bench_t* B = nullptr; // C output matrix - bench_t* d_C = NULL; + bench_t* d_C = nullptr; bench_t* h_C = (bench_t*) malloc(mem_size); // init devices char char device[100] = ""; From 0959099f7f808a646097c943ef5d30ae9ad0c665 Mon Sep 17 00:00:00 2001 From: Noah Perret Date: Thu, 13 Aug 2026 15:25:21 +0200 Subject: [PATCH 10/27] fix kernel size for 2D convolution UMA --- gpu4s_benchmark/convolution_2D_bench/main.cpp | 18 ++++++++++-------- .../opencl/lib_opencl_common.cpp | 7 +++++-- 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/gpu4s_benchmark/convolution_2D_bench/main.cpp b/gpu4s_benchmark/convolution_2D_bench/main.cpp index e049de51..1b73207b 100644 --- a/gpu4s_benchmark/convolution_2D_bench/main.cpp +++ b/gpu4s_benchmark/convolution_2D_bench/main.cpp @@ -36,8 +36,10 @@ int main(int argc, char *argv[]){ unsigned int mem_size = sizeof(bench_t) * size_matrix; bench_t* A = NULL; // kernel matrix + unsigned int size_k = arguments_parameters->kernel_size * arguments_parameters->kernel_size ; + unsigned int mem_size_k = sizeof(bench_t) * size_k; bench_t* kernel = NULL; - // B input matrix + // B output matrix bench_t* d_B = NULL; bench_t* h_B = (bench_t*) malloc(mem_size); // init devices @@ -53,14 +55,14 @@ int main(int argc, char *argv[]){ conv_bench->profiling_clock = arguments_parameters->profiling_clock; // --- 2. Allocate Device Memory --- - device_memory_init(conv_bench, size_matrix, size_matrix, size_matrix); + device_memory_init(conv_bench, size_matrix, size_matrix, size_k); // --- 3. Allocate Host Pointers --- if (arguments_parameters->unified_memory) { #ifdef UMA_COMPATIBILITY // map the buffzer to the gpu + cpu take the lead - get_unified_memory_pointers(conv_bench, A, kernel, d_B, mem_size); + get_unified_memory_pointers(conv_bench, A, kernel, d_B, mem_size, size_k); #else fprintf(stderr, "\033[1;31merror:\033[0m This framework is not compatible with unified memory. Please remove the -u arg!\n"); exit(-1); @@ -69,7 +71,7 @@ int main(int argc, char *argv[]){ { // normale malloc A = (bench_t*) malloc(mem_size); - kernel = (bench_t*) malloc(mem_size); + kernel = (bench_t*) malloc(mem_size_k); d_B = (bench_t*) malloc(mem_size); } @@ -90,7 +92,7 @@ int main(int argc, char *argv[]){ } // iniciate kernel matrix - for (int i=0; i < size_matrix; ++i) + for (int i=0; i < size_k; ++i) { #ifdef INT kernel[i] = rand() % (NUMBER_BASE * 100); @@ -99,7 +101,7 @@ int main(int argc, char *argv[]){ #endif } - // reset B matrix + // reset output B matrix for (int i=0; isize; i++){ for (int j=0; jsize; j++){ h_B[i*arguments_parameters->size+j] = 0; @@ -137,7 +139,7 @@ int main(int argc, char *argv[]){ printf("\n"); } printf("\n\n"); - for (int i=0; i < size_matrix; ++i) + for (int i=0; i < size_k; ++i) { #ifdef INT printf("%d ",kernel[i]); @@ -163,7 +165,7 @@ int main(int argc, char *argv[]){ } else { - copy_memory_to_device(conv_bench, A, kernel, size_matrix, size_matrix); + copy_memory_to_device(conv_bench, A, kernel, size_matrix, size_k); } // execute kernel diff --git a/gpu4s_benchmark/convolution_2D_bench/opencl/lib_opencl_common.cpp b/gpu4s_benchmark/convolution_2D_bench/opencl/lib_opencl_common.cpp index c50f5aaa..626f8cd5 100644 --- a/gpu4s_benchmark/convolution_2D_bench/opencl/lib_opencl_common.cpp +++ b/gpu4s_benchmark/convolution_2D_bench/opencl/lib_opencl_common.cpp @@ -158,14 +158,17 @@ void clean(GraficCommon* device_object){ #ifdef UMA_COMPATIBILITY // ====== UMA function ====== -void get_unified_memory_pointers(GraficCommon* device_object, bench_t* &A, bench_t* &B, bench_t* &C, unsigned int memSize){ +void get_unified_memory_pointers(GraficCommon* device_object, bench_t* &A, bench_t* &B, bench_t* &C, unsigned int memSize, unsigned int memSize2){ GraficObject* deviceObj = static_cast(device_object); // --- Call the openCL common function --- map_unified_memory(device_object, memSize, BufferMapCL{&A, deviceObj->d_A, nullptr}, - BufferMapCL{&B, deviceObj->kernel, nullptr}, BufferMapCL{&C, deviceObj->d_B, nullptr} ); + + map_unified_memory(device_object, memSize2, + BufferMapCL{&B, deviceObj->kernel, nullptr} + ); } void sync_unified_memory_to_device(GraficCommon* device_object, bench_t* &A, bench_t* &B, bench_t* &C){ From 528603ad1e8d0487ff61ac9ef85b3ceead970508 Mon Sep 17 00:00:00 2001 From: Noah Perret Date: Thu, 13 Aug 2026 16:18:57 +0200 Subject: [PATCH 11/27] add UMA for FIR bench --- .../hip/lib_hip.cpp | 2 +- .../finite_impulse_response_filter/main.cpp | 155 ++++++++++++------ .../opencl/lib_opencl.cpp | 45 +++++ .../opencl/lib_opencl_common.cpp | 8 - 4 files changed, 148 insertions(+), 62 deletions(-) delete mode 100644 gpu4s_benchmark/finite_impulse_response_filter/opencl/lib_opencl_common.cpp diff --git a/gpu4s_benchmark/finite_impulse_response_filter/hip/lib_hip.cpp b/gpu4s_benchmark/finite_impulse_response_filter/hip/lib_hip.cpp index fbba315b..2095b0a0 100644 --- a/gpu4s_benchmark/finite_impulse_response_filter/hip/lib_hip.cpp +++ b/gpu4s_benchmark/finite_impulse_response_filter/hip/lib_hip.cpp @@ -198,7 +198,7 @@ float get_elapsed_time(GraficCommon* device_object, bool csv_format,bool csv_for void clean(GraficCommon* device_object){ GraficObject* deviceObj = static_cast(device_object); - hipError_terr = hipFree(deviceObj->d_A); + hipError_t err = hipFree(deviceObj->d_A); if (err != hipSuccess) { fprintf(stderr, "Failed to free device vector A (error code %s)!\n", hipGetErrorString(err)); diff --git a/gpu4s_benchmark/finite_impulse_response_filter/main.cpp b/gpu4s_benchmark/finite_impulse_response_filter/main.cpp index dd1f1257..462f2893 100644 --- a/gpu4s_benchmark/finite_impulse_response_filter/main.cpp +++ b/gpu4s_benchmark/finite_impulse_response_filter/main.cpp @@ -26,36 +26,68 @@ int main(int argc, char *argv[]) BenchmarkParameters *arguments_parameters = (BenchmarkParameters *)malloc(sizeof(BenchmarkParameters)); int resolution = arguments_handler(argc,argv,arguments_parameters); - if (resolution == ERROR_ARGUMENTS){ + if (resolution == ERROR_ARGUMENTS) + { exit(-1); } /////////////////////////////////////////////////////////////////////////////////////////////// // VARIABLES /////////////////////////////////////////////////////////////////////////////////////////////// // linearizable versions of matrix - unsigned int size_matrix =arguments_parameters->size; + unsigned int size_matrix = arguments_parameters->size; + unsigned int mem_size = sizeof(bench_t) * size_matrix; // A input matrix - unsigned int size_A = arguments_parameters->size; - unsigned int mem_size_A = sizeof(bench_t) * size_A; - bench_t* A = (bench_t*) malloc(mem_size_A); + bench_t* A = nullptr; + // kernel matrix + unsigned int size_k = arguments_parameters->kernel_size ; + unsigned int mem_size_k = sizeof(bench_t) * size_k; + bench_t* kernel = nullptr; // B output matrix unsigned int size_B = arguments_parameters->size + arguments_parameters->kernel_size - 1; unsigned int mem_size_B = sizeof(bench_t) * size_B; + bench_t* d_B = nullptr; bench_t* h_B = (bench_t*) malloc(mem_size_B); - bench_t* d_B = (bench_t*) malloc(mem_size_B); - // kernel matrix - unsigned int size_k = arguments_parameters->kernel_size ; - unsigned int mem_size_k = sizeof(bench_t) * size_k; - bench_t* kernel = (bench_t*) malloc(mem_size_k); - // comparation result - bool result = false; + + // init devices + char device[100] = ""; + + // main object init + GraficCommon*fir_bench = (GraficCommon*)malloc(sizeof(GraficObject)); + + // --- 1. Init Device & Context --- + init(fir_bench, 0,arguments_parameters->gpu, device); + // Update profiling clock mode + fir_bench->profiling_clock = arguments_parameters->profiling_clock; + + + // --- 2. Allocate Device Memory --- + device_memory_init(fir_bench, size_matrix, size_B, size_k); + + // --- 3. Allocate Host Pointers --- + if (arguments_parameters->unified_memory) + { + #ifdef UMA_COMPATIBILITY + // map the buffzer to the gpu + cpu take the lead + get_unified_memory_pointers(fir_bench, A, kernel, d_B, mem_size, mem_size_k, mem_size_B); + #else + fprintf(stderr, "\033[1;31merror:\033[0m This framework is not compatible with unified memory. Please remove the -u arg!\n"); + exit(-1); + #endif + } else + { + // normale malloc + A = (bench_t*) malloc(mem_size); + kernel = (bench_t*) malloc(mem_size_k); + d_B = (bench_t*) malloc(mem_size_B); + } + /////////////////////////////////////////////////////////////////////////////////////////////// // DATA INIT /////////////////////////////////////////////////////////////////////////////////////////////// if (strlen(arguments_parameters->input_file_A) == 0) { - // inicialice A matrix - for (int i=0; isize; i++){ + // inicialice A matrix + for (int i=0; isize; i++){ - h_B[i] = 0; - d_B[i] = 0; - } + // iniciate kernel matrix for (int i=0; i < size_k; ++i) { @@ -78,6 +106,12 @@ int main(int argc, char *argv[]) #endif } + // reset output B matrix + for (int i=0; iprint_input) { - for (int i=0; isize; i++){ + for (int i=0; igpu, device); if (!arguments_parameters->csv_format_timestamp && !arguments_parameters->csv_format && !arguments_parameters->mute_messages ){ printf("Using device: %s\n", device); } - - // Update profiling clock mode - fir_bench->profiling_clock = arguments_parameters->profiling_clock; - - // If android and opencl force profiling clock - #ifdef FORCE_PROFILING_CLOCK - fir_bench->profiling_clock = true; - #endif - // init memory - device_memory_init(fir_bench, arguments_parameters->size , size_B , size_k); // copy memory to device - copy_memory_to_device(fir_bench, A, kernel, arguments_parameters->size , size_k); + if(arguments_parameters->unified_memory) + { + #ifdef UMA_COMPATIBILITY + sync_unified_memory_to_device(fir_bench, A, kernel, d_B); + #endif + } + else + { + copy_memory_to_device(fir_bench, A, kernel, size_matrix, size_k); + } + // execute kernel - execute_kernel(fir_bench, size_B, arguments_parameters->size, size_B, arguments_parameters->kernel_size); + execute_kernel(fir_bench, size_B, size_matrix, size_B, size_k); + // copy memory to host - copy_memory_to_host(fir_bench, d_B, size_B); + if (arguments_parameters->unified_memory) + { + #ifdef UMA_COMPATIBILITY + sync_unified_memory_to_host(fir_bench, d_B, mem_size_B); + #endif + } else + { + copy_memory_to_host(fir_bench, d_B, size_B); + } + // get time if (arguments_parameters->print_timing || arguments_parameters->csv_format || arguments_parameters->csv_format_timestamp) { get_elapsed_time(fir_bench, arguments_parameters->csv_format, arguments_parameters->csv_format_timestamp, get_timestamp()); } + + // print output buffer if (arguments_parameters->print_output) { #ifdef INT @@ -169,18 +209,26 @@ int main(int argc, char *argv[]) } + // export gpu buffer + if (arguments_parameters->export_results_gpu) + { + print_double_hexadecimal_values(GPU_FILE, d_B, size_B); + } + //check for error if (arguments_parameters->verification) { Clock cpuKernelCLK; cpuKernelCLK.start(); - vector_convolution(A,kernel,h_B,arguments_parameters->size,arguments_parameters->kernel_size); + vector_convolution(A,kernel,h_B,size_matrix,size_k); cpuKernelCLK.end(); + if (arguments_parameters->print_timing) { printf("CPU Time %.0f milliseconds\n", cpuKernelCLK.getElapsedMS()); } + if (arguments_parameters->print_output) { #ifdef INT @@ -195,20 +243,17 @@ int main(int argc, char *argv[]) printf("\n"); #endif } - result = compare_vectors(h_B, d_B, size_B); - if (result){ + + if (compare_vectors(h_B, d_B, size_B)){ printf("OK\n"); } + if (arguments_parameters->export_results){ print_double_hexadecimal_values(GPU_FILE, d_B, size_B); print_double_hexadecimal_values(CPU_FILE, h_B, size_B); } } - if (arguments_parameters->export_results_gpu) - { - print_double_hexadecimal_values(GPU_FILE, d_B, size_B); - } /////////////////////////////////////////////////////////////////////////////////////////////// // CLEAN MEMORY /////////////////////////////////////////////////////////////////////////////////////////////// @@ -217,10 +262,14 @@ int main(int argc, char *argv[]) // free object memory free(fir_bench); free(arguments_parameters); - free(A); - free(kernel); + + if (!arguments_parameters->unified_memory) + { + free(A); + free(kernel); + free(d_B); + } free(h_B); - free(d_B); return 0; } diff --git a/gpu4s_benchmark/finite_impulse_response_filter/opencl/lib_opencl.cpp b/gpu4s_benchmark/finite_impulse_response_filter/opencl/lib_opencl.cpp index 67968540..d60ff6a8 100644 --- a/gpu4s_benchmark/finite_impulse_response_filter/opencl/lib_opencl.cpp +++ b/gpu4s_benchmark/finite_impulse_response_filter/opencl/lib_opencl.cpp @@ -3,6 +3,8 @@ #include "../benchmark_library.h" #include #include "kernel.cl" +#include "../../common/opencl_common.hpp" + void init(GraficCommon* device_object, char* device_name){ init(device_object, 0,0, device_name); @@ -205,3 +207,46 @@ void clean(GraficCommon* device_object){ delete deviceObj->evt_copyB; delete deviceObj->evt_copyC; } + + +#ifdef UMA_COMPATIBILITY +// ====== UMA function ====== +void get_unified_memory_pointers(GraficCommon* device_object, bench_t* &A, bench_t* &B, bench_t* &C, unsigned memSize, unsigned memSize2, unsigned memSize3){ + GraficObject* deviceObj = static_cast(device_object); + // --- Call the openCL common function --- + // input + map_unified_memory(device_object, memSize, + BufferMapCL{&A, deviceObj->d_A, nullptr} + ); + + // kernel + map_unified_memory(device_object, memSize2, + BufferMapCL{&B, deviceObj->kernel, nullptr} + ); + + // output + map_unified_memory(device_object, memSize3, + BufferMapCL{&C, deviceObj->d_B, nullptr} + ); +} + +void sync_unified_memory_to_device(GraficCommon* device_object, bench_t* &A, bench_t* &B, bench_t* &C){ + GraficObject* deviceObj = static_cast(device_object); + // --- Call the openCL common function --- + unmap_unified_memory(device_object, + BufferMapCL{&A, deviceObj->d_A, deviceObj->evt_copyA}, + BufferMapCL{&B, deviceObj->kernel, deviceObj->evt_copyB}, + BufferMapCL{&C, deviceObj->d_B, nullptr} + ); +} + + +void sync_unified_memory_to_host(GraficCommon* device_object, bench_t* &d_output, unsigned int memSize){ + GraficObject* deviceObj = static_cast(device_object); + // --- Call the openCL common function --- + map_unified_memory_to_host(device_object, memSize, + BufferMapCL{&d_output, deviceObj->d_B, deviceObj->evt_copyB} + ); +} + +#endif \ No newline at end of file diff --git a/gpu4s_benchmark/finite_impulse_response_filter/opencl/lib_opencl_common.cpp b/gpu4s_benchmark/finite_impulse_response_filter/opencl/lib_opencl_common.cpp deleted file mode 100644 index 72085dae..00000000 --- a/gpu4s_benchmark/finite_impulse_response_filter/opencl/lib_opencl_common.cpp +++ /dev/null @@ -1,8 +0,0 @@ -/** * ==================================================================== - * @file lib_opencl_common.cpp (./finite_impulse_response_filter) - * @brief Common OpenCL platform initialization, device setup, - * profiling timer evaluation, and generic cleanup routines. - * @paragraph License - * ESA-PL Strong Copyleft – v2.5 - * ======================================================================= */ -#include "../benchmark_library.h" From a6767ff6cedd17e98a35c0b01a0181f7b96dd940 Mon Sep 17 00:00:00 2001 From: Noah Perret Date: Thu, 13 Aug 2026 18:23:54 +0200 Subject: [PATCH 12/27] add UMA ofr LRN bench --- gpu4s_benchmark/LRN_bench/main.cpp | 148 +++++++++++------- .../LRN_bench/opencl/lib_opencl_common.cpp | 31 ++++ 2 files changed, 125 insertions(+), 54 deletions(-) diff --git a/gpu4s_benchmark/LRN_bench/main.cpp b/gpu4s_benchmark/LRN_bench/main.cpp index 6919d4af..578d81b9 100644 --- a/gpu4s_benchmark/LRN_bench/main.cpp +++ b/gpu4s_benchmark/LRN_bench/main.cpp @@ -31,36 +31,60 @@ int main(int argc, char *argv[]){ // VARIABLES /////////////////////////////////////////////////////////////////////////////////////////////// // linearizable versions of matrix - unsigned int size_matrix =arguments_parameters->size * arguments_parameters->size; + unsigned int size_matrix = arguments_parameters->size * arguments_parameters->size; + unsigned int mem_size = sizeof(bench_t) * size_matrix; // A input matrix - unsigned int size_A = arguments_parameters->size * arguments_parameters->size; - unsigned int mem_size_A = sizeof(bench_t) * size_A; - bench_t* A = (bench_t*) malloc(mem_size_A); + bench_t* A = (bench_t*) malloc(mem_size); // B input matrix - unsigned int size_B = arguments_parameters->size * arguments_parameters->size; - unsigned int mem_size_B = sizeof(bench_t) * size_B; - bench_t* h_B = (bench_t*) malloc(mem_size_B); - bench_t* d_B = (bench_t*) malloc(mem_size_B); - // comparation result - bool result = false; + bench_t* d_B = (bench_t*) malloc(mem_size); + bench_t* h_B = (bench_t*) malloc(mem_size); + // init devices + char device[100] = ""; + + // main object init + GraficCommon*lrn_bench = (GraficCommon*)malloc(sizeof(GraficObject)); + + // --- 1. Init Device & Context --- + init(lrn_bench, 0,arguments_parameters->gpu, device); + // Update profiling clock mode + lrn_bench->profiling_clock = arguments_parameters->profiling_clock; + + // --- 2. Allocate Device Memory --- + device_memory_init(lrn_bench, size_matrix, size_matrix); + + // --- 3. Allocate Host Pointers --- + if (arguments_parameters->unified_memory) + { + #ifdef UMA_COMPATIBILITY + // map the buffzer to the gpu + cpu take the lead + get_unified_memory_pointers(lrn_bench, A, d_B, mem_size); + #else + fprintf(stderr, "\033[1;31merror:\033[0m This framework is not compatible with unified memory. Please remove the -u arg!\n"); + exit(-1); + #endif + } else + { + // normale malloc + A = (bench_t*) malloc(mem_size); + d_B = (bench_t*) malloc(mem_size); + } /////////////////////////////////////////////////////////////////////////////////////////////// // DATA INIT /////////////////////////////////////////////////////////////////////////////////////////////// if (strlen(arguments_parameters->input_file_A) == 0) { - // initialise A matrix + // initialise A matrix for (int i=0; isize; i++){ for (int j=0; jsize; j++){ #ifdef INT A[i*arguments_parameters->size+j] = rand() % (NUMBER_BASE * 100); - #else A[i*arguments_parameters->size+j] = (double)rand()/RAND_MAX*2.0-1.0; #endif } } - // initiate B matrix + // reset output B matrix for (int i=0; isize; i++){ for (int j=0; jsize; j++){ h_B[i*arguments_parameters->size+j] = 0; @@ -83,6 +107,7 @@ int main(int argc, char *argv[]){ } }*/ } + // print input if (arguments_parameters->print_input) { @@ -102,68 +127,83 @@ int main(int argc, char *argv[]){ /////////////////////////////////////////////////////////////////////////////////////////////// // CODE BENCKMARK /////////////////////////////////////////////////////////////////////////////////////////////// - - // base object init - GraficCommon*lrn_bench = (GraficCommon*)malloc(sizeof(GraficObject)); - // init devices - char device[100] = ""; - init(lrn_bench, 0,arguments_parameters->gpu, device); if (!arguments_parameters->csv_format_timestamp && !arguments_parameters->csv_format && !arguments_parameters->mute_messages ){ printf("Using device: %s\n", device); } - - // Update profiling clock mode - lrn_bench->profiling_clock = arguments_parameters->profiling_clock; - // If android and opencl force profiling clock - #ifdef FORCE_PROFILING_CLOCK - lrn_bench->profiling_clock = true; - #endif - - // init memory - device_memory_init(lrn_bench, arguments_parameters->size * arguments_parameters->size, arguments_parameters->size * arguments_parameters->size); // copy memory to device - copy_memory_to_device(lrn_bench, A, arguments_parameters->size * arguments_parameters->size); + if(arguments_parameters->unified_memory) + { + #ifdef UMA_COMPATIBILITY + sync_unified_memory_to_device(lrn_bench, A, d_B); + #endif + } + else + { + copy_memory_to_device(lrn_bench, A, size_matrix); + } + // execute kernel execute_kernel(lrn_bench, arguments_parameters->size, arguments_parameters->size, arguments_parameters->size); + + + // copy memory to host - copy_memory_to_host(lrn_bench, d_B, size_matrix); + if (arguments_parameters->unified_memory) + { + #ifdef UMA_COMPATIBILITY + sync_unified_memory_to_host(lrn_bench, d_B, mem_size); + #endif + } else + { + copy_memory_to_host(lrn_bench, d_B, size_matrix); + } // get time if (arguments_parameters->print_timing || arguments_parameters->csv_format || arguments_parameters->csv_format_timestamp) { get_elapsed_time(lrn_bench, arguments_parameters->csv_format, arguments_parameters->csv_format_timestamp, get_timestamp()); } + + // print output buffer if (arguments_parameters->print_output) { #ifdef INT - for (int i=0; isize; i++){ - for (int j=0; jsize; j++){ - printf("%d ", d_B[i*arguments_parameters->size+j]); - - } - printf("\n"); - } + for (int i=0; isize; i++){ + for (int j=0; jsize; j++){ + printf("%d ", d_B[i*arguments_parameters->size+j]); + } + printf("\n"); + } #else for (int i=0; isize; i++){ - for (int j=0; jsize; j++){ - printf("%f ", d_B[i*arguments_parameters->size+j]); - - } + for (int j=0; jsize; j++){ + printf("%f ", d_B[i*arguments_parameters->size+j]); + } printf("\n"); - } + } #endif } + + // export gpu buffer + if (arguments_parameters->export_results_gpu) + { + print_double_hexadecimal_values(GPU_FILE, d_B, size_matrix); + } + + //check for error if (arguments_parameters->verification) { Clock cpuKernelCLK; cpuKernelCLK.start(); lrn(A,h_B, arguments_parameters->size); cpuKernelCLK.end(); + if (arguments_parameters->print_timing) { printf("CPU Time %.0f milliseconds\n", cpuKernelCLK.getElapsedMS()); } + if (arguments_parameters->print_output) { #ifdef INT @@ -184,20 +224,16 @@ int main(int argc, char *argv[]){ } #endif } - result = compare_vectors(h_B, d_B, size_B, 10e-3); - if (result){ + + if (compare_vectors(h_B, d_B, size_matrix, 10e-3)){ printf("OK\n"); } if (arguments_parameters->export_results){ - print_double_hexadecimal_values(GPU_FILE, d_B, size_B); - print_double_hexadecimal_values(CPU_FILE, h_B, size_B); + print_double_hexadecimal_values(GPU_FILE, d_B, size_matrix); + print_double_hexadecimal_values(CPU_FILE, h_B, size_matrix); } } - if (arguments_parameters->export_results_gpu) - { - print_double_hexadecimal_values(GPU_FILE, d_B, size_B); - } /////////////////////////////////////////////////////////////////////////////////////////////// // CLEAN MEMORY /////////////////////////////////////////////////////////////////////////////////////////////// @@ -206,15 +242,19 @@ int main(int argc, char *argv[]){ free(arguments_parameters); // free object memory free(lrn_bench); - free(A); + + if (!arguments_parameters->unified_memory) + { + free(A); + free(d_B); + } + free(h_B); - free(d_B); return 0; } // Arguments part - void print_usage(const char * appName) { printf("Usage: %s -s Size [-v] [-e] [-o] [-t] [-d] [-i input_file_A_MATRIX input_file_B_MATRIX] \n", appName); diff --git a/gpu4s_benchmark/LRN_bench/opencl/lib_opencl_common.cpp b/gpu4s_benchmark/LRN_bench/opencl/lib_opencl_common.cpp index dce82144..86b56203 100644 --- a/gpu4s_benchmark/LRN_bench/opencl/lib_opencl_common.cpp +++ b/gpu4s_benchmark/LRN_bench/opencl/lib_opencl_common.cpp @@ -145,3 +145,34 @@ void clean(GraficCommon* device_object){ delete deviceObj->evt_copyA; delete deviceObj->evt_copyB; } + +#ifdef UMA_COMPATIBILITY +// ====== UMA function ====== +void get_unified_memory_pointers(GraficCommon* device_object, bench_t* &A, bench_t* &B, unsigned int memSize){ + GraficObject* deviceObj = static_cast(device_object); + // --- Call the openCL common function --- + map_unified_memory(device_object, memSize, + BufferMapCL{&A, deviceObj->d_A, nullptr}, + BufferMapCL{&B, deviceObj->d_B, nullptr} + ); +} + +void sync_unified_memory_to_device(GraficCommon* device_object, bench_t* &A, bench_t* &B){ + GraficObject* deviceObj = static_cast(device_object); + // --- Call the openCL common function --- + unmap_unified_memory(device_object, + BufferMapCL{&A, deviceObj->d_A, deviceObj->evt_copyA}, + BufferMapCL{&B, deviceObj->d_B, nullptr} + ); +} + + +void sync_unified_memory_to_host(GraficCommon* device_object, bench_t* &d_output, unsigned int memSize){ + GraficObject* deviceObj = static_cast(device_object); + // --- Call the openCL common function --- + map_unified_memory_to_host(device_object, memSize, + BufferMapCL{&d_output, deviceObj->d_B, deviceObj->evt_copyB} + ); +} + +#endif From 9e24a5cf17dac6140aef75ebc6a08e5dee0257de Mon Sep 17 00:00:00 2001 From: Noah Perret Date: Thu, 13 Aug 2026 19:03:30 +0200 Subject: [PATCH 13/27] add float android uma for matrix mult fp16 bench --- .../matrix_multiplication_bench_fp16/main.cpp | 183 ++++++++++-------- .../opencl/lib_opencl_common.cpp | 36 +++- .../opencl/lib_opencl_lib.cpp | 1 + 3 files changed, 140 insertions(+), 80 deletions(-) diff --git a/gpu4s_benchmark/matrix_multiplication_bench_fp16/main.cpp b/gpu4s_benchmark/matrix_multiplication_bench_fp16/main.cpp index 5fe64fb1..de59a2d3 100644 --- a/gpu4s_benchmark/matrix_multiplication_bench_fp16/main.cpp +++ b/gpu4s_benchmark/matrix_multiplication_bench_fp16/main.cpp @@ -33,23 +33,46 @@ int main(int argc, char *argv[]){ /////////////////////////////////////////////////////////////////////////////////////////////// // linearizable versions of matrix unsigned int size_matrix = arguments_parameters->size * arguments_parameters->size; + unsigned int mem_size = sizeof(bench_t) * size_matrix; // A input matrix - unsigned int size_A = arguments_parameters->size * arguments_parameters->size; - unsigned int mem_size_A = sizeof(bench_t) * size_A; - bench_t* A = (bench_t*) malloc(mem_size_A); + bench_t* A = (bench_t*) malloc(mem_size); // B input matrix - unsigned int size_B = arguments_parameters->size * arguments_parameters->size; - unsigned int mem_size_B = sizeof(bench_t) * size_B; - bench_t* B = (bench_t*) malloc(mem_size_B); + bench_t* B = (bench_t*) malloc(mem_size); // C matrix - unsigned int size_C = arguments_parameters->size * arguments_parameters->size; - unsigned int mem_size_C = sizeof(bench_t) * size_C; - bench_t* h_C = (bench_t*) malloc(mem_size_C); - bench_t* d_C = (bench_t*) malloc(mem_size_C); - // auxiliar matrix for compare the output - bench_t* h_C_output = (bench_t*) malloc(mem_size_C);; - // comparation result - bool result = false; + bench_t* d_C = (bench_t*) malloc(mem_size); + bench_t* h_C = (bench_t*) malloc(mem_size); + // init devices + char device[100] = ""; + + // main object init + GraficCommon*matrix_benck = (GraficCommon*)malloc(sizeof(GraficObject)); + + // --- 1. Init Device & Context --- + init(matrix_benck, 0,arguments_parameters->gpu, device); + // Update profiling clock mode + matrix_benck->profiling_clock = arguments_parameters->profiling_clock; + + // --- 2. Allocate Device Memory --- + device_memory_init(matrix_benck, size_matrix, size_matrix, size_matrix); + + // --- 3. Allocate Host Pointers --- + if (arguments_parameters->unified_memory) + { + #ifdef UMA_COMPATIBILITY + // map the buffzer to the gpu + cpu take the lead + get_unified_memory_pointers(matrix_benck, A, B, d_C, mem_size); + #else + fprintf(stderr, "\033[1;31merror:\033[0m This framework is not compatible with unified memory. Please remove the -u arg!\n"); + exit(-1); + #endif + } else + { + // normale malloc + A = (bench_t*) malloc(mem_size); + B = (bench_t*) malloc(mem_size); + d_C = (bench_t*) malloc(mem_size); + } + /////////////////////////////////////////////////////////////////////////////////////////////// // DATA INIT /////////////////////////////////////////////////////////////////////////////////////////////// @@ -76,103 +99,105 @@ int main(int argc, char *argv[]){ #endif } } - // iniciate C matrix - for (int i=0; isize; i++){ - for (int j=0; jsize; j++){ - h_C[i*arguments_parameters->size+j] = 0; - d_C[i*arguments_parameters->size+j] = 0; - - } - } } else { /// load data - get_double_hexadecimal_values(arguments_parameters->input_file_A, A,size_A); - get_double_hexadecimal_values(arguments_parameters->input_file_B, B,size_B); + get_double_hexadecimal_values(arguments_parameters->input_file_A, A,size_matrix); + get_double_hexadecimal_values(arguments_parameters->input_file_B, B,size_matrix); //get_values_file(input_file, A, B); + } - // iniciate C matrix - for (int i=0; isize; i++){ - for (int j=0; jsize; j++){ - h_C[i*arguments_parameters->size+j] = 0; - d_C[i*arguments_parameters->size+j] = 0; - - } + // reset C output matrix + for (int i=0; isize; i++){ + for (int j=0; jsize; j++){ + h_C[i*arguments_parameters->size+j] = 0; + d_C[i*arguments_parameters->size+j] = 0; } } /////////////////////////////////////////////////////////////////////////////////////////////// // CODE BENCKMARK /////////////////////////////////////////////////////////////////////////////////////////////// - - // base object init - GraficCommon*matrix_benck = (GraficCommon*)malloc(sizeof(GraficObject)); - // init devices - char device[100] = ""; - init(matrix_benck, 0,arguments_parameters->gpu, device); if (!arguments_parameters->csv_format_timestamp && !arguments_parameters->csv_format && !arguments_parameters->mute_messages ){ printf("Using device: %s\n", device); } - // Update profiling clock mode - matrix_benck->profiling_clock = arguments_parameters->profiling_clock; - - // If android and opencl force profiling clock - #ifdef FORCE_PROFILING_CLOCK - matrix_benck->profiling_clock = true; - #endif - - // init memory - device_memory_init(matrix_benck, size_matrix, size_matrix, size_matrix); // copy memory to device - copy_memory_to_device(matrix_benck, A, B, size_matrix, size_matrix); + if(arguments_parameters->unified_memory) + { + #ifdef UMA_COMPATIBILITY + sync_unified_memory_to_device(matrix_benck, A, B, d_C); + #endif + } + else + { + copy_memory_to_device(matrix_benck, A, B, size_matrix, size_matrix); + } + // execute kernel execute_kernel(matrix_benck, arguments_parameters->size, arguments_parameters->size, arguments_parameters->size); + // copy memory to host - copy_memory_to_host(matrix_benck, d_C, size_matrix); + if (arguments_parameters->unified_memory) + { + #ifdef UMA_COMPATIBILITY + sync_unified_memory_to_host(matrix_benck, d_C, mem_size); + #endif + } else + { + copy_memory_to_host(matrix_benck, d_C, size_matrix); + } + // get time if (arguments_parameters->print_timing || arguments_parameters->csv_format || arguments_parameters->csv_format_timestamp) { get_elapsed_time(matrix_benck, arguments_parameters->csv_format); } + + // print output buffer if (arguments_parameters->print_output) { #ifdef INT - for (int i=0; isize; i++){ - for (int j=0; jsize; j++){ - printf("%d ", d_C[i*arguments_parameters->size+j]); - - } - printf("\n"); - } + for (int i=0; isize; i++){ + for (int j=0; jsize; j++){ + printf("%d ", d_C[i*arguments_parameters->size+j]); + } + printf("\n"); + } #else - for (int i=0; isize; i++){ - for (int j=0; jsize; j++){ - printf("%f ", d_C[i*arguments_parameters->size+j]); - - } - printf("\n"); - } + for (int i=0; isize; i++){ + for (int j=0; jsize; j++){ + printf("%f ", d_C[i*arguments_parameters->size+j]); + } + printf("\n"); + } #endif printf("\n"); - } + // export gpu buffer + if (arguments_parameters->export_results_gpu) + { + print_double_hexadecimal_values(GPU_FILE, d_C, size_matrix); + //set_values_file(output_file, d_C, size); + } - + //check for error if (arguments_parameters->verification) { Clock cpuKernelCLK; cpuKernelCLK.start(); matrix_multiplication(A, B, h_C, arguments_parameters->size, arguments_parameters->size, arguments_parameters->size); cpuKernelCLK.end(); + if (arguments_parameters->print_timing) { printf("CPU Time %.0f milliseconds\n", cpuKernelCLK.getElapsedMS()); } + if (arguments_parameters->print_output) { #ifdef INT @@ -193,21 +218,16 @@ int main(int argc, char *argv[]){ } #endif } - result = compare_vectors(h_C, d_C, size_C); - if (result){ + + if (compare_vectors(h_C, d_C, size_matrix)){ printf("OK\n"); } + if (arguments_parameters->export_results){ //set_values_file(output_file, d_C, size); - print_double_hexadecimal_values(GPU_FILE, d_C, size_C); - print_double_hexadecimal_values(CPU_FILE, h_C, size_C); + print_double_hexadecimal_values(GPU_FILE, d_C, size_matrix); + print_double_hexadecimal_values(CPU_FILE, h_C, size_matrix); } - - } - if (arguments_parameters->export_results_gpu) - { - print_double_hexadecimal_values(GPU_FILE, d_C, size_C); - //set_values_file(output_file, d_C, size); } /////////////////////////////////////////////////////////////////////////////////////////////// // CLEAN MEMORY @@ -217,11 +237,16 @@ int main(int argc, char *argv[]){ free(arguments_parameters); // free object memory free(matrix_benck); - free(A); - free(B); + + if (!arguments_parameters->unified_memory) + { + free(A); + free(B); + free(d_C); + } + free(h_C); - free(d_C); -return 0; + return 0; } diff --git a/gpu4s_benchmark/matrix_multiplication_bench_fp16/opencl/lib_opencl_common.cpp b/gpu4s_benchmark/matrix_multiplication_bench_fp16/opencl/lib_opencl_common.cpp index 3831724e..4e605eed 100644 --- a/gpu4s_benchmark/matrix_multiplication_bench_fp16/opencl/lib_opencl_common.cpp +++ b/gpu4s_benchmark/matrix_multiplication_bench_fp16/opencl/lib_opencl_common.cpp @@ -211,4 +211,38 @@ void clean(GraficCommon* device_object){ delete deviceObj->d_half_B; delete deviceObj->d_half_C; #endif -} \ No newline at end of file +} + + +#ifdef UMA_COMPATIBILITY +// ====== UMA function ====== +void get_unified_memory_pointers(GraficCommon* device_object, bench_t* &A, bench_t* &B, bench_t* &C, unsigned int memSize){ + GraficObject* deviceObj = static_cast(device_object); + // --- Call the openCL common function --- + map_unified_memory(device_object, memSize, + BufferMapCL{&A, deviceObj->d_A, nullptr}, + BufferMapCL{&B, deviceObj->d_B, nullptr}, + BufferMapCL{&C, deviceObj->d_C, nullptr} + ); +} + +void sync_unified_memory_to_device(GraficCommon* device_object, bench_t* &A, bench_t* &B, bench_t* &C){ + GraficObject* deviceObj = static_cast(device_object); + // --- Call the openCL common function --- + unmap_unified_memory(device_object, + BufferMapCL{&A, deviceObj->d_A, deviceObj->evt_copyA}, + BufferMapCL{&B, deviceObj->d_B, deviceObj->evt_copyB}, + BufferMapCL{&C, deviceObj->d_C, nullptr} + ); +} + + +void sync_unified_memory_to_host(GraficCommon* device_object, bench_t* &d_output, unsigned int memSize){ + GraficObject* deviceObj = static_cast(device_object); + // --- Call the openCL common function --- + map_unified_memory_to_host(device_object, memSize, + BufferMapCL{&d_output, deviceObj->d_C, deviceObj->evt_copyC} + ); +} + +#endif \ No newline at end of file diff --git a/gpu4s_benchmark/matrix_multiplication_bench_fp16/opencl/lib_opencl_lib.cpp b/gpu4s_benchmark/matrix_multiplication_bench_fp16/opencl/lib_opencl_lib.cpp index 34a4d3a1..30865e2e 100644 --- a/gpu4s_benchmark/matrix_multiplication_bench_fp16/opencl/lib_opencl_lib.cpp +++ b/gpu4s_benchmark/matrix_multiplication_bench_fp16/opencl/lib_opencl_lib.cpp @@ -1,6 +1,7 @@ // OpenCL lib code #include #include "../benchmark_library.h" +#include "../../common/opencl_common.hpp" #include void execute_kernel(GraficCommon* device_object, unsigned int n, unsigned int m, unsigned int w){ From 70c8fe7477473de5e836252c05f8a164a78e60b6 Mon Sep 17 00:00:00 2001 From: Noah Perret Date: Thu, 13 Aug 2026 19:22:32 +0200 Subject: [PATCH 14/27] add android UMA for matrix mult tensor bench --- .../main.cpp | 193 ++++++++++-------- .../opencl/lib_opencl_common.cpp | 37 +++- 2 files changed, 146 insertions(+), 84 deletions(-) diff --git a/gpu4s_benchmark/matrix_multiplication_tensor_bench/main.cpp b/gpu4s_benchmark/matrix_multiplication_tensor_bench/main.cpp index d54dc2c3..aca39735 100644 --- a/gpu4s_benchmark/matrix_multiplication_tensor_bench/main.cpp +++ b/gpu4s_benchmark/matrix_multiplication_tensor_bench/main.cpp @@ -25,7 +25,8 @@ int main(int argc, char *argv[]){ int resolution = arguments_handler(argc,argv,arguments_parameters); - if (resolution == ERROR_ARGUMENTS){ + if (resolution == ERROR_ARGUMENTS) + { exit(-1); } /////////////////////////////////////////////////////////////////////////////////////////////// @@ -33,40 +34,64 @@ int main(int argc, char *argv[]){ /////////////////////////////////////////////////////////////////////////////////////////////// // linearizable versions of matrix unsigned int size_matrix = arguments_parameters->size * arguments_parameters->size; + unsigned int mem_size = sizeof(bench_t) * size_matrix; // A input matrix - unsigned int size_A = arguments_parameters->size * arguments_parameters->size; - unsigned int mem_size_A = sizeof(bench_t) * size_A; - bench_t* A = (bench_t*) malloc(mem_size_A); + bench_t* A = (bench_t*) malloc(mem_size); // B input matrix - unsigned int size_B = arguments_parameters->size * arguments_parameters->size; - unsigned int mem_size_B = sizeof(bench_t) * size_B; - bench_t* B = (bench_t*) malloc(mem_size_B); + bench_t* B = (bench_t*) malloc(mem_size); // C matrix - unsigned int size_C = arguments_parameters->size * arguments_parameters->size; - unsigned int mem_size_C = sizeof(bench_t) * size_C; - bench_t* h_C = (bench_t*) malloc(mem_size_C); - bench_t* d_C = (bench_t*) malloc(mem_size_C); - // auxiliar matrix for compare the output - bench_t* h_C_output = (bench_t*) malloc(mem_size_C);; - // comparation result - bool result = false; + bench_t* d_C = (bench_t*) malloc(mem_size); + bench_t* h_C = (bench_t*) malloc(mem_size); + // init devices + char device[100] = ""; + + // main object init + GraficCommon*matrix_benck = (GraficCommon*)malloc(sizeof(GraficObject)); + + // --- 1. Init Device & Context --- + init(matrix_benck, 0, arguments_parameters->gpu, device); + // Update profiling clock mode + matrix_benck->profiling_clock = arguments_parameters->profiling_clock; + + // --- 2. Allocate Device Memory --- + device_memory_init(matrix_benck, size_matrix, size_matrix, size_matrix); + + + // --- 3. Allocate Host Pointers --- + if (arguments_parameters->unified_memory) + { + #ifdef UMA_COMPATIBILITY + // map the buffzer to the gpu + cpu take the lead + get_unified_memory_pointers(matrix_benck, A, B, d_C, mem_size); + #else + fprintf(stderr, "\033[1;31merror:\033[0m This framework is not compatible with unified memory. Please remove the -u arg!\n"); + exit(-1); + #endif + } else + { + // normale malloc + A = (bench_t*) malloc(mem_size); + B = (bench_t*) malloc(mem_size); + d_C = (bench_t*) malloc(mem_size); + } + + /////////////////////////////////////////////////////////////////////////////////////////////// // DATA INIT /////////////////////////////////////////////////////////////////////////////////////////////// if (strlen(arguments_parameters->input_file_A) == 0) { - // inicialice A matrix + // inicialice A matrix for (int i=0; isize; i++){ for (int j=0; jsize; j++){ #ifdef INT A[i*arguments_parameters->size+j] = rand() % (NUMBER_BASE * 100); - #else A[i*arguments_parameters->size+j] = (bench_t)rand()/(bench_t)(RAND_MAX/NUMBER_BASE); #endif } } - // iniciate B matrix + // iniciate B matrix for (int i=0; isize; i++){ for (int j=0; jsize; j++){ #ifdef INT @@ -76,101 +101,105 @@ int main(int argc, char *argv[]){ #endif } } - // iniciate C matrix - for (int i=0; isize; i++){ - for (int j=0; jsize; j++){ - h_C[i*arguments_parameters->size+j] = 0; - d_C[i*arguments_parameters->size+j] = 0; - - } - } } else { /// load data - get_double_hexadecimal_values(arguments_parameters->input_file_A, A,size_A); - get_double_hexadecimal_values(arguments_parameters->input_file_B, B,size_B); + get_double_hexadecimal_values(arguments_parameters->input_file_A, A,size_matrix); + get_double_hexadecimal_values(arguments_parameters->input_file_B, B,size_matrix); //get_values_file(input_file, A, B); - // iniciate C matrix - for (int i=0; isize; i++){ - for (int j=0; jsize; j++){ - h_C[i*arguments_parameters->size+j] = 0; - d_C[i*arguments_parameters->size+j] = 0; - - } + } + + // reset output C matrix + for (int i=0; isize; i++){ + for (int j=0; jsize; j++){ + h_C[i*arguments_parameters->size+j] = 0; + d_C[i*arguments_parameters->size+j] = 0; + } } - + /////////////////////////////////////////////////////////////////////////////////////////////// // CODE BENCKMARK /////////////////////////////////////////////////////////////////////////////////////////////// - - // base object init - GraficCommon*matrix_benck = (GraficCommon*)malloc(sizeof(GraficObject)); - // init devices - char device[100] = ""; - init(matrix_benck, 0, arguments_parameters->gpu, device); if (!arguments_parameters->csv_format_timestamp && !arguments_parameters->csv_format && !arguments_parameters->mute_messages ){ printf("Using device: %s\n", device); } - - // Update profiling clock mode - matrix_benck->profiling_clock = arguments_parameters->profiling_clock; - // If android and opencl force profiling clock - #ifdef FORCE_PROFILING_CLOCK - matrix_benck->profiling_clock = true; - #endif - // init memory - device_memory_init(matrix_benck, size_matrix, size_matrix, size_matrix); // copy memory to device - copy_memory_to_device(matrix_benck, A, B, size_matrix, size_matrix); + if(arguments_parameters->unified_memory) + { + #ifdef UMA_COMPATIBILITY + sync_unified_memory_to_device(matrix_benck, A, B, d_C); + #endif + } + else + { + copy_memory_to_device(matrix_benck, A, B, size_matrix, size_matrix); + } + // execute kernel execute_kernel(matrix_benck, arguments_parameters->size, arguments_parameters->size, arguments_parameters->size); + // copy memory to host - copy_memory_to_host(matrix_benck, d_C, size_matrix); + if (arguments_parameters->unified_memory) + { + #ifdef UMA_COMPATIBILITY + sync_unified_memory_to_host(matrix_benck, d_C, mem_size); + #endif + } else + { + copy_memory_to_host(matrix_benck, d_C, size_matrix); + } // get time if (arguments_parameters->print_timing || arguments_parameters->csv_format || arguments_parameters->csv_format_timestamp) { get_elapsed_time(matrix_benck, arguments_parameters->csv_format); } + + // print output buffer if (arguments_parameters->print_output) { #ifdef INT - for (int i=0; isize; i++){ - for (int j=0; jsize; j++){ - printf("%d ", d_C[i*arguments_parameters->size+j]); - - } - printf("\n"); - } + for (int i=0; isize; i++){ + for (int j=0; jsize; j++){ + printf("%d ", d_C[i*arguments_parameters->size+j]); + } + printf("\n"); + } #else - for (int i=0; isize; i++){ - for (int j=0; jsize; j++){ - printf("%f ", d_C[i*arguments_parameters->size+j]); - - } - printf("\n"); - } + for (int i=0; isize; i++){ + for (int j=0; jsize; j++){ + printf("%f ", d_C[i*arguments_parameters->size+j]); + } + printf("\n"); + } #endif - - } + // export gpu buffer + if (arguments_parameters->export_results_gpu) + { + print_double_hexadecimal_values(GPU_FILE, d_C, size_matrix); + //set_values_file(output_file, d_C, size); + } + //check for error if (arguments_parameters->verification) { Clock kernelCLK; kernelCLK.start(); matrix_multiplication(A, B, h_C, arguments_parameters->size, arguments_parameters->size, arguments_parameters->size); kernelCLK.end(); + if (arguments_parameters->print_timing) { printf("CPU Time %.0f milliseconds\n", kernelCLK.getElapsedMS() ); } + if (arguments_parameters->print_output) { #ifdef INT @@ -191,21 +220,16 @@ int main(int argc, char *argv[]){ } #endif } - result = compare_vectors(h_C, d_C, size_C); - if (result){ + + if (compare_vectors(h_C, d_C, size_matrix)){ printf("OK\n"); } if (arguments_parameters->export_results){ //set_values_file(output_file, d_C, size); - print_double_hexadecimal_values(GPU_FILE, d_C, size_C); - print_double_hexadecimal_values(CPU_FILE, h_C, size_C); + print_double_hexadecimal_values(GPU_FILE, d_C, size_matrix); + print_double_hexadecimal_values(CPU_FILE, h_C, size_matrix); } } - if (arguments_parameters->export_results_gpu) - { - print_double_hexadecimal_values(GPU_FILE, d_C, size_C); - //set_values_file(output_file, d_C, size); - } /////////////////////////////////////////////////////////////////////////////////////////////// // CLEAN MEMORY /////////////////////////////////////////////////////////////////////////////////////////////// @@ -214,15 +238,18 @@ int main(int argc, char *argv[]){ free(arguments_parameters); // free object memory free(matrix_benck); - free(A); - free(B); + + if (!arguments_parameters->unified_memory) + { + free(A); + free(B); + free(d_C); + } free(h_C); - free(d_C); -return 0; + return 0; } -// Arguments part // Arguments part void print_usage(const char * appName) { diff --git a/gpu4s_benchmark/matrix_multiplication_tensor_bench/opencl/lib_opencl_common.cpp b/gpu4s_benchmark/matrix_multiplication_tensor_bench/opencl/lib_opencl_common.cpp index 8240dbbf..6fe0545f 100644 --- a/gpu4s_benchmark/matrix_multiplication_tensor_bench/opencl/lib_opencl_common.cpp +++ b/gpu4s_benchmark/matrix_multiplication_tensor_bench/opencl/lib_opencl_common.cpp @@ -155,4 +155,39 @@ void clean(GraficCommon* device_object){ delete deviceObj->evt_copyA; delete deviceObj->evt_copyB; delete deviceObj->evt_copyC; -} \ No newline at end of file +} + + + +#ifdef UMA_COMPATIBILITY +// ====== UMA function ====== +void get_unified_memory_pointers(GraficCommon* device_object, bench_t* &A, bench_t* &B, bench_t* &C, unsigned int memSize){ + GraficObject* deviceObj = static_cast(device_object); + // --- Call the openCL common function --- + map_unified_memory(device_object, memSize, + BufferMapCL{&A, deviceObj->d_A, nullptr}, + BufferMapCL{&B, deviceObj->d_B, nullptr}, + BufferMapCL{&C, deviceObj->d_C, nullptr} + ); +} + +void sync_unified_memory_to_device(GraficCommon* device_object, bench_t* &A, bench_t* &B, bench_t* &C){ + GraficObject* deviceObj = static_cast(device_object); + // --- Call the openCL common function --- + unmap_unified_memory(device_object, + BufferMapCL{&A, deviceObj->d_A, deviceObj->evt_copyA}, + BufferMapCL{&B, deviceObj->d_B, deviceObj->evt_copyB}, + BufferMapCL{&C, deviceObj->d_C, nullptr} + ); +} + + +void sync_unified_memory_to_host(GraficCommon* device_object, bench_t* &d_output, unsigned int memSize){ + GraficObject* deviceObj = static_cast(device_object); + // --- Call the openCL common function --- + map_unified_memory_to_host(device_object, memSize, + BufferMapCL{&d_output, deviceObj->d_C, deviceObj->evt_copyC} + ); +} + +#endif \ No newline at end of file From c7b0be146ab82442f06c2f09596b0475769bccec Mon Sep 17 00:00:00 2001 From: Noah Perret Date: Thu, 13 Aug 2026 19:41:26 +0200 Subject: [PATCH 15/27] add UMA for android --- gpu4s_benchmark/max_pooling_bench/main.cpp | 152 +++++++++++------- .../opencl/lib_opencl_common.cpp | 31 ++++ 2 files changed, 126 insertions(+), 57 deletions(-) diff --git a/gpu4s_benchmark/max_pooling_bench/main.cpp b/gpu4s_benchmark/max_pooling_bench/main.cpp index 870aa9ba..96cc44bd 100644 --- a/gpu4s_benchmark/max_pooling_bench/main.cpp +++ b/gpu4s_benchmark/max_pooling_bench/main.cpp @@ -31,8 +31,6 @@ int main(int argc, char *argv[]){ /////////////////////////////////////////////////////////////////////////////////////////////// // VARIABLES /////////////////////////////////////////////////////////////////////////////////////////////// - // linearizable versions of matrix - unsigned int size_matrix =arguments_parameters->size * arguments_parameters->size; // A input matrix unsigned int size_A = arguments_parameters->size * arguments_parameters->size; unsigned int mem_size_A = sizeof(bench_t) * size_A; @@ -41,27 +39,56 @@ int main(int argc, char *argv[]){ unsigned int size_lateral = arguments_parameters->size / arguments_parameters->stride; unsigned int size_B = size_lateral * size_lateral; unsigned int mem_size_B = sizeof(bench_t) * size_B; - bench_t* h_B = (bench_t*) malloc(mem_size_B); bench_t* d_B = (bench_t*) malloc(mem_size_B); - // comparation result - bool result = false; + bench_t* h_B = (bench_t*) malloc(mem_size_B); + // init devices + char device[100] = ""; + + // main object init + GraficCommon*max_bench = (GraficCommon*)malloc(sizeof(GraficObject)); + + // --- 1. Init Device & Context --- + init(max_bench, 0,arguments_parameters->gpu, device); + // Update profiling clock mode + max_bench->profiling_clock = arguments_parameters->profiling_clock; + + // --- 2. Allocate Device Memory --- + device_memory_init(max_bench, size_A, size_B); + + // --- 3. Allocate Host Pointers --- + if (arguments_parameters->unified_memory) + { + #ifdef UMA_COMPATIBILITY + // map the buffzer to the gpu + cpu take the lead + get_unified_memory_pointers(max_bench, A, mem_size_A); + #else + fprintf(stderr, "\033[1;31merror:\033[0m This framework is not compatible with unified memory. Please remove the -u arg!\n"); + exit(-1); + #endif + } else + { + // normale malloc + A = (bench_t*) malloc(mem_size_A); + d_B = (bench_t*) malloc(mem_size_B); + } + + /////////////////////////////////////////////////////////////////////////////////////////////// // DATA INIT /////////////////////////////////////////////////////////////////////////////////////////////// if (strlen(arguments_parameters->input_file_A) == 0) { - // inicialice A matrix + // inicialice input A matrix for (int i=0; isize; i++){ for (int j=0; jsize; j++){ #ifdef INT A[i*arguments_parameters->size+j] = rand() % (NUMBER_BASE * 100); - #else A[i*arguments_parameters->size+j] = (double)rand()/RAND_MAX*2.0-1.0; #endif } } - // iniciate B matrix + // iniciate output B matrix for (int i=0; iprint_input) { @@ -103,76 +131,84 @@ int main(int argc, char *argv[]){ /////////////////////////////////////////////////////////////////////////////////////////////// // CODE BENCKMARK /////////////////////////////////////////////////////////////////////////////////////////////// - - // base object init - GraficCommon*max_bench = (GraficCommon*)malloc(sizeof(GraficObject)); - // init devices - char device[100] = ""; - init(max_bench, 0,arguments_parameters->gpu, device); if (!arguments_parameters->csv_format_timestamp && !arguments_parameters->csv_format && !arguments_parameters->mute_messages ){ printf("Using device: %s\n", device); } - - - // Update profiling clock mode - max_bench->profiling_clock = arguments_parameters->profiling_clock; - // If android and opencl force profiling clock - #ifdef FORCE_PROFILING_CLOCK - max_bench->profiling_clock = true; - #endif - - // init memory - device_memory_init(max_bench, arguments_parameters->size * arguments_parameters->size, size_B); // copy memory to device - copy_memory_to_device(max_bench, A, arguments_parameters->size * arguments_parameters->size); + if(arguments_parameters->unified_memory) + { + #ifdef UMA_COMPATIBILITY + sync_unified_memory_to_device(max_bench, A); + #endif + } + else + { + copy_memory_to_device(max_bench, A, size_A); + } + // execute kernel execute_kernel(max_bench, arguments_parameters->size, arguments_parameters->size, arguments_parameters->size, arguments_parameters->stride, size_lateral); + // copy memory to host - copy_memory_to_host(max_bench, d_B, size_B); + if (arguments_parameters->unified_memory) + { + #ifdef UMA_COMPATIBILITY + sync_unified_memory_to_host(max_bench, d_B, size_B); + #endif + } else + { + copy_memory_to_host(max_bench, d_B, size_B); + } // get time if (arguments_parameters->print_timing || arguments_parameters->csv_format || arguments_parameters->csv_format_timestamp) { get_elapsed_time(max_bench, arguments_parameters->csv_format, arguments_parameters->csv_format_timestamp, get_timestamp()); } + + // print output buffer if (arguments_parameters->print_output) { #ifdef INT - for (int i=0; iexport_results_gpu) + { + print_double_hexadecimal_values(GPU_FILE, d_B, size_B); + } - + //check for error if (arguments_parameters->verification) { Clock cpuKernelCLK; cpuKernelCLK.start(); max_pooling(A, h_B, arguments_parameters->size, arguments_parameters->stride, size_lateral); cpuKernelCLK.end(); + if (arguments_parameters->print_timing) { printf("CPU Time %.0f milliseconds\n", cpuKernelCLK.getElapsedMS()); } + if (arguments_parameters->print_output) { #ifdef INT @@ -193,20 +229,18 @@ int main(int argc, char *argv[]){ } #endif } - result = compare_vectors(h_B, d_B, size_B); - if (result){ + + if (compare_vectors(h_B, d_B, size_B)) + { printf("OK\n"); } - if (arguments_parameters->export_results){ + if (arguments_parameters->export_results) + { print_double_hexadecimal_values(GPU_FILE, d_B, size_B); print_double_hexadecimal_values(CPU_FILE, h_B, size_B); } } - if (arguments_parameters->export_results_gpu) - { - print_double_hexadecimal_values(GPU_FILE, d_B, size_B); - } /////////////////////////////////////////////////////////////////////////////////////////////// // CLEAN MEMORY /////////////////////////////////////////////////////////////////////////////////////////////// @@ -215,15 +249,19 @@ int main(int argc, char *argv[]){ // free object memory free(max_bench); free(arguments_parameters); - free(A); + + if (!arguments_parameters->unified_memory) + { + free(A); + free(d_B); + } + free(h_B); - free(d_B); -return 0; + return 0; } // Arguments part - void print_usage(const char * appName) { printf("Usage: %s -s Size -k [-v] [-e] [-o] [-t] [-d] [-i input_file_A_MATRIX input_file_B_MATRIX] \n", appName); diff --git a/gpu4s_benchmark/max_pooling_bench/opencl/lib_opencl_common.cpp b/gpu4s_benchmark/max_pooling_bench/opencl/lib_opencl_common.cpp index 78b1792a..d4a65e16 100644 --- a/gpu4s_benchmark/max_pooling_bench/opencl/lib_opencl_common.cpp +++ b/gpu4s_benchmark/max_pooling_bench/opencl/lib_opencl_common.cpp @@ -6,6 +6,7 @@ * ESA-PL Strong Copyleft – v2.5 * ======================================================================= */ #include "../benchmark_library.h" +#include "../../common/opencl_common.hpp" void init(GraficCommon* device_object, char* device_name){ init(device_object, 0,0, device_name); @@ -146,3 +147,33 @@ void clean(GraficCommon* device_object){ delete deviceObj->evt_copyA; delete deviceObj->evt_copyB; } + + +#ifdef UMA_COMPATIBILITY +// ====== UMA function ====== +void get_unified_memory_pointers(GraficCommon* device_object, bench_t* &A, unsigned int memSize){ + GraficObject* deviceObj = static_cast(device_object); + // --- Call the openCL common function --- + map_unified_memory(device_object, memSize, + BufferMapCL{&A, deviceObj->d_A, nullptr} + ); +} + +void sync_unified_memory_to_device(GraficCommon* device_object, bench_t* &A){ + GraficObject* deviceObj = static_cast(device_object); + // --- Call the openCL common function --- + unmap_unified_memory(device_object, + BufferMapCL{&A, deviceObj->d_A, deviceObj->evt_copyA} + ); +} + + +void sync_unified_memory_to_host(GraficCommon* device_object, bench_t* &d_output, unsigned int memSize){ + GraficObject* deviceObj = static_cast(device_object); + // --- Call the openCL common function --- + map_unified_memory_to_host(device_object, memSize, + BufferMapCL{&d_output, deviceObj->d_B, deviceObj->evt_copyB} + ); +} + +#endif \ No newline at end of file From 4f9cb99ced77a0b5c145951866129e86098d093f Mon Sep 17 00:00:00 2001 From: Noah Perret Date: Fri, 14 Aug 2026 11:32:28 +0200 Subject: [PATCH 16/27] add androdi uma for android --- .../memory_bandwidth_bench/main.cpp | 178 +++++++++++------- .../opencl/lib_opencl.cpp | 35 ++++ 2 files changed, 141 insertions(+), 72 deletions(-) diff --git a/gpu4s_benchmark/memory_bandwidth_bench/main.cpp b/gpu4s_benchmark/memory_bandwidth_bench/main.cpp index 2a2d373d..9dd228ed 100644 --- a/gpu4s_benchmark/memory_bandwidth_bench/main.cpp +++ b/gpu4s_benchmark/memory_bandwidth_bench/main.cpp @@ -34,145 +34,174 @@ int main(int argc, char *argv[]) // VARIABLES /////////////////////////////////////////////////////////////////////////////////////////////// // linearizable versions of matrix - unsigned int size_matrix =arguments_parameters->size * arguments_parameters->size; + unsigned int size_matrix = arguments_parameters->size * arguments_parameters->size; + unsigned int mem_size = sizeof(bench_t) * size_matrix; // A input matrix - unsigned int size_A = arguments_parameters->size * arguments_parameters->size; - unsigned int mem_size_A = sizeof(bench_t) * size_A; - bench_t* A = (bench_t*) malloc(mem_size_A); + bench_t* A = (bench_t*) malloc(mem_size); // B output matrix - unsigned int size_B = arguments_parameters->size * arguments_parameters->size; - unsigned int mem_size_B = sizeof(bench_t) * size_B; - bench_t* h_B = (bench_t*) malloc(mem_size_B); - bench_t* d_B = (bench_t*) malloc(mem_size_B); - // comparation result - bool result = false; + bench_t* d_B = (bench_t*) malloc(mem_size); + bench_t* h_B = (bench_t*) malloc(mem_size); + // init devices + char device[100] = ""; + + // main object init + GraficCommon*mem_bench = (GraficCommon*)malloc(sizeof(GraficObject)); + + // --- 1. Init Device & Context --- + init(mem_bench, 0,arguments_parameters->gpu, device); + + // Update profiling clock mode + mem_bench->profiling_clock = arguments_parameters->profiling_clock; + + // --- 2. Allocate Device Memory --- + device_memory_init(mem_bench, size_matrix, size_matrix); + + + // --- 3. Allocate Host Pointers --- + if (arguments_parameters->unified_memory) + { + #ifdef UMA_COMPATIBILITY + // map the buffzer to the gpu + cpu take the lead + get_unified_memory_pointers(mem_bench, A, d_B, mem_size); + #else + fprintf(stderr, "\033[1;31merror:\033[0m This framework is not compatible with unified memory. Please remove the -u arg!\n"); + exit(-1); + #endif + } else + { + // normale malloc + A = (bench_t*) malloc(mem_size); + d_B = (bench_t*) malloc(mem_size); + } + + /////////////////////////////////////////////////////////////////////////////////////////////// // DATA INIT /////////////////////////////////////////////////////////////////////////////////////////////// if (strlen(arguments_parameters->input_file_A) == 0) { // inicialice A matrix - for (int i=0; iinput_file_A, A,size_A); + get_double_hexadecimal_values(arguments_parameters->input_file_A, A, size_matrix); + } - // iniciate B matrix - for (int i=0; igpu, device); if (!arguments_parameters->csv_format_timestamp && !arguments_parameters->csv_format && !arguments_parameters->mute_messages ){ printf("Using device: %s\n", device); } - // Update profiling clock mode - mem_bench->profiling_clock = arguments_parameters->profiling_clock; - - // If android and opencl force profiling clock - #ifdef FORCE_PROFILING_CLOCK - mem_bench->profiling_clock = true; - #endif - - - // init memory - device_memory_init(mem_bench, size_A , size_B ); // copy memory to device - copy_memory_to_device(mem_bench, A, size_A); + if(arguments_parameters->unified_memory) + { + #ifdef UMA_COMPATIBILITY + sync_unified_memory_to_device(mem_bench, A, d_B); + #endif + } + else + { + copy_memory_to_device(mem_bench, A, size_matrix); + } + + // execute kernel - execute_kernel(mem_bench, size_A); + execute_kernel(mem_bench, size_matrix); + // copy memory to host - copy_memory_to_host(mem_bench, h_B, size_B); + if (arguments_parameters->unified_memory) + { + #ifdef UMA_COMPATIBILITY + sync_unified_memory_to_host(mem_bench, d_B, size_matrix); + #endif + } else + { + copy_memory_to_host(mem_bench, d_B, size_matrix); + } // get time if (arguments_parameters->print_timing || arguments_parameters->csv_format || arguments_parameters->csv_format_timestamp) { get_elapsed_time(mem_bench, arguments_parameters->csv_format); } + + // print output buffer if (arguments_parameters->print_output) { #ifdef INT - for (int i=0; iexport_results_gpu) + { + print_double_hexadecimal_values(GPU_FILE, d_B, size_matrix); + } + + //check for error if (arguments_parameters->verification) { Clock cpuKernelCLK; cpuKernelCLK.start(); - memcpy(d_B, A, mem_size_A); + memcpy(h_B, A, mem_size); cpuKernelCLK.end(); + if (arguments_parameters->print_timing) { printf("CPU Time %.0f milliseconds\n", cpuKernelCLK.getElapsedMS()); } + if (arguments_parameters->print_output) { #ifdef INT - for (int i=0; iexport_results){ - print_double_hexadecimal_values(GPU_FILE, h_B, size_B); - print_double_hexadecimal_values(CPU_FILE, A, size_B); + print_double_hexadecimal_values(GPU_FILE, d_B, size_matrix); + print_double_hexadecimal_values(CPU_FILE, h_B, size_matrix); } - - } - if (arguments_parameters->export_results_gpu) - { - print_double_hexadecimal_values(GPU_FILE, h_B, size_B); } /////////////////////////////////////////////////////////////////////////////////////////////// // CLEAN MEMORY @@ -182,10 +211,15 @@ int main(int argc, char *argv[]) free(arguments_parameters); // free object memory free(mem_bench); - free(A); + + if (!arguments_parameters->unified_memory) + { + free(A); + free(d_B); + } + free(h_B); - free(d_B); -return 0; + return 0; } diff --git a/gpu4s_benchmark/memory_bandwidth_bench/opencl/lib_opencl.cpp b/gpu4s_benchmark/memory_bandwidth_bench/opencl/lib_opencl.cpp index 18f01313..dbdbbd6b 100644 --- a/gpu4s_benchmark/memory_bandwidth_bench/opencl/lib_opencl.cpp +++ b/gpu4s_benchmark/memory_bandwidth_bench/opencl/lib_opencl.cpp @@ -1,6 +1,7 @@ // OpenCL lib code #include #include "../benchmark_library.h" +#include "../../common/opencl_common.hpp" #include #include "kernel.cl" @@ -157,3 +158,37 @@ void clean(GraficCommon* device_object){ delete deviceObj->evt_copyB; delete deviceObj->evt_copyC; } + + + +#ifdef UMA_COMPATIBILITY +// ====== UMA function ====== +void get_unified_memory_pointers(GraficCommon* device_object, bench_t* &A, bench_t* &B, unsigned int memSize){ + GraficObject* deviceObj = static_cast(device_object); + // --- Call the openCL common function --- + map_unified_memory(device_object, memSize, + BufferMapCL{&A, deviceObj->d_A, nullptr}, + BufferMapCL{&B, deviceObj->d_B, nullptr} + ); +} + +void sync_unified_memory_to_device(GraficCommon* device_object, bench_t* &A, bench_t* &B){ + GraficObject* deviceObj = static_cast(device_object); + // --- Call the openCL common function --- + unmap_unified_memory(device_object, + BufferMapCL{&A, deviceObj->d_A, deviceObj->evt_copyA}, + BufferMapCL{&B, deviceObj->d_B, nullptr} + ); +} + + +void sync_unified_memory_to_host(GraficCommon* device_object, bench_t* &d_output, unsigned int memSize){ + GraficObject* deviceObj = static_cast(device_object); + // --- Call the openCL common function --- + map_unified_memory_to_host(device_object, memSize, + BufferMapCL{&d_output, deviceObj->d_B, deviceObj->evt_copyB} + ); +} + + +#endif \ No newline at end of file From 0670bfb92d236615f8c0cf149162577c69d7c520 Mon Sep 17 00:00:00 2001 From: Noah Perret Date: Fri, 14 Aug 2026 12:10:24 +0200 Subject: [PATCH 17/27] delete opencl lib (it was a buggy opt version) add uma for softmax --- gpu4s_benchmark/softmax_bench/CMakeLists.txt | 27 --- gpu4s_benchmark/softmax_bench/main.cpp | 159 +++++++++++------- .../opencl/lib_opencl_common.cpp | 30 ++++ .../softmax_bench/opencl/lib_opencl_lib.cpp | 66 -------- 4 files changed, 128 insertions(+), 154 deletions(-) delete mode 100644 gpu4s_benchmark/softmax_bench/opencl/lib_opencl_lib.cpp diff --git a/gpu4s_benchmark/softmax_bench/CMakeLists.txt b/gpu4s_benchmark/softmax_bench/CMakeLists.txt index 2be96c19..17e26829 100644 --- a/gpu4s_benchmark/softmax_bench/CMakeLists.txt +++ b/gpu4s_benchmark/softmax_bench/CMakeLists.txt @@ -61,20 +61,6 @@ if(ANDROID) SHORTCUTS_NAMES opencl-opt OpenCL-opt ) - # --- OpenCL-lib --- - compile_target(${PROJECT_NAME}_opencl_lib - BENCH_DIR ${CMAKE_SOURCE_DIR} - SOURCES_FILES opencl/lib_opencl_lib.cpp - opencl/lib_opencl_common.cpp - - COMPILE_DEFS OPENCL - CL_HPP_TARGET_OPENCL_VERSION=${OPENCL_VERSION} - - INCLUDES ${ANDROID_INC} - LIBRARIES ${ANDROID_LIB}/${ANDROID_ABI}/libOpenCL.so - - SHORTCUTS_NAMES opencl-lib OpenCL-lib - ) endif() # --- OpenMP--- @@ -138,19 +124,6 @@ if(NOT ANDROID) LIBRARIES OpenCL::OpenCL SHORTCUTS_NAMES opencl-opt OpenCL-opt ) - - # --- OpenCL-lib --- - compile_target(${PROJECT_NAME}_opencl_lib - BENCH_DIR ${CMAKE_SOURCE_DIR} - SOURCES_FILES opencl/lib_opencl_lib.cpp - opencl/lib_opencl_common.cpp - - COMPILE_DEFS OPENCL - CL_HPP_TARGET_OPENCL_VERSION=${OPENCL_VERSION} - - LIBRARIES OpenCL::OpenCL - SHORTCUTS_NAMES opencl-lib OpenCL-lib - ) endif() diff --git a/gpu4s_benchmark/softmax_bench/main.cpp b/gpu4s_benchmark/softmax_bench/main.cpp index ed4c3182..764e2c41 100644 --- a/gpu4s_benchmark/softmax_bench/main.cpp +++ b/gpu4s_benchmark/softmax_bench/main.cpp @@ -31,18 +31,45 @@ int main(int argc, char *argv[]){ // VARIABLES /////////////////////////////////////////////////////////////////////////////////////////////// // linearizable versions of matrix - unsigned int size_matrix =arguments_parameters->size * arguments_parameters->size; + unsigned int size_matrix = arguments_parameters->size * arguments_parameters->size; + unsigned int mem_size = sizeof(bench_t) * size_matrix; // A input matrix - unsigned int size_A = arguments_parameters->size * arguments_parameters->size; - unsigned int mem_size_A = sizeof(bench_t) * size_A; - bench_t* A = (bench_t*) malloc(mem_size_A); + bench_t* A = nullptr; // B input matrix - unsigned int size_B = arguments_parameters->size * arguments_parameters->size; - unsigned int mem_size_B = sizeof(bench_t) * size_B; - bench_t* h_B = (bench_t*) malloc(mem_size_B); - bench_t* d_B = (bench_t*) malloc(mem_size_B); - // comparation result - bool result = false; + bench_t* d_B = nullptr; + bench_t* h_B = (bench_t*) malloc(mem_size); + // init devices + char device[100] = ""; + + // main object init + GraficCommon*softmax_bench = (GraficCommon*)malloc(sizeof(GraficObject)); + + // --- 1. Init Device & Context --- + init(softmax_bench, 0,arguments_parameters->gpu, device); + // Update profiling clock mode + softmax_bench->profiling_clock = arguments_parameters->profiling_clock; + + // --- 2. Allocate Device Memory --- + device_memory_init(softmax_bench, size_matrix, size_matrix); + + + // --- 3. Allocate Host Pointers --- + if (arguments_parameters->unified_memory) + { + #ifdef UMA_COMPATIBILITY + // map the buffzer to the gpu + cpu take the lead + get_unified_memory_pointers(softmax_bench, A, d_B, mem_size); + #else + fprintf(stderr, "\033[1;31merror:\033[0m This framework is not compatible with unified memory. Please remove the -u arg!\n"); + exit(-1); + #endif + } else + { + // normale malloc + A = (bench_t*) malloc(mem_size); + d_B = (bench_t*) malloc(mem_size); + } + /////////////////////////////////////////////////////////////////////////////////////////////// // DATA INIT /////////////////////////////////////////////////////////////////////////////////////////////// @@ -53,13 +80,12 @@ int main(int argc, char *argv[]){ for (int j=0; jsize; j++){ #ifdef INT A[i*arguments_parameters->size+j] = rand() % (NUMBER_BASE * 100); - #else A[i*arguments_parameters->size+j] = (double)rand()/RAND_MAX*2.0-1.0; #endif } } - // iniciate B matrix + // reset output B matrix for (int i=0; isize; i++){ for (int j=0; jsize; j++){ h_B[i*arguments_parameters->size+j] = 0; @@ -82,6 +108,7 @@ int main(int argc, char *argv[]){ } }*/ } + // print input if (arguments_parameters->print_input) { @@ -101,64 +128,70 @@ int main(int argc, char *argv[]){ /////////////////////////////////////////////////////////////////////////////////////////////// // CODE BENCKMARK /////////////////////////////////////////////////////////////////////////////////////////////// - - // base object init - GraficCommon*softmax_bench = (GraficCommon*)malloc(sizeof(GraficObject)); - // init devices - char device[100] = ""; - init(softmax_bench, 0,arguments_parameters->gpu, device); if (!arguments_parameters->csv_format_timestamp && !arguments_parameters->csv_format && !arguments_parameters->mute_messages ){ printf("Using device: %s\n", device); } - - // Update profiling clock mode - softmax_bench->profiling_clock = arguments_parameters->profiling_clock; - // If android and opencl force profiling clock - #ifdef FORCE_PROFILING_CLOCK - softmax_bench->profiling_clock = true; - #endif - - - // init memory - device_memory_init(softmax_bench, arguments_parameters->size * arguments_parameters->size, arguments_parameters->size * arguments_parameters->size); // copy memory to device - copy_memory_to_device(softmax_bench, A, arguments_parameters->size * arguments_parameters->size); + if(arguments_parameters->unified_memory) + { + #ifdef UMA_COMPATIBILITY + sync_unified_memory_to_device(softmax_bench, A, d_B); + #endif + } + else + { + copy_memory_to_device(softmax_bench, A, size_matrix); + } + // execute kernel execute_kernel(softmax_bench, arguments_parameters->size, arguments_parameters->size, arguments_parameters->size); + // copy memory to host - copy_memory_to_host(softmax_bench, d_B, size_matrix); + if (arguments_parameters->unified_memory) + { + #ifdef UMA_COMPATIBILITY + sync_unified_memory_to_host(softmax_bench, d_B, size_matrix); + #endif + } else + { + copy_memory_to_host(softmax_bench, d_B, size_matrix); + } + // get time if (arguments_parameters->print_timing || arguments_parameters->csv_format || arguments_parameters->csv_format_timestamp) { get_elapsed_time(softmax_bench, arguments_parameters->csv_format, arguments_parameters->csv_format_timestamp, get_timestamp()); } + + // print output buffer if (arguments_parameters->print_output) { #ifdef INT - for (int i=0; isize; i++){ - for (int j=0; jsize; j++){ - printf("%d ", d_B[i*arguments_parameters->size+j]); - - } - printf("\n"); - } + for (int i=0; isize; i++){ + for (int j=0; jsize; j++){ + printf("%d ", d_B[i*arguments_parameters->size+j]); + } + printf("\n"); + } #else - for (int i=0; isize; i++){ - for (int j=0; jsize; j++){ - printf("%f ", d_B[i*arguments_parameters->size+j]); - - } - printf("\n"); - } - #endif - - + for (int i=0; isize; i++){ + for (int j=0; jsize; j++){ + printf("%f ", d_B[i*arguments_parameters->size+j]); + } + printf("\n"); + } + #endif } + // export gpu buffer + if (arguments_parameters->export_results_gpu) + { + print_double_hexadecimal_values(GPU_FILE, d_B, size_matrix); + } - + //check for error if (arguments_parameters->verification) { Clock cpuKernelCLK; @@ -166,10 +199,12 @@ int main(int argc, char *argv[]){ //matrix_convolution(A,kernel,h_B,size,kernel_size); softmax(A,h_B, arguments_parameters->size); cpuKernelCLK.end(); + if (arguments_parameters->print_timing) { printf("CPU Time %.0f milliseconds\n", cpuKernelCLK.getElapsedMS()); } + if (arguments_parameters->print_output) { #ifdef INT @@ -190,20 +225,18 @@ int main(int argc, char *argv[]){ } #endif } - result = compare_vectors(h_B, d_B, size_B); - if (result){ + + + if (compare_vectors(h_B, d_B, size_matrix)){ printf("OK\n"); } + if (arguments_parameters->export_results){ - print_double_hexadecimal_values(GPU_FILE, d_B, size_B); - print_double_hexadecimal_values(CPU_FILE, h_B, size_B); + print_double_hexadecimal_values(GPU_FILE, d_B, size_matrix); + print_double_hexadecimal_values(CPU_FILE, h_B, size_matrix); } } - if (arguments_parameters->export_results_gpu) - { - print_double_hexadecimal_values(GPU_FILE, d_B, size_B); - } /////////////////////////////////////////////////////////////////////////////////////////////// // CLEAN MEMORY /////////////////////////////////////////////////////////////////////////////////////////////// @@ -212,15 +245,19 @@ int main(int argc, char *argv[]){ // free object memory free(softmax_bench); free(arguments_parameters); - free(A); + + if (!arguments_parameters->unified_memory) + { + free(A); + free(d_B); + } + free(h_B); - free(d_B); -return 0; + return 0; } // Arguments part - void print_usage(const char * appName) { printf("Usage: %s -s Size [-v] [-e] [-o] [-t] [-d] [-i input_file_A_MATRIX input_file_B_MATRIX] \n", appName); diff --git a/gpu4s_benchmark/softmax_bench/opencl/lib_opencl_common.cpp b/gpu4s_benchmark/softmax_bench/opencl/lib_opencl_common.cpp index 6df6d3f4..78834167 100644 --- a/gpu4s_benchmark/softmax_bench/opencl/lib_opencl_common.cpp +++ b/gpu4s_benchmark/softmax_bench/opencl/lib_opencl_common.cpp @@ -154,3 +154,33 @@ void clean(GraficCommon* device_object){ delete deviceObj->evt_copyB; } +#ifdef UMA_COMPATIBILITY +// ====== UMA function ====== +void get_unified_memory_pointers(GraficCommon* device_object, bench_t* &A, bench_t* &B, unsigned int memSize){ + GraficObject* deviceObj = static_cast(device_object); + // --- Call the openCL common function --- + map_unified_memory(device_object, memSize, + BufferMapCL{&A, deviceObj->d_A, nullptr}, + BufferMapCL{&B, deviceObj->d_B, nullptr} + ); +} + +void sync_unified_memory_to_device(GraficCommon* device_object, bench_t* &A, bench_t* &B){ + GraficObject* deviceObj = static_cast(device_object); + // --- Call the openCL common function --- + unmap_unified_memory(device_object, + BufferMapCL{&A, deviceObj->d_A, deviceObj->evt_copyA}, + BufferMapCL{&B, deviceObj->d_B, nullptr} + ); +} + + +void sync_unified_memory_to_host(GraficCommon* device_object, bench_t* &d_output, unsigned int memSize){ + GraficObject* deviceObj = static_cast(device_object); + // --- Call the openCL common function --- + map_unified_memory_to_host(device_object, memSize, + BufferMapCL{&d_output, deviceObj->d_B, deviceObj->evt_copyB} + ); +} + +#endif \ No newline at end of file diff --git a/gpu4s_benchmark/softmax_bench/opencl/lib_opencl_lib.cpp b/gpu4s_benchmark/softmax_bench/opencl/lib_opencl_lib.cpp deleted file mode 100644 index 5efd1ad5..00000000 --- a/gpu4s_benchmark/softmax_bench/opencl/lib_opencl_lib.cpp +++ /dev/null @@ -1,66 +0,0 @@ -// OpenCL lib code -#include -#include "../benchmark_library.h" -#include -#include "GEN_kernel_opt.hcl" -#include "GEN_atomic_functions.hcl" - -void execute_kernel(GraficCommon* device_object, unsigned int n, unsigned int m, unsigned int w){ - GraficObject* deviceObj = static_cast(device_object); - const unsigned int x_local= BLOCK_SIZE; - const unsigned int y_local= BLOCK_SIZE; - cl::NDRange local, global; - if(n < BLOCK_SIZE) - { - local = cl::NDRange (1, 1); - global = cl::NDRange (n, w); - } - else - { - local = cl::NDRange(x_local, y_local); - global = cl::NDRange(n, w); - } - - cl::Program::Sources sources; - // FIX: Removed duplicate "new cl::Event" memory leak - - // --- FIX: load the full kernel from file + #define BLOCK_SIZE --- - std::string preamble = "#define BLOCK_SIZE " + std::to_string(BLOCK_SIZE) + "\n"; - std::string full_kernel = preamble + type_kernel_common + atomic_code + kernel_code; - sources.push_back(full_kernel); - - cl::Program program(*deviceObj->context,sources); - if(program.build({deviceObj->default_device})!=CL_SUCCESS){ - std::cout<<" Error building: "<(deviceObj->default_device)<<"\n"; - exit(1); - } - - // kernel time execution - Clock kernelCLK; - - // Clock profilling start - kernelCLK.start(); - - cl::Kernel softmax_kernel=cl::Kernel(program,"kernel_softmax"); - softmax_kernel.setArg(0,*deviceObj->d_A); - softmax_kernel.setArg(1,*deviceObj->d_B); - softmax_kernel.setArg(2,*deviceObj->sum_d_B); - softmax_kernel.setArg(3,n); - - deviceObj->queue->enqueueNDRangeKernel(softmax_kernel,cl::NullRange,global,local, NULL, deviceObj->evt); - - cl::Kernel softmax_end_kernel=cl::Kernel(program,"kernel_softmax_end"); - softmax_end_kernel.setArg(0,*deviceObj->d_B); - softmax_end_kernel.setArg(1,*deviceObj->sum_d_B); - softmax_end_kernel.setArg(2,n); - - deviceObj->queue->enqueueNDRangeKernel(softmax_end_kernel,cl::NullRange,global,local, NULL, deviceObj->evt_complemet); - // Wait for completion before stopping the clock - deviceObj->queue->finish(); - // Clock profilling end - kernelCLK.end(); - - // store the kernel time - deviceObj->elapsed_time = kernelCLK.getElapsedNS(); -} - From dcc606205763b5b10ba9bf9a247e5cf6ebffb975 Mon Sep 17 00:00:00 2001 From: Noah Perret Date: Fri, 14 Aug 2026 15:36:45 +0200 Subject: [PATCH 18/27] add UMA for wavelet transform --- .../wavelet_transform/benchmark_library.h | 4 + gpu4s_benchmark/wavelet_transform/main.cpp | 164 ++++++++++++------ .../wavelet_transform/opencl/lib_opencl.cpp | 52 ++++++ 3 files changed, 167 insertions(+), 53 deletions(-) diff --git a/gpu4s_benchmark/wavelet_transform/benchmark_library.h b/gpu4s_benchmark/wavelet_transform/benchmark_library.h index d67d9a57..aa7e557c 100644 --- a/gpu4s_benchmark/wavelet_transform/benchmark_library.h +++ b/gpu4s_benchmark/wavelet_transform/benchmark_library.h @@ -71,3 +71,7 @@ struct GraficObject : public GraficCommon { }; // --- Specefic overload of benchmarking function --- +#ifdef UMA_COMPATIBILITY + void get_unified_memory_pointers(GraficCommon* device_object, bench_t* &A, bench_t* &B, bench_t* &C, bench_t* &D, unsigned int memSize); + void sync_unified_memory_to_device(GraficCommon* device_object, bench_t* &A, bench_t* &B, bench_t* &C, bench_t* &D); +#endif \ No newline at end of file diff --git a/gpu4s_benchmark/wavelet_transform/main.cpp b/gpu4s_benchmark/wavelet_transform/main.cpp index 1c043f7f..1c266c2c 100644 --- a/gpu4s_benchmark/wavelet_transform/main.cpp +++ b/gpu4s_benchmark/wavelet_transform/main.cpp @@ -5,7 +5,6 @@ #define NUMBER_BASE 1 - #define OK_ARGUMENTS 0 #define ERROR_ARGUMENTS -1 @@ -35,26 +34,68 @@ int main(int argc, char *argv[]){ // VARIABLES /////////////////////////////////////////////////////////////////////////////////////////////// // linearizable versions of matrix - unsigned int size_matrix =arguments_parameters->size; + unsigned int size_matrix = arguments_parameters->size; + unsigned int mem_size = sizeof(bench_t) * size_matrix; // A input matrix - unsigned int size_A = arguments_parameters->size; - unsigned int mem_size_A = sizeof(bench_t) * size_A; - bench_t* A = (bench_t*) malloc(mem_size_A); + bench_t* A = nullptr; // B input matrix - unsigned int size_B = arguments_parameters->size ; - unsigned int mem_size_B = sizeof(bench_t) * size_B; - bench_t* h_B = (bench_t*) malloc(mem_size_B); - bench_t* d_B = (bench_t*) malloc(mem_size_B); - // comparation result - bool result = false; - // strucs for CPU timing + bench_t* d_B = nullptr; + bench_t* h_B = (bench_t*) malloc(mem_size); + // init devices + char device[100] = ""; + + bench_t* lowpass_filter_ptr = nullptr; + bench_t* highpass_filter_ptr = nullptr; + + + // main object init + GraficCommon*wavelet_bench = (GraficCommon*)malloc(sizeof(GraficObject)); + + // --- 1. Init Device & Context --- + init(wavelet_bench, 0,arguments_parameters->gpu, device); + // Update profiling clock mode + wavelet_bench->profiling_clock = arguments_parameters->profiling_clock; + + // --- 2. Allocate Device Memory --- + device_memory_init(wavelet_bench, size_matrix, size_matrix ); + + // --- 3. Allocate Host Pointers --- + if (arguments_parameters->unified_memory) + { + #ifdef UMA_COMPATIBILITY + + // map the buffzer to the gpu + cpu take the lead + get_unified_memory_pointers(wavelet_bench, A, d_B, lowpass_filter_ptr, highpass_filter_ptr, mem_size); + + + for (int i=0; i < LOWPASSFILTERSIZE; i++){ + lowpass_filter_ptr[i] = lowpass_filter[i]; + } + + //initiate + for (int i=0; i < HIGHPASSFILTERSIZE; i++){ + highpass_filter_ptr[i] = highpass_filter[i]; + } + + + #else + fprintf(stderr, "\033[1;31merror:\033[0m This framework is not compatible with unified memory. Please remove the -u arg!\n"); + exit(-1); + #endif + } else + { + // normale malloc + A = (bench_t*) malloc(mem_size); + d_B = (bench_t*) malloc(mem_size); + } + /////////////////////////////////////////////////////////////////////////////////////////////// // DATA INIT /////////////////////////////////////////////////////////////////////////////////////////////// if (strlen(arguments_parameters->input_file_A) == 0) { - // inicialice A matrix + // inicialice A matrix for (int i=0; isize; i++){ #ifdef INT //A[i] = i+1; @@ -64,10 +105,11 @@ int main(int argc, char *argv[]){ #endif //} } - // iniciate B matrix + + // reset output B matrix for (int i=0; isize; i++){ h_B[i] = 0; - h_B[i] = 0; + d_B[i] = 0; } } else @@ -85,6 +127,7 @@ int main(int argc, char *argv[]){ } }*/ } + // print input if (arguments_parameters->print_input) { @@ -101,65 +144,77 @@ int main(int argc, char *argv[]){ /////////////////////////////////////////////////////////////////////////////////////////////// // CODE BENCKMARK /////////////////////////////////////////////////////////////////////////////////////////////// - - // base object init - GraficCommon*wavelet_bench = (GraficCommon*)malloc(sizeof(GraficObject)); - // init devices - char device[100] = ""; - init(wavelet_bench, 0,arguments_parameters->gpu, device); if (!arguments_parameters->csv_format_timestamp && !arguments_parameters->csv_format && !arguments_parameters->mute_messages ){ printf("Using device: %s\n", device); } - // Update profiling clock mode - wavelet_bench->profiling_clock = arguments_parameters->profiling_clock; - - // If android and opencl force profiling clock - #ifdef FORCE_PROFILING_CLOCK - wavelet_bench->profiling_clock = true; - #endif - - // init memory - device_memory_init(wavelet_bench, arguments_parameters->size , arguments_parameters->size ); // copy memory to device - copy_memory_to_device(wavelet_bench, A, arguments_parameters->size ); + if(arguments_parameters->unified_memory) + { + #ifdef UMA_COMPATIBILITY + sync_unified_memory_to_device(wavelet_bench, A, d_B, lowpass_filter_ptr, highpass_filter_ptr); + #endif + } + else + { + copy_memory_to_device(wavelet_bench, A, size_matrix); + } + // execute kernel execute_kernel(wavelet_bench, arguments_parameters->size/2); + // copy memory to host - copy_memory_to_host(wavelet_bench, d_B, size_matrix); + if (arguments_parameters->unified_memory) + { + #ifdef UMA_COMPATIBILITY + sync_unified_memory_to_host(wavelet_bench, d_B, size_matrix); + #endif + } else + { + copy_memory_to_host(wavelet_bench, d_B, size_matrix); + } // get time if (arguments_parameters->print_timing || arguments_parameters->csv_format || arguments_parameters->csv_format_timestamp) { get_elapsed_time(wavelet_bench, arguments_parameters->csv_format, arguments_parameters->csv_format_timestamp, get_timestamp()); } + + // print output buffer if (arguments_parameters->print_output) { #ifdef INT - for (int i=0; isize; i++){ - printf("%d ", d_B[i]); - } - printf("\n"); + for (int i=0; isize; i++){ + printf("%d ", d_B[i]); + } + printf("\n"); #else - for (int i=0; isize; i++){ - printf("%f ", d_B[i]); - } - printf("\n"); + for (int i=0; isize; i++){ + printf("%f ", d_B[i]); + } + printf("\n"); #endif + } - + // export gpu buffer + if (arguments_parameters->export_results_gpu) + { + print_double_hexadecimal_values(GPU_FILE, d_B, size_matrix); } + //check for error if (arguments_parameters->verification) { Clock cpuKernelCLK; cpuKernelCLK.start(); ccsds_wavelet_transform(A,h_B,arguments_parameters->size/2); cpuKernelCLK.end(); + if (arguments_parameters->print_timing) { printf("CPU Time %.0f milliseconds\n", cpuKernelCLK.getElapsedMS()); } + if (arguments_parameters->print_output) { #ifdef INT @@ -177,20 +232,18 @@ int main(int argc, char *argv[]){ #endif } - result = compare_vectors(h_B, d_B, size_B); - if (result){ + + if (compare_vectors(h_B, d_B, size_matrix)) + { printf("OK\n"); } + if (arguments_parameters->export_results){ - print_double_hexadecimal_values(GPU_FILE, d_B, size_B); - print_double_hexadecimal_values(CPU_FILE, h_B, size_B); + print_double_hexadecimal_values(GPU_FILE, d_B, size_matrix); + print_double_hexadecimal_values(CPU_FILE, h_B, size_matrix); } } - if (arguments_parameters->export_results_gpu) - { - print_double_hexadecimal_values(GPU_FILE, d_B, size_B); - } /////////////////////////////////////////////////////////////////////////////////////////////// // CLEAN MEMORY /////////////////////////////////////////////////////////////////////////////////////////////// @@ -199,10 +252,15 @@ int main(int argc, char *argv[]){ // free object memory free(wavelet_bench); free(arguments_parameters); - free(A); + + if (!arguments_parameters->unified_memory) + { + free(A); + free(d_B); + } + free(h_B); - free(d_B); -return 0; + return 0; } diff --git a/gpu4s_benchmark/wavelet_transform/opencl/lib_opencl.cpp b/gpu4s_benchmark/wavelet_transform/opencl/lib_opencl.cpp index 43988395..9a1eb549 100644 --- a/gpu4s_benchmark/wavelet_transform/opencl/lib_opencl.cpp +++ b/gpu4s_benchmark/wavelet_transform/opencl/lib_opencl.cpp @@ -1,6 +1,7 @@ // OpenCL lib code #include #include "../benchmark_library.h" +#include "../../common/opencl_common.hpp" #include #ifdef INT #include "GEN_kernel_integer.hcl" @@ -253,3 +254,54 @@ void clean(GraficCommon* device_object){ delete deviceObj->evt_copyB; delete deviceObj->evt_copyC; } + + +#ifdef UMA_COMPATIBILITY +// ====== UMA function ====== +void get_unified_memory_pointers(GraficCommon* device_object, bench_t* &A, bench_t* &B, bench_t* &C, bench_t* &D, unsigned int memSize){ + GraficObject* deviceObj = static_cast(device_object); + // --- Call the openCL common function --- + map_unified_memory(device_object, memSize, + BufferMapCL{&A, deviceObj->d_A, nullptr}, + BufferMapCL{&B, deviceObj->d_B, nullptr} + ); + + #ifndef INT + //lowpass_filter + map_unified_memory(device_object, sizeof(bench_t) * LOWPASSFILTERSIZE, + BufferMapCL{&C, deviceObj->low_filter, nullptr} + ); + + //high pass_filter + map_unified_memory(device_object, sizeof(bench_t) * HIGHPASSFILTERSIZE, + BufferMapCL{&D, deviceObj->high_filter, nullptr} + ); + #endif +} + +void sync_unified_memory_to_device(GraficCommon* device_object, bench_t* &A, bench_t* &B, bench_t* &C, bench_t* &D){ + GraficObject* deviceObj = static_cast(device_object); + // --- Call the openCL common function --- + unmap_unified_memory(device_object, + BufferMapCL{&A, deviceObj->d_A, deviceObj->evt_copyA}, + BufferMapCL{&B, deviceObj->d_B, nullptr} + #ifndef INT + // comma only for FLOAT or DOUBLE + ,BufferMapCL{&C, deviceObj->low_filter, nullptr}, + BufferMapCL{&D, deviceObj->high_filter, nullptr} + #endif + ); + + +} + + +void sync_unified_memory_to_host(GraficCommon* device_object, bench_t* &d_output, unsigned int memSize){ + GraficObject* deviceObj = static_cast(device_object); + // --- Call the openCL common function --- + map_unified_memory_to_host(device_object, memSize, + BufferMapCL{&d_output, deviceObj->d_B, deviceObj->evt_copyB} + ); +} + +#endif \ No newline at end of file From a1d18a70e343b7abc90a6328e33464caded02ab6 Mon Sep 17 00:00:00 2001 From: Noah Perret Date: Fri, 14 Aug 2026 15:39:09 +0200 Subject: [PATCH 19/27] small fix in previosu benchmark for android UMA --- gpu4s_benchmark/LRN_bench/main.cpp | 4 ++-- gpu4s_benchmark/cifar_10/opencl/lib_opencl.cpp | 2 -- gpu4s_benchmark/common/benchmark_common.h | 9 +++++++++ .../fast_fourier_transform_window_bench/main.cpp | 2 ++ .../matrix_multiplication_bench_fp16/main.cpp | 6 +++--- gpu4s_benchmark/max_pooling_bench/main.cpp | 4 ++-- 6 files changed, 18 insertions(+), 9 deletions(-) diff --git a/gpu4s_benchmark/LRN_bench/main.cpp b/gpu4s_benchmark/LRN_bench/main.cpp index 578d81b9..15e201b0 100644 --- a/gpu4s_benchmark/LRN_bench/main.cpp +++ b/gpu4s_benchmark/LRN_bench/main.cpp @@ -34,9 +34,9 @@ int main(int argc, char *argv[]){ unsigned int size_matrix = arguments_parameters->size * arguments_parameters->size; unsigned int mem_size = sizeof(bench_t) * size_matrix; // A input matrix - bench_t* A = (bench_t*) malloc(mem_size); + bench_t* A = nullptr; // B input matrix - bench_t* d_B = (bench_t*) malloc(mem_size); + bench_t* d_B = nullptr; bench_t* h_B = (bench_t*) malloc(mem_size); // init devices char device[100] = ""; diff --git a/gpu4s_benchmark/cifar_10/opencl/lib_opencl.cpp b/gpu4s_benchmark/cifar_10/opencl/lib_opencl.cpp index e0962dda..9f57ca62 100644 --- a/gpu4s_benchmark/cifar_10/opencl/lib_opencl.cpp +++ b/gpu4s_benchmark/cifar_10/opencl/lib_opencl.cpp @@ -5,8 +5,6 @@ #include "GEN_atomic_functions.hcl" - - void execute_kernel(GraficCommon* device_object, unsigned int input_data, unsigned int output_data, unsigned int kernel_1, unsigned int kernel_2, unsigned int stride_1, unsigned int stride_2, unsigned int neurons_dense_1, unsigned int neurons_dense_2){ GraficObject* deviceObj = static_cast(device_object); unsigned int x_local= BLOCK_SIZE; diff --git a/gpu4s_benchmark/common/benchmark_common.h b/gpu4s_benchmark/common/benchmark_common.h index f42c9fb8..4e26100c 100644 --- a/gpu4s_benchmark/common/benchmark_common.h +++ b/gpu4s_benchmark/common/benchmark_common.h @@ -174,5 +174,14 @@ void clean(GraficCommon *device_object); // --- 3 buffer --- void get_unified_memory_pointers(GraficCommon* device_object, bench_t* &A, bench_t* &B, bench_t* &C, unsigned int memSize); void sync_unified_memory_to_device(GraficCommon* device_object, bench_t* &A, bench_t* &B, bench_t* &C); + + // --- 3 buffer + 2 size --- + void get_unified_memory_pointers(GraficCommon* device_object, bench_t* &A, bench_t* &B, bench_t* &C, unsigned int memSize, unsigned int memSize2); + + // --- 3 buffer + 3 size --- + void get_unified_memory_pointers(GraficCommon* device_object, bench_t* &A, bench_t* &B, bench_t* &C, unsigned memSize, unsigned memSize2, unsigned memSize3); + + // --- common --- void sync_unified_memory_to_host(GraficCommon* device_object, bench_t* &d_output, unsigned int memSize); + #endif \ No newline at end of file diff --git a/gpu4s_benchmark/fast_fourier_transform_window_bench/main.cpp b/gpu4s_benchmark/fast_fourier_transform_window_bench/main.cpp index 511da054..191d904c 100644 --- a/gpu4s_benchmark/fast_fourier_transform_window_bench/main.cpp +++ b/gpu4s_benchmark/fast_fourier_transform_window_bench/main.cpp @@ -211,11 +211,13 @@ int main(int argc, char *argv[]){ // free object memory free(fft_bench); free(arguments_parameters); + if (!arguments_parameters->unified_memory) { free(A); free(d_B); } + free(h_B); return 0; } diff --git a/gpu4s_benchmark/matrix_multiplication_bench_fp16/main.cpp b/gpu4s_benchmark/matrix_multiplication_bench_fp16/main.cpp index de59a2d3..0cf4f704 100644 --- a/gpu4s_benchmark/matrix_multiplication_bench_fp16/main.cpp +++ b/gpu4s_benchmark/matrix_multiplication_bench_fp16/main.cpp @@ -35,11 +35,11 @@ int main(int argc, char *argv[]){ unsigned int size_matrix = arguments_parameters->size * arguments_parameters->size; unsigned int mem_size = sizeof(bench_t) * size_matrix; // A input matrix - bench_t* A = (bench_t*) malloc(mem_size); + bench_t* A = nullptr; // B input matrix - bench_t* B = (bench_t*) malloc(mem_size); + bench_t* B = nullptr; // C matrix - bench_t* d_C = (bench_t*) malloc(mem_size); + bench_t* d_C = nullptr; bench_t* h_C = (bench_t*) malloc(mem_size); // init devices char device[100] = ""; diff --git a/gpu4s_benchmark/max_pooling_bench/main.cpp b/gpu4s_benchmark/max_pooling_bench/main.cpp index 96cc44bd..30684c82 100644 --- a/gpu4s_benchmark/max_pooling_bench/main.cpp +++ b/gpu4s_benchmark/max_pooling_bench/main.cpp @@ -34,12 +34,12 @@ int main(int argc, char *argv[]){ // A input matrix unsigned int size_A = arguments_parameters->size * arguments_parameters->size; unsigned int mem_size_A = sizeof(bench_t) * size_A; - bench_t* A = (bench_t*) malloc(mem_size_A); + bench_t* A = nullptr; // B input matrix unsigned int size_lateral = arguments_parameters->size / arguments_parameters->stride; unsigned int size_B = size_lateral * size_lateral; unsigned int mem_size_B = sizeof(bench_t) * size_B; - bench_t* d_B = (bench_t*) malloc(mem_size_B); + bench_t* d_B = nullptr; bench_t* h_B = (bench_t*) malloc(mem_size_B); // init devices char device[100] = ""; From 34cdf3188a25e5e02032ce9e363d9fd95dc45ac3 Mon Sep 17 00:00:00 2001 From: Noah Perret Date: Fri, 14 Aug 2026 18:42:37 +0200 Subject: [PATCH 20/27] fix android bug by using cifar_10 kernel code --- .../cifar_10_multiple/opencl/GEN_kernel.hcl | 7 +++ .../opencl/GEN_kernel_opt.hcl | 51 +++++++++++-------- .../cifar_10_multiple/opencl/lib_opencl.cpp | 41 ++++++++------- .../opencl/lib_opencl_opt.cpp | 35 ++++++------- 4 files changed, 79 insertions(+), 55 deletions(-) diff --git a/gpu4s_benchmark/cifar_10_multiple/opencl/GEN_kernel.hcl b/gpu4s_benchmark/cifar_10_multiple/opencl/GEN_kernel.hcl index 6408dc5b..572b6f05 100644 --- a/gpu4s_benchmark/cifar_10_multiple/opencl/GEN_kernel.hcl +++ b/gpu4s_benchmark/cifar_10_multiple/opencl/GEN_kernel.hcl @@ -74,6 +74,13 @@ std::string kernel_code = "C[i*m+j] = acumulated;\n" "}\n" "}\n" +"void kernel kernel_relu_linear(global const bench_t* A, global bench_t* B, const int size ){\n" +"int i = get_global_id(0);\n" +"if (i < size){\n" +"bench_t threshold = 0;\n" +"B[i] = max(threshold, A[i]);\n" +"}\n" +"}\n" "void kernel kernel_softmax(global const bench_t* A, global bench_t* B, global bench_t* sum_d_B, const int size, const int offset ){\n" "int i = get_global_id(0);\n" "int j = get_global_id(1);\n" diff --git a/gpu4s_benchmark/cifar_10_multiple/opencl/GEN_kernel_opt.hcl b/gpu4s_benchmark/cifar_10_multiple/opencl/GEN_kernel_opt.hcl index effd196a..c7d14b9c 100644 --- a/gpu4s_benchmark/cifar_10_multiple/opencl/GEN_kernel_opt.hcl +++ b/gpu4s_benchmark/cifar_10_multiple/opencl/GEN_kernel_opt.hcl @@ -1,4 +1,3 @@ - std::string kernel_code = "void kernel kernel_matrix_convolution_old(global const bench_t* A, global bench_t* B, global const bench_t* kernel_data, const int n, const int m, const int w, const int kernel_size, const int offset ){\n" "int x = get_global_id(0);\n" @@ -11,7 +10,7 @@ std::string kernel_code = "if (x < size && y < size){\n" "A_aux = A + offset;\n" "B_aux = B + offset;\n" -"for(int i = -kernel_rad; i <= kernel_rad; ++i) // loop over kernel_rad -1 to 1 in kernel_size 3\n" +"for(int i = -kernel_rad; i <= kernel_rad; ++i)\n" "{\n" "for(int j = -kernel_rad; j <= kernel_rad; ++j)\n" "{\n" @@ -110,7 +109,18 @@ std::string kernel_code = "bench_t threshold = 0;\n" "A_aux = A + offset;\n" "B_aux = B + offset;\n" -"B[i] = max(threshold, A[i]);\n" +"B_aux[i] = max(threshold, A_aux[i]);\n" +"}\n" +"}\n" +"void kernel kernel_relu_linear(global const bench_t* A, global bench_t* B, const int size, const int offset){\n" +"int i = get_global_id(0);\n" +"global const bench_t* A_aux;\n" +"global bench_t* B_aux;\n" +"if (i < size){\n" +"bench_t threshold = 0;\n" +"A_aux = A + offset;\n" +"B_aux = B + offset;\n" +"B_aux[i] = max(threshold, A_aux[i]);\n" "}\n" "}\n" "void kernel kernel_max(global const bench_t* A, global bench_t* B, const int size, const int stride, const int lateral_stride, const int offset_input, const int offset_output ){\n" @@ -161,32 +171,31 @@ std::string kernel_code = "void kernel kernel_softmax(global const bench_t* A, global bench_t* B, global bench_t* sum_d_B, const int size, const int offset, const int offset_input, const int offset_sum ){\n" "int i = get_global_id(0);\n" "int tid = get_local_id(0);\n" -"global bench_t* B_aux;\n" -"global bench_t* A_aux;\n" -"global bench_t* sum_d_B_aux;\n" +"global bench_t* B_aux = B + offset;\n" +"global const bench_t* A_aux = A + offset_input;\n" +"global bench_t* sum_d_B_aux = sum_d_B + offset_sum;\n" "bench_t value = 0;\n" "__local bench_t shared_data[BLOCK_SIZE];\n" -"if (i < (size) ){\n" -"B_aux = B + offset;\n" -"A_aux = A + offset_input;\n" -"sum_d_B_aux = sum_d_B + offset_sum;\n" +"if (i < size ){\n" "value = exp(A_aux[i]);\n" "B_aux[i] = value;\n" -"*sum_d_B_aux = 0;\n" "shared_data[tid] = value;\n" +"} else {\n" +"shared_data[tid] = 0.0f;\n" +"}\n" "barrier(CLK_LOCAL_MEM_FENCE);\n" -"for (unsigned int s=get_local_size(0)/2; s>0; s>>=1)\n" -"{\n" -"if (tid < s)\n" -"{\n" -"shared_data[tid] += shared_data[tid + s];\n" +"unsigned int next_pow2 = 1;\n" +"while (next_pow2 < get_local_size(0)) {\n" +"next_pow2 *= 2;\n" "}\n" +"for (unsigned int s = next_pow2 / 2; s > 0; s >>= 1) {\n" +"if (tid < s && (tid + s) < get_local_size(0)) {\n" +"shared_data[tid] += shared_data[tid + s];\n" "}\n" -"barrier(CLK_LOCAL_MEM_FENCE);\n" -"if (tid == 0)\n" -"{\n" -"atomic_add_global(sum_d_B_aux, shared_data[0]);\n" +"barrier(CLK_LOCAL_MEM_FENCE); // CRITICAL: Barrier inside the loop\n" "}\n" +"if (tid == 0) {\n" +"*sum_d_B_aux = shared_data[0];\n" "}\n" "}\n" "void kernel kernel_softmax_end(global bench_t* B, global bench_t* sum_d_B, const int size, const int offset, const int offset_sum){\n" @@ -199,4 +208,4 @@ std::string kernel_code = "B_aux[i] = (B_aux[i]/(*sum_d_B_aux));\n" "}\n" "}\n" -; +; \ No newline at end of file diff --git a/gpu4s_benchmark/cifar_10_multiple/opencl/lib_opencl.cpp b/gpu4s_benchmark/cifar_10_multiple/opencl/lib_opencl.cpp index f46088d9..1c511ca2 100644 --- a/gpu4s_benchmark/cifar_10_multiple/opencl/lib_opencl.cpp +++ b/gpu4s_benchmark/cifar_10_multiple/opencl/lib_opencl.cpp @@ -171,22 +171,25 @@ void execute_kernel(GraficCommon* device_object, unsigned int input_data, unsign deviceObj->queue->enqueueNDRangeKernel(kernel_add,cl::NullRange,global,local, NULL, NULL); - //activation layer dense 1 - if(neurons_dense_1 <= BLOCK_SIZE) + //FIX : use the cifar_10 code + ///activation layer dense 1 + /*if(neurons_dense_1 > BLOCK_SIZE * 32) { local = cl::NullRange; - global = cl::NDRange (neurons_dense_1/2, neurons_dense_1/2); + global = cl::NDRange (neurons_dense_1); } else { - local = cl::NDRange(x_local, y_local); - global = cl::NDRange(neurons_dense_1/2, neurons_dense_1/2); - } - kernel_add=cl::Kernel(program,"kernel_relu"); + local = cl::NDRange(x_local*y_local); + global = cl::NDRange(neurons_dense_1); + }*/ + local = cl::NullRange; + global = cl::NDRange (neurons_dense_1); + kernel_add=cl::Kernel(program,"kernel_relu_linear"); kernel_add.setArg(0,*deviceObj->dense_layer_1_output); kernel_add.setArg(1,*deviceObj->dense_layer_1_output); - kernel_add.setArg(2,neurons_dense_1/2); - deviceObj->queue->enqueueNDRangeKernel(kernel_add,cl::NullRange,global,local, NULL, NULL); + kernel_add.setArg(2,neurons_dense_1); + deviceObj->queue->enqueueNDRangeKernel(kernel_add,cl::NullRange,global,local, NULL, deviceObj->evtd_1_a); // dense layer 2 if(neurons_dense_2 <= BLOCK_SIZE) @@ -210,21 +213,23 @@ void execute_kernel(GraficCommon* device_object, unsigned int input_data, unsign deviceObj->queue->enqueueNDRangeKernel(kernel_add,cl::NullRange,global,local, NULL, NULL); //activation layer dense 2 - if(neurons_dense_2 < BLOCK_SIZE) + /*if(neurons_dense_2 < BLOCK_SIZE * BLOCK_SIZE) { local = cl::NullRange; - global = cl::NDRange (neurons_dense_2/2, neurons_dense_2/2); + global = cl::NDRange (neurons_dense_2); } else { - local = cl::NDRange(x_local, y_local); - global = cl::NDRange(neurons_dense_2/2, neurons_dense_2/2); - } - kernel_add=cl::Kernel(program,"kernel_relu"); + local = cl::NDRange(x_local*y_local); + global = cl::NDRange(neurons_dense_2); + }*/ + local = cl::NullRange; + global = cl::NDRange (neurons_dense_2); + kernel_add=cl::Kernel(program,"kernel_relu_linear"); kernel_add.setArg(0,*deviceObj->dense_layer_2_output); kernel_add.setArg(1,*deviceObj->dense_layer_2_output); - kernel_add.setArg(2,neurons_dense_2/2); - deviceObj->queue->enqueueNDRangeKernel(kernel_add,cl::NullRange,global,local, NULL, NULL); + kernel_add.setArg(2,neurons_dense_2); + deviceObj->queue->enqueueNDRangeKernel(kernel_add,cl::NullRange,global,local, NULL, deviceObj->evtd_2_a); //soft max if(neurons_dense_2 < BLOCK_SIZE) @@ -237,6 +242,7 @@ void execute_kernel(GraficCommon* device_object, unsigned int input_data, unsign local = cl::NDRange(1, x_local); global = cl::NDRange(1, neurons_dense_2); } + cl::Kernel softmax_kernel=cl::Kernel(program,"kernel_softmax"); softmax_kernel.setArg(0,*deviceObj->dense_layer_2_output); softmax_kernel.setArg(1,*aux_output_data); @@ -253,6 +259,7 @@ void execute_kernel(GraficCommon* device_object, unsigned int input_data, unsign softmax_end_kernel.setArg(3, position * output_data); deviceObj->queue->enqueueNDRangeKernel(softmax_end_kernel,cl::NullRange,global,local, NULL, NULL); + } //FIX : GPU profiling use opencl marker diff --git a/gpu4s_benchmark/cifar_10_multiple/opencl/lib_opencl_opt.cpp b/gpu4s_benchmark/cifar_10_multiple/opencl/lib_opencl_opt.cpp index e5a15711..b3981fa1 100644 --- a/gpu4s_benchmark/cifar_10_multiple/opencl/lib_opencl_opt.cpp +++ b/gpu4s_benchmark/cifar_10_multiple/opencl/lib_opencl_opt.cpp @@ -259,22 +259,23 @@ void execute_kernel(GraficCommon* device_object, unsigned int input_data, unsign queues[stream].enqueueNDRangeKernel(kernel_add,cl::NullRange,global,local, NULL, NULL); + //FIX: implement the cifar_10 code //activation layer dense 1 - if ((neurons_dense_1/2) *(neurons_dense_1/2) <= BLOCK_SIZE_PLANE) + if ((neurons_dense_1) <= BLOCK_SIZE_PLANE) { local = cl::NullRange; - global = cl::NDRange((neurons_dense_1/2) *(neurons_dense_1/2)); + global = cl::NDRange(neurons_dense_1); } else { local = cl::NullRange; - global = cl::NDRange((neurons_dense_1/2) *(neurons_dense_1/2)); + global = cl::NDRange(neurons_dense_1); } - kernel_add=cl::Kernel(program,"kernel_relu"); + kernel_add=cl::Kernel(program,"kernel_relu_linear"); kernel_add.setArg(0,*deviceObj->dense_layer_1_output); kernel_add.setArg(1,*deviceObj->dense_layer_1_output); - kernel_add.setArg(2,neurons_dense_1/2); - kernel_add.setArg(3,size_lateral_2*size_lateral_2); + kernel_add.setArg(2,neurons_dense_1); + kernel_add.setArg(3,stream*neurons_dense_1); queues[stream].enqueueNDRangeKernel(kernel_add,cl::NullRange,global,local, NULL, NULL); // dense layer 2 @@ -301,20 +302,20 @@ void execute_kernel(GraficCommon* device_object, unsigned int input_data, unsign queues[stream].enqueueNDRangeKernel(kernel_add,cl::NullRange,global,local, NULL, NULL); //activation layer dense 2 - if ((neurons_dense_2/2) *(neurons_dense_2/2) <= BLOCK_SIZE_PLANE) + if ((neurons_dense_2) <= BLOCK_SIZE_PLANE) { local = cl::NullRange; - global = cl::NDRange((neurons_dense_2/2) *(neurons_dense_2/2)); + global = cl::NDRange(neurons_dense_2); } else - { + { local = cl::NDRange(x_local_plane); - global = cl::NDRange((neurons_dense_2/2) *(neurons_dense_2/2)); + global = cl::NDRange(neurons_dense_2); } - kernel_add=cl::Kernel(program,"kernel_relu"); + kernel_add=cl::Kernel(program,"kernel_relu_linear"); kernel_add.setArg(0,*deviceObj->dense_layer_2_output); kernel_add.setArg(1,*deviceObj->dense_layer_2_output); - kernel_add.setArg(2,neurons_dense_2/2); + kernel_add.setArg(2,neurons_dense_2); kernel_add.setArg(3,stream * neurons_dense_2); queues[stream].enqueueNDRangeKernel(kernel_add,cl::NullRange,global,local, NULL, NULL); @@ -337,7 +338,6 @@ void execute_kernel(GraficCommon* device_object, unsigned int input_data, unsign softmax_kernel.setArg(4, position * output_data); softmax_kernel.setArg(5, stream * neurons_dense_2); softmax_kernel.setArg(6, stream); - queues[stream].enqueueNDRangeKernel(softmax_kernel,cl::NullRange,global,local, NULL, NULL); cl::Kernel softmax_end_kernel=cl::Kernel(program,"kernel_softmax_end"); @@ -346,16 +346,17 @@ void execute_kernel(GraficCommon* device_object, unsigned int input_data, unsign softmax_end_kernel.setArg(2,neurons_dense_2); softmax_end_kernel.setArg(3, position * output_data); softmax_end_kernel.setArg(4, stream); - queues[stream].enqueueNDRangeKernel(softmax_end_kernel,cl::NullRange,global,local, NULL, NULL); - //deviceObj->queue->enqueueWriteBuffer(*deviceObj->sum_ouput,CL_TRUE,0,sizeof(bench_t), 0, NULL,NULL); } //FIX : GPU profiling use opencl marker deviceObj->queue->enqueueMarkerWithWaitList(NULL, deviceObj->evt_softmax_fin); - // Wait for completion before stopping the clock - deviceObj->queue->finish(); + // Wait all the stream completion before stopping the clock + for (unsigned int i = 0; i < NUMBER_OF_STREAMS; ++i) { + queues[i].finish(); + } + // Clock profilling end kernelCLK.end(); From 43afd09124bf359db6abaad5e4b4355e3d237ed9 Mon Sep 17 00:00:00 2001 From: Noah Perret Date: Fri, 14 Aug 2026 19:15:16 +0200 Subject: [PATCH 21/27] add UMA for cifar_10 mutiple --- .../cifar_10_multiple/benchmark_library.h | 2 + gpu4s_benchmark/cifar_10_multiple/main.cpp | 62 +++++++++++-------- .../opencl/lib_opencl_common.cpp | 47 +++++++++++++- 3 files changed, 83 insertions(+), 28 deletions(-) diff --git a/gpu4s_benchmark/cifar_10_multiple/benchmark_library.h b/gpu4s_benchmark/cifar_10_multiple/benchmark_library.h index bf999154..f8e69b8f 100644 --- a/gpu4s_benchmark/cifar_10_multiple/benchmark_library.h +++ b/gpu4s_benchmark/cifar_10_multiple/benchmark_library.h @@ -121,4 +121,6 @@ void copy_memory_to_host(GraficCommon* device_object, bench_t* h_C, int size, un #ifdef UMA_COMPATIBILITY +void get_unified_memory_pointers(GraficCommon* device_object,bench_t* &input_data, unsigned int input_mem_size,bench_t* &kernel_1, bench_t* &kernel_2, unsigned int kernel_mem_size, bench_t* &weights_1, unsigned int weights_1_mem_size, bench_t* &weights_2, unsigned int weights_2_mem_size, bench_t* &d_output, unsigned int output_mem_size); +void sync_unified_memory_to_device(GraficCommon* device_object, bench_t* &input_data, bench_t* &kernel_1, bench_t* &kernel_2, bench_t* &weights_1, bench_t* &weights_2, bench_t* &d_output); #endif \ No newline at end of file diff --git a/gpu4s_benchmark/cifar_10_multiple/main.cpp b/gpu4s_benchmark/cifar_10_multiple/main.cpp index 685d3ce1..bf7685f7 100644 --- a/gpu4s_benchmark/cifar_10_multiple/main.cpp +++ b/gpu4s_benchmark/cifar_10_multiple/main.cpp @@ -51,27 +51,27 @@ int main(int argc, char *argv[]){ // A input matrix unsigned int size_A = CIFAR_10_INPUT * CIFAR_10_INPUT * arguments_parameters->size; unsigned int mem_size_A = sizeof(bench_t) * size_A; - bench_t* input_data = (bench_t*) malloc(mem_size_A); + bench_t* input_data = nullptr; // B output matrix - unsigned int size_B = CIFAR_10_OUTPUT * CIFAR_10_OUTPUT * arguments_parameters->size; + unsigned int size_B = CIFAR_10_OUTPUT * arguments_parameters->size; unsigned int mem_size_B = sizeof(bench_t) * size_B; - bench_t* d_output = (bench_t*) malloc(mem_size_B); + bench_t* d_output = nullptr; // kernel matrix 1 unsigned int size_k_1 = KERNEL_CON_1 * KERNEL_CON_2; unsigned int mem_size_k_1 = sizeof(bench_t) * size_k_1; - bench_t* kernel_1 = (bench_t*) malloc(mem_size_k_1); + bench_t* kernel_1 = nullptr; // kernel matrix 2 unsigned int size_k_2 = KERNEL_CON_2 * KERNEL_CON_2; unsigned int mem_size_k_2 = sizeof(bench_t) * size_k_2; - bench_t* kernel_2 = (bench_t*) malloc(mem_size_k_2); + bench_t* kernel_2 = nullptr; // weights 1 unsigned int size_w_1 = DENSE_1 * (((CIFAR_10_INPUT / STRIDE_1)/STRIDE_2)*((CIFAR_10_INPUT / STRIDE_1)/STRIDE_2)); unsigned int mem_size_w_1 = sizeof(bench_t) * size_w_1; - bench_t* weights_1 = (bench_t*) malloc(mem_size_w_1); + bench_t* weights_1 = nullptr; // weights 1 unsigned int size_w_2 = DENSE_1 * DENSE_2; unsigned int mem_size_w_2 = sizeof(bench_t) * size_w_2; - bench_t* weights_2 = (bench_t*) malloc(mem_size_w_2); + bench_t* weights_2 = nullptr; // Outputs const unsigned int size_pooling_1 = CIFAR_10_INPUT / STRIDE_1; const unsigned int size_pooling_2 = size_pooling_1 / STRIDE_2; @@ -101,13 +101,12 @@ int main(int argc, char *argv[]){ exit(-1); } - // --- 3. Allocate Host Pointers --- if (arguments_parameters->unified_memory) { #ifdef UMA_COMPATIBILITY // map the buffzer to the gpu + cpu take the lead - //get_unified_memory_pointers(//...); + get_unified_memory_pointers(cifar10_bench,input_data, mem_size_A,kernel_1, kernel_2, mem_size_k_1,weights_1, mem_size_w_1,weights_2, mem_size_w_2,d_output, mem_size_B); #else fprintf(stderr, "\033[1;31merror:\033[0m This framework is not compatible with unified memory. Please remove the -u arg!\n"); exit(-1); @@ -115,7 +114,12 @@ int main(int argc, char *argv[]){ } else { // normale malloc - ///... to ne fill + input_data = (bench_t*) malloc(mem_size_A); + kernel_1 = (bench_t*) malloc(mem_size_k_1); + kernel_2 = (bench_t*) malloc(mem_size_k_2); + weights_1 = (bench_t*) malloc(mem_size_w_1); + weights_2 = (bench_t*) malloc(mem_size_w_2); + d_output = (bench_t*) malloc(mem_size_B); } @@ -125,7 +129,7 @@ int main(int argc, char *argv[]){ /////////////////////////////////////////////////////////////////////////////////////////////// if (strlen(arguments_parameters->input_file_A) == 0) { - // inicialice A matrix + // inicialice inputçdata matrix for (int k=0; k < arguments_parameters->size; ++k){ for (int i=0; iunified_memory) { #ifdef UMA_COMPATIBILITY - //sync_unified_memory_to_device(//to be fill; + sync_unified_memory_to_device(cifar10_bench, input_data, kernel_1, kernel_2, weights_1, weights_2, d_output); #endif } else @@ -243,7 +247,7 @@ int main(int argc, char *argv[]){ if (arguments_parameters->unified_memory) { #ifdef UMA_COMPATIBILITY - //sync_unified_memory_to_host(// to be fill); + sync_unified_memory_to_host(cifar10_bench, d_output, mem_size_B); #endif } else { @@ -338,12 +342,16 @@ int main(int argc, char *argv[]){ // free object memory free(arguments_parameters); free(cifar10_bench); - free(input_data); - free(d_output); - free(kernel_1); - free(kernel_2); - free(weights_1); - free(weights_2); + if (!arguments_parameters->unified_memory) + { + free(input_data); + free(d_output); + free(kernel_1); + free(kernel_2); + free(weights_1); + free(weights_2); + } + free(conv_1_output); free(pooling_1_output); free(conv_2_output); @@ -351,7 +359,7 @@ int main(int argc, char *argv[]){ free(dense_layer_1_output); free(dense_layer_2_output); free(output_data); -return 0; + return 0; } diff --git a/gpu4s_benchmark/cifar_10_multiple/opencl/lib_opencl_common.cpp b/gpu4s_benchmark/cifar_10_multiple/opencl/lib_opencl_common.cpp index 6c3dbc81..dfd18d8d 100644 --- a/gpu4s_benchmark/cifar_10_multiple/opencl/lib_opencl_common.cpp +++ b/gpu4s_benchmark/cifar_10_multiple/opencl/lib_opencl_common.cpp @@ -267,4 +267,49 @@ void clean(GraficCommon* device_object){ delete deviceObj->dense_layer_2_output; delete deviceObj->output_data; delete deviceObj->sum_ouput; -} \ No newline at end of file +} + +#ifdef UMA_COMPATIBILITY +// ====== UMA function ====== +void get_unified_memory_pointers(GraficCommon* device_object,bench_t* &input_data, unsigned int input_mem_size,bench_t* &kernel_1, bench_t* &kernel_2, unsigned int kernel_mem_size, bench_t* &weights_1, unsigned int weights_1_mem_size, bench_t* &weights_2, unsigned int weights_2_mem_size, bench_t* &d_output, unsigned int output_mem_size){ + GraficObject* deviceObj = static_cast(device_object); + // --- Call the openCL common function --- + map_unified_memory(device_object, input_mem_size, + BufferMapCL{&input_data, deviceObj->input_data, nullptr}); + + map_unified_memory(device_object, kernel_mem_size, + BufferMapCL{&kernel_1, deviceObj->kernel_1, nullptr}, + BufferMapCL{&kernel_2, deviceObj->kernel_2, nullptr}); + + map_unified_memory(device_object, weights_1_mem_size, + BufferMapCL{&weights_1, deviceObj->dense_layer_1_weights, nullptr}); + + map_unified_memory(device_object, weights_2_mem_size, + BufferMapCL{&weights_2, deviceObj->dense_layer_2_weights, nullptr}); + + map_unified_memory(device_object, output_mem_size, + BufferMapCL{&d_output, deviceObj->output_data, nullptr}); +} + +void sync_unified_memory_to_device(GraficCommon* device_object, bench_t* &input_data, bench_t* &kernel_1, bench_t* &kernel_2, bench_t* &weights_1, bench_t* &weights_2, bench_t* &d_output){ + GraficObject* deviceObj = static_cast(device_object); + // --- Call the openCL common function --- + unmap_unified_memory(device_object, + BufferMapCL{&input_data, deviceObj->input_data, deviceObj->evt_copyIN}, + BufferMapCL{&kernel_1, deviceObj->kernel_1, deviceObj->evt_copyK1}, + BufferMapCL{&kernel_2, deviceObj->kernel_2, deviceObj->evt_copyK2}, + BufferMapCL{&weights_1, deviceObj->dense_layer_1_weights, deviceObj->evt_copyW1}, + BufferMapCL{&weights_2, deviceObj->dense_layer_2_weights, deviceObj->evt_copyW2}, + BufferMapCL{&d_output, deviceObj->output_data, nullptr} + ); +} + +void sync_unified_memory_to_host(GraficCommon* device_object, bench_t* &d_output, unsigned int memSize){ + GraficObject* deviceObj = static_cast(device_object); + // --- Call the openCL common function --- + map_unified_memory_to_host(device_object, memSize, + BufferMapCL{&d_output, deviceObj->output_data, deviceObj->evt_copyOut} + ); +} + +#endif \ No newline at end of file From 6e57a234426ebe4b29a47e908016fff1fc802932 Mon Sep 17 00:00:00 2001 From: Noah Perret Date: Fri, 14 Aug 2026 19:40:28 +0200 Subject: [PATCH 22/27] fix UMA for android --- .../finite_impulse_response_filter/cpu/lib_cpu.cpp | 2 +- gpu4s_benchmark/finite_impulse_response_filter/main.cpp | 2 +- .../finite_impulse_response_filter/opencl/lib_opencl.cpp | 2 ++ .../finite_impulse_response_filter/openmp/lib_omp.cpp | 2 +- .../openmp/openmp_common.cpp | 8 -------- .../finite_impulse_response_filter/openmp/openmp_common.h | 8 -------- 6 files changed, 5 insertions(+), 19 deletions(-) delete mode 100644 gpu4s_benchmark/finite_impulse_response_filter/openmp/openmp_common.cpp delete mode 100644 gpu4s_benchmark/finite_impulse_response_filter/openmp/openmp_common.h diff --git a/gpu4s_benchmark/finite_impulse_response_filter/cpu/lib_cpu.cpp b/gpu4s_benchmark/finite_impulse_response_filter/cpu/lib_cpu.cpp index 84cb3c7b..dbff2b78 100644 --- a/gpu4s_benchmark/finite_impulse_response_filter/cpu/lib_cpu.cpp +++ b/gpu4s_benchmark/finite_impulse_response_filter/cpu/lib_cpu.cpp @@ -16,7 +16,7 @@ void init(GraficCommon* device_object, int platform, int device, char* device_na bool device_memory_init(GraficCommon* device_object, unsigned int size_a_matrix, unsigned int size_b_matrix, unsigned int size_c_matrix) { GraficObject* deviceObj = static_cast(device_object); - deviceObj->d_B = (bench_t*) malloc ( size_b_matrix * sizeof(bench_t*)); + deviceObj->d_B = (bench_t*) malloc ( size_b_matrix * sizeof(bench_t)); return true; } diff --git a/gpu4s_benchmark/finite_impulse_response_filter/main.cpp b/gpu4s_benchmark/finite_impulse_response_filter/main.cpp index 462f2893..31fbd035 100644 --- a/gpu4s_benchmark/finite_impulse_response_filter/main.cpp +++ b/gpu4s_benchmark/finite_impulse_response_filter/main.cpp @@ -170,7 +170,7 @@ int main(int argc, char *argv[]) } // execute kernel - execute_kernel(fir_bench, size_B, size_matrix, size_B, size_k); + execute_kernel(fir_bench, size_matrix, size_matrix, size_B, size_k); // copy memory to host if (arguments_parameters->unified_memory) diff --git a/gpu4s_benchmark/finite_impulse_response_filter/opencl/lib_opencl.cpp b/gpu4s_benchmark/finite_impulse_response_filter/opencl/lib_opencl.cpp index d60ff6a8..346c1e0e 100644 --- a/gpu4s_benchmark/finite_impulse_response_filter/opencl/lib_opencl.cpp +++ b/gpu4s_benchmark/finite_impulse_response_filter/opencl/lib_opencl.cpp @@ -84,6 +84,8 @@ void copy_memory_to_device(GraficCommon* device_object, bench_t* h_A, bench_t* k void execute_kernel(GraficCommon* device_object, unsigned int n, unsigned int m,unsigned int w, unsigned int kernel_size){ GraficObject* deviceObj = static_cast(device_object); + //FIX: use W instead of N the other implementation need size_matrix and this one need size_B + n = w; const unsigned int x_local= BLOCK_SIZE; cl::NDRange local; cl::NDRange global; diff --git a/gpu4s_benchmark/finite_impulse_response_filter/openmp/lib_omp.cpp b/gpu4s_benchmark/finite_impulse_response_filter/openmp/lib_omp.cpp index ab1bb0c4..17fb3da4 100644 --- a/gpu4s_benchmark/finite_impulse_response_filter/openmp/lib_omp.cpp +++ b/gpu4s_benchmark/finite_impulse_response_filter/openmp/lib_omp.cpp @@ -16,7 +16,7 @@ void init(GraficCommon* device_object, int platform, int device, char* device_na bool device_memory_init(GraficCommon* device_object, unsigned int size_a_matrix, unsigned int size_b_matrix, unsigned int size_c_matrix) { GraficObject* deviceObj = static_cast(device_object); - deviceObj->d_B = (bench_t*) malloc ( size_b_matrix * sizeof(bench_t*)); + deviceObj->d_B = (bench_t*) malloc ( size_b_matrix * sizeof(bench_t)); return true; } diff --git a/gpu4s_benchmark/finite_impulse_response_filter/openmp/openmp_common.cpp b/gpu4s_benchmark/finite_impulse_response_filter/openmp/openmp_common.cpp deleted file mode 100644 index bd795c40..00000000 --- a/gpu4s_benchmark/finite_impulse_response_filter/openmp/openmp_common.cpp +++ /dev/null @@ -1,8 +0,0 @@ -/** * ==================================================================== - * @file openmp_common.cpp (./finite_impulse_response_filter) - * @brief Common OpenMP platform initialization, device setup, - * profiling timer evaluation, and generic cleanup routines. - * @paragraph License - * ESA-PL Strong Copyleft – v2.5 - * ======================================================================= */ -#include "../benchmark_library.h" diff --git a/gpu4s_benchmark/finite_impulse_response_filter/openmp/openmp_common.h b/gpu4s_benchmark/finite_impulse_response_filter/openmp/openmp_common.h deleted file mode 100644 index 87e64a57..00000000 --- a/gpu4s_benchmark/finite_impulse_response_filter/openmp/openmp_common.h +++ /dev/null @@ -1,8 +0,0 @@ -/** * ==================================================================== - * @file openmp_common.h (./finite_impulse_response_filter) - * @brief Shared declarations, data structures, and timing utilities - * for OpenMP benchmark backends. - * @paragraph License - * ESA-PL Strong Copyleft – v2.5 - * ======================================================================= */ -#pragma once From 98bb06cb931ee4b7ac698dd4c591bc56689393ea Mon Sep 17 00:00:00 2001 From: Noah Perret Date: Fri, 14 Aug 2026 20:00:59 +0200 Subject: [PATCH 23/27] add comment for uma function in main --- gpu4s_benchmark/LRN_bench/main.cpp | 3 +++ gpu4s_benchmark/LRN_bench/openmp/omp_common.h | 8 ------- gpu4s_benchmark/cifar_10/main.cpp | 22 ++++++++++--------- gpu4s_benchmark/cifar_10/openmp/omp_common.h | 8 ------- gpu4s_benchmark/cifar_10_multiple/main.cpp | 3 +++ .../cifar_10_multiple/openmp/omp_common.h | 10 --------- gpu4s_benchmark/common/opencl_common.hpp | 1 + gpu4s_benchmark/convolution_2D_bench/main.cpp | 3 +++ .../convolution_2D_bench/openmp/omp_common.h | 8 ------- gpu4s_benchmark/correlation_2D/main.cpp | 3 +++ .../correlation_2D/openmp/omp_common.h | 9 -------- .../fast_fourier_transform_2D_bench/main.cpp | 3 +++ .../fast_fourier_transform_bench/main.cpp | 4 +++- .../openmp/omp_common.h | 8 ------- .../main.cpp | 3 +++ .../openmp/omp_common.h | 8 ------- .../finite_impulse_response_filter/main.cpp | 4 +++- .../matrix_multiplication_bench/main.cpp | 3 +++ .../matrix_multiplication_bench_fp16/main.cpp | 3 +++ .../main.cpp | 3 +++ gpu4s_benchmark/max_pooling_bench/main.cpp | 3 +++ .../max_pooling_bench/openmp/omp_common.h | 8 ------- .../memory_bandwidth_bench/main.cpp | 3 +++ gpu4s_benchmark/relu_bench/main.cpp | 9 +++++--- .../relu_bench/openmp/omp_common.h | 8 ------- gpu4s_benchmark/softmax_bench/main.cpp | 3 +++ .../softmax_bench/openmp/omp_common.h | 8 ------- gpu4s_benchmark/wavelet_transform/main.cpp | 3 +++ .../wavelet_transform/openmp/omp_common.h | 10 --------- 29 files changed, 64 insertions(+), 108 deletions(-) delete mode 100644 gpu4s_benchmark/LRN_bench/openmp/omp_common.h delete mode 100644 gpu4s_benchmark/cifar_10/openmp/omp_common.h delete mode 100644 gpu4s_benchmark/cifar_10_multiple/openmp/omp_common.h delete mode 100644 gpu4s_benchmark/convolution_2D_bench/openmp/omp_common.h delete mode 100644 gpu4s_benchmark/correlation_2D/openmp/omp_common.h delete mode 100644 gpu4s_benchmark/fast_fourier_transform_bench/openmp/omp_common.h delete mode 100644 gpu4s_benchmark/fast_fourier_transform_window_bench/openmp/omp_common.h delete mode 100644 gpu4s_benchmark/max_pooling_bench/openmp/omp_common.h delete mode 100644 gpu4s_benchmark/relu_bench/openmp/omp_common.h delete mode 100644 gpu4s_benchmark/softmax_bench/openmp/omp_common.h delete mode 100644 gpu4s_benchmark/wavelet_transform/openmp/omp_common.h diff --git a/gpu4s_benchmark/LRN_bench/main.cpp b/gpu4s_benchmark/LRN_bench/main.cpp index 15e201b0..7d29c2b0 100644 --- a/gpu4s_benchmark/LRN_bench/main.cpp +++ b/gpu4s_benchmark/LRN_bench/main.cpp @@ -57,6 +57,7 @@ int main(int argc, char *argv[]){ { #ifdef UMA_COMPATIBILITY // map the buffzer to the gpu + cpu take the lead + // UMA: map buffers between device and cpu (takes the lead) get_unified_memory_pointers(lrn_bench, A, d_B, mem_size); #else fprintf(stderr, "\033[1;31merror:\033[0m This framework is not compatible with unified memory. Please remove the -u arg!\n"); @@ -135,6 +136,7 @@ int main(int argc, char *argv[]){ if(arguments_parameters->unified_memory) { #ifdef UMA_COMPATIBILITY + // UMA: unmap shared buffer from host to device sync_unified_memory_to_device(lrn_bench, A, d_B); #endif } @@ -152,6 +154,7 @@ int main(int argc, char *argv[]){ if (arguments_parameters->unified_memory) { #ifdef UMA_COMPATIBILITY + // UMA: map back output buffer to host sync_unified_memory_to_host(lrn_bench, d_B, mem_size); #endif } else diff --git a/gpu4s_benchmark/LRN_bench/openmp/omp_common.h b/gpu4s_benchmark/LRN_bench/openmp/omp_common.h deleted file mode 100644 index 2b99de6d..00000000 --- a/gpu4s_benchmark/LRN_bench/openmp/omp_common.h +++ /dev/null @@ -1,8 +0,0 @@ -/** * ==================================================================== - * @file omp_common.h (./LRN_bench) - * @brief Shared declarations, data structures, and timing utilities - * for OpenMP benchmark backends. - * @paragraph License - * ESA-PL Strong Copyleft – v2.5 - * ======================================================================= */ -#pragma once diff --git a/gpu4s_benchmark/cifar_10/main.cpp b/gpu4s_benchmark/cifar_10/main.cpp index 95b8f602..f52aa943 100644 --- a/gpu4s_benchmark/cifar_10/main.cpp +++ b/gpu4s_benchmark/cifar_10/main.cpp @@ -46,29 +46,28 @@ int main(int argc, char *argv[]){ // A input matrix unsigned int size_A = CIFAR_10_INPUT * CIFAR_10_INPUT; unsigned int mem_size_A = sizeof(bench_t) * size_A; - bench_t* input_data = NULL; + bench_t* input_data = nullptr; // B output matrix - unsigned int size_B = CIFAR_10_INPUT * CIFAR_10_INPUT; + unsigned int size_B = CIFAR_10_INPUT; unsigned int mem_size_B = sizeof(bench_t) * size_B; - bench_t* d_output = NULL; + bench_t* d_output = nullptr; // kernel matrix 1 unsigned int size_k_1 = KERNEL_CON_1 * KERNEL_CON_2; unsigned int mem_size_k_1 = sizeof(bench_t) * size_k_1; - bench_t* kernel_1 = NULL; + bench_t* kernel_1 = nullptr; // kernel matrix 2 unsigned int size_k_2 = KERNEL_CON_2 * KERNEL_CON_2; unsigned int mem_size_k_2 = sizeof(bench_t) * size_k_2; - bench_t* kernel_2 = NULL; + bench_t* kernel_2 = nullptr; // weights 1 unsigned int size_w_1 = DENSE_1 * (((CIFAR_10_INPUT / STRIDE_1)/STRIDE_2)*((CIFAR_10_INPUT / STRIDE_1)/STRIDE_2)); unsigned int mem_size_w_1 = sizeof(bench_t) * size_w_1; - bench_t* weights_1 = NULL; + bench_t* weights_1 = nullptr; // weights 1 unsigned int size_w_2 = DENSE_1 * DENSE_2; unsigned int mem_size_w_2 = sizeof(bench_t) * size_w_2; - bench_t* weights_2 = NULL; + bench_t* weights_2 = nullptr; // Outputs - unsigned int mem_size_output = sizeof(bench_t) * CIFAR_10_OUTPUT; const unsigned int size_pooling_1 = CIFAR_10_INPUT / STRIDE_1; const unsigned int size_pooling_2 = size_pooling_1 / STRIDE_2; bench_t* conv_1_output = (bench_t*) malloc ( CIFAR_10_INPUT * CIFAR_10_INPUT * sizeof(bench_t*)); @@ -103,6 +102,7 @@ int main(int argc, char *argv[]){ { #ifdef UMA_COMPATIBILITY // map the buffzer to the gpu + cpu take the lead + // UMA: map buffers between device and cpu (takes the lead) get_unified_memory_pointers(cifar10_bench,input_data, mem_size_A,kernel_1, kernel_2, mem_size_k_1,weights_1, mem_size_w_1,weights_2, mem_size_w_2,d_output, mem_size_output); #else fprintf(stderr, "\033[1;31merror:\033[0m This framework is not compatible with unified memory. Please remove the -u arg!\n"); @@ -216,6 +216,7 @@ int main(int argc, char *argv[]){ if(arguments_parameters->unified_memory) { #ifdef UMA_COMPATIBILITY + // UMA: unmap shared buffer from host to device sync_unified_memory_to_device(cifar10_bench, input_data, kernel_1, kernel_2, weights_1, weights_2, d_output); #endif } @@ -231,7 +232,8 @@ int main(int argc, char *argv[]){ if (arguments_parameters->unified_memory) { #ifdef UMA_COMPATIBILITY - sync_unified_memory_to_host(cifar10_bench, d_output, mem_size_output); + // UMA: map back output buffer to host + sync_unified_memory_to_host(cifar10_bench, d_output, mem_size_B); #endif } else { @@ -330,7 +332,7 @@ int main(int argc, char *argv[]){ free(dense_layer_1_output); free(dense_layer_2_output); free(output_data); -return 0; + return 0; } diff --git a/gpu4s_benchmark/cifar_10/openmp/omp_common.h b/gpu4s_benchmark/cifar_10/openmp/omp_common.h deleted file mode 100644 index 2f6c01b1..00000000 --- a/gpu4s_benchmark/cifar_10/openmp/omp_common.h +++ /dev/null @@ -1,8 +0,0 @@ -/** * ==================================================================== - * @file omp_common.h (./cifar_10) - * @brief Shared declarations, data structures, and timing utilities - * for OpenMP benchmark backends. - * @paragraph License - * ESA-PL Strong Copyleft – v2.5 - * ======================================================================= */ -#pragma once diff --git a/gpu4s_benchmark/cifar_10_multiple/main.cpp b/gpu4s_benchmark/cifar_10_multiple/main.cpp index bf7685f7..8d99f7ad 100644 --- a/gpu4s_benchmark/cifar_10_multiple/main.cpp +++ b/gpu4s_benchmark/cifar_10_multiple/main.cpp @@ -106,6 +106,7 @@ int main(int argc, char *argv[]){ { #ifdef UMA_COMPATIBILITY // map the buffzer to the gpu + cpu take the lead + // UMA: map buffers between device and cpu (takes the lead) get_unified_memory_pointers(cifar10_bench,input_data, mem_size_A,kernel_1, kernel_2, mem_size_k_1,weights_1, mem_size_w_1,weights_2, mem_size_w_2,d_output, mem_size_B); #else fprintf(stderr, "\033[1;31merror:\033[0m This framework is not compatible with unified memory. Please remove the -u arg!\n"); @@ -231,6 +232,7 @@ int main(int argc, char *argv[]){ if(arguments_parameters->unified_memory) { #ifdef UMA_COMPATIBILITY + // UMA: unmap shared buffer from host to device sync_unified_memory_to_device(cifar10_bench, input_data, kernel_1, kernel_2, weights_1, weights_2, d_output); #endif } @@ -247,6 +249,7 @@ int main(int argc, char *argv[]){ if (arguments_parameters->unified_memory) { #ifdef UMA_COMPATIBILITY + // UMA: map back output buffer to host sync_unified_memory_to_host(cifar10_bench, d_output, mem_size_B); #endif } else diff --git a/gpu4s_benchmark/cifar_10_multiple/openmp/omp_common.h b/gpu4s_benchmark/cifar_10_multiple/openmp/omp_common.h deleted file mode 100644 index 35e536ee..00000000 --- a/gpu4s_benchmark/cifar_10_multiple/openmp/omp_common.h +++ /dev/null @@ -1,10 +0,0 @@ -/** * ==================================================================== - * @file omp_common.h (./cifar_10_multiple) - * @brief Shared declarations, data structures, and timing utilities - * for OpenMP benchmark backends. - * @paragraph License - * ESA-PL Strong Copyleft – v2.5 - * ======================================================================= */ -#pragma once - - diff --git a/gpu4s_benchmark/common/opencl_common.hpp b/gpu4s_benchmark/common/opencl_common.hpp index 0eb6042f..dd9a2a05 100644 --- a/gpu4s_benchmark/common/opencl_common.hpp +++ b/gpu4s_benchmark/common/opencl_common.hpp @@ -54,6 +54,7 @@ inline void map_unified_memory(GraficCommon* device_object, unsigned memSize, Ma // --- C++17 Fold Expression Unrolled at compile-time --- // For each MapCL map host buffer to devcie buffer (( + //map the buffer between cpu and gpu (cpu is faster) *(mapCL.hostBuffer) = static_cast( deviceObj->queue->enqueueMapBuffer( *(mapCL.deviceBuffer), CL_TRUE, CL_MAP_WRITE, 0, memSize, nullptr, mapCL.deviceEvent, &lastErr diff --git a/gpu4s_benchmark/convolution_2D_bench/main.cpp b/gpu4s_benchmark/convolution_2D_bench/main.cpp index 1b73207b..61b8322f 100644 --- a/gpu4s_benchmark/convolution_2D_bench/main.cpp +++ b/gpu4s_benchmark/convolution_2D_bench/main.cpp @@ -62,6 +62,7 @@ int main(int argc, char *argv[]){ { #ifdef UMA_COMPATIBILITY // map the buffzer to the gpu + cpu take the lead + // UMA: map buffers between device and cpu (takes the lead) get_unified_memory_pointers(conv_bench, A, kernel, d_B, mem_size, size_k); #else fprintf(stderr, "\033[1;31merror:\033[0m This framework is not compatible with unified memory. Please remove the -u arg!\n"); @@ -160,6 +161,7 @@ int main(int argc, char *argv[]){ if(arguments_parameters->unified_memory) { #ifdef UMA_COMPATIBILITY + // UMA: unmap shared buffer from host to device sync_unified_memory_to_device(conv_bench, A, kernel, d_B); #endif } @@ -176,6 +178,7 @@ int main(int argc, char *argv[]){ if (arguments_parameters->unified_memory) { #ifdef UMA_COMPATIBILITY + // UMA: map back output buffer to host sync_unified_memory_to_host(conv_bench, d_B, mem_size); #endif } else diff --git a/gpu4s_benchmark/convolution_2D_bench/openmp/omp_common.h b/gpu4s_benchmark/convolution_2D_bench/openmp/omp_common.h deleted file mode 100644 index 8b835b9e..00000000 --- a/gpu4s_benchmark/convolution_2D_bench/openmp/omp_common.h +++ /dev/null @@ -1,8 +0,0 @@ -/** * ==================================================================== - * @file omp_common.h (./convolution_2D_bench) - * @brief Shared declarations, data structures, and timing utilities - * for OpenMP benchmark backends. - * @paragraph License - * ESA-PL Strong Copyleft – v2.5 - * ======================================================================= */ -#pragma once diff --git a/gpu4s_benchmark/correlation_2D/main.cpp b/gpu4s_benchmark/correlation_2D/main.cpp index 635da386..d2d44ce2 100644 --- a/gpu4s_benchmark/correlation_2D/main.cpp +++ b/gpu4s_benchmark/correlation_2D/main.cpp @@ -62,6 +62,7 @@ int main(int argc, char *argv[]){ { #ifdef UMA_COMPATIBILITY // map the buffzer to the gpu + cpu take the lead + // UMA: map buffers between device and cpu (takes the lead) get_unified_memory_pointers(correlation_bench, A, B, d_R, mem_size); #else fprintf(stderr, "\033[1;31merror:\033[0m This framework is not compatible with unified memory. Please remove the -u arg!\n"); @@ -161,6 +162,7 @@ int main(int argc, char *argv[]){ if(arguments_parameters->unified_memory) { #ifdef UMA_COMPATIBILITY + // UMA: unmap shared buffer from host to device sync_unified_memory_to_device(correlation_bench, A, B, d_R); #endif } @@ -176,6 +178,7 @@ int main(int argc, char *argv[]){ if (arguments_parameters->unified_memory) { #ifdef UMA_COMPATIBILITY + // UMA: map back output buffer to host sync_unified_memory_to_host(correlation_bench, d_R, sizeof(result_bench_t)); #endif } else diff --git a/gpu4s_benchmark/correlation_2D/openmp/omp_common.h b/gpu4s_benchmark/correlation_2D/openmp/omp_common.h deleted file mode 100644 index ec8fb05d..00000000 --- a/gpu4s_benchmark/correlation_2D/openmp/omp_common.h +++ /dev/null @@ -1,9 +0,0 @@ -/** * ==================================================================== - * @file omp_common.h (./correlation_2D) - * @brief Shared declarations, data structures, and timing utilities - * for OpenMP benchmark backends. - * @paragraph License - * ESA-PL Strong Copyleft – v2.5 - * ======================================================================= */ -#pragma once - diff --git a/gpu4s_benchmark/fast_fourier_transform_2D_bench/main.cpp b/gpu4s_benchmark/fast_fourier_transform_2D_bench/main.cpp index 0ec21bbd..59ecf3b6 100644 --- a/gpu4s_benchmark/fast_fourier_transform_2D_bench/main.cpp +++ b/gpu4s_benchmark/fast_fourier_transform_2D_bench/main.cpp @@ -63,6 +63,7 @@ int main(int argc, char *argv[]){ { #ifdef UMA_COMPATIBILITY // map the buffzer to the gpu + cpu take the lead + // UMA: map buffers between device and cpu (takes the lead) get_unified_memory_pointers(fft_bench, A, d_B, size_A); #else fprintf(stderr, "\033[1;31merror:\033[0m This framework is not compatible with unified memory. Please remove the -u arg!\n"); @@ -122,6 +123,7 @@ int main(int argc, char *argv[]){ if(arguments_parameters->unified_memory) { #ifdef UMA_COMPATIBILITY + // UMA: unmap shared buffer from host to device sync_unified_memory_to_device(fft_bench, A, d_B, size_A); #endif } else @@ -136,6 +138,7 @@ int main(int argc, char *argv[]){ if (arguments_parameters->unified_memory) { #ifdef UMA_COMPATIBILITY + // UMA: map back output buffer to host sync_unified_memory_to_host(fft_bench, d_B, size_A); #endif } else diff --git a/gpu4s_benchmark/fast_fourier_transform_bench/main.cpp b/gpu4s_benchmark/fast_fourier_transform_bench/main.cpp index 8f9b443b..0ba8a0d2 100644 --- a/gpu4s_benchmark/fast_fourier_transform_bench/main.cpp +++ b/gpu4s_benchmark/fast_fourier_transform_bench/main.cpp @@ -55,7 +55,7 @@ int main(int argc, char *argv[]){ if (arguments_parameters->unified_memory) { #ifdef UMA_COMPATIBILITY - // map the buffzer to the gpu + cpu take the lead + // UMA: map buffers between device and cpu (takes the lead) get_unified_memory_pointers(fft_bench, d_B, mem_size); #else fprintf(stderr, "\033[1;31merror:\033[0m This framework is not compatible with unified memory. Please remove the -u arg!\n"); @@ -119,6 +119,7 @@ int main(int argc, char *argv[]){ if(arguments_parameters->unified_memory) { #ifdef UMA_COMPATIBILITY + // UMA: unmap shared buffer from host to device sync_unified_memory_to_device(fft_bench, d_B); #endif } @@ -134,6 +135,7 @@ int main(int argc, char *argv[]){ if (arguments_parameters->unified_memory) { #ifdef UMA_COMPATIBILITY + // UMA: map back output buffer to host sync_unified_memory_to_host(fft_bench, d_B, mem_size); #endif } else diff --git a/gpu4s_benchmark/fast_fourier_transform_bench/openmp/omp_common.h b/gpu4s_benchmark/fast_fourier_transform_bench/openmp/omp_common.h deleted file mode 100644 index df74647a..00000000 --- a/gpu4s_benchmark/fast_fourier_transform_bench/openmp/omp_common.h +++ /dev/null @@ -1,8 +0,0 @@ -/** * ==================================================================== - * @file omp_common.h (./fast_fourier_transform_bench) - * @brief Shared declarations, data structures, and timing utilities - * for OpenMP benchmark backends. - * @paragraph License - * ESA-PL Strong Copyleft – v2.5 - * ======================================================================= */ -#pragma once diff --git a/gpu4s_benchmark/fast_fourier_transform_window_bench/main.cpp b/gpu4s_benchmark/fast_fourier_transform_window_bench/main.cpp index 191d904c..7fbc22df 100644 --- a/gpu4s_benchmark/fast_fourier_transform_window_bench/main.cpp +++ b/gpu4s_benchmark/fast_fourier_transform_window_bench/main.cpp @@ -61,6 +61,7 @@ int main(int argc, char *argv[]){ { #ifdef UMA_COMPATIBILITY // map the buffzer to the gpu + cpu take the lead + // UMA: map buffers between device and cpu (takes the lead) get_unified_memory_pointers(fft_bench, A, mem_size_A); #else fprintf(stderr, "\033[1;31merror:\033[0m This framework is not compatible with unified memory. Please remove the -u arg!\n"); @@ -116,6 +117,7 @@ int main(int argc, char *argv[]){ if(arguments_parameters->unified_memory) { #ifdef UMA_COMPATIBILITY + // UMA: unmap shared buffer from host to device sync_unified_memory_to_device(fft_bench, A); #endif } @@ -131,6 +133,7 @@ int main(int argc, char *argv[]){ if (arguments_parameters->unified_memory) { #ifdef UMA_COMPATIBILITY + // UMA: map back output buffer to host sync_unified_memory_to_host(fft_bench, d_B, size_B); #endif } else diff --git a/gpu4s_benchmark/fast_fourier_transform_window_bench/openmp/omp_common.h b/gpu4s_benchmark/fast_fourier_transform_window_bench/openmp/omp_common.h deleted file mode 100644 index 4bd77040..00000000 --- a/gpu4s_benchmark/fast_fourier_transform_window_bench/openmp/omp_common.h +++ /dev/null @@ -1,8 +0,0 @@ -/** * ==================================================================== - * @file omp_common.h (./fast_fourier_transform_window_bench) - * @brief Shared declarations, data structures, and timing utilities - * for OpenMP benchmark backends. - * @paragraph License - * ESA-PL Strong Copyleft – v2.5 - * ======================================================================= */ -#pragma once diff --git a/gpu4s_benchmark/finite_impulse_response_filter/main.cpp b/gpu4s_benchmark/finite_impulse_response_filter/main.cpp index 31fbd035..70f8ddc8 100644 --- a/gpu4s_benchmark/finite_impulse_response_filter/main.cpp +++ b/gpu4s_benchmark/finite_impulse_response_filter/main.cpp @@ -67,7 +67,7 @@ int main(int argc, char *argv[]) if (arguments_parameters->unified_memory) { #ifdef UMA_COMPATIBILITY - // map the buffzer to the gpu + cpu take the lead + // UMA: map buffers between device and cpu (takes the lead) get_unified_memory_pointers(fir_bench, A, kernel, d_B, mem_size, mem_size_k, mem_size_B); #else fprintf(stderr, "\033[1;31merror:\033[0m This framework is not compatible with unified memory. Please remove the -u arg!\n"); @@ -161,6 +161,7 @@ int main(int argc, char *argv[]) if(arguments_parameters->unified_memory) { #ifdef UMA_COMPATIBILITY + // UMA: unmap shared buffer from host to device sync_unified_memory_to_device(fir_bench, A, kernel, d_B); #endif } @@ -176,6 +177,7 @@ int main(int argc, char *argv[]) if (arguments_parameters->unified_memory) { #ifdef UMA_COMPATIBILITY + // UMA: map back output buffer to host sync_unified_memory_to_host(fir_bench, d_B, mem_size_B); #endif } else diff --git a/gpu4s_benchmark/matrix_multiplication_bench/main.cpp b/gpu4s_benchmark/matrix_multiplication_bench/main.cpp index ee8aa539..7784ac41 100644 --- a/gpu4s_benchmark/matrix_multiplication_bench/main.cpp +++ b/gpu4s_benchmark/matrix_multiplication_bench/main.cpp @@ -60,6 +60,7 @@ int main(int argc, char *argv[]) { #ifdef UMA_COMPATIBILITY // map the buffzer to the gpu + cpu take the lead + // UMA: map buffers between device and cpu (takes the lead) get_unified_memory_pointers(matrix_bench, A, B, d_C, mem_size); #else fprintf(stderr, "\033[1;31merror:\033[0m This framework is not compatible with unified memory. Please remove the -u arg!\n"); @@ -126,6 +127,7 @@ int main(int argc, char *argv[]) if(arguments_parameters->unified_memory) { #ifdef UMA_COMPATIBILITY + // UMA: unmap shared buffer from host to device sync_unified_memory_to_device(matrix_bench, A, B, d_C); #endif } @@ -142,6 +144,7 @@ int main(int argc, char *argv[]) if (arguments_parameters->unified_memory) { #ifdef UMA_COMPATIBILITY + // UMA: map back output buffer to host sync_unified_memory_to_host(matrix_bench, d_C, mem_size); #endif } else diff --git a/gpu4s_benchmark/matrix_multiplication_bench_fp16/main.cpp b/gpu4s_benchmark/matrix_multiplication_bench_fp16/main.cpp index 0cf4f704..84a6e438 100644 --- a/gpu4s_benchmark/matrix_multiplication_bench_fp16/main.cpp +++ b/gpu4s_benchmark/matrix_multiplication_bench_fp16/main.cpp @@ -60,6 +60,7 @@ int main(int argc, char *argv[]){ { #ifdef UMA_COMPATIBILITY // map the buffzer to the gpu + cpu take the lead + // UMA: map buffers between device and cpu (takes the lead) get_unified_memory_pointers(matrix_benck, A, B, d_C, mem_size); #else fprintf(stderr, "\033[1;31merror:\033[0m This framework is not compatible with unified memory. Please remove the -u arg!\n"); @@ -128,6 +129,7 @@ int main(int argc, char *argv[]){ if(arguments_parameters->unified_memory) { #ifdef UMA_COMPATIBILITY + // UMA: unmap shared buffer from host to device sync_unified_memory_to_device(matrix_benck, A, B, d_C); #endif } @@ -143,6 +145,7 @@ int main(int argc, char *argv[]){ if (arguments_parameters->unified_memory) { #ifdef UMA_COMPATIBILITY + // UMA: map back output buffer to host sync_unified_memory_to_host(matrix_benck, d_C, mem_size); #endif } else diff --git a/gpu4s_benchmark/matrix_multiplication_tensor_bench/main.cpp b/gpu4s_benchmark/matrix_multiplication_tensor_bench/main.cpp index aca39735..fa3b68f4 100644 --- a/gpu4s_benchmark/matrix_multiplication_tensor_bench/main.cpp +++ b/gpu4s_benchmark/matrix_multiplication_tensor_bench/main.cpp @@ -62,6 +62,7 @@ int main(int argc, char *argv[]){ { #ifdef UMA_COMPATIBILITY // map the buffzer to the gpu + cpu take the lead + // UMA: map buffers between device and cpu (takes the lead) get_unified_memory_pointers(matrix_benck, A, B, d_C, mem_size); #else fprintf(stderr, "\033[1;31merror:\033[0m This framework is not compatible with unified memory. Please remove the -u arg!\n"); @@ -132,6 +133,7 @@ int main(int argc, char *argv[]){ if(arguments_parameters->unified_memory) { #ifdef UMA_COMPATIBILITY + // UMA: unmap shared buffer from host to device sync_unified_memory_to_device(matrix_benck, A, B, d_C); #endif } @@ -147,6 +149,7 @@ int main(int argc, char *argv[]){ if (arguments_parameters->unified_memory) { #ifdef UMA_COMPATIBILITY + // UMA: map back output buffer to host sync_unified_memory_to_host(matrix_benck, d_C, mem_size); #endif } else diff --git a/gpu4s_benchmark/max_pooling_bench/main.cpp b/gpu4s_benchmark/max_pooling_bench/main.cpp index 30684c82..25477e6e 100644 --- a/gpu4s_benchmark/max_pooling_bench/main.cpp +++ b/gpu4s_benchmark/max_pooling_bench/main.cpp @@ -60,6 +60,7 @@ int main(int argc, char *argv[]){ { #ifdef UMA_COMPATIBILITY // map the buffzer to the gpu + cpu take the lead + // UMA: map buffers between device and cpu (takes the lead) get_unified_memory_pointers(max_bench, A, mem_size_A); #else fprintf(stderr, "\033[1;31merror:\033[0m This framework is not compatible with unified memory. Please remove the -u arg!\n"); @@ -139,6 +140,7 @@ int main(int argc, char *argv[]){ if(arguments_parameters->unified_memory) { #ifdef UMA_COMPATIBILITY + // UMA: unmap shared buffer from host to device sync_unified_memory_to_device(max_bench, A); #endif } @@ -154,6 +156,7 @@ int main(int argc, char *argv[]){ if (arguments_parameters->unified_memory) { #ifdef UMA_COMPATIBILITY + // UMA: map back output buffer to host sync_unified_memory_to_host(max_bench, d_B, size_B); #endif } else diff --git a/gpu4s_benchmark/max_pooling_bench/openmp/omp_common.h b/gpu4s_benchmark/max_pooling_bench/openmp/omp_common.h deleted file mode 100644 index 588397a8..00000000 --- a/gpu4s_benchmark/max_pooling_bench/openmp/omp_common.h +++ /dev/null @@ -1,8 +0,0 @@ -/** * ==================================================================== - * @file omp_common.h (./max_pooling_bench) - * @brief Shared declarations, data structures, and timing utilities - * for OpenMP benchmark backends. - * @paragraph License - * ESA-PL Strong Copyleft – v2.5 - * ======================================================================= */ -#pragma once diff --git a/gpu4s_benchmark/memory_bandwidth_bench/main.cpp b/gpu4s_benchmark/memory_bandwidth_bench/main.cpp index 9dd228ed..2c034671 100644 --- a/gpu4s_benchmark/memory_bandwidth_bench/main.cpp +++ b/gpu4s_benchmark/memory_bandwidth_bench/main.cpp @@ -62,6 +62,7 @@ int main(int argc, char *argv[]) { #ifdef UMA_COMPATIBILITY // map the buffzer to the gpu + cpu take the lead + // UMA: map buffers between device and cpu (takes the lead) get_unified_memory_pointers(mem_bench, A, d_B, mem_size); #else fprintf(stderr, "\033[1;31merror:\033[0m This framework is not compatible with unified memory. Please remove the -u arg!\n"); @@ -113,6 +114,7 @@ int main(int argc, char *argv[]) if(arguments_parameters->unified_memory) { #ifdef UMA_COMPATIBILITY + // UMA: unmap shared buffer from host to device sync_unified_memory_to_device(mem_bench, A, d_B); #endif } @@ -129,6 +131,7 @@ int main(int argc, char *argv[]) if (arguments_parameters->unified_memory) { #ifdef UMA_COMPATIBILITY + // UMA: map back output buffer to host sync_unified_memory_to_host(mem_bench, d_B, size_matrix); #endif } else diff --git a/gpu4s_benchmark/relu_bench/main.cpp b/gpu4s_benchmark/relu_bench/main.cpp index 2fd019b5..eca6fcd0 100644 --- a/gpu4s_benchmark/relu_bench/main.cpp +++ b/gpu4s_benchmark/relu_bench/main.cpp @@ -35,9 +35,9 @@ int main(int argc, char *argv[]){ unsigned int size_matrix = arguments_parameters->size * arguments_parameters->size; unsigned int mem_size = sizeof(bench_t) * size_matrix; // A input matrix - bench_t* A = NULL; + bench_t* A = nullptr; // B input matrix - bench_t* d_B = NULL; + bench_t* d_B = nullptr; bench_t* h_B = (bench_t*) malloc(mem_size); // init devices char device[100] = ""; @@ -58,6 +58,7 @@ int main(int argc, char *argv[]){ { #ifdef UMA_COMPATIBILITY // map the buffer to the gpu + cpu take the lead + // UMA: map buffers between device and cpu (takes the lead) get_unified_memory_pointers(relu_bench, A, d_B, mem_size); #else fprintf(stderr, "\033[1;31merror:\033[0m This framework is not compatible with unified memory. Please remove the -u arg!\n"); @@ -129,6 +130,7 @@ int main(int argc, char *argv[]){ if(arguments_parameters->unified_memory) { #ifdef UMA_COMPATIBILITY + // UMA: unmap shared buffer from host to device sync_unified_memory_to_device(relu_bench, A, d_B); #endif } @@ -144,6 +146,7 @@ int main(int argc, char *argv[]){ if (arguments_parameters->unified_memory) { #ifdef UMA_COMPATIBILITY + // UMA: map back output buffer to host sync_unified_memory_to_host(relu_bench, d_B, mem_size); #endif } else @@ -268,8 +271,8 @@ void init_arguments(BenchmarkParameters* arguments_parameters){ arguments_parameters->profiling_clock = false; #endif } -// Arguments part +// Arguments part void print_usage(const char * appName) { printf("Usage: %s -s Size -k [-v] [-e] [-o] [-t] [-d] [-i input_file_A_MATRIX input_file_B_MATRIX] \n", appName); diff --git a/gpu4s_benchmark/relu_bench/openmp/omp_common.h b/gpu4s_benchmark/relu_bench/openmp/omp_common.h deleted file mode 100644 index d15e8047..00000000 --- a/gpu4s_benchmark/relu_bench/openmp/omp_common.h +++ /dev/null @@ -1,8 +0,0 @@ -/** * ==================================================================== - * @file omp_common.h (./relu_bench) - * @brief Shared declarations, data structures, and timing utilities - * for OpenMP benchmark backends. - * @paragraph License - * ESA-PL Strong Copyleft – v2.5 - * ======================================================================= */ -#pragma once diff --git a/gpu4s_benchmark/softmax_bench/main.cpp b/gpu4s_benchmark/softmax_bench/main.cpp index 764e2c41..0788d523 100644 --- a/gpu4s_benchmark/softmax_bench/main.cpp +++ b/gpu4s_benchmark/softmax_bench/main.cpp @@ -58,6 +58,7 @@ int main(int argc, char *argv[]){ { #ifdef UMA_COMPATIBILITY // map the buffzer to the gpu + cpu take the lead + // UMA: map buffers between device and cpu (takes the lead) get_unified_memory_pointers(softmax_bench, A, d_B, mem_size); #else fprintf(stderr, "\033[1;31merror:\033[0m This framework is not compatible with unified memory. Please remove the -u arg!\n"); @@ -136,6 +137,7 @@ int main(int argc, char *argv[]){ if(arguments_parameters->unified_memory) { #ifdef UMA_COMPATIBILITY + // UMA: unmap shared buffer from host to device sync_unified_memory_to_device(softmax_bench, A, d_B); #endif } @@ -151,6 +153,7 @@ int main(int argc, char *argv[]){ if (arguments_parameters->unified_memory) { #ifdef UMA_COMPATIBILITY + // UMA: map back output buffer to host sync_unified_memory_to_host(softmax_bench, d_B, size_matrix); #endif } else diff --git a/gpu4s_benchmark/softmax_bench/openmp/omp_common.h b/gpu4s_benchmark/softmax_bench/openmp/omp_common.h deleted file mode 100644 index 50484a05..00000000 --- a/gpu4s_benchmark/softmax_bench/openmp/omp_common.h +++ /dev/null @@ -1,8 +0,0 @@ -/** * ==================================================================== - * @file omp_common.h (./softmax_bench) - * @brief Shared declarations, data structures, and timing utilities - * for OpenMP benchmark backends. - * @paragraph License - * ESA-PL Strong Copyleft – v2.5 - * ======================================================================= */ -#pragma once diff --git a/gpu4s_benchmark/wavelet_transform/main.cpp b/gpu4s_benchmark/wavelet_transform/main.cpp index 1c266c2c..cb0b0b79 100644 --- a/gpu4s_benchmark/wavelet_transform/main.cpp +++ b/gpu4s_benchmark/wavelet_transform/main.cpp @@ -65,6 +65,7 @@ int main(int argc, char *argv[]){ #ifdef UMA_COMPATIBILITY // map the buffzer to the gpu + cpu take the lead + // UMA: map buffers between device and cpu (takes the lead) get_unified_memory_pointers(wavelet_bench, A, d_B, lowpass_filter_ptr, highpass_filter_ptr, mem_size); @@ -152,6 +153,7 @@ int main(int argc, char *argv[]){ if(arguments_parameters->unified_memory) { #ifdef UMA_COMPATIBILITY + // UMA: unmap shared buffer from host to device sync_unified_memory_to_device(wavelet_bench, A, d_B, lowpass_filter_ptr, highpass_filter_ptr); #endif } @@ -167,6 +169,7 @@ int main(int argc, char *argv[]){ if (arguments_parameters->unified_memory) { #ifdef UMA_COMPATIBILITY + // UMA: map back output buffer to host sync_unified_memory_to_host(wavelet_bench, d_B, size_matrix); #endif } else diff --git a/gpu4s_benchmark/wavelet_transform/openmp/omp_common.h b/gpu4s_benchmark/wavelet_transform/openmp/omp_common.h deleted file mode 100644 index c82618d4..00000000 --- a/gpu4s_benchmark/wavelet_transform/openmp/omp_common.h +++ /dev/null @@ -1,10 +0,0 @@ -/** * ==================================================================== - * @file omp_common.h (./wavelet_transform) - * @brief Shared declarations, data structures, and timing utilities - * for OpenMP benchmark backends. - * @paragraph License - * ESA-PL Strong Copyleft – v2.5 - * ======================================================================= */ -#pragma once - - From 05f64b52d3d0391fdde9f028b60ce5db60d5a54c Mon Sep 17 00:00:00 2001 From: Noah Perret Date: Fri, 14 Aug 2026 20:07:22 +0200 Subject: [PATCH 24/27] add comment for uma function in main --- gpu4s_benchmark/LRN_bench/main.cpp | 1 + gpu4s_benchmark/cifar_10/main.cpp | 1 + gpu4s_benchmark/cifar_10_multiple/main.cpp | 1 + gpu4s_benchmark/convolution_2D_bench/main.cpp | 7 ++++--- gpu4s_benchmark/correlation_2D/main.cpp | 7 ++++--- gpu4s_benchmark/fast_fourier_transform_2D_bench/main.cpp | 5 +++-- gpu4s_benchmark/fast_fourier_transform_bench/main.cpp | 1 + .../fast_fourier_transform_window_bench/main.cpp | 1 + gpu4s_benchmark/finite_impulse_response_filter/main.cpp | 1 + gpu4s_benchmark/matrix_multiplication_bench/main.cpp | 1 + gpu4s_benchmark/matrix_multiplication_bench_fp16/main.cpp | 1 + .../matrix_multiplication_tensor_bench/main.cpp | 7 ++++--- gpu4s_benchmark/max_pooling_bench/main.cpp | 1 + gpu4s_benchmark/memory_bandwidth_bench/main.cpp | 5 +++-- gpu4s_benchmark/relu_bench/main.cpp | 1 + gpu4s_benchmark/softmax_bench/main.cpp | 1 + gpu4s_benchmark/wavelet_transform/main.cpp | 1 + 17 files changed, 30 insertions(+), 13 deletions(-) diff --git a/gpu4s_benchmark/LRN_bench/main.cpp b/gpu4s_benchmark/LRN_bench/main.cpp index 7d29c2b0..1fcdd357 100644 --- a/gpu4s_benchmark/LRN_bench/main.cpp +++ b/gpu4s_benchmark/LRN_bench/main.cpp @@ -31,6 +31,7 @@ int main(int argc, char *argv[]){ // VARIABLES /////////////////////////////////////////////////////////////////////////////////////////////// // linearizable versions of matrix + // initialized to nullptr to prevent wild/dangling pointer references with UMA unsigned int size_matrix = arguments_parameters->size * arguments_parameters->size; unsigned int mem_size = sizeof(bench_t) * size_matrix; // A input matrix diff --git a/gpu4s_benchmark/cifar_10/main.cpp b/gpu4s_benchmark/cifar_10/main.cpp index f52aa943..70c18ef0 100644 --- a/gpu4s_benchmark/cifar_10/main.cpp +++ b/gpu4s_benchmark/cifar_10/main.cpp @@ -44,6 +44,7 @@ int main(int argc, char *argv[]){ // linearizable versions of matrix unsigned int size_matrix = CIFAR_10_INPUT * CIFAR_10_INPUT; // A input matrix + // initialized to nullptr to prevent wild/dangling pointer references with UMA unsigned int size_A = CIFAR_10_INPUT * CIFAR_10_INPUT; unsigned int mem_size_A = sizeof(bench_t) * size_A; bench_t* input_data = nullptr; diff --git a/gpu4s_benchmark/cifar_10_multiple/main.cpp b/gpu4s_benchmark/cifar_10_multiple/main.cpp index 8d99f7ad..d41d674b 100644 --- a/gpu4s_benchmark/cifar_10_multiple/main.cpp +++ b/gpu4s_benchmark/cifar_10_multiple/main.cpp @@ -49,6 +49,7 @@ int main(int argc, char *argv[]){ // linearizable versions of matrix unsigned int size_matrix = CIFAR_10_INPUT * CIFAR_10_INPUT * arguments_parameters->size; // A input matrix + // initialized to nullptr to prevent wild/dangling pointer references with UMA unsigned int size_A = CIFAR_10_INPUT * CIFAR_10_INPUT * arguments_parameters->size; unsigned int mem_size_A = sizeof(bench_t) * size_A; bench_t* input_data = nullptr; diff --git a/gpu4s_benchmark/convolution_2D_bench/main.cpp b/gpu4s_benchmark/convolution_2D_bench/main.cpp index 61b8322f..a3e0d2cd 100644 --- a/gpu4s_benchmark/convolution_2D_bench/main.cpp +++ b/gpu4s_benchmark/convolution_2D_bench/main.cpp @@ -34,13 +34,14 @@ int main(int argc, char *argv[]){ unsigned int size_matrix = arguments_parameters->size * arguments_parameters->size; // A input matrix unsigned int mem_size = sizeof(bench_t) * size_matrix; - bench_t* A = NULL; + // initialized to nullptr to prevent wild/dangling pointer references with UMA + bench_t* A = nullptr; // kernel matrix unsigned int size_k = arguments_parameters->kernel_size * arguments_parameters->kernel_size ; unsigned int mem_size_k = sizeof(bench_t) * size_k; - bench_t* kernel = NULL; + bench_t* kernel = nullptr; // B output matrix - bench_t* d_B = NULL; + bench_t* d_B = nullptr; bench_t* h_B = (bench_t*) malloc(mem_size); // init devices char device[100] = ""; diff --git a/gpu4s_benchmark/correlation_2D/main.cpp b/gpu4s_benchmark/correlation_2D/main.cpp index d2d44ce2..60acd7da 100644 --- a/gpu4s_benchmark/correlation_2D/main.cpp +++ b/gpu4s_benchmark/correlation_2D/main.cpp @@ -37,11 +37,12 @@ int main(int argc, char *argv[]){ unsigned int size_matrix =arguments_parameters->size * arguments_parameters->size; // A input matrix unsigned int mem_size = sizeof(bench_t) * size_matrix; - bench_t* A = NULL; + // initialized to nullptr to prevent wild/dangling pointer references with UMA + bench_t* A = nullptr; // B input matrix - bench_t* B = NULL; + bench_t* B = nullptr; // Correaltion Value alwais is a float number - result_bench_t* d_R = NULL; + result_bench_t* d_R = nullptr; result_bench_t* h_R = (result_bench_t*) malloc(sizeof(result_bench_t)); // init devices char device[100] = ""; diff --git a/gpu4s_benchmark/fast_fourier_transform_2D_bench/main.cpp b/gpu4s_benchmark/fast_fourier_transform_2D_bench/main.cpp index 59ecf3b6..938b96ba 100644 --- a/gpu4s_benchmark/fast_fourier_transform_2D_bench/main.cpp +++ b/gpu4s_benchmark/fast_fourier_transform_2D_bench/main.cpp @@ -35,11 +35,12 @@ int main(int argc, char *argv[]){ // A input vector int64_t size_A = arguments_parameters->size; int64_t mem_size = sizeof(COMPLEX*) * size_A; + // initialized to nullptr to prevent wild/dangling pointer references with UMA COMPLEX **A = (COMPLEX **)malloc(arguments_parameters->size * sizeof(COMPLEX*)); - for(int64_t i = 0; i < arguments_parameters->size; ++i) A[i] = NULL; + for(int64_t i = 0; i < arguments_parameters->size; ++i) A[i] = nullptr; COMPLEX **d_B = (COMPLEX **)malloc(arguments_parameters->size * sizeof(COMPLEX*)); - for(int64_t i = 0; i < arguments_parameters->size; ++i) d_B[i] = NULL; + for(int64_t i = 0; i < arguments_parameters->size; ++i) d_B[i] = nullptr; COMPLEX **h_B = (COMPLEX **)malloc(arguments_parameters->size * sizeof(COMPLEX*)); for(int64_t i = 0; i < arguments_parameters->size; ++i) h_B[i] = (COMPLEX *)malloc(arguments_parameters->size * sizeof(COMPLEX)); diff --git a/gpu4s_benchmark/fast_fourier_transform_bench/main.cpp b/gpu4s_benchmark/fast_fourier_transform_bench/main.cpp index 0ba8a0d2..c8d44fd5 100644 --- a/gpu4s_benchmark/fast_fourier_transform_bench/main.cpp +++ b/gpu4s_benchmark/fast_fourier_transform_bench/main.cpp @@ -32,6 +32,7 @@ int main(int argc, char *argv[]){ // VARIABLES /////////////////////////////////////////////////////////////////////////////////////////////// // A input vector + // initialized to nullptr to prevent wild/dangling pointer references with UMA int64_t size = arguments_parameters->size; int64_t mem_size = sizeof(bench_t) * size; bench_t* A = (bench_t*) malloc(mem_size); diff --git a/gpu4s_benchmark/fast_fourier_transform_window_bench/main.cpp b/gpu4s_benchmark/fast_fourier_transform_window_bench/main.cpp index 7fbc22df..21312b61 100644 --- a/gpu4s_benchmark/fast_fourier_transform_window_bench/main.cpp +++ b/gpu4s_benchmark/fast_fourier_transform_window_bench/main.cpp @@ -32,6 +32,7 @@ int main(int argc, char *argv[]){ // VARIABLES /////////////////////////////////////////////////////////////////////////////////////////////// // A input vector + // initialized to nullptr to prevent wild/dangling pointer references with UMA int64_t size_A = arguments_parameters->size; int64_t mem_size_A = sizeof(bench_t) * size_A; bench_t* A = nullptr; diff --git a/gpu4s_benchmark/finite_impulse_response_filter/main.cpp b/gpu4s_benchmark/finite_impulse_response_filter/main.cpp index 70f8ddc8..eacc642e 100644 --- a/gpu4s_benchmark/finite_impulse_response_filter/main.cpp +++ b/gpu4s_benchmark/finite_impulse_response_filter/main.cpp @@ -34,6 +34,7 @@ int main(int argc, char *argv[]) // VARIABLES /////////////////////////////////////////////////////////////////////////////////////////////// // linearizable versions of matrix + // initialized to nullptr to prevent wild/dangling pointer references with UMA unsigned int size_matrix = arguments_parameters->size; unsigned int mem_size = sizeof(bench_t) * size_matrix; // A input matrix diff --git a/gpu4s_benchmark/matrix_multiplication_bench/main.cpp b/gpu4s_benchmark/matrix_multiplication_bench/main.cpp index 7784ac41..6f6262bb 100644 --- a/gpu4s_benchmark/matrix_multiplication_bench/main.cpp +++ b/gpu4s_benchmark/matrix_multiplication_bench/main.cpp @@ -35,6 +35,7 @@ int main(int argc, char *argv[]) unsigned int size_matrix = arguments_parameters->size * arguments_parameters->size; unsigned int mem_size = sizeof(bench_t) * size_matrix; // A input matrix + // initialized to nullptr to prevent wild/dangling pointer references with UMA bench_t* A = nullptr; // B input matrix bench_t* B = nullptr; diff --git a/gpu4s_benchmark/matrix_multiplication_bench_fp16/main.cpp b/gpu4s_benchmark/matrix_multiplication_bench_fp16/main.cpp index 84a6e438..2a168607 100644 --- a/gpu4s_benchmark/matrix_multiplication_bench_fp16/main.cpp +++ b/gpu4s_benchmark/matrix_multiplication_bench_fp16/main.cpp @@ -35,6 +35,7 @@ int main(int argc, char *argv[]){ unsigned int size_matrix = arguments_parameters->size * arguments_parameters->size; unsigned int mem_size = sizeof(bench_t) * size_matrix; // A input matrix + // initialized to nullptr to prevent wild/dangling pointer references with UMA bench_t* A = nullptr; // B input matrix bench_t* B = nullptr; diff --git a/gpu4s_benchmark/matrix_multiplication_tensor_bench/main.cpp b/gpu4s_benchmark/matrix_multiplication_tensor_bench/main.cpp index fa3b68f4..e1da713a 100644 --- a/gpu4s_benchmark/matrix_multiplication_tensor_bench/main.cpp +++ b/gpu4s_benchmark/matrix_multiplication_tensor_bench/main.cpp @@ -36,11 +36,12 @@ int main(int argc, char *argv[]){ unsigned int size_matrix = arguments_parameters->size * arguments_parameters->size; unsigned int mem_size = sizeof(bench_t) * size_matrix; // A input matrix - bench_t* A = (bench_t*) malloc(mem_size); + // initialized to nullptr to prevent wild/dangling pointer references with UMA + bench_t* A = nullptr; // B input matrix - bench_t* B = (bench_t*) malloc(mem_size); + bench_t* B = nullptr; // C matrix - bench_t* d_C = (bench_t*) malloc(mem_size); + bench_t* d_C = nullptr; bench_t* h_C = (bench_t*) malloc(mem_size); // init devices char device[100] = ""; diff --git a/gpu4s_benchmark/max_pooling_bench/main.cpp b/gpu4s_benchmark/max_pooling_bench/main.cpp index 25477e6e..c80bdfe4 100644 --- a/gpu4s_benchmark/max_pooling_bench/main.cpp +++ b/gpu4s_benchmark/max_pooling_bench/main.cpp @@ -34,6 +34,7 @@ int main(int argc, char *argv[]){ // A input matrix unsigned int size_A = arguments_parameters->size * arguments_parameters->size; unsigned int mem_size_A = sizeof(bench_t) * size_A; + // initialized to nullptr to prevent wild/dangling pointer references with UMA bench_t* A = nullptr; // B input matrix unsigned int size_lateral = arguments_parameters->size / arguments_parameters->stride; diff --git a/gpu4s_benchmark/memory_bandwidth_bench/main.cpp b/gpu4s_benchmark/memory_bandwidth_bench/main.cpp index 2c034671..f3fe07e5 100644 --- a/gpu4s_benchmark/memory_bandwidth_bench/main.cpp +++ b/gpu4s_benchmark/memory_bandwidth_bench/main.cpp @@ -37,9 +37,10 @@ int main(int argc, char *argv[]) unsigned int size_matrix = arguments_parameters->size * arguments_parameters->size; unsigned int mem_size = sizeof(bench_t) * size_matrix; // A input matrix - bench_t* A = (bench_t*) malloc(mem_size); + // initialized to nullptr to prevent wild/dangling pointer references with UMA + bench_t* A = nullptr; // B output matrix - bench_t* d_B = (bench_t*) malloc(mem_size); + bench_t* d_B = nullptr; bench_t* h_B = (bench_t*) malloc(mem_size); // init devices char device[100] = ""; diff --git a/gpu4s_benchmark/relu_bench/main.cpp b/gpu4s_benchmark/relu_bench/main.cpp index eca6fcd0..a0248dbf 100644 --- a/gpu4s_benchmark/relu_bench/main.cpp +++ b/gpu4s_benchmark/relu_bench/main.cpp @@ -35,6 +35,7 @@ int main(int argc, char *argv[]){ unsigned int size_matrix = arguments_parameters->size * arguments_parameters->size; unsigned int mem_size = sizeof(bench_t) * size_matrix; // A input matrix + // initialized to nullptr to prevent wild/dangling pointer references with UMA bench_t* A = nullptr; // B input matrix bench_t* d_B = nullptr; diff --git a/gpu4s_benchmark/softmax_bench/main.cpp b/gpu4s_benchmark/softmax_bench/main.cpp index 0788d523..6efd7a15 100644 --- a/gpu4s_benchmark/softmax_bench/main.cpp +++ b/gpu4s_benchmark/softmax_bench/main.cpp @@ -34,6 +34,7 @@ int main(int argc, char *argv[]){ unsigned int size_matrix = arguments_parameters->size * arguments_parameters->size; unsigned int mem_size = sizeof(bench_t) * size_matrix; // A input matrix + // initialized to nullptr to prevent wild/dangling pointer references with UMA bench_t* A = nullptr; // B input matrix bench_t* d_B = nullptr; diff --git a/gpu4s_benchmark/wavelet_transform/main.cpp b/gpu4s_benchmark/wavelet_transform/main.cpp index cb0b0b79..0e775d67 100644 --- a/gpu4s_benchmark/wavelet_transform/main.cpp +++ b/gpu4s_benchmark/wavelet_transform/main.cpp @@ -37,6 +37,7 @@ int main(int argc, char *argv[]){ unsigned int size_matrix = arguments_parameters->size; unsigned int mem_size = sizeof(bench_t) * size_matrix; // A input matrix + // initialized to nullptr to prevent wild/dangling pointer references with UMA bench_t* A = nullptr; // B input matrix bench_t* d_B = nullptr; From 057a8aafec9cad731d477d5d0837c8153b78216a Mon Sep 17 00:00:00 2001 From: Noah Perret Date: Fri, 14 Aug 2026 20:45:16 +0200 Subject: [PATCH 25/27] add comment for uma function in .h --- gpu4s_benchmark/cifar_10/benchmark_library.h | 35 +++++++++++- .../cifar_10_multiple/benchmark_library.h | 28 ++++++++++ gpu4s_benchmark/common/benchmark_common.h | 56 ++++++++++++++++--- .../convolution_2D_bench/benchmark_library.h | 16 ++++++ .../benchmark_library.h | 29 ++++++++++ .../opencl/lib_opencl.cpp | 2 +- .../wavelet_transform/benchmark_library.h | 30 +++++++++- 7 files changed, 181 insertions(+), 15 deletions(-) diff --git a/gpu4s_benchmark/cifar_10/benchmark_library.h b/gpu4s_benchmark/cifar_10/benchmark_library.h index 488fd76d..38809500 100644 --- a/gpu4s_benchmark/cifar_10/benchmark_library.h +++ b/gpu4s_benchmark/cifar_10/benchmark_library.h @@ -121,6 +121,35 @@ void copy_memory_to_device(GraficCommon* device_object, bench_t* input_data, ben void execute_kernel(GraficCommon* device_object, unsigned int input_data, unsigned int output_data, unsigned int kernel_1, unsigned int kernel_2, unsigned int stride_1, unsigned int stride_2, unsigned int neurons_dense_1, unsigned int neurons_dense_2); #ifdef UMA_COMPATIBILITY -void get_unified_memory_pointers(GraficCommon* device_object,bench_t* &input_data, unsigned int input_mem_size,bench_t* &kernel_1, bench_t* &kernel_2, unsigned int kernel_mem_size, bench_t* &weights_1, unsigned int weights_1_mem_size, bench_t* &weights_2, unsigned int weights_2_mem_size, bench_t* &d_output, unsigned int output_mem_size); -void sync_unified_memory_to_device(GraficCommon* device_object, bench_t* &input_data, bench_t* &kernel_1, bench_t* &kernel_2, bench_t* &weights_1, bench_t* &weights_2, bench_t* &d_output); -#endif \ No newline at end of file + +// --- 5 buffer, mixed sizes (cifar_10_multiple) --- + /** + * @brief Maps cifar's five input buffers and its output buffer into host-visible memory. + * Unlike the equal-sized overloads, each buffer here has its own byte size - + * there's no single shared memSize. + * @param device_object Pointer to the device common structure + * @param input_data Reference to receive the mapped input host pointer + * @param input_mem_size Size of input_data, in bytes + * @param kernel_1 Reference to receive the mapped first conv kernel host pointer + * @param kernel_2 Reference to receive the mapped second conv kernel host pointer + * @param kernel_mem_size Size of EACH kernel buffer, in bytes - kernel_1 and kernel_2 share this one size + * @param weights_1 Reference to receive the mapped dense-layer-1 weights host pointer + * @param weights_1_mem_size Size of weights_1, in bytes + * @param weights_2 Reference to receive the mapped dense-layer-2 weights host pointer + * @param weights_2_mem_size Size of weights_2, in bytes + * @param d_output Reference to receive the mapped output host pointer + * @param output_mem_size Size of d_output, in bytes + */ + void get_unified_memory_pointers(GraficCommon* device_object, bench_t* &input_data, unsigned int input_mem_size, bench_t* &kernel_1, bench_t* &kernel_2, unsigned int kernel_mem_size, bench_t* &weights_1, unsigned int weights_1_mem_size, bench_t* &weights_2, unsigned int weights_2_mem_size, bench_t* &d_output, unsigned int output_mem_size); + /** + * @brief Unmaps all six cifar buffers, blocked for host until the device give aigain ownership . + * @param device_object Pointer to the device common structure + * @param input_data Reference to the mapped input host pointer to unmap + * @param kernel_1 Reference to the mapped first conv kernel host pointer to unmap + * @param kernel_2 Reference to the mapped second conv kernel host pointer to unmap + * @param weights_1 Reference to the mapped dense-layer-1 weights host pointer to unmap + * @param weights_2 Reference to the mapped dense-layer-2 weights host pointer to unmap + * @param d_output Reference to the mapped output host pointer to unmap + */ + void sync_unified_memory_to_device(GraficCommon* device_object, bench_t* &input_data, bench_t* &kernel_1, bench_t* &kernel_2, bench_t* &weights_1, bench_t* &weights_2, bench_t* &d_output); +#endif diff --git a/gpu4s_benchmark/cifar_10_multiple/benchmark_library.h b/gpu4s_benchmark/cifar_10_multiple/benchmark_library.h index f8e69b8f..55e5a3ce 100644 --- a/gpu4s_benchmark/cifar_10_multiple/benchmark_library.h +++ b/gpu4s_benchmark/cifar_10_multiple/benchmark_library.h @@ -122,5 +122,33 @@ void copy_memory_to_host(GraficCommon* device_object, bench_t* h_C, int size, un #ifdef UMA_COMPATIBILITY void get_unified_memory_pointers(GraficCommon* device_object,bench_t* &input_data, unsigned int input_mem_size,bench_t* &kernel_1, bench_t* &kernel_2, unsigned int kernel_mem_size, bench_t* &weights_1, unsigned int weights_1_mem_size, bench_t* &weights_2, unsigned int weights_2_mem_size, bench_t* &d_output, unsigned int output_mem_size); +/** + * @brief Maps cifar's five input buffers and its output buffer into host-visible memory. + * Unlike the equal-sized overloads above, each buffer here has its own byte size - + * there's no single shared memSize. + * @param device_object Pointer to the device common structure + * @param input_data Reference to receive the mapped input host pointer + * @param input_mem_size Size of input_data, in bytes + * @param kernel_1 Reference to receive the mapped first conv kernel host pointer + * @param kernel_2 Reference to receive the mapped second conv kernel host pointer + * @param kernel_mem_size Size of EACH kernel buffer, in bytes - kernel_1 and kernel_2 share this one size + * @param weights_1 Reference to receive the mapped dense-layer-1 weights host pointer + * @param weights_1_mem_size Size of weights_1, in bytes + * @param weights_2 Reference to receive the mapped dense-layer-2 weights host pointer + * @param weights_2_mem_size Size of weights_2, in bytes + * @param d_output Reference to receive the mapped output host pointer + * @param output_mem_size Size of d_output, in bytes + */ +void get_unified_memory_pointers(GraficCommon* device_object, bench_t* &input_data, unsigned int input_mem_size, bench_t* &kernel_1, bench_t* &kernel_2, unsigned int kernel_mem_size, bench_t* &weights_1, unsigned int weights_1_mem_size, bench_t* &weights_2, unsigned int weights_2_mem_size, bench_t* &d_output, unsigned int output_mem_size); +/** + * @brief Unmaps all six cifar buffers, blocked for host until the device give aigain ownership . + * @param device_object Pointer to the device common structure + * @param input_data Reference to the mapped input host pointer to unmap + * @param kernel_1 Reference to the mapped first conv kernel host pointer to unmap + * @param kernel_2 Reference to the mapped second conv kernel host pointer to unmap + * @param weights_1 Reference to the mapped dense-layer-1 weights host pointer to unmap + * @param weights_2 Reference to the mapped dense-layer-2 weights host pointer to unmap + * @param d_output Reference to the mapped output host pointer to unmap + */ void sync_unified_memory_to_device(GraficCommon* device_object, bench_t* &input_data, bench_t* &kernel_1, bench_t* &kernel_2, bench_t* &weights_1, bench_t* &weights_2, bench_t* &d_output); #endif \ No newline at end of file diff --git a/gpu4s_benchmark/common/benchmark_common.h b/gpu4s_benchmark/common/benchmark_common.h index 4e26100c..489fcf13 100644 --- a/gpu4s_benchmark/common/benchmark_common.h +++ b/gpu4s_benchmark/common/benchmark_common.h @@ -161,27 +161,65 @@ float get_elapsed_time(GraficCommon *device_object, bool csv_format, bool csv_fo void clean(GraficCommon *device_object); -// --- UMA memory function --- +/// --- UMA memory function --- #ifdef UMA_COMPATIBILITY + // --- 1 buffer --- + /** + * @brief Maps one device buffer into host-visible memory (blocking write-map). + * @param device_object Pointer to the device common structure + * @param A Reference to receive the mapped host pointer + * @param memSize Size of the buffer to map, in bytes + */ void get_unified_memory_pointers(GraficCommon* device_object, bench_t* &A, unsigned int memSize); + /** + * @brief Unmaps a single buffer, blocking until the device regains ownership. + * @param device_object Pointer to the device common structure + * @param A Reference to the mapped host pointer to unmap + */ void sync_unified_memory_to_device(GraficCommon* device_object, bench_t* &A); // --- 2 buffer --- + /** + * @brief Maps two equal-sized device buffers into host-visible memory + * @param device_object Pointer to the device common structure + * @param A Reference to receive the first mapped host pointer + * @param B Reference to receive the second mapped host pointer + * @param memSize Size of EACH buffer to map, in bytes - both buffers share this one size + */ void get_unified_memory_pointers(GraficCommon* device_object, bench_t* &A, bench_t* &B, unsigned int memSize); + /** + * @brief Unmaps two buffers, blocked for host until the device give aigain ownership + * @param device_object Pointer to the device common structure + * @param A Reference to the first mapped host pointer to unmap + * @param B Reference to the second mapped host pointer to unmap + */ void sync_unified_memory_to_device(GraficCommon* device_object, bench_t* &A, bench_t* &B); // --- 3 buffer --- + /** + * @brief Maps three equal-sized device buffers into host-visible memory + * @param device_object Pointer to the device common structure + * @param A Reference to receive the first mapped host pointer + * @param B Reference to receive the second mapped host pointer + * @param C Reference to receive the third mapped host pointer + * @param memSize Size of EACH buffer, in bytes. + */ void get_unified_memory_pointers(GraficCommon* device_object, bench_t* &A, bench_t* &B, bench_t* &C, unsigned int memSize); + /** + * @brief Unmaps three buffers, blocked for host until the device give aigain ownership + * @param device_object Pointer to the device common structure + * @param A Reference to the first mapped host pointer to unmap + * @param B Reference to the second mapped host pointer to unmap + * @param C Reference to the third mapped host pointer to unmap + */ void sync_unified_memory_to_device(GraficCommon* device_object, bench_t* &A, bench_t* &B, bench_t* &C); - // --- 3 buffer + 2 size --- - void get_unified_memory_pointers(GraficCommon* device_object, bench_t* &A, bench_t* &B, bench_t* &C, unsigned int memSize, unsigned int memSize2); - - // --- 3 buffer + 3 size --- - void get_unified_memory_pointers(GraficCommon* device_object, bench_t* &A, bench_t* &B, bench_t* &C, unsigned memSize, unsigned memSize2, unsigned memSize3); - - // --- common --- + /** + * @brief Maps output result buffer back to host + * @param device_object Pointer to the device common structure + * @param d_output Reference to receive the mapped host pointer + * @param memSize Size of the buffer to map, in bytes + */ void sync_unified_memory_to_host(GraficCommon* device_object, bench_t* &d_output, unsigned int memSize); - #endif \ No newline at end of file diff --git a/gpu4s_benchmark/convolution_2D_bench/benchmark_library.h b/gpu4s_benchmark/convolution_2D_bench/benchmark_library.h index 425d6fc5..d7cf804d 100644 --- a/gpu4s_benchmark/convolution_2D_bench/benchmark_library.h +++ b/gpu4s_benchmark/convolution_2D_bench/benchmark_library.h @@ -54,3 +54,19 @@ struct GraficObject : public GraficCommon { // --- Specefic overload of benchmarking function --- void execute_kernel(GraficCommon* device_object, unsigned int n, unsigned int m, unsigned int w, unsigned int kernel_size); + +// --- UMA memory function --- +#ifdef UMA_COMPATIBILITY +// --- 3 buffer, 2 sizes +/** + * @brief Maps three device buffers into host-visible memory across two distinct sizes. + * + * @param device_object Pointer to the device common structure + * @param A Reference to receive the mapped host pointer for d_A (sized memSize) + * @param B Reference to receive the mapped host pointer for kernel (sized memSize2, NOT memSize) + * @param C Reference to receive the mapped host pointer for d_B (sized memSize, same as A) + * @param memSize Size shared by A and C, in bytes + * @param memSize2 Size of B alone, in bytes + */ +void get_unified_memory_pointers(GraficCommon* device_object, bench_t* &A, bench_t* &B, bench_t* &C, unsigned int memSize, unsigned int memSize2); +#endif \ No newline at end of file diff --git a/gpu4s_benchmark/finite_impulse_response_filter/benchmark_library.h b/gpu4s_benchmark/finite_impulse_response_filter/benchmark_library.h index 33c58011..7f959815 100644 --- a/gpu4s_benchmark/finite_impulse_response_filter/benchmark_library.h +++ b/gpu4s_benchmark/finite_impulse_response_filter/benchmark_library.h @@ -47,3 +47,32 @@ struct GraficObject : public GraficCommon { // --- Specefic overload of benchmarking function --- void execute_kernel(GraficCommon* device_object, unsigned int n, unsigned int m, unsigned int w, unsigned int kernel_size); + + +#ifdef UMA_COMPATIBILITY + +// --- 3 buffer, 3 sizes --- +/** + * @brief Maps three device buffers of three independent sizes into host-visible memory + * + * @param device_object Pointer to the device common structure + * @param A Reference to receive the mapped input host pointer (d_A) + * @param B Reference to receive the mapped kernel-weights host pointer (kernel) + * @param C Reference to receive the mapped output host pointer (d_B) + * @param memSize Size of A, in bytes + * @param memSize2 Size of B, in bytes + * @param memSize3 Size of C, in bytes + */ +void get_unified_memory_pointers(GraficCommon* device_object, bench_t* &A, bench_t* &B, bench_t* &C, unsigned memSize, unsigned memSize2, unsigned memSize3); + +/** + * @brief Unmaps all three buffers, blocked for host until the device give aigain ownership + * + * @param device_object Pointer to the device common structure + * @param A Reference to the mapped input host pointer to unmap + * @param B Reference to the mapped kernel-weights host pointer to unmap + * @param C Reference to the mapped output host pointer to unmap + */ +void sync_unified_memory_to_device(GraficCommon* device_object, bench_t* &A, bench_t* &B, bench_t* &C); + +#endif \ No newline at end of file diff --git a/gpu4s_benchmark/finite_impulse_response_filter/opencl/lib_opencl.cpp b/gpu4s_benchmark/finite_impulse_response_filter/opencl/lib_opencl.cpp index 346c1e0e..f5fcf4a5 100644 --- a/gpu4s_benchmark/finite_impulse_response_filter/opencl/lib_opencl.cpp +++ b/gpu4s_benchmark/finite_impulse_response_filter/opencl/lib_opencl.cpp @@ -247,7 +247,7 @@ void sync_unified_memory_to_host(GraficCommon* device_object, bench_t* &d_output GraficObject* deviceObj = static_cast(device_object); // --- Call the openCL common function --- map_unified_memory_to_host(device_object, memSize, - BufferMapCL{&d_output, deviceObj->d_B, deviceObj->evt_copyB} + BufferMapCL{&d_output, deviceObj->d_B, deviceObj->evt_copyC} ); } diff --git a/gpu4s_benchmark/wavelet_transform/benchmark_library.h b/gpu4s_benchmark/wavelet_transform/benchmark_library.h index aa7e557c..52354fd8 100644 --- a/gpu4s_benchmark/wavelet_transform/benchmark_library.h +++ b/gpu4s_benchmark/wavelet_transform/benchmark_library.h @@ -70,8 +70,34 @@ struct GraficObject : public GraficCommon { #endif }; + + // --- Specefic overload of benchmarking function --- #ifdef UMA_COMPATIBILITY - void get_unified_memory_pointers(GraficCommon* device_object, bench_t* &A, bench_t* &B, bench_t* &C, bench_t* &D, unsigned int memSize); - void sync_unified_memory_to_device(GraficCommon* device_object, bench_t* &A, bench_t* &B, bench_t* &C, bench_t* &D); +// --- 4 buffer, 1 shared size + 2 conditional (wavelet_transform) --- + /** + * @brief Maps input/output (A -> d_A, B -> d_B, both sized memSize) plus, in FLOAT/DOUBLE + * builds only, two filter buffers (C -> low_filter, sized + * LOWPASSFILTERSIZE; D -> high_filter, sized HIGHPASSFILTERSIZE). + + * @param device_object Pointer to the device common structure + * @param A Reference to receive the mapped input host pointer (d_A) + * @param B Reference to receive the mapped output host pointer (d_B) + * @param C Reference to receive the mapped lowpass-filter host pointer (low_filter); unused under INT + * @param D Reference to receive the mapped highpass-filter host pointer (high_filter); unused under INT + * @param memSize Size shared by A and B, in bytes. C and D use their own fixed + * LOWPASSFILTERSIZE/HIGHPASSFILTERSIZE internally, not this parameter. + */ + void get_unified_memory_pointers(GraficCommon* device_object, bench_t* &A, bench_t* &B, bench_t* &C, bench_t* &D, unsigned int memSize); + /** + * @brief Unmaps A, B, and (FLOAT/DOUBLE builds only) C and D, blocking until the device + * regains ownership of each. + * + * @param device_object Pointer to the device common structure + * @param A Reference to the mapped input host pointer to unmap + * @param B Reference to the mapped output host pointer to unmap + * @param C Reference to the mapped lowpass-filter host pointer to unmap; unused under INT + * @param D Reference to the mapped highpass-filter host pointer to unmap; unused under INT + */ + void sync_unified_memory_to_device(GraficCommon* device_object, bench_t* &A, bench_t* &B, bench_t* &C, bench_t* &D); #endif \ No newline at end of file From 713e5876bd1a5b367d4541f05d6c795319262d0e Mon Sep 17 00:00:00 2001 From: Noah Perret Date: Mon, 17 Aug 2026 10:28:27 +0200 Subject: [PATCH 26/27] improve comment for UMA --- .../LRN_bench/opencl/lib_opencl_common.cpp | 4 +- .../cifar_10/opencl/lib_opencl_common.cpp | 4 +- .../opencl/lib_opencl_common.cpp | 4 +- gpu4s_benchmark/common/benchmark_common.h | 6 +-- .../convolution_2D_bench/benchmark_library.h | 12 ++--- .../opencl/lib_opencl_common.cpp | 10 ++-- .../opencl/lib_opencl_common.cpp | 2 +- .../benchmark_library.h | 33 +++++++++++-- .../opencl/lib_opencl_lib.cpp | 9 ++-- .../opencl/lib_opencl_common.cpp | 4 +- .../opencl/lib_opencl_common.cpp | 4 +- .../benchmark_library.h | 4 +- .../opencl/lib_opencl.cpp | 12 ++--- .../opencl/lib_opencl_common.cpp | 4 +- .../opencl/lib_opencl_common.cpp | 4 +- .../opencl/lib_opencl_common.cpp | 4 +- .../opencl/lib_opencl_common.cpp | 4 +- .../opencl/lib_opencl.cpp | 4 +- .../relu_bench/opencl/lib_opencl_common.cpp | 4 +- .../wavelet_transform/benchmark_library.h | 49 +++++++++---------- .../wavelet_transform/opencl/lib_opencl.cpp | 8 +-- 21 files changed, 106 insertions(+), 83 deletions(-) diff --git a/gpu4s_benchmark/LRN_bench/opencl/lib_opencl_common.cpp b/gpu4s_benchmark/LRN_bench/opencl/lib_opencl_common.cpp index 86b56203..19c2c85c 100644 --- a/gpu4s_benchmark/LRN_bench/opencl/lib_opencl_common.cpp +++ b/gpu4s_benchmark/LRN_bench/opencl/lib_opencl_common.cpp @@ -167,10 +167,10 @@ void sync_unified_memory_to_device(GraficCommon* device_object, bench_t* &A, ben } -void sync_unified_memory_to_host(GraficCommon* device_object, bench_t* &d_output, unsigned int memSize){ +void sync_unified_memory_to_host(GraficCommon* device_object, bench_t* &d_output, unsigned int size_output){ GraficObject* deviceObj = static_cast(device_object); // --- Call the openCL common function --- - map_unified_memory_to_host(device_object, memSize, + map_unified_memory_to_host(device_object, size_output, BufferMapCL{&d_output, deviceObj->d_B, deviceObj->evt_copyB} ); } diff --git a/gpu4s_benchmark/cifar_10/opencl/lib_opencl_common.cpp b/gpu4s_benchmark/cifar_10/opencl/lib_opencl_common.cpp index 0b3f0af8..bb0864c8 100644 --- a/gpu4s_benchmark/cifar_10/opencl/lib_opencl_common.cpp +++ b/gpu4s_benchmark/cifar_10/opencl/lib_opencl_common.cpp @@ -311,10 +311,10 @@ void sync_unified_memory_to_device(GraficCommon* device_object, bench_t* &input_ ); } -void sync_unified_memory_to_host(GraficCommon* device_object, bench_t* &d_output, unsigned int memSize){ +void sync_unified_memory_to_host(GraficCommon* device_object, bench_t* &d_output, unsigned int size_output){ GraficObject* deviceObj = static_cast(device_object); // --- Call the openCL common function --- - map_unified_memory_to_host(device_object, memSize, + map_unified_memory_to_host(device_object, size_output, BufferMapCL{&d_output, deviceObj->output_data, deviceObj->evt_copyOut} ); } diff --git a/gpu4s_benchmark/cifar_10_multiple/opencl/lib_opencl_common.cpp b/gpu4s_benchmark/cifar_10_multiple/opencl/lib_opencl_common.cpp index dfd18d8d..51685da8 100644 --- a/gpu4s_benchmark/cifar_10_multiple/opencl/lib_opencl_common.cpp +++ b/gpu4s_benchmark/cifar_10_multiple/opencl/lib_opencl_common.cpp @@ -304,10 +304,10 @@ void sync_unified_memory_to_device(GraficCommon* device_object, bench_t* &input_ ); } -void sync_unified_memory_to_host(GraficCommon* device_object, bench_t* &d_output, unsigned int memSize){ +void sync_unified_memory_to_host(GraficCommon* device_object, bench_t* &d_output, unsigned int size_output){ GraficObject* deviceObj = static_cast(device_object); // --- Call the openCL common function --- - map_unified_memory_to_host(device_object, memSize, + map_unified_memory_to_host(device_object, size_output, BufferMapCL{&d_output, deviceObj->output_data, deviceObj->evt_copyOut} ); } diff --git a/gpu4s_benchmark/common/benchmark_common.h b/gpu4s_benchmark/common/benchmark_common.h index 489fcf13..cea91d1e 100644 --- a/gpu4s_benchmark/common/benchmark_common.h +++ b/gpu4s_benchmark/common/benchmark_common.h @@ -218,8 +218,8 @@ void clean(GraficCommon *device_object); /** * @brief Maps output result buffer back to host * @param device_object Pointer to the device common structure - * @param d_output Reference to receive the mapped host pointer - * @param memSize Size of the buffer to map, in bytes + * @param d_output Reference to receive the mapped output host pointer + * @param size_output Size of the output buffer to map, in bytes */ - void sync_unified_memory_to_host(GraficCommon* device_object, bench_t* &d_output, unsigned int memSize); + void sync_unified_memory_to_host(GraficCommon* device_object, bench_t* &d_output, unsigned int size_output); #endif \ No newline at end of file diff --git a/gpu4s_benchmark/convolution_2D_bench/benchmark_library.h b/gpu4s_benchmark/convolution_2D_bench/benchmark_library.h index d7cf804d..2ea6947d 100644 --- a/gpu4s_benchmark/convolution_2D_bench/benchmark_library.h +++ b/gpu4s_benchmark/convolution_2D_bench/benchmark_library.h @@ -62,11 +62,11 @@ void execute_kernel(GraficCommon* device_object, unsigned int n, unsigned int m, * @brief Maps three device buffers into host-visible memory across two distinct sizes. * * @param device_object Pointer to the device common structure - * @param A Reference to receive the mapped host pointer for d_A (sized memSize) - * @param B Reference to receive the mapped host pointer for kernel (sized memSize2, NOT memSize) - * @param C Reference to receive the mapped host pointer for d_B (sized memSize, same as A) - * @param memSize Size shared by A and C, in bytes - * @param memSize2 Size of B alone, in bytes + * @param A Reference to receive the mapped host pointer for d_A (sized sizeAC) + * @param B Reference to receive the mapped host pointer for kernel (sized sizeB) + * @param C Reference to receive the mapped host pointer for d_B (sized sizeAC, same as A) + * @param sizeAC Size shared by A and C, in bytes + * @param sizeB Size of B alone, in bytes */ -void get_unified_memory_pointers(GraficCommon* device_object, bench_t* &A, bench_t* &B, bench_t* &C, unsigned int memSize, unsigned int memSize2); +void get_unified_memory_pointers(GraficCommon* device_object, bench_t* &A, bench_t* &B, bench_t* &C, unsigned int sizeAC, unsigned int sizeB); #endif \ No newline at end of file diff --git a/gpu4s_benchmark/convolution_2D_bench/opencl/lib_opencl_common.cpp b/gpu4s_benchmark/convolution_2D_bench/opencl/lib_opencl_common.cpp index 626f8cd5..1ff5d148 100644 --- a/gpu4s_benchmark/convolution_2D_bench/opencl/lib_opencl_common.cpp +++ b/gpu4s_benchmark/convolution_2D_bench/opencl/lib_opencl_common.cpp @@ -158,15 +158,15 @@ void clean(GraficCommon* device_object){ #ifdef UMA_COMPATIBILITY // ====== UMA function ====== -void get_unified_memory_pointers(GraficCommon* device_object, bench_t* &A, bench_t* &B, bench_t* &C, unsigned int memSize, unsigned int memSize2){ +void get_unified_memory_pointers(GraficCommon* device_object, bench_t* &A, bench_t* &B, bench_t* &C, unsigned int sizeAC, unsigned int sizeB){ GraficObject* deviceObj = static_cast(device_object); // --- Call the openCL common function --- - map_unified_memory(device_object, memSize, + map_unified_memory(device_object, sizeAC, BufferMapCL{&A, deviceObj->d_A, nullptr}, BufferMapCL{&C, deviceObj->d_B, nullptr} ); - map_unified_memory(device_object, memSize2, + map_unified_memory(device_object, sizeB, BufferMapCL{&B, deviceObj->kernel, nullptr} ); } @@ -182,10 +182,10 @@ void sync_unified_memory_to_device(GraficCommon* device_object, bench_t* &A, ben } -void sync_unified_memory_to_host(GraficCommon* device_object, bench_t* &d_output, unsigned int memSize){ +void sync_unified_memory_to_host(GraficCommon* device_object, bench_t* &d_output, unsigned int size_output){ GraficObject* deviceObj = static_cast(device_object); // --- Call the openCL common function --- - map_unified_memory_to_host(device_object, memSize, + map_unified_memory_to_host(device_object, size_output, BufferMapCL{&d_output, deviceObj->d_B, deviceObj->evt_copyB} ); } diff --git a/gpu4s_benchmark/correlation_2D/opencl/lib_opencl_common.cpp b/gpu4s_benchmark/correlation_2D/opencl/lib_opencl_common.cpp index e7b81ab1..01a1dfc2 100644 --- a/gpu4s_benchmark/correlation_2D/opencl/lib_opencl_common.cpp +++ b/gpu4s_benchmark/correlation_2D/opencl/lib_opencl_common.cpp @@ -221,7 +221,7 @@ void sync_unified_memory_to_device(GraficCommon* device_object, bench_t* &A, ben } -void sync_unified_memory_to_host(GraficCommon* device_object, bench_t* &d_output, unsigned int memSize){ +void sync_unified_memory_to_host(GraficCommon* device_object, bench_t* &d_output, unsigned int size_output){ GraficObject* deviceObj = static_cast(device_object); bench_t* tmp_aa = nullptr; diff --git a/gpu4s_benchmark/fast_fourier_transform_2D_bench/benchmark_library.h b/gpu4s_benchmark/fast_fourier_transform_2D_bench/benchmark_library.h index 65541e89..7662dbcd 100644 --- a/gpu4s_benchmark/fast_fourier_transform_2D_bench/benchmark_library.h +++ b/gpu4s_benchmark/fast_fourier_transform_2D_bench/benchmark_library.h @@ -60,7 +60,34 @@ void copy_memory_to_host(GraficCommon* device_object, COMPLEX **h_B, int64_t siz #ifdef UMA_COMPATIBILITY -void get_unified_memory_pointers(GraficCommon* device_object, COMPLEX** &A, COMPLEX** &B, int64_t memSize); -void sync_unified_memory_to_device(GraficCommon* device_object, COMPLEX** &A, COMPLEX** &B, int64_t memSize); -void sync_unified_memory_to_host(GraficCommon* device_object, COMPLEX** &d_output, int64_t memSize); + /** + * @brief Maps the flat d_A/d_B device buffers into host-visible memory, then reconnects + * A[i]/B[i] row pointers into that single contiguous mapped block (2D COMPLEX** + * to 1D flat buffer). + * + * @param device_object Pointer to the device common structure + * @param A Reference to the row-pointer array to reconnect over the mapped input buffer + * @param B Reference to the row-pointer array to reconnect over the mapped output buffer + * @param memSize N - the FFT side length (rows == cols), NOT a byte size + */ + + void get_unified_memory_pointers(GraficCommon* device_object, COMPLEX** &A, COMPLEX** &B, int64_t memSize); + /** + * @brief Unmaps d_A/d_B, blocked for host until the device give aigain ownership + * + * @param device_object Pointer to the device common structure + * @param A Reference to the row-pointer array whose A[0] gives the mapped pointer to unmap + * @param B Reference to the row-pointer array whose B[0] gives the mapped pointer to unmap + */ + void sync_unified_memory_to_device(GraficCommon* device_object, COMPLEX** &A, COMPLEX** &B, int64_t memSize); + /** + * @brief Maps d_B back to a host-readable pointer, then reconnects d_output[i] row + * pointers into that mapped block, same N-based reasoning as + * get_unified_memory_pointers above. + * + * @param device_object Pointer to the device common structure + * @param d_output Reference to the row-pointer array to reconnect over the mapped output buffer + * @param memSize N - the FFT side length (rows == cols), NOT a byte size + */ + void sync_unified_memory_to_host(GraficCommon* device_object, COMPLEX** &d_output, int64_t memSize); #endif \ No newline at end of file diff --git a/gpu4s_benchmark/fast_fourier_transform_2D_bench/opencl/lib_opencl_lib.cpp b/gpu4s_benchmark/fast_fourier_transform_2D_bench/opencl/lib_opencl_lib.cpp index a2ad0c15..6ac540e5 100644 --- a/gpu4s_benchmark/fast_fourier_transform_2D_bench/opencl/lib_opencl_lib.cpp +++ b/gpu4s_benchmark/fast_fourier_transform_2D_bench/opencl/lib_opencl_lib.cpp @@ -221,7 +221,7 @@ void get_unified_memory_pointers(GraficCommon* device_object, COMPLEX** &A, COMP GraficObject* deviceObj = static_cast(device_object); int64_t flatSize = sizeof(bench_t) * memSize * memSize * 2; - // Map temp flat buffer + //Map temp 2D buffer bench_t* tmp_flat_A = nullptr; bench_t* tmp_flat_B = nullptr; @@ -243,7 +243,7 @@ void get_unified_memory_pointers(GraficCommon* device_object, COMPLEX** &A, COMP } } -void sync_unified_memory_to_device(GraficCommon* device_object, COMPLEX** &A, COMPLEX** &B, int64_t memSize){ +void sync_unified_memory_to_device(GraficCommon* device_object, COMPLEX** &A, COMPLEX** &B){ GraficObject* deviceObj = static_cast(device_object); bench_t* tmp_flat_A = (bench_t*)A[0]; @@ -260,7 +260,6 @@ void sync_unified_memory_to_device(GraficCommon* device_object, COMPLEX** &A, CO void sync_unified_memory_to_host(GraficCommon* device_object, COMPLEX** &d_output, int64_t memSize){ GraficObject* deviceObj = static_cast(device_object); int64_t flatSize = sizeof(bench_t) * memSize * memSize * 2; - bench_t* tmp_flat_B = nullptr; // --- Call the openCL common function --- @@ -268,10 +267,10 @@ void sync_unified_memory_to_host(GraficCommon* device_object, COMPLEX** &d_outpu BufferMapCL{&tmp_flat_B, deviceObj->d_B, deviceObj->evt_copyB} ); - // --- Cast back to bench_t --- + // --- Cast back to 2D complex buffer --- COMPLEX* flat_B = (COMPLEX*)tmp_flat_B; - // Reconnect the 2D pointer array to the newly mapped output memory + // Reconnect to 2D pointer array to the newly mapped output memory for (int i = 0; i < memSize; ++i){ d_output[i] = flat_B + (i * memSize); } diff --git a/gpu4s_benchmark/fast_fourier_transform_bench/opencl/lib_opencl_common.cpp b/gpu4s_benchmark/fast_fourier_transform_bench/opencl/lib_opencl_common.cpp index 31c23a48..36382f02 100644 --- a/gpu4s_benchmark/fast_fourier_transform_bench/opencl/lib_opencl_common.cpp +++ b/gpu4s_benchmark/fast_fourier_transform_bench/opencl/lib_opencl_common.cpp @@ -169,10 +169,10 @@ void sync_unified_memory_to_device(GraficCommon* device_object, bench_t* &A){ } -void sync_unified_memory_to_host(GraficCommon* device_object, bench_t* &d_output, unsigned int memSize){ +void sync_unified_memory_to_host(GraficCommon* device_object, bench_t* &d_output, unsigned int size_output){ GraficObject* deviceObj = static_cast(device_object); // --- Call the openCL common function --- - map_unified_memory_to_host(device_object, memSize, + map_unified_memory_to_host(device_object, size_output, BufferMapCL{&d_output, deviceObj->d_Br, deviceObj->evt_copyBr} ); } diff --git a/gpu4s_benchmark/fast_fourier_transform_window_bench/opencl/lib_opencl_common.cpp b/gpu4s_benchmark/fast_fourier_transform_window_bench/opencl/lib_opencl_common.cpp index 44f6d0ef..e3c07a73 100644 --- a/gpu4s_benchmark/fast_fourier_transform_window_bench/opencl/lib_opencl_common.cpp +++ b/gpu4s_benchmark/fast_fourier_transform_window_bench/opencl/lib_opencl_common.cpp @@ -164,10 +164,10 @@ void sync_unified_memory_to_device(GraficCommon* device_object, bench_t* &A){ } -void sync_unified_memory_to_host(GraficCommon* device_object, bench_t* &d_output, unsigned int memSize){ +void sync_unified_memory_to_host(GraficCommon* device_object, bench_t* &d_output, unsigned int size_output){ GraficObject* deviceObj = static_cast(device_object); // --- Call the openCL common function --- - map_unified_memory_to_host(device_object, memSize, + map_unified_memory_to_host(device_object, size_output, BufferMapCL{&d_output, deviceObj->d_B, deviceObj->evt_copyB} ); } diff --git a/gpu4s_benchmark/finite_impulse_response_filter/benchmark_library.h b/gpu4s_benchmark/finite_impulse_response_filter/benchmark_library.h index 7f959815..cb084c72 100644 --- a/gpu4s_benchmark/finite_impulse_response_filter/benchmark_library.h +++ b/gpu4s_benchmark/finite_impulse_response_filter/benchmark_library.h @@ -50,8 +50,6 @@ void execute_kernel(GraficCommon* device_object, unsigned int n, unsigned int m, #ifdef UMA_COMPATIBILITY - -// --- 3 buffer, 3 sizes --- /** * @brief Maps three device buffers of three independent sizes into host-visible memory * @@ -63,7 +61,7 @@ void execute_kernel(GraficCommon* device_object, unsigned int n, unsigned int m, * @param memSize2 Size of B, in bytes * @param memSize3 Size of C, in bytes */ -void get_unified_memory_pointers(GraficCommon* device_object, bench_t* &A, bench_t* &B, bench_t* &C, unsigned memSize, unsigned memSize2, unsigned memSize3); +void get_unified_memory_pointers(GraficCommon* device_object, bench_t* &A, bench_t* &B, bench_t* &C, unsigned sizeA, unsigned sizeB, unsigned sizeC); /** * @brief Unmaps all three buffers, blocked for host until the device give aigain ownership diff --git a/gpu4s_benchmark/finite_impulse_response_filter/opencl/lib_opencl.cpp b/gpu4s_benchmark/finite_impulse_response_filter/opencl/lib_opencl.cpp index f5fcf4a5..d7cc2d18 100644 --- a/gpu4s_benchmark/finite_impulse_response_filter/opencl/lib_opencl.cpp +++ b/gpu4s_benchmark/finite_impulse_response_filter/opencl/lib_opencl.cpp @@ -213,21 +213,21 @@ void clean(GraficCommon* device_object){ #ifdef UMA_COMPATIBILITY // ====== UMA function ====== -void get_unified_memory_pointers(GraficCommon* device_object, bench_t* &A, bench_t* &B, bench_t* &C, unsigned memSize, unsigned memSize2, unsigned memSize3){ +void get_unified_memory_pointers(GraficCommon* device_object, bench_t* &A, bench_t* &B, bench_t* &C, unsigned sizeA, unsigned sizeB, unsigned sizeC){ GraficObject* deviceObj = static_cast(device_object); // --- Call the openCL common function --- // input - map_unified_memory(device_object, memSize, + map_unified_memory(device_object, sizeA, BufferMapCL{&A, deviceObj->d_A, nullptr} ); // kernel - map_unified_memory(device_object, memSize2, + map_unified_memory(device_object, sizeB, BufferMapCL{&B, deviceObj->kernel, nullptr} ); // output - map_unified_memory(device_object, memSize3, + map_unified_memory(device_object, sizeC, BufferMapCL{&C, deviceObj->d_B, nullptr} ); } @@ -243,10 +243,10 @@ void sync_unified_memory_to_device(GraficCommon* device_object, bench_t* &A, ben } -void sync_unified_memory_to_host(GraficCommon* device_object, bench_t* &d_output, unsigned int memSize){ +void sync_unified_memory_to_host(GraficCommon* device_object, bench_t* &d_output, unsigned int size_output){ GraficObject* deviceObj = static_cast(device_object); // --- Call the openCL common function --- - map_unified_memory_to_host(device_object, memSize, + map_unified_memory_to_host(device_object, size_output, BufferMapCL{&d_output, deviceObj->d_B, deviceObj->evt_copyC} ); } diff --git a/gpu4s_benchmark/matrix_multiplication_bench/opencl/lib_opencl_common.cpp b/gpu4s_benchmark/matrix_multiplication_bench/opencl/lib_opencl_common.cpp index 0773302a..7674794d 100644 --- a/gpu4s_benchmark/matrix_multiplication_bench/opencl/lib_opencl_common.cpp +++ b/gpu4s_benchmark/matrix_multiplication_bench/opencl/lib_opencl_common.cpp @@ -182,10 +182,10 @@ void sync_unified_memory_to_device(GraficCommon* device_object, bench_t* &A, ben } -void sync_unified_memory_to_host(GraficCommon* device_object, bench_t* &d_output, unsigned int memSize){ +void sync_unified_memory_to_host(GraficCommon* device_object, bench_t* &d_output, unsigned int size_output){ GraficObject* deviceObj = static_cast(device_object); // --- Call the openCL common function --- - map_unified_memory_to_host(device_object, memSize, + map_unified_memory_to_host(device_object, size_output, BufferMapCL{&d_output, deviceObj->d_C, deviceObj->evt_copyC} ); } diff --git a/gpu4s_benchmark/matrix_multiplication_bench_fp16/opencl/lib_opencl_common.cpp b/gpu4s_benchmark/matrix_multiplication_bench_fp16/opencl/lib_opencl_common.cpp index 4e605eed..a5ecae30 100644 --- a/gpu4s_benchmark/matrix_multiplication_bench_fp16/opencl/lib_opencl_common.cpp +++ b/gpu4s_benchmark/matrix_multiplication_bench_fp16/opencl/lib_opencl_common.cpp @@ -237,10 +237,10 @@ void sync_unified_memory_to_device(GraficCommon* device_object, bench_t* &A, ben } -void sync_unified_memory_to_host(GraficCommon* device_object, bench_t* &d_output, unsigned int memSize){ +void sync_unified_memory_to_host(GraficCommon* device_object, bench_t* &d_output, unsigned int size_output){ GraficObject* deviceObj = static_cast(device_object); // --- Call the openCL common function --- - map_unified_memory_to_host(device_object, memSize, + map_unified_memory_to_host(device_object, size_output, BufferMapCL{&d_output, deviceObj->d_C, deviceObj->evt_copyC} ); } diff --git a/gpu4s_benchmark/matrix_multiplication_tensor_bench/opencl/lib_opencl_common.cpp b/gpu4s_benchmark/matrix_multiplication_tensor_bench/opencl/lib_opencl_common.cpp index 6fe0545f..e4415d92 100644 --- a/gpu4s_benchmark/matrix_multiplication_tensor_bench/opencl/lib_opencl_common.cpp +++ b/gpu4s_benchmark/matrix_multiplication_tensor_bench/opencl/lib_opencl_common.cpp @@ -182,10 +182,10 @@ void sync_unified_memory_to_device(GraficCommon* device_object, bench_t* &A, ben } -void sync_unified_memory_to_host(GraficCommon* device_object, bench_t* &d_output, unsigned int memSize){ +void sync_unified_memory_to_host(GraficCommon* device_object, bench_t* &d_output, unsigned int size_output){ GraficObject* deviceObj = static_cast(device_object); // --- Call the openCL common function --- - map_unified_memory_to_host(device_object, memSize, + map_unified_memory_to_host(device_object, size_output, BufferMapCL{&d_output, deviceObj->d_C, deviceObj->evt_copyC} ); } diff --git a/gpu4s_benchmark/max_pooling_bench/opencl/lib_opencl_common.cpp b/gpu4s_benchmark/max_pooling_bench/opencl/lib_opencl_common.cpp index d4a65e16..0aa11d38 100644 --- a/gpu4s_benchmark/max_pooling_bench/opencl/lib_opencl_common.cpp +++ b/gpu4s_benchmark/max_pooling_bench/opencl/lib_opencl_common.cpp @@ -168,10 +168,10 @@ void sync_unified_memory_to_device(GraficCommon* device_object, bench_t* &A){ } -void sync_unified_memory_to_host(GraficCommon* device_object, bench_t* &d_output, unsigned int memSize){ +void sync_unified_memory_to_host(GraficCommon* device_object, bench_t* &d_output, unsigned int size_output){ GraficObject* deviceObj = static_cast(device_object); // --- Call the openCL common function --- - map_unified_memory_to_host(device_object, memSize, + map_unified_memory_to_host(device_object, size_output, BufferMapCL{&d_output, deviceObj->d_B, deviceObj->evt_copyB} ); } diff --git a/gpu4s_benchmark/memory_bandwidth_bench/opencl/lib_opencl.cpp b/gpu4s_benchmark/memory_bandwidth_bench/opencl/lib_opencl.cpp index dbdbbd6b..0fe06d24 100644 --- a/gpu4s_benchmark/memory_bandwidth_bench/opencl/lib_opencl.cpp +++ b/gpu4s_benchmark/memory_bandwidth_bench/opencl/lib_opencl.cpp @@ -182,10 +182,10 @@ void sync_unified_memory_to_device(GraficCommon* device_object, bench_t* &A, ben } -void sync_unified_memory_to_host(GraficCommon* device_object, bench_t* &d_output, unsigned int memSize){ +void sync_unified_memory_to_host(GraficCommon* device_object, bench_t* &d_output, unsigned int size_output){ GraficObject* deviceObj = static_cast(device_object); // --- Call the openCL common function --- - map_unified_memory_to_host(device_object, memSize, + map_unified_memory_to_host(device_object, size_output, BufferMapCL{&d_output, deviceObj->d_B, deviceObj->evt_copyB} ); } diff --git a/gpu4s_benchmark/relu_bench/opencl/lib_opencl_common.cpp b/gpu4s_benchmark/relu_bench/opencl/lib_opencl_common.cpp index 538d06f6..2e802fbd 100644 --- a/gpu4s_benchmark/relu_bench/opencl/lib_opencl_common.cpp +++ b/gpu4s_benchmark/relu_bench/opencl/lib_opencl_common.cpp @@ -174,10 +174,10 @@ void sync_unified_memory_to_device(GraficCommon* device_object, bench_t* &A, ben } -void sync_unified_memory_to_host(GraficCommon* device_object, bench_t* &d_output, unsigned int memSize){ +void sync_unified_memory_to_host(GraficCommon* device_object, bench_t* &d_output, unsigned int size_output){ GraficObject* deviceObj = static_cast(device_object); // --- Call the openCL common function --- - map_unified_memory_to_host(device_object, memSize, + map_unified_memory_to_host(device_object, size_output, BufferMapCL{&d_output, deviceObj->d_B, deviceObj->evt_copyB} ); } diff --git a/gpu4s_benchmark/wavelet_transform/benchmark_library.h b/gpu4s_benchmark/wavelet_transform/benchmark_library.h index 52354fd8..46031c31 100644 --- a/gpu4s_benchmark/wavelet_transform/benchmark_library.h +++ b/gpu4s_benchmark/wavelet_transform/benchmark_library.h @@ -74,30 +74,29 @@ struct GraficObject : public GraficCommon { // --- Specefic overload of benchmarking function --- #ifdef UMA_COMPATIBILITY -// --- 4 buffer, 1 shared size + 2 conditional (wavelet_transform) --- - /** - * @brief Maps input/output (A -> d_A, B -> d_B, both sized memSize) plus, in FLOAT/DOUBLE - * builds only, two filter buffers (C -> low_filter, sized - * LOWPASSFILTERSIZE; D -> high_filter, sized HIGHPASSFILTERSIZE). +/** + * @brief Maps input/output (A -> d_A, B -> d_B, both sized memSize) plus, in FLOAT/DOUBLE + * builds only, two filter buffers (C -> low_filter, sized + * LOWPASSFILTERSIZE; D -> high_filter, sized HIGHPASSFILTERSIZE). - * @param device_object Pointer to the device common structure - * @param A Reference to receive the mapped input host pointer (d_A) - * @param B Reference to receive the mapped output host pointer (d_B) - * @param C Reference to receive the mapped lowpass-filter host pointer (low_filter); unused under INT - * @param D Reference to receive the mapped highpass-filter host pointer (high_filter); unused under INT - * @param memSize Size shared by A and B, in bytes. C and D use their own fixed - * LOWPASSFILTERSIZE/HIGHPASSFILTERSIZE internally, not this parameter. - */ - void get_unified_memory_pointers(GraficCommon* device_object, bench_t* &A, bench_t* &B, bench_t* &C, bench_t* &D, unsigned int memSize); - /** - * @brief Unmaps A, B, and (FLOAT/DOUBLE builds only) C and D, blocking until the device - * regains ownership of each. - * - * @param device_object Pointer to the device common structure - * @param A Reference to the mapped input host pointer to unmap - * @param B Reference to the mapped output host pointer to unmap - * @param C Reference to the mapped lowpass-filter host pointer to unmap; unused under INT - * @param D Reference to the mapped highpass-filter host pointer to unmap; unused under INT - */ - void sync_unified_memory_to_device(GraficCommon* device_object, bench_t* &A, bench_t* &B, bench_t* &C, bench_t* &D); + * @param device_object Pointer to the device common structure + * @param A Reference to receive the mapped input host pointer (d_A) + * @param B Reference to receive the mapped output host pointer (d_B) + * @param C Reference to receive the mapped lowpass-filter host pointer (low_filter); unused under INT + * @param D Reference to receive the mapped highpass-filter host pointer (high_filter); unused under INT + * @param sizeAB Size shared by A and B, in bytes. C and D use their own fixed + * LOWPASSFILTERSIZE/HIGHPASSFILTERSIZE internally, not this parameter. + */ + +void get_unified_memory_pointers(GraficCommon* device_object, bench_t* &A, bench_t* &B, bench_t* &C, bench_t* &D, unsigned int sizeAB); +/** + * @brief Unmaps A, B, and (FLOAT/DOUBLE builds only) C and D, blocked for host until the device give aigain ownership + * + * @param device_object Pointer to the device common structure + * @param A Reference to the mapped input host pointer to unmap + * @param B Reference to the mapped output host pointer to unmap + * @param C Reference to the mapped lowpass-filter host pointer to unmap; unused under INT + * @param D Reference to the mapped highpass-filter host pointer to unmap; unused under INT + */ +void sync_unified_memory_to_device(GraficCommon* device_object, bench_t* &A, bench_t* &B, bench_t* &C, bench_t* &D); #endif \ No newline at end of file diff --git a/gpu4s_benchmark/wavelet_transform/opencl/lib_opencl.cpp b/gpu4s_benchmark/wavelet_transform/opencl/lib_opencl.cpp index 9a1eb549..87743b66 100644 --- a/gpu4s_benchmark/wavelet_transform/opencl/lib_opencl.cpp +++ b/gpu4s_benchmark/wavelet_transform/opencl/lib_opencl.cpp @@ -258,10 +258,10 @@ void clean(GraficCommon* device_object){ #ifdef UMA_COMPATIBILITY // ====== UMA function ====== -void get_unified_memory_pointers(GraficCommon* device_object, bench_t* &A, bench_t* &B, bench_t* &C, bench_t* &D, unsigned int memSize){ +void get_unified_memory_pointers(GraficCommon* device_object, bench_t* &A, bench_t* &B, bench_t* &C, bench_t* &D, unsigned int sizeAB){ GraficObject* deviceObj = static_cast(device_object); // --- Call the openCL common function --- - map_unified_memory(device_object, memSize, + map_unified_memory(device_object, sizeAB, BufferMapCL{&A, deviceObj->d_A, nullptr}, BufferMapCL{&B, deviceObj->d_B, nullptr} ); @@ -296,10 +296,10 @@ void sync_unified_memory_to_device(GraficCommon* device_object, bench_t* &A, ben } -void sync_unified_memory_to_host(GraficCommon* device_object, bench_t* &d_output, unsigned int memSize){ +void sync_unified_memory_to_host(GraficCommon* device_object, bench_t* &d_output, unsigned int size_output){ GraficObject* deviceObj = static_cast(device_object); // --- Call the openCL common function --- - map_unified_memory_to_host(device_object, memSize, + map_unified_memory_to_host(device_object, size_output, BufferMapCL{&d_output, deviceObj->d_B, deviceObj->evt_copyB} ); } From 53a15231f088071a0e48501db683300ad9ac68ce Mon Sep 17 00:00:00 2001 From: Noah Perret Date: Mon, 17 Aug 2026 10:38:56 +0200 Subject: [PATCH 27/27] improve comment for opencl_common --- gpu4s_benchmark/common/opencl_common.hpp | 14 +++++++------- .../softmax_bench/opencl/lib_opencl_common.cpp | 4 ++-- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/gpu4s_benchmark/common/opencl_common.hpp b/gpu4s_benchmark/common/opencl_common.hpp index dd9a2a05..e80ab8e3 100644 --- a/gpu4s_benchmark/common/opencl_common.hpp +++ b/gpu4s_benchmark/common/opencl_common.hpp @@ -52,15 +52,15 @@ inline void map_unified_memory(GraficCommon* device_object, unsigned memSize, Ma mapCLK.start(); // --- C++17 Fold Expression Unrolled at compile-time --- - // For each MapCL map host buffer to devcie buffer + // For each MapCL buffer host buffer map device memory into the CPU's address space (( - //map the buffer between cpu and gpu (cpu is faster) + // Map the buffer with CL_MAP_WRITE so CPU can directly use it *(mapCL.hostBuffer) = static_cast( deviceObj->queue->enqueueMapBuffer( *(mapCL.deviceBuffer), CL_TRUE, CL_MAP_WRITE, 0, memSize, nullptr, mapCL.deviceEvent, &lastErr ) ), - // Update err to not miss an error + // Save first error, so no failures are silently ignored (lastErr != CL_SUCCESS ? err = lastErr : CL_SUCCESS) ), ...); @@ -91,12 +91,12 @@ inline void unmap_unified_memory(GraficCommon* device_object, MapCL... mapCL) { unmapCLK.start(); // --- C++17 Fold Expression Unrolled at compile-time --- - // For each MapCL unmap host buffer to devcie buffer + // For each MapCL buffer unmap host buffer to device buffer (( lastErr = deviceObj->queue->enqueueUnmapMemObject( *(mapCL.deviceBuffer), *(mapCL.hostBuffer), NULL, mapCL.deviceEvent ), - // Update err to not miss an error + // Save first error, so no failures are silently ignored (lastErr != CL_SUCCESS ? err = lastErr : CL_SUCCESS) ), ...); @@ -127,14 +127,14 @@ inline void map_unified_memory_to_host(GraficCommon* device_object, unsigned mem mapCLK.start(); // --- C++17 Fold Expression Unrolled at compile-time --- - // For each MapCL map host buffer to devcie buffer + // For each MapCL buffer host buffer map device memory into the CPU's address space (( *(mapCL.hostBuffer) = static_cast( deviceObj->queue->enqueueMapBuffer( *(mapCL.deviceBuffer), CL_TRUE, CL_MAP_READ, 0, memSize, nullptr, mapCL.deviceEvent, &lastErr ) ), - // Update err to not miss an error + // Save first error, so no failures are silently ignored (lastErr != CL_SUCCESS ? err = lastErr : CL_SUCCESS) ), ...); diff --git a/gpu4s_benchmark/softmax_bench/opencl/lib_opencl_common.cpp b/gpu4s_benchmark/softmax_bench/opencl/lib_opencl_common.cpp index 78834167..a65d0c18 100644 --- a/gpu4s_benchmark/softmax_bench/opencl/lib_opencl_common.cpp +++ b/gpu4s_benchmark/softmax_bench/opencl/lib_opencl_common.cpp @@ -175,10 +175,10 @@ void sync_unified_memory_to_device(GraficCommon* device_object, bench_t* &A, ben } -void sync_unified_memory_to_host(GraficCommon* device_object, bench_t* &d_output, unsigned int memSize){ +void sync_unified_memory_to_host(GraficCommon* device_object, bench_t* &d_output, unsigned int size_output){ GraficObject* deviceObj = static_cast(device_object); // --- Call the openCL common function --- - map_unified_memory_to_host(device_object, memSize, + map_unified_memory_to_host(device_object, size_output, BufferMapCL{&d_output, deviceObj->d_B, deviceObj->evt_copyB} ); }