`| **Stride Size** | *(Specific to `max_pooling`)* Defines the horizontal and vertical step size of the pooling sliding window. |
\ No newline at end of file
diff --git a/docs/INSTALL.md b/docs/INSTALL.md
new file mode 100644
index 00000000..e90d7444
--- /dev/null
+++ b/docs/INSTALL.md
@@ -0,0 +1,310 @@
+
+# GPU4S: Installation Guide
+This document describes how to install all dependencies required to build GPU4S. For general information about the project, check the main [README](../README.md).
+
+## Global Requirements
+### 1. GNU Compiler Collection (GCC) / CLang
+In order to compile the files of the project you need to have installed [**GCC**](https://gcc.gnu.org/releases.html) ≥ 7. or [**Clang**](https://releases.llvm.org/download.html) ≥ 6 in order to support C++17.
+```bash
+# Install on Fedora
+sudo dnf install gcc-c++ clang
+
+# Install on Ubuntu
+sudo apt update
+sudo apt install build-essential clang
+
+# Check version
+g++ --version
+clang --version
+```
+
+
+### 2. CMake
+In order to build the project you need to install [**CMake**](https://cmake.org/download) ≥ 3.24
+```bash
+ # Install on Fedora
+ sudo dnf install cmake
+ # Install on Ubuntu
+ sudo apt install cmake
+ # Check version
+ cmake --version
+```
+
+### 3. Git
+
+To fetch external dependencies and CMake `FetchContent` modules, you need [**Git**](https://git-scm.com/install/).
+
+```bash
+# Install on Fedora
+sudo dnf install git
+
+# Install on Ubuntu
+sudo apt install git
+
+# Check version
+git --version
+```
+
+
+## Specific Framework Requirements
+
+### 1. NVIDIA CUDA (nvcc)
+
+Required for compiling [**CUDA**](https://developer.nvidia.com/cuda-downloads) accelerated benchmarks (`.cu` targets).
+
+>Tested with version: **V13.2.86**
+
+```bash
+# Install on Fedora (via RPM Fusion / NVIDIA repo)
+sudo dnf install xorg-x11-drv-nvidia-cuda cuda-toolkit
+
+# Install on Ubuntu
+sudo apt update
+sudo apt install nvidia-cuda-toolkit
+
+# Check version
+nvcc --version
+```
+> **Additional lib NVIDIA cuDNN**
+> NVIDIA CUDA Deep Neural Network library (cuDNN) is required by some of the benchmark.
+> Tested with **V9.23.2**, can be downloaded from [NVIDIA website](https://developer.nvidia.com/cudnn-9-23-2-download-archive).
+
+
+Installation Details
+
+When downloading the local package installer from the NVIDIA website, select your operating system distribution:
+* **Fedora:** Select **Linux** $\rightarrow$ **x86_64** $\rightarrow$ **RHEL** (`.rpm` package) $\rightarrow$ **FULL**.
+* **Ubuntu:** Select **Linux** $\rightarrow$ **x86_64** $\rightarrow$ **Ubuntu** or **Debian** (`.deb` package) $\rightarrow$ **FULL**.
+
+
+### Fedora Installation
+
+```bash
+# Download the RPM repository package for cuDNN 9.23.2
+wget https://developer.download.nvidia.com/compute/cudnn/9.23.2/local_installers/cudnn-local-repo-rhel10-9.23.2-1.0-1.x86_64.rpm
+# Install the package to register it with the package manager
+sudo rpm -i cudnn-local-repo-rhel10-9.23.2-1.0-1.x86_64.rpm
+# Clean the DNF package manager
+sudo dnf clean all
+
+# Install the cuDNN 9 library for CUDA 13
+sudo dnf -y install cudnn9-cuda-13
+```
+
+### Ubuntu Installation
+
+```bash
+# Download the local DEB package for cuDNN 9.23.2
+wget https://developer.download.nvidia.com/compute/cudnn/9.23.2/local_installers/cudnn-local-repo-ubuntu2404-9.23.2_1.0-1_amd64.deb
+# Install the local package to register it with APT
+sudo dpkg -i cudnn-local-repo-ubuntu2404-9.23.2_1.0-1_amd64.deb
+# Copy the GPG key to authenticate packages
+sudo cp /var/cudnn-local-repo-ubuntu2404-9.23.2/cudnn-*-keyring.gpg /usr/share/keyrings/
+# Refresh the APT package
+sudo apt-get update
+
+# Install the cuDNN 9 library for CUDA 13
+sudo apt-get -y install cudnn9-cuda-13
+```
+
+
+
+### 2. AMD ROCm (hipcc)
+
+Required for compiling [AMD HIP](https://rocm.docs.amd.com/en/latest/install/rocm.html?fam=all&w=graphics&os=ubuntu&ubuntu-ver=26.04) benchmarks (.cpp HIP targets).
+
+>Tested with version: **6.4.43484-9999**
+
+```Bash
+# Install on Fedora
+sudo dnf install rocm-hip-devel rocm-runtime
+
+# Install on Ubuntu
+sudo apt update
+sudo apt install hipcc rocm-dev
+
+# Check version
+hipcc --version
+```
+
+### 3. OpenCL
+
+Required for compiling [**OpenCL**](https://www.khronos.org/opencl/) accelerated benchmarks (`.cpp` OpenCL targets).
+
+> Tested with version: **OpenCL 3.0**
+
+```bash
+# Install on Fedora
+sudo dnf install opencl-headers ocl-icd-devel clinfo
+
+# Install on Ubuntu
+sudo apt update
+sudo apt install opencl-headers ocl-icd-opencl-dev clinfo
+
+# Check version and available devices
+clinfo
+```
+
+> **Additional lib CLBlast**
+> The tuned OpenCL BLAS library (CLBlast) is required by some benchmarks.
+> Tested with **v1.6.3 and v1.7.0**, can be downloaded from the [CLBlast GitHub Releases](https://github.com/CNugteren/CLBlast/releases).
+
+
+Installation Details
+
+### Fedora Installation
+
+```bash
+# Install CLBlast development libraries directly via DNF
+sudo dnf -y install clblast-devel
+```
+
+### Ubuntu Installation
+
+```bash
+# Install CLBlast development libraries directly via APT
+sudo apt-get -y install libclblast-dev
+```
+
+
+
+### 4. OpenMP
+
+Required for multi-threaded CPU parallel execution (`-fopenmp`).
+
+> Tested with: **OpenMP 4.5 (201511)**
+
+```bash
+# Install runtime & development libraries on Fedora
+sudo dnf install libgomp
+
+# Install runtime & development libraries on Ubuntu
+sudo apt install libomp-dev
+
+# Check supported OpenMP version via compiler macro (_OPENMP)
+echo | g++ -fopenmp -dM -E - | grep _OPENMP
+```
+>**Additional lib OpenBLAS**
+> An optimized Basic Linear Algebra Subprograms (BLAS) library required by some benchmarks.
+> Tested with **v0.3.x**, can be downloaded from the [OpenBLAS GitHub Releases](https://github.com/OpenMathLib/OpenBLAS/releases).
+
+
+Installation Details
+
+### Fedora Installation
+
+```bash
+# Install OpenBLAS development libraries directly via DNF
+sudo dnf -y install openblas-devel
+```
+
+### Ubuntu Installation
+
+```bash
+# Install OpenBLAS development libraries directly via APT
+sudo apt-get -y install libopenblas-dev
+```
+
+
+
+
+
+### 5. **Additional lib FFTW3**
+> A C subroutine library for computing the Discrete Fourier Transform (DFT) required by some benchmarks.
+> Tested with v3.3.10, can be downloaded from the [FFTW Official Website](http://www.fftw.org/download.html).
+
+
+Installation Details
+
+### Fedora Installation
+
+```bash
+# Install FFTW3 development libraries directly via DNF
+sudo dnf -y install fftw-devel
+```
+
+### Ubuntu Installation
+
+```bash
+# Install FFTW3 development libraries directly via APT
+sudo apt-get -y install libfftw3-dev
+```
+
+
+
+
+## ANDROID specific Requirements
+
+### 1. Android NDK r27d (27.3.13750724)
+
+First, you will need to download the [Android NDK](https://github.com/android/ndk/wiki) in your environment to cross-compile for Android targets.
+
+You can use other versions of the Android NDK, but the project was built and successfully tested using **NDK r27d (27.3.13750724)**.
+
+**Recommended installation instructions:**
+1. Download the [Android Command Line Tools](https://developer.android.com/studio#command-line-tools-only)
+2. Install them and set `ANDROID_HOME` and `sdkmanager` to your bash path:
+```bash
+ # Put default Android Studio path
+ # or wherever you installed it
+ echo 'export ANDROID_HOME=$HOME/Android/Sdk' >> ~/.bashrc
+ echo 'export PATH=$PATH:$ANDROID_HOME/cmdline-tools/latest/bin' >> ~/.bashrc
+ source ~/.bashrc #reload bash configuration
+```
+3. Download your preferred version of the NDK using the `sdkmanager`:
+```bash
+sdkmanager --install "ndk;27.3.13750724"
+```
+### 2. Android Debug Bridge (ADB)
+
+In addition, if you want to push the binaries to your phone and execute them, you should install **ADB (Android Debug Bridge)**.
+
+```bash
+# Ubuntu
+ sudo apt install android-tools-adb
+# Fedora
+ sudo dnf install android-tools
+```
+
+### 3. Additional Android Libs
+
+Some benchmarks on Android will require several pre-compiled static libraries, headers, and an OpenCL stub.
+
+In release versions, these dependencies are already pre-compiled and included under `./gpu4s_benchmark/common/android/` this version targets the following specifications:
+
+- Target ABIs: arm64-v8a, armeabi-v7a
+- Minimum Android API: 21
+- Built With: Android NDK r27d
+
+If you need to target a newer architecture (like ARMv9) or running the main repo, you can use my custom toolchains to download, compile the stub, libraries and headers:
+- **[clblast-android-toolchain](https://github.com/EmbeddedFrime/clblast-android-toolchain)** (`libclblast.a` and `libOpenCL.so` stub)
+- **[openblas-android-toolchain](https://github.com/EmbeddedFrime/openblas-android-toolchain)** (`cblas.h,` `openblas_config.h`, and `libopenblas.a`)
+- **[fftw-android-toolchain](https://github.com/EmbeddedFrime/fftw-android-toolchain)** (`libfftw3.a` and `libfftw3_omp.a`)
+
+After having recompiled the libraries, you need to replace the corresponding files in the common/android/ directory with the new ones:
+
+
+common/android/
+├── include/
+│ ├── arm64-v8a/
+│ │ ├── cblas.h *
+│ │ └── openblas_config.h *
+│ └── armeabi-v7a/
+│ ├── cblas.h *
+│ └── openblas_config.h *
+└── libs/
+ ├── arm64-v8a/
+ │ ├── libOpenCL.so *
+ │ ├── libclblast.a *
+ │ ├── libfftw3_omp.a *
+ │ ├── libfftw3.a *
+ │ └── libopenblas.a *
+ └── armeabi-v7a/
+ ├── libOpenCL.so *
+ ├── libopenblas.a *
+ ├── libfftw3_omp.a *
+ ├── libfftw3.a *
+ └── libopenblas.a *
+
+OpenBLAS toolchain* CLBlast toolchain* fftw3 toolchain*
+
diff --git a/gpu4s_benchmark/CMakeLists.txt b/gpu4s_benchmark/CMakeLists.txt
new file mode 100644
index 00000000..5175a813
--- /dev/null
+++ b/gpu4s_benchmark/CMakeLists.txt
@@ -0,0 +1,71 @@
+cmake_minimum_required(VERSION 3.24)
+project(gpu4s_benchmark_global NONE)
+
+# add module
+list(APPEND CMAKE_MODULE_PATH
+ "${CMAKE_CURRENT_SOURCE_DIR}/common/cmake/"
+)
+include(showConfig)
+
+# create list of all the bench folder
+set(GPU4S_SUBPROJECTS
+ cifar_10
+ cifar_10_multiple
+ convolution_2D_bench
+ correlation_2D
+ fast_fourier_transform_2D_bench
+ fast_fourier_transform_bench
+ fast_fourier_transform_window_bench
+ finite_impulse_response_filter
+ LRN_bench
+ matrix_multiplication_bench
+ matrix_multiplication_bench_fp16
+ matrix_multiplication_tensor_bench
+ max_pooling_bench
+ memory_bandwidth_bench
+ relu_bench
+ softmax_bench
+ wavelet_transform
+)
+
+
+foreach(bench ${GPU4S_SUBPROJECTS})
+ add_subdirectory(${bench})
+endforeach()
+
+# ====== Global aggregator targets ======
+# --- project name array ---
+set(GPU4S_PROJECT_NAME
+ cifar_10
+ cifar_10_multiple
+ convolution_2D
+ correlation_2D
+ FFT_2D
+ FFT
+ FFT_window
+ FIR_filter
+ LRN
+ matrix_mult
+ matrix_mult_fp16
+ matrix_mult_tensor
+ max_pooling
+ memory_bandwidth
+ relu
+ softmax
+ wavelet_transform
+)
+
+
+set(GPU4S_ALL_TARGETS cpu all-opencl all-openmp all-cuda all-hip)
+
+foreach(all ${GPU4S_ALL_TARGETS})
+ add_custom_target(${all})
+ foreach(bench ${GPU4S_PROJECT_NAME})
+ if(TARGET ${bench}-${all})
+ add_dependencies(${all} ${bench}-${all})
+ endif()
+ endforeach()
+endforeach()
+
+#show global config
+showConfig()
\ No newline at end of file
diff --git a/gpu4s_benchmark/LRN_bench/CMakeLists.txt b/gpu4s_benchmark/LRN_bench/CMakeLists.txt
new file mode 100644
index 00000000..a22905d8
--- /dev/null
+++ b/gpu4s_benchmark/LRN_bench/CMakeLists.txt
@@ -0,0 +1,297 @@
+# =======================================================================
+# File: CMakeLists.txt (./LRN_bench)
+# Description: Build targets for Local Response Normalization benchmark
+# Target: CPU, OpenMP, OpenCL, CUDA, HIP
+# License: ESA-PL Strong Copyleft – v2.5
+# =======================================================================
+
+cmake_minimum_required(VERSION 3.24)
+project(LRN CXX) # Local Response Normalization bench
+
+# ====== Include cmake module ======
+list(APPEND CMAKE_MODULE_PATH
+ "${CMAKE_CURRENT_SOURCE_DIR}/../common/cmake/"
+ "${CMAKE_CURRENT_SOURCE_DIR}/../common/cmake/module"
+)
+# Global:
+include(setup)
+include(compileBlueprint)
+# Module:
+include(findOpenMP)
+include(findHIP)
+include(findOpenBLAS)
+include(findCUDNN)
+
+# show the configuration of the project
+if(PROJECT_IS_TOP_LEVEL)
+ showConfig()
+endif()
+
+
+# ====== Compilation of the targets ======
+
+# --- CPU target ---
+compile_target(${PROJECT_NAME}_cpu
+ BENCH_DIR ${CMAKE_CURRENT_SOURCE_DIR}
+ SOURCES_FILES cpu/lib_cpu.cpp
+ SHORTCUTS_NAMES cpu CPU
+)
+
+# --- Android Targets---
+if(ANDROID)
+
+ if(ANDROID_OPENCL_LIB_INC)
+ # --- OpenCL ---
+ compile_target(${PROJECT_NAME}_opencl
+ BENCH_DIR ${CMAKE_CURRENT_SOURCE_DIR}
+ SOURCES_FILES opencl/lib_opencl.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 cl OpenCL
+ )
+ # --- OpenCL-opt ---
+ compile_target(${PROJECT_NAME}_opencl_opt
+ BENCH_DIR ${CMAKE_CURRENT_SOURCE_DIR}
+ SOURCES_FILES opencl/lib_opencl_opt.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-opt OpenCL-opt
+ )
+
+ endif()
+
+ # --- OpenMP---
+ compile_target(${PROJECT_NAME}_openmp
+ BENCH_DIR ${CMAKE_CURRENT_SOURCE_DIR}
+ SOURCES_FILES openmp/lib_omp.cpp
+ openmp/omp_common.cpp
+
+ COMPILE_DEFS OPENMP
+ COMPILE_OPTIONS -fopenmp
+ LIBRARIES -static-openmp #openmp flags
+ -fopenmp
+ -lm # add math lib
+
+ SHORTCUTS_NAMES openmp OpenMP
+ )
+
+ # --- OpenMP-opt ---
+ compile_target(${PROJECT_NAME}_openmp_opt
+ BENCH_DIR ${CMAKE_CURRENT_SOURCE_DIR}
+ SOURCES_FILES openmp/lib_omp_opt.cpp
+ openmp/omp_common.cpp
+
+ COMPILE_DEFS OPENMP
+ COMPILE_OPTIONS -fopenmp
+ LIBRARIES -static-openmp #openmp flags
+ -fopenmp
+ -lm # add math lib
+
+ SHORTCUTS_NAMES openmp-opt OpenMP-opt
+ )
+
+endif(ANDROID)
+
+# --- Computeur targets ---
+if(NOT ANDROID)
+ # --- OpenCL Targets ---
+ if(OpenCL_FOUND)
+ # --- OpenCL ---
+ compile_target(${PROJECT_NAME}_opencl
+ BENCH_DIR ${CMAKE_CURRENT_SOURCE_DIR}
+ SOURCES_FILES opencl/lib_opencl.cpp
+ opencl/lib_opencl_common.cpp
+
+ COMPILE_DEFS OPENCL
+ CL_HPP_TARGET_OPENCL_VERSION=${OPENCL_VERSION}
+
+ LIBRARIES OpenCL::OpenCL
+ SHORTCUTS_NAMES cl OpenCL
+ )
+
+ # --- OpenCL-opt ---
+ compile_target(${PROJECT_NAME}_opencl_opt
+ BENCH_DIR ${CMAKE_CURRENT_SOURCE_DIR}
+ SOURCES_FILES opencl/lib_opencl_opt.cpp
+ opencl/lib_opencl_common.cpp
+
+ COMPILE_DEFS OPENCL
+ CL_HPP_TARGET_OPENCL_VERSION=${OPENCL_VERSION}
+
+ LIBRARIES OpenCL::OpenCL
+ SHORTCUTS_NAMES opencl-opt OpenCL-opt
+ )
+
+ endif()
+
+ # --- OpenMP Targets ---
+ if(OpenMP_CXX_FOUND)
+ # --- OpenMP ---
+ compile_target(${PROJECT_NAME}_openmp
+ BENCH_DIR ${CMAKE_CURRENT_SOURCE_DIR}
+ SOURCES_FILES openmp/lib_omp.cpp
+ openmp/omp_common.cpp
+
+ COMPILE_DEFS OPENMP
+
+ LIBRARIES OpenMP::OpenMP_CXX # openmp flags
+ m # equivalent to -lm
+
+ SHORTCUTS_NAMES openmp OpenMP
+ )
+
+ # --- OpenMP-opt ---
+ compile_target(${PROJECT_NAME}_openmp_opt
+ BENCH_DIR ${CMAKE_CURRENT_SOURCE_DIR}
+ SOURCES_FILES openmp/lib_omp_opt.cpp
+ openmp/omp_common.cpp
+
+ COMPILE_DEFS OPENMP
+
+ LIBRARIES OpenMP::OpenMP_CXX # openmp flags
+ m # equivalent to -lm
+
+ SHORTCUTS_NAMES openmp-opt OpenMP-opt
+ )
+
+ endif()
+
+
+ # --- CUDA Targets---
+ if(CUDAToolkit_FOUND)
+ # --- CUDA ---
+ compile_target(${PROJECT_NAME}_cuda
+ BENCH_DIR ${CMAKE_CURRENT_SOURCE_DIR}
+ SOURCES_FILES cuda/lib_cuda.cu
+ cuda/cuda_common.cu
+
+ COMPILE_DEFS CUDA
+ SET_CUDA 1
+ LIBRARIES CUDA::cudart
+ SHORTCUTS_NAMES cuda CUDA
+ )
+
+ # --- CUDA-opt ---
+ compile_target(${PROJECT_NAME}_cuda_opt
+ BENCH_DIR ${CMAKE_CURRENT_SOURCE_DIR}
+ SOURCES_FILES cuda/lib_cuda_opt.cu
+ cuda/cuda_common.cu
+
+ COMPILE_DEFS CUDA
+ SET_CUDA 1
+ LIBRARIES CUDA::cudart
+ SHORTCUTS_NAMES cuda-opt CUDA-opt
+ )
+
+ if(CUDNN_FOUND)
+ # --- CUDA-lib ---
+ compile_target(${PROJECT_NAME}_cuda_lib
+ BENCH_DIR ${CMAKE_CURRENT_SOURCE_DIR}
+ SOURCES_FILES cuda/lib_cuda_lib.cu
+ cuda/cuda_common.cu
+
+ COMPILE_DEFS CUDA
+ SET_CUDA 1
+ LIBRARIES CUDA::cudart cudnn
+ SHORTCUTS_NAMES cuda-lib CUDA-lib
+ )
+ endif()
+ endif()
+
+ # --- HIP targets---
+ if(hip_FOUND)
+ # --- HIP ---²
+ compile_target(${PROJECT_NAME}_hip
+ BENCH_DIR ${CMAKE_CURRENT_SOURCE_DIR}
+ SOURCES_FILES hip/lib_hip.cpp
+ hip/hip_common.cpp
+
+ SET_HIP_FILES hip/lib_hip.cpp
+ hip/hip_common.cpp
+
+ COMPILE_DEFS HIP
+ LIBRARIES hip::host
+ SHORTCUTS_NAMES hip- HIP
+ )
+
+ # --- HIP-opt ---
+ compile_target(${PROJECT_NAME}_hip_opt
+ BENCH_DIR ${CMAKE_CURRENT_SOURCE_DIR}
+ SOURCES_FILES hip/lib_hip_opt.cpp
+ hip/hip_common.cpp
+
+ SET_HIP_FILES hip/lib_hip_opt.cpp
+ hip/hip_common.cpp
+
+ COMPILE_DEFS HIP
+ LIBRARIES hip::host
+ SHORTCUTS_NAMES hip-opt HIP-opt
+ )
+ endif()
+endif(NOT ANDROID)
+
+
+# ====== Shorcuts ======
+
+# --- all-opencl (Android) ---
+if(ANDROID AND ANDROID_OPENCL_LIB_INC )
+ add_custom_target(${SHORTCUT_PREFIX}all-opencl DEPENDS
+ ${PROJECT_NAME}_opencl
+ ${PROJECT_NAME}_opencl_opt
+ )
+endif()
+
+# --- all-opencl---
+if(NOT ANDROID AND OpenCL_FOUND )
+ add_custom_target(${SHORTCUT_PREFIX}all-opencl DEPENDS
+ ${PROJECT_NAME}_opencl
+ ${PROJECT_NAME}_opencl_opt
+ )
+endif()
+
+
+# --- all-openmp (Android) ---
+if(ANDROID AND ANDROID_OPENBLAS_LIB_INC )
+ add_custom_target(${SHORTCUT_PREFIX}all-openmp DEPENDS
+ ${PROJECT_NAME}_openmp
+ ${PROJECT_NAME}_openmp_opt
+ )
+endif()
+
+
+# --- all-openmp---
+if(NOT ANDROID AND OpenMP_CXX_FOUND )
+ add_custom_target(${SHORTCUT_PREFIX}all-openmp DEPENDS
+ ${PROJECT_NAME}_openmp
+ ${PROJECT_NAME}_openmp_opt
+ )
+endif()
+
+
+# --- all-hip---
+if(NOT ANDROID AND hip_FOUND)
+ add_custom_target(${SHORTCUT_PREFIX}all-hip DEPENDS
+ ${PROJECT_NAME}_hip
+ ${PROJECT_NAME}_hip_opt
+ )
+endif()
+
+
+# --- all-cuda---
+if(NOT ANDROID AND CUDAToolkit_FOUND)
+ add_custom_target(${SHORTCUT_PREFIX}all-cuda DEPENDS
+ ${PROJECT_NAME}_cuda
+ ${PROJECT_NAME}_cuda_opt
+ ${PROJECT_NAME}_cuda_lib
+ )
+endif()
\ No newline at end of file
diff --git a/gpu4s_benchmark/LRN_bench/Makefile b/gpu4s_benchmark/LRN_bench/Makefile
index 3163ed9f..614cd4c4 100644
--- a/gpu4s_benchmark/LRN_bench/Makefile
+++ b/gpu4s_benchmark/LRN_bench/Makefile
@@ -2,14 +2,16 @@
# Compilers
CC = g++
NVCC = /usr/local/cuda/bin/nvcc
-HIP = /opt/rocm/hip/bin/hipcc
+HIP = hipcc #ubuntu : /opt/rocm/hip/bin/hipcc
# the build target executable:
TARGET = lrn
# FLAGS
# CC compiler flags:
CFLAGS = -g
# NVCC compiler flags
-NVCCFLAGS = -arch compute_72 -code sm_72
+# Automatically targets the host machine's local GPU (Supported in CUDA 11.5.1+)
+# Note: For cross-compiling or older legacy gpu, set target (e.g., -arch=sm_72)
+NVCCFLAGS = -arch=native -O3
# CUDA FLAGS
CUFLAGS = -I/usr/local/cuda/include/ -L/usr/local/cuda/lib64 -lcuda -lcudart
# OPENCL FLAGS
@@ -52,13 +54,13 @@ all:
# End Main
# Shortcuts
.PHONY: all-bin
-all-bin: cuda cuda-opt cuda-lib opencl opencl-opt opencl-lib openmp openmp-opt openmp-lib hip hip-opt
+all-bin: cuda cuda-opt cuda-lib opencl opencl-opt openmp openmp-opt hip hip-opt
.PHONY: all-cuda
all-cuda: cuda cuda-opt cuda-lib
.PHONY: all-opencl
-all-opencl: opencl opencl-opt opencl-lib
+all-opencl: opencl opencl-opt
.PHONY: all-openmp
-all-openmp: openmp openmp-opt openmp-lib
+all-openmp: openmp openmp-opt
.PHONY: all-hip
all-hip: hip hip-opt
.PHONY: CUDA
@@ -79,14 +81,10 @@ OpenMP-opt: openmp-opt
Hip-opt: hip-opt
.PHONY: CUDA-lib
CUDA-lib: cuda-lib
-.PHONY: OpenCL-lib
-OpenCL-lib: opencl-lib
-.PHONY: OpenMP-lib
-OpenMP-lib: openmp-lib
# End Shortcuts
# CPU part
cpu_functions.o: $(CPUFUNCTIONFOLDER)cpu_functions.cpp
- $(CC) $(ENDIANFLAGS) -D$(DATATYPE) -c $(CPUFUNCTIONFOLDER)cpu_functions.cpp -o $(CPUFUNCTIONFOLDER)cpu_functions.o $(CFLAGS)
+ $(CC) $(ENDIANFLAGS) -D$(DATATYPE) -fPIC -c $(CPUFUNCTIONFOLDER)cpu_functions.cpp -o $(CPUFUNCTIONFOLDER)cpu_functions.o $(CFLAGS)
# End CPU
# CUDA part
@@ -214,17 +212,6 @@ main_cuda_lib: main.cpp lib_cuda_lib.o cpu_functions.o
# End CUDA library
-# OpenCL Part library
-opencl-lib: main_opencl_lib
-
-lib_opencl_lib.o: $(OPFOLDER)lib_opencl_lib.cpp
- $(CC) -D$(DATATYPE) -DOPENCL -c $(OPFOLDER)lib_opencl_lib.cpp -o $(OPFOLDER)lib_opencl_lib.o $(CFLAGS) $(OPFLAGS)
-
-main_opencl_lib: main.cpp lib_opencl_lib.o cpu_functions.o
- mkdir -p $(OUTPUTFOLDER)
- $(CC) -D$(DATATYPE) -DOPENCL main.cpp $(OPFOLDER)lib_opencl_lib.o $(CPUFUNCTIONFOLDER)cpu_functions.o -o $(OUTPUTFOLDER)$(TARGET)_opencl_lib_$(shell echo $(DATATYPE) | tr A-Z a-z) $(CFLAGS) $(OPFLAGS)
-
-# End OpenCL library
# Clean
.PHONY: clean
diff --git a/gpu4s_benchmark/LRN_bench/benchmark_library.h b/gpu4s_benchmark/LRN_bench/benchmark_library.h
index 575da53f..f2b14be5 100644
--- a/gpu4s_benchmark/LRN_bench/benchmark_library.h
+++ b/gpu4s_benchmark/LRN_bench/benchmark_library.h
@@ -1,110 +1,45 @@
-#include
-#include
-#include
-#include
-
-
-#ifdef INT
-typedef int bench_t;
-static const std::string type_kernel = "typedef int bench_t;\n";
-#elif FLOAT
-typedef float bench_t;
-static const std::string type_kernel = "typedef float bench_t;\n";
-const float K = 2;
-const float ALPHA = 10e-4;
-const float BETA = 0.75;
-#elif DOUBLE
-typedef double bench_t;
-static const std::string type_kernel = "#pragma OPENCL EXTENSION cl_khr_fp64 : enable\ntypedef double bench_t;\n";
-const double K = 2;
-const double ALPHA = 10e-4;
-const double BETA = 0.75;
-#endif
-
-#ifdef CUDA
-// CUDA lib
-#include
-#elif OPENCL
-// OpenCL lib
-#include
-#elif OPENMP
-// OpenMP lib
-#include
-#elif HIP
-// HIP part
-#include
-#else
-// CPU part
-#endif
-
-#ifdef INT
- typedef int bench_t;
- #define __ptype "%d"
-#elif FLOAT
- typedef float bench_t;
- #define __ptype "%f"
-#elif DOUBLE
- typedef double bench_t;
- #define __ptype "%f"
-#else
- // printf type helper, will resolve to %d or %f given the computed type
- #define __ptype "%f"
-#endif
-
-#ifndef BENCHMARK_H
-#define BENCHMARK_H
-
-struct GraficObject{
+/** * ====================================================================
+ * @file benchmark_library.h (./LRN_bench)
+ * @brief Specific memory structures and function overloads
+ * for the LRN benchmark.
+ * @paragraph License
+ * ESA-PL Strong Copyleft – v2.5
+ * ======================================================================= */
+#pragma once
+// Include all the benchmark common variable, struct, prototype, lib
+#include "benchmark_common.h"
+
+// ======= Benchmark local variable =======
+// --- Compute ---
+const bench_t K = 2;
+const bench_t ALPHA = 10e-4;
+const bench_t BETA = 0.75;
+
+struct GraficObject : public GraficCommon {
#ifdef CUDA
- // CUDA PART
- bench_t* d_A;
- bench_t* d_B;
- cudaEvent_t *start_memory_copy_device;
- cudaEvent_t *stop_memory_copy_device;
- cudaEvent_t *start_memory_copy_host;
- cudaEvent_t *stop_memory_copy_host;
- cudaEvent_t *start;
- cudaEvent_t *stop;
+ // CUDA PART
+ bench_t* d_A;
+ bench_t* d_B;
#elif OPENCL
- // OpenCL PART
- cl::Context *context;
- cl::CommandQueue *queue;
- cl::Device default_device;
- cl::Event *evt_copyA;
- cl::Event *evt_copyB;
- cl::Event *evt;
- cl::Buffer *d_A;
- cl::Buffer *d_B;
- #elif OPENMP
- // OpenMP part
- bench_t* d_A;
- bench_t* d_B;
+ // OpenCL PART
+ cl::Event *evt_copyA;
+ cl::Event *evt_copyB;
+ cl::Event *evt;
+ cl::Buffer *d_A;
+ cl::Buffer *d_B;
#elif HIP
- // Hip part --
- bench_t* d_A;
- bench_t* d_B;
- hipEvent_t *start_memory_copy_device;
- hipEvent_t *stop_memory_copy_device;
- hipEvent_t *start_memory_copy_host;
- hipEvent_t *stop_memory_copy_host;
- hipEvent_t *start;
- hipEvent_t *stop;
+ // Hip part
+ bench_t* d_A;
+ bench_t* d_B;
+ #elif OPENMP
+ // OpenMP part
+ bench_t* d_A;
+ bench_t* d_B;
#else
- // CPU part
- bench_t* d_A;
- bench_t* d_B;
+ // CPU part
+ bench_t* d_A;
+ bench_t* d_B;
#endif
- float elapsed_time;
};
-void init(GraficObject *device_object, char* device_name);
-void init(GraficObject *device_object, int platform, int device, char* device_name);
-bool device_memory_init(GraficObject *device_object, unsigned int size_a_matrix, unsigned int size_b_matrix);
-void copy_memory_to_device(GraficObject *device_object, bench_t* h_A, unsigned int size_a);
-void execute_kernel(GraficObject *device_object, unsigned int n, unsigned int m, unsigned int w);
-void copy_memory_to_host(GraficObject *device_object, bench_t* h_C, int size);
-float get_elapsed_time(GraficObject *device_object, bool csv_format, bool csv_format_timestamp, long int timestamp);
-void clean(GraficObject *device_object);
-
-
-#endif
\ No newline at end of file
+// --- Specefic overload of benchmarking function ---
diff --git a/gpu4s_benchmark/LRN_bench/cpu/lib_cpu.cpp b/gpu4s_benchmark/LRN_bench/cpu/lib_cpu.cpp
index de06241e..3c823815 100644
--- a/gpu4s_benchmark/LRN_bench/cpu/lib_cpu.cpp
+++ b/gpu4s_benchmark/LRN_bench/cpu/lib_cpu.cpp
@@ -3,77 +3,84 @@
#include
-void init(GraficObject *device_object, char* device_name)
+void init(GraficCommon* device_object, char* device_name)
{
init(device_object, 0,0, device_name);
}
-void init(GraficObject *device_object, int platform ,int device, char* device_name)
+void init(GraficCommon* device_object, int platform ,int device, char* device_name)
{
// TBD Feature: device name. -- Bulky generic platform implementation
strcpy(device_name,"Generic device");
}
-bool device_memory_init(GraficObject *device_object, unsigned int size_a_matrix, unsigned int size_b_matrix)
+bool device_memory_init(GraficCommon* device_object, unsigned int size_a_matrix, unsigned int size_b_matrix)
{
- device_object->d_B = (bench_t*) malloc ( size_b_matrix * sizeof(bench_t*));
+ GraficObject* deviceObj = static_cast(device_object);
+ deviceObj->d_B = (bench_t*) malloc ( size_b_matrix * sizeof(bench_t*));
return true;
}
-void copy_memory_to_device(GraficObject *device_object, bench_t* h_A, unsigned int size_a)
+void copy_memory_to_device(GraficCommon* device_object, bench_t* h_A, unsigned int size_a)
{
- device_object->d_A = h_A;
+ GraficObject* deviceObj = static_cast(device_object);
+ deviceObj->d_A = h_A;
}
-void execute_kernel(GraficObject *device_object, unsigned int n, unsigned int m, unsigned int w)
+void execute_kernel(GraficCommon* device_object, unsigned int n, unsigned int m, unsigned int w)
{
+ GraficObject* deviceObj = static_cast(device_object);
+ Clock kernelCLK;
+ kernelCLK.start();
- struct timespec start, end;
- clock_gettime(CLOCK_MONOTONIC_RAW, &start);
for (unsigned int i = 0; i < n; ++i)
{
for (unsigned int j = 0; j < n; ++j)
{
- device_object->d_B[i*n+j] = device_object->d_A[i*n+j]/pow((K+ALPHA*pow(device_object->d_A[i*n+j],2)),BETA);
+ deviceObj->d_B[i*n+j] = deviceObj->d_A[i*n+j]/pow((K+ALPHA*pow(deviceObj->d_A[i*n+j],2)),BETA);
}
}
// End compute timer
- clock_gettime(CLOCK_MONOTONIC_RAW, &end);
- device_object->elapsed_time = (end.tv_sec - start.tv_sec) * 1000 + (end.tv_nsec - start.tv_nsec) / 1000000;
+ kernelCLK.end();
+ deviceObj->elapsed_time = kernelCLK.getElapsedMS();
}
-void copy_memory_to_host(GraficObject *device_object, bench_t* h_C, int size)
-{
- memcpy(h_C, &device_object->d_B[0], sizeof(bench_t)*size);
+void copy_memory_to_host(GraficCommon* device_object, bench_t* h_C, int size)
+{
+ GraficObject* deviceObj = static_cast(device_object);
+ memcpy(h_C, &deviceObj->d_B[0], sizeof(bench_t)*size);
}
-float get_elapsed_time(GraficObject *device_object, bool csv_format, bool csv_format_timestamp, long int current_time)
+float get_elapsed_time(GraficCommon* device_object, bool csv_format, bool csv_format_timestamp, long int current_time)
{
+ GraficObject* deviceObj = static_cast(device_object);
if (csv_format_timestamp){
- printf("%.10f;%.10f;%.10f;%ld;\n", (bench_t) 0, device_object->elapsed_time * 1000.f, (bench_t) 0, current_time);
+ printf("%.10f;%.10f;%.10f;%ld;\n", (bench_t) 0, deviceObj->elapsed_time, (bench_t) 0, current_time);
}
else if (csv_format)
{
- printf("%.10f;%.10f;%.10f;\n", (bench_t) 0, device_object->elapsed_time * 1000.f, (bench_t) 0);
+ printf("%.10f;%.10f;%.10f;\n", (bench_t) 0, deviceObj->elapsed_time, (bench_t) 0);
}
else
{
+ //--- FIX: print te time in milliseconds
printf("Elapsed time Host->Device: %.10f milliseconds\n", (bench_t) 0);
- printf("Elapsed time kernel: %.10f milliseconds\n", device_object->elapsed_time * 1000.f);
+ printf("Elapsed time kernel: %.10f milliseconds\n", deviceObj->elapsed_time);
printf("Elapsed time Device->Host: %.10f milliseconds\n", (bench_t) 0);
}
- return device_object->elapsed_time * 1000.f;
+ return deviceObj->elapsed_time;
}
-void clean(GraficObject *device_object)
+void clean(GraficCommon* device_object)
{
- free(device_object->d_B);
+ GraficObject* deviceObj = static_cast(device_object);
+ free(deviceObj->d_B);
}
\ No newline at end of file
diff --git a/gpu4s_benchmark/LRN_bench/cpu_functions/cpu_functions.cpp b/gpu4s_benchmark/LRN_bench/cpu_functions/cpu_functions.cpp
index cccdfda6..15379fe9 100644
--- a/gpu4s_benchmark/LRN_bench/cpu_functions/cpu_functions.cpp
+++ b/gpu4s_benchmark/LRN_bench/cpu_functions/cpu_functions.cpp
@@ -26,7 +26,7 @@ void relu(const bench_t* A, bench_t* B, const unsigned int size)
}
else
{
- B[i*size+j];
+ B[i*size+j] = 0;
}
}
}
diff --git a/gpu4s_benchmark/LRN_bench/cpu_functions/cpu_functions.h b/gpu4s_benchmark/LRN_bench/cpu_functions/cpu_functions.h
index 79ee5963..a4b17f00 100644
--- a/gpu4s_benchmark/LRN_bench/cpu_functions/cpu_functions.h
+++ b/gpu4s_benchmark/LRN_bench/cpu_functions/cpu_functions.h
@@ -56,6 +56,8 @@ struct BenchmarkParameters{
bool csv_format = false;
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/cuda/cuda_common.cu b/gpu4s_benchmark/LRN_bench/cuda/cuda_common.cu
new file mode 100644
index 00000000..e8dddd41
--- /dev/null
+++ b/gpu4s_benchmark/LRN_bench/cuda/cuda_common.cu
@@ -0,0 +1,160 @@
+/** * ====================================================================
+ * @file cuda_common.cu (./LRN_bench)
+ * @brief Common CUDA platform initialization, device setup,
+ * profiling timer evaluation, and generic cleanup routines.
+ * @paragraph License
+ * ESA-PL Strong Copyleft – v2.5
+ * ======================================================================= */
+#include "../benchmark_library.h"
+
+void init(GraficCommon* device_object, char* device_name){
+ init(device_object, 0,0, device_name);
+}
+
+void init(GraficCommon* device_object, int platform ,int device, char* device_name){
+ GraficObject* deviceObj = static_cast(device_object);
+ cudaSetDevice(device);
+ cudaDeviceProp prop;
+ cudaGetDeviceProperties(&prop, device);
+ //printf("Using device: %s\n", prop.name);
+ strcpy(device_name,prop.name);
+ //event create
+ deviceObj->start = new cudaEvent_t;
+ deviceObj->stop = new cudaEvent_t;
+ deviceObj->start_memory_copy_device = new cudaEvent_t;
+ deviceObj->stop_memory_copy_device = new cudaEvent_t;
+ deviceObj->start_memory_copy_host = new cudaEvent_t;
+ deviceObj->stop_memory_copy_host= new cudaEvent_t;
+
+ cudaEventCreate(deviceObj->start);
+ cudaEventCreate(deviceObj->stop);
+ cudaEventCreate(deviceObj->start_memory_copy_device);
+ cudaEventCreate(deviceObj->stop_memory_copy_device);
+ cudaEventCreate(deviceObj->start_memory_copy_host);
+ cudaEventCreate(deviceObj->stop_memory_copy_host);
+}
+
+bool device_memory_init(GraficCommon* device_object, unsigned int size_a_matrix, unsigned int size_b_matrix){
+
+ GraficObject* deviceObj = static_cast(device_object);
+
+ // Allocate the device input vector A
+ cudaError_t err = cudaMalloc((void **)&deviceObj->d_A, size_a_matrix * sizeof(bench_t));
+ if (err != cudaSuccess) return false;
+
+ // Allocate the device input vector B
+ err = cudaMalloc((void **)&deviceObj->d_B, size_b_matrix * sizeof(bench_t));
+ if (err != cudaSuccess) return false;
+
+ return true;
+}
+
+void copy_memory_to_device(GraficCommon* device_object, bench_t* h_A, unsigned int size_a){
+ GraficObject* deviceObj = static_cast(device_object);
+ // host -> device
+ Clock h2dCLK;
+
+ // profilling start
+ h2dCLK.start();
+ cudaEventRecord(*deviceObj->start_memory_copy_device);
+
+ cudaError_t err = cudaMemcpy(deviceObj->d_A, h_A, sizeof(bench_t) * size_a, cudaMemcpyHostToDevice);
+ if (err != cudaSuccess)
+ {
+ fprintf(stderr, "Failed to copy vector A from host to device (error code %s)!\n", cudaGetErrorString(err));
+ return;
+ }
+
+ // profilling end
+ cudaEventRecord(*deviceObj->stop_memory_copy_device);
+ h2dCLK.end();
+
+ // store the h2d time
+ deviceObj->h2d_elapsed_time = h2dCLK.getElapsedMS();
+}
+
+
+void copy_memory_to_host(GraficCommon* device_object, bench_t* h_C, int size){
+ GraficObject* deviceObj = static_cast(device_object);
+ // device -> host
+ Clock d2hCLK;
+
+ // profilling start
+ d2hCLK.start();
+ cudaEventRecord(*deviceObj->start_memory_copy_host);
+
+ cudaError_t err = cudaMemcpy(h_C, deviceObj->d_B, size * sizeof(bench_t), cudaMemcpyDeviceToHost);
+ if (err != cudaSuccess)
+ {
+ fprintf(stderr, "Failed to copy vector B from device to host (error code %s)!\n", cudaGetErrorString(err));
+ return;
+ }
+
+ // profilling end
+ cudaEventRecord(*deviceObj->stop_memory_copy_host);
+ d2hCLK.end();
+
+ // store the hd2h time
+ deviceObj->d2h_elapsed_time = d2hCLK.getElapsedMS();
+ }
+
+float get_elapsed_time(GraficCommon* device_object, bool csv_format, bool csv_format_timestamp, long int current_time){
+ GraficObject* deviceObj = static_cast(device_object);
+ cudaEventSynchronize(*deviceObj->stop_memory_copy_host); // wait
+
+ float milliseconds_h_d = 0, milliseconds = 0, milliseconds_d_h = 0;
+
+ if (deviceObj->profiling_clock)
+ {
+ // --- FIX: Use instead of CLBlast event profiling (unreliable on PROFILING_CLOCK) ---
+ milliseconds_h_d = deviceObj->h2d_elapsed_time;
+ milliseconds = deviceObj->elapsed_time;
+ milliseconds_d_h = deviceObj->d2h_elapsed_time;
+ }else{
+ // memory transfer time host-device
+ cudaEventElapsedTime(&milliseconds_h_d, *deviceObj->start_memory_copy_device, *deviceObj->stop_memory_copy_device);
+ // kernel time
+ cudaEventElapsedTime(&milliseconds, *deviceObj->start, *deviceObj->stop);
+ // memory transfer time device-host
+ cudaEventElapsedTime(&milliseconds_d_h, *deviceObj->start_memory_copy_host, *deviceObj->stop_memory_copy_host);
+ }
+
+ if (csv_format_timestamp){
+ printf("%.10f;%.10f;%.10f;%ld;\n", milliseconds_h_d,milliseconds,milliseconds_d_h, current_time);
+ }
+ else if (csv_format){
+ printf("%.10f;%.10f;%.10f;\n", milliseconds_h_d,milliseconds,milliseconds_d_h);
+ }else{
+ printf("profiling mode: %s\n", deviceObj->profiling_clock ? "CLOCK" : "GPU");
+ printf("Elapsed time Host->Device: %.10f milliseconds\n", milliseconds_h_d);
+ printf("Elapsed time kernel: %.10f milliseconds\n", milliseconds);
+ printf("Elapsed time Device->Host: %.10f milliseconds\n", milliseconds_d_h);
+ }
+ return milliseconds;
+}
+
+void clean(GraficCommon* device_object){
+ GraficObject* deviceObj = static_cast(device_object);
+
+ cudaError_t err = cudaFree(deviceObj->d_A);
+ if (err != cudaSuccess)
+ {
+ fprintf(stderr, "Failed to free device vector A (error code %s)!\n", cudaGetErrorString(err));
+ return;
+ }
+
+ err = cudaFree(deviceObj->d_B);
+ if (err != cudaSuccess)
+ {
+ fprintf(stderr, "Failed to free device vector B (error code %s)!\n", cudaGetErrorString(err));
+ return;
+ }
+
+ // delete events
+ delete deviceObj->start;
+ delete deviceObj->stop;
+ delete deviceObj->start_memory_copy_device;
+ delete deviceObj->stop_memory_copy_device;
+ delete deviceObj->start_memory_copy_host;
+ delete deviceObj->stop_memory_copy_host;
+}
diff --git a/gpu4s_benchmark/LRN_bench/cuda/lib_cuda.cu b/gpu4s_benchmark/LRN_bench/cuda/lib_cuda.cu
index 101c6cdf..1ef938af 100644
--- a/gpu4s_benchmark/LRN_bench/cuda/lib_cuda.cu
+++ b/gpu4s_benchmark/LRN_bench/cuda/lib_cuda.cu
@@ -7,8 +7,8 @@
* Computes the vector addition of A and B into C. The 3 vectors have the same
* number of elements numElements.
*/
-//#define BLOCK_SIZE 32
-__global__ void
+
+ __global__ void
lrn_kernel(const bench_t *A, bench_t *B, const int size)
{
unsigned int i = blockIdx.x * blockDim.x + threadIdx.x;
@@ -24,126 +24,26 @@ lrn_kernel(const bench_t *A, bench_t *B, const int size)
}
}
-void init(GraficObject *device_object, char* device_name){
- init(device_object, 0,0, device_name);
-}
-
-void init(GraficObject *device_object, int platform ,int device, char* device_name){
- cudaSetDevice(device);
- cudaDeviceProp prop;
- cudaGetDeviceProperties(&prop, device);
- //printf("Using device: %s\n", prop.name);
- strcpy(device_name,prop.name);
- //event create
- device_object->start = new cudaEvent_t;
- device_object->stop = new cudaEvent_t;
- device_object->start_memory_copy_device = new cudaEvent_t;
- device_object->stop_memory_copy_device = new cudaEvent_t;
- device_object->start_memory_copy_host = new cudaEvent_t;
- device_object->stop_memory_copy_host= new cudaEvent_t;
-
- cudaEventCreate(device_object->start);
- cudaEventCreate(device_object->stop);
- cudaEventCreate(device_object->start_memory_copy_device);
- cudaEventCreate(device_object->stop_memory_copy_device);
- cudaEventCreate(device_object->start_memory_copy_host);
- cudaEventCreate(device_object->stop_memory_copy_host);
-}
-
-
-bool device_memory_init(GraficObject *device_object, unsigned int size_a_matrix, unsigned int size_b_matrix){
-
- // Allocate the device input vector A
- cudaError_t err = cudaSuccess;
- err = cudaMalloc((void **)&device_object->d_A, size_a_matrix * sizeof(bench_t));
-
- if (err != cudaSuccess)
- {
- return false;
- }
-
- // Allocate the device input vector B
- err = cudaMalloc((void **)&device_object->d_B, size_b_matrix * sizeof(bench_t));
-
- if (err != cudaSuccess)
- {
- return false;
- }
- return true;
-}
-
-void copy_memory_to_device(GraficObject *device_object, bench_t* h_A, unsigned int size_a){
- cudaEventRecord(*device_object->start_memory_copy_device);
- cudaError_t err = cudaMemcpy(device_object->d_A, h_A, sizeof(bench_t) * size_a, cudaMemcpyHostToDevice);
- if (err != cudaSuccess)
- {
- fprintf(stderr, "Failed to copy vector A from host to device (error code %s)!\n", cudaGetErrorString(err));
- return;
- }
- cudaEventRecord(*device_object->stop_memory_copy_device);
-}
-void execute_kernel(GraficObject *device_object, unsigned int n, unsigned int m,unsigned int w){
+void execute_kernel(GraficCommon* device_object, unsigned int n, unsigned int m,unsigned int w){
+ GraficObject* deviceObj = static_cast(device_object);
dim3 dimBlock(BLOCK_SIZE, BLOCK_SIZE);
dim3 dimGrid(ceil(float(n)/dimBlock.x), ceil(float(m)/dimBlock.y));
- cudaEventRecord(*device_object->start);
- lrn_kernel<<>>(device_object->d_A, device_object->d_B, n);
- cudaEventRecord(*device_object->stop);
-}
-
-void copy_memory_to_host(GraficObject *device_object, bench_t* h_C, int size){
- cudaEventRecord(*device_object->start_memory_copy_host);
- cudaMemcpy(h_C, device_object->d_B, size * sizeof(bench_t), cudaMemcpyDeviceToHost);
- cudaEventRecord(*device_object->stop_memory_copy_host);
- }
-
-float get_elapsed_time(GraficObject *device_object, bool csv_format, bool csv_format_timestamp, long int current_time){
- cudaEventSynchronize(*device_object->stop_memory_copy_host);
- float milliseconds_h_d = 0, milliseconds = 0, milliseconds_d_h = 0;
- // memory transfer time host-device
- cudaEventElapsedTime(&milliseconds_h_d, *device_object->start_memory_copy_device, *device_object->stop_memory_copy_device);
- // kernel time
- cudaEventElapsedTime(&milliseconds, *device_object->start, *device_object->stop);
- // memory transfer time device-host
- cudaEventElapsedTime(&milliseconds_d_h, *device_object->start_memory_copy_host, *device_object->stop_memory_copy_host);
-
- if (csv_format_timestamp){
- printf("%.10f;%.10f;%.10f;%ld;\n", milliseconds_h_d,milliseconds,milliseconds_d_h, current_time);
- }
- else if (csv_format){
- printf("%.10f;%.10f;%.10f;\n", milliseconds_h_d,milliseconds,milliseconds_d_h);
- }else{
- printf("Elapsed time Host->Device: %.10f milliseconds\n", milliseconds_h_d);
- printf("Elapsed time kernel: %.10f milliseconds\n", milliseconds);
- printf("Elapsed time Device->Host: %.10f milliseconds\n", milliseconds_d_h);
- }
- return milliseconds;
-}
+ // kernel time execution
+ Clock kernelCLK;
-void clean(GraficObject *device_object){
- cudaError_t err = cudaSuccess;
- err = cudaFree(device_object->d_A);
+ // profilling start
+ kernelCLK.start();
+ cudaEventRecord(*deviceObj->start);
- if (err != cudaSuccess)
- {
- fprintf(stderr, "Failed to free device vector A (error code %s)!\n", cudaGetErrorString(err));
- return;
- }
+ lrn_kernel<<>>(deviceObj->d_A, deviceObj->d_B, n);
- err = cudaFree(device_object->d_B);
+ // profilling end
+ cudaEventRecord(*deviceObj->stop);
+ cudaDeviceSynchronize();
+ kernelCLK.end();
- if (err != cudaSuccess)
- {
- fprintf(stderr, "Failed to free device vector B (error code %s)!\n", cudaGetErrorString(err));
- return;
- }
-
-
- // delete events
- delete device_object->start;
- delete device_object->stop;
- delete device_object->start_memory_copy_device;
- delete device_object->stop_memory_copy_device;
- delete device_object->start_memory_copy_host;
- delete device_object->stop_memory_copy_host;
+ // store the kernel time
+ deviceObj->elapsed_time = kernelCLK.getElapsedMS();
}
+
diff --git a/gpu4s_benchmark/LRN_bench/cuda/lib_cuda_lib.cu b/gpu4s_benchmark/LRN_bench/cuda/lib_cuda_lib.cu
index d62c6baf..556f9fb3 100644
--- a/gpu4s_benchmark/LRN_bench/cuda/lib_cuda_lib.cu
+++ b/gpu4s_benchmark/LRN_bench/cuda/lib_cuda_lib.cu
@@ -1,6 +1,7 @@
#include
#include "../benchmark_library.h"
+
#define checkCUDNN(expression) \
{ \
cudnnStatus_t status = (expression); \
@@ -18,73 +19,21 @@
#elif DOUBLE
#define CUDNNTYPE CUDNN_DATA_DOUBLE
#endif
-void init(GraficObject *device_object, char* device_name){
- init(device_object, 0,0, device_name);
-}
-
-void init(GraficObject *device_object, int platform ,int device, char* device_name){
- cudaSetDevice(device);
- cudaDeviceProp prop;
- cudaGetDeviceProperties(&prop, device);
- //printf("Using device: %s\n", prop.name);
- strcpy(device_name,prop.name);
- //event create
- device_object->start = new cudaEvent_t;
- device_object->stop = new cudaEvent_t;
- device_object->start_memory_copy_device = new cudaEvent_t;
- device_object->stop_memory_copy_device = new cudaEvent_t;
- device_object->start_memory_copy_host = new cudaEvent_t;
- device_object->stop_memory_copy_host= new cudaEvent_t;
-
- cudaEventCreate(device_object->start);
- cudaEventCreate(device_object->stop);
- cudaEventCreate(device_object->start_memory_copy_device);
- cudaEventCreate(device_object->stop_memory_copy_device);
- cudaEventCreate(device_object->start_memory_copy_host);
- cudaEventCreate(device_object->stop_memory_copy_host);
-}
-
-
-bool device_memory_init(GraficObject *device_object, unsigned int size_a_matrix, unsigned int size_b_matrix){
-
- // Allocate the device input vector A
- cudaError_t err = cudaSuccess;
- err = cudaMalloc((void **)&device_object->d_A, size_a_matrix * sizeof(bench_t));
- if (err != cudaSuccess)
- {
- return false;
- }
-
- // Allocate the device input vector B
- err = cudaMalloc((void **)&device_object->d_B, size_b_matrix * sizeof(bench_t));
-
- if (err != cudaSuccess)
- {
- return false;
- }
- return true;
-}
-
-void copy_memory_to_device(GraficObject *device_object, bench_t* h_A, unsigned int size_a){
- cudaEventRecord(*device_object->start_memory_copy_device);
- cudaError_t err = cudaMemcpy(device_object->d_A, h_A, sizeof(bench_t) * size_a, cudaMemcpyHostToDevice);
- if (err != cudaSuccess)
- {
- fprintf(stderr, "Failed to copy vector A from host to device (error code %s)!\n", cudaGetErrorString(err));
- return;
- }
-
- cudaEventRecord(*device_object->stop_memory_copy_device);
-}
-void execute_kernel(GraficObject *device_object, unsigned int n, unsigned int m,unsigned int w){
- // CUDNN settings
+void execute_kernel(GraficCommon* device_object, unsigned int n, unsigned int m,unsigned int w){
+ GraficObject* deviceObj = static_cast(device_object);
+ // CUDNN settings
const bench_t alf = 1;
const bench_t bet = 0;
cudnnHandle_t cudnn;
+ // kernel time execution
+ Clock kernelCLK;
- cudaEventRecord(*device_object->start);
+ // profilling start
+ kernelCLK.start();
+ cudaEventRecord(*deviceObj->start);
checkCUDNN(cudnnCreate(&cudnn));
+
// create input tensor
cudnnTensorDescriptor_t input_descriptor;
checkCUDNN(cudnnCreateTensorDescriptor(&input_descriptor));
@@ -120,73 +69,22 @@ void execute_kernel(GraficObject *device_object, unsigned int n, unsigned int m,
CUDNN_LRN_CROSS_CHANNEL_DIM1,
&alf,
input_descriptor,
- device_object->d_A,
+ deviceObj->d_A,
&bet,
output_descriptor,
- device_object->d_B));
+ deviceObj->d_B));
- cudaEventRecord(*device_object->stop);
+ // profilling end
+ cudaEventRecord(*deviceObj->stop);
+ cudaDeviceSynchronize();
+ kernelCLK.end();
+
+ // store the kernel time
+ deviceObj->elapsed_time = kernelCLK.getElapsedMS();
+
// destroy cuDNN
cudnnDestroyTensorDescriptor(input_descriptor);
cudnnDestroyTensorDescriptor(output_descriptor);
cudnnDestroyLRNDescriptor(lrn_descriptor);
-
cudnnDestroy(cudnn);
}
-
-void copy_memory_to_host(GraficObject *device_object, bench_t* h_C, int size){
- cudaEventRecord(*device_object->start_memory_copy_host);
- cudaMemcpy(h_C, device_object->d_B, size * sizeof(bench_t), cudaMemcpyDeviceToHost);
- cudaEventRecord(*device_object->stop_memory_copy_host);
- }
-
-float get_elapsed_time(GraficObject *device_object, bool csv_format, bool csv_format_timestamp, long int current_time){
- cudaEventSynchronize(*device_object->stop_memory_copy_host);
- float milliseconds_h_d = 0, milliseconds = 0, milliseconds_d_h = 0;
- // memory transfer time host-device
- cudaEventElapsedTime(&milliseconds_h_d, *device_object->start_memory_copy_device, *device_object->stop_memory_copy_device);
- // kernel time
- cudaEventElapsedTime(&milliseconds, *device_object->start, *device_object->stop);
- // memory transfer time device-host
- cudaEventElapsedTime(&milliseconds_d_h, *device_object->start_memory_copy_host, *device_object->stop_memory_copy_host);
-
- if (csv_format_timestamp){
- printf("%.10f;%.10f;%.10f;%ld;\n", milliseconds_h_d,milliseconds,milliseconds_d_h, current_time);
- }
- else if (csv_format){
- printf("%.10f;%.10f;%.10f;\n", milliseconds_h_d,milliseconds,milliseconds_d_h);
- }else{
- printf("Elapsed time Host->Device: %.10f milliseconds\n", milliseconds_h_d);
- printf("Elapsed time kernel: %.10f milliseconds\n", milliseconds);
- printf("Elapsed time Device->Host: %.10f milliseconds\n", milliseconds_d_h);
- }
- return milliseconds;
-}
-
-void clean(GraficObject *device_object){
- cudaError_t err = cudaSuccess;
- err = cudaFree(device_object->d_A);
-
- if (err != cudaSuccess)
- {
- fprintf(stderr, "Failed to free device vector A (error code %s)!\n", cudaGetErrorString(err));
- return;
- }
-
- err = cudaFree(device_object->d_B);
-
- if (err != cudaSuccess)
- {
- fprintf(stderr, "Failed to free device vector B (error code %s)!\n", cudaGetErrorString(err));
- return;
- }
-
-
- // delete events
- delete device_object->start;
- delete device_object->stop;
- delete device_object->start_memory_copy_device;
- delete device_object->stop_memory_copy_device;
- delete device_object->start_memory_copy_host;
- delete device_object->stop_memory_copy_host;
-}
\ No newline at end of file
diff --git a/gpu4s_benchmark/LRN_bench/cuda/lib_cuda_opt.cu b/gpu4s_benchmark/LRN_bench/cuda/lib_cuda_opt.cu
index e9e04073..c5224b41 100644
--- a/gpu4s_benchmark/LRN_bench/cuda/lib_cuda_opt.cu
+++ b/gpu4s_benchmark/LRN_bench/cuda/lib_cuda_opt.cu
@@ -7,9 +7,9 @@
* Computes the vector addition of A and B into C. The 3 vectors have the same
* number of elements numElements.
*/
-//#define BLOCK_SIZE 1024
+
__global__ void
-relu_kernel(const bench_t *A, bench_t *B, const int size)
+lrn_kernel(const bench_t *A, bench_t *B, const int size)
{
unsigned int i = blockIdx.x * blockDim.x + threadIdx.x;
if (i < (size * size)){
@@ -25,126 +25,25 @@ relu_kernel(const bench_t *A, bench_t *B, const int size)
}
}
-void init(GraficObject *device_object, char* device_name){
- init(device_object, 0,0, device_name);
-}
-
-void init(GraficObject *device_object, int platform ,int device, char* device_name){
- cudaSetDevice(device);
- cudaDeviceProp prop;
- cudaGetDeviceProperties(&prop, device);
- //printf("Using device: %s\n", prop.name);
- strcpy(device_name,prop.name);
- //event create
- device_object->start = new cudaEvent_t;
- device_object->stop = new cudaEvent_t;
- device_object->start_memory_copy_device = new cudaEvent_t;
- device_object->stop_memory_copy_device = new cudaEvent_t;
- device_object->start_memory_copy_host = new cudaEvent_t;
- device_object->stop_memory_copy_host= new cudaEvent_t;
-
- cudaEventCreate(device_object->start);
- cudaEventCreate(device_object->stop);
- cudaEventCreate(device_object->start_memory_copy_device);
- cudaEventCreate(device_object->stop_memory_copy_device);
- cudaEventCreate(device_object->start_memory_copy_host);
- cudaEventCreate(device_object->stop_memory_copy_host);
-}
-
-
-bool device_memory_init(GraficObject *device_object, unsigned int size_a_matrix, unsigned int size_b_matrix){
-
- // Allocate the device input vector A
- cudaError_t err = cudaSuccess;
- err = cudaMalloc((void **)&device_object->d_A, size_a_matrix * sizeof(bench_t));
-
- if (err != cudaSuccess)
- {
- return false;
- }
-
- // Allocate the device input vector B
- err = cudaMalloc((void **)&device_object->d_B, size_b_matrix * sizeof(bench_t));
-
- if (err != cudaSuccess)
- {
- return false;
- }
- return true;
-}
-
-void copy_memory_to_device(GraficObject *device_object, bench_t* h_A, unsigned int size_a){
- cudaEventRecord(*device_object->start_memory_copy_device);
- cudaError_t err = cudaMemcpy(device_object->d_A, h_A, sizeof(bench_t) * size_a, cudaMemcpyHostToDevice);
- if (err != cudaSuccess)
- {
- fprintf(stderr, "Failed to copy vector A from host to device (error code %s)!\n", cudaGetErrorString(err));
- return;
- }
-
- cudaEventRecord(*device_object->stop_memory_copy_device);
-}
-void execute_kernel(GraficObject *device_object, unsigned int n, unsigned int m,unsigned int w){
+void execute_kernel(GraficCommon* device_object, unsigned int n, unsigned int m,unsigned int w){
+ GraficObject* deviceObj = static_cast(device_object);
dim3 dimBlock(BLOCK_SIZE);
dim3 dimGrid(ceil(float((n*n))/(dimBlock.x)));
- cudaEventRecord(*device_object->start);
- relu_kernel<<>>(device_object->d_A, device_object->d_B, n);
- cudaEventRecord(*device_object->stop);
-}
+ // kernel time execution
+ Clock kernelCLK;
-void copy_memory_to_host(GraficObject *device_object, bench_t* h_C, int size){
- cudaEventRecord(*device_object->start_memory_copy_host);
- cudaMemcpy(h_C, device_object->d_B, size * sizeof(bench_t), cudaMemcpyDeviceToHost);
- cudaEventRecord(*device_object->stop_memory_copy_host);
- }
+ // profilling start
+ kernelCLK.start();
+ cudaEventRecord(*deviceObj->start);
-float get_elapsed_time(GraficObject *device_object, bool csv_format, bool csv_format_timestamp, long int current_time){
- cudaEventSynchronize(*device_object->stop_memory_copy_host);
- float milliseconds_h_d = 0, milliseconds = 0, milliseconds_d_h = 0;
- // memory transfer time host-device
- cudaEventElapsedTime(&milliseconds_h_d, *device_object->start_memory_copy_device, *device_object->stop_memory_copy_device);
- // kernel time
- cudaEventElapsedTime(&milliseconds, *device_object->start, *device_object->stop);
- // memory transfer time device-host
- cudaEventElapsedTime(&milliseconds_d_h, *device_object->start_memory_copy_host, *device_object->stop_memory_copy_host);
+ lrn_kernel<<>>(deviceObj->d_A, deviceObj->d_B, n);
- if (csv_format_timestamp){
- printf("%.10f;%.10f;%.10f;%ld;\n", milliseconds_h_d,milliseconds,milliseconds_d_h, current_time);
- }
- else if (csv_format){
- printf("%.10f;%.10f;%.10f;\n", milliseconds_h_d,milliseconds,milliseconds_d_h);
- }else{
- printf("Elapsed time Host->Device: %.10f milliseconds\n", milliseconds_h_d);
- printf("Elapsed time kernel: %.10f milliseconds\n", milliseconds);
- printf("Elapsed time Device->Host: %.10f milliseconds\n", milliseconds_d_h);
- }
- return milliseconds;
-}
-
-void clean(GraficObject *device_object){
- cudaError_t err = cudaSuccess;
- err = cudaFree(device_object->d_A);
+ // profilling end
+ cudaEventRecord(*deviceObj->stop);
+ cudaDeviceSynchronize();
+ kernelCLK.end();
- if (err != cudaSuccess)
- {
- fprintf(stderr, "Failed to free device vector A (error code %s)!\n", cudaGetErrorString(err));
- return;
- }
-
- err = cudaFree(device_object->d_B);
-
- if (err != cudaSuccess)
- {
- fprintf(stderr, "Failed to free device vector B (error code %s)!\n", cudaGetErrorString(err));
- return;
- }
-
-
- // delete events
- delete device_object->start;
- delete device_object->stop;
- delete device_object->start_memory_copy_device;
- delete device_object->stop_memory_copy_device;
- delete device_object->start_memory_copy_host;
- delete device_object->stop_memory_copy_host;
+ // store the kernel time
+ deviceObj->elapsed_time = kernelCLK.getElapsedMS();
}
+
diff --git a/gpu4s_benchmark/LRN_bench/hip/hip_common.cpp b/gpu4s_benchmark/LRN_bench/hip/hip_common.cpp
new file mode 100644
index 00000000..7cf499fb
--- /dev/null
+++ b/gpu4s_benchmark/LRN_bench/hip/hip_common.cpp
@@ -0,0 +1,165 @@
+/** * ====================================================================
+ * @file hip_common.cpp (./LRN_bench)
+ * @brief Common HIP platform initialization, device setup,
+ * profiling timer evaluation, and generic cleanup routines.
+ * @paragraph License
+ * ESA-PL Strong Copyleft – v2.5
+ * ======================================================================= */
+#include "../benchmark_library.h"
+
+void init(GraficCommon* device_object, char* device_name){
+ init(device_object, 0,0, device_name);
+}
+
+void init(GraficCommon* device_object, int platform ,int device, char* device_name){
+ GraficObject* deviceObj = static_cast(device_object);
+ (void)hipSetDevice(device);
+ hipDeviceProp_t prop;
+ (void)hipGetDeviceProperties(&prop, device);
+ //printf("Using device: %s\n", prop.name);
+ strcpy(device_name,prop.name);
+ //event create
+ deviceObj->start = new hipEvent_t;
+ deviceObj->stop = new hipEvent_t;
+ deviceObj->start_memory_copy_device = new hipEvent_t;
+ deviceObj->stop_memory_copy_device = new hipEvent_t;
+ deviceObj->start_memory_copy_host = new hipEvent_t;
+ deviceObj->stop_memory_copy_host= new hipEvent_t;
+
+ (void)hipEventCreate(deviceObj->start);
+ (void)hipEventCreate(deviceObj->stop);
+ (void)hipEventCreate(deviceObj->start_memory_copy_device);
+ (void)hipEventCreate(deviceObj->stop_memory_copy_device);
+ (void)hipEventCreate(deviceObj->start_memory_copy_host);
+ (void)hipEventCreate(deviceObj->stop_memory_copy_host);
+}
+
+bool device_memory_init(GraficCommon* device_object, unsigned int size_a_matrix, unsigned int size_b_matrix){
+ GraficObject* deviceObj = static_cast(device_object);
+
+ // FIX: create a dumb obj to sync the profling clock
+ if (deviceObj->profiling_clock)
+ {
+ hipDumbSync();
+ }
+
+ // Allocate the device input vector A
+ hipError_t err = hipMalloc((void **)&deviceObj->d_A, size_a_matrix * sizeof(bench_t));
+ if (err != hipSuccess) return false;
+
+ // Allocate the device input vector B
+ err = hipMalloc((void **)&deviceObj->d_B, size_b_matrix * sizeof(bench_t));
+ if (err != hipSuccess) return false;
+
+ return true;
+}
+
+void copy_memory_to_device(GraficCommon* device_object, bench_t* h_A, unsigned int size_a){
+ GraficObject* deviceObj = static_cast(device_object);
+ // host -> device
+ Clock h2dCLK;
+
+ // profilling start
+ h2dCLK.start();
+ (void)hipEventRecord(*deviceObj->start_memory_copy_device);
+
+ hipError_t err = hipMemcpy(deviceObj->d_A, h_A, sizeof(bench_t) * size_a, hipMemcpyHostToDevice);
+ if (err != hipSuccess)
+ {
+ fprintf(stderr, "Failed to copy vector A from host to device (error code %s)!\n", hipGetErrorString(err));
+ return;
+ }
+
+ // profilling end
+ (void)hipEventRecord(*deviceObj->stop_memory_copy_device);
+ h2dCLK.end();
+
+ // store the h2d time
+ deviceObj->h2d_elapsed_time = h2dCLK.getElapsedMS();
+}
+
+
+void copy_memory_to_host(GraficCommon* device_object, bench_t* h_C, int size){
+ GraficObject* deviceObj = static_cast(device_object);
+ // device -> host
+ Clock d2hCLK;
+
+ // profilling start
+ d2hCLK.start();
+ (void)hipEventRecord(*deviceObj->start_memory_copy_host);
+
+ hipError_t err = hipMemcpy(h_C, deviceObj->d_B, size * sizeof(bench_t), hipMemcpyDeviceToHost);
+ if (err != hipSuccess)
+ {
+ fprintf(stderr, "Failed to copy vector B from device to host (error code %s)!\n", hipGetErrorString(err));
+ return;
+ }
+
+ // profilling end
+ (void)hipEventRecord(*deviceObj->stop_memory_copy_host);
+ d2hCLK.end();
+
+ // store the hd2h time
+ deviceObj->d2h_elapsed_time = d2hCLK.getElapsedMS();
+}
+
+float get_elapsed_time(GraficCommon* device_object, bool csv_format, bool csv_format_timestamp, long int current_time){
+ GraficObject* deviceObj = static_cast(device_object);
+ (void)hipEventSynchronize(*deviceObj->stop_memory_copy_host); // wait
+
+ float milliseconds_h_d = 0, milliseconds = 0, milliseconds_d_h = 0;
+
+ if (deviceObj->profiling_clock)
+ {
+ // --- FIX: Use instead of CLBlast event profiling (unreliable on PROFILING_CLOCK) ---
+ milliseconds_h_d = deviceObj->h2d_elapsed_time;
+ milliseconds = deviceObj->elapsed_time;
+ milliseconds_d_h = deviceObj->d2h_elapsed_time;
+ }else{
+ // memory transfer time host-device
+ (void)hipEventElapsedTime(&milliseconds_h_d, *deviceObj->start_memory_copy_device, *deviceObj->stop_memory_copy_device);
+ // kernel time
+ (void)hipEventElapsedTime(&milliseconds, *deviceObj->start, *deviceObj->stop);
+ // memory transfer time device-host
+ (void)hipEventElapsedTime(&milliseconds_d_h, *deviceObj->start_memory_copy_host, *deviceObj->stop_memory_copy_host);
+ }
+
+ if (csv_format_timestamp){
+ printf("%.10f;%.10f;%.10f;%ld;\n", milliseconds_h_d,milliseconds,milliseconds_d_h, current_time);
+ }
+ else if (csv_format){
+ printf("%.10f;%.10f;%.10f;\n", milliseconds_h_d,milliseconds,milliseconds_d_h);
+ }else{
+ printf("profiling mode: %s\n", deviceObj->profiling_clock ? "CLOCK" : "GPU");
+ printf("Elapsed time Host->Device: %.10f milliseconds\n", milliseconds_h_d);
+ printf("Elapsed time kernel: %.10f milliseconds\n", milliseconds);
+ printf("Elapsed time Device->Host: %.10f milliseconds\n", milliseconds_d_h);
+ }
+ return milliseconds;
+}
+
+void clean(GraficCommon* device_object){
+ GraficObject* deviceObj = static_cast(device_object);
+
+ hipError_t err = hipFree(deviceObj->d_A);
+ if (err != hipSuccess)
+ {
+ fprintf(stderr, "Failed to free device vector A (error code %s)!\n", hipGetErrorString(err));
+ return;
+ }
+
+ err = hipFree(deviceObj->d_B);
+ if (err != hipSuccess)
+ {
+ fprintf(stderr, "Failed to free device vector B (error code %s)!\n", hipGetErrorString(err));
+ return;
+ }
+
+ // delete events
+ delete deviceObj->start;
+ delete deviceObj->stop;
+ delete deviceObj->start_memory_copy_device;
+ delete deviceObj->stop_memory_copy_device;
+ delete deviceObj->start_memory_copy_host;
+ delete deviceObj->stop_memory_copy_host;
+}
\ No newline at end of file
diff --git a/gpu4s_benchmark/LRN_bench/hip/lib_hip.cpp b/gpu4s_benchmark/LRN_bench/hip/lib_hip.cpp
index 94c04239..2e3b08c6 100644
--- a/gpu4s_benchmark/LRN_bench/hip/lib_hip.cpp
+++ b/gpu4s_benchmark/LRN_bench/hip/lib_hip.cpp
@@ -1,15 +1,13 @@
-#include "hip/hip_runtime.h"
#include "../benchmark_library.h"
#include "math.h"
-
/**
* CUDA Kernel Device code
*
* Computes the vector addition of A and B into C. The 3 vectors have the same
* number of elements numElements.
*/
-//#define BLOCK_SIZE 32
-__global__ void
+
+ __global__ void
lrn_kernel(const bench_t *A, bench_t *B, const int size)
{
unsigned int i = blockIdx.x * blockDim.x + threadIdx.x;
@@ -25,126 +23,24 @@ lrn_kernel(const bench_t *A, bench_t *B, const int size)
}
}
-void init(GraficObject *device_object, char* device_name){
- init(device_object, 0,0, device_name);
-}
-
-void init(GraficObject *device_object, int platform ,int device, char* device_name){
- hipSetDevice(device);
- hipDeviceProp_t prop;
- hipGetDeviceProperties(&prop, device);
- //printf("Using device: %s\n", prop.name);
- strcpy(device_name,prop.name);
- //event create
- device_object->start = new hipEvent_t;
- device_object->stop = new hipEvent_t;
- device_object->start_memory_copy_device = new hipEvent_t;
- device_object->stop_memory_copy_device = new hipEvent_t;
- device_object->start_memory_copy_host = new hipEvent_t;
- device_object->stop_memory_copy_host= new hipEvent_t;
-
- hipEventCreate(device_object->start);
- hipEventCreate(device_object->stop);
- hipEventCreate(device_object->start_memory_copy_device);
- hipEventCreate(device_object->stop_memory_copy_device);
- hipEventCreate(device_object->start_memory_copy_host);
- hipEventCreate(device_object->stop_memory_copy_host);
-}
-
-
-bool device_memory_init(GraficObject *device_object, unsigned int size_a_matrix, unsigned int size_b_matrix){
-
- // Allocate the device input vector A
- hipError_t err = hipSuccess;
- err = hipMalloc((void **)&device_object->d_A, size_a_matrix * sizeof(bench_t));
-
- if (err != hipSuccess)
- {
- return false;
- }
-
- // Allocate the device input vector B
- err = hipMalloc((void **)&device_object->d_B, size_b_matrix * sizeof(bench_t));
-
- if (err != hipSuccess)
- {
- return false;
- }
- return true;
-}
-
-void copy_memory_to_device(GraficObject *device_object, bench_t* h_A, unsigned int size_a){
- hipEventRecord(*device_object->start_memory_copy_device);
- hipError_t err = hipMemcpy(device_object->d_A, h_A, sizeof(bench_t) * size_a, hipMemcpyHostToDevice);
- if (err != hipSuccess)
- {
- fprintf(stderr, "Failed to copy vector A from host to device (error code %s)!\n", hipGetErrorString(err));
- return;
- }
-
- hipEventRecord(*device_object->stop_memory_copy_device);
-}
-void execute_kernel(GraficObject *device_object, unsigned int n, unsigned int m,unsigned int w){
+void execute_kernel(GraficCommon* device_object, unsigned int n, unsigned int m,unsigned int w){
+ GraficObject* deviceObj = static_cast(device_object);
dim3 dimBlock(BLOCK_SIZE, BLOCK_SIZE);
dim3 dimGrid(ceil(float(n)/dimBlock.x), ceil(float(m)/dimBlock.y));
- hipEventRecord(*device_object->start);
- hipLaunchKernelGGL(lrn_kernel, dim3(dimGrid), dim3(dimBlock), 0, 0, device_object->d_A, device_object->d_B, n);
- hipEventRecord(*device_object->stop);
-}
+ // kernel time execution
+ Clock kernelCLK;
-void copy_memory_to_host(GraficObject *device_object, bench_t* h_C, int size){
- hipEventRecord(*device_object->start_memory_copy_host);
- hipMemcpy(h_C, device_object->d_B, size * sizeof(bench_t), hipMemcpyDeviceToHost);
- hipEventRecord(*device_object->stop_memory_copy_host);
- }
+ // profilling start
+ kernelCLK.start();
+ (void)hipEventRecord(*deviceObj->start);
-float get_elapsed_time(GraficObject *device_object, bool csv_format, bool csv_format_timestamp, long int current_time){
- hipEventSynchronize(*device_object->stop_memory_copy_host);
- float milliseconds_h_d = 0, milliseconds = 0, milliseconds_d_h = 0;
- // memory transfer time host-device
- hipEventElapsedTime(&milliseconds_h_d, *device_object->start_memory_copy_device, *device_object->stop_memory_copy_device);
- // kernel time
- hipEventElapsedTime(&milliseconds, *device_object->start, *device_object->stop);
- // memory transfer time device-host
- hipEventElapsedTime(&milliseconds_d_h, *device_object->start_memory_copy_host, *device_object->stop_memory_copy_host);
+ hipLaunchKernelGGL(lrn_kernel, dim3(dimGrid), dim3(dimBlock), 0, 0, deviceObj->d_A, deviceObj->d_B, n);
- if (csv_format_timestamp){
- printf("%.10f;%.10f;%.10f;%ld;\n", milliseconds_h_d,milliseconds,milliseconds_d_h, current_time);
- }
- else if (csv_format){
- printf("%.10f;%.10f;%.10f;\n", milliseconds_h_d,milliseconds,milliseconds_d_h);
- }else{
- printf("Elapsed time Host->Device: %.10f milliseconds\n", milliseconds_h_d);
- printf("Elapsed time kernel: %.10f milliseconds\n", milliseconds);
- printf("Elapsed time Device->Host: %.10f milliseconds\n", milliseconds_d_h);
- }
- return milliseconds;
-}
-
-void clean(GraficObject *device_object){
- hipError_t err = hipSuccess;
- err = hipFree(device_object->d_A);
-
- if (err != hipSuccess)
- {
- fprintf(stderr, "Failed to free device vector A (error code %s)!\n", hipGetErrorString(err));
- return;
- }
-
- err = hipFree(device_object->d_B);
-
- if (err != hipSuccess)
- {
- fprintf(stderr, "Failed to free device vector B (error code %s)!\n", hipGetErrorString(err));
- return;
- }
-
-
- // delete events
- delete device_object->start;
- delete device_object->stop;
- delete device_object->start_memory_copy_device;
- delete device_object->stop_memory_copy_device;
- delete device_object->start_memory_copy_host;
- delete device_object->stop_memory_copy_host;
-}
+ // profilling end
+ (void)hipEventRecord(*deviceObj->stop);
+ hipDeviceSynchronize();
+ kernelCLK.end();
+
+ // store the kernel time
+ deviceObj->elapsed_time = kernelCLK.getElapsedMS();
+}
\ No newline at end of file
diff --git a/gpu4s_benchmark/LRN_bench/hip/lib_hip_opt.cpp b/gpu4s_benchmark/LRN_bench/hip/lib_hip_opt.cpp
index 8f028792..a5d8d763 100644
--- a/gpu4s_benchmark/LRN_bench/hip/lib_hip_opt.cpp
+++ b/gpu4s_benchmark/LRN_bench/hip/lib_hip_opt.cpp
@@ -1,4 +1,3 @@
-#include "hip/hip_runtime.h"
#include "../benchmark_library.h"
#include "math.h"
@@ -8,8 +7,8 @@
* Computes the vector addition of A and B into C. The 3 vectors have the same
* number of elements numElements.
*/
-//#define BLOCK_SIZE 1024
-__global__ void
+
+ __global__ void
relu_kernel(const bench_t *A, bench_t *B, const int size)
{
unsigned int i = blockIdx.x * blockDim.x + threadIdx.x;
@@ -26,126 +25,24 @@ relu_kernel(const bench_t *A, bench_t *B, const int size)
}
}
-void init(GraficObject *device_object, char* device_name){
- init(device_object, 0,0, device_name);
-}
-
-void init(GraficObject *device_object, int platform ,int device, char* device_name){
- hipSetDevice(device);
- hipDeviceProp_t prop;
- hipGetDeviceProperties(&prop, device);
- //printf("Using device: %s\n", prop.name);
- strcpy(device_name,prop.name);
- //event create
- device_object->start = new hipEvent_t;
- device_object->stop = new hipEvent_t;
- device_object->start_memory_copy_device = new hipEvent_t;
- device_object->stop_memory_copy_device = new hipEvent_t;
- device_object->start_memory_copy_host = new hipEvent_t;
- device_object->stop_memory_copy_host= new hipEvent_t;
-
- hipEventCreate(device_object->start);
- hipEventCreate(device_object->stop);
- hipEventCreate(device_object->start_memory_copy_device);
- hipEventCreate(device_object->stop_memory_copy_device);
- hipEventCreate(device_object->start_memory_copy_host);
- hipEventCreate(device_object->stop_memory_copy_host);
-}
-
-
-bool device_memory_init(GraficObject *device_object, unsigned int size_a_matrix, unsigned int size_b_matrix){
-
- // Allocate the device input vector A
- hipError_t err = hipSuccess;
- err = hipMalloc((void **)&device_object->d_A, size_a_matrix * sizeof(bench_t));
-
- if (err != hipSuccess)
- {
- return false;
- }
-
- // Allocate the device input vector B
- err = hipMalloc((void **)&device_object->d_B, size_b_matrix * sizeof(bench_t));
-
- if (err != hipSuccess)
- {
- return false;
- }
- return true;
-}
-
-void copy_memory_to_device(GraficObject *device_object, bench_t* h_A, unsigned int size_a){
- hipEventRecord(*device_object->start_memory_copy_device);
- hipError_t err = hipMemcpy(device_object->d_A, h_A, sizeof(bench_t) * size_a, hipMemcpyHostToDevice);
- if (err != hipSuccess)
- {
- fprintf(stderr, "Failed to copy vector A from host to device (error code %s)!\n", hipGetErrorString(err));
- return;
- }
-
- hipEventRecord(*device_object->stop_memory_copy_device);
-}
-void execute_kernel(GraficObject *device_object, unsigned int n, unsigned int m,unsigned int w){
+void execute_kernel(GraficCommon* device_object, unsigned int n, unsigned int m,unsigned int w){
+ GraficObject* deviceObj = static_cast(device_object);
dim3 dimBlock(BLOCK_SIZE);
dim3 dimGrid(ceil(float((n*n))/(dimBlock.x)));
- hipEventRecord(*device_object->start);
- hipLaunchKernelGGL(relu_kernel, dim3(dimGrid), dim3(dimBlock), 0, 0, device_object->d_A, device_object->d_B, n);
- hipEventRecord(*device_object->stop);
-}
+ // kernel time execution
+ Clock kernelCLK;
-void copy_memory_to_host(GraficObject *device_object, bench_t* h_C, int size){
- hipEventRecord(*device_object->start_memory_copy_host);
- hipMemcpy(h_C, device_object->d_B, size * sizeof(bench_t), hipMemcpyDeviceToHost);
- hipEventRecord(*device_object->stop_memory_copy_host);
- }
+ // profilling start
+ kernelCLK.start();
+ (void)hipEventRecord(*deviceObj->start);
-float get_elapsed_time(GraficObject *device_object, bool csv_format, bool csv_format_timestamp, long int current_time){
- hipEventSynchronize(*device_object->stop_memory_copy_host);
- float milliseconds_h_d = 0, milliseconds = 0, milliseconds_d_h = 0;
- // memory transfer time host-device
- hipEventElapsedTime(&milliseconds_h_d, *device_object->start_memory_copy_device, *device_object->stop_memory_copy_device);
- // kernel time
- hipEventElapsedTime(&milliseconds, *device_object->start, *device_object->stop);
- // memory transfer time device-host
- hipEventElapsedTime(&milliseconds_d_h, *device_object->start_memory_copy_host, *device_object->stop_memory_copy_host);
+ hipLaunchKernelGGL(relu_kernel, dim3(dimGrid), dim3(dimBlock), 0, 0, deviceObj->d_A, deviceObj->d_B, n);
- if (csv_format_timestamp){
- printf("%.10f;%.10f;%.10f;%ld;\n", milliseconds_h_d,milliseconds,milliseconds_d_h, current_time);
- }
- else if (csv_format){
- printf("%.10f;%.10f;%.10f;\n", milliseconds_h_d,milliseconds,milliseconds_d_h);
- }else{
- printf("Elapsed time Host->Device: %.10f milliseconds\n", milliseconds_h_d);
- printf("Elapsed time kernel: %.10f milliseconds\n", milliseconds);
- printf("Elapsed time Device->Host: %.10f milliseconds\n", milliseconds_d_h);
- }
- return milliseconds;
-}
-
-void clean(GraficObject *device_object){
- hipError_t err = hipSuccess;
- err = hipFree(device_object->d_A);
-
- if (err != hipSuccess)
- {
- fprintf(stderr, "Failed to free device vector A (error code %s)!\n", hipGetErrorString(err));
- return;
- }
-
- err = hipFree(device_object->d_B);
-
- if (err != hipSuccess)
- {
- fprintf(stderr, "Failed to free device vector B (error code %s)!\n", hipGetErrorString(err));
- return;
- }
-
+ // profilling end
+ (void)hipEventRecord(*deviceObj->stop);
+ hipDeviceSynchronize();
+ kernelCLK.end();
- // delete events
- delete device_object->start;
- delete device_object->stop;
- delete device_object->start_memory_copy_device;
- delete device_object->stop_memory_copy_device;
- delete device_object->start_memory_copy_host;
- delete device_object->stop_memory_copy_host;
+ // store the kernel time
+ deviceObj->elapsed_time = kernelCLK.getElapsedMS();
}
diff --git a/gpu4s_benchmark/LRN_bench/main.cpp b/gpu4s_benchmark/LRN_bench/main.cpp
index 63272275..1fcdd357 100644
--- a/gpu4s_benchmark/LRN_bench/main.cpp
+++ b/gpu4s_benchmark/LRN_bench/main.cpp
@@ -31,37 +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;
- // strucs for CPU timing
- struct timespec start, end;
+ 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; 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;
@@ -84,6 +109,7 @@ int main(int argc, char *argv[]){
}
}*/
}
+
// print input
if (arguments_parameters->print_input)
{
@@ -103,59 +129,85 @@ int main(int argc, char *argv[]){
///////////////////////////////////////////////////////////////////////////////////////////////
// CODE BENCKMARK
///////////////////////////////////////////////////////////////////////////////////////////////
-
- // base object init
- GraficObject *lrn_bench = (GraficObject *)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);
}
-
- // 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; 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_gettime(CLOCK_MONOTONIC_RAW, &start);
- lrn(A,h_B, arguments_parameters->size);
- clock_gettime(CLOCK_MONOTONIC_RAW, &end);
+ Clock cpuKernelCLK;
+ cpuKernelCLK.start();
+ lrn(A,h_B, arguments_parameters->size);
+ cpuKernelCLK.end();
+
if (arguments_parameters->print_timing)
{
- printf("CPU Time %lu milliseconds\n", (end.tv_sec - start.tv_sec) * 1000 + (end.tv_nsec - start.tv_nsec) / 1000000);
+ printf("CPU Time %.0f milliseconds\n", cpuKernelCLK.getElapsedMS());
}
+
if (arguments_parameters->print_output)
{
#ifdef INT
@@ -176,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
///////////////////////////////////////////////////////////////////////////////////////////////
@@ -198,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);
@@ -224,6 +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(" -u: enable unified memory (ANDROID/JETSON)\n");
}
void init_arguments(BenchmarkParameters* arguments_parameters){
@@ -238,6 +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->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
}
@@ -266,6 +328,8 @@ int arguments_handler(int argc, char ** argv, BenchmarkParameters* arguments_par
case 'i' : args +=1;
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;
}
@@ -276,4 +340,4 @@ int arguments_handler(int argc, char ** argv, BenchmarkParameters* arguments_par
return ERROR_ARGUMENTS;
}
return OK_ARGUMENTS;
-}
\ No newline at end of file
+}
diff --git a/gpu4s_benchmark/LRN_bench/opencl/GEN_kernel.hcl b/gpu4s_benchmark/LRN_bench/opencl/GEN_kernel.hcl
new file mode 100644
index 00000000..bf78be26
--- /dev/null
+++ b/gpu4s_benchmark/LRN_bench/opencl/GEN_kernel.hcl
@@ -0,0 +1,10 @@
+
+std::string kernel_code =
+"void kernel kernel_lrn(global const bench_t* A, global bench_t* B, const int size, const bench_t K, const bench_t ALPHA, const bench_t BETA ){\n"
+"int i = get_global_id(0);\n"
+"int j = get_global_id(1);\n"
+"if (i < size && j < size){\n"
+"B[i*size+j] = A[i*size+j]/pow((K+ALPHA*pow(A[i*size+j],2)),BETA);\n"
+"}\n"
+"}\n"
+;
diff --git a/gpu4s_benchmark/LRN_bench/opencl/GEN_kernel_opt.hcl b/gpu4s_benchmark/LRN_bench/opencl/GEN_kernel_opt.hcl
new file mode 100644
index 00000000..550bd70b
--- /dev/null
+++ b/gpu4s_benchmark/LRN_bench/opencl/GEN_kernel_opt.hcl
@@ -0,0 +1,8 @@
+std::string kernel_code =
+"void kernel kernel_lrn(global const bench_t* A, global bench_t* B, const int size, const bench_t K, const bench_t ALPHA, const bench_t BETA ){\n"
+"long i = (long)get_global_id(0) * size + get_global_id(1);\n"
+"if (i < (long)size * size){\n"
+"B[i] = A[i]/pow((K+ALPHA*pow(A[i], (bench_t)2.0)), BETA);\n"
+"}\n"
+"}\n"
+;
\ No newline at end of file
diff --git a/gpu4s_benchmark/LRN_bench/opencl/kernel_opt.cl b/gpu4s_benchmark/LRN_bench/opencl/kernel_opt.cl
index e211c405..194bc92b 100644
--- a/gpu4s_benchmark/LRN_bench/opencl/kernel_opt.cl
+++ b/gpu4s_benchmark/LRN_bench/opencl/kernel_opt.cl
@@ -1,9 +1,8 @@
#htvar kernel_code
-void kernel kernel_relu(global const bench_t* A, global bench_t* B, const int size ){
- int i = get_global_id(0);
- if (i < (size * size) ){
- bench_t threshold = 0;
- B[i] = max(threshold, A[i]);
- }
+void kernel kernel_lrn(global const bench_t* A, global bench_t* B, const int size, const bench_t K, const bench_t ALPHA, const bench_t BETA ){
+ int i = get_global_id(0);
+ if (i < (size * size)){
+ B[i] = A[i]/powf((K+ALPHA*powf(A[i],2)),BETA);
+ }
}
#htendvar
\ No newline at end of file
diff --git a/gpu4s_benchmark/LRN_bench/opencl/lib_opencl.cpp b/gpu4s_benchmark/LRN_bench/opencl/lib_opencl.cpp
index 08227771..ab400952 100644
--- a/gpu4s_benchmark/LRN_bench/opencl/lib_opencl.cpp
+++ b/gpu4s_benchmark/LRN_bench/opencl/lib_opencl.cpp
@@ -4,58 +4,8 @@
#include
#include "GEN_kernel.hcl"
-
-//#define BLOCK_SIZE 16
-void init(GraficObject *device_object, char* device_name){
- init(device_object, 0,0, device_name);
-}
-void init(GraficObject *device_object, int platform ,int device, char* device_name){
- //get all platforms (drivers)
- std::vector all_platforms;
- cl::Platform::get(&all_platforms);
- if(all_platforms.size()==0){
- std::cout<<" No platforms found. Check OpenCL installation!\n";
- exit(1);
- }
- cl::Platform default_platform=all_platforms[platform];
- //std::cout << "Using platform: "<()<<"\n";
- //get default device of the default platform
- std::vector all_devices;
- default_platform.getDevices(CL_DEVICE_TYPE_ALL, &all_devices);
- if(all_devices.size()==0){
- std::cout<<" No devices found. Check OpenCL installation!\n";
- exit(1);
- }
- cl::Device default_device=all_devices[device];
- //std::cout<< "Using device: "<()<<"\n";
- strcpy(device_name,default_device.getInfo().c_str() );
- // context
- device_object->context = new cl::Context(default_device);
- device_object->queue = new cl::CommandQueue(*device_object->context,default_device,CL_QUEUE_PROFILING_ENABLE);
- device_object->default_device = default_device;
-
- // events
- device_object->evt = new cl::Event;
- device_object->evt_copyA = new cl::Event;
- device_object->evt_copyB = new cl::Event;
-
-}
-
-bool device_memory_init(GraficObject *device_object, unsigned int size_a_matrix, unsigned int size_b_matrix){
- device_object->d_A = new cl::Buffer(*device_object->context,CL_MEM_READ_ONLY ,sizeof(bench_t)*size_a_matrix);
- device_object->d_B = new cl::Buffer(*device_object->context,CL_MEM_READ_ONLY ,sizeof(bench_t)*size_b_matrix);
- // inicialice Arrays
- return true;
-}
-
-void copy_memory_to_device(GraficObject *device_object, bench_t* h_A, unsigned int size_a){
- // copy memory host -> device
- //TODO Errors check
- device_object->queue->enqueueWriteBuffer(*device_object->d_A,CL_TRUE,0,sizeof(bench_t)*size_a, h_A, NULL, device_object->evt_copyA);
-}
-
-
-void execute_kernel(GraficObject *device_object, unsigned int n, unsigned int m, unsigned int w){
+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;
@@ -72,65 +22,37 @@ void execute_kernel(GraficObject *device_object, unsigned int n, unsigned int m,
}
cl::Program::Sources sources;
- device_object->evt = new cl::Event;
+ deviceObj->evt = new cl::Event;
// load kernel from file
- kernel_code = type_kernel + kernel_code;
+ kernel_code = type_kernel_common + kernel_code;
sources.push_back({kernel_code.c_str(),kernel_code.length()});
- cl::Program program(*device_object->context,sources);
- if(program.build({device_object->default_device})!=CL_SUCCESS){
- std::cout<<" Error building: "<(device_object->default_device)<<"\n";
+ 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 kernel_add=cl::Kernel(program,"kernel_lrn");
- kernel_add.setArg(0,*device_object->d_A);
- kernel_add.setArg(1,*device_object->d_B);
+ kernel_add.setArg(0,*deviceObj->d_A);
+ kernel_add.setArg(1,*deviceObj->d_B);
kernel_add.setArg(2,n);
kernel_add.setArg(3,K);
kernel_add.setArg(4,ALPHA);
kernel_add.setArg(5,BETA);
- device_object->queue->enqueueNDRangeKernel(kernel_add,cl::NullRange,global,local, NULL, device_object->evt);
- device_object->queue->finish();
-
-}
-
-void copy_memory_to_host(GraficObject *device_object, bench_t* h_C, int size){
- device_object->queue->enqueueReadBuffer(*device_object->d_B,CL_TRUE,0,sizeof(bench_t)*size,h_C, NULL, device_object->evt_copyB);
-}
-
-float get_elapsed_time(GraficObject *device_object, bool csv_format, bool csv_format_timestamp, long int current_time){
- device_object->evt_copyB->wait();
- float elapsed_h_d = 0, elapsed = 0, elapsed_d_h = 0;
- elapsed_h_d = device_object->evt_copyA->getProfilingInfo() - device_object->evt_copyA->getProfilingInfo();
- //printf("Elapsed time Host->Device: %.10f \n", elapsed / 1000000.0);
- elapsed = device_object->evt->getProfilingInfo() - device_object->evt->getProfilingInfo();
- //printf("Elapsed time kernel: %.10f \n", elapsed / 1000000.0);
- elapsed_d_h = device_object->evt_copyB->getProfilingInfo() - device_object->evt_copyB->getProfilingInfo();
- //printf("Elapsed time Device->Host: %.10f \n", );
-
-
- if (csv_format_timestamp){
- printf("%.10f;%.10f;%.10f;%ld;\n", milliseconds_h_d,milliseconds,milliseconds_d_h, current_time);
- }
- else if (csv_format){
- printf("%.10f;%.10f;%.10f;\n", elapsed_h_d / 1000000.0,elapsed / 1000000.0,elapsed_d_h / 1000000.0);
- }else{
- printf("Elapsed time Host->Device: %.10f milliseconds\n", (elapsed_h_d / 1000000.0));
- printf("Elapsed time kernel: %.10f milliseconds\n", elapsed / 1000000.0);
- printf("Elapsed time Device->Host: %.10f milliseconds\n", elapsed_d_h / 1000000.0);
- }
- return elapsed / 1000000.0; // TODO Change
-}
+ deviceObj->queue->enqueueNDRangeKernel(kernel_add,cl::NullRange,global,local, NULL, deviceObj->evt);
+ // Wait for completion before stopping the clock
+ deviceObj->queue->finish();
+ // Clock profilling end
+ kernelCLK.end();
-void clean(GraficObject *device_object){
- // pointers clean
- delete device_object->context;
- delete device_object->queue;
- // pointer to memory
- delete device_object->d_A;
- delete device_object->d_B;
- delete device_object->evt;
- delete device_object->evt_copyA;
- delete device_object->evt_copyB;
+ // store the kernel time
+ deviceObj->elapsed_time = kernelCLK.getElapsedNS();
}
diff --git a/gpu4s_benchmark/LRN_bench/opencl/lib_opencl_common.cpp b/gpu4s_benchmark/LRN_bench/opencl/lib_opencl_common.cpp
new file mode 100644
index 00000000..19c2c85c
--- /dev/null
+++ b/gpu4s_benchmark/LRN_bench/opencl/lib_opencl_common.cpp
@@ -0,0 +1,178 @@
+/** * ====================================================================
+ * @file lib_opencl_common.cpp (./LRN_bench)
+ * @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"
+#include "../../common/opencl_common.hpp"
+
+void init(GraficCommon* device_object, char* device_name){
+ init(device_object, 0,0, device_name);
+}
+void init(GraficCommon* device_object, int platform ,int device, char* device_name){
+ GraficObject* deviceObj = static_cast(device_object);
+ //get all platforms (drivers)
+ std::vector all_platforms;
+ cl::Platform::get(&all_platforms);
+ if(all_platforms.size()==0){
+ std::cout<<" No platforms found. Check OpenCL installation!\n";
+ exit(1);
+ }
+ cl::Platform default_platform=all_platforms[platform];
+ //std::cout << "Using platform: "<()<<"\n";
+ //get default device of the default platform
+ std::vector all_devices;
+ default_platform.getDevices(CL_DEVICE_TYPE_ALL, &all_devices);
+ if(all_devices.size()==0){
+ std::cout<<" No devices found. Check OpenCL installation!\n";
+ exit(1);
+ }
+ cl::Device default_device=all_devices[device];
+ //std::cout<< "Using device: "<()<<"\n";
+ strcpy(device_name,default_device.getInfo().c_str() );
+ // context
+ deviceObj->context = new cl::Context(default_device);
+ deviceObj->queue = new cl::CommandQueue(*deviceObj->context,default_device,CL_QUEUE_PROFILING_ENABLE);
+ deviceObj->default_device = default_device;
+
+ // events
+ deviceObj->evt = new cl::Event;
+ deviceObj->evt_copyA = new cl::Event;
+ deviceObj->evt_copyB = new cl::Event;
+
+}
+
+bool device_memory_init(GraficCommon* device_object, unsigned int size_a_matrix, unsigned int size_b_matrix){
+ GraficObject* deviceObj = static_cast(device_object);
+ cl_int err;
+
+ deviceObj->d_A = new cl::Buffer(*deviceObj->context,CL_MEM_READ_ONLY ,sizeof(bench_t)*size_a_matrix, nullptr, &err);
+ if (err != CL_SUCCESS) return false;
+
+ deviceObj->d_B = new cl::Buffer(*deviceObj->context,CL_MEM_READ_WRITE ,sizeof(bench_t)*size_b_matrix, nullptr, &err);
+ if (err != CL_SUCCESS) return false;
+
+ // inicialice Arrays
+ return true;
+}
+
+void copy_memory_to_device(GraficCommon* device_object, bench_t* h_A, unsigned int size_a){
+ GraficObject* deviceObj = static_cast(device_object);
+ // host -> device
+ Clock h2dCLK;
+
+ // Clock profilling start
+ 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 (openclError("Failed to copy vector A from host to device", err)) return;
+
+ // Clock profilling end
+ h2dCLK.end();
+
+ // store the hd2h time
+ deviceObj->h2d_elapsed_time = h2dCLK.getElapsedNS();
+}
+
+
+void copy_memory_to_host(GraficCommon* device_object, bench_t* h_C, int size){
+ GraficObject* deviceObj = static_cast(device_object);
+ // device -> host
+ Clock d2hCLK;
+
+ // Clock profilling start
+ 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 (openclError("Failed to copy vector B from device to host", err)) return;
+
+ // Clock profilling end
+ 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_copyB->wait();
+
+ float elapsed_h_d = 0, elapsed = 0, elapsed_d_h = 0;
+
+ if (deviceObj->profiling_clock)
+ {
+ // --- FIX: Use instead of CLBlast event profiling (unreliable on PROFILING_CLOCK) ---
+ elapsed_h_d = deviceObj->h2d_elapsed_time;
+ elapsed = deviceObj->elapsed_time;
+ elapsed_d_h = deviceObj->d2h_elapsed_time;
+ }else{
+ elapsed_h_d = deviceObj->evt_copyA->getProfilingInfo() - deviceObj->evt_copyA->getProfilingInfo();
+ //printf("Elapsed time Host->Device: %.10f \n", elapsed / 1000000.0);
+
+ elapsed = deviceObj->evt->getProfilingInfo() - deviceObj->evt->getProfilingInfo();
+ //printf("Elapsed time kernel: %.10f \n", elapsed / 1000000.0);
+
+ elapsed_d_h = deviceObj->evt_copyB->getProfilingInfo() - deviceObj->evt_copyB->getProfilingInfo();
+ //printf("Elapsed time Device->Host: %.10f \n", );
+ }
+
+
+ if (csv_format_timestamp){
+ printf("%.10f;%.10f;%.10f;%ld;\n", elapsed_h_d / 1000000.0,deviceObj->elapsed_time ,elapsed_d_h / 1000000.0, current_time);
+ }
+ else if (csv_format){
+ printf("%.10f;%.10f;%.10f;\n", elapsed_h_d / 1000000.0,elapsed / 1000000.0,elapsed_d_h / 1000000.0);
+ }else{
+ printf("profiling mode: %s\n", deviceObj->profiling_clock ? "CLOCK" : "GPU");
+ printf("Elapsed time Host->Device: %.10f milliseconds\n", (elapsed_h_d / 1000000.0));
+ printf("Elapsed time kernel: %.10f milliseconds\n", elapsed / 1000000.0);
+ printf("Elapsed time Device->Host: %.10f milliseconds\n", elapsed_d_h / 1000000.0);
+ }
+ return elapsed / 1000000.0; // TODO Change
+}
+
+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;
+}
+
+#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 size_output){
+ GraficObject* deviceObj = static_cast(device_object);
+ // --- Call the openCL common function ---
+ map_unified_memory_to_host(device_object, size_output,
+ BufferMapCL{&d_output, deviceObj->d_B, deviceObj->evt_copyB}
+ );
+}
+
+#endif
diff --git a/gpu4s_benchmark/LRN_bench/opencl/lib_opencl_lib.cpp b/gpu4s_benchmark/LRN_bench/opencl/lib_opencl_lib.cpp
deleted file mode 100644
index 91a425a9..00000000
--- a/gpu4s_benchmark/LRN_bench/opencl/lib_opencl_lib.cpp
+++ /dev/null
@@ -1,112 +0,0 @@
-// OpenCL lib code
-#include
-#include "../benchmark_library.h"
-#include
-
-void init(GraficObject *device_object, char* device_name){
- init(device_object, 0,0, device_name);
-}
-void init(GraficObject *device_object, int platform ,int device, char* device_name){
- //get all platforms (drivers)
- std::vector all_platforms;
- cl::Platform::get(&all_platforms);
- if(all_platforms.size()==0){
- std::cout<<" No platforms found. Check OpenCL installation!\n";
- exit(1);
- }
- cl::Platform default_platform=all_platforms[platform];
- //std::cout << "Using platform: "<()<<"\n";
- //get default device of the default platform
- std::vector all_devices;
- default_platform.getDevices(CL_DEVICE_TYPE_ALL, &all_devices);
- if(all_devices.size()==0){
- std::cout<<" No devices found. Check OpenCL installation!\n";
- exit(1);
- }
- cl::Device default_device=all_devices[device];
- //std::cout<< "Using device: "<()<<"\n";
- strcpy(device_name,default_device.getInfo().c_str() );
- // context
- device_object->context = new cl::Context(default_device);
- device_object->queue = new cl::CommandQueue(*device_object->context,default_device,CL_QUEUE_PROFILING_ENABLE);
- device_object->default_device = default_device;
-
- // events
- device_object->evt = new cl::Event;
- device_object->evt_copyA = new cl::Event;
- device_object->evt_copyB = new cl::Event;
- device_object->evt_copyC = new cl::Event;
-
-}
-
-bool device_memory_init(GraficObject *device_object, unsigned int size_a_matrix, unsigned int size_b_matrix, unsigned int size_c_matrix){
- device_object->d_A = new cl::Buffer(*device_object->context,CL_MEM_READ_ONLY ,sizeof(bench_t)*size_a_matrix);
- device_object->d_B = new cl::Buffer(*device_object->context,CL_MEM_READ_ONLY ,sizeof(bench_t)*size_b_matrix);
- device_object->d_C = new cl::Buffer(*device_object->context,CL_MEM_READ_ONLY ,sizeof(bench_t)*size_c_matrix);
- // inicialice Arrays
- return true;
-}
-
-void copy_memory_to_device(GraficObject *device_object, bench_t* h_A, bench_t* h_B, unsigned int size_a, unsigned int size_b){
- // copy memory host -> device
- //TODO Errors check
- device_object->queue->enqueueWriteBuffer(*device_object->d_A,CL_TRUE,0,sizeof(bench_t)*size_a, h_A, NULL, device_object->evt_copyA);
- device_object->queue->enqueueWriteBuffer(*device_object->d_B,CL_TRUE,0,sizeof(bench_t)*size_b, h_B, NULL, device_object->evt_copyB);
-}
-
-
-void execute_kernel(GraficObject *device_object, unsigned int n, unsigned int m, unsigned int w){
- const bench_t alpha = 1.0f;
- const bench_t beta = 1.0f;
- const unsigned int a_ld = n;
- const unsigned int b_ld = n;
- const unsigned int c_ld = n;
- #ifdef INT
- printf("CLBLAST NOT SUPPORT INT OPERATIOS\n");
- #else
- auto status = clblast::Gemm(clblast::Layout::kRowMajor,clblast::Transpose::kNo, clblast::Transpose::kNo, n, n, n, alpha, (*device_object->d_A)() , 0, a_ld, (*device_object->d_B)(), 0, b_ld, beta, (*device_object->d_C)(), 0, c_ld,&(*device_object->queue)(), &(*device_object->evt)());
- #endif
-}
-
-void copy_memory_to_host(GraficObject *device_object, bench_t* h_C, int size){
- device_object->queue->enqueueReadBuffer(*device_object->d_C,CL_TRUE,0,sizeof(bench_t)*size,h_C, NULL, device_object->evt_copyC);
-}
-
-float get_elapsed_time(GraficObject *device_object, bool csv_format, bool csv_format_timestamp, long int current_time){
- device_object->evt_copyC->wait();
- float elapsed_h_d = 0, elapsed = 0, elapsed_d_h = 0;
- elapsed_h_d = device_object->evt_copyA->getProfilingInfo() - device_object->evt_copyA->getProfilingInfo();
- elapsed_h_d += device_object->evt_copyB->getProfilingInfo() - device_object->evt_copyB->getProfilingInfo();
- //printf("Elapsed time Host->Device: %.10f \n", elapsed / 1000000.0);
- elapsed = device_object->evt->getProfilingInfo() - device_object->evt->getProfilingInfo();
- //printf("Elapsed time kernel: %.10f \n", elapsed / 1000000.0);
- elapsed_d_h = device_object->evt_copyC->getProfilingInfo() - device_object->evt_copyC->getProfilingInfo();
- //printf("Elapsed time Device->Host: %.10f \n", );
-
-
- if (csv_format_timestamp){
- printf("%.10f;%.10f;%.10f;%ld;\n", milliseconds_h_d,milliseconds,milliseconds_d_h, current_time);
- }
- else if (csv_format){
- printf("%.10f;%.10f;%.10f;\n", elapsed_h_d / 1000000.0,elapsed / 1000000.0,elapsed_d_h / 1000000.0);
- }else{
- printf("Elapsed time Host->Device: %.10f milliseconds\n", (elapsed_h_d / 1000000.0));
- printf("Elapsed time kernel: %.10f milliseconds\n", elapsed / 1000000.0);
- printf("Elapsed time Device->Host: %.10f milliseconds\n", elapsed_d_h / 1000000.0);
- }
- return elapsed / 1000000.0; // TODO Change
-}
-
-void clean(GraficObject *device_object){
- // pointers clean
- delete device_object->context;
- delete device_object->queue;
- // pointer to memory
- delete device_object->d_A;
- delete device_object->d_B;
- delete device_object->d_C;
- delete device_object->evt;
- delete device_object->evt_copyA;
- delete device_object->evt_copyB;
- delete device_object->evt_copyC;
-}
\ No newline at end of file
diff --git a/gpu4s_benchmark/LRN_bench/opencl/lib_opencl_opt.cpp b/gpu4s_benchmark/LRN_bench/opencl/lib_opencl_opt.cpp
index cc53cd3d..db7c8464 100644
--- a/gpu4s_benchmark/LRN_bench/opencl/lib_opencl_opt.cpp
+++ b/gpu4s_benchmark/LRN_bench/opencl/lib_opencl_opt.cpp
@@ -4,120 +4,57 @@
#include
#include "GEN_kernel_opt.hcl"
-
-//#define BLOCK_SIZE 256
-void init(GraficObject *device_object, char* device_name){
- init(device_object, 0,0, device_name);
-}
-void init(GraficObject *device_object, int platform ,int device, char* device_name){
- //get all platforms (drivers)
- std::vector all_platforms;
- cl::Platform::get(&all_platforms);
- if(all_platforms.size()==0){
- std::cout<<" No platforms found. Check OpenCL installation!\n";
- exit(1);
+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;
+ cl::NDRange global;
+ if (n < BLOCK_SIZE)
+ {
+ local = cl::NullRange;
+ global = cl::NDRange(n, w);
}
- cl::Platform default_platform=all_platforms[platform];
- //std::cout << "Using platform: "<()<<"\n";
- //get default device of the default platform
- std::vector all_devices;
- default_platform.getDevices(CL_DEVICE_TYPE_ALL, &all_devices);
- if(all_devices.size()==0){
- std::cout<<" No devices found. Check OpenCL installation!\n";
- exit(1);
+ else
+ {
+ local = cl::NDRange(x_local, y_local);
+ global = cl::NDRange(n, w);
}
- cl::Device default_device=all_devices[device];
- //std::cout<< "Using device: "<()<<"\n";
- strcpy(device_name,default_device.getInfo().c_str() );
- // context
- device_object->context = new cl::Context(default_device);
- device_object->queue = new cl::CommandQueue(*device_object->context,default_device,CL_QUEUE_PROFILING_ENABLE);
- device_object->default_device = default_device;
-
- // events
- device_object->evt = new cl::Event;
- device_object->evt_copyA = new cl::Event;
- device_object->evt_copyB = new cl::Event;
-
-}
-
-bool device_memory_init(GraficObject *device_object, unsigned int size_a_matrix, unsigned int size_b_matrix){
- device_object->d_A = new cl::Buffer(*device_object->context,CL_MEM_READ_ONLY ,sizeof(bench_t)*size_a_matrix);
- device_object->d_B = new cl::Buffer(*device_object->context,CL_MEM_READ_ONLY ,sizeof(bench_t)*size_b_matrix);
- // inicialice Arrays
- return true;
-}
-
-void copy_memory_to_device(GraficObject *device_object, bench_t* h_A, unsigned int size_a){
- // copy memory host -> device
- //TODO Errors check
- device_object->queue->enqueueWriteBuffer(*device_object->d_A,CL_TRUE,0,sizeof(bench_t)*size_a, h_A, NULL, device_object->evt_copyA);
-}
-
-
-void execute_kernel(GraficObject *device_object, unsigned int n, unsigned int m, unsigned int w){
- const unsigned int x_local= BLOCK_SIZE;
- const unsigned int y_local= BLOCK_SIZE;
- cl::NDRange local(x_local);
- cl::NDRange global(n * n);
cl::Program::Sources sources;
- device_object->evt = new cl::Event;
+ deviceObj->evt = new cl::Event;
// load kernel from file
- kernel_code = type_kernel + kernel_code;
+ kernel_code = type_kernel_common + kernel_code;
sources.push_back({kernel_code.c_str(),kernel_code.length()});
- cl::Program program(*device_object->context,sources);
- if(program.build({device_object->default_device})!=CL_SUCCESS){
- std::cout<<" Error building: "<(device_object->default_device)<<"\n";
+ cl::Program program(*deviceObj->context,sources);
+ if(program.build({deviceObj->default_device})!=CL_SUCCESS){
+ std::cout<<" Error building: "<(deviceObj->default_device)<<"\n";
exit(1);
}
- cl::Kernel kernel_add=cl::Kernel(program,"kernel_relu");
- kernel_add.setArg(0,*device_object->d_A);
- kernel_add.setArg(1,*device_object->d_B);
- kernel_add.setArg(2,n);
-
- device_object->queue->enqueueNDRangeKernel(kernel_add,cl::NullRange,global,local, NULL, device_object->evt);
- device_object->queue->finish();
-}
-
-void copy_memory_to_host(GraficObject *device_object, bench_t* h_C, int size){
- device_object->queue->enqueueReadBuffer(*device_object->d_B,CL_TRUE,0,sizeof(bench_t)*size,h_C, NULL, device_object->evt_copyB);
-}
+ // kernel time execution
+ Clock kernelCLK;
-float get_elapsed_time(GraficObject *device_object, bool csv_format, bool csv_format_timestamp, long int current_time){
- device_object->evt_copyB->wait();
- float elapsed_h_d = 0, elapsed = 0, elapsed_d_h = 0;
- elapsed_h_d = device_object->evt_copyA->getProfilingInfo() - device_object->evt_copyA->getProfilingInfo();
- //printf("Elapsed time Host->Device: %.10f \n", elapsed / 1000000.0);
- elapsed = device_object->evt->getProfilingInfo() - device_object->evt->getProfilingInfo();
- //printf("Elapsed time kernel: %.10f \n", elapsed / 1000000.0);
- elapsed_d_h = device_object->evt_copyB->getProfilingInfo() - device_object->evt_copyB->getProfilingInfo();
- //printf("Elapsed time Device->Host: %.10f \n", );
+ // Clock profilling start
+ kernelCLK.start();
+ cl::Kernel kernel_add=cl::Kernel(program,"kernel_lrn");
+ kernel_add.setArg(0,*deviceObj->d_A);
+ kernel_add.setArg(1,*deviceObj->d_B);
+ kernel_add.setArg(2,n);
+ kernel_add.setArg(3,K);
+ kernel_add.setArg(4,ALPHA);
+ kernel_add.setArg(5,BETA);
- if (csv_format_timestamp){
- printf("%.10f;%.10f;%.10f;%ld;\n", milliseconds_h_d,milliseconds,milliseconds_d_h, current_time);
- }
- else if (csv_format){
- printf("%.10f;%.10f;%.10f;\n", elapsed_h_d / 1000000.0,elapsed / 1000000.0,elapsed_d_h / 1000000.0);
- }else{
- printf("Elapsed time Host->Device: %.10f milliseconds\n", (elapsed_h_d / 1000000.0));
- printf("Elapsed time kernel: %.10f milliseconds\n", elapsed / 1000000.0);
- printf("Elapsed time Device->Host: %.10f milliseconds\n", elapsed_d_h / 1000000.0);
- }
- return elapsed / 1000000.0; // TODO Change
-}
+ deviceObj->queue->enqueueNDRangeKernel(kernel_add,cl::NullRange,global,local, NULL, deviceObj->evt);
+
+ // Wait for completion before stopping the clock
+ deviceObj->queue->finish();
+ // Clock profilling end
+ kernelCLK.end();
-void clean(GraficObject *device_object){
- // pointers clean
- delete device_object->context;
- delete device_object->queue;
- // pointer to memory
- delete device_object->d_A;
- delete device_object->d_B;
- delete device_object->evt;
- delete device_object->evt_copyA;
- delete device_object->evt_copyB;
+ // store the kernel time
+ deviceObj->elapsed_time = kernelCLK.getElapsedNS();
}
diff --git a/gpu4s_benchmark/LRN_bench/openmp/lib_omp.cpp b/gpu4s_benchmark/LRN_bench/openmp/lib_omp.cpp
index 0c7359cd..ef1dfb08 100644
--- a/gpu4s_benchmark/LRN_bench/openmp/lib_omp.cpp
+++ b/gpu4s_benchmark/LRN_bench/openmp/lib_omp.cpp
@@ -1,36 +1,10 @@
#include "../benchmark_library.h"
-#include
#include
-void init(GraficObject *device_object, char* device_name)
-{
- init(device_object, 0,0, device_name);
-}
-
-
-void init(GraficObject *device_object, int platform ,int device, char* device_name)
-{
- // TBD Feature: device name. -- Bulky generic platform implementation
- strcpy(device_name,"Generic device");
-}
-
-
-bool device_memory_init(GraficObject *device_object, unsigned int size_a_matrix, unsigned int size_b_matrix)
-{
- device_object->d_B = (bench_t*) malloc ( size_b_matrix * sizeof(bench_t*));
- return true;
-}
-
-
-void copy_memory_to_device(GraficObject *device_object, bench_t* h_A, unsigned int size_a)
-{
- device_object->d_A = h_A;
-}
-
-
-void execute_kernel(GraficObject *device_object, unsigned int n, unsigned int m, unsigned int w)
+void execute_kernel(GraficCommon* device_object, unsigned int n, unsigned int m, unsigned int w)
{
+ GraficObject* deviceObj = static_cast(device_object);
// Start compute timer
const double start_wtime = omp_get_wtime();
@@ -39,41 +13,10 @@ void execute_kernel(GraficObject *device_object, unsigned int n, unsigned int m,
{
for (unsigned int j = 0; j < n; ++j)
{
- device_object->d_B[i*n+j] = device_object->d_A[i*n+j]/pow((K+ALPHA*pow(device_object->d_A[i*n+j],2)),BETA);
+ deviceObj->d_B[i*n+j] = deviceObj->d_A[i*n+j]/pow((K+ALPHA*pow(deviceObj->d_A[i*n+j],2)),BETA);
}
}
// End compute timer
- device_object->elapsed_time = omp_get_wtime() - start_wtime;
-}
-
-
-void copy_memory_to_host(GraficObject *device_object, bench_t* h_C, int size)
-{
- memcpy(h_C, &device_object->d_B[0], sizeof(bench_t)*size);
-}
-
-
-float get_elapsed_time(GraficObject *device_object, bool csv_format, bool csv_format_timestamp, long int current_time)
-{
- if (csv_format_timestamp){
- printf("%.10f;%.10f;%.10f;%ld;\n", (bench_t) 0, device_object->elapsed_time * 1000.f, (bench_t) 0, current_time);
- }
- else if (csv_format)
- {
- printf("%.10f;%.10f;%.10f;\n", (bench_t) 0, device_object->elapsed_time * 1000.f, (bench_t) 0);
- }
- else
- {
- printf("Elapsed time Host->Device: %.10f milliseconds\n", (bench_t) 0);
- printf("Elapsed time kernel: %.10f milliseconds\n", device_object->elapsed_time * 1000.f);
- printf("Elapsed time Device->Host: %.10f milliseconds\n", (bench_t) 0);
- }
- return device_object->elapsed_time * 1000.f;
+ deviceObj->elapsed_time = omp_get_wtime() - start_wtime;
}
-
-
-void clean(GraficObject *device_object)
-{
- free(device_object->d_B);
-}
\ No newline at end of file
diff --git a/gpu4s_benchmark/LRN_bench/openmp/lib_omp_opt.cpp b/gpu4s_benchmark/LRN_bench/openmp/lib_omp_opt.cpp
index f4c909fa..38ff5f5e 100644
--- a/gpu4s_benchmark/LRN_bench/openmp/lib_omp_opt.cpp
+++ b/gpu4s_benchmark/LRN_bench/openmp/lib_omp_opt.cpp
@@ -2,34 +2,10 @@
#include
#include
-void init(GraficObject *device_object, char* device_name)
-{
- init(device_object, 0,0, device_name);
-}
-
-
-void init(GraficObject *device_object, int platform ,int device, char* device_name)
-{
- // TBD Feature: device name. -- Bulky generic platform implementation
- strcpy(device_name,"Generic device");
-}
-
-bool device_memory_init(GraficObject *device_object, unsigned int size_a_matrix, unsigned int size_b_matrix)
-{
- device_object->d_B = (bench_t*) malloc ( size_b_matrix * sizeof(bench_t*));
- return true;
-}
-
-
-void copy_memory_to_device(GraficObject *device_object, bench_t* h_A, unsigned int size_a)
-{
- device_object->d_A = h_A;
-}
-
-
-void execute_kernel(GraficObject *device_object, unsigned int n, unsigned int m, unsigned int w)
+void execute_kernel(GraficCommon* device_object, unsigned int n, unsigned int m, unsigned int w)
{
+ GraficObject* deviceObj = static_cast(device_object);
// Start compute timer
const double start_wtime = omp_get_wtime();
@@ -38,40 +14,9 @@ void execute_kernel(GraficObject *device_object, unsigned int n, unsigned int m,
#pragma omp parallel for
for (unsigned int i = 0; i < squared_size; ++i)
{
- device_object->d_B[i] = device_object->d_A[i]/pow((K+ALPHA*pow(device_object->d_A[i],2)),BETA);
+ deviceObj->d_B[i] = deviceObj->d_A[i]/pow((K+ALPHA*pow(deviceObj->d_A[i],2)),BETA);
}
// End compute timer
- device_object->elapsed_time = omp_get_wtime() - start_wtime;
-}
-
-
-void copy_memory_to_host(GraficObject *device_object, bench_t* h_C, int size)
-{
- memcpy(h_C, &device_object->d_B[0], sizeof(bench_t)*size);
+ deviceObj->elapsed_time = omp_get_wtime() - start_wtime;
}
-
-
-float get_elapsed_time(GraficObject *device_object, bool csv_format, bool csv_format_timestamp, long int current_time)
-{
- if (csv_format_timestamp){
- printf("%.10f;%.10f;%.10f;%ld;\n", (bench_t) 0, device_object->elapsed_time * 1000.f, (bench_t) 0, current_time);
- }
- else if (csv_format)
- {
- printf("%.10f;%.10f;%.10f;\n", (bench_t) 0, device_object->elapsed_time * 1000.f, (bench_t) 0);
- }
- else
- {
- printf("Elapsed time Host->Device: %.10f milliseconds\n", (bench_t) 0);
- printf("Elapsed time kernel: %.10f milliseconds\n", device_object->elapsed_time * 1000.f);
- printf("Elapsed time Device->Host: %.10f milliseconds\n", (bench_t) 0);
- }
- return device_object->elapsed_time * 1000.f;
-}
-
-
-void clean(GraficObject *device_object)
-{
- free(device_object->d_B);
-}
\ No newline at end of file
diff --git a/gpu4s_benchmark/LRN_bench/openmp/omp_common.cpp b/gpu4s_benchmark/LRN_bench/openmp/omp_common.cpp
new file mode 100644
index 00000000..67ca5651
--- /dev/null
+++ b/gpu4s_benchmark/LRN_bench/openmp/omp_common.cpp
@@ -0,0 +1,71 @@
+/** * ====================================================================
+ * @file omp_common.cpp (./LRN_bench)
+ * @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"
+#include
+
+
+void init(GraficCommon* device_object, char* device_name)
+{
+ init(device_object, 0,0, device_name);
+}
+
+
+void init(GraficCommon* device_object, int platform ,int device, char* device_name)
+{
+ // TBD Feature: device name. -- Bulky generic platform implementation
+ strcpy(device_name,"Generic device");
+}
+
+
+bool device_memory_init(GraficCommon* device_object, unsigned int size_a_matrix, unsigned int size_b_matrix)
+{
+ GraficObject* deviceObj = static_cast(device_object);
+ deviceObj->d_B = (bench_t*) malloc ( size_b_matrix * sizeof(bench_t*));
+ return true;
+}
+
+
+void copy_memory_to_device(GraficCommon* device_object, bench_t* h_A, unsigned int size_a)
+{
+ GraficObject* deviceObj = static_cast(device_object);
+ deviceObj->d_A = h_A;
+}
+
+
+void copy_memory_to_host(GraficCommon* device_object, bench_t* h_C, int size)
+{
+ GraficObject* deviceObj = static_cast(device_object);
+ memcpy(h_C, &deviceObj->d_B[0], sizeof(bench_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);
+ if (csv_format_timestamp){
+ printf("%.10f;%.10f;%.10f;%ld;\n", (bench_t) 0, deviceObj->elapsed_time * 1000.f, (bench_t) 0, current_time);
+ }
+ else if (csv_format)
+ {
+ printf("%.10f;%.10f;%.10f;\n", (bench_t) 0, deviceObj->elapsed_time * 1000.f, (bench_t) 0);
+ }
+ else
+ {
+ printf("Elapsed time Host->Device: %.10f milliseconds\n", (bench_t) 0);
+ printf("Elapsed time kernel: %.10f milliseconds\n", deviceObj->elapsed_time * 1000.f);
+ printf("Elapsed time Device->Host: %.10f milliseconds\n", (bench_t) 0);
+ }
+ return deviceObj->elapsed_time * 1000.f;
+}
+
+
+void clean(GraficCommon* device_object)
+{
+ GraficObject* deviceObj = static_cast(device_object);
+ free(deviceObj->d_B);
+}
\ No newline at end of file
diff --git a/gpu4s_benchmark/cifar_10/CLHT.sh b/gpu4s_benchmark/cifar_10/CLHT.sh
deleted file mode 100755
index 66dc3598..00000000
--- a/gpu4s_benchmark/cifar_10/CLHT.sh
+++ /dev/null
@@ -1,38 +0,0 @@
-# Open CL Header tool
-for fi in $(find . -type f -name "*.cl"); do
- basename=$(basename -- "$fi")
- filename="${basename%.*}"
- dir=$(dirname "$fi")
- # Override emplace file content
- echo "" > ${dir}/GEN_$filename.hcl
- # Iterate line by line detecting tokens -r option includes backward slashes
- while read -r s || [ -n "$s" ]; do
- if [[ $s != "" ]]; then
- if [[ $s == "#htvar "* ]]; then
- # Add variable when token is found
- echo "std::string "${s#"#htvar "}" = " >> ${dir}/GEN_$filename.hcl
- elif [[ $s == "#htdefine "* ]]; then
- # Add macro when token is found
- echo "#define "${s#"#htdefine "}"" >> ${dir}/GEN_$filename.hcl
- elif [[ $s == "#htifdef "* ]]; then
- # Add macro when token is found
- echo "#ifdef "${s#"#htifdef "}"" >> ${dir}/GEN_$filename.hcl
- elif [[ $s == "#htifndef "* ]]; then
- # Add macro when token is found
- echo "#ifndef "${s#"#htifndef "}"" >> ${dir}/GEN_$filename.hcl
- elif [[ $s == "#htelse"* ]]; then
- # Add macro when token is found
- echo "#else" >> ${dir}/GEN_$filename.hcl
- elif [[ $s == "#htendif"* ]]; then
- # Add macro when token is found
- echo "#endif" >> ${dir}/GEN_$filename.hcl
- elif [[ $s == "#htendvar"* ]]; then
- # Add macro when token is found
- echo ";" >> ${dir}/GEN_$filename.hcl
- else
- quotations=$(echo "$s" | sed 's|"|\\"|g')
- echo "$quotations" | sed 's/^.\{1,\}$/"&\\n"/' >> ${dir}/GEN_$filename.hcl
- fi
- fi
- done < $fi
-done
diff --git a/gpu4s_benchmark/cifar_10/CMakeLists.txt b/gpu4s_benchmark/cifar_10/CMakeLists.txt
new file mode 100644
index 00000000..759dc77b
--- /dev/null
+++ b/gpu4s_benchmark/cifar_10/CMakeLists.txt
@@ -0,0 +1,303 @@
+# =======================================================================
+# File: CMakeLists.txt (./cifar_10)
+# Description: Build targets for CIFAR-10 benchmark
+# Target: CPU, OpenMP, OpenCL, CUDA, HIP
+# License: ESA-PL Strong Copyleft – v2.5
+# =======================================================================
+
+cmake_minimum_required(VERSION 3.24)
+project(cifar_10 CXX)
+
+# ====== Include cmake module ======
+list(APPEND CMAKE_MODULE_PATH
+ "${CMAKE_CURRENT_SOURCE_DIR}/../common/cmake/"
+ "${CMAKE_CURRENT_SOURCE_DIR}/../common/cmake/module"
+)
+# Global:
+include(setup)
+include(compileBlueprint)
+# Module:
+include(findOpenMP)
+include(findHIP)
+include(findOpenBLAS)
+include(findCUDNN)
+
+# show the configuration of the project
+if(PROJECT_IS_TOP_LEVEL)
+ showConfig()
+endif()
+
+# ====== Compilation of the targets ======
+
+# --- CPU target ---
+compile_target(${PROJECT_NAME}_cpu
+ BENCH_DIR ${CMAKE_CURRENT_SOURCE_DIR}
+ SOURCES_FILES cpu/lib_cpu.cpp
+ SHORTCUTS_NAMES cpu CPU
+)
+
+# --- Android Targets---
+if(ANDROID)
+
+ if(ANDROID_OPENCL_LIB_INC)
+ # --- OpenCL ---
+ compile_target(${PROJECT_NAME}_opencl
+ BENCH_DIR ${CMAKE_CURRENT_SOURCE_DIR}
+ SOURCES_FILES opencl/lib_opencl.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 cl OpenCL
+ )
+
+ # --- OpenCL-opt ---
+ compile_target(${PROJECT_NAME}_opencl_opt
+ BENCH_DIR ${CMAKE_CURRENT_SOURCE_DIR}
+ SOURCES_FILES opencl/lib_opencl_opt.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-opt OpenCL-opt
+ )
+
+ endif()
+
+ # --- OpenMP---
+ compile_target(${PROJECT_NAME}_openmp
+ BENCH_DIR ${CMAKE_CURRENT_SOURCE_DIR}
+ SOURCES_FILES openmp/lib_omp.cpp
+ openmp/omp_common.cpp
+
+ COMPILE_DEFS OPENMP
+ COMPILE_OPTIONS -fopenmp
+ LIBRARIES -static-openmp #openmp flags
+ -fopenmp
+ -lm # add math lib
+
+ SHORTCUTS_NAMES openmp OpenMP
+ )
+
+
+ # --- OpenMP-opt ---
+ compile_target(${PROJECT_NAME}_openmp_opt
+ BENCH_DIR ${CMAKE_CURRENT_SOURCE_DIR}
+ SOURCES_FILES openmp/lib_omp_opt.cpp
+ openmp/omp_common.cpp
+
+ COMPILE_DEFS OPENMP
+ COMPILE_OPTIONS -fopenmp
+ LIBRARIES -static-openmp #openmp flags
+ -fopenmp
+ -lm # add math lib
+
+ SHORTCUTS_NAMES openmp-opt OpenMP-opt
+ )
+
+endif(ANDROID)
+
+# --- Computeur targets ---
+if(NOT ANDROID)
+ # --- OpenCL Targets ---
+ if(OpenCL_FOUND)
+ # --- OpenCL ---
+ compile_target(${PROJECT_NAME}_opencl
+ BENCH_DIR ${CMAKE_CURRENT_SOURCE_DIR}
+ SOURCES_FILES opencl/lib_opencl.cpp
+ opencl/lib_opencl_common.cpp
+
+ COMPILE_DEFS OPENCL
+ CL_HPP_TARGET_OPENCL_VERSION=${OPENCL_VERSION}
+
+ LIBRARIES OpenCL::OpenCL
+ SHORTCUTS_NAMES cl OpenCL
+ )
+
+ # --- OpenCL-opt ---
+ compile_target(${PROJECT_NAME}_opencl_opt
+ BENCH_DIR ${CMAKE_CURRENT_SOURCE_DIR}
+ SOURCES_FILES opencl/lib_opencl_opt.cpp
+ opencl/lib_opencl_common.cpp
+
+ COMPILE_DEFS OPENCL
+ CL_HPP_TARGET_OPENCL_VERSION=${OPENCL_VERSION}
+
+ LIBRARIES OpenCL::OpenCL
+ SHORTCUTS_NAMES opencl-opt OpenCL-opt
+ )
+
+
+ endif()
+
+ # --- OpenMP Targets ---
+ if(OpenMP_CXX_FOUND)
+ # --- OpenMP ---
+ compile_target(${PROJECT_NAME}_openmp
+ BENCH_DIR ${CMAKE_CURRENT_SOURCE_DIR}
+ SOURCES_FILES openmp/lib_omp.cpp
+ openmp/omp_common.cpp
+
+ COMPILE_DEFS OPENMP
+
+ LIBRARIES OpenMP::OpenMP_CXX # openmp flags
+ m # equivalent to -lm
+
+ SHORTCUTS_NAMES openmp OpenMP
+ )
+
+ # --- OpenMP-opt ---
+ compile_target(${PROJECT_NAME}_openmp_opt
+ BENCH_DIR ${CMAKE_CURRENT_SOURCE_DIR}
+ SOURCES_FILES openmp/lib_omp_opt.cpp
+ openmp/omp_common.cpp
+
+ COMPILE_DEFS OPENMP
+
+ LIBRARIES OpenMP::OpenMP_CXX # openmp flags
+ m # equivalent to -lm
+
+ SHORTCUTS_NAMES openmp-opt OpenMP-opt
+ )
+
+
+ endif()
+
+
+ # --- CUDA Targets---
+ if(CUDAToolkit_FOUND)
+ # --- CUDA ---
+ compile_target(${PROJECT_NAME}_cuda
+ BENCH_DIR ${CMAKE_CURRENT_SOURCE_DIR}
+ SOURCES_FILES cuda/lib_cuda.cu
+ cuda/cuda_common.cu
+
+ COMPILE_DEFS CUDA
+ SET_CUDA 1
+ LIBRARIES CUDA::cudart
+ SHORTCUTS_NAMES cuda CUDA
+ )
+
+ # --- CUDA-opt ---
+ compile_target(${PROJECT_NAME}_cuda_opt
+ BENCH_DIR ${CMAKE_CURRENT_SOURCE_DIR}
+ SOURCES_FILES cuda/lib_cuda_opt.cu
+ cuda/cuda_common.cu
+
+ COMPILE_DEFS CUDA
+ SET_CUDA 1
+ LIBRARIES CUDA::cudart
+ SHORTCUTS_NAMES cuda-opt CUDA-opt
+ )
+
+ if(CUDNN_FOUND)
+ # --- CUDA-lib ---
+ compile_target(${PROJECT_NAME}_cuda_lib
+ BENCH_DIR ${CMAKE_CURRENT_SOURCE_DIR}
+ SOURCES_FILES cuda/lib_cuda_lib.cu
+ cuda/cuda_common.cu
+
+ COMPILE_DEFS CUDA
+ SET_CUDA 1
+ LIBRARIES CUDA::cudart CUDA::cublas cudnn
+ SHORTCUTS_NAMES cuda-lib CUDA-lib
+ )
+ endif()
+
+
+
+ endif()
+
+ # --- HIP targets---
+ if(hip_FOUND)
+ # --- HIP ---
+ compile_target(${PROJECT_NAME}_hip
+ BENCH_DIR ${CMAKE_CURRENT_SOURCE_DIR}
+ SOURCES_FILES hip/lib_hip.cpp
+ hip/hip_common.cpp
+
+ SET_HIP_FILES hip/lib_hip.cpp
+ hip/hip_common.cpp
+
+ COMPILE_DEFS HIP
+ LIBRARIES hip::host
+ SHORTCUTS_NAMES hip- HIP
+ )
+
+ # --- HIP-opt ---
+ compile_target(${PROJECT_NAME}_hip_opt
+ BENCH_DIR ${CMAKE_CURRENT_SOURCE_DIR}
+ SOURCES_FILES hip/lib_hip_opt.cpp
+ hip/hip_common.cpp
+
+ SET_HIP_FILES hip/lib_hip_opt.cpp
+ hip/hip_common.cpp
+
+ COMPILE_DEFS HIP
+ LIBRARIES hip::host
+ SHORTCUTS_NAMES hip-opt HIP-opt
+ )
+ endif()
+endif(NOT ANDROID)
+
+
+# ====== Shorcuts ======
+
+# --- all-opencl (Android) ---
+if(ANDROID AND ANDROID_OPENCL_LIB_INC )
+ add_custom_target(${SHORTCUT_PREFIX}all-opencl DEPENDS
+ ${PROJECT_NAME}_opencl
+ ${PROJECT_NAME}_opencl_opt
+ )
+endif()
+
+# --- all-opencl---
+if(NOT ANDROID AND OpenCL_FOUND )
+ add_custom_target(${SHORTCUT_PREFIX}all-opencl DEPENDS
+ ${PROJECT_NAME}_opencl
+ ${PROJECT_NAME}_opencl_opt
+ )
+endif()
+
+
+# --- all-openmp (Android) ---
+if(ANDROID AND ANDROID_OPENBLAS_LIB_INC )
+ add_custom_target(${SHORTCUT_PREFIX}all-openmp DEPENDS
+ ${PROJECT_NAME}_openmp
+ ${PROJECT_NAME}_openmp_opt
+ )
+endif()
+
+
+# --- all-openmp---
+if(NOT ANDROID AND OpenMP_CXX_FOUND )
+ add_custom_target(${SHORTCUT_PREFIX}all-openmp DEPENDS
+ ${PROJECT_NAME}_openmp
+ ${PROJECT_NAME}_openmp_opt
+ )
+endif()
+
+
+# --- all-hip---
+if(NOT ANDROID AND hip_FOUND)
+ add_custom_target(${SHORTCUT_PREFIX}all-hip DEPENDS
+ ${PROJECT_NAME}_hip
+ ${PROJECT_NAME}_hip_opt
+ )
+endif()
+
+
+# --- all-cuda---
+if(NOT ANDROID AND CUDAToolkit_FOUND)
+ add_custom_target(${SHORTCUT_PREFIX}all-cuda DEPENDS
+ ${PROJECT_NAME}_cuda
+ ${PROJECT_NAME}_cuda_opt
+ ${PROJECT_NAME}_cuda_lib
+ )
+endif()
\ No newline at end of file
diff --git a/gpu4s_benchmark/cifar_10/Makefile b/gpu4s_benchmark/cifar_10/Makefile
index 9807c8f6..36620cea 100644
--- a/gpu4s_benchmark/cifar_10/Makefile
+++ b/gpu4s_benchmark/cifar_10/Makefile
@@ -2,14 +2,16 @@
# Compilers
CC = g++
NVCC = /usr/local/cuda/bin/nvcc
-HIP = /opt/rocm/hip/bin/hipcc
+HIP = hipcc #ubuntu : /opt/rocm/hip/bin/hipcc
# the build target executable:
TARGET = cifar_10
# FLAGS
# CC compiler flags:
CFLAGS = -g
# NVCC compiler flags
-NVCCFLAGS = -arch compute_72 -code sm_72
+# Automatically targets the host machine's local GPU (Supported in CUDA 11.5.1+)
+# Note: For cross-compiling or older legacy gpu, set target (e.g., -arch=sm_72)
+NVCCFLAGS = -arch=native -O3
# CUDA FLAGS
CUFLAGS = -I/usr/local/cuda/include/ -L/usr/local/cuda/lib64 -lcuda -lcudart
# OPENCL FLAGS
@@ -52,13 +54,13 @@ all:
# End Main
# Shortcuts
.PHONY: all-bin
-all-bin: cuda cuda-opt cuda-lib opencl opencl-opt opencl-lib openmp openmp-opt openmp-lib hip hip-opt
+all-bin: cuda cuda-opt cuda-lib opencl opencl-opt openmp openmp-opt hip hip-opt
.PHONY: all-cuda
all-cuda: cuda cuda-opt cuda-lib
.PHONY: all-opencl
-all-opencl: opencl opencl-opt opencl-lib
+all-opencl: opencl opencl-opt
.PHONY: all-openmp
-all-openmp: openmp openmp-opt openmp-lib
+all-openmp: openmp openmp-opt
.PHONY: CUDA
CUDA: cuda
.PHONY: OpenCL
@@ -77,14 +79,11 @@ OpenMP-opt: openmp-opt
Hip-opt: hip-opt
.PHONY: CUDA-lib
CUDA-lib: cuda-lib
-.PHONY: OpenCL-lib
-OpenCL-lib: opencl-lib
-.PHONY: OpenMP-lib
-OpenMP-lib: opencl-lib
+
# End Shortcuts
# CPU part
cpu_functions.o: $(CPUFUNCTIONFOLDER)cpu_functions.cpp
- $(CC) $(ENDIANFLAGS) -D$(DATATYPE) -c $(CPUFUNCTIONFOLDER)cpu_functions.cpp -o $(CPUFUNCTIONFOLDER)cpu_functions.o $(CFLAGS)
+ $(CC) $(ENDIANFLAGS) -D$(DATATYPE) -fPIC -c $(CPUFUNCTIONFOLDER)cpu_functions.cpp -o $(CPUFUNCTIONFOLDER)cpu_functions.o $(CFLAGS)
# End CPU
# CUDA part
@@ -211,18 +210,6 @@ main_cuda_lib: main.cpp lib_cuda_lib.o cpu_functions.o
# End CUDA library
-# OpenCL Part library
-opencl-lib: main_opencl_lib
-
-lib_opencl_lib.o: $(OPFOLDER)lib_opencl_lib.cpp
- $(CC) -D$(DATATYPE) -DOPENCL -c $(OPFOLDER)lib_opencl_lib.cpp -o $(OPFOLDER)lib_opencl_lib.o $(CFLAGS) $(OPFLAGS) -I/home/irodrig/clBlast/include/ -L/home/irodrig/clBlast/lib/ -lclblast
-
-main_opencl_lib: main.cpp lib_opencl_lib.o cpu_functions.o
- mkdir -p $(OUTPUTFOLDER)
- $(CC) -D$(DATATYPE) -DOPENCL main.cpp $(OPFOLDER)lib_opencl_lib.o $(CPUFUNCTIONFOLDER)cpu_functions.o -o $(OUTPUTFOLDER)$(TARGET)_opencl_lib_$(shell echo $(DATATYPE) | tr A-Z a-z) $(CFLAGS) $(OPFLAGS) -I/home/irodrig/clBlast/include/ -L/home/irodrig/clBlast/lib/ -lclblast
-
-# End OpenCL library
-
# Clean
.PHONY: clean
clean:
diff --git a/gpu4s_benchmark/cifar_10/benchmark_library.h b/gpu4s_benchmark/cifar_10/benchmark_library.h
index 303467ec..38809500 100644
--- a/gpu4s_benchmark/cifar_10/benchmark_library.h
+++ b/gpu4s_benchmark/cifar_10/benchmark_library.h
@@ -1,178 +1,155 @@
-#include
-#include
-#include
-#include
+/** * ====================================================================
+ * @file benchmark_library.h (./cifar_10)
+ * @brief Specific memory structures and function overloads
+ * for the Cifar 10 benchmark.
+ * @paragraph License
+ * ESA-PL Strong Copyleft – v2.5
+ * ======================================================================= */
+#pragma once
+// Include all the benchmark common variable, struct, prototype, lib
+#include "benchmark_common.h"
+#include "Clock.h"
+// ======= Benchmark local variable =======
+// --- Compute ---
+const bench_t K = 2;
+const bench_t ALPHA = 10e-4;
+const bench_t BETA = 0.75;
-#ifdef INT
-typedef int bench_t;
-#define __ptype "%d"
-static const std::string type_kernel = "typedef int bench_t;\n";
-#elif FLOAT
-typedef float bench_t;
-#define __ptype "%f"
-static const std::string type_kernel = "typedef float bench_t;\n";
-const float K = 2;
-const float ALPHA = 10e-4;
-const float BETA = 0.75;
-#elif DOUBLE
-typedef double bench_t;
-#define __ptype "%f"
-static const std::string type_kernel = "#pragma OPENCL EXTENSION cl_khr_fp64 : enable\ntypedef double bench_t;\n";
-const double K = 2;
-const double ALPHA = 10e-4;
-const double BETA = 0.75;
-#else
- // printf type helper, will resolve to %d or %f given the computed type
- #define __ptype "%f"
-#endif
-
-#ifdef CUDA
-// CUDA lib
-#include
-#elif OPENCL
-// OpenCL lib
-//#include
-#include
-#elif OPENMP
-// OpenMP lib
-#include
-#elif HIP
-// HIP part
-#include
-#else
-// CPU part
-#endif
-
-
-#ifndef BENCHMARK_H
-#define BENCHMARK_H
-struct GraficObject{
+struct GraficObject : public GraficCommon {
#ifdef CUDA
- // CUDA PART
- bench_t* input_data;
- bench_t* kernel_1;
- bench_t* conv_1_output;
- bench_t* pooling_1_output;
- bench_t* kernel_2;
- bench_t* conv_2_output;
- bench_t* pooling_2_output;
- bench_t* dense_layer_1_weights;
- bench_t* dense_layer_1_output;
- bench_t* dense_layer_2_weights;
- bench_t* dense_layer_2_output;
- bench_t* output_data;
- bench_t* sum_ouput;
-
- cudaEvent_t *start_memory_copy_device;
- cudaEvent_t *stop_memory_copy_device;
- cudaEvent_t *start_memory_copy_host;
- cudaEvent_t *stop_memory_copy_host;
- cudaEvent_t *start;
- cudaEvent_t *stop;
+ // CUDA PART
+ bench_t* input_data;
+ bench_t* kernel_1;
+ bench_t* conv_1_output;
+ bench_t* pooling_1_output;
+ bench_t* kernel_2;
+ bench_t* conv_2_output;
+ bench_t* pooling_2_output;
+ bench_t* dense_layer_1_weights;
+ bench_t* dense_layer_1_output;
+ bench_t* dense_layer_2_weights;
+ bench_t* dense_layer_2_output;
+ bench_t* output_data;
+ bench_t* sum_ouput;
#elif OPENCL
- // OpenCL PART
- cl::Context *context;
- cl::CommandQueue *queue;
- cl::Device default_device;
- cl::Event *evt_copyIN;
- cl::Event *evt_copyK1;
- cl::Event *evt_copyK2;
- cl::Event *evt_copyW1;
- cl::Event *evt_copyW2;
- cl::Event *evt_copyOut;
- cl::Event *evt1_1;
- cl::Event *evt1_2;
- cl::Event *evt1_3;
- cl::Event *evt1_4;
- cl::Event *evt2_1;
- cl::Event *evt2_2;
- cl::Event *evt2_3;
- cl::Event *evt2_4;
- cl::Event *evtd_1;
- cl::Event *evtd_1_a;
- cl::Event *evtd_2;
- cl::Event *evtd_2_a;
- cl::Event *evt_softmax;
- cl::Event *evt_softmax_fin;
-
- cl::Buffer *input_data;
- cl::Buffer *kernel_1;
- cl::Buffer *conv_1_output;
- cl::Buffer *pooling_1_output;
- cl::Buffer *kernel_2;
- cl::Buffer *conv_2_output;
- cl::Buffer *pooling_2_output;
- cl::Buffer *dense_layer_1_weights;
- cl::Buffer *dense_layer_1_output;
- cl::Buffer *dense_layer_2_weights;
- cl::Buffer *dense_layer_2_output;
- cl::Buffer *output_data;
- cl::Buffer *sum_ouput;
-
- #elif OPENMP
- // OpenMP part
- bench_t* input_data;
- bench_t* kernel_1;
- bench_t* conv_1_output;
- bench_t* pooling_1_output;
- bench_t* kernel_2;
- bench_t* conv_2_output;
- bench_t* pooling_2_output;
- bench_t* dense_layer_1_weights;
- bench_t* dense_layer_1_output;
- bench_t* dense_layer_2_weights;
- bench_t* dense_layer_2_output;
- bench_t* output_data;
+ // OpenCL PART
+ cl::Event *evt_copyIN;
+ cl::Event *evt_copyK1;
+ cl::Event *evt_copyK2;
+ cl::Event *evt_copyW1;
+ cl::Event *evt_copyW2;
+ cl::Event *evt_copyOut;
+ cl::Event *evt1_1;
+ cl::Event *evt1_2;
+ cl::Event *evt1_3;
+ cl::Event *evt1_4;
+ cl::Event *evt2_1;
+ cl::Event *evt2_2;
+ cl::Event *evt2_3;
+ cl::Event *evt2_4;
+ cl::Event *evtd_1;
+ cl::Event *evtd_1_a;
+ cl::Event *evtd_2;
+ cl::Event *evtd_2_a;
+ cl::Event *evt_softmax;
+ cl::Event *evt_softmax_fin;
+ cl::Buffer *input_data;
+ cl::Buffer *kernel_1;
+ cl::Buffer *conv_1_output;
+ cl::Buffer *pooling_1_output;
+ cl::Buffer *kernel_2;
+ cl::Buffer *conv_2_output;
+ cl::Buffer *pooling_2_output;
+ cl::Buffer *dense_layer_1_weights;
+ cl::Buffer *dense_layer_1_output;
+ cl::Buffer *dense_layer_2_weights;
+ cl::Buffer *dense_layer_2_output;
+ cl::Buffer *output_data;
+ cl::Buffer *sum_ouput;
#elif HIP
- bench_t* input_data;
- bench_t* kernel_1;
- bench_t* conv_1_output;
- bench_t* pooling_1_output;
- bench_t* kernel_2;
- bench_t* conv_2_output;
- bench_t* pooling_2_output;
- bench_t* dense_layer_1_weights;
- bench_t* dense_layer_1_output;
- bench_t* dense_layer_2_weights;
- bench_t* dense_layer_2_output;
- bench_t* output_data;
- bench_t* sum_ouput;
- hipEvent_t *start_memory_copy_device;
- hipEvent_t *stop_memory_copy_device;
- hipEvent_t *start_memory_copy_host;
- hipEvent_t *stop_memory_copy_host;
- hipEvent_t *start;
- hipEvent_t *stop;
-
+ //HIP part
+ bench_t* input_data;
+ bench_t* kernel_1;
+ bench_t* conv_1_output;
+ bench_t* pooling_1_output;
+ bench_t* kernel_2;
+ bench_t* conv_2_output;
+ bench_t* pooling_2_output;
+ bench_t* dense_layer_1_weights;
+ bench_t* dense_layer_1_output;
+ bench_t* dense_layer_2_weights;
+ bench_t* dense_layer_2_output;
+ bench_t* output_data;
+ bench_t* sum_ouput;
+ #elif OPENMP
+ // OpenMP part
+ bench_t* input_data;
+ bench_t* kernel_1;
+ bench_t* conv_1_output;
+ bench_t* pooling_1_output;
+ bench_t* kernel_2;
+ bench_t* conv_2_output;
+ bench_t* pooling_2_output;
+ bench_t* dense_layer_1_weights;
+ bench_t* dense_layer_1_output;
+ bench_t* dense_layer_2_weights;
+ bench_t* dense_layer_2_output;
+ bench_t* output_data;
#else
- // CPU part
- bench_t* input_data;
- bench_t* kernel_1;
- bench_t* conv_1_output;
- bench_t* pooling_1_output;
- bench_t* kernel_2;
- bench_t* conv_2_output;
- bench_t* pooling_2_output;
- bench_t* dense_layer_1_weights;
- bench_t* dense_layer_1_output;
- bench_t* dense_layer_2_weights;
- bench_t* dense_layer_2_output;
- bench_t* output_data;
+ // CPU part
+ bench_t* input_data;
+ bench_t* kernel_1;
+ bench_t* conv_1_output;
+ bench_t* pooling_1_output;
+ bench_t* kernel_2;
+ bench_t* conv_2_output;
+ bench_t* pooling_2_output;
+ bench_t* dense_layer_1_weights;
+ bench_t* dense_layer_1_output;
+ bench_t* dense_layer_2_weights;
+ bench_t* dense_layer_2_output;
+ bench_t* output_data;
#endif
- float elapsed_time;
};
-void init(GraficObject *device_object, char* device_name);
-void init(GraficObject *device_object, int platform, int device, char* device_name);
-bool device_memory_init(GraficObject *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(GraficObject *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(GraficObject *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_host(GraficObject *device_object, bench_t* h_C, int size);
-float get_elapsed_time(GraficObject *device_object, bool csv_format, bool csv_format_timestamp, long int timestamp);
-void clean(GraficObject *device_object);
+// --- Specefic overload of benchmarking function ---
+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
+// --- 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/bin/cifar_10_cpu_float b/gpu4s_benchmark/cifar_10/bin/cifar_10_cpu_float
new file mode 100755
index 00000000..87916b43
Binary files /dev/null and b/gpu4s_benchmark/cifar_10/bin/cifar_10_cpu_float differ
diff --git a/gpu4s_benchmark/cifar_10/cpu/lib_cpu.cpp b/gpu4s_benchmark/cifar_10/cpu/lib_cpu.cpp
index a8f5ffc7..635815f9 100644
--- a/gpu4s_benchmark/cifar_10/cpu/lib_cpu.cpp
+++ b/gpu4s_benchmark/cifar_10/cpu/lib_cpu.cpp
@@ -152,140 +152,149 @@ void softmax_kernel(const bench_t *A, bench_t *B, const int size)
}
-void init(GraficObject *device_object, char* device_name)
+void init(GraficCommon* device_object, char* device_name)
{
init(device_object, 0,0, device_name);
}
-void init(GraficObject *device_object, int platform ,int device, char* device_name)
+void init(GraficCommon* device_object, int platform ,int device, char* device_name)
{
// TBD Feature: device name. -- Bulky generic platform implementation
strcpy(device_name,"Generic device");
}
-bool device_memory_init(GraficObject *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)
+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)
{
+ GraficObject* deviceObj = static_cast(device_object);
const unsigned int size_pooling_1 = input_data / stride_1;
const unsigned int size_pooling_2 = size_pooling_1 / stride_2;
const unsigned int weights_layer_1 = size_pooling_2 * size_pooling_2 * neurons_dense_1;
const unsigned int weights_layer_2 = neurons_dense_1 * neurons_dense_2;
// Convolution 1
- device_object->conv_1_output = (bench_t*) malloc ( input_data * input_data * sizeof(bench_t*));
+ deviceObj->conv_1_output = (bench_t*) malloc ( input_data * input_data * sizeof(bench_t*));
// Pooling 1
- device_object->pooling_1_output = (bench_t*) malloc ( size_pooling_1 * size_pooling_1 * sizeof(bench_t));
+ deviceObj->pooling_1_output = (bench_t*) malloc ( size_pooling_1 * size_pooling_1 * sizeof(bench_t));
// Convolution 2
- device_object->conv_2_output = (bench_t*) malloc ( size_pooling_1 * size_pooling_1 * sizeof(bench_t*));
+ deviceObj->conv_2_output = (bench_t*) malloc ( size_pooling_1 * size_pooling_1 * sizeof(bench_t*));
// Pooling 2
- device_object->pooling_2_output = (bench_t*) malloc ( size_pooling_2 * size_pooling_2 * sizeof(bench_t));
+ deviceObj->pooling_2_output = (bench_t*) malloc ( size_pooling_2 * size_pooling_2 * sizeof(bench_t));
// Dense 1
- device_object->dense_layer_1_output = (bench_t*) malloc ( neurons_dense_1 * sizeof(bench_t));
+ deviceObj->dense_layer_1_output = (bench_t*) malloc ( neurons_dense_1 * sizeof(bench_t));
// Dense 2
- device_object->dense_layer_2_output = (bench_t*) malloc ( neurons_dense_2 * sizeof(bench_t));
+ deviceObj->dense_layer_2_output = (bench_t*) malloc ( neurons_dense_2 * sizeof(bench_t));
// Output data
- device_object->output_data = (bench_t*) malloc ( neurons_dense_2 * sizeof(bench_t));
+ deviceObj->output_data = (bench_t*) malloc ( neurons_dense_2 * sizeof(bench_t));
return true;
}
-void copy_memory_to_device(GraficObject *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 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)
{
+ GraficObject* deviceObj = static_cast(device_object);
// Input data
- device_object->input_data = input_data;
- device_object->kernel_1 = kernel_1_data;
- device_object->kernel_2 = kernel_2_data;
- device_object->dense_layer_1_weights = weights_1;
- device_object->dense_layer_2_weights = weights_2;
+ deviceObj->input_data = input_data;
+ deviceObj->kernel_1 = kernel_1_data;
+ deviceObj->kernel_2 = kernel_2_data;
+ deviceObj->dense_layer_1_weights = weights_1;
+ deviceObj->dense_layer_2_weights = weights_2;
}
-void execute_kernel(GraficObject *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 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);
+ Clock kernelCLK;
+
// Start compute timer
- struct timespec start, end;
- clock_gettime(CLOCK_MONOTONIC_RAW, &start);
+ kernelCLK.start();
// 1-1 Step convolution
- convolution_kernel(device_object->input_data, device_object->conv_1_output, device_object->kernel_1, input_data, input_data, input_data, kernel_1);
+ convolution_kernel(deviceObj->input_data, deviceObj->conv_1_output, deviceObj->kernel_1, input_data, input_data, input_data, kernel_1);
// 1-2 Step activation
- relu_kernel(device_object->conv_1_output, device_object->conv_1_output, input_data);
+ relu_kernel(deviceObj->conv_1_output, deviceObj->conv_1_output, input_data);
// 1-3 Step pooling
const unsigned int size_lateral_1 = input_data / stride_1;
- max_pooling_kernel(device_object->conv_1_output, device_object->pooling_1_output, input_data, stride_1, size_lateral_1);
+ max_pooling_kernel(deviceObj->conv_1_output, deviceObj->pooling_1_output, input_data, stride_1, size_lateral_1);
// 1-4 Normalization
- lrn_kernel(device_object->pooling_1_output, device_object->pooling_1_output, size_lateral_1);
+ lrn_kernel(deviceObj->pooling_1_output, deviceObj->pooling_1_output, size_lateral_1);
// 2-1 Step convolution
- convolution_kernel(device_object->pooling_1_output, device_object->conv_2_output, device_object->kernel_2, size_lateral_1, size_lateral_1, size_lateral_1, kernel_2);
+ convolution_kernel(deviceObj->pooling_1_output, deviceObj->conv_2_output, deviceObj->kernel_2, size_lateral_1, size_lateral_1, size_lateral_1, kernel_2);
// 2-2 Step activation
- relu_kernel(device_object->conv_2_output, device_object->conv_2_output, size_lateral_1);
+ relu_kernel(deviceObj->conv_2_output, deviceObj->conv_2_output, size_lateral_1);
// 2-3 Normalization
- lrn_kernel(device_object->conv_2_output, device_object->conv_2_output, size_lateral_1);
+ lrn_kernel(deviceObj->conv_2_output, deviceObj->conv_2_output, size_lateral_1);
// 2-4 Step pooling
const unsigned int size_lateral_2 = size_lateral_1 / stride_2;
- max_pooling_kernel(device_object->conv_2_output, device_object->pooling_2_output, size_lateral_1, stride_2, size_lateral_2);
+ max_pooling_kernel(deviceObj->conv_2_output, deviceObj->pooling_2_output, size_lateral_1, stride_2, size_lateral_2);
// Dense layer 1
- matrix_multiplication_kernel(device_object->dense_layer_1_weights, device_object->pooling_2_output,device_object->dense_layer_1_output,neurons_dense_1, 1, size_lateral_2*size_lateral_2);
+ matrix_multiplication_kernel(deviceObj->dense_layer_1_weights, deviceObj->pooling_2_output,deviceObj->dense_layer_1_output,neurons_dense_1, 1, size_lateral_2*size_lateral_2);
// Activation layer dense 1
- relu_linear_kernel(device_object->dense_layer_1_output, device_object->dense_layer_1_output, neurons_dense_1);
+ relu_linear_kernel(deviceObj->dense_layer_1_output, deviceObj->dense_layer_1_output, neurons_dense_1);
// Dense layer 2
- matrix_multiplication_kernel(device_object->dense_layer_2_weights, device_object->dense_layer_1_output, device_object->dense_layer_2_output, neurons_dense_2, 1, neurons_dense_1);
+ matrix_multiplication_kernel(deviceObj->dense_layer_2_weights, deviceObj->dense_layer_1_output, deviceObj->dense_layer_2_output, neurons_dense_2, 1, neurons_dense_1);
// Activation layer dense 2
- relu_linear_kernel(device_object->dense_layer_2_output, device_object->dense_layer_2_output, neurons_dense_2);
+ relu_linear_kernel(deviceObj->dense_layer_2_output, deviceObj->dense_layer_2_output, neurons_dense_2);
// Softmax - Output
- softmax_kernel(device_object->dense_layer_2_output, device_object->output_data, neurons_dense_2);
+ softmax_kernel(deviceObj->dense_layer_2_output, deviceObj->output_data, neurons_dense_2);
// End compute timer
- clock_gettime(CLOCK_MONOTONIC_RAW, &end);
- device_object->elapsed_time = (end.tv_sec - start.tv_sec) * 1000 + (end.tv_nsec - start.tv_nsec) / 1000000;
+ kernelCLK.end();
+ //FIX: add float division
+ deviceObj->elapsed_time = kernelCLK.getElapsedMS();
}
-void copy_memory_to_host(GraficObject *device_object, bench_t* h_C, int size)
-{
- memcpy(h_C, &device_object->output_data[0], sizeof(bench_t)*size);
+void copy_memory_to_host(GraficCommon* device_object, bench_t* h_C, int size)
+{
+ GraficObject* deviceObj = static_cast(device_object);
+ memcpy(h_C, &deviceObj->output_data[0], sizeof(bench_t)*size);
}
-float get_elapsed_time(GraficObject *device_object, bool csv_format,bool csv_format_timestamp, long int current_time)
+float get_elapsed_time(GraficCommon* device_object, bool csv_format,bool csv_format_timestamp, long int current_time)
{
+ GraficObject* deviceObj = static_cast(device_object);
if (csv_format_timestamp){
- printf("%.10f;%.10f;%.10f;%ld;\n", (bench_t) 0, device_object->elapsed_time * 1000.f, (bench_t) 0, current_time);
+ printf("%.10f;%.10f;%.10f;%ld;\n", (bench_t) 0, deviceObj->elapsed_time, (bench_t) 0, current_time);
}
else if (csv_format)
{
- printf("%.10f;%.10f;%.10f;\n", (bench_t) 0, device_object->elapsed_time * 1000.f, (bench_t) 0);
+ printf("%.10f;%.10f;%.10f;\n", (bench_t) 0, deviceObj->elapsed_time, (bench_t) 0);
}
else
- {
+ {
+ //--- FIX: print te time in milliseconds
printf("Elapsed time Host->Device: %.10f milliseconds\n", (bench_t) 0);
- printf("Elapsed time kernel: %.10f milliseconds\n", device_object->elapsed_time * 1000.f);
+ printf("Elapsed time kernel: %.10f milliseconds\n", deviceObj->elapsed_time);
printf("Elapsed time Device->Host: %.10f milliseconds\n", (bench_t) 0);
}
- return device_object->elapsed_time * 1000.f;
+ return deviceObj->elapsed_time;
}
-void clean(GraficObject *device_object)
+void clean(GraficCommon* device_object)
{
- free(device_object->conv_1_output);
- free(device_object->pooling_1_output);
- free(device_object->conv_2_output);
- free(device_object->pooling_2_output);
- free(device_object->dense_layer_1_output);
- free(device_object->dense_layer_2_output);
- free(device_object->output_data);
+ GraficObject* deviceObj = static_cast(device_object);
+ free(deviceObj->conv_1_output);
+ free(deviceObj->pooling_1_output);
+ free(deviceObj->conv_2_output);
+ free(deviceObj->pooling_2_output);
+ free(deviceObj->dense_layer_1_output);
+ free(deviceObj->dense_layer_2_output);
+ free(deviceObj->output_data);
}
\ No newline at end of file
diff --git a/gpu4s_benchmark/cifar_10/cpu_functions/cpu_functions.cpp b/gpu4s_benchmark/cifar_10/cpu_functions/cpu_functions.cpp
index e9b18968..9a87da57 100644
--- a/gpu4s_benchmark/cifar_10/cpu_functions/cpu_functions.cpp
+++ b/gpu4s_benchmark/cifar_10/cpu_functions/cpu_functions.cpp
@@ -209,7 +209,8 @@ bool compare_vectors(const bench_t* host,const bench_t* device, const int size){
return true;
#else
for (int i = 0; i < size; ++i){
- if (fabs(host[i] - device[i]) > 1e-4){
+ // FIx: tolerance relaxed to 1E-2 to be compatible with cuda_lib that use TF-32
+ if (fabs(host[i] - device[i]) > 1e-2){
printf("Error in element %d is %f but was %f\n", i,device[i], host[i]);
return false;
}
diff --git a/gpu4s_benchmark/cifar_10/cpu_functions/cpu_functions.h b/gpu4s_benchmark/cifar_10/cpu_functions/cpu_functions.h
index bb28f24d..3c777199 100644
--- a/gpu4s_benchmark/cifar_10/cpu_functions/cpu_functions.h
+++ b/gpu4s_benchmark/cifar_10/cpu_functions/cpu_functions.h
@@ -54,6 +54,8 @@ struct BenchmarkParameters{
bool csv_format = false;
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/cuda/cuda_common.cu b/gpu4s_benchmark/cifar_10/cuda/cuda_common.cu
new file mode 100644
index 00000000..ae0db0ff
--- /dev/null
+++ b/gpu4s_benchmark/cifar_10/cuda/cuda_common.cu
@@ -0,0 +1,349 @@
+/** * ====================================================================
+ * @file cuda_common.cu (./cifar_10)
+ * @brief Common CUDA platform initialization, device setup,
+ * profiling timer evaluation, and generic cleanup routines.
+ * @paragraph License
+ * ESA-PL Strong Copyleft – v2.5
+ * ======================================================================= */
+#include "../benchmark_library.h"
+
+void init(GraficCommon* device_object, char* device_name){
+ init(device_object, 0,0, device_name);
+}
+
+void init(GraficCommon* device_object, int platform ,int device, char* device_name){
+ GraficObject* deviceObj = static_cast(device_object);
+ cudaSetDevice(device);
+ cudaDeviceProp prop;
+ cudaGetDeviceProperties(&prop, device);
+ //printf("Using device: %s\n", prop.name);
+ strcpy(device_name,prop.name);
+ //event create
+ deviceObj->start = new cudaEvent_t;
+ deviceObj->stop = new cudaEvent_t;
+ deviceObj->start_memory_copy_device = new cudaEvent_t;
+ deviceObj->stop_memory_copy_device = new cudaEvent_t;
+ deviceObj->start_memory_copy_host = new cudaEvent_t;
+ deviceObj->stop_memory_copy_host= new cudaEvent_t;
+
+ cudaEventCreate(deviceObj->start);
+ cudaEventCreate(deviceObj->stop);
+ cudaEventCreate(deviceObj->start_memory_copy_device);
+ cudaEventCreate(deviceObj->stop_memory_copy_device);
+ cudaEventCreate(deviceObj->start_memory_copy_host);
+ cudaEventCreate(deviceObj->stop_memory_copy_host);
+}
+
+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){
+ GraficObject* deviceObj = static_cast(device_object);
+ // Allocate input
+ cudaError_t err = cudaSuccess;
+ err = cudaMalloc((void **)&deviceObj->input_data, input_data * input_data * sizeof(bench_t));
+
+ if (err != cudaSuccess)
+ {
+ return false;
+ }
+ // Allocate kernel
+ err = cudaMalloc((void **)&deviceObj->kernel_1, kernel_1 * kernel_1 * sizeof(bench_t));
+
+ if (err != cudaSuccess)
+ {
+ return false;
+ }
+ // Allocate conv 1 output
+ err = cudaMalloc((void **)&deviceObj->conv_1_output, input_data * input_data * sizeof(bench_t));
+
+ if (err != cudaSuccess)
+ {
+ return false;
+ }
+ // Allocate pooling output
+ unsigned int size_pooling_1 = input_data / stride_1;
+ err = cudaMalloc((void **)&deviceObj->pooling_1_output, size_pooling_1 * size_pooling_1 * sizeof(bench_t));
+
+ if (err != cudaSuccess)
+ {
+ return false;
+ }
+ // Allocate kernel 2
+ err = cudaMalloc((void **)&deviceObj->kernel_2, kernel_2 * kernel_2 * sizeof(bench_t));
+
+ if (err != cudaSuccess)
+ {
+ return false;
+ }
+ // Allocate conv 1 output
+ err = cudaMalloc((void **)&deviceObj->conv_2_output, size_pooling_1 * size_pooling_1 * sizeof(bench_t));
+
+ if (err != cudaSuccess)
+ {
+ return false;
+ }
+ // Allocate pooling output
+ unsigned int size_pooling_2 = size_pooling_1 / stride_2;
+ err = cudaMalloc((void **)&deviceObj->pooling_2_output, size_pooling_2 * size_pooling_2 * sizeof(bench_t));
+
+ if (err != cudaSuccess)
+ {
+ return false;
+ }
+ //dense layer 1 weights
+ unsigned int weights_layer_1 = size_pooling_2 * size_pooling_2 * neurons_dense_1;
+
+ err = cudaMalloc((void **)&deviceObj->dense_layer_1_weights, weights_layer_1* sizeof(bench_t));
+
+ if (err != cudaSuccess)
+ {
+ return false;
+ }
+ // dense layer output 1
+ err = cudaMalloc((void **)&deviceObj->dense_layer_1_output, neurons_dense_1 * sizeof(bench_t));
+
+ if (err != cudaSuccess)
+ {
+ return false;
+ }
+ //dense layer 2 weights
+ unsigned int weights_layer_2 = neurons_dense_1 * neurons_dense_2;
+ err = cudaMalloc((void **)&deviceObj->dense_layer_2_weights, weights_layer_2 * sizeof(bench_t));
+
+ if (err != cudaSuccess)
+ {
+ return false;
+ }
+ // dense layer output 2
+ err = cudaMalloc((void **)&deviceObj->dense_layer_2_output, neurons_dense_2 * sizeof(bench_t));
+
+ if (err != cudaSuccess)
+ {
+ return false;
+ }
+ // sum data
+ err = cudaMalloc((void **)&deviceObj->sum_ouput, sizeof(bench_t));
+
+ if (err != cudaSuccess)
+ {
+ return false;
+ }
+ // output data
+ err = cudaMalloc((void **)&deviceObj->output_data, neurons_dense_2 * sizeof(bench_t));
+
+ if (err != cudaSuccess)
+ {
+ return false;
+ }
+ return true;
+ }
+
+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){
+ GraficObject* deviceObj = static_cast(device_object);
+ // host -> device
+ Clock h2dCLK;
+
+ // profilling start
+ h2dCLK.start();
+ cudaEventRecord(*deviceObj->start_memory_copy_device);
+
+ cudaError_t err = cudaMemcpy(deviceObj->input_data, input_data, sizeof(bench_t) * input * input, cudaMemcpyHostToDevice);
+ if (err != cudaSuccess)
+ {
+ fprintf(stderr, "Failed to copy vector input from host to device (error code %s)!\n", cudaGetErrorString(err));
+ return;
+ }
+ err = cudaMemcpy(deviceObj->kernel_1, kernel_1_data, sizeof(bench_t) * kernel_size_1 * kernel_size_1, cudaMemcpyHostToDevice);
+ if (err != cudaSuccess)
+ {
+ fprintf(stderr, "Failed to copy vector kernel_1 from host to device (error code %s)!\n", cudaGetErrorString(err));
+ return;
+ }
+ err = cudaMemcpy(deviceObj->kernel_2, kernel_2_data, sizeof(bench_t) * kernel_size_2 * kernel_size_2, cudaMemcpyHostToDevice);
+ if (err != cudaSuccess)
+ {
+ fprintf(stderr, "Failed to copy vector kernel_2 from host to device (error code %s)!\n", cudaGetErrorString(err));
+ return;
+ }
+ err = cudaMemcpy(deviceObj->dense_layer_1_weights, weights_1, sizeof(bench_t) * weights_1_size, cudaMemcpyHostToDevice);
+ if (err != cudaSuccess)
+ {
+ fprintf(stderr, "Failed to copy vector weights_layer_1 from host to device (error code %s)!\n", cudaGetErrorString(err));
+ return;
+ }
+ err = cudaMemcpy(deviceObj->dense_layer_2_weights, weights_2, sizeof(bench_t) * weights_2_size, cudaMemcpyHostToDevice);
+ if (err != cudaSuccess)
+ {
+ fprintf(stderr, "Failed to copy vector weights_layer_2 from host to device (error code %s)!\n", cudaGetErrorString(err));
+ return;
+ }
+
+ // profilling end
+ cudaEventRecord(*deviceObj->stop_memory_copy_device);
+ h2dCLK.end();
+
+ // store the h2d time
+ deviceObj->h2d_elapsed_time = h2dCLK.getElapsedMS();
+}
+
+
+void copy_memory_to_host(GraficCommon* device_object, bench_t* h_C, int size){
+ GraficObject* deviceObj = static_cast(device_object);
+ // device -> host
+ Clock d2hCLK;
+
+ // profilling start
+ d2hCLK.start();
+ cudaEventRecord(*deviceObj->start_memory_copy_host);
+
+ cudaError_t err = cudaMemcpy(h_C, deviceObj->output_data, size * sizeof(bench_t), cudaMemcpyDeviceToHost);
+ if (err != cudaSuccess)
+ {
+ fprintf(stderr, "Failed to copy vector output_data from device to host (error code %s)!\n", cudaGetErrorString(err));
+ return;
+ }
+ //cudaMemcpy(h_C, deviceObj->dense_layer_2_output, 10 * sizeof(bench_t), cudaMemcpyDeviceToHost);
+
+ // profilling end
+ cudaEventRecord(*deviceObj->stop_memory_copy_host);
+ d2hCLK.end();
+
+ // store the hd2h time
+ deviceObj->d2h_elapsed_time = d2hCLK.getElapsedMS();
+}
+
+float get_elapsed_time(GraficCommon* device_object, bool csv_format,bool csv_format_timestamp, long int current_time){
+ GraficObject* deviceObj = static_cast(device_object);
+ cudaEventSynchronize(*deviceObj->stop_memory_copy_host); // wait
+
+ float milliseconds_h_d = 0, milliseconds = 0, milliseconds_d_h = 0;
+
+ if (deviceObj->profiling_clock)
+ {
+ // --- FIX: Use instead of CLBlast event profiling (unreliable on PROFILING_CLOCK) ---
+ milliseconds_h_d = deviceObj->h2d_elapsed_time;
+ milliseconds = deviceObj->elapsed_time;
+ milliseconds_d_h = deviceObj->d2h_elapsed_time;
+ }else{
+ // memory transfer time host-device
+ cudaEventElapsedTime(&milliseconds_h_d, *deviceObj->start_memory_copy_device, *deviceObj->stop_memory_copy_device);
+ // kernel time
+ cudaEventElapsedTime(&milliseconds, *deviceObj->start, *deviceObj->stop);
+ // memory transfer time device-host
+ cudaEventElapsedTime(&milliseconds_d_h, *deviceObj->start_memory_copy_host, *deviceObj->stop_memory_copy_host);
+ }
+
+ if (csv_format_timestamp){
+ printf("%.10f;%.10f;%.10f;%ld;\n", milliseconds_h_d,milliseconds,milliseconds_d_h, current_time);
+ }
+ else if (csv_format){
+ printf("%.10f;%.10f;%.10f;\n", milliseconds_h_d,milliseconds,milliseconds_d_h);
+ }else{
+ printf("profiling mode: %s\n", deviceObj->profiling_clock ? "CLOCK" : "GPU");
+ printf("Elapsed time Host->Device: %.10f milliseconds\n", milliseconds_h_d);
+ printf("Elapsed time kernel: %.10f milliseconds\n", milliseconds);
+ printf("Elapsed time Device->Host: %.10f milliseconds\n", milliseconds_d_h);
+ }
+ return milliseconds;
+}
+
+void clean(GraficCommon* device_object){
+ GraficObject* deviceObj = static_cast(device_object);
+
+ cudaError_t err = cudaFree(deviceObj->input_data);
+ if (err != cudaSuccess)
+ {
+ fprintf(stderr, "Failed to free device vector input_data (error code %s)!\n", cudaGetErrorString(err));
+ return;
+ }
+
+ err = cudaFree(deviceObj->kernel_1);
+ if (err != cudaSuccess)
+ {
+ fprintf(stderr, "Failed to free device vector kernel_1 (error code %s)!\n", cudaGetErrorString(err));
+ return;
+ }
+
+ err = cudaFree(deviceObj->conv_1_output);
+ if (err != cudaSuccess)
+ {
+ fprintf(stderr, "Failed to free device vector conv_1_output (error code %s)!\n", cudaGetErrorString(err));
+ return;
+ }
+
+ err = cudaFree(deviceObj->pooling_1_output);
+ if (err != cudaSuccess)
+ {
+ fprintf(stderr, "Failed to free device vector pooling_1_output (error code %s)!\n", cudaGetErrorString(err));
+ return;
+ }
+
+ err = cudaFree(deviceObj->kernel_2);
+ if (err != cudaSuccess)
+ {
+ fprintf(stderr, "Failed to free device vector kernel_2 (error code %s)!\n", cudaGetErrorString(err));
+ return;
+ }
+
+ err = cudaFree(deviceObj->conv_2_output);
+ if (err != cudaSuccess)
+ {
+ fprintf(stderr, "Failed to free device vector conv_2_output (error code %s)!\n", cudaGetErrorString(err));
+ return;
+ }
+
+ err = cudaFree(deviceObj->pooling_2_output);
+ if (err != cudaSuccess)
+ {
+ fprintf(stderr, "Failed to free device vector pooling_2_output (error code %s)!\n", cudaGetErrorString(err));
+ return;
+ }
+
+ err = cudaFree(deviceObj->dense_layer_1_weights);
+ if (err != cudaSuccess)
+ {
+ fprintf(stderr, "Failed to free device vector dense_layer_1_weights (error code %s)!\n", cudaGetErrorString(err));
+ return;
+ }
+
+ err = cudaFree(deviceObj->dense_layer_2_weights);
+ if (err != cudaSuccess)
+ {
+ fprintf(stderr, "Failed to free device vector dense_layer_2_weights (error code %s)!\n", cudaGetErrorString(err));
+ return;
+ }
+
+ err = cudaFree(deviceObj->dense_layer_1_output);
+ if (err != cudaSuccess)
+ {
+ fprintf(stderr, "Failed to free device vector dense_layer_1_output (error code %s)!\n", cudaGetErrorString(err));
+ return;
+ }
+
+ err = cudaFree(deviceObj->dense_layer_2_output);
+ if (err != cudaSuccess)
+ {
+ fprintf(stderr, "Failed to free device vector dense_layer_2_output (error code %s)!\n", cudaGetErrorString(err));
+ return;
+ }
+
+ err = cudaFree(deviceObj->output_data);
+ if (err != cudaSuccess)
+ {
+ fprintf(stderr, "Failed to free device vector output_data (error code %s)!\n", cudaGetErrorString(err));
+ return;
+ }
+
+ err = cudaFree(deviceObj->sum_ouput);
+ if (err != cudaSuccess)
+ {
+ fprintf(stderr, "Failed to free device vector sum_ouput (error code %s)!\n", cudaGetErrorString(err));
+ return;
+ }
+
+ // delete events
+ delete deviceObj->start;
+ delete deviceObj->stop;
+ delete deviceObj->start_memory_copy_device;
+ delete deviceObj->stop_memory_copy_device;
+ delete deviceObj->start_memory_copy_host;
+ delete deviceObj->stop_memory_copy_host;
+}
diff --git a/gpu4s_benchmark/cifar_10/cuda/lib_cuda.cu b/gpu4s_benchmark/cifar_10/cuda/lib_cuda.cu
index 091dcb0e..b96e7f56 100644
--- a/gpu4s_benchmark/cifar_10/cuda/lib_cuda.cu
+++ b/gpu4s_benchmark/cifar_10/cuda/lib_cuda.cu
@@ -1,12 +1,13 @@
#include "../benchmark_library.h"
+
+
/**
* CUDA Kernel Device code
*
* Computes the vector addition of A and B into C. The 3 vectors have the same
* number of elements numElements.
*/
-//#define BLOCK_SIZE 32
__global__ void
covolution_kernel(const bench_t *A, bench_t *B, const bench_t *kernel,const int n, const int m, const int w, const int kernel_size)
{
@@ -149,6 +150,7 @@ softmax_kernel(const bench_t *A, bench_t *B, bench_t *sum_d_B,const int size)
#else
B[i*size+j] = exp(A[i*size+j]);
#endif
+
atomicAdd(sum_d_B, B[i*size+j]);
}
}
@@ -166,181 +168,24 @@ softmax_finish_kernel(bench_t *B, bench_t *sum_d_B,const int size)
// End CUDA part
//////////////////////////////////////////////////////////////////////////////////////
-
-void init(GraficObject *device_object, char* device_name){
- init(device_object, 0,0, device_name);
-}
-
-void init(GraficObject *device_object, int platform ,int device, char* device_name){
- cudaSetDevice(device);
- cudaDeviceProp prop;
- cudaGetDeviceProperties(&prop, device);
- //printf("Using device: %s\n", prop.name);
- strcpy(device_name,prop.name);
- //event create
- device_object->start = new cudaEvent_t;
- device_object->stop = new cudaEvent_t;
- device_object->start_memory_copy_device = new cudaEvent_t;
- device_object->stop_memory_copy_device = new cudaEvent_t;
- device_object->start_memory_copy_host = new cudaEvent_t;
- device_object->stop_memory_copy_host= new cudaEvent_t;
+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);
+ dim3 dimBlock, dimGrid;
+ dimBlock = dim3(BLOCK_SIZE, BLOCK_SIZE);
+ dimGrid = dim3(ceil(float(input_data)/dimBlock.x), ceil(float(input_data)/dimBlock.y));
- cudaEventCreate(device_object->start);
- cudaEventCreate(device_object->stop);
- cudaEventCreate(device_object->start_memory_copy_device);
- cudaEventCreate(device_object->stop_memory_copy_device);
- cudaEventCreate(device_object->start_memory_copy_host);
- cudaEventCreate(device_object->stop_memory_copy_host);
-}
-
-
-bool device_memory_init(GraficObject *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){
- // Allocate input
- cudaError_t err = cudaSuccess;
- err = cudaMalloc((void **)&device_object->input_data, input_data * input_data * sizeof(bench_t));
-
- if (err != cudaSuccess)
- {
- return false;
- }
- // Allocate kernel
- err = cudaMalloc((void **)&device_object->kernel_1, kernel_1 * kernel_1 * sizeof(bench_t));
+ // kernel time execution
+ Clock kernelCLK;
- if (err != cudaSuccess)
- {
- return false;
- }
- // Allocate conv 1 output
- err = cudaMalloc((void **)&device_object->conv_1_output, input_data * input_data * sizeof(bench_t));
-
- if (err != cudaSuccess)
- {
- return false;
- }
- // Allocate pooling output
- unsigned int size_pooling_1 = input_data / stride_1;
- err = cudaMalloc((void **)&device_object->pooling_1_output, size_pooling_1 * size_pooling_1 * sizeof(bench_t));
-
- if (err != cudaSuccess)
- {
- return false;
- }
- // Allocate kernel 2
- err = cudaMalloc((void **)&device_object->kernel_2, kernel_2 * kernel_2 * sizeof(bench_t));
+ // profilling start
+ kernelCLK.start();
+ cudaEventRecord(*deviceObj->start);
- if (err != cudaSuccess)
- {
- return false;
- }
- // Allocate conv 1 output
- err = cudaMalloc((void **)&device_object->conv_2_output, size_pooling_1 * size_pooling_1 * sizeof(bench_t));
-
- if (err != cudaSuccess)
- {
- return false;
- }
- // Allocate pooling output
- unsigned int size_pooling_2 = size_pooling_1 / stride_2;
- err = cudaMalloc((void **)&device_object->pooling_2_output, size_pooling_2 * size_pooling_2 * sizeof(bench_t));
-
- if (err != cudaSuccess)
- {
- return false;
- }
- //dense layer 1 weights
- unsigned int weights_layer_1 = size_pooling_2 * size_pooling_2 * neurons_dense_1;
-
- err = cudaMalloc((void **)&device_object->dense_layer_1_weights, weights_layer_1* sizeof(bench_t));
-
- if (err != cudaSuccess)
- {
- return false;
- }
- // dense layer output 1
- err = cudaMalloc((void **)&device_object->dense_layer_1_output, neurons_dense_1 * sizeof(bench_t));
-
- if (err != cudaSuccess)
- {
- return false;
- }
- //dense layer 2 weights
- unsigned int weights_layer_2 = neurons_dense_1 * neurons_dense_2;
- err = cudaMalloc((void **)&device_object->dense_layer_2_weights, weights_layer_2 * sizeof(bench_t));
-
- if (err != cudaSuccess)
- {
- return false;
- }
- // dense layer output 2
- err = cudaMalloc((void **)&device_object->dense_layer_2_output, neurons_dense_2 * sizeof(bench_t));
-
- if (err != cudaSuccess)
- {
- return false;
- }
- // sum data
- err = cudaMalloc((void **)&device_object->sum_ouput, sizeof(bench_t));
-
- if (err != cudaSuccess)
- {
- return false;
- }
- // output data
- err = cudaMalloc((void **)&device_object->output_data, neurons_dense_2 * sizeof(bench_t));
-
- if (err != cudaSuccess)
- {
- return false;
- }
- return true;
- }
-
-void copy_memory_to_device(GraficObject *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){
- cudaEventRecord(*device_object->start_memory_copy_device);
- cudaError_t err = cudaMemcpy(device_object->input_data, input_data, sizeof(bench_t) * input * input, cudaMemcpyHostToDevice);
- if (err != cudaSuccess)
- {
- fprintf(stderr, "Failed to copy vector input from host to device (error code %s)!\n", cudaGetErrorString(err));
- return;
- }
- err = cudaMemcpy(device_object->kernel_1, kernel_1_data, sizeof(bench_t) * kernel_size_1 * kernel_size_1, cudaMemcpyHostToDevice);
- if (err != cudaSuccess)
- {
- fprintf(stderr, "Failed to copy vector kernel_1 from host to device (error code %s)!\n", cudaGetErrorString(err));
- return;
- }
- err = cudaMemcpy(device_object->kernel_2, kernel_2_data, sizeof(bench_t) * kernel_size_2 * kernel_size_2, cudaMemcpyHostToDevice);
- if (err != cudaSuccess)
- {
- fprintf(stderr, "Failed to copy vector kernel_2 from host to device (error code %s)!\n", cudaGetErrorString(err));
- return;
- }
- err = cudaMemcpy(device_object->dense_layer_1_weights, weights_1, sizeof(bench_t) * weights_1_size, cudaMemcpyHostToDevice);
- if (err != cudaSuccess)
- {
- fprintf(stderr, "Failed to copy vector weights_layer_1 from host to device (error code %s)!\n", cudaGetErrorString(err));
- return;
- }
- err = cudaMemcpy(device_object->dense_layer_2_weights, weights_2, sizeof(bench_t) * weights_2_size, cudaMemcpyHostToDevice);
- if (err != cudaSuccess)
- {
- fprintf(stderr, "Failed to copy vector weights_layer_2 from host to device (error code %s)!\n", cudaGetErrorString(err));
- return;
- }
- cudaEventRecord(*device_object->stop_memory_copy_device);
-
-}
-void execute_kernel(GraficObject *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){
- // execute net
// 1-1 step convolution
- cudaEventRecord(*device_object->start);
- dim3 dimBlock, dimGrid;
- dimBlock = dim3(BLOCK_SIZE, BLOCK_SIZE);
- dimGrid = dim3(ceil(float(input_data)/dimBlock.x), ceil(float(input_data)/dimBlock.y));
- covolution_kernel<<>>(device_object->input_data, device_object->conv_1_output, device_object->kernel_1, input_data, input_data, input_data, kernel_1);
+ covolution_kernel<<>>(deviceObj->input_data, deviceObj->conv_1_output, deviceObj->kernel_1, input_data, input_data, input_data, kernel_1);
// 1-2 step activation
- relu_kernel<<>>(device_object->conv_1_output, device_object->conv_1_output, input_data);
+ relu_kernel<<>>(deviceObj->conv_1_output, deviceObj->conv_1_output, input_data);
// 1-3 step pooling
unsigned int size_lateral_1 = input_data / stride_1;
if(size_lateral_1 <= BLOCK_SIZE)
@@ -353,18 +198,18 @@ void execute_kernel(GraficObject *device_object, unsigned int input_data, unsign
dimBlock = dim3(BLOCK_SIZE, BLOCK_SIZE);
dimGrid = dim3(ceil(((float(size_lateral_1)))/dimBlock.x), ceil(((float(size_lateral_1) ))/dimBlock.y));
}
- max_pooling_kernel<<>>(device_object->conv_1_output, device_object->pooling_1_output, input_data, stride_1, size_lateral_1);
+ max_pooling_kernel<<>>(deviceObj->conv_1_output, deviceObj->pooling_1_output, input_data, stride_1, size_lateral_1);
// 1-4 normalization
- lrn_kernel<<>>(device_object->pooling_1_output, device_object->pooling_1_output, size_lateral_1);
+ lrn_kernel<<>>(deviceObj->pooling_1_output, deviceObj->pooling_1_output, size_lateral_1);
// 2-1 step convolution
- covolution_kernel<<>>(device_object->pooling_1_output, device_object->conv_2_output, device_object->kernel_2, size_lateral_1, size_lateral_1, size_lateral_1, kernel_2);
+ covolution_kernel<<>>(deviceObj->pooling_1_output, deviceObj->conv_2_output, deviceObj->kernel_2, size_lateral_1, size_lateral_1, size_lateral_1, kernel_2);
// 2-2 step activation
- relu_kernel<<>>(device_object->conv_2_output, device_object->conv_2_output, size_lateral_1);
+ relu_kernel<<>>(deviceObj->conv_2_output, deviceObj->conv_2_output, size_lateral_1);
// 2-3 normalization
- lrn_kernel<<>>(device_object->conv_2_output, device_object->conv_2_output, size_lateral_1);
+ lrn_kernel<<>>(deviceObj->conv_2_output, deviceObj->conv_2_output, size_lateral_1);
// 2-4 step pooling
unsigned int size_lateral_2 = size_lateral_1 / stride_2;
@@ -378,167 +223,38 @@ void execute_kernel(GraficObject *device_object, unsigned int input_data, unsign
dimBlock = dim3(BLOCK_SIZE, BLOCK_SIZE);
dimGrid = dim3(ceil(((float(size_lateral_2) ))/dimBlock.x), ceil(((float(size_lateral_2) ))/dimBlock.y));
}
- max_pooling_kernel<<>>(device_object->conv_2_output, device_object->pooling_2_output, size_lateral_1, stride_2, size_lateral_2);
+ max_pooling_kernel<<>>(deviceObj->conv_2_output, deviceObj->pooling_2_output, size_lateral_1, stride_2, size_lateral_2);
// dense layer 1
dimBlock = dim3(BLOCK_SIZE, 1);
dimGrid = dim3(ceil(float(neurons_dense_1)/dimBlock.x), 1);
- matrix_multiplication_kernel<<>>(device_object->dense_layer_1_weights, device_object->pooling_2_output,device_object->dense_layer_1_output,neurons_dense_1, 1, size_lateral_2*size_lateral_2);
+ matrix_multiplication_kernel<<>>(deviceObj->dense_layer_1_weights, deviceObj->pooling_2_output,deviceObj->dense_layer_1_output,neurons_dense_1, 1, size_lateral_2*size_lateral_2);
//activation layer dense 1
dimBlock = dim3(BLOCK_SIZE);
dimGrid = dim3(ceil(float(neurons_dense_1)/dimBlock.x));
- relu_linear_kernel<<>>(device_object->dense_layer_1_output, device_object->dense_layer_1_output, neurons_dense_1);
+ relu_linear_kernel<<>>(deviceObj->dense_layer_1_output, deviceObj->dense_layer_1_output, neurons_dense_1);
// dense layer 2
dimBlock = dim3(BLOCK_SIZE, 1);
dimGrid = dim3(ceil(float(neurons_dense_2)/dimBlock.x), 1);
- matrix_multiplication_kernel<<>>(device_object->dense_layer_2_weights, device_object->dense_layer_1_output, device_object->dense_layer_2_output, neurons_dense_2, 1, neurons_dense_1);
+ matrix_multiplication_kernel<<>>(deviceObj->dense_layer_2_weights, deviceObj->dense_layer_1_output, deviceObj->dense_layer_2_output, neurons_dense_2, 1, neurons_dense_1);
// activation layer dense 2
dimBlock = dim3(BLOCK_SIZE*BLOCK_SIZE);
dimGrid = dim3(ceil(float(neurons_dense_2)/dimBlock.x));
- relu_linear_kernel<<>>(device_object->dense_layer_2_output, device_object->dense_layer_2_output, neurons_dense_2);
+ relu_linear_kernel<<>>(deviceObj->dense_layer_2_output, deviceObj->dense_layer_2_output, neurons_dense_2);
// softmax
dimBlock = dim3(1, BLOCK_SIZE);
dimGrid = dim3(1, ceil(float(neurons_dense_2)/dimBlock.x));
- softmax_kernel<<>>(device_object->dense_layer_2_output, device_object->output_data, device_object->sum_ouput, neurons_dense_2);
- softmax_finish_kernel<<>>(device_object->output_data, device_object->sum_ouput, neurons_dense_2);
- cudaEventRecord(*device_object->stop);
-}
-
-void copy_memory_to_host(GraficObject *device_object, bench_t* h_C, int size){
- cudaEventRecord(*device_object->start_memory_copy_host);
- cudaMemcpy(h_C, device_object->output_data, size * sizeof(bench_t), cudaMemcpyDeviceToHost);
- //cudaMemcpy(h_C, device_object->dense_layer_2_output, 10 * sizeof(bench_t), cudaMemcpyDeviceToHost);
- cudaEventRecord(*device_object->stop_memory_copy_host);
-}
-
-float get_elapsed_time(GraficObject *device_object, bool csv_format,bool csv_format_timestamp, long int current_time){
- cudaEventSynchronize(*device_object->stop_memory_copy_host);
- float milliseconds_h_d = 0, milliseconds = 0, milliseconds_d_h = 0;
- // memory transfer time host-device
- cudaEventElapsedTime(&milliseconds_h_d, *device_object->start_memory_copy_device, *device_object->stop_memory_copy_device);
- // kernel time
- cudaEventElapsedTime(&milliseconds, *device_object->start, *device_object->stop);
- // memory transfer time device-host
- cudaEventElapsedTime(&milliseconds_d_h, *device_object->start_memory_copy_host, *device_object->stop_memory_copy_host);
+ softmax_kernel<<>>(deviceObj->dense_layer_2_output, deviceObj->output_data, deviceObj->sum_ouput, neurons_dense_2);
+ softmax_finish_kernel<<>>(deviceObj->output_data, deviceObj->sum_ouput, neurons_dense_2);
- if (csv_format_timestamp){
- printf("%.10f;%.10f;%.10f;%ld;\n", milliseconds_h_d,milliseconds,milliseconds_d_h, current_time);
- }
- else if (csv_format){
- printf("%.10f;%.10f;%.10f;\n", milliseconds_h_d,milliseconds,milliseconds_d_h);
- }else{
- printf("Elapsed time Host->Device: %.10f milliseconds\n", milliseconds_h_d);
- printf("Elapsed time kernel: %.10f milliseconds\n", milliseconds);
- printf("Elapsed time Device->Host: %.10f milliseconds\n", milliseconds_d_h);
- }
- return milliseconds;
-}
-
-void clean(GraficObject *device_object){
- cudaError_t err = cudaSuccess;
+ // profilling end
+ cudaEventRecord(*deviceObj->stop);
+ cudaDeviceSynchronize();
+ kernelCLK.end();
- err = cudaFree(device_object->input_data);
-
- if (err != cudaSuccess)
- {
- fprintf(stderr, "Failed to free device vector input_data (error code %s)!\n", cudaGetErrorString(err));
- return;
- }
-
- err = cudaFree(device_object->kernel_1);
-
- if (err != cudaSuccess)
- {
- fprintf(stderr, "Failed to free device vector kernel_1 (error code %s)!\n", cudaGetErrorString(err));
- return;
- }
- err = cudaFree(device_object->conv_1_output);
-
- if (err != cudaSuccess)
- {
- fprintf(stderr, "Failed to free device vector conv_1_output (error code %s)!\n", cudaGetErrorString(err));
- return;
- }
- err = cudaFree(device_object->pooling_1_output);
- if (err != cudaSuccess)
- {
- fprintf(stderr, "Failed to free device vector pooling_1_output (error code %s)!\n", cudaGetErrorString(err));
- return;
- }
-
- err = cudaFree(device_object->kernel_2);
-
- if (err != cudaSuccess)
- {
- fprintf(stderr, "Failed to free device vector kernel_2 (error code %s)!\n", cudaGetErrorString(err));
- return;
- }
- err = cudaFree(device_object->conv_2_output);
-
- if (err != cudaSuccess)
- {
- fprintf(stderr, "Failed to free device vector conv_2_output (error code %s)!\n", cudaGetErrorString(err));
- return;
- }
- err = cudaFree(device_object->pooling_2_output);
-
- if (err != cudaSuccess)
- {
- fprintf(stderr, "Failed to free device vector pooling_2_output (error code %s)!\n", cudaGetErrorString(err));
- return;
- }
-
- err = cudaFree(device_object->dense_layer_1_weights);
-
- if (err != cudaSuccess)
- {
- fprintf(stderr, "Failed to free device vector dense_layer_1_weights (error code %s)!\n", cudaGetErrorString(err));
- return;
- }
- err = cudaFree(device_object->dense_layer_2_weights);
-
- if (err != cudaSuccess)
- {
- fprintf(stderr, "Failed to free device vector dense_layer_2_weights (error code %s)!\n", cudaGetErrorString(err));
- return;
- }
- err = cudaFree(device_object->dense_layer_1_output);
- if (err != cudaSuccess)
- {
- fprintf(stderr, "Failed to free device vector dense_layer_1_output (error code %s)!\n", cudaGetErrorString(err));
- return;
- }
-
- err = cudaFree(device_object->dense_layer_2_output);
-
- if (err != cudaSuccess)
- {
- fprintf(stderr, "Failed to free device vector dense_layer_2_output (error code %s)!\n", cudaGetErrorString(err));
- return;
- }
- err = cudaFree(device_object->output_data);
-
- if (err != cudaSuccess)
- {
- fprintf(stderr, "Failed to free device vector output_data (error code %s)!\n", cudaGetErrorString(err));
- return;
- }
- err = cudaFree(device_object->sum_ouput);
-
- if (err != cudaSuccess)
- {
- fprintf(stderr, "Failed to free device vector sum_ouput (error code %s)!\n", cudaGetErrorString(err));
- return;
- }
-
-
- // delete events
- delete device_object->start;
- delete device_object->stop;
- delete device_object->start_memory_copy_device;
- delete device_object->stop_memory_copy_device;
- delete device_object->start_memory_copy_host;
- delete device_object->stop_memory_copy_host;
+ // store the kernel time
+ deviceObj->elapsed_time = kernelCLK.getElapsedMS();
}
+
diff --git a/gpu4s_benchmark/cifar_10/cuda/lib_cuda_lib.cu b/gpu4s_benchmark/cifar_10/cuda/lib_cuda_lib.cu
index 3719ac17..aef9c2e3 100644
--- a/gpu4s_benchmark/cifar_10/cuda/lib_cuda_lib.cu
+++ b/gpu4s_benchmark/cifar_10/cuda/lib_cuda_lib.cu
@@ -27,7 +27,9 @@ const bench_t bet = 0;
// START CUDNN
///////////////////////////////////////////////////////////////////////////////////
-void convolution_1_1(GraficObject *device_object ,cudnnHandle_t cudnn, unsigned int input_data_size, unsigned int kernel_size){
+void convolution_1_1(GraficCommon* device_object ,cudnnHandle_t cudnn, unsigned int input_data_size, unsigned int kernel_size){
+
+GraficObject* deviceObj = static_cast(device_object);
// create input tensor
cudnnTensorDescriptor_t input_descriptor;
@@ -74,15 +76,18 @@ void convolution_1_1(GraficObject *device_object ,cudnnHandle_t cudnn, unsigned
//use tensorcore
//cudnnSetConvolutionMathType(convolution_descriptor, CUDNN_TENSOR_OP_MATH)
// describing convolution
- cudnnConvolutionFwdAlgo_t convolution_algorithm;
- checkCUDNN(cudnnGetConvolutionForwardAlgorithm(cudnn,
+ // --- FIX: New code for cuDNN 8+ ---
+ cudnnConvolutionFwdAlgoPerf_t algo_perf;
+ int returned_algo_count;
+ checkCUDNN(cudnnGetConvolutionForwardAlgorithm_v7(cudnn,
input_descriptor,
kernel_descriptor,
convolution_descriptor,
output_descriptor,
- CUDNN_CONVOLUTION_FWD_PREFER_FASTEST,
- /*memoryLimitInBytes=*/0,
- &convolution_algorithm));
+ /*requestedAlgoCount=*/1,
+ &returned_algo_count,
+ &algo_perf));
+ cudnnConvolutionFwdAlgo_t convolution_algorithm = algo_perf.algo;
// get memory needed for the convolution
size_t workspace_bytes = 0;
checkCUDNN(cudnnGetConvolutionForwardWorkspaceSize(cudnn,
@@ -99,16 +104,16 @@ void convolution_1_1(GraficObject *device_object ,cudnnHandle_t cudnn, unsigned
checkCUDNN(cudnnConvolutionForward(cudnn,
&alf,
input_descriptor,
- device_object->input_data,
+ deviceObj->input_data,
kernel_descriptor,
- device_object->kernel_1,
+ deviceObj->kernel_1,
convolution_descriptor,
convolution_algorithm,
d_workspace,
workspace_bytes,
&bet,
output_descriptor,
- device_object->conv_1_output));
+ deviceObj->conv_1_output));
@@ -120,7 +125,9 @@ void convolution_1_1(GraficObject *device_object ,cudnnHandle_t cudnn, unsigned
cudnnDestroyConvolutionDescriptor(convolution_descriptor);
}
-void activation_1_2(GraficObject *device_object, cudnnHandle_t cudnn, unsigned int input_data){
+void activation_1_2(GraficCommon* device_object, cudnnHandle_t cudnn, unsigned int input_data){
+
+GraficObject* deviceObj = static_cast(device_object);
cudnnTensorDescriptor_t input_descriptor;
checkCUDNN(cudnnCreateTensorDescriptor(&input_descriptor));
@@ -154,17 +161,18 @@ void activation_1_2(GraficObject *device_object, cudnnHandle_t cudnn, unsigned i
activation_algorithm,
&alf,
input_descriptor,
- device_object->conv_1_output,
+ deviceObj->conv_1_output,
&bet,
output_descriptor,
- device_object->conv_1_output));
+ deviceObj->conv_1_output));
// destroy data
cudnnDestroyTensorDescriptor(input_descriptor);
cudnnDestroyTensorDescriptor(output_descriptor);
cudnnDestroyActivationDescriptor(activation_algorithm);
}
-void pooling_1_3(GraficObject *device_object ,cudnnHandle_t cudnn, unsigned int input_data,unsigned int size_lateral, unsigned int stride){
+void pooling_1_3(GraficCommon* device_object ,cudnnHandle_t cudnn, unsigned int input_data,unsigned int size_lateral, unsigned int stride){
+ GraficObject* deviceObj = static_cast(device_object);
// create input tensor
cudnnTensorDescriptor_t input_descriptor;
checkCUDNN(cudnnCreateTensorDescriptor(&input_descriptor));
@@ -205,10 +213,10 @@ void pooling_1_3(GraficObject *device_object ,cudnnHandle_t cudnn, unsigned int
poolingDesc,
&alf,
input_descriptor,
- device_object->conv_1_output,
+ deviceObj->conv_1_output,
&bet,
output_descriptor,
- device_object->pooling_1_output))
+ deviceObj->pooling_1_output))
// destroy data
cudnnDestroyTensorDescriptor(input_descriptor);
@@ -216,7 +224,8 @@ void pooling_1_3(GraficObject *device_object ,cudnnHandle_t cudnn, unsigned int
cudnnDestroyPoolingDescriptor(poolingDesc);
}
-void normalization_1_4(GraficObject *device_object, cudnnHandle_t cudnn,unsigned int size_lateral_1){
+void normalization_1_4(GraficCommon* device_object, cudnnHandle_t cudnn,unsigned int size_lateral_1){
+ GraficObject* deviceObj = static_cast(device_object);
cudnnTensorDescriptor_t input_descriptor;
checkCUDNN(cudnnCreateTensorDescriptor(&input_descriptor));
checkCUDNN(cudnnSetTensor4dDescriptor(input_descriptor,
@@ -251,10 +260,10 @@ cudnnTensorDescriptor_t input_descriptor;
CUDNN_LRN_CROSS_CHANNEL_DIM1,
&alf,
input_descriptor,
- device_object->pooling_1_output,
+ deviceObj->pooling_1_output,
&bet,
output_descriptor,
- device_object->pooling_1_output));
+ deviceObj->pooling_1_output));
// destroy cuDNN
cudnnDestroyTensorDescriptor(input_descriptor);
@@ -263,7 +272,9 @@ cudnnTensorDescriptor_t input_descriptor;
}
-void convolution_2_1(GraficObject *device_object, cudnnHandle_t cudnn, unsigned int input_data_size, unsigned int kernel_size){
+void convolution_2_1(GraficCommon* device_object, cudnnHandle_t cudnn, unsigned int input_data_size, unsigned int kernel_size){
+
+GraficObject* deviceObj = static_cast(device_object);
// create input tensor
cudnnTensorDescriptor_t input_descriptor;
@@ -310,15 +321,18 @@ void convolution_2_1(GraficObject *device_object, cudnnHandle_t cudnn, unsigned
//use tensorcore
//cudnnSetConvolutionMathType(convolution_descriptor, CUDNN_TENSOR_OP_MATH)
// describing convolution
- cudnnConvolutionFwdAlgo_t convolution_algorithm;
- checkCUDNN(cudnnGetConvolutionForwardAlgorithm(cudnn,
+ // --- FIX: New code for cuDNN 8+ ---
+ cudnnConvolutionFwdAlgoPerf_t algo_perf;
+ int returned_algo_count;
+ checkCUDNN(cudnnGetConvolutionForwardAlgorithm_v7(cudnn,
input_descriptor,
kernel_descriptor,
convolution_descriptor,
output_descriptor,
- CUDNN_CONVOLUTION_FWD_PREFER_FASTEST,
- /*memoryLimitInBytes=*/0,
- &convolution_algorithm));
+ /*requestedAlgoCount=*/1,
+ &returned_algo_count,
+ &algo_perf));
+ cudnnConvolutionFwdAlgo_t convolution_algorithm = algo_perf.algo;
// get memory needed for the convolution
size_t workspace_bytes = 0;
checkCUDNN(cudnnGetConvolutionForwardWorkspaceSize(cudnn,
@@ -335,16 +349,16 @@ void convolution_2_1(GraficObject *device_object, cudnnHandle_t cudnn, unsigned
checkCUDNN(cudnnConvolutionForward(cudnn,
&alf,
input_descriptor,
- device_object->pooling_1_output,
+ deviceObj->pooling_1_output,
kernel_descriptor,
- device_object->kernel_2,
+ deviceObj->kernel_2,
convolution_descriptor,
convolution_algorithm,
d_workspace,
workspace_bytes,
&bet,
output_descriptor,
- device_object->conv_2_output));
+ deviceObj->conv_2_output));
@@ -356,7 +370,9 @@ void convolution_2_1(GraficObject *device_object, cudnnHandle_t cudnn, unsigned
cudnnDestroyConvolutionDescriptor(convolution_descriptor);
}
-void activation_2_2(GraficObject *device_object, cudnnHandle_t cudnn, unsigned int input_data){
+void activation_2_2(GraficCommon* device_object, cudnnHandle_t cudnn, unsigned int input_data){
+
+GraficObject* deviceObj = static_cast(device_object);
cudnnTensorDescriptor_t input_descriptor;
checkCUDNN(cudnnCreateTensorDescriptor(&input_descriptor));
@@ -390,17 +406,18 @@ void activation_2_2(GraficObject *device_object, cudnnHandle_t cudnn, unsigned i
activation_algorithm,
&alf,
input_descriptor,
- device_object->conv_2_output,
+ deviceObj->conv_2_output,
&bet,
output_descriptor,
- device_object->conv_2_output));
+ deviceObj->conv_2_output));
// destroy data
cudnnDestroyTensorDescriptor(input_descriptor);
cudnnDestroyTensorDescriptor(output_descriptor);
cudnnDestroyActivationDescriptor(activation_algorithm);
}
-void normalization_2_3(GraficObject *device_object, cudnnHandle_t cudnn,unsigned int size_lateral_1){
+void normalization_2_3(GraficCommon* device_object, cudnnHandle_t cudnn,unsigned int size_lateral_1){
+ GraficObject* deviceObj = static_cast(device_object);
cudnnTensorDescriptor_t input_descriptor;
checkCUDNN(cudnnCreateTensorDescriptor(&input_descriptor));
checkCUDNN(cudnnSetTensor4dDescriptor(input_descriptor,
@@ -435,10 +452,10 @@ cudnnTensorDescriptor_t input_descriptor;
CUDNN_LRN_CROSS_CHANNEL_DIM1,
&alf,
input_descriptor,
- device_object->conv_2_output,
+ deviceObj->conv_2_output,
&bet,
output_descriptor,
- device_object->conv_2_output));
+ deviceObj->conv_2_output));
// destroy cuDNN
cudnnDestroyTensorDescriptor(input_descriptor);
@@ -446,7 +463,8 @@ cudnnTensorDescriptor_t input_descriptor;
cudnnDestroyLRNDescriptor(lrn_descriptor);
}
-void pooling_2_4(GraficObject *device_object, cudnnHandle_t cudnn, unsigned int input_data,unsigned int size_lateral, unsigned int stride){
+void pooling_2_4(GraficCommon* device_object, cudnnHandle_t cudnn, unsigned int input_data,unsigned int size_lateral, unsigned int stride){
+ GraficObject* deviceObj = static_cast(device_object);
// create input tensor
cudnnTensorDescriptor_t input_descriptor;
checkCUDNN(cudnnCreateTensorDescriptor(&input_descriptor));
@@ -487,10 +505,10 @@ void pooling_2_4(GraficObject *device_object, cudnnHandle_t cudnn, unsigned int
poolingDesc,
&alf,
input_descriptor,
- device_object->conv_2_output,
+ deviceObj->conv_2_output,
&bet,
output_descriptor,
- device_object->pooling_2_output))
+ deviceObj->pooling_2_output))
// destroy data
cudnnDestroyTensorDescriptor(input_descriptor);
@@ -499,8 +517,8 @@ void pooling_2_4(GraficObject *device_object, cudnnHandle_t cudnn, unsigned int
}
-void dense_1(GraficObject *device_object, unsigned int n, unsigned int m, unsigned int w){
- int lda=m,ldb=n,ldc=w;
+void dense_1(GraficCommon* device_object, unsigned int n, unsigned int m, unsigned int w){
+ GraficObject* deviceObj = static_cast(device_object);
const bench_t *alpha = &alf;
const bench_t *beta = &bet;
cublasHandle_t handle;
@@ -509,15 +527,17 @@ void dense_1(GraficObject *device_object, unsigned int n, unsigned int m, unsign
#ifdef INT
printf("CUBLAS NOT SUPPORT INT OPERATIOS\n");
#elif FLOAT
- cublasSgemm(handle, CUBLAS_OP_N, CUBLAS_OP_N, m, n, w, alpha, device_object->pooling_2_output, m, device_object->dense_layer_1_weights, w, beta, device_object->dense_layer_1_output, m);
+ cublasSgemm(handle, CUBLAS_OP_N, CUBLAS_OP_N, m, n, w, alpha, deviceObj->pooling_2_output, m, deviceObj->dense_layer_1_weights, w, beta, deviceObj->dense_layer_1_output, m);
#else
- cublasDgemm(handle, CUBLAS_OP_N, CUBLAS_OP_N, m, n, w, alpha, device_object->pooling_2_output, m, device_object->dense_layer_1_weights, w, beta, device_object->dense_layer_1_output, m);
+ cublasDgemm(handle, CUBLAS_OP_N, CUBLAS_OP_N, m, n, w, alpha, deviceObj->pooling_2_output, m, deviceObj->dense_layer_1_weights, w, beta, deviceObj->dense_layer_1_output, m);
#endif
cublasDestroy(handle);
}
-void activation_d_1(GraficObject *device_object, cudnnHandle_t cudnn, unsigned int input_data){
+void activation_d_1(GraficCommon* device_object, cudnnHandle_t cudnn, unsigned int input_data){
+
+GraficObject* deviceObj = static_cast(device_object);
cudnnTensorDescriptor_t input_descriptor;
checkCUDNN(cudnnCreateTensorDescriptor(&input_descriptor));
@@ -551,10 +571,10 @@ void activation_d_1(GraficObject *device_object, cudnnHandle_t cudnn, unsigned i
activation_algorithm,
&alf,
input_descriptor,
- device_object->dense_layer_1_output,
+ deviceObj->dense_layer_1_output,
&bet,
output_descriptor,
- device_object->dense_layer_1_output));
+ deviceObj->dense_layer_1_output));
// destroy data
cudnnDestroyTensorDescriptor(input_descriptor);
@@ -562,8 +582,8 @@ void activation_d_1(GraficObject *device_object, cudnnHandle_t cudnn, unsigned i
cudnnDestroyActivationDescriptor(activation_algorithm);
}
-void dense_2(GraficObject *device_object, unsigned int n, unsigned int m, unsigned int w){
- int lda=m,ldb=n,ldc=w;
+void dense_2(GraficCommon* device_object, unsigned int n, unsigned int m, unsigned int w){
+ GraficObject* deviceObj = static_cast(device_object);
const bench_t *alpha = &alf;
const bench_t *beta = &bet;
cublasHandle_t handle;
@@ -572,15 +592,17 @@ void dense_2(GraficObject *device_object, unsigned int n, unsigned int m, unsign
#ifdef INT
printf("CUBLAS NOT SUPPORT INT OPERATIOS\n");
#elif FLOAT
- cublasSgemm(handle, CUBLAS_OP_N, CUBLAS_OP_N, m, n, w, alpha, device_object->dense_layer_1_output, m, device_object->dense_layer_2_weights, w, beta, device_object->dense_layer_2_output, m);
+ cublasSgemm(handle, CUBLAS_OP_N, CUBLAS_OP_N, m, n, w, alpha, deviceObj->dense_layer_1_output, m, deviceObj->dense_layer_2_weights, w, beta, deviceObj->dense_layer_2_output, m);
#else
- cublasDgemm(handle, CUBLAS_OP_N, CUBLAS_OP_N, m, n, w, alpha, device_object->dense_layer_1_output, m, device_object->dense_layer_2_weights, w, beta, device_object->dense_layer_2_output, m);
+ cublasDgemm(handle, CUBLAS_OP_N, CUBLAS_OP_N, m, n, w, alpha, deviceObj->dense_layer_1_output, m, deviceObj->dense_layer_2_weights, w, beta, deviceObj->dense_layer_2_output, m);
#endif
cublasDestroy(handle);
}
-void activation_d_2(GraficObject *device_object, cudnnHandle_t cudnn, unsigned int input_data){
+void activation_d_2(GraficCommon* device_object, cudnnHandle_t cudnn, unsigned int input_data){
+
+GraficObject* deviceObj = static_cast(device_object);
cudnnTensorDescriptor_t input_descriptor;
checkCUDNN(cudnnCreateTensorDescriptor(&input_descriptor));
@@ -614,10 +636,10 @@ void activation_d_2(GraficObject *device_object, cudnnHandle_t cudnn, unsigned i
activation_algorithm,
&alf,
input_descriptor,
- device_object->dense_layer_2_output,
+ deviceObj->dense_layer_2_output,
&bet,
output_descriptor,
- device_object->dense_layer_2_output));
+ deviceObj->dense_layer_2_output));
// destroy data
cudnnDestroyTensorDescriptor(input_descriptor);
@@ -625,8 +647,8 @@ void activation_d_2(GraficObject *device_object, cudnnHandle_t cudnn, unsigned i
cudnnDestroyActivationDescriptor(activation_algorithm);
}
-
-void softmax(GraficObject *device_object, cudnnHandle_t cudnn, unsigned int input_data){
+void softmax(GraficCommon* device_object, cudnnHandle_t cudnn, unsigned int input_data){
+ GraficObject* deviceObj = static_cast(device_object);
cudnnTensorDescriptor_t input_descriptor;
checkCUDNN(cudnnCreateTensorDescriptor(&input_descriptor));
checkCUDNN(cudnnSetTensor4dDescriptor(input_descriptor,
@@ -653,10 +675,10 @@ void softmax(GraficObject *device_object, cudnnHandle_t cudnn, unsigned int inpu
CUDNN_SOFTMAX_MODE_INSTANCE,
&alf,
input_descriptor,
- device_object->dense_layer_2_output,
+ deviceObj->dense_layer_2_output,
&bet,
output_descriptor,
- device_object->output_data));
+ deviceObj->output_data));
// destroy cuDNN
cudnnDestroyTensorDescriptor(input_descriptor);
@@ -667,175 +689,18 @@ void softmax(GraficObject *device_object, cudnnHandle_t cudnn, unsigned int inpu
// END CUDNN
///////////////////////////////////////////////////////////////////////////////////
-void init(GraficObject *device_object, char* device_name){
- init(device_object, 0,0, device_name);
-}
-
-void init(GraficObject *device_object, int platform ,int device, char* device_name){
- cudaSetDevice(device);
- cudaDeviceProp prop;
- cudaGetDeviceProperties(&prop, device);
- //printf("Using device: %s\n", prop.name);
- strcpy(device_name,prop.name);
- //event create
- device_object->start = new cudaEvent_t;
- device_object->stop = new cudaEvent_t;
- device_object->start_memory_copy_device = new cudaEvent_t;
- device_object->stop_memory_copy_device = new cudaEvent_t;
- device_object->start_memory_copy_host = new cudaEvent_t;
- device_object->stop_memory_copy_host= new cudaEvent_t;
-
- cudaEventCreate(device_object->start);
- cudaEventCreate(device_object->stop);
- cudaEventCreate(device_object->start_memory_copy_device);
- cudaEventCreate(device_object->stop_memory_copy_device);
- cudaEventCreate(device_object->start_memory_copy_host);
- cudaEventCreate(device_object->stop_memory_copy_host);
-}
-
-
-bool device_memory_init(GraficObject *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){
- // Allocate input
- cudaError_t err = cudaSuccess;
- err = cudaMalloc((void **)&device_object->input_data, input_data * input_data * sizeof(bench_t));
-
- if (err != cudaSuccess)
- {
- return false;
- }
- // Allocate kernel
- err = cudaMalloc((void **)&device_object->kernel_1, kernel_1 * kernel_1 * sizeof(bench_t));
-
- if (err != cudaSuccess)
- {
- return false;
- }
- // Allocate conv 1 output
- err = cudaMalloc((void **)&device_object->conv_1_output, input_data * input_data * sizeof(bench_t));
-
- if (err != cudaSuccess)
- {
- return false;
- }
- // Allocate pooling output
- unsigned int size_pooling_1 = input_data / stride_1;
- err = cudaMalloc((void **)&device_object->pooling_1_output, size_pooling_1 * size_pooling_1 * sizeof(bench_t));
-
- if (err != cudaSuccess)
- {
- return false;
- }
- // Allocate kernel 2
- err = cudaMalloc((void **)&device_object->kernel_2, kernel_2 * kernel_2 * sizeof(bench_t));
-
- if (err != cudaSuccess)
- {
- return false;
- }
- // Allocate conv 1 output
- err = cudaMalloc((void **)&device_object->conv_2_output, size_pooling_1 * size_pooling_1 * sizeof(bench_t));
-
- if (err != cudaSuccess)
- {
- return false;
- }
- // Allocate pooling output
- unsigned int size_pooling_2 = size_pooling_1 / stride_2;
- err = cudaMalloc((void **)&device_object->pooling_2_output, size_pooling_2 * size_pooling_2 * sizeof(bench_t));
-
- if (err != cudaSuccess)
- {
- return false;
- }
- //dense layer 1 weights
- unsigned int weights_layer_1 = size_pooling_2 * size_pooling_2 * neurons_dense_1;
-
- err = cudaMalloc((void **)&device_object->dense_layer_1_weights, weights_layer_1* sizeof(bench_t));
-
- if (err != cudaSuccess)
- {
- return false;
- }
- // dense layer output 1
- err = cudaMalloc((void **)&device_object->dense_layer_1_output, neurons_dense_1 * sizeof(bench_t));
-
- if (err != cudaSuccess)
- {
- return false;
- }
- //dense layer 2 weights
- unsigned int weights_layer_2 = neurons_dense_1 * neurons_dense_2;
- err = cudaMalloc((void **)&device_object->dense_layer_2_weights, weights_layer_2 * sizeof(bench_t));
-
- if (err != cudaSuccess)
- {
- return false;
- }
- // dense layer output 2
- err = cudaMalloc((void **)&device_object->dense_layer_2_output, neurons_dense_2 * sizeof(bench_t));
-
- if (err != cudaSuccess)
- {
- return false;
- }
- // sum data
- err = cudaMalloc((void **)&device_object->sum_ouput, sizeof(bench_t));
-
- if (err != cudaSuccess)
- {
- return false;
- }
- // output data
- err = cudaMalloc((void **)&device_object->output_data, neurons_dense_2 * sizeof(bench_t));
-
- if (err != cudaSuccess)
- {
- return false;
- }
- return true;
- }
-
-void copy_memory_to_device(GraficObject *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){
- cudaEventRecord(*device_object->start_memory_copy_device);
- cudaError_t err = cudaMemcpy(device_object->input_data, input_data, sizeof(bench_t) * input * input, cudaMemcpyHostToDevice);
- if (err != cudaSuccess)
- {
- fprintf(stderr, "Failed to copy vector input from host to device (error code %s)!\n", cudaGetErrorString(err));
- return;
- }
- err = cudaMemcpy(device_object->kernel_1, kernel_1_data, sizeof(bench_t) * kernel_size_1 * kernel_size_1, cudaMemcpyHostToDevice);
- if (err != cudaSuccess)
- {
- fprintf(stderr, "Failed to copy vector kernel_1 from host to device (error code %s)!\n", cudaGetErrorString(err));
- return;
- }
- err = cudaMemcpy(device_object->kernel_2, kernel_2_data, sizeof(bench_t) * kernel_size_2 * kernel_size_2, cudaMemcpyHostToDevice);
- if (err != cudaSuccess)
- {
- fprintf(stderr, "Failed to copy vector kernel_2 from host to device (error code %s)!\n", cudaGetErrorString(err));
- return;
- }
- err = cudaMemcpy(device_object->dense_layer_1_weights, weights_1, sizeof(bench_t) * weights_1_size, cudaMemcpyHostToDevice);
- if (err != cudaSuccess)
- {
- fprintf(stderr, "Failed to copy vector weights_layer_1 from host to device (error code %s)!\n", cudaGetErrorString(err));
- return;
- }
- err = cudaMemcpy(device_object->dense_layer_2_weights, weights_2, sizeof(bench_t) * weights_2_size, cudaMemcpyHostToDevice);
- if (err != cudaSuccess)
- {
- fprintf(stderr, "Failed to copy vector weights_layer_2 from host to device (error code %s)!\n", cudaGetErrorString(err));
- return;
- }
- cudaEventRecord(*device_object->stop_memory_copy_device);
-
-}
-void execute_kernel(GraficObject *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 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);
// cublas settings
cudnnHandle_t cudnn;
- cudaEventRecord(*device_object->start);
+ // kernel time execution
+ Clock kernelCLK;
+
+ // profilling start
+ kernelCLK.start();
+ cudaEventRecord(*deviceObj->start);
checkCUDNN(cudnnCreate(&cudnn));
// 1-1 step convolution
@@ -864,150 +729,20 @@ void execute_kernel(GraficObject *device_object, unsigned int input_data, unsign
// dense activation 1
activation_d_1(device_object,cudnn, neurons_dense_1);
-
// dense layer 2
dense_2(device_object, neurons_dense_2, 1, neurons_dense_1);
// dense activation 2
activation_d_2(device_object,cudnn, neurons_dense_2);
//softmax
softmax(device_object,cudnn, neurons_dense_2);
- cudaEventRecord(*device_object->stop);
- cudnnDestroy(cudnn);
-}
-void copy_memory_to_host(GraficObject *device_object, bench_t* h_C, int size){
- cudaEventRecord(*device_object->start_memory_copy_host);
- cudaMemcpy(h_C, device_object->output_data, size * sizeof(bench_t), cudaMemcpyDeviceToHost);
- //cudaMemcpy(h_C, device_object->dense_layer_2_output, 10 * sizeof(bench_t), cudaMemcpyDeviceToHost);
- cudaEventRecord(*device_object->stop_memory_copy_host);
-}
+ // profilling end
+ cudaEventRecord(*deviceObj->stop);
+ cudaDeviceSynchronize();
+ kernelCLK.end();
-float get_elapsed_time(GraficObject *device_object, bool csv_format,bool csv_format_timestamp, long int current_time){
- cudaEventSynchronize(*device_object->stop_memory_copy_host);
- float milliseconds_h_d = 0, milliseconds = 0, milliseconds_d_h = 0;
- // memory transfer time host-device
- cudaEventElapsedTime(&milliseconds_h_d, *device_object->start_memory_copy_device, *device_object->stop_memory_copy_device);
- // kernel time
- cudaEventElapsedTime(&milliseconds, *device_object->start, *device_object->stop);
- // memory transfer time device-host
- cudaEventElapsedTime(&milliseconds_d_h, *device_object->start_memory_copy_host, *device_object->stop_memory_copy_host);
-
- if (csv_format_timestamp){
- printf("%.10f;%.10f;%.10f;%ld;\n", milliseconds_h_d,milliseconds,milliseconds_d_h, current_time);
- }
- else if (csv_format){
- printf("%.10f;%.10f;%.10f;\n", milliseconds_h_d,milliseconds,milliseconds_d_h);
- }else{
- printf("Elapsed time Host->Device: %.10f milliseconds\n", milliseconds_h_d);
- printf("Elapsed time kernel: %.10f milliseconds\n", milliseconds);
- printf("Elapsed time Device->Host: %.10f milliseconds\n", milliseconds_d_h);
- }
- return milliseconds;
-}
+ // store the kernel time
+ deviceObj->elapsed_time = kernelCLK.getElapsedMS();
-void clean(GraficObject *device_object){
- cudaError_t err = cudaSuccess;
-
- err = cudaFree(device_object->input_data);
-
- if (err != cudaSuccess)
- {
- fprintf(stderr, "Failed to free device vector input_data (error code %s)!\n", cudaGetErrorString(err));
- return;
- }
-
- err = cudaFree(device_object->kernel_1);
-
- if (err != cudaSuccess)
- {
- fprintf(stderr, "Failed to free device vector kernel_1 (error code %s)!\n", cudaGetErrorString(err));
- return;
- }
- err = cudaFree(device_object->conv_1_output);
-
- if (err != cudaSuccess)
- {
- fprintf(stderr, "Failed to free device vector conv_1_output (error code %s)!\n", cudaGetErrorString(err));
- return;
- }
- err = cudaFree(device_object->pooling_1_output);
- if (err != cudaSuccess)
- {
- fprintf(stderr, "Failed to free device vector pooling_1_output (error code %s)!\n", cudaGetErrorString(err));
- return;
- }
-
- err = cudaFree(device_object->kernel_2);
-
- if (err != cudaSuccess)
- {
- fprintf(stderr, "Failed to free device vector kernel_2 (error code %s)!\n", cudaGetErrorString(err));
- return;
- }
- err = cudaFree(device_object->conv_2_output);
-
- if (err != cudaSuccess)
- {
- fprintf(stderr, "Failed to free device vector conv_2_output (error code %s)!\n", cudaGetErrorString(err));
- return;
- }
- err = cudaFree(device_object->pooling_2_output);
-
- if (err != cudaSuccess)
- {
- fprintf(stderr, "Failed to free device vector pooling_2_output (error code %s)!\n", cudaGetErrorString(err));
- return;
- }
-
- err = cudaFree(device_object->dense_layer_1_weights);
-
- if (err != cudaSuccess)
- {
- fprintf(stderr, "Failed to free device vector dense_layer_1_weights (error code %s)!\n", cudaGetErrorString(err));
- return;
- }
- err = cudaFree(device_object->dense_layer_2_weights);
-
- if (err != cudaSuccess)
- {
- fprintf(stderr, "Failed to free device vector dense_layer_2_weights (error code %s)!\n", cudaGetErrorString(err));
- return;
- }
- err = cudaFree(device_object->dense_layer_1_output);
- if (err != cudaSuccess)
- {
- fprintf(stderr, "Failed to free device vector dense_layer_1_output (error code %s)!\n", cudaGetErrorString(err));
- return;
- }
-
- err = cudaFree(device_object->dense_layer_2_output);
-
- if (err != cudaSuccess)
- {
- fprintf(stderr, "Failed to free device vector dense_layer_2_output (error code %s)!\n", cudaGetErrorString(err));
- return;
- }
- err = cudaFree(device_object->output_data);
-
- if (err != cudaSuccess)
- {
- fprintf(stderr, "Failed to free device vector output_data (error code %s)!\n", cudaGetErrorString(err));
- return;
- }
- err = cudaFree(device_object->sum_ouput);
-
- if (err != cudaSuccess)
- {
- fprintf(stderr, "Failed to free device vector sum_ouput (error code %s)!\n", cudaGetErrorString(err));
- return;
- }
-
-
- // delete events
- delete device_object->start;
- delete device_object->stop;
- delete device_object->start_memory_copy_device;
- delete device_object->stop_memory_copy_device;
- delete device_object->start_memory_copy_host;
- delete device_object->stop_memory_copy_host;
-}
\ No newline at end of file
+ cudnnDestroy(cudnn);
+}
diff --git a/gpu4s_benchmark/cifar_10/cuda/lib_cuda_opt.cu b/gpu4s_benchmark/cifar_10/cuda/lib_cuda_opt.cu
index d57048a4..708ba24f 100644
--- a/gpu4s_benchmark/cifar_10/cuda/lib_cuda_opt.cu
+++ b/gpu4s_benchmark/cifar_10/cuda/lib_cuda_opt.cu
@@ -6,7 +6,6 @@
* Computes the vector addition of A and B into C. The 3 vectors have the same
* number of elements numElements.
*/
-//#define BLOCK_SIZE 16
#define BLOCK_SIZE_PLANE (BLOCK_SIZE * BLOCK_SIZE)
__global__ void
@@ -300,6 +299,7 @@ softmax_kernel(const bench_t *A, bench_t *B, bench_t *sum_d_B,const int size)
#else
value = exp(A[i]);
#endif
+
shared_data[tid] = value;
B[i] = value;
// sync threads
@@ -331,184 +331,30 @@ softmax_finish_kernel(bench_t *B, bench_t *sum_d_B,const int size)
//////////////////////////////////////////////////////////////////////////////////////
-void init(GraficObject *device_object, char* device_name){
- init(device_object, 0,0, device_name);
-}
-
-void init(GraficObject *device_object, int platform ,int device, char* device_name){
- cudaSetDevice(device);
- cudaDeviceProp prop;
- cudaGetDeviceProperties(&prop, device);
- //printf("Using device: %s\n", prop.name);
- strcpy(device_name,prop.name);
- //event create
- device_object->start = new cudaEvent_t;
- device_object->stop = new cudaEvent_t;
- device_object->start_memory_copy_device = new cudaEvent_t;
- device_object->stop_memory_copy_device = new cudaEvent_t;
- device_object->start_memory_copy_host = new cudaEvent_t;
- device_object->stop_memory_copy_host= new cudaEvent_t;
-
- cudaEventCreate(device_object->start);
- cudaEventCreate(device_object->stop);
- cudaEventCreate(device_object->start_memory_copy_device);
- cudaEventCreate(device_object->stop_memory_copy_device);
- cudaEventCreate(device_object->start_memory_copy_host);
- cudaEventCreate(device_object->stop_memory_copy_host);
-}
-
-
-bool device_memory_init(GraficObject *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){
- // Allocate input
- cudaError_t err = cudaSuccess;
- err = cudaMalloc((void **)&device_object->input_data, input_data * input_data * sizeof(bench_t));
-
- if (err != cudaSuccess)
- {
- return false;
- }
- // Allocate kernel
- err = cudaMalloc((void **)&device_object->kernel_1, kernel_1 * kernel_1 * sizeof(bench_t));
-
- if (err != cudaSuccess)
- {
- return false;
- }
- // Allocate conv 1 output
- err = cudaMalloc((void **)&device_object->conv_1_output, input_data * input_data * sizeof(bench_t));
-
- if (err != cudaSuccess)
- {
- return false;
- }
- // Allocate pooling output
- unsigned int size_pooling_1 = input_data / stride_1;
- err = cudaMalloc((void **)&device_object->pooling_1_output, size_pooling_1 * size_pooling_1 * sizeof(bench_t));
-
- if (err != cudaSuccess)
- {
- return false;
- }
- // Allocate kernel 2
- err = cudaMalloc((void **)&device_object->kernel_2, kernel_2 * kernel_2 * sizeof(bench_t));
-
- if (err != cudaSuccess)
- {
- return false;
- }
- // Allocate conv 1 output
- err = cudaMalloc((void **)&device_object->conv_2_output, size_pooling_1 * size_pooling_1 * sizeof(bench_t));
-
- if (err != cudaSuccess)
- {
- return false;
- }
- // Allocate pooling output
- unsigned int size_pooling_2 = size_pooling_1 / stride_2;
- err = cudaMalloc((void **)&device_object->pooling_2_output, size_pooling_2 * size_pooling_2 * sizeof(bench_t));
-
- if (err != cudaSuccess)
- {
- return false;
- }
- //dense layer 1 weights
- unsigned int weights_layer_1 = size_pooling_2 * size_pooling_2 * neurons_dense_1;
-
- err = cudaMalloc((void **)&device_object->dense_layer_1_weights, weights_layer_1* sizeof(bench_t));
-
- if (err != cudaSuccess)
- {
- return false;
- }
- // dense layer output 1
- err = cudaMalloc((void **)&device_object->dense_layer_1_output, neurons_dense_1 * sizeof(bench_t));
-
- if (err != cudaSuccess)
- {
- return false;
- }
- //dense layer 2 weights
- unsigned int weights_layer_2 = neurons_dense_1 * neurons_dense_2;
- err = cudaMalloc((void **)&device_object->dense_layer_2_weights, weights_layer_2 * sizeof(bench_t));
-
- if (err != cudaSuccess)
- {
- return false;
- }
- // dense layer output 2
- err = cudaMalloc((void **)&device_object->dense_layer_2_output, neurons_dense_2 * sizeof(bench_t));
-
- if (err != cudaSuccess)
- {
- return false;
- }
- // sum data
- err = cudaMalloc((void **)&device_object->sum_ouput, sizeof(bench_t));
-
- if (err != cudaSuccess)
- {
- return false;
- }
- // output data
- err = cudaMalloc((void **)&device_object->output_data, neurons_dense_2 * sizeof(bench_t));
-
- if (err != cudaSuccess)
- {
- return false;
- }
- return true;
- }
-
-void copy_memory_to_device(GraficObject *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){
- cudaEventRecord(*device_object->start_memory_copy_device);
- cudaError_t err = cudaMemcpy(device_object->input_data, input_data, sizeof(bench_t) * input * input, cudaMemcpyHostToDevice);
- if (err != cudaSuccess)
- {
- fprintf(stderr, "Failed to copy vector input from host to device (error code %s)!\n", cudaGetErrorString(err));
- return;
- }
- err = cudaMemcpy(device_object->kernel_1, kernel_1_data, sizeof(bench_t) * kernel_size_1 * kernel_size_1, cudaMemcpyHostToDevice);
- if (err != cudaSuccess)
- {
- fprintf(stderr, "Failed to copy vector kernel_1 from host to device (error code %s)!\n", cudaGetErrorString(err));
- return;
- }
- err = cudaMemcpy(device_object->kernel_2, kernel_2_data, sizeof(bench_t) * kernel_size_2 * kernel_size_2, cudaMemcpyHostToDevice);
- if (err != cudaSuccess)
- {
- fprintf(stderr, "Failed to copy vector kernel_2 from host to device (error code %s)!\n", cudaGetErrorString(err));
- return;
- }
- err = cudaMemcpy(device_object->dense_layer_1_weights, weights_1, sizeof(bench_t) * weights_1_size, cudaMemcpyHostToDevice);
- if (err != cudaSuccess)
- {
- fprintf(stderr, "Failed to copy vector weights_layer_1 from host to device (error code %s)!\n", cudaGetErrorString(err));
- return;
- }
- err = cudaMemcpy(device_object->dense_layer_2_weights, weights_2, sizeof(bench_t) * weights_2_size, cudaMemcpyHostToDevice);
- if (err != cudaSuccess)
- {
- fprintf(stderr, "Failed to copy vector weights_layer_2 from host to device (error code %s)!\n", cudaGetErrorString(err));
- return;
- }
- cudaEventRecord(*device_object->stop_memory_copy_device);
-
-}
-void execute_kernel(GraficObject *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){
- // execute net
- // 1-1 step convolution
- cudaEventRecord(*device_object->start);
+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);
dim3 dimBlock, dimGrid,dimBlock_act, dimGrid_act;
dimBlock = dim3(BLOCK_SIZE, BLOCK_SIZE);
dimGrid = dim3(ceil(float(input_data)/dimBlock.x), ceil(float(input_data)/dimBlock.y));
unsigned int kernel_rad = kernel_1 / 2;
unsigned int size_shared = (BLOCK_SIZE + kernel_rad *2 ) * sizeof(bench_t) * (BLOCK_SIZE + kernel_rad *2) * sizeof(bench_t);
unsigned int size_shared_position = (BLOCK_SIZE + kernel_rad *2);
- covolution_kernel<<>>(device_object->input_data, device_object->conv_1_output, device_object->kernel_1, input_data, input_data, input_data, kernel_1, size_shared_position, kernel_rad);
+
+ // kernel time execution
+ Clock kernelCLK;
+
+ // profilling start
+ kernelCLK.start();
+ cudaEventRecord(*deviceObj->start);
+
+ // 1-1 step convolution
+ covolution_kernel<<>>(deviceObj->input_data, deviceObj->conv_1_output, deviceObj->kernel_1, input_data, input_data, input_data, kernel_1, size_shared_position, kernel_rad);
+
// 1-2 step activation
dimBlock = dim3(BLOCK_SIZE_PLANE);
dimGrid = dim3(ceil(float(input_data)/dimBlock.x));
- relu_kernel<<>>(device_object->conv_1_output, device_object->conv_1_output, input_data*input_data);
+ relu_kernel<<>>(deviceObj->conv_1_output, deviceObj->conv_1_output, input_data*input_data);
+
// 1-3 step pooling
unsigned int size_lateral_1 = input_data / stride_1;
if(size_lateral_1*size_lateral_1 <= BLOCK_SIZE_PLANE)
@@ -521,7 +367,8 @@ void execute_kernel(GraficObject *device_object, unsigned int input_data, unsign
dimBlock = dim3(BLOCK_SIZE_PLANE);
dimGrid = dim3(ceil((size_lateral_1*size_lateral_1)/dimBlock.x));
}
- max_pooling_kernel<<>>(device_object->conv_1_output, device_object->pooling_1_output, input_data, stride_1, size_lateral_1);
+ max_pooling_kernel<<>>(deviceObj->conv_1_output, deviceObj->pooling_1_output, input_data, stride_1, size_lateral_1);
+
// 1-4 normalization
if(size_lateral_1 < BLOCK_SIZE)
{
@@ -534,21 +381,21 @@ void execute_kernel(GraficObject *device_object, unsigned int input_data, unsign
dimGrid = dim3(ceil(((float(size_lateral_1) ))/dimBlock.x), ceil(((float(size_lateral_1) ))/dimBlock.y));
}
- lrn_kernel<<>>(device_object->pooling_1_output, device_object->pooling_1_output, size_lateral_1);
+ lrn_kernel<<>>(deviceObj->pooling_1_output, deviceObj->pooling_1_output, size_lateral_1);
// 2-1 step convolution
//kernel_rad = kernel_2 / 2;
//size_shared = (BLOCK_SIZE + kernel_rad *2 ) * sizeof(bench_t) * (BLOCK_SIZE + kernel_rad *2) * sizeof(bench_t);
//size_shared_position = (BLOCK_SIZE + kernel_rad *2);
- //covolution_kernel<<>>(device_object->pooling_1_output, device_object->conv_2_output, device_object->kernel_2, size_lateral_1, size_lateral_1, size_lateral_1, kernel_2,size_shared_position, kernel_rad);
- covolution_kernel_base<<>>(device_object->pooling_1_output, device_object->conv_2_output, device_object->kernel_2, size_lateral_1, size_lateral_1, size_lateral_1, kernel_2);
+ //covolution_kernel<<>>(deviceObj->pooling_1_output, deviceObj->conv_2_output, deviceObj->kernel_2, size_lateral_1, size_lateral_1, size_lateral_1, kernel_2,size_shared_position, kernel_rad);
+ covolution_kernel_base<<>>(deviceObj->pooling_1_output, deviceObj->conv_2_output, deviceObj->kernel_2, size_lateral_1, size_lateral_1, size_lateral_1, kernel_2);
// 2-2 step activation
dimBlock_act = dim3(BLOCK_SIZE_PLANE);
dimGrid_act = dim3(ceil(float(size_lateral_1*size_lateral_1)/dimBlock.x));
- relu_kernel<<>>(device_object->conv_2_output, device_object->conv_2_output, size_lateral_1);
+ relu_kernel<<>>(deviceObj->conv_2_output, deviceObj->conv_2_output, size_lateral_1);
// 2-3 normalization
- lrn_kernel<<>>(device_object->conv_2_output, device_object->conv_2_output, size_lateral_1);
+ lrn_kernel<<>>(deviceObj->conv_2_output, deviceObj->conv_2_output, size_lateral_1);
// 2-4 step pooling
unsigned int size_lateral_2 = size_lateral_1 / stride_2;
if(size_lateral_2*size_lateral_2 <= BLOCK_SIZE_PLANE)
@@ -561,168 +408,38 @@ void execute_kernel(GraficObject *device_object, unsigned int input_data, unsign
dimBlock = dim3(BLOCK_SIZE_PLANE);
dimGrid = dim3(ceil((size_lateral_2*size_lateral_2)/dimBlock.x));
}
- max_pooling_kernel<<>>(device_object->conv_2_output, device_object->pooling_2_output, size_lateral_1, stride_2, size_lateral_2);
+ max_pooling_kernel<<>>(deviceObj->conv_2_output, deviceObj->pooling_2_output, size_lateral_1, stride_2, size_lateral_2);
// dense layer 1
dimBlock = dim3(BLOCK_SIZE, 1);
dimGrid = dim3(ceil(float(neurons_dense_1)/dimBlock.x), 1);
- matrix_multiplication_kernel_other<<>>(device_object->dense_layer_1_weights, device_object->pooling_2_output,device_object->dense_layer_1_output,neurons_dense_1, 1, size_lateral_2*size_lateral_2);
+ matrix_multiplication_kernel_other<<>>(deviceObj->dense_layer_1_weights, deviceObj->pooling_2_output,deviceObj->dense_layer_1_output,neurons_dense_1, 1, size_lateral_2*size_lateral_2);
//activation layer dense 1
dimBlock_act = dim3(BLOCK_SIZE_PLANE);
dimGrid_act = dim3(ceil(float(neurons_dense_1)/dimBlock.x));
- relu_linear_kernel<<>>(device_object->dense_layer_1_output, device_object->dense_layer_1_output, neurons_dense_1);
+ relu_linear_kernel<<>>(deviceObj->dense_layer_1_output, deviceObj->dense_layer_1_output, neurons_dense_1);
// dense layer 2
dimBlock = dim3(BLOCK_SIZE, 1);
dimGrid = dim3(ceil(float(neurons_dense_2)/dimBlock.x), 1);
- matrix_multiplication_kernel_other<<>>(device_object->dense_layer_2_weights, device_object->dense_layer_1_output, device_object->dense_layer_2_output, neurons_dense_2, 1, neurons_dense_1);
+ matrix_multiplication_kernel_other<<>>(deviceObj->dense_layer_2_weights, deviceObj->dense_layer_1_output, deviceObj->dense_layer_2_output, neurons_dense_2, 1, neurons_dense_1);
// activation layer dense 2
dimBlock = dim3(BLOCK_SIZE_PLANE);
dimGrid = dim3(ceil(float(neurons_dense_2)/dimBlock.x));
- relu_linear_kernel<<>>(device_object->dense_layer_2_output, device_object->dense_layer_2_output, neurons_dense_2);
+ relu_linear_kernel<<>>(deviceObj->dense_layer_2_output, deviceObj->dense_layer_2_output, neurons_dense_2);
// softmax
dimBlock = dim3(BLOCK_SIZE);
dimGrid = dim3(ceil(float(neurons_dense_2)/dimBlock.x));
- softmax_kernel<<>>(device_object->dense_layer_2_output, device_object->output_data, device_object->sum_ouput, neurons_dense_2);
- softmax_finish_kernel<<>>(device_object->output_data, device_object->sum_ouput, neurons_dense_2);
- cudaEventRecord(*device_object->stop);
-}
-
-void copy_memory_to_host(GraficObject *device_object, bench_t* h_C, int size){
- cudaEventRecord(*device_object->start_memory_copy_host);
- cudaMemcpy(h_C, device_object->output_data, size * sizeof(bench_t), cudaMemcpyDeviceToHost);
- //cudaMemcpy(h_C, device_object->dense_layer_2_output, 10 * sizeof(bench_t), cudaMemcpyDeviceToHost);
- cudaEventRecord(*device_object->stop_memory_copy_host);
-}
-
-float get_elapsed_time(GraficObject *device_object, bool csv_format,bool csv_format_timestamp, long int current_time){
- cudaEventSynchronize(*device_object->stop_memory_copy_host);
- float milliseconds_h_d = 0, milliseconds = 0, milliseconds_d_h = 0;
- // memory transfer time host-device
- cudaEventElapsedTime(&milliseconds_h_d, *device_object->start_memory_copy_device, *device_object->stop_memory_copy_device);
- // kernel time
- cudaEventElapsedTime(&milliseconds, *device_object->start, *device_object->stop);
- // memory transfer time device-host
- cudaEventElapsedTime(&milliseconds_d_h, *device_object->start_memory_copy_host, *device_object->stop_memory_copy_host);
+ softmax_kernel<<>>(deviceObj->dense_layer_2_output, deviceObj->output_data, deviceObj->sum_ouput, neurons_dense_2);
+ softmax_finish_kernel<<>>(deviceObj->output_data, deviceObj->sum_ouput, neurons_dense_2);
- if (csv_format_timestamp){
- printf("%.10f;%.10f;%.10f;%ld;\n", milliseconds_h_d,milliseconds,milliseconds_d_h, current_time);
- }
- else if (csv_format){
- printf("%.10f;%.10f;%.10f;\n", milliseconds_h_d,milliseconds,milliseconds_d_h);
- }else{
- printf("Elapsed time Host->Device: %.10f milliseconds\n", milliseconds_h_d);
- printf("Elapsed time kernel: %.10f milliseconds\n", milliseconds);
- printf("Elapsed time Device->Host: %.10f milliseconds\n", milliseconds_d_h);
- }
- return milliseconds;
-}
-
-void clean(GraficObject *device_object){
- cudaError_t err = cudaSuccess;
-
- err = cudaFree(device_object->input_data);
-
- if (err != cudaSuccess)
- {
- fprintf(stderr, "Failed to free device vector input_data (error code %s)!\n", cudaGetErrorString(err));
- return;
- }
-
- err = cudaFree(device_object->kernel_1);
-
- if (err != cudaSuccess)
- {
- fprintf(stderr, "Failed to free device vector kernel_1 (error code %s)!\n", cudaGetErrorString(err));
- return;
- }
- err = cudaFree(device_object->conv_1_output);
-
- if (err != cudaSuccess)
- {
- fprintf(stderr, "Failed to free device vector conv_1_output (error code %s)!\n", cudaGetErrorString(err));
- return;
- }
- err = cudaFree(device_object->pooling_1_output);
- if (err != cudaSuccess)
- {
- fprintf(stderr, "Failed to free device vector pooling_1_output (error code %s)!\n", cudaGetErrorString(err));
- return;
- }
-
- err = cudaFree(device_object->kernel_2);
-
- if (err != cudaSuccess)
- {
- fprintf(stderr, "Failed to free device vector kernel_2 (error code %s)!\n", cudaGetErrorString(err));
- return;
- }
- err = cudaFree(device_object->conv_2_output);
-
- if (err != cudaSuccess)
- {
- fprintf(stderr, "Failed to free device vector conv_2_output (error code %s)!\n", cudaGetErrorString(err));
- return;
- }
- err = cudaFree(device_object->pooling_2_output);
-
- if (err != cudaSuccess)
- {
- fprintf(stderr, "Failed to free device vector pooling_2_output (error code %s)!\n", cudaGetErrorString(err));
- return;
- }
-
- err = cudaFree(device_object->dense_layer_1_weights);
-
- if (err != cudaSuccess)
- {
- fprintf(stderr, "Failed to free device vector dense_layer_1_weights (error code %s)!\n", cudaGetErrorString(err));
- return;
- }
- err = cudaFree(device_object->dense_layer_2_weights);
-
- if (err != cudaSuccess)
- {
- fprintf(stderr, "Failed to free device vector dense_layer_2_weights (error code %s)!\n", cudaGetErrorString(err));
- return;
- }
- err = cudaFree(device_object->dense_layer_1_output);
- if (err != cudaSuccess)
- {
- fprintf(stderr, "Failed to free device vector dense_layer_1_output (error code %s)!\n", cudaGetErrorString(err));
- return;
- }
-
- err = cudaFree(device_object->dense_layer_2_output);
-
- if (err != cudaSuccess)
- {
- fprintf(stderr, "Failed to free device vector dense_layer_2_output (error code %s)!\n", cudaGetErrorString(err));
- return;
- }
- err = cudaFree(device_object->output_data);
-
- if (err != cudaSuccess)
- {
- fprintf(stderr, "Failed to free device vector output_data (error code %s)!\n", cudaGetErrorString(err));
- return;
- }
- err = cudaFree(device_object->sum_ouput);
-
- if (err != cudaSuccess)
- {
- fprintf(stderr, "Failed to free device vector sum_ouput (error code %s)!\n", cudaGetErrorString(err));
- return;
- }
-
+ // profilling end
+ cudaEventRecord(*deviceObj->stop);
+ cudaDeviceSynchronize();
+ kernelCLK.end();
- // delete events
- delete device_object->start;
- delete device_object->stop;
- delete device_object->start_memory_copy_device;
- delete device_object->stop_memory_copy_device;
- delete device_object->start_memory_copy_host;
- delete device_object->stop_memory_copy_host;
+ // store the kernel time
+ deviceObj->elapsed_time = kernelCLK.getElapsedMS();
}
diff --git a/gpu4s_benchmark/cifar_10/hip/hip_common.cpp b/gpu4s_benchmark/cifar_10/hip/hip_common.cpp
new file mode 100644
index 00000000..a2f1d587
--- /dev/null
+++ b/gpu4s_benchmark/cifar_10/hip/hip_common.cpp
@@ -0,0 +1,318 @@
+/** * ====================================================================
+ * @file hip_common.cpp (./cifar_10)
+ * @brief Common HIP platform initialization, device setup,
+ * profiling timer evaluation, and generic cleanup routines.
+ * @paragraph License
+ * ESA-PL Strong Copyleft – v2.5
+ * ======================================================================= */
+#include "../benchmark_library.h"
+
+
+void init(GraficCommon* device_object, char* device_name){
+ init(device_object, 0,0, device_name);
+}
+
+void init(GraficCommon* device_object, int platform ,int device, char* device_name){
+ GraficObject* deviceObj = static_cast(device_object);
+ (void)hipSetDevice(device);
+ hipDeviceProp_t prop;
+ (void)hipGetDeviceProperties(&prop, device);
+ //printf("Using device: %s\n", prop.name);
+ strcpy(device_name,prop.name);
+ //event create
+ deviceObj->start = new hipEvent_t;
+ deviceObj->stop = new hipEvent_t;
+ deviceObj->start_memory_copy_device = new hipEvent_t;
+ deviceObj->stop_memory_copy_device = new hipEvent_t;
+ deviceObj->start_memory_copy_host = new hipEvent_t;
+ deviceObj->stop_memory_copy_host= new hipEvent_t;
+
+ (void)hipEventCreate(deviceObj->start);
+ (void)hipEventCreate(deviceObj->stop);
+ (void)hipEventCreate(deviceObj->start_memory_copy_device);
+ (void)hipEventCreate(deviceObj->stop_memory_copy_device);
+ (void)hipEventCreate(deviceObj->start_memory_copy_host);
+ (void)hipEventCreate(deviceObj->stop_memory_copy_host);
+}
+
+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){
+ GraficObject* deviceObj = static_cast(device_object);
+
+ // FIX: create a dumb obj to sync the profling clock
+ if (deviceObj->profiling_clock)
+ {
+ hipDumbSync();
+ }
+ // Allocate input
+ hipError_t err = hipMalloc((void **)&deviceObj->input_data, input_data * input_data * sizeof(bench_t));
+ if (err != hipSuccess) return false;
+
+ // Allocate kernel
+ err = hipMalloc((void **)&deviceObj->kernel_1, kernel_1 * kernel_1 * sizeof(bench_t));
+ if (err != hipSuccess) return false;
+
+ // Allocate conv 1 output
+ err = hipMalloc((void **)&deviceObj->conv_1_output, input_data * input_data * sizeof(bench_t));
+ if (err != hipSuccess) return false;
+
+ // Allocate pooling output
+ unsigned int size_pooling_1 = input_data / stride_1;
+ err = hipMalloc((void **)&deviceObj->pooling_1_output, size_pooling_1 * size_pooling_1 * sizeof(bench_t));
+ if (err != hipSuccess) return false;
+
+ // Allocate kernel 2
+ err = hipMalloc((void **)&deviceObj->kernel_2, kernel_2 * kernel_2 * sizeof(bench_t));
+ if (err != hipSuccess) return false;
+
+ // Allocate conv 1 output
+ err = hipMalloc((void **)&deviceObj->conv_2_output, size_pooling_1 * size_pooling_1 * sizeof(bench_t));
+ if (err != hipSuccess) return false;
+
+ // Allocate pooling output
+ unsigned int size_pooling_2 = size_pooling_1 / stride_2;
+ if (err != hipSuccess) return false;
+
+ //dense layer 1 weights
+ unsigned int weights_layer_1 = size_pooling_2 * size_pooling_2 * neurons_dense_1;
+
+ err = hipMalloc((void **)&deviceObj->dense_layer_1_weights, weights_layer_1* sizeof(bench_t));
+ if (err != hipSuccess) return false;
+
+ // dense layer output 1
+ err = hipMalloc((void **)&deviceObj->dense_layer_1_output, neurons_dense_1 * sizeof(bench_t));
+ if (err != hipSuccess) return false;
+
+ //dense layer 2 weights
+ unsigned int weights_layer_2 = neurons_dense_1 * neurons_dense_2;
+ err = hipMalloc((void **)&deviceObj->dense_layer_2_weights, weights_layer_2 * sizeof(bench_t));
+ if (err != hipSuccess) return false;
+
+ // dense layer output 2
+ err = hipMalloc((void **)&deviceObj->dense_layer_2_output, neurons_dense_2 * sizeof(bench_t));
+ if (err != hipSuccess) return false;
+
+ // sum data
+ err = hipMalloc((void **)&deviceObj->sum_ouput, sizeof(bench_t));
+ if (err != hipSuccess) return false;
+
+ // output data
+ err = hipMalloc((void **)&deviceObj->output_data, neurons_dense_2 * sizeof(bench_t));
+ if (err != hipSuccess) return false;
+
+ return true;
+ }
+
+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){
+ GraficObject* deviceObj = static_cast(device_object);
+ // host -> device
+ Clock h2dCLK;
+
+ // profilling start
+ h2dCLK.start();
+ (void)hipEventRecord(*deviceObj->start_memory_copy_device);
+
+ hipError_t err = hipMemcpy(deviceObj->input_data, input_data, sizeof(bench_t) * input * input, hipMemcpyHostToDevice);
+ if (err != hipSuccess)
+ {
+ fprintf(stderr, "Failed to copy vector input from host to device (error code %s)!\n", hipGetErrorString(err));
+ return;
+ }
+ err = hipMemcpy(deviceObj->kernel_1, kernel_1_data, sizeof(bench_t) * kernel_size_1 * kernel_size_1, hipMemcpyHostToDevice);
+ if (err != hipSuccess)
+ {
+ fprintf(stderr, "Failed to copy vector kernel_1 from host to device (error code %s)!\n", hipGetErrorString(err));
+ return;
+ }
+ err = hipMemcpy(deviceObj->kernel_2, kernel_2_data, sizeof(bench_t) * kernel_size_2 * kernel_size_2, hipMemcpyHostToDevice);
+ if (err != hipSuccess)
+ {
+ fprintf(stderr, "Failed to copy vector kernel_2 from host to device (error code %s)!\n", hipGetErrorString(err));
+ return;
+ }
+ err = hipMemcpy(deviceObj->dense_layer_1_weights, weights_1, sizeof(bench_t) * weights_1_size, hipMemcpyHostToDevice);
+ if (err != hipSuccess)
+ {
+ fprintf(stderr, "Failed to copy vector weights_layer_1 from host to device (error code %s)!\n", hipGetErrorString(err));
+ return;
+ }
+ err = hipMemcpy(deviceObj->dense_layer_2_weights, weights_2, sizeof(bench_t) * weights_2_size, hipMemcpyHostToDevice);
+ if (err != hipSuccess)
+ {
+ fprintf(stderr, "Failed to copy vector weights_layer_2 from host to device (error code %s)!\n", hipGetErrorString(err));
+ return;
+ }
+
+ // profilling end
+ (void)hipEventRecord(*deviceObj->stop_memory_copy_device);
+ h2dCLK.end();
+
+ // store the h2d time
+ deviceObj->h2d_elapsed_time = h2dCLK.getElapsedMS();
+}
+
+
+
+
+
+void copy_memory_to_host(GraficCommon* device_object, bench_t* h_C, int size){
+ GraficObject* deviceObj = static_cast(device_object);
+ // device -> host
+ Clock d2hCLK;
+
+ // profilling start
+ d2hCLK.start();
+ (void)hipEventRecord(*deviceObj->start_memory_copy_host);
+
+ hipError_t err = hipMemcpy(h_C, deviceObj->output_data, size * sizeof(bench_t), hipMemcpyDeviceToHost);
+ if (err != hipSuccess)
+ {
+ fprintf(stderr, "Failed to copy vector output_data from device to host (error code %s)!\n", hipGetErrorString(err));
+ return;
+ }
+ //hipMemcpy(h_C, deviceObj->dense_layer_2_output, 10 * sizeof(bench_t), hipMemcpyDeviceToHost);
+
+ // profilling end
+ (void)hipEventRecord(*deviceObj->stop_memory_copy_host);
+ d2hCLK.end();
+
+ // store the hd2h time
+ deviceObj->d2h_elapsed_time = d2hCLK.getElapsedMS();
+}
+
+float get_elapsed_time(GraficCommon* device_object, bool csv_format,bool csv_format_timestamp, long int current_time){
+ GraficObject* deviceObj = static_cast(device_object);
+ (void)hipEventSynchronize(*deviceObj->stop_memory_copy_host); // wait
+
+ float milliseconds_h_d = 0, milliseconds = 0, milliseconds_d_h = 0;
+
+ if (deviceObj->profiling_clock)
+ {
+ // --- FIX: Use instead of CLBlast event profiling (unreliable on PROFILING_CLOCK) ---
+ milliseconds_h_d = deviceObj->h2d_elapsed_time;
+ milliseconds = deviceObj->elapsed_time;
+ milliseconds_d_h = deviceObj->d2h_elapsed_time;
+ }else{
+ // memory transfer time host-device
+ (void)hipEventElapsedTime(&milliseconds_h_d, *deviceObj->start_memory_copy_device, *deviceObj->stop_memory_copy_device);
+ // kernel time
+ (void)hipEventElapsedTime(&milliseconds, *deviceObj->start, *deviceObj->stop);
+ // memory transfer time device-host
+ (void)hipEventElapsedTime(&milliseconds_d_h, *deviceObj->start_memory_copy_host, *deviceObj->stop_memory_copy_host);
+ }
+
+ if (csv_format_timestamp){
+ printf("%.10f;%.10f;%.10f;%ld;\n", milliseconds_h_d,milliseconds,milliseconds_d_h, current_time);
+ }
+ else if (csv_format){
+ printf("%.10f;%.10f;%.10f;\n", milliseconds_h_d,milliseconds,milliseconds_d_h);
+ }else{
+ printf("profiling mode: %s\n", deviceObj->profiling_clock ? "CLOCK" : "GPU");
+ printf("Elapsed time Host->Device: %.10f milliseconds\n", milliseconds_h_d);
+ printf("Elapsed time kernel: %.10f milliseconds\n", milliseconds);
+ printf("Elapsed time Device->Host: %.10f milliseconds\n", milliseconds_d_h);
+ }
+ return milliseconds;
+}
+
+void clean(GraficCommon* device_object){
+ GraficObject* deviceObj = static_cast(device_object);
+
+ hipError_t err = hipFree(deviceObj->input_data);
+ if (err != hipSuccess)
+ {
+ fprintf(stderr, "Failed to free device vector input_data (error code %s)!\n", hipGetErrorString(err));
+ return;
+ }
+
+ err = hipFree(deviceObj->kernel_1);
+ if (err != hipSuccess)
+ {
+ fprintf(stderr, "Failed to free device vector kernel_1 (error code %s)!\n", hipGetErrorString(err));
+ return;
+ }
+
+ err = hipFree(deviceObj->conv_1_output);
+ if (err != hipSuccess)
+ {
+ fprintf(stderr, "Failed to free device vector conv_1_output (error code %s)!\n", hipGetErrorString(err));
+ return;
+ }
+
+ err = hipFree(deviceObj->pooling_1_output);
+ if (err != hipSuccess)
+ {
+ fprintf(stderr, "Failed to free device vector pooling_1_output (error code %s)!\n", hipGetErrorString(err));
+ return;
+ }
+
+ err = hipFree(deviceObj->kernel_2);
+ if (err != hipSuccess)
+ {
+ fprintf(stderr, "Failed to free device vector kernel_2 (error code %s)!\n", hipGetErrorString(err));
+ return;
+ }
+
+ err = hipFree(deviceObj->conv_2_output);
+ if (err != hipSuccess)
+ {
+ fprintf(stderr, "Failed to free device vector conv_2_output (error code %s)!\n", hipGetErrorString(err));
+ return;
+ }
+
+ err = hipFree(deviceObj->pooling_2_output);
+ if (err != hipSuccess)
+ {
+ fprintf(stderr, "Failed to free device vector pooling_2_output (error code %s)!\n", hipGetErrorString(err));
+ return;
+ }
+
+ err = hipFree(deviceObj->dense_layer_1_weights);
+ if (err != hipSuccess)
+ {
+ fprintf(stderr, "Failed to free device vector dense_layer_1_weights (error code %s)!\n", hipGetErrorString(err));
+ return;
+ }
+
+ err = hipFree(deviceObj->dense_layer_2_weights);
+ if (err != hipSuccess)
+ {
+ fprintf(stderr, "Failed to free device vector dense_layer_2_weights (error code %s)!\n", hipGetErrorString(err));
+ return;
+ }
+
+ err = hipFree(deviceObj->dense_layer_1_output);
+ if (err != hipSuccess)
+ {
+ fprintf(stderr, "Failed to free device vector dense_layer_1_output (error code %s)!\n", hipGetErrorString(err));
+ return;
+ }
+
+ err = hipFree(deviceObj->dense_layer_2_output);
+ if (err != hipSuccess)
+ {
+ fprintf(stderr, "Failed to free device vector dense_layer_2_output (error code %s)!\n", hipGetErrorString(err));
+ return;
+ }
+
+ err = hipFree(deviceObj->output_data);
+ if (err != hipSuccess)
+ {
+ fprintf(stderr, "Failed to free device vector output_data (error code %s)!\n", hipGetErrorString(err));
+ return;
+ }
+
+ err = hipFree(deviceObj->sum_ouput);
+ if (err != hipSuccess)
+ {
+ fprintf(stderr, "Failed to free device vector sum_ouput (error code %s)!\n", hipGetErrorString(err));
+ return;
+ }
+
+ // delete events
+ delete deviceObj->start;
+ delete deviceObj->stop;
+ delete deviceObj->start_memory_copy_device;
+ delete deviceObj->stop_memory_copy_device;
+ delete deviceObj->start_memory_copy_host;
+ delete deviceObj->stop_memory_copy_host;
+}
diff --git a/gpu4s_benchmark/cifar_10/hip/lib_hip.cpp b/gpu4s_benchmark/cifar_10/hip/lib_hip.cpp
index e14bc0c7..f7998347 100644
--- a/gpu4s_benchmark/cifar_10/hip/lib_hip.cpp
+++ b/gpu4s_benchmark/cifar_10/hip/lib_hip.cpp
@@ -1,4 +1,3 @@
-#include "hip/hip_runtime.h"
#include "../benchmark_library.h"
/**
@@ -7,8 +6,8 @@
* Computes the vector addition of A and B into C. The 3 vectors have the same
* number of elements numElements.
*/
-//#define BLOCK_SIZE 32
-__global__ void
+
+ __global__ void
covolution_kernel(const bench_t *A, bench_t *B, const bench_t *kernel,const int n, const int m, const int w, const int kernel_size)
{
unsigned int size = n;
@@ -150,6 +149,7 @@ softmax_kernel(const bench_t *A, bench_t *B, bench_t *sum_d_B,const int size)
#else
B[i*size+j] = exp(A[i*size+j]);
#endif
+
atomicAdd(sum_d_B, B[i*size+j]);
}
}
@@ -168,180 +168,23 @@ softmax_finish_kernel(bench_t *B, bench_t *sum_d_B,const int size)
//////////////////////////////////////////////////////////////////////////////////////
-void init(GraficObject *device_object, char* device_name){
- init(device_object, 0,0, device_name);
-}
-
-void init(GraficObject *device_object, int platform ,int device, char* device_name){
- hipSetDevice(device);
- hipDeviceProp_t prop;
- hipGetDeviceProperties(&prop, device);
- //printf("Using device: %s\n", prop.name);
- strcpy(device_name,prop.name);
- //event create
- device_object->start = new hipEvent_t;
- device_object->stop = new hipEvent_t;
- device_object->start_memory_copy_device = new hipEvent_t;
- device_object->stop_memory_copy_device = new hipEvent_t;
- device_object->start_memory_copy_host = new hipEvent_t;
- device_object->stop_memory_copy_host= new hipEvent_t;
-
- hipEventCreate(device_object->start);
- hipEventCreate(device_object->stop);
- hipEventCreate(device_object->start_memory_copy_device);
- hipEventCreate(device_object->stop_memory_copy_device);
- hipEventCreate(device_object->start_memory_copy_host);
- hipEventCreate(device_object->stop_memory_copy_host);
-}
-
-
-bool device_memory_init(GraficObject *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){
- // Allocate input
- hipError_t err = hipSuccess;
- err = hipMalloc((void **)&device_object->input_data, input_data * input_data * sizeof(bench_t));
-
- if (err != hipSuccess)
- {
- return false;
- }
- // Allocate kernel
- err = hipMalloc((void **)&device_object->kernel_1, kernel_1 * kernel_1 * sizeof(bench_t));
-
- if (err != hipSuccess)
- {
- return false;
- }
- // Allocate conv 1 output
- err = hipMalloc((void **)&device_object->conv_1_output, input_data * input_data * sizeof(bench_t));
-
- if (err != hipSuccess)
- {
- return false;
- }
- // Allocate pooling output
- unsigned int size_pooling_1 = input_data / stride_1;
- err = hipMalloc((void **)&device_object->pooling_1_output, size_pooling_1 * size_pooling_1 * sizeof(bench_t));
-
- if (err != hipSuccess)
- {
- return false;
- }
- // Allocate kernel 2
- err = hipMalloc((void **)&device_object->kernel_2, kernel_2 * kernel_2 * sizeof(bench_t));
-
- if (err != hipSuccess)
- {
- return false;
- }
- // Allocate conv 1 output
- err = hipMalloc((void **)&device_object->conv_2_output, size_pooling_1 * size_pooling_1 * sizeof(bench_t));
-
- if (err != hipSuccess)
- {
- return false;
- }
- // Allocate pooling output
- unsigned int size_pooling_2 = size_pooling_1 / stride_2;
- err = hipMalloc((void **)&device_object->pooling_2_output, size_pooling_2 * size_pooling_2 * sizeof(bench_t));
-
- if (err != hipSuccess)
- {
- return false;
- }
- //dense layer 1 weights
- unsigned int weights_layer_1 = size_pooling_2 * size_pooling_2 * neurons_dense_1;
-
- err = hipMalloc((void **)&device_object->dense_layer_1_weights, weights_layer_1* sizeof(bench_t));
-
- if (err != hipSuccess)
- {
- return false;
- }
- // dense layer output 1
- err = hipMalloc((void **)&device_object->dense_layer_1_output, neurons_dense_1 * sizeof(bench_t));
-
- if (err != hipSuccess)
- {
- return false;
- }
- //dense layer 2 weights
- unsigned int weights_layer_2 = neurons_dense_1 * neurons_dense_2;
- err = hipMalloc((void **)&device_object->dense_layer_2_weights, weights_layer_2 * sizeof(bench_t));
-
- if (err != hipSuccess)
- {
- return false;
- }
- // dense layer output 2
- err = hipMalloc((void **)&device_object->dense_layer_2_output, neurons_dense_2 * sizeof(bench_t));
-
- if (err != hipSuccess)
- {
- return false;
- }
- // sum data
- err = hipMalloc((void **)&device_object->sum_ouput, sizeof(bench_t));
-
- if (err != hipSuccess)
- {
- return false;
- }
- // output data
- err = hipMalloc((void **)&device_object->output_data, neurons_dense_2 * sizeof(bench_t));
-
- if (err != hipSuccess)
- {
- return false;
- }
- return true;
- }
-
-void copy_memory_to_device(GraficObject *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){
- hipEventRecord(*device_object->start_memory_copy_device);
- hipError_t err = hipMemcpy(device_object->input_data, input_data, sizeof(bench_t) * input * input, hipMemcpyHostToDevice);
- if (err != hipSuccess)
- {
- fprintf(stderr, "Failed to copy vector input from host to device (error code %s)!\n", hipGetErrorString(err));
- return;
- }
- err = hipMemcpy(device_object->kernel_1, kernel_1_data, sizeof(bench_t) * kernel_size_1 * kernel_size_1, hipMemcpyHostToDevice);
- if (err != hipSuccess)
- {
- fprintf(stderr, "Failed to copy vector kernel_1 from host to device (error code %s)!\n", hipGetErrorString(err));
- return;
- }
- err = hipMemcpy(device_object->kernel_2, kernel_2_data, sizeof(bench_t) * kernel_size_2 * kernel_size_2, hipMemcpyHostToDevice);
- if (err != hipSuccess)
- {
- fprintf(stderr, "Failed to copy vector kernel_2 from host to device (error code %s)!\n", hipGetErrorString(err));
- return;
- }
- err = hipMemcpy(device_object->dense_layer_1_weights, weights_1, sizeof(bench_t) * weights_1_size, hipMemcpyHostToDevice);
- if (err != hipSuccess)
- {
- fprintf(stderr, "Failed to copy vector weights_layer_1 from host to device (error code %s)!\n", hipGetErrorString(err));
- return;
- }
- err = hipMemcpy(device_object->dense_layer_2_weights, weights_2, sizeof(bench_t) * weights_2_size, hipMemcpyHostToDevice);
- if (err != hipSuccess)
- {
- fprintf(stderr, "Failed to copy vector weights_layer_2 from host to device (error code %s)!\n", hipGetErrorString(err));
- return;
- }
- hipEventRecord(*device_object->stop_memory_copy_device);
-
-}
-void execute_kernel(GraficObject *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){
- // execute net
- // 1-1 step convolution
- hipEventRecord(*device_object->start);
+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);
dim3 dimBlock, dimGrid;
dimBlock = dim3(BLOCK_SIZE, BLOCK_SIZE);
dimGrid = dim3(ceil(float(input_data)/dimBlock.x), ceil(float(input_data)/dimBlock.y));
- hipLaunchKernelGGL((covolution_kernel), dim3(dimGrid), dim3(dimBlock), 0, 0, device_object->input_data, device_object->conv_1_output, device_object->kernel_1, input_data, input_data, input_data, kernel_1);
+ // kernel time execution
+ Clock kernelCLK;
+
+ // profilling start
+ kernelCLK.start();
+ (void)hipEventRecord(*deviceObj->start);
+
+ // 1-1 step convolution
+ hipLaunchKernelGGL((covolution_kernel), dim3(dimGrid), dim3(dimBlock), 0, 0, deviceObj->input_data, deviceObj->conv_1_output, deviceObj->kernel_1, input_data, input_data, input_data, kernel_1);
// 1-2 step activation
- hipLaunchKernelGGL((relu_kernel), dim3(dimGrid), dim3(dimBlock), 0, 0, device_object->conv_1_output, device_object->conv_1_output, input_data);
+ hipLaunchKernelGGL((relu_kernel), dim3(dimGrid), dim3(dimBlock), 0, 0, deviceObj->conv_1_output, deviceObj->conv_1_output, input_data);
// 1-3 step pooling
unsigned int size_lateral_1 = input_data / stride_1;
if(size_lateral_1 <= BLOCK_SIZE)
@@ -354,18 +197,18 @@ void execute_kernel(GraficObject *device_object, unsigned int input_data, unsign
dimBlock = dim3(BLOCK_SIZE, BLOCK_SIZE);
dimGrid = dim3(ceil(((float(size_lateral_1)))/dimBlock.x), ceil(((float(size_lateral_1) ))/dimBlock.y));
}
- hipLaunchKernelGGL((max_pooling_kernel), dim3(dimGrid), dim3(dimBlock), 0, 0, device_object->conv_1_output, device_object->pooling_1_output, input_data, stride_1, size_lateral_1);
+ hipLaunchKernelGGL((max_pooling_kernel), dim3(dimGrid), dim3(dimBlock), 0, 0, deviceObj->conv_1_output, deviceObj->pooling_1_output, input_data, stride_1, size_lateral_1);
// 1-4 normalization
- hipLaunchKernelGGL((lrn_kernel), dim3(dimGrid), dim3(dimBlock), 0, 0, device_object->pooling_1_output, device_object->pooling_1_output, size_lateral_1);
+ hipLaunchKernelGGL((lrn_kernel), dim3(dimGrid), dim3(dimBlock), 0, 0, deviceObj->pooling_1_output, deviceObj->pooling_1_output, size_lateral_1);
// 2-1 step convolution
- hipLaunchKernelGGL((covolution_kernel), dim3(dimGrid), dim3(dimBlock), 0, 0, device_object->pooling_1_output, device_object->conv_2_output, device_object->kernel_2, size_lateral_1, size_lateral_1, size_lateral_1, kernel_2);
+ hipLaunchKernelGGL((covolution_kernel), dim3(dimGrid), dim3(dimBlock), 0, 0, deviceObj->pooling_1_output, deviceObj->conv_2_output, deviceObj->kernel_2, size_lateral_1, size_lateral_1, size_lateral_1, kernel_2);
// 2-2 step activation
- hipLaunchKernelGGL((relu_kernel), dim3(dimGrid), dim3(dimBlock), 0, 0, device_object->conv_2_output, device_object->conv_2_output, size_lateral_1);
+ hipLaunchKernelGGL((relu_kernel), dim3(dimGrid), dim3(dimBlock), 0, 0, deviceObj->conv_2_output, deviceObj->conv_2_output, size_lateral_1);
// 2-3 normalization
- hipLaunchKernelGGL((lrn_kernel), dim3(dimGrid), dim3(dimBlock), 0, 0, device_object->conv_2_output, device_object->conv_2_output, size_lateral_1);
+ hipLaunchKernelGGL((lrn_kernel), dim3(dimGrid), dim3(dimBlock), 0, 0, deviceObj->conv_2_output, deviceObj->conv_2_output, size_lateral_1);
// 2-4 step pooling
unsigned int size_lateral_2 = size_lateral_1 / stride_2;
@@ -379,167 +222,37 @@ void execute_kernel(GraficObject *device_object, unsigned int input_data, unsign
dimBlock = dim3(BLOCK_SIZE, BLOCK_SIZE);
dimGrid = dim3(ceil(((float(size_lateral_2) ))/dimBlock.x), ceil(((float(size_lateral_2) ))/dimBlock.y));
}
- hipLaunchKernelGGL((max_pooling_kernel), dim3(dimGrid), dim3(dimBlock), 0, 0, device_object->conv_2_output, device_object->pooling_2_output, size_lateral_1, stride_2, size_lateral_2);
+ hipLaunchKernelGGL((max_pooling_kernel), dim3(dimGrid), dim3(dimBlock), 0, 0, deviceObj->conv_2_output, deviceObj->pooling_2_output, size_lateral_1, stride_2, size_lateral_2);
// dense layer 1
dimBlock = dim3(BLOCK_SIZE, 1);
dimGrid = dim3(ceil(float(neurons_dense_1)/dimBlock.x), 1);
- hipLaunchKernelGGL((matrix_multiplication_kernel), dim3(dimGrid), dim3(dimBlock), 0, 0, device_object->dense_layer_1_weights, device_object->pooling_2_output,device_object->dense_layer_1_output,neurons_dense_1, 1, size_lateral_2*size_lateral_2);
+ hipLaunchKernelGGL((matrix_multiplication_kernel), dim3(dimGrid), dim3(dimBlock), 0, 0, deviceObj->dense_layer_1_weights, deviceObj->pooling_2_output,deviceObj->dense_layer_1_output,neurons_dense_1, 1, size_lateral_2*size_lateral_2);
//activation layer dense 1
dimBlock = dim3(BLOCK_SIZE);
dimGrid = dim3(ceil(float(neurons_dense_1)/dimBlock.x));
- hipLaunchKernelGGL((relu_linear_kernel), dim3(dimGrid), dim3(dimBlock), 0, 0, device_object->dense_layer_1_output, device_object->dense_layer_1_output, neurons_dense_1);
+ hipLaunchKernelGGL((relu_linear_kernel), dim3(dimGrid), dim3(dimBlock), 0, 0, deviceObj->dense_layer_1_output, deviceObj->dense_layer_1_output, neurons_dense_1);
// dense layer 2
dimBlock = dim3(BLOCK_SIZE, 1);
dimGrid = dim3(ceil(float(neurons_dense_2)/dimBlock.x), 1);
- hipLaunchKernelGGL((matrix_multiplication_kernel), dim3(dimGrid), dim3(dimBlock), 0, 0, device_object->dense_layer_2_weights, device_object->dense_layer_1_output, device_object->dense_layer_2_output, neurons_dense_2, 1, neurons_dense_1);
+ hipLaunchKernelGGL((matrix_multiplication_kernel), dim3(dimGrid), dim3(dimBlock), 0, 0, deviceObj->dense_layer_2_weights, deviceObj->dense_layer_1_output, deviceObj->dense_layer_2_output, neurons_dense_2, 1, neurons_dense_1);
// activation layer dense 2
dimBlock = dim3(BLOCK_SIZE*BLOCK_SIZE);
dimGrid = dim3(ceil(float(neurons_dense_2)/dimBlock.x));
- hipLaunchKernelGGL((relu_linear_kernel), dim3(dimGrid), dim3(dimBlock), 0, 0, device_object->dense_layer_2_output, device_object->dense_layer_2_output, neurons_dense_2);
+ hipLaunchKernelGGL((relu_linear_kernel), dim3(dimGrid), dim3(dimBlock), 0, 0, deviceObj->dense_layer_2_output, deviceObj->dense_layer_2_output, neurons_dense_2);
// softmax
dimBlock = dim3(1, BLOCK_SIZE);
dimGrid = dim3(1, ceil(float(neurons_dense_2)/dimBlock.x));
- hipLaunchKernelGGL((softmax_kernel), dim3(dimGrid), dim3(dimBlock), 0, 0, device_object->dense_layer_2_output, device_object->output_data, device_object->sum_ouput, neurons_dense_2);
- hipLaunchKernelGGL((softmax_finish_kernel), dim3(dimGrid), dim3(dimBlock), 0, 0, device_object->output_data, device_object->sum_ouput, neurons_dense_2);
- hipEventRecord(*device_object->stop);
-}
-
-void copy_memory_to_host(GraficObject *device_object, bench_t* h_C, int size){
- hipEventRecord(*device_object->start_memory_copy_host);
- hipMemcpy(h_C, device_object->output_data, size * sizeof(bench_t), hipMemcpyDeviceToHost);
- //hipMemcpy(h_C, device_object->dense_layer_2_output, 10 * sizeof(bench_t), hipMemcpyDeviceToHost);
- hipEventRecord(*device_object->stop_memory_copy_host);
-}
-
-float get_elapsed_time(GraficObject *device_object, bool csv_format,bool csv_format_timestamp, long int current_time){
- hipEventSynchronize(*device_object->stop_memory_copy_host);
- float milliseconds_h_d = 0, milliseconds = 0, milliseconds_d_h = 0;
- // memory transfer time host-device
- hipEventElapsedTime(&milliseconds_h_d, *device_object->start_memory_copy_device, *device_object->stop_memory_copy_device);
- // kernel time
- hipEventElapsedTime(&milliseconds, *device_object->start, *device_object->stop);
- // memory transfer time device-host
- hipEventElapsedTime(&milliseconds_d_h, *device_object->start_memory_copy_host, *device_object->stop_memory_copy_host);
+ hipLaunchKernelGGL((softmax_kernel), dim3(dimGrid), dim3(dimBlock), 0, 0, deviceObj->dense_layer_2_output, deviceObj->output_data, deviceObj->sum_ouput, neurons_dense_2);
+ hipLaunchKernelGGL((softmax_finish_kernel), dim3(dimGrid), dim3(dimBlock), 0, 0, deviceObj->output_data, deviceObj->sum_ouput, neurons_dense_2);
- if (csv_format_timestamp){
- printf("%.10f;%.10f;%.10f;%ld;\n", milliseconds_h_d,milliseconds,milliseconds_d_h, current_time);
- }
- else if (csv_format){
- printf("%.10f;%.10f;%.10f;\n", milliseconds_h_d,milliseconds,milliseconds_d_h);
- }else{
- printf("Elapsed time Host->Device: %.10f milliseconds\n", milliseconds_h_d);
- printf("Elapsed time kernel: %.10f milliseconds\n", milliseconds);
- printf("Elapsed time Device->Host: %.10f milliseconds\n", milliseconds_d_h);
- }
- return milliseconds;
-}
-
-void clean(GraficObject *device_object){
- hipError_t err = hipSuccess;
-
- err = hipFree(device_object->input_data);
-
- if (err != hipSuccess)
- {
- fprintf(stderr, "Failed to free device vector input_data (error code %s)!\n", hipGetErrorString(err));
- return;
- }
-
- err = hipFree(device_object->kernel_1);
-
- if (err != hipSuccess)
- {
- fprintf(stderr, "Failed to free device vector kernel_1 (error code %s)!\n", hipGetErrorString(err));
- return;
- }
- err = hipFree(device_object->conv_1_output);
-
- if (err != hipSuccess)
- {
- fprintf(stderr, "Failed to free device vector conv_1_output (error code %s)!\n", hipGetErrorString(err));
- return;
- }
- err = hipFree(device_object->pooling_1_output);
- if (err != hipSuccess)
- {
- fprintf(stderr, "Failed to free device vector pooling_1_output (error code %s)!\n", hipGetErrorString(err));
- return;
- }
-
- err = hipFree(device_object->kernel_2);
-
- if (err != hipSuccess)
- {
- fprintf(stderr, "Failed to free device vector kernel_2 (error code %s)!\n", hipGetErrorString(err));
- return;
- }
- err = hipFree(device_object->conv_2_output);
-
- if (err != hipSuccess)
- {
- fprintf(stderr, "Failed to free device vector conv_2_output (error code %s)!\n", hipGetErrorString(err));
- return;
- }
- err = hipFree(device_object->pooling_2_output);
-
- if (err != hipSuccess)
- {
- fprintf(stderr, "Failed to free device vector pooling_2_output (error code %s)!\n", hipGetErrorString(err));
- return;
- }
-
- err = hipFree(device_object->dense_layer_1_weights);
-
- if (err != hipSuccess)
- {
- fprintf(stderr, "Failed to free device vector dense_layer_1_weights (error code %s)!\n", hipGetErrorString(err));
- return;
- }
- err = hipFree(device_object->dense_layer_2_weights);
-
- if (err != hipSuccess)
- {
- fprintf(stderr, "Failed to free device vector dense_layer_2_weights (error code %s)!\n", hipGetErrorString(err));
- return;
- }
- err = hipFree(device_object->dense_layer_1_output);
- if (err != hipSuccess)
- {
- fprintf(stderr, "Failed to free device vector dense_layer_1_output (error code %s)!\n", hipGetErrorString(err));
- return;
- }
-
- err = hipFree(device_object->dense_layer_2_output);
-
- if (err != hipSuccess)
- {
- fprintf(stderr, "Failed to free device vector dense_layer_2_output (error code %s)!\n", hipGetErrorString(err));
- return;
- }
- err = hipFree(device_object->output_data);
-
- if (err != hipSuccess)
- {
- fprintf(stderr, "Failed to free device vector output_data (error code %s)!\n", hipGetErrorString(err));
- return;
- }
- err = hipFree(device_object->sum_ouput);
-
- if (err != hipSuccess)
- {
- fprintf(stderr, "Failed to free device vector sum_ouput (error code %s)!\n", hipGetErrorString(err));
- return;
- }
-
+ // profilling end
+ (void)hipEventRecord(*deviceObj->stop);
+ hipDeviceSynchronize();
+ kernelCLK.end();
- // delete events
- delete device_object->start;
- delete device_object->stop;
- delete device_object->start_memory_copy_device;
- delete device_object->stop_memory_copy_device;
- delete device_object->start_memory_copy_host;
- delete device_object->stop_memory_copy_host;
+ // store the kernel time
+ deviceObj->elapsed_time = kernelCLK.getElapsedMS();
}
diff --git a/gpu4s_benchmark/cifar_10/hip/lib_hip_opt.cpp b/gpu4s_benchmark/cifar_10/hip/lib_hip_opt.cpp
index 764dc029..0825ed44 100644
--- a/gpu4s_benchmark/cifar_10/hip/lib_hip_opt.cpp
+++ b/gpu4s_benchmark/cifar_10/hip/lib_hip_opt.cpp
@@ -1,13 +1,12 @@
-#include "hip/hip_runtime.h"
#include "../benchmark_library.h"
+
/**
* CUDA Kernel Device code
*
* Computes the vector addition of A and B into C. The 3 vectors have the same
* number of elements numElements.
*/
-//#define BLOCK_SIZE 16
#define BLOCK_SIZE_PLANE (BLOCK_SIZE * BLOCK_SIZE)
__global__ void
@@ -77,10 +76,10 @@ covolution_kernel(const bench_t *A, bench_t *B, const bench_t *kernel,const int
bench_t sum = 0;
unsigned int xa = kernel_rad + threadIdx.x;
unsigned int ya = kernel_rad + threadIdx.y;
- #pragma unroll
+ #pragma unroll 3
for(int i = -kernel_rad; i <= kernel_rad; ++i) // loop over kernel_rad -1 to 1 in kernel_size 3
{
- #pragma unroll
+ #pragma unroll 3
for(int j = -kernel_rad; j <= kernel_rad; ++j)
{
//printf("ACHIVED position %d %d value %f\n", (xa + i) , (ya + j), data[(xa + i)][(ya + j)]);
@@ -300,6 +299,7 @@ softmax_kernel(const bench_t *A, bench_t *B, bench_t *sum_d_B,const int size)
#else
value = exp(A[i]);
#endif
+
shared_data[tid] = value;
B[i] = value;
// sync threads
@@ -330,185 +330,27 @@ softmax_finish_kernel(bench_t *B, bench_t *sum_d_B,const int size)
// End CUDA part
//////////////////////////////////////////////////////////////////////////////////////
-
-void init(GraficObject *device_object, char* device_name){
- init(device_object, 0,0, device_name);
-}
-
-void init(GraficObject *device_object, int platform ,int device, char* device_name){
- hipSetDevice(device);
- hipDeviceProp_t prop;
- hipGetDeviceProperties(&prop, device);
- //printf("Using device: %s\n", prop.name);
- strcpy(device_name,prop.name);
- //event create
- device_object->start = new hipEvent_t;
- device_object->stop = new hipEvent_t;
- device_object->start_memory_copy_device = new hipEvent_t;
- device_object->stop_memory_copy_device = new hipEvent_t;
- device_object->start_memory_copy_host = new hipEvent_t;
- device_object->stop_memory_copy_host= new hipEvent_t;
-
- hipEventCreate(device_object->start);
- hipEventCreate(device_object->stop);
- hipEventCreate(device_object->start_memory_copy_device);
- hipEventCreate(device_object->stop_memory_copy_device);
- hipEventCreate(device_object->start_memory_copy_host);
- hipEventCreate(device_object->stop_memory_copy_host);
-}
-
-
-bool device_memory_init(GraficObject *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){
- // Allocate input
- hipError_t err = hipSuccess;
- err = hipMalloc((void **)&device_object->input_data, input_data * input_data * sizeof(bench_t));
-
- if (err != hipSuccess)
- {
- return false;
- }
- // Allocate kernel
- err = hipMalloc((void **)&device_object->kernel_1, kernel_1 * kernel_1 * sizeof(bench_t));
-
- if (err != hipSuccess)
- {
- return false;
- }
- // Allocate conv 1 output
- err = hipMalloc((void **)&device_object->conv_1_output, input_data * input_data * sizeof(bench_t));
-
- if (err != hipSuccess)
- {
- return false;
- }
- // Allocate pooling output
- unsigned int size_pooling_1 = input_data / stride_1;
- err = hipMalloc((void **)&device_object->pooling_1_output, size_pooling_1 * size_pooling_1 * sizeof(bench_t));
-
- if (err != hipSuccess)
- {
- return false;
- }
- // Allocate kernel 2
- err = hipMalloc((void **)&device_object->kernel_2, kernel_2 * kernel_2 * sizeof(bench_t));
-
- if (err != hipSuccess)
- {
- return false;
- }
- // Allocate conv 1 output
- err = hipMalloc((void **)&device_object->conv_2_output, size_pooling_1 * size_pooling_1 * sizeof(bench_t));
-
- if (err != hipSuccess)
- {
- return false;
- }
- // Allocate pooling output
- unsigned int size_pooling_2 = size_pooling_1 / stride_2;
- err = hipMalloc((void **)&device_object->pooling_2_output, size_pooling_2 * size_pooling_2 * sizeof(bench_t));
-
- if (err != hipSuccess)
- {
- return false;
- }
- //dense layer 1 weights
- unsigned int weights_layer_1 = size_pooling_2 * size_pooling_2 * neurons_dense_1;
-
- err = hipMalloc((void **)&device_object->dense_layer_1_weights, weights_layer_1* sizeof(bench_t));
-
- if (err != hipSuccess)
- {
- return false;
- }
- // dense layer output 1
- err = hipMalloc((void **)&device_object->dense_layer_1_output, neurons_dense_1 * sizeof(bench_t));
-
- if (err != hipSuccess)
- {
- return false;
- }
- //dense layer 2 weights
- unsigned int weights_layer_2 = neurons_dense_1 * neurons_dense_2;
- err = hipMalloc((void **)&device_object->dense_layer_2_weights, weights_layer_2 * sizeof(bench_t));
-
- if (err != hipSuccess)
- {
- return false;
- }
- // dense layer output 2
- err = hipMalloc((void **)&device_object->dense_layer_2_output, neurons_dense_2 * sizeof(bench_t));
-
- if (err != hipSuccess)
- {
- return false;
- }
- // sum data
- err = hipMalloc((void **)&device_object->sum_ouput, sizeof(bench_t));
-
- if (err != hipSuccess)
- {
- return false;
- }
- // output data
- err = hipMalloc((void **)&device_object->output_data, neurons_dense_2 * sizeof(bench_t));
-
- if (err != hipSuccess)
- {
- return false;
- }
- return true;
- }
-
-void copy_memory_to_device(GraficObject *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){
- hipEventRecord(*device_object->start_memory_copy_device);
- hipError_t err = hipMemcpy(device_object->input_data, input_data, sizeof(bench_t) * input * input, hipMemcpyHostToDevice);
- if (err != hipSuccess)
- {
- fprintf(stderr, "Failed to copy vector input from host to device (error code %s)!\n", hipGetErrorString(err));
- return;
- }
- err = hipMemcpy(device_object->kernel_1, kernel_1_data, sizeof(bench_t) * kernel_size_1 * kernel_size_1, hipMemcpyHostToDevice);
- if (err != hipSuccess)
- {
- fprintf(stderr, "Failed to copy vector kernel_1 from host to device (error code %s)!\n", hipGetErrorString(err));
- return;
- }
- err = hipMemcpy(device_object->kernel_2, kernel_2_data, sizeof(bench_t) * kernel_size_2 * kernel_size_2, hipMemcpyHostToDevice);
- if (err != hipSuccess)
- {
- fprintf(stderr, "Failed to copy vector kernel_2 from host to device (error code %s)!\n", hipGetErrorString(err));
- return;
- }
- err = hipMemcpy(device_object->dense_layer_1_weights, weights_1, sizeof(bench_t) * weights_1_size, hipMemcpyHostToDevice);
- if (err != hipSuccess)
- {
- fprintf(stderr, "Failed to copy vector weights_layer_1 from host to device (error code %s)!\n", hipGetErrorString(err));
- return;
- }
- err = hipMemcpy(device_object->dense_layer_2_weights, weights_2, sizeof(bench_t) * weights_2_size, hipMemcpyHostToDevice);
- if (err != hipSuccess)
- {
- fprintf(stderr, "Failed to copy vector weights_layer_2 from host to device (error code %s)!\n", hipGetErrorString(err));
- return;
- }
- hipEventRecord(*device_object->stop_memory_copy_device);
-
-}
-void execute_kernel(GraficObject *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){
- // execute net
- // 1-1 step convolution
- hipEventRecord(*device_object->start);
+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);
dim3 dimBlock, dimGrid,dimBlock_act, dimGrid_act;
dimBlock = dim3(BLOCK_SIZE, BLOCK_SIZE);
dimGrid = dim3(ceil(float(input_data)/dimBlock.x), ceil(float(input_data)/dimBlock.y));
unsigned int kernel_rad = kernel_1 / 2;
unsigned int size_shared = (BLOCK_SIZE + kernel_rad *2 ) * sizeof(bench_t) * (BLOCK_SIZE + kernel_rad *2) * sizeof(bench_t);
unsigned int size_shared_position = (BLOCK_SIZE + kernel_rad *2);
- hipLaunchKernelGGL((covolution_kernel), dim3(dimGrid), dim3(dimBlock), size_shared, 0, device_object->input_data, device_object->conv_1_output, device_object->kernel_1, input_data, input_data, input_data, kernel_1, size_shared_position, kernel_rad);
+ // kernel time execution
+ Clock kernelCLK;
+
+ // profilling start
+ kernelCLK.start();
+ (void)hipEventRecord(*deviceObj->start);
+
+ // 1-1 step convolution
+ hipLaunchKernelGGL((covolution_kernel), dim3(dimGrid), dim3(dimBlock), size_shared, 0, deviceObj->input_data, deviceObj->conv_1_output, deviceObj->kernel_1, input_data, input_data, input_data, kernel_1, size_shared_position, kernel_rad);
// 1-2 step activation
dimBlock = dim3(BLOCK_SIZE_PLANE);
dimGrid = dim3(ceil(float(input_data)/dimBlock.x));
- hipLaunchKernelGGL((relu_kernel), dim3(dimGrid), dim3(dimBlock), 0, 0, device_object->conv_1_output, device_object->conv_1_output, input_data*input_data);
+ hipLaunchKernelGGL((relu_kernel), dim3(dimGrid), dim3(dimBlock), 0, 0, deviceObj->conv_1_output, deviceObj->conv_1_output, input_data*input_data);
// 1-3 step pooling
unsigned int size_lateral_1 = input_data / stride_1;
if(size_lateral_1*size_lateral_1 < BLOCK_SIZE_PLANE)
@@ -521,7 +363,7 @@ void execute_kernel(GraficObject *device_object, unsigned int input_data, unsign
dimBlock = dim3(BLOCK_SIZE_PLANE);
dimGrid = dim3(ceil((size_lateral_1*size_lateral_1)/dimBlock.x));
}
- hipLaunchKernelGGL((max_pooling_kernel), dim3(dimGrid), dim3(dimBlock), 0, 0, device_object->conv_1_output, device_object->pooling_1_output, input_data, stride_1, size_lateral_1);
+ hipLaunchKernelGGL((max_pooling_kernel), dim3(dimGrid), dim3(dimBlock), 0, 0, deviceObj->conv_1_output, deviceObj->pooling_1_output, input_data, stride_1, size_lateral_1);
// 1-4 normalization
if(size_lateral_1 < BLOCK_SIZE)
{
@@ -534,21 +376,21 @@ void execute_kernel(GraficObject *device_object, unsigned int input_data, unsign
dimGrid = dim3(ceil(((float(size_lateral_1) ))/dimBlock.x), ceil(((float(size_lateral_1) ))/dimBlock.y));
}
- hipLaunchKernelGGL((lrn_kernel), dim3(dimGrid), dim3(dimBlock), 0, 0, device_object->pooling_1_output, device_object->pooling_1_output, size_lateral_1);
+ hipLaunchKernelGGL((lrn_kernel), dim3(dimGrid), dim3(dimBlock), 0, 0, deviceObj->pooling_1_output, deviceObj->pooling_1_output, size_lateral_1);
// 2-1 step convolution
//kernel_rad = kernel_2 / 2;
//size_shared = (BLOCK_SIZE + kernel_rad *2 ) * sizeof(bench_t) * (BLOCK_SIZE + kernel_rad *2) * sizeof(bench_t);
//size_shared_position = (BLOCK_SIZE + kernel_rad *2);
- //hipLaunchKernelGGL((covolution_kernel), dim3(dimGrid), dim3(dimBlock), size_shared, 0, device_object->pooling_1_output, device_object->conv_2_output, device_object->kernel_2, size_lateral_1, size_lateral_1, size_lateral_1, kernel_2,size_shared_position, kernel_rad);
- hipLaunchKernelGGL((covolution_kernel_base), dim3(dimGrid), dim3(dimBlock), 0, 0, device_object->pooling_1_output, device_object->conv_2_output, device_object->kernel_2, size_lateral_1, size_lateral_1, size_lateral_1, kernel_2);
+ //hipLaunchKernelGGL((covolution_kernel), dim3(dimGrid), dim3(dimBlock), size_shared, 0, deviceObj->pooling_1_output, deviceObj->conv_2_output, deviceObj->kernel_2, size_lateral_1, size_lateral_1, size_lateral_1, kernel_2,size_shared_position, kernel_rad);
+ hipLaunchKernelGGL((covolution_kernel_base), dim3(dimGrid), dim3(dimBlock), 0, 0, deviceObj->pooling_1_output, deviceObj->conv_2_output, deviceObj->kernel_2, size_lateral_1, size_lateral_1, size_lateral_1, kernel_2);
// 2-2 step activation
dimBlock_act = dim3(BLOCK_SIZE_PLANE);
dimGrid_act = dim3(ceil(float(size_lateral_1*size_lateral_1)/dimBlock.x));
- hipLaunchKernelGGL((relu_kernel), dim3(dimGrid_act), dim3(dimBlock_act), 0, 0, device_object->conv_2_output, device_object->conv_2_output, size_lateral_1);
+ hipLaunchKernelGGL((relu_kernel), dim3(dimGrid_act), dim3(dimBlock_act), 0, 0, deviceObj->conv_2_output, deviceObj->conv_2_output, size_lateral_1);
// 2-3 normalization
- hipLaunchKernelGGL((lrn_kernel), dim3(dimGrid), dim3(dimBlock), 0, 0, device_object->conv_2_output, device_object->conv_2_output, size_lateral_1);
+ hipLaunchKernelGGL((lrn_kernel), dim3(dimGrid), dim3(dimBlock), 0, 0, deviceObj->conv_2_output, deviceObj->conv_2_output, size_lateral_1);
// 2-4 step pooling
unsigned int size_lateral_2 = size_lateral_1 / stride_2;
if(size_lateral_2*size_lateral_2 <= BLOCK_SIZE_PLANE)
@@ -561,168 +403,38 @@ void execute_kernel(GraficObject *device_object, unsigned int input_data, unsign
dimBlock = dim3(BLOCK_SIZE_PLANE);
dimGrid = dim3(ceil((size_lateral_2*size_lateral_2)/dimBlock.x));
}
- hipLaunchKernelGGL((max_pooling_kernel), dim3(dimGrid), dim3(dimBlock), 0, 0, device_object->conv_2_output, device_object->pooling_2_output, size_lateral_1, stride_2, size_lateral_2);
+ hipLaunchKernelGGL((max_pooling_kernel), dim3(dimGrid), dim3(dimBlock), 0, 0, deviceObj->conv_2_output, deviceObj->pooling_2_output, size_lateral_1, stride_2, size_lateral_2);
// dense layer 1
dimBlock = dim3(BLOCK_SIZE, 1);
dimGrid = dim3(ceil(float(neurons_dense_1)/dimBlock.x), 1);
- hipLaunchKernelGGL((matrix_multiplication_kernel_other), dim3(dimGrid), dim3(dimBlock), 0, 0, device_object->dense_layer_1_weights, device_object->pooling_2_output,device_object->dense_layer_1_output,neurons_dense_1, 1, size_lateral_2*size_lateral_2);
+ hipLaunchKernelGGL((matrix_multiplication_kernel_other), dim3(dimGrid), dim3(dimBlock), 0, 0, deviceObj->dense_layer_1_weights, deviceObj->pooling_2_output,deviceObj->dense_layer_1_output,neurons_dense_1, 1, size_lateral_2*size_lateral_2);
//activation layer dense 1
dimBlock_act = dim3(BLOCK_SIZE_PLANE);
dimGrid_act = dim3(ceil(float(neurons_dense_1)/dimBlock.x));
- hipLaunchKernelGGL((relu_linear_kernel), dim3(dimGrid_act), dim3(dimBlock_act), 0, 0, device_object->dense_layer_1_output, device_object->dense_layer_1_output, neurons_dense_1);
+ hipLaunchKernelGGL((relu_linear_kernel), dim3(dimGrid_act), dim3(dimBlock_act), 0, 0, deviceObj->dense_layer_1_output, deviceObj->dense_layer_1_output, neurons_dense_1);
// dense layer 2
dimBlock = dim3(BLOCK_SIZE, 1);
dimGrid = dim3(ceil(float(neurons_dense_2)/dimBlock.x), 1);
- hipLaunchKernelGGL((matrix_multiplication_kernel_other), dim3(dimGrid), dim3(dimBlock), 0, 0, device_object->dense_layer_2_weights, device_object->dense_layer_1_output, device_object->dense_layer_2_output, neurons_dense_2, 1, neurons_dense_1);
+ hipLaunchKernelGGL((matrix_multiplication_kernel_other), dim3(dimGrid), dim3(dimBlock), 0, 0, deviceObj->dense_layer_2_weights, deviceObj->dense_layer_1_output, deviceObj->dense_layer_2_output, neurons_dense_2, 1, neurons_dense_1);
// activation layer dense 2
dimBlock = dim3(BLOCK_SIZE_PLANE);
dimGrid = dim3(ceil(float(neurons_dense_2)/dimBlock.x));
- hipLaunchKernelGGL((relu_linear_kernel), dim3(dimGrid_act), dim3(dimBlock_act), 0, 0, device_object->dense_layer_2_output, device_object->dense_layer_2_output, neurons_dense_2);
+ hipLaunchKernelGGL((relu_linear_kernel), dim3(dimGrid_act), dim3(dimBlock_act), 0, 0, deviceObj->dense_layer_2_output, deviceObj->dense_layer_2_output, neurons_dense_2);
// softmax
dimBlock = dim3(BLOCK_SIZE);
dimGrid = dim3(ceil(float(neurons_dense_2)/dimBlock.x));
- hipLaunchKernelGGL((softmax_kernel), dim3(dimGrid), dim3(dimBlock), 0, 0, device_object->dense_layer_2_output, device_object->output_data, device_object->sum_ouput, neurons_dense_2);
- hipLaunchKernelGGL((softmax_finish_kernel), dim3(dimGrid), dim3(dimBlock), 0, 0, device_object->output_data, device_object->sum_ouput, neurons_dense_2);
- hipEventRecord(*device_object->stop);
-}
-
-void copy_memory_to_host(GraficObject *device_object, bench_t* h_C, int size){
- hipEventRecord(*device_object->start_memory_copy_host);
- hipMemcpy(h_C, device_object->output_data, size * sizeof(bench_t), hipMemcpyDeviceToHost);
- //hipMemcpy(h_C, device_object->dense_layer_2_output, 10 * sizeof(bench_t), hipMemcpyDeviceToHost);
- hipEventRecord(*device_object->stop_memory_copy_host);
-}
-
-float get_elapsed_time(GraficObject *device_object, bool csv_format,bool csv_format_timestamp, long int current_time){
- hipEventSynchronize(*device_object->stop_memory_copy_host);
- float milliseconds_h_d = 0, milliseconds = 0, milliseconds_d_h = 0;
- // memory transfer time host-device
- hipEventElapsedTime(&milliseconds_h_d, *device_object->start_memory_copy_device, *device_object->stop_memory_copy_device);
- // kernel time
- hipEventElapsedTime(&milliseconds, *device_object->start, *device_object->stop);
- // memory transfer time device-host
- hipEventElapsedTime(&milliseconds_d_h, *device_object->start_memory_copy_host, *device_object->stop_memory_copy_host);
+ hipLaunchKernelGGL((softmax_kernel), dim3(dimGrid), dim3(dimBlock), 0, 0, deviceObj->dense_layer_2_output, deviceObj->output_data, deviceObj->sum_ouput, neurons_dense_2);
+ hipLaunchKernelGGL((softmax_finish_kernel), dim3(dimGrid), dim3(dimBlock), 0, 0, deviceObj->output_data, deviceObj->sum_ouput, neurons_dense_2);
- if (csv_format_timestamp){
- printf("%.10f;%.10f;%.10f;%ld;\n", milliseconds_h_d,milliseconds,milliseconds_d_h, current_time);
- }
- else if (csv_format){
- printf("%.10f;%.10f;%.10f;\n", milliseconds_h_d,milliseconds,milliseconds_d_h);
- }else{
- printf("Elapsed time Host->Device: %.10f milliseconds\n", milliseconds_h_d);
- printf("Elapsed time kernel: %.10f milliseconds\n", milliseconds);
- printf("Elapsed time Device->Host: %.10f milliseconds\n", milliseconds_d_h);
- }
- return milliseconds;
-}
-
-void clean(GraficObject *device_object){
- hipError_t err = hipSuccess;
-
- err = hipFree(device_object->input_data);
-
- if (err != hipSuccess)
- {
- fprintf(stderr, "Failed to free device vector input_data (error code %s)!\n", hipGetErrorString(err));
- return;
- }
-
- err = hipFree(device_object->kernel_1);
-
- if (err != hipSuccess)
- {
- fprintf(stderr, "Failed to free device vector kernel_1 (error code %s)!\n", hipGetErrorString(err));
- return;
- }
- err = hipFree(device_object->conv_1_output);
-
- if (err != hipSuccess)
- {
- fprintf(stderr, "Failed to free device vector conv_1_output (error code %s)!\n", hipGetErrorString(err));
- return;
- }
- err = hipFree(device_object->pooling_1_output);
- if (err != hipSuccess)
- {
- fprintf(stderr, "Failed to free device vector pooling_1_output (error code %s)!\n", hipGetErrorString(err));
- return;
- }
-
- err = hipFree(device_object->kernel_2);
-
- if (err != hipSuccess)
- {
- fprintf(stderr, "Failed to free device vector kernel_2 (error code %s)!\n", hipGetErrorString(err));
- return;
- }
- err = hipFree(device_object->conv_2_output);
-
- if (err != hipSuccess)
- {
- fprintf(stderr, "Failed to free device vector conv_2_output (error code %s)!\n", hipGetErrorString(err));
- return;
- }
- err = hipFree(device_object->pooling_2_output);
-
- if (err != hipSuccess)
- {
- fprintf(stderr, "Failed to free device vector pooling_2_output (error code %s)!\n", hipGetErrorString(err));
- return;
- }
-
- err = hipFree(device_object->dense_layer_1_weights);
-
- if (err != hipSuccess)
- {
- fprintf(stderr, "Failed to free device vector dense_layer_1_weights (error code %s)!\n", hipGetErrorString(err));
- return;
- }
- err = hipFree(device_object->dense_layer_2_weights);
-
- if (err != hipSuccess)
- {
- fprintf(stderr, "Failed to free device vector dense_layer_2_weights (error code %s)!\n", hipGetErrorString(err));
- return;
- }
- err = hipFree(device_object->dense_layer_1_output);
- if (err != hipSuccess)
- {
- fprintf(stderr, "Failed to free device vector dense_layer_1_output (error code %s)!\n", hipGetErrorString(err));
- return;
- }
-
- err = hipFree(device_object->dense_layer_2_output);
-
- if (err != hipSuccess)
- {
- fprintf(stderr, "Failed to free device vector dense_layer_2_output (error code %s)!\n", hipGetErrorString(err));
- return;
- }
- err = hipFree(device_object->output_data);
-
- if (err != hipSuccess)
- {
- fprintf(stderr, "Failed to free device vector output_data (error code %s)!\n", hipGetErrorString(err));
- return;
- }
- err = hipFree(device_object->sum_ouput);
-
- if (err != hipSuccess)
- {
- fprintf(stderr, "Failed to free device vector sum_ouput (error code %s)!\n", hipGetErrorString(err));
- return;
- }
-
+ // profilling end
+ (void)hipEventRecord(*deviceObj->stop);
+ hipDeviceSynchronize();
+ kernelCLK.end();
- // delete events
- delete device_object->start;
- delete device_object->stop;
- delete device_object->start_memory_copy_device;
- delete device_object->stop_memory_copy_device;
- delete device_object->start_memory_copy_host;
- delete device_object->stop_memory_copy_host;
+ // store the kernel time
+ deviceObj->elapsed_time = kernelCLK.getElapsedMS();
}
diff --git a/gpu4s_benchmark/cifar_10/main.cpp b/gpu4s_benchmark/cifar_10/main.cpp
index 5910ae66..da84df0b 100644
--- a/gpu4s_benchmark/cifar_10/main.cpp
+++ b/gpu4s_benchmark/cifar_10/main.cpp
@@ -1,7 +1,5 @@
-#include
#include "benchmark_library.h"
#include "cpu_functions/cpu_functions.h"
-#include
#define NUMBER_BASE 1
#define MIN_VALUE -0.6
@@ -30,7 +28,6 @@ bench_t RandomNumber();
int main(int argc, char *argv[]){
// random init
- //srand (time(NULL));
srand (21121993);
///////////////////////////////////////////////////////////////////////////////////////////////
// Arguments
@@ -45,31 +42,32 @@ 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
+ // 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 = (bench_t*) malloc(mem_size_A);
+ 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 = (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;
@@ -80,11 +78,49 @@ 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
+ // 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");
+ 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;
- // strucs for CPU timing
- struct timespec start, end;
///////////////////////////////////////////////////////////////////////////////////////////////
// DATA INIT
///////////////////////////////////////////////////////////////////////////////////////////////
@@ -94,14 +130,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
}
@@ -111,7 +146,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);
}
-
- // 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
+ // 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
}
- // 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
+ // UMA: map back output buffer to host
+ sync_unified_memory_to_host(cifar10_bench, d_output, mem_size_B);
+ #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_gettime(CLOCK_MONOTONIC_RAW, &start);
+ 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);
- clock_gettime(CLOCK_MONOTONIC_RAW, &end);
+ cpuKernelCLK.end();
+
if (arguments_parameters->print_timing)
{
- printf("CPU Time %lu milliseconds\n", (end.tv_sec - start.tv_sec) * 1000 + (end.tv_nsec - start.tv_nsec) / 1000000);
+ 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
///////////////////////////////////////////////////////////////////////////////////////////////
@@ -273,12 +315,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);
@@ -286,7 +333,7 @@ int main(int argc, char *argv[]){
free(dense_layer_1_output);
free(dense_layer_2_output);
free(output_data);
-return 0;
+ return 0;
}
@@ -307,6 +354,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(" -u: enable unified memory (ANDROID/JETSON)\n");
}
void init_arguments(BenchmarkParameters* arguments_parameters){
@@ -320,6 +369,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->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){
@@ -341,6 +398,8 @@ int arguments_handler(int argc, char ** argv, BenchmarkParameters* arguments_par
args +=1;
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]);
@@ -359,4 +418,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/opencl/lib_opencl.cpp b/gpu4s_benchmark/cifar_10/opencl/lib_opencl.cpp
index eebd3ae8..9f57ca62 100644
--- a/gpu4s_benchmark/cifar_10/opencl/lib_opencl.cpp
+++ b/gpu4s_benchmark/cifar_10/opencl/lib_opencl.cpp
@@ -1,114 +1,12 @@
// OpenCL lib code
#include
#include "../benchmark_library.h"
-#include
#include "GEN_kernel.hcl"
#include "GEN_atomic_functions.hcl"
-//#define BLOCK_SIZE 16
-void init(GraficObject *device_object, char* device_name){
- init(device_object, 0,0, device_name);
-}
-void init(GraficObject *device_object, int platform ,int device, char* device_name){
- //get all platforms (drivers)
- std::vector all_platforms;
- cl::Platform::get(&all_platforms);
- if(all_platforms.size()==0){
- std::cout<<" No platforms found. Check OpenCL installation!\n";
- exit(1);
- }
- cl::Platform default_platform=all_platforms[platform];
- //std::cout << "Using platform: "<()<<"\n";
- //get default device of the default platform
- std::vector all_devices;
- default_platform.getDevices(CL_DEVICE_TYPE_ALL, &all_devices);
- if(all_devices.size()==0){
- std::cout<<" No devices found. Check OpenCL installation!\n";
- exit(1);
- }
- cl::Device default_device=all_devices[device];
- //std::cout<< "Using device: "<