Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
43d1487
UMA for matrix mult opencl
EmbeddedFrime Aug 11, 2026
52861af
rename common file inside framework
EmbeddedFrime Aug 11, 2026
6de109d
refactor main for relu + create a common for opencl UMA
EmbeddedFrime Aug 11, 2026
06db52b
add cl check for unmap and map fucntion
EmbeddedFrime Aug 12, 2026
4881a87
fix main.cpp cifar_10_mutiple
EmbeddedFrime Aug 12, 2026
057bcc7
first UMA for 2D FFT
EmbeddedFrime Aug 13, 2026
dee328b
implementation of UMA in FFT bench
EmbeddedFrime Aug 13, 2026
2d41e22
add UMA on fft windows bench
EmbeddedFrime Aug 13, 2026
3803ef5
small fix for previous UMA refactor
EmbeddedFrime Aug 13, 2026
0959099
fix kernel size for 2D convolution UMA
EmbeddedFrime Aug 13, 2026
528603a
add UMA for FIR bench
EmbeddedFrime Aug 13, 2026
a6767ff
add UMA ofr LRN bench
EmbeddedFrime Aug 13, 2026
9e24a5c
add float android uma for matrix mult fp16 bench
EmbeddedFrime Aug 13, 2026
70c8fe7
add android UMA for matrix mult tensor bench
EmbeddedFrime Aug 13, 2026
c7b0be1
add UMA for android
EmbeddedFrime Aug 13, 2026
4f9cb99
add androdi uma for android
EmbeddedFrime Aug 14, 2026
0670bfb
delete opencl lib (it was a buggy opt version) add uma for softmax
EmbeddedFrime Aug 14, 2026
dcc6062
add UMA for wavelet transform
EmbeddedFrime Aug 14, 2026
a1d18a7
small fix in previosu benchmark for android UMA
EmbeddedFrime Aug 14, 2026
34cdf31
fix android bug by using cifar_10 kernel code
EmbeddedFrime Aug 14, 2026
43afd09
add UMA for cifar_10 mutiple
EmbeddedFrime Aug 14, 2026
6e57a23
fix UMA for android
EmbeddedFrime Aug 14, 2026
98bb06c
add comment for uma function in main
EmbeddedFrime Aug 14, 2026
05f64b5
add comment for uma function in main
EmbeddedFrime Aug 14, 2026
057a8aa
add comment for uma function in .h
EmbeddedFrime Aug 14, 2026
713e587
improve comment for UMA
EmbeddedFrime Aug 17, 2026
53a1523
improve comment for opencl_common
EmbeddedFrime Aug 17, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion doc.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
```
Expand All @@ -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!"
Expand Down
8 changes: 4 additions & 4 deletions gpu4s_benchmark/LRN_bench/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand All @@ -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}
Expand Down Expand Up @@ -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}
Expand All @@ -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}
Expand Down
1 change: 1 addition & 0 deletions gpu4s_benchmark/LRN_bench/cpu_functions/cpu_functions.h
Original file line number Diff line number Diff line change
Expand Up @@ -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] = "";
};
Expand Down
165 changes: 109 additions & 56 deletions gpu4s_benchmark/LRN_bench/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,36 +31,62 @@ int main(int argc, char *argv[]){
// VARIABLES
///////////////////////////////////////////////////////////////////////////////////////////////
// linearizable versions of matrix
unsigned int size_matrix =arguments_parameters->size * arguments_parameters->size;
// 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
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*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
// 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");
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; i<arguments_parameters->size; i++){
for (int j=0; j<arguments_parameters->size; 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; i<arguments_parameters->size; i++){
for (int j=0; j<arguments_parameters->size; j++){
h_B[i*arguments_parameters->size+j] = 0;
Expand All @@ -83,6 +109,7 @@ int main(int argc, char *argv[]){
}
}*/
}

// print input
if (arguments_parameters->print_input)
{
Expand All @@ -102,68 +129,85 @@ 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 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
// UMA: unmap shared buffer from host to device
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
// UMA: map back output buffer to host
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; i<arguments_parameters->size; i++){
for (int j=0; j<arguments_parameters->size; j++){
printf("%d ", d_B[i*arguments_parameters->size+j]);

}
printf("\n");
}
for (int i=0; i<arguments_parameters->size; i++){
for (int j=0; j<arguments_parameters->size; j++){
printf("%d ", d_B[i*arguments_parameters->size+j]);
}
printf("\n");
}
#else
for (int i=0; i<arguments_parameters->size; i++){
for (int j=0; j<arguments_parameters->size; j++){
printf("%f ", d_B[i*arguments_parameters->size+j]);

}
for (int j=0; j<arguments_parameters->size; 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
Expand All @@ -184,20 +228,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
///////////////////////////////////////////////////////////////////////////////////////////////
Expand All @@ -206,15 +246,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);
Expand All @@ -232,7 +276,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){
Expand All @@ -247,7 +292,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
}


Expand Down Expand Up @@ -277,6 +329,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;
}

Expand Down
Loading