Project
Loading...
Searching...
No Matches
GPUReconstructionDeviceBase.cxx
Go to the documentation of this file.
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
14
17
18#include "GPUTPCTracker.h"
19#include "GPUTPCSectorOutput.h"
20
21using namespace o2::gpu;
22
23#if defined(_WIN32)
24#include "../utils/pthread_mutex_win32_wrapper.h"
25#else
26#include <cerrno>
27#include <unistd.h>
28#endif
29#include <cstring>
30
31class GPUTPCRow;
32
33#define SemLockName "AliceHLTTPCGPUTrackerInitLockSem"
34
36{
37 if (sizeCheck != sizeof(GPUReconstructionDeviceBase)) {
38 GPUFatal("Mismatch of C++ object size between GPU compilers!");
39 }
40}
41
43
45{
46#ifdef _WIN32
47 HANDLE* semLock = new HANDLE;
48 *semLock = CreateSemaphore(nullptr, 1, 1, SemLockName);
49 if (*semLock == nullptr) {
50 GPUError("Error creating GPUInit Semaphore");
51 return (1);
52 }
53 WaitForSingleObject(*semLock, INFINITE);
54#elif !defined(__APPLE__) // GPU not supported on MacOS anyway
55 sem_t* semLock = sem_open(SemLockName, O_CREAT, 0x01B6, 1);
56 if (semLock == SEM_FAILED) {
57 GPUError("Error creating GPUInit Semaphore");
58 return (1);
59 }
60 timespec semtime;
61 clock_gettime(CLOCK_REALTIME, &semtime);
62 semtime.tv_sec += 10;
63 while (sem_timedwait(semLock, &semtime) != 0) {
64 GPUError("Global Lock for GPU initialisation was not released for 10 seconds, assuming another thread died");
65 GPUWarning("Resetting the global lock");
66 sem_post(semLock);
67 }
68#else
69 void* semLock = nullptr;
70#endif
71 pLock = semLock;
72 return 0;
73}
74
76{
77// Release the global named semaphore that locks GPU Initialization
78#ifdef _WIN32
79 HANDLE* h = (HANDLE*)sem;
80 ReleaseSemaphore(*h, 1, nullptr);
81 CloseHandle(*h);
82 delete h;
83#elif !defined(__APPLE__) // GPU not supported on MacOS anyway
84 sem_t* pSem = (sem_t*)sem;
85 sem_post(pSem);
86 sem_unlink(SemLockName);
87#endif
88}
89
91{
92 // cpu_set_t mask;
93 // CPU_ZERO(&mask);
94 // CPU_SET(0, &mask);
95 // sched_setaffinity(0, sizeof(mask), &mask);
96
97 if (mProcessingSettings.memoryAllocationStrategy == GPUMemoryResource::ALLOCATION_INDIVIDUAL) {
98 GPUError("Individual memory allocation strategy unsupported for device\n");
99 return (1);
100 }
101 if (mProcessingSettings.nStreams > GPUCA_MAX_STREAMS) {
102 GPUError("Too many straems requested %d > %d\n", mProcessingSettings.nStreams, GPUCA_MAX_STREAMS);
103 return (1);
104 }
105
106 void* semLock = nullptr;
107 if (mProcessingSettings.globalInitMutex && GetGlobalLock(semLock)) {
108 return (1);
109 }
110
111 if (mProcessingSettings.deviceTimers) {
113 }
114
115 int32_t retVal = InitDevice_Runtime();
116 if (retVal) {
117 GPUImportant("GPU Tracker initialization failed");
118 return (1);
119 }
120
121 if (mProcessingSettings.globalInitMutex) {
122 ReleaseGlobalLock(semLock);
123 }
124
128
132
133 if (mMaster == nullptr || mProcessingSettings.debugLevel >= 2) {
134 GPUInfo("GPU Tracker initialization successfull"); // Verbosity reduced because GPU backend will print GPUImportant message!
135 }
136
137 return (retVal);
138}
139
140void* GPUReconstructionDeviceBase::GPUProcessorProcessors::SetPointersDeviceProcessor(void* mem)
141{
142 // Don't run constructor / destructor here, this will be just local memcopy of Processors in GPU Memory
144 return mem;
145}
146
156
158{
159 return IsGPU();
160}
161
163{
164 return IsGPU();
165}
166
174
176{
177 auto& list = getDeviceConstantMemRegistratorsVector();
178 for (uint32_t i = 0; i < list.size(); i++) {
179 mDeviceConstantMemList.emplace_back(list[i]());
180 }
181}
182
183size_t GPUReconstructionDeviceBase::TransferMemoryInternal(GPUMemoryResource* res, int32_t stream, deviceEvent* ev, deviceEvent* evList, int32_t nEvents, bool toGPU, const void* src, void* dst)
184{
185 if (!(res->Type() & GPUMemoryResource::MEMORY_GPU)) {
186 if (mProcessingSettings.debugLevel >= 4) {
187 GPUInfo("Skipped transfer of non-GPU memory resource: %s", res->Name());
188 }
189 return 0;
190 }
191 if (mProcessingSettings.debugLevel >= 3 && (strcmp(res->Name(), "ErrorCodes") || mProcessingSettings.debugLevel >= 4)) {
192 GPUInfo("Copying to %s: %s - %ld bytes", toGPU ? "GPU" : "Host", res->Name(), (int64_t)res->Size());
193 }
194 return GPUMemCpy(dst, src, res->Size(), stream, toGPU, ev, evList, nEvents);
195}
int32_t i
#define GPUCA_MAX_STREAMS
#define SemLockName
int32_t retVal
uint32_t res
Definition RawData.h:0
TBranch * ptr
Class for time synchronization of RawReader instances.
static void computePointerWithAlignment(T *&basePtr, S *&objPtr, size_t nEntries=1)
void InitGPUProcessor(GPUReconstruction *rec, ProcessorType type=PROCESSOR_TYPE_CPU, GPUProcessor *slaveProcessor=nullptr)
virtual 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)
int32_t unregisterMemoryForGPU_internal(const void *ptr) override
virtual int32_t InitDevice_Runtime()=0
size_t TransferMemoryInternal(GPUMemoryResource *res, int32_t stream, deviceEvent *ev, deviceEvent *evList, int32_t nEvents, bool toGPU, const void *src, void *dst) override
GPUReconstructionDeviceBase(const GPUSettingsDeviceBackend &cfg, size_t sizeCheck)
int32_t registerMemoryForGPU_internal(const void *ptr, size_t size) override
int32_t unregisterMemoryForGPU_internal(const void *ptr) override
std::unordered_set< const void * > mRegisteredMemoryPtrs
GPUSettingsProcessing mProcessingSettings
int16_t RegisterMemoryAllocation(T *proc, void *(T::*setPtr)(void *), int32_t type, const char *name="", const GPUMemoryReuse &re=GPUMemoryReuse())
void ClearAllocatedMemory(bool clearOutputs=true)
size_t AllocateRegisteredMemory(GPUProcessor *proc, bool resetCustom=false)
GLenum src
Definition glcorearb.h:1767
GLsizeiptr size
Definition glcorearb.h:659
GLenum GLenum dst
Definition glcorearb.h:1767
GLuint GLuint stream
Definition glcorearb.h:1806
Definition list.h:40
const int nEvents
Definition test_Fifo.cxx:27