Skip to content

Commit d9b654e

Browse files
committed
GPU: Add getThrustVolatileDeviceAllocator function
1 parent c2aa2f5 commit d9b654e

12 files changed

+47
-52
lines changed

GPU/Common/GPUCommonHelpers.h

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
#include "GPUCommonDef.h"
3636
#include "GPUCommonLogger.h"
3737
#include <cstdint>
38+
#include <functional>
3839

3940
namespace o2::gpu::internal
4041
{
@@ -60,4 +61,22 @@ static inline int32_t GPUReconstructionChkErr(const int64_t error, const char* f
6061
#undef GPUCOMMON_INTERNAL_CAT
6162
} // namespace o2::gpu::internal
6263

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

GPU/GPUTracking/Base/GPUReconstruction.cxx

Lines changed: 10 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,12 @@ void GPUReconstruction::SetInputControl(void* ptr, size_t size)
11931194
{
11941195
mInputControl.set(ptr, size);
11951196
}
1197+
1198+
ThrustVolatileAllocator::ThrustVolatileAllocator(GPUReconstruction* r)
1199+
{
1200+
mAlloc = [&r](size_t n) { return (char*)r->AllocateVolatileDeviceMemory(n); };
1201+
}
1202+
ThrustVolatileAllocator GPUReconstruction::getThrustVolatileDeviceAllocator()
1203+
{
1204+
return ThrustVolatileAllocator(this);
1205+
}

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 mAlloc(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: 2 additions & 2 deletions
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})
@@ -63,7 +63,7 @@ endif()
6363

6464
set(SRCS ${GPUCA_HIP_SOURCE_DIR}/GPUReconstructionHIP.hip ${GPUCA_HIP_SOURCE_DIR}/GPUReconstructionHIPKernels.hip)
6565
set(SRCS_CXX ${GPUCA_HIP_SOURCE_DIR}/GPUReconstructionHIPGenRTC.cxx)
66-
set(HDRS ${GPUCA_HIP_SOURCE_DIR}/GPUReconstructionHIP.h ${GPUCA_HIP_SOURCE_DIR}/GPUReconstructionHIPInternals.h ${GPUCA_HIP_SOURCE_DIR}/GPUReconstructionHIPHelpers.inc ${GPUCA_HIP_SOURCE_DIR}/GPUReconstructionHIPDef.h ${GPUCA_HIP_SOURCE_DIR}/GPUReconstructionHIPIncludesHost.h ${GPUCA_HIP_SOURCE_DIR}/HIPThrustHelpers.h)
66+
set(HDRS ${GPUCA_HIP_SOURCE_DIR}/GPUReconstructionHIP.h ${GPUCA_HIP_SOURCE_DIR}/GPUReconstructionHIPInternals.h ${GPUCA_HIP_SOURCE_DIR}/GPUReconstructionHIPHelpers.inc ${GPUCA_HIP_SOURCE_DIR}/GPUReconstructionHIPDef.h ${GPUCA_HIP_SOURCE_DIR}/GPUReconstructionHIPIncludesHost.h)
6767

6868
# -------------------------------- Prepare RTC -------------------------------------------------------
6969
enable_language(ASM)

0 commit comments

Comments
 (0)