16#ifndef ITSTRACKINGGPU_UTILS_H_
17#define ITSTRACKINGGPU_UTILS_H_
32#include <thrust/device_ptr.h>
34#define THRUST_NAMESPACE thrust::cuda
36#define THRUST_NAMESPACE thrust::hip
42#define GPULogSync() GPUChkErrS(hipDeviceSynchronize())
43#elif defined(__CUDACC__)
44#define GPULogSync() GPUChkErrS(cudaDeviceSynchronize())
50 LOGP(info, __VA_ARGS__); \
64template <
typename T1,
typename T2>
78 GPUd()
ref operator[](
unsigned int idx)
const {
return _data[idx]; }
117#if defined(__HIPCC__)
118 using Handle = hipStream_t;
120 static constexpr unsigned int DefaultFlag = hipStreamNonBlocking;
121 using Event = hipEvent_t;
122#elif defined(__CUDACC__)
123 using Handle = cudaStream_t;
125 static constexpr unsigned int DefaultFlag = cudaStreamNonBlocking;
126 using Event = cudaEvent_t;
136#if defined(__HIPCC__)
138 GPUChkErrS(hipEventCreateWithFlags(&mEvent, hipEventDisableTiming));
139#elif defined(__CUDACC__)
141 GPUChkErrS(cudaEventCreateWithFlags(&mEvent, cudaEventDisableTiming));
149#if defined(__HIPCC__)
152#elif defined(__CUDACC__)
165#if defined(__HIPCC__)
167#elif defined(__CUDACC__)
173#if defined(__HIPCC__)
175#elif defined(__CUDACC__)
182 Event mEvent{
nullptr};
189 size_t size() const noexcept {
return mStreams.size(); }
197#if defined(__HIPCC__)
199#elif defined(__CUDACC__)
203 for (
auto&
s : mStreams) {
210#if defined(__HIPCC__)
211 GPUChkErrS(hipStreamWaitEvent(mStreams[iStream].
get(), mStreams[iEvent].getEvent()));
212#elif defined(__CUDACC__)
213 GPUChkErrS(cudaStreamWaitEvent(mStreams[iStream].
get(), mStreams[iEvent].getEvent()));
218 std::vector<Stream> mStreams;
221#ifdef ITS_MEASURE_GPU_TIME
225 GPUTimer(
const std::string&
name)
231 GPUTimer(Streams& streams,
const std::string&
name)
234 for (
size_t i{0};
i < streams.size(); ++
i) {
235 mStreams.push_back(streams[
i].
get());
242 for (
size_t sta{
start}; sta <
end; ++sta) {
243 mStreams.push_back(streams[sta].
get());
250 mStreams.push_back(
stream.get());
256 for (
size_t i{0};
i < mStreams.size(); ++
i) {
258#if defined(__HIPCC__)
261 GPUChkErrS(hipEventElapsedTime(&ms, mStarts[
i], mStops[
i]));
264#elif defined(__CUDACC__)
267 GPUChkErrS(cudaEventElapsedTime(&ms, mStarts[
i], mStops[
i]));
271 LOGP(info,
"Elapsed time for {}:{} {} ms", mName,
i, ms);
277 mStarts.resize(mStreams.size());
278 mStops.resize(mStreams.size());
279 for (
size_t i{0};
i < mStreams.size(); ++
i) {
280#if defined(__HIPCC__)
284#elif defined(__CUDACC__)
294 std::vector<Stream::Event> mStarts, mStops;
295 std::vector<Stream::Handle> mStreams;
301 template <
typename... Args>
310struct TypedAllocator {
311 using value_type = T;
312 using pointer = thrust::device_ptr<T>;
313 using const_pointer = thrust::device_ptr<const T>;
314 using size_type = std::size_t;
315 using difference_type = std::ptrdiff_t;
317 TypedAllocator() noexcept : mInternalAllocator(
nullptr) {}
318 explicit TypedAllocator(ExternalAllocator*
a) noexcept : mInternalAllocator(
a) {}
320 template <
typename U>
321 TypedAllocator(
const TypedAllocator<U>& o) noexcept : mInternalAllocator(o.mInternalAllocator)
327 void*
raw = mInternalAllocator->allocateStack(
n *
sizeof(T));
328 return thrust::device_pointer_cast(
static_cast<T*
>(
raw));
331 void deallocate(
pointer p, size_type
n)
noexcept
336 void*
raw = thrust::raw_pointer_cast(p);
337 mInternalAllocator->deallocate(
static_cast<char*
>(
raw),
n *
sizeof(T));
340 bool operator==(TypedAllocator
const& o)
const noexcept
342 return mInternalAllocator == o.mInternalAllocator;
344 bool operator!=(TypedAllocator
const& o)
const noexcept
346 return !(*
this == o);
350 ExternalAllocator* mInternalAllocator;
355GPUdii() int deviceLowerBound(const T*
a,
int beg,
int end, const T
key)
358 const int mid = beg + (
end - beg) / 2;
370GPUdii() int deviceUpperBound(const T*
a,
int beg,
int end, const T
key)
373 const int mid = beg + (
end - beg) / 2;
383GPUdii() gpuSpan<const
Cluster> getClustersOnLayer(const
int rof,
386 const
int** roframesClus,
389 if (rof < 0 || rof >= totROFs) {
390 return gpuSpan<const Cluster>();
392 const int start_clus_id{roframesClus[
layer][rof]};
393 const int stop_rof = rof >= totROFs - 1 ? totROFs : rof + 1;
394 const unsigned int delta = roframesClus[
layer][stop_rof] - start_clus_id;
395 return gpuSpan<const Cluster>(&(
clusters[
layer][start_clus_id]), delta);
o2::raw::RawFileWriter * raw
Timeframe settings Average distance in cm of events merged into Randomize distance around average distance of merged events Simulate correct bunch interactions instead of placing only the average number of events A value[n] sets TFlen for[n] collisions in Number of bunches per trainsort Number of bunch trains Instantaneous interaction rate Do not simulate border Total number of collisions to be placed in the interior of all time Do not select random but walk over array of events in stride steps h Event generator settings h configStandalone Use CPU for GPU Force usage of the specified GPU device no CPU fallback Continue processing after an error s
configStandalone Reconstruction rec_tpc multiplier for the combined cluster track error during track following area in cm for the search of for z only used if decrease removal by when above this local occupancy rowx Shift of TPC revert cluster flag edge bit distance to edge exceeds this ZOffset for secondary multiple of radius max P of electron K BB bands crossing max P of electron p BB bands crossing max P of electron d BB bands crossing max P of electron t BB bands crossing min accepted dEdxMaxTPC of the track Additive extra cluster error for Y2 if edge flag set Additive extra cluster error for Y2 if single set Additive extra cluster error for Y2 if or single set Additive extra cluster error for Z2 if or single set Extra errors to add to track when crossing depending on addErrorsCECrossing Inner portion of y range in sector that is not used in searching for extrapolated track candidates factor2YS for track merging factor2K for track merging Margin in cm of Y position when rejecting edge clusters based on uncorrected track Y Max fraction of shared clusters for tracklet Except pad from cluster finding if total number of charges in a fragment is above this Except pad from cluster finding if number of consecutive charges in a fragment is above this Threshold where a timebin is considered disabling the noisy pad check for that pad Treat signal above this minimum as saturated Smoothing factor for the exponential Highly Ionising Particle tail filter Number of timebins to use for the averaging Add additional custom track errors when crossing relative as fraction of Do N fit passes in final fit of< 0:reject at max -n hits") AddOptionRTC(rejectIFCLowRadiusCluster, uint8_t, 1, "", 0, "Reject clusters that get the IFC mask error during refit") AddOptionRTC(dEdxTruncLow, uint8_t, 2, "", 0, "Low truncation threshold, fraction of 128") AddOptionRTC(dEdxTruncHigh, uint8_t, 77, "", 0, "High truncation threshold, fraction of 128") AddOptionRTC(extrapolationTracking, int8_t, 1, "", 0, "Enable Extrapolation Tracking(prolong tracks to adjacent sectors to find short segments)") AddOptionRTC(disableRefitAttachment, uint8_t, 0, "", 0, "Bitmask to disable certain attachment steps during refit(1:attachment, 2:propagation, 4:loop following, 8:mirroring)") AddOptionRTC(rejectionStrategy, uint8_t, o2::gpu::GPUSettings::RejectionStrategyA, "", 0, "Enable rejection of TPC clusters for compression(0=no, 1=strategy A, 2=strategy B)") AddOptionRTC(mergeLoopersAfterburner, uint8_t, 1, "", 0, "Run afterburner for additional looper merging") AddOptionRTC(compressionTypeMask, uint8_t, o2::gpu::GPUSettings::CompressionFull, "", 0, "TPC Compression mode bits(1=truncate charge/width LSB, 2=differences, 4=track-model)") AddOptionRTC(compressionSortOrder, uint8_t, o2::gpu::GPUSettings::SortTime, "", 0, "Sort order of TPC compression(0=time, 1=pad, 2=Z-time-pad, 3=Z-pad-time, 4=no sorting(use incoming order))") AddOptionRTC(sigBitsCharge, uint8_t, 4, "", 0, "Number of significant bits for TPC cluster charge in compression mode 1") AddOptionRTC(sigBitsWidth, uint8_t, 3, "", 0, "Number of significant bits for TPC cluster width in compression mode 1") AddOptionRTC(dropLoopers, uint8_t, 0, "", 0, "Drop looping tracks starting from second loop") AddOptionRTC(mergerInterpolateErrors, uint8_t, 1, "", 0, "Use interpolation instead of extrapolation for chi2 based cluster rejection") AddOptionRTC(mergerInterpolateRejectAlsoOnCurrentPosition, uint8_t, 1, "", 0, "When using mergerInterpolateErrors, reject based on chi2 twice computed with interpolated and current track position starting from NDF > mergerNonInterpolateRejectMinNDF Merge tracks accross the central electrode Enable PID response Add sub threshold clusters in TPC dEdx computation OR mask of TPC flags that will reject the cluster in alternative dEdx Reject edge clusters based on uncorrected track Y during track fit Increase decrease removal by when on this number of pads from the edge h configStandalone Reconstruction rec_trd Max chi2 for TRD tracklets to be matched to a track Chi2 cut for strict matching mode Number of sigmas for ITS TPC track time error estimate Addition to search road around track prolongation along Y in cm Optimal tracklet rphi resolution in maximum chi2 per attached tracklet for TRD tracks take into account the full likelihood of the slope including exponential tails Tracks with less attached tracklets are discarded after the tracking Post trigger Pile up integration time in BCs fits all iterations but the last one in projections Use material lookup table for TPC refit Apply workarounds to avoid cyclic merge should not be needed tpc dyn configStandalone Processing proc_rtc bool
configStandalone Reconstruction rec_tpc multiplier for the combined cluster track error during track following area in cm for the search of for z only used if decrease removal by when above this local occupancy rowx Shift of TPC revert cluster flag edge bit distance to edge exceeds this ZOffset for secondary multiple of radius max P of electron K BB bands crossing max P of electron p BB bands crossing max P of electron d BB bands crossing max P of electron t BB bands crossing min accepted dEdxMaxTPC of the track Additive extra cluster error for Y2 if edge flag set Additive extra cluster error for Y2 if single set Additive extra cluster error for Y2 if or single set Additive extra cluster error for Z2 if or single set Extra errors to add to track when crossing depending on addErrorsCECrossing Inner portion of y range in sector that is not used in searching for extrapolated track candidates factor2YS for track merging factor2K for track merging Margin in cm of Y position when rejecting edge clusters based on uncorrected track Y Max fraction of shared clusters for tracklet Except pad from cluster finding if total number of charges in a fragment is above this Except pad from cluster finding if number of consecutive charges in a fragment is above this Threshold where a timebin is considered disabling the noisy pad check for that pad Treat signal above this minimum as saturated Smoothing factor for the exponential Highly Ionising Particle tail filter Number of timebins to use for the averaging Add additional custom track errors when crossing relative as fraction of Do N fit passes in final fit of< 0:reject at max -n hits") AddOptionRTC(rejectIFCLowRadiusCluster, uint8_t, 1, "", 0, "Reject clusters that get the IFC mask error during refit") AddOptionRTC(dEdxTruncLow, uint8_t, 2, "", 0, "Low truncation threshold, fraction of 128") AddOptionRTC(dEdxTruncHigh, uint8_t, 77, "", 0, "High truncation threshold, fraction of 128") AddOptionRTC(extrapolationTracking, int8_t, 1, "", 0, "Enable Extrapolation Tracking(prolong tracks to adjacent sectors to find short segments)") AddOptionRTC(disableRefitAttachment, uint8_t, 0, "", 0, "Bitmask to disable certain attachment steps during refit(1:attachment, 2:propagation, 4:loop following, 8:mirroring)") AddOptionRTC(rejectionStrategy, uint8_t, o2::gpu::GPUSettings::RejectionStrategyA, "", 0, "Enable rejection of TPC clusters for compression(0=no, 1=strategy A, 2=strategy B)") AddOptionRTC(mergeLoopersAfterburner, uint8_t, 1, "", 0, "Run afterburner for additional looper merging") AddOptionRTC(compressionTypeMask, uint8_t, o2::gpu::GPUSettings::CompressionFull, "", 0, "TPC Compression mode bits(1=truncate charge/width LSB, 2=differences, 4=track-model)") AddOptionRTC(compressionSortOrder, uint8_t, o2::gpu::GPUSettings::SortTime, "", 0, "Sort order of TPC compression(0=time, 1=pad, 2=Z-time-pad, 3=Z-pad-time, 4=no sorting(use incoming order))") AddOptionRTC(sigBitsCharge, uint8_t, 4, "", 0, "Number of significant bits for TPC cluster charge in compression mode 1") AddOptionRTC(sigBitsWidth, uint8_t, 3, "", 0, "Number of significant bits for TPC cluster width in compression mode 1") AddOptionRTC(dropLoopers, uint8_t, 0, "", 0, "Drop looping tracks starting from second loop") AddOptionRTC(mergerInterpolateErrors, uint8_t, 1, "", 0, "Use interpolation instead of extrapolation for chi2 based cluster rejection") AddOptionRTC(mergerInterpolateRejectAlsoOnCurrentPosition, uint8_t, 1, "", 0, "When using mergerInterpolateErrors, reject based on chi2 twice computed with interpolated and current track position starting from NDF > mergerNonInterpolateRejectMinNDF Merge tracks accross the central electrode Enable PID response Add sub threshold clusters in TPC dEdx computation OR mask of TPC flags that will reject the cluster in alternative dEdx Reject edge clusters based on uncorrected track Y during track fit Increase decrease removal by when on this number of pads from the edge h configStandalone Reconstruction rec_trd Max chi2 for TRD tracklets to be matched to a track Chi2 cut for strict matching mode Number of sigmas for ITS TPC track time error estimate Addition to search road around track prolongation along Y in cm Optimal tracklet rphi resolution in maximum chi2 per attached tracklet for TRD tracks take into account the full likelihood of the slope including exponential tails Tracks with less attached tracklets are discarded after the tracking Post trigger Pile up integration time in BCs fits all iterations but the last one in projections Use material lookup table for TPC refit Apply workarounds to avoid cyclic merge should not be needed tpc dyn configStandalone Processing proc_rtc Replace constant variables static by constexpr expressions Compile RTC in deterministic with NO_FAST_MATH flags and GPUCA_DETERMINISTIC_MODE define Use RTC to optimize GPU code h configStandalone Processing proc_rtctech Use a file lock to serialize access to the cache folder Print launch bounds used for RTC code as debugging for exit after Allow RTC with slave GPUReconstruction instances with optConstexpr and optSpecialcode Maximum number of RTC cache files per backend in the cache the oldest are Prepend RTC compilation commands by this string Load a parameter object containing the launch bounds from a file h configStandalone Processing proc_param TPC Cluster Z Error Parameterization h configStandalone Processing settings for neural network proc_nn std::string Specify inference device(cpu(default), rocm, cuda)") AddOption(nnInferenceDeviceId
Class for time synchronization of RawReader instances.
HMPID cluster implementation.
const Handle & getStream()
static constexpr Handle DefaultStream
static constexpr unsigned int DefaultFlag
Stream(unsigned int flags=DefaultFlag)
void push_back(const Stream &stream)
void waitEvent(size_t iStream, size_t iEvent)
void sync(bool device=true)
auto & operator[](size_t i)
size_t size() const noexcept
GLuint const GLchar * name
GLenum GLuint GLint GLint layer
GLboolean GLboolean GLboolean GLboolean a
std::pair< T1, T2 > gpuPair
bool operator!=(const DsChannelId &a, const DsChannelId &b)
std::string to_string(gsl::span< T, Size > span)
GPUd() gpuSpan(const gpuSpan< T > &other)
GPUd() bool empty() const
GPUd() ref operator[](unsigned int idx) const
GPUd() unsigned int size() const
GPUd() bool empty() const
GPUd() ref operator[](unsigned int idx) const
GPUd() unsigned int size() const
VectorOfTObjectPtrs other
std::vector< Cluster > clusters