Project
Loading...
Searching...
No Matches
GPUReconstructionCPUDeviceInternals.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 GPURECONSTRUCTIONCPUDEVICEINTERNALS_H
16#define GPURECONSTRUCTIONCPUDEVICEINTERNALS_H
17
19
20#include <array>
21#include <atomic>
22#include <condition_variable>
23#include <deque>
24#include <functional>
25#include <memory>
26#include <mutex>
27#include <utility>
28#include <vector>
29
30#include <oneapi/tbb.h>
31
32namespace o2::gpu
33{
34struct GPUReconstructionCPUDeviceInternals;
35
36// Event of the CPUDevice backend. Recording a marker increments nRecorded when the marker is enqueued, the command queue sets nCompleted when the marker is processed. A wait captures the value of nRecorded at the time the wait is enqueued, so it behaves like cudaStreamWaitEvent.
43 std::mutex mutex;
44 std::condition_variable cv; // For host threads waiting for the event
45 std::vector<waitingQueue> waiting; // Suspended command queues, which are resumed when the event reaches the value
46 uint64_t nRecorded = 0;
47 uint64_t nCompleted = 0;
48};
49
50// Command in a command queue: wait for events, run the work, mark an event as completed
52 std::vector<std::pair<GPUReconstructionCPUDeviceEvent*, uint64_t>> waits;
53 uint32_t nextWait = 0;
54 std::function<void()> work;
56 uint64_t recordValue = 0;
57};
58
59// In-order command queue. It does not own a thread: When commands are enqueued, a TBB task is started which processes them, and which returns once the queue is empty, or when the next command must wait for an event. In the latter case, the queue is registered at the event,
60// and a new TBB task is started when the event completes. At most one TBB task processes a queue at a time.
62 std::mutex mutex;
63 std::condition_variable cv; // For host threads synchronizing the queue
64 std::deque<GPUReconstructionCPUDeviceTask> tasks;
65 bool active = false; // Queue has pending commands, and is either being processed by a TBB task or suspended waiting for an event
66};
67
69 std::unique_ptr<tbb::task_arena> arena;
70 std::array<GPUReconstructionCPUDeviceQueue, constants::GPU_MAX_STREAMS> queues;
71 std::atomic<int32_t> error{0}; // Set if a command in a command queue has failed
72
73 char* deviceMemory = nullptr; // "Device" memory, a separate host memory region
74 char* hostMemory = nullptr; // Host memory, corresponds to page-locked host memory of real GPUs
75 char* constantMemory = nullptr; // "Device" constant memory, holding the device copy of GPUConstantMem
76
77 std::vector<void*> rtcLibraries; // dlopen handles of RTC-compiled kernel libraries
78 std::vector<void*> rtcKernels; // RTC kernel entry points, indexed by kernel number
79
80 void enqueue(int32_t stream, GPUReconstructionCPUDeviceTask&& task);
81 void startQueue(int32_t stream);
82 void processQueue(int32_t stream);
84};
85
86} // namespace o2::gpu
87
88#endif
GLsizei const GLfloat * value
Definition glcorearb.h:819
typedef void(APIENTRYP PFNGLCULLFACEPROC)(GLenum mode)
GLuint GLuint stream
Definition glcorearb.h:1806
void enqueue(int32_t stream, GPUReconstructionCPUDeviceTask &&task)
void completeEvent(GPUReconstructionCPUDeviceEvent *e, uint64_t value)
std::array< GPUReconstructionCPUDeviceQueue, constants::GPU_MAX_STREAMS > queues
std::deque< GPUReconstructionCPUDeviceTask > tasks
std::vector< std::pair< GPUReconstructionCPUDeviceEvent *, uint64_t > > waits