Skip to content

Commit c776054

Browse files
committed
GPU: Add getThrustVolatileDeviceAllocator function
1 parent b268465 commit c776054

12 files changed

+42
-51
lines changed

GPU/Common/GPUCommonHelpers.h

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,4 +60,22 @@ static inline int32_t GPUReconstructionChkErr(const int64_t error, const char* f
6060
#undef GPUCOMMON_INTERNAL_CAT
6161
} // namespace o2::gpu::internal
6262

63+
namespace o2::gpu
64+
{
65+
class GPUReconstruction;
66+
class ThrustVolatileAllocator
67+
{
68+
public:
69+
typedef char value_type;
70+
71+
char* allocate(std::ptrdiff_t n);
72+
void deallocate(char* ptr, size_t);
73+
74+
private:
75+
ThrustVolatileAllocator(GPUReconstruction* r);
76+
GPUReconstruction* mRec;
77+
friend class GPUReconstruction;
78+
};
79+
} // namespace o2::gpu
80+
6381
#endif

GPU/GPUTracking/Base/GPUReconstruction.cxx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
#include "GPUROOTDumpCore.h"
3131
#include "GPUConfigDump.h"
3232
#include "GPUChainTracking.h"
33+
#include "GPUCommonHelpers.h"
3334

3435
#include "GPUMemoryResource.h"
3536
#include "GPUChain.h"
@@ -1193,3 +1194,9 @@ void GPUReconstruction::SetInputControl(void* ptr, size_t size)
11931194
{
11941195
mInputControl.set(ptr, size);
11951196
}
1197+
1198+
ThrustVolatileAllocator::ThrustVolatileAllocator(GPUReconstruction* r) : mRec(r) {}
1199+
ThrustVolatileAllocator GPUReconstruction::getThrustVolatileDeviceAllocator()
1200+
{
1201+
return ThrustVolatileAllocator(this);
1202+
}

GPU/GPUTracking/Base/GPUReconstruction.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ struct GPUMemorySizeScalers;
4747
struct GPUReconstructionPipelineContext;
4848
struct GPUReconstructionThreading;
4949
class GPUROOTDumpCore;
50+
class ThrustVolatileAllocator;
5051

5152
namespace gpu_reconstruction_kernels
5253
{
@@ -165,6 +166,7 @@ class GPUReconstruction
165166
void ClearAllocatedMemory(bool clearOutputs = true);
166167
void ReturnVolatileDeviceMemory();
167168
void ReturnVolatileMemory();
169+
ThrustVolatileAllocator getThrustVolatileDeviceAllocator();
168170
void PushNonPersistentMemory(uint64_t tag);
169171
void PopNonPersistentMemory(RecoStep step, uint64_t tag);
170172
void BlockStackedMemory(GPUReconstruction* rec);

GPU/GPUTracking/Base/cuda/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ endif()
1818
message(STATUS "Building GPUTracking with CUDA support ${TMP_TARGET}")
1919

2020
set(SRCS GPUReconstructionCUDA.cu GPUReconstructionCUDAGenRTC.cxx GPUReconstructionCUDAKernels.cu)
21-
set(HDRS GPUReconstructionCUDA.h GPUReconstructionCUDAInternals.h GPUReconstructionCUDAHelpers.inc GPUReconstructionCUDADef.h GPUReconstructionCUDAIncludesHost.h CUDAThrustHelpers.h)
21+
set(HDRS GPUReconstructionCUDA.h GPUReconstructionCUDAInternals.h GPUReconstructionCUDAHelpers.inc GPUReconstructionCUDADef.h GPUReconstructionCUDAIncludesHost.h)
2222
# -------------------------------- Prepare RTC -------------------------------------------------------
2323
enable_language(ASM)
2424
if(ALIGPU_BUILD_TYPE STREQUAL "O2")

GPU/GPUTracking/Base/cuda/CUDAThrustHelpers.h

Lines changed: 0 additions & 41 deletions
This file was deleted.

GPU/GPUTracking/Base/cuda/GPUReconstructionCUDA.cu

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919

2020
#include "GPUReconstructionCUDA.h"
2121
#include "GPUReconstructionCUDAInternals.h"
22-
#include "CUDAThrustHelpers.h"
2322
#include "GPUReconstructionIncludes.h"
2423
#include "GPUParamRTC.h"
2524
#include "GPUReconstructionCUDAHelpers.inc"

GPU/GPUTracking/Base/cuda/GPUReconstructionCUDAExternalProvider.cu

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616

1717
#include "GPUReconstructionCUDA.h"
1818
#include "GPUReconstructionCUDAInternals.h"
19-
#include "CUDAThrustHelpers.h"
2019

2120
#include <stdexcept>
2221

GPU/GPUTracking/Base/cuda/GPUReconstructionCUDAHelpers.inc

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#define GPURECONSTRUCTIONCUDAHELPERS_INC_H
1717

1818
#include "GPUCommonHelpers.h"
19+
#include "GPUReconstruction.h"
1920

2021
namespace o2::gpu::internal
2122
{
@@ -28,4 +29,10 @@ int32_t __attribute__((weak)) GPUReconstructionCUDAChkErr(const int64_t error, c
2829
}
2930
} // namespace o2::gpu::internal
3031

32+
namespace o2::gpu
33+
{
34+
char* __attribute__((weak)) ThrustVolatileAllocator::allocate(std::ptrdiff_t n) { return (char*)mRec->AllocateVolatileDeviceMemory(n); }
35+
void __attribute__((weak)) ThrustVolatileAllocator::deallocate(char* ptr, size_t) {}
36+
} // namespace o2::gpu
37+
3138
#endif

GPU/GPUTracking/Base/cuda/GPUReconstructionCUDAKernels.cu

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616

1717
#include "GPUReconstructionCUDA.h"
1818
#include "GPUReconstructionCUDAInternals.h"
19-
#include "CUDAThrustHelpers.h"
2019

2120
using namespace o2::gpu;
2221

GPU/GPUTracking/Base/hip/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ message(STATUS "Building GPUTracking with HIP support ${TMP_TARGET}")
2424
if(NOT DEFINED GPUCA_HIP_HIPIFY_FROM_CUDA OR "${GPUCA_HIP_HIPIFY_FROM_CUDA}")
2525
set(GPUCA_HIP_SOURCE_DIR ${CMAKE_CURRENT_BINARY_DIR}/hipify)
2626
file(MAKE_DIRECTORY ${GPUCA_HIP_SOURCE_DIR})
27-
set(GPUCA_HIP_FILE_LIST GPUReconstructionCUDA.cu GPUReconstructionCUDAExternalProvider.cu GPUReconstructionCUDA.h GPUReconstructionCUDAInternals.h GPUReconstructionCUDAHelpers.inc GPUReconstructionCUDAkernel.template.cu CUDAThrustHelpers.h GPUReconstructionCUDADef.h GPUReconstructionCUDAGenRTC.cxx GPUReconstructionCUDAKernels.cu GPUReconstructionCUDArtc.cu)
27+
set(GPUCA_HIP_FILE_LIST GPUReconstructionCUDA.cu GPUReconstructionCUDAExternalProvider.cu GPUReconstructionCUDA.h GPUReconstructionCUDAInternals.h GPUReconstructionCUDAHelpers.inc GPUReconstructionCUDAkernel.template.cu GPUReconstructionCUDADef.h GPUReconstructionCUDAGenRTC.cxx GPUReconstructionCUDAKernels.cu GPUReconstructionCUDArtc.cu)
2828
set(GPUCA_HIP_LOCAL_FILE_LIST GPUReconstructionHIPIncludesHost.h)
2929
set(HIP_SOURCES "")
3030
foreach(file ${GPUCA_HIP_FILE_LIST})

0 commit comments

Comments
 (0)