Project
Loading...
Searching...
No Matches
GPUReconstructionCPUDevice.h
Go to the documentation of this file.
1// Copyright 2019-2026 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
14
15#ifndef GPURECONSTRUCTIONCPUDEVICE_H
16#define GPURECONSTRUCTIONCPUDEVICE_H
17
19#include <functional>
20#include <string>
21#include <vector>
22
23#ifdef _WIN32
25#else
27#endif
28
29namespace o2::gpu
30{
31struct GPUReconstructionCPUDeviceInternals;
32struct GPUReconstructionCPUDeviceEvent;
33
34// Backend which runs on the host, but behaves like a GPU device: It has a separate device memory region with explicit memcopies,
35// and multiple in-order command queues (streams) which are processed asynchronously by TBB. One device block is one TBB task,
36// the number of device threads per block is fixed to 1, such that the normal CPU kernels can be used.
37class GPUReconstructionCPUDevice : public GPUReconstructionProcessing::KernelInterface<GPUReconstructionCPUDevice, GPUReconstructionDeviceBase>
38{
39 public:
42
43 template <class T, int32_t I = 0, typename... Args>
44 void runKernelBackend(const krnlSetupTime& _xyz, const Args&... args);
45
46 protected:
47 int32_t InitDevice_Runtime() override;
48 int32_t ExitDevice_Runtime() override;
49
50 int32_t GPUChkErrInternal(const int64_t retval, const char* file, int32_t line) const override;
51
52 void SynchronizeGPU() override;
53 int32_t GPUDebug(const char* state = "UNKNOWN", int32_t stream = -1, bool force = false) override;
54 void SynchronizeStream(int32_t stream) override;
55 void SynchronizeEvents(deviceEvent* evList, int32_t nEvents = 1) override;
56 void StreamWaitForEvents(int32_t stream, deviceEvent* evList, int32_t nEvents = 1) override;
57 bool IsEventDone(deviceEvent* evList, int32_t nEvents = 1) override;
58 int32_t registerMemoryForGPU_internal(const void* ptr, size_t size) override { return 0; }
59 int32_t unregisterMemoryForGPU_internal(const void* ptr) override { return 0; }
60
61 size_t WriteToConstantMemory(size_t offset, const void* src, size_t size, int32_t stream = -1, deviceEvent* ev = nullptr) override;
62 size_t GPUMemCpy(void* dst, const void* src, size_t size, int32_t stream, int32_t toGPU, deviceEvent* ev = nullptr, deviceEvent* evList = nullptr, int32_t nEvents = 1) override;
63 void ReleaseEvent(deviceEvent ev) override {}
64 void RecordMarker(deviceEvent* ev, int32_t stream) override;
65
67
68 private:
69 // Enqueue a task into the command queue of the stream, which waits for evList, runs work, and then marks ev as completed
70 void EnqueueTask(int32_t stream, deviceEvent* evList, int32_t nEvents, deviceEvent* ev, std::function<void()>&& work);
71 static GPUReconstructionCPUDeviceEvent* getEvent(deviceEvent& ev);
72 std::vector<std::vector<GPUReconstructionCPUDeviceEvent>> mEventStorage; // Backs the deviceEvents in mEvents, inner vectors are never resized
73
74 int32_t genRTC(std::string& filename, uint32_t& nCompile);
75 void getRTCKernelCalls(std::vector<std::string>& kernels);
76 void genAndLoadRTC();
77};
78
79} // namespace o2::gpu
80
81#endif
o2::gpu::GPUReconstruction * GPUReconstruction_Create_CPUDEVICE(const o2::gpu::GPUSettingsDeviceBackend &cfg)
SurfaceTrackState state
TBranch * ptr
int32_t GPUChkErrInternal(const int64_t retval, const char *file, int32_t line) const override
void StreamWaitForEvents(int32_t stream, deviceEvent *evList, int32_t nEvents=1) override
int32_t GPUDebug(const char *state="UNKNOWN", int32_t stream=-1, bool force=false) override
int32_t unregisterMemoryForGPU_internal(const void *ptr) override
size_t WriteToConstantMemory(size_t offset, const void *src, size_t size, int32_t stream=-1, deviceEvent *ev=nullptr) override
void runKernelBackend(const krnlSetupTime &_xyz, const Args &... args)
void RecordMarker(deviceEvent *ev, int32_t stream) override
size_t GPUMemCpy(void *dst, const void *src, size_t size, int32_t stream, int32_t toGPU, deviceEvent *ev=nullptr, deviceEvent *evList=nullptr, int32_t nEvents=1) override
GPUReconstructionCPUDeviceInternals * mInternals
int32_t registerMemoryForGPU_internal(const void *ptr, size_t size) override
void SynchronizeEvents(deviceEvent *evList, int32_t nEvents=1) override
bool IsEventDone(deviceEvent *evList, int32_t nEvents=1) override
gpu_reconstruction_kernels::deviceEvent deviceEvent
GLenum src
Definition glcorearb.h:1767
GLsizeiptr size
Definition glcorearb.h:659
GLenum GLenum dst
Definition glcorearb.h:1767
GLintptr offset
Definition glcorearb.h:660
GLuint GLuint stream
Definition glcorearb.h:1806
std::string filename()
const int nEvents
Definition test_Fifo.cxx:27