Project
Loading...
Searching...
No Matches
GPUTPCSectorOutput.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
15#include "GPUOutputControl.h"
16#include "GPUTPCSectorOutput.h"
17#include "GPUCommonMath.h"
18#include <atomic>
19
20using namespace o2::gpu;
21
22uint32_t GPUTPCSectorOutput::EstimateSize(uint32_t nOfTracks, uint32_t nOfTrackClusters)
23{
24 // calculate the amount of memory [bytes] needed for the event
25 return sizeof(GPUTPCSectorOutput) + sizeof(GPUTPCTrack) * nOfTracks + sizeof(GPUTPCSectorOutCluster) * nOfTrackClusters;
26}
27
28#ifndef GPUCA_GPUCODE
29void GPUTPCSectorOutput::Allocate(GPUTPCSectorOutput*& ptrOutput, int32_t nTracks, int32_t nTrackHits, GPUOutputControl* outputControl, void*& internalMemory)
30{
31 // Allocate All memory needed for sector output
32 const size_t memsize = EstimateSize(nTracks, nTrackHits);
33
34 if (outputControl && outputControl->useExternal()) {
35 static std::atomic_flag lock = ATOMIC_FLAG_INIT;
36 while (lock.test_and_set(std::memory_order_acquire)) {
37 }
38 outputControl->checkCurrent();
39 if (outputControl->size - ((char*)outputControl->ptrCurrent - (char*)outputControl->ptrBase) < memsize) {
40 outputControl->size = 1;
41 ptrOutput = nullptr;
42 lock.clear(std::memory_order_release);
43 return;
44 }
45 ptrOutput = reinterpret_cast<GPUTPCSectorOutput*>(outputControl->ptrCurrent);
46 outputControl->ptrCurrent = (char*)outputControl->ptrCurrent + memsize;
47 lock.clear(std::memory_order_release);
48 } else {
49 if (internalMemory) {
50 free(internalMemory);
51 }
52 internalMemory = malloc(memsize);
53 ptrOutput = reinterpret_cast<GPUTPCSectorOutput*>(internalMemory);
54 }
55 ptrOutput->SetMemorySize(memsize);
56}
57#endif
static uint32_t EstimateSize(uint32_t nOfTracks, uint32_t nOfTrackClusters)
static void Allocate(GPUTPCSectorOutput *&ptrOutput, int32_t nTracks, int32_t nTrackHits, GPUOutputControl *outputControl, void *&internalMemory)