Skip to content

Commit 6455bcb

Browse files
committed
GPU: Make GPUDefParamters available as C++ struct at runtime
1 parent 78d0f9c commit 6455bcb

12 files changed

+422
-38
lines changed

GPU/GPUTracking/Base/GPUReconstructionProcessing.cxx

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,31 @@
1414

1515
#include "GPUReconstructionProcessing.h"
1616
#include "GPUReconstructionThreading.h"
17+
#include "GPUDefParametersDefault.h"
18+
#include "GPUDefParametersLoad.inc"
1719

1820
using namespace o2::gpu;
1921

22+
GPUReconstructionProcessing::GPUReconstructionProcessing(const GPUSettingsDeviceBackend& cfg) : GPUReconstruction(cfg)
23+
{
24+
if (mMaster == nullptr) {
25+
mParCPU = new GPUDefParameters(o2::gpu::internal::GPUDefParametersLoad());
26+
mParDevice = new GPUDefParameters();
27+
} else {
28+
GPUReconstructionProcessing* master = dynamic_cast<GPUReconstructionProcessing*>(mMaster);
29+
mParCPU = master->mParCPU;
30+
mParDevice = master->mParDevice;
31+
}
32+
}
33+
34+
GPUReconstructionProcessing::~GPUReconstructionProcessing()
35+
{
36+
if (mMaster == nullptr) {
37+
delete mParCPU;
38+
delete mParDevice;
39+
}
40+
}
41+
2042
int32_t GPUReconstructionProcessing::getNKernelHostThreads(bool splitCores)
2143
{
2244
int32_t nThreads = 0;

GPU/GPUTracking/Base/GPUReconstructionProcessing.h

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525
namespace o2::gpu
2626
{
2727

28+
struct GPUDefParameters;
29+
2830
namespace gpu_reconstruction_kernels
2931
{
3032
struct deviceEvent {
@@ -63,7 +65,7 @@ class threadContext
6365
class GPUReconstructionProcessing : public GPUReconstruction
6466
{
6567
public:
66-
~GPUReconstructionProcessing() override = default;
68+
~GPUReconstructionProcessing() override;
6769

6870
// Threading
6971
int32_t getNKernelHostThreads(bool splitCores);
@@ -101,7 +103,7 @@ class GPUReconstructionProcessing : public GPUReconstruction
101103
};
102104

103105
protected:
104-
GPUReconstructionProcessing(const GPUSettingsDeviceBackend& cfg) : GPUReconstruction(cfg) {}
106+
GPUReconstructionProcessing(const GPUSettingsDeviceBackend& cfg);
105107
using deviceEvent = gpu_reconstruction_kernels::deviceEvent;
106108

107109
static const std::vector<std::string> mKernelNames;
@@ -132,6 +134,9 @@ class GPUReconstructionProcessing : public GPUReconstruction
132134
template <class T, int32_t J = -1>
133135
HighResTimer& getTimer(const char* name, int32_t num = -1);
134136

137+
GPUDefParameters* mParCPU = nullptr;
138+
GPUDefParameters* mParDevice = nullptr;
139+
135140
private:
136141
uint32_t getNextTimerId();
137142
timerMeta* getTimerById(uint32_t id, bool increment = true);

GPU/GPUTracking/Base/cuda/GPUReconstructionCUDA.cu

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,15 +47,21 @@ __global__ void dummyInitKernel(void*) {}
4747

4848
#include "GPUReconstructionIncludesITS.h"
4949

50+
#include "GPUDefParametersDefault.h"
51+
#include "GPUDefParametersLoad.inc"
52+
5053
GPUReconstructionCUDABackend::GPUReconstructionCUDABackend(const GPUSettingsDeviceBackend& cfg) : GPUReconstructionDeviceBase(cfg, sizeof(GPUReconstructionDeviceBase))
5154
{
5255
if (mMaster == nullptr) {
5356
mInternals = new GPUReconstructionCUDAInternals;
57+
*mParDevice = o2::gpu::internal::GPUDefParametersLoad();
5458
}
59+
mDeviceBackendSettings.deviceType = DeviceType::CUDA;
5560
}
5661

5762
GPUReconstructionCUDABackend::~GPUReconstructionCUDABackend()
5863
{
64+
Exit(); // Make sure we destroy everything (in particular the ITS tracker) before we exit CUDA
5965
if (mMaster == nullptr) {
6066
delete mInternals;
6167
}
@@ -69,7 +75,6 @@ int32_t GPUReconstructionCUDABackend::GPUChkErrInternal(const int64_t error, con
6975

7076
GPUReconstructionCUDA::GPUReconstructionCUDA(const GPUSettingsDeviceBackend& cfg) : GPUReconstructionKernels(cfg)
7177
{
72-
mDeviceBackendSettings.deviceType = DeviceType::CUDA;
7378
#ifndef __HIPCC__ // CUDA
7479
mRtcSrcExtension = ".cu";
7580
mRtcBinExtension = ".fatbin";
@@ -78,11 +83,7 @@ GPUReconstructionCUDA::GPUReconstructionCUDA(const GPUSettingsDeviceBackend& cfg
7883
mRtcBinExtension = ".o";
7984
#endif
8085
}
81-
82-
GPUReconstructionCUDA::~GPUReconstructionCUDA()
83-
{
84-
Exit(); // Make sure we destroy everything (in particular the ITS tracker) before we exit CUDA
85-
}
86+
GPUReconstructionCUDA::~GPUReconstructionCUDA() {}
8687

8788
GPUReconstruction* GPUReconstruction_Create_CUDA(const GPUSettingsDeviceBackend& cfg) { return new GPUReconstructionCUDA(cfg); }
8889

GPU/GPUTracking/Base/opencl/GPUReconstructionOCL.cxx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@
1414

1515
#include "GPUReconstructionOCLIncludesHost.h"
1616

17+
#include "GPUDefParametersDefault.h"
18+
#include "GPUDefParametersLoad.inc"
19+
1720
#include <map>
1821

1922
static_assert(std::is_convertible<cl_event, void*>::value, "OpenCL event type incompatible to deviceEvent");
@@ -36,6 +39,7 @@ GPUReconstructionOCLBackend::GPUReconstructionOCLBackend(const GPUSettingsDevice
3639
{
3740
if (mMaster == nullptr) {
3841
mInternals = new GPUReconstructionOCLInternals;
42+
*mParDevice = o2::gpu::internal::GPUDefParametersLoad();
3943
}
4044
mDeviceBackendSettings.deviceType = DeviceType::OCL;
4145
}

GPU/GPUTracking/CMakeLists.txt

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ set(HDRS_INSTALL
128128
DataTypes/GPUTriggerOutputs.h
129129
Debug/GPUROOTDump.h
130130
Definitions/GPUDefConstantsAndSettings.h
131-
Definitions/GPUDefGPUParameters.h
131+
Definitions/GPUDefParametersDefault.h
132132
Definitions/GPUDef.h
133133
Definitions/GPUDefMacros.h
134134
Definitions/GPULogging.h
@@ -246,10 +246,18 @@ file(GENERATE
246246
OUTPUT include_gpu_onthefly/GPUNoFastMathKernels.h
247247
INPUT cmake/GPUNoFastMathKernels.template.h
248248
)
249+
file(GENERATE
250+
OUTPUT include_gpu_onthefly/GPUDefParameters.h
251+
INPUT Definitions/GPUDefParameters.template.h
252+
)
253+
file(GENERATE
254+
OUTPUT include_gpu_onthefly/GPUDefParametersLoad.inc
255+
INPUT Definitions/GPUDefParametersLoad.template.inc
256+
)
249257
if(NOT ALIGPU_BUILD_TYPE STREQUAL "O2")
250258
include_directories(${CMAKE_CURRENT_BINARY_DIR}/include_gpu_onthefly)
251259
endif()
252-
set(HDRS_INSTALL ${HDRS_INSTALL} ${CMAKE_CURRENT_BINARY_DIR}/include_gpu_onthefly/GPUReconstructionKernelList.h)
260+
set(HDRS_INSTALL ${HDRS_INSTALL} ${CMAKE_CURRENT_BINARY_DIR}/include_gpu_onthefly/GPUReconstructionKernelList.h ${CMAKE_CURRENT_BINARY_DIR}/include_gpu_onthefly/GPUDefParameters.h)
253261
include(kernels.cmake)
254262

255263
# Optional sources depending on optional dependencies

GPU/GPUTracking/Definitions/GPUDef.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
#include "GPUCommonDef.h"
2020
#include "GPUDefConstantsAndSettings.h"
21-
#include "GPUDefGPUParameters.h"
21+
#include "GPUDefParametersDefault.h"
2222
#include "GPUCommonRtypes.h"
2323

2424
// Macros for masking ptrs in OpenCL kernel calls as uint64_t (The API only allows us to pass buffer objects)

GPU/GPUTracking/Definitions/GPUDefConstantsAndSettings.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
/// \author David Rohr
1414

1515
// This files contains compile-time constants affecting the GPU algorithms / reconstruction results.
16-
// Architecture-dependant compile-time constants affecting the performance without changing the results are stored in GPUDefGPUParameters.h
16+
// Architecture-dependant compile-time constants affecting the performance without changing the results are stored in GPUDefParameters.h
1717

1818
#ifndef GPUDEFCONSTANTSANDSETTINGS_H
1919
#define GPUDEFCONSTANTSANDSETTINGS_H
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
2+
// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
3+
// All rights not expressly granted are reserved.
4+
//
5+
// This software is distributed under the terms of the GNU General Public
6+
// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
7+
//
8+
// In applying this license CERN does not waive the privileges and immunities
9+
// granted to it by virtue of its status as an Intergovernmental Organization
10+
// or submit itself to any jurisdiction.
11+
12+
/// \file GPUDefParameters.h
13+
/// \author David Rohr
14+
15+
#ifndef GPUDEFPARAMETERS_H
16+
#define GPUDEFPARAMETERS_H
17+
18+
namespace o2::gpu
19+
{
20+
struct GPUDefParameters { // clang-format off
21+
$<JOIN:$<LIST:TRANSFORM,$<LIST:TRANSFORM,$<LIST:TRANSFORM,$<TARGET_PROPERTY:O2_GPU_KERNELS,O2_GPU_KERNEL_NAMES>,REPLACE,[^A-Za-z0-9]+,_>,PREPEND,int32_t parLB_>,APPEND,_1 = -1>,;
22+
>;
23+
$<JOIN:$<LIST:TRANSFORM,$<LIST:TRANSFORM,$<LIST:TRANSFORM,$<TARGET_PROPERTY:O2_GPU_KERNELS,O2_GPU_KERNEL_NAMES>,REPLACE,[^A-Za-z0-9]+,_>,PREPEND,int32_t parLB_>,APPEND,_2 = -1>,;
24+
>;
25+
}; // clang-format on
26+
} // namespace o2::gpu
27+
28+
#endif

0 commit comments

Comments
 (0)