Skip to content

Commit 18112bc

Browse files
authored
Merge pull request #6773 from mconcas/improve-gpu-benchmark
Improve GPU benchmark
1 parent 2e523ea commit 18112bc

8 files changed

Lines changed: 615 additions & 762 deletions

File tree

GPU/GPUbenchmark/CMakeLists.txt

Lines changed: 3 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -9,49 +9,12 @@
99
# granted to it by virtue of its status as an Intergovernmental Organization
1010
# or submit itself to any jurisdiction.
1111

12-
set(HDRS_INSTALL ../Shared/Kernels.h)
13-
1412
if(CUDA_ENABLED)
15-
o2_add_executable(gpu-memory-benchmark-cuda
16-
SOURCES benchmark.cxx
17-
cuda/Kernels.cu
18-
PUBLIC_LINK_LIBRARIES Boost::program_options
19-
ROOT::Tree
20-
TARGETVARNAME targetName)
13+
add_subdirectory(cuda)
2114
endif()
2215

2316
if(HIP_ENABLED)
24-
# Hipify-perl
25-
set(HIPIFY_EXECUTABLE "/opt/rocm/bin/hipify-perl")
26-
27-
set(HIP_KERNEL "Kernels.hip.cxx")
28-
set(CU_KERNEL ${CMAKE_CURRENT_SOURCE_DIR}/cuda/Kernels.cu)
29-
set(HIP_KERNEL_PATH "${CMAKE_CURRENT_SOURCE_DIR}/hip/${HIP_KERNEL}")
30-
31-
if(EXISTS ${HIPIFY_EXECUTABLE})
32-
set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS ${CU_KERNEL})
33-
add_custom_command(
34-
OUTPUT ${HIP_KERNEL_PATH}
35-
COMMAND ${HIPIFY_EXECUTABLE} --quiet-warnings ${CU_KERNEL} | sed '1{/\#include \"hip\\/hip_runtime.h\"/d}' > ${HIP_KERNEL_PATH}
36-
)
37-
set(CMAKE_CXX_COMPILER ${HIP_HIPCC_EXECUTABLE})
38-
set(CMAKE_CXX_LINKER ${HIP_HIPCC_EXECUTABLE})
39-
set(CMAKE_CXX_EXTENSIONS OFF)
40-
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${O2_HIP_CMAKE_CXX_FLAGS} -fgpu-rdc")
41-
42-
o2_add_executable(gpu-memory-benchmark-hip
43-
SOURCES benchmark.cxx
44-
hip/Kernels.hip.cxx
45-
PUBLIC_LINK_LIBRARIES hip::host
46-
Boost::program_options
47-
ROOT::Tree
48-
TARGETVARNAME targetName)
49-
50-
if(HIP_AMDGPUTARGET)
51-
# Need to add gpu target also to link flags due to gpu-rdc option
52-
target_link_options(${targetName} PUBLIC --amdgpu-target=${HIP_AMDGPUTARGET})
53-
endif()
54-
endif()
17+
add_subdirectory(hip)
5518
endif()
5619

57-
o2_add_test_root_macro(macro/showBenchmarks.C)
20+
o2_add_test_root_macro(macro/showBenchmarks.C)

GPU/GPUbenchmark/Shared/Kernels.h

Lines changed: 19 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ namespace o2
2727
namespace benchmark
2828
{
2929

30-
template <class chunk_type>
30+
template <class chunk_t>
3131
class GPUbenchmark final
3232
{
3333
public:
@@ -41,13 +41,22 @@ class GPUbenchmark final
4141

4242
// Single stream synchronous (sequential kernels) execution
4343
template <typename... T>
44-
float benchmarkSync(void (*kernel)(T...),
45-
int nLaunches, int blocks, int threads, T&... args);
44+
float runSequential(void (*kernel)(chunk_t*, size_t, T...),
45+
std::pair<int, int>& chunkRanges,
46+
int nLaunches,
47+
int dimGrid,
48+
int dimBlock,
49+
T&... args);
4650

4751
// Multi-streams asynchronous executions on whole memory
4852
template <typename... T>
49-
std::vector<float> benchmarkAsync(void (*kernel)(int, T...),
50-
int nStreams, int nLaunches, int blocks, int threads, T&... args);
53+
std::vector<float> runConcurrent(void (*kernel)(chunk_t*, size_t, T...),
54+
std::vector<std::pair<int, int>>& chunkRanges,
55+
int nLaunches,
56+
int dimStreams,
57+
int nBlocks,
58+
int nThreads,
59+
T&... args);
5160

5261
// Main interface
5362
void globalInit(); // Allocate scratch buffers and compute runtime parameters
@@ -56,27 +65,14 @@ class GPUbenchmark final
5665
void printDevices(); // Dump info
5766

5867
// Initializations/Finalizations of tests. Not to be measured, in principle used for report
59-
void readInit();
60-
void readFinalize();
68+
void initTest(Test);
69+
void finalizeTest(Test);
6170

62-
void writeInit();
63-
void writeFinalize();
64-
65-
void copyInit();
66-
void copyFinalize();
67-
68-
// Kernel calling wrappers
69-
void readSequential(SplitLevel sl);
70-
void readConcurrent(SplitLevel sl, int nRegions = 2);
71-
72-
void writeSequential(SplitLevel sl);
73-
void writeConcurrent(SplitLevel sl, int nRegions = 2);
74-
75-
void copySequential(SplitLevel sl);
76-
void copyConcurrent(SplitLevel sl, int nRegions = 2);
71+
// Kernel calling wrapper
72+
void runTest(Test, Mode, KernelConfig);
7773

7874
private:
79-
gpuState<chunk_type> mState;
75+
gpuState<chunk_t> mState;
8076
std::shared_ptr<ResultWriter> mResultWriter;
8177
benchmarkOpts mOptions;
8278
};

0 commit comments

Comments
 (0)