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
43 LOGP(info, __VA_ARGS__); \
44 GPUChkErrS(cudaDeviceSynchronize()); \
57template <
typename T1,
typename T2>
71 GPUd()
ref operator[](
unsigned int idx)
const {
return _data[idx]; }
93 GPUd()
ref operator[](
unsigned int idx)
const {
return _data[idx]; }
110#if defined(__HIPCC__)
111 using Handle = hipStream_t;
113 static constexpr unsigned int DefaultFlag = hipStreamNonBlocking;
114 using Event = hipEvent_t;
115#elif defined(__CUDACC__)
116 using Handle = cudaStream_t;
118 static constexpr unsigned int DefaultFlag = cudaStreamNonBlocking;
119 using Event = cudaEvent_t;
129#if defined(__HIPCC__)
131 GPUChkErrS(hipEventCreateWithFlags(&mEvent, hipEventDisableTiming));
132#elif defined(__CUDACC__)
134 GPUChkErrS(cudaEventCreateWithFlags(&mEvent, cudaEventDisableTiming));
142#if defined(__HIPCC__)
145#elif defined(__CUDACC__)
158#if defined(__HIPCC__)
160#elif defined(__CUDACC__)
166#if defined(__HIPCC__)
168#elif defined(__CUDACC__)
175 Event mEvent{
nullptr};
182 size_t size() const noexcept {
return mStreams.size(); }
190#if defined(__HIPCC__)
192#elif defined(__CUDACC__)
196 for (
auto& s : mStreams) {
203#if defined(__HIPCC__)
204 GPUChkErrS(hipStreamWaitEvent(mStreams[iStream].
get(), mStreams[iEvent].getEvent()));
205#elif defined(__CUDACC__)
206 GPUChkErrS(cudaStreamWaitEvent(mStreams[iStream].
get(), mStreams[iEvent].getEvent()));
211 std::vector<Stream> mStreams;
214#ifdef ITS_MEASURE_GPU_TIME
218 GPUTimer(
const std::string&
name)
224 GPUTimer(Streams& streams,
const std::string&
name)
227 for (
size_t i{0};
i < streams.size(); ++
i) {
228 mStreams.push_back(streams[
i].
get());
235 for (
size_t sta{
start}; sta <
end; ++sta) {
236 mStreams.push_back(streams[sta].
get());
243 mStreams.push_back(
stream.get());
249 for (
size_t i{0};
i < mStreams.size(); ++
i) {
251#if defined(__HIPCC__)
254 GPUChkErrS(hipEventElapsedTime(&ms, mStarts[
i], mStops[
i]));
257#elif defined(__CUDACC__)
260 GPUChkErrS(cudaEventElapsedTime(&ms, mStarts[
i], mStops[
i]));
264 LOGP(info,
"Elapsed time for {}:{} {} ms", mName,
i, ms);
270 mStarts.resize(mStreams.size());
271 mStops.resize(mStreams.size());
272 for (
size_t i{0};
i < mStreams.size(); ++
i) {
273#if defined(__HIPCC__)
277#elif defined(__CUDACC__)
287 std::vector<Stream::Event> mStarts, mStops;
288 std::vector<Stream::Handle> mStreams;
294 template <
typename... Args>
303struct TypedAllocator {
304 using value_type = T;
305 using pointer = thrust::device_ptr<T>;
306 using const_pointer = thrust::device_ptr<const T>;
307 using size_type = std::size_t;
308 using difference_type = std::ptrdiff_t;
310 TypedAllocator() noexcept : mInternalAllocator(
nullptr) {}
311 explicit TypedAllocator(ExternalAllocator*
a) noexcept : mInternalAllocator(
a) {}
313 template <
typename U>
314 TypedAllocator(
const TypedAllocator<U>& o) noexcept : mInternalAllocator(o.mInternalAllocator)
320 void*
raw = mInternalAllocator->allocateStack(
n *
sizeof(T));
321 return thrust::device_pointer_cast(
static_cast<T*
>(
raw));
324 void deallocate(
pointer p, size_type
n)
noexcept
329 void*
raw = thrust::raw_pointer_cast(p);
330 mInternalAllocator->deallocate(
static_cast<char*
>(
raw),
n *
sizeof(T));
333 bool operator==(TypedAllocator
const& o)
const noexcept
335 return mInternalAllocator == o.mInternalAllocator;
337 bool operator!=(TypedAllocator
const& o)
const noexcept
339 return !(*
this == o);
343 ExternalAllocator* mInternalAllocator;
346GPUdii() gpuSpan<const
Cluster> getClustersOnLayer(const
int rof,
349 const
int** roframesClus,
352 if (rof < 0 || rof >= totROFs) {
353 return gpuSpan<const Cluster>();
355 const int start_clus_id{roframesClus[
layer][rof]};
356 const int stop_rof = rof >= totROFs - 1 ? totROFs : rof + 1;
357 const unsigned int delta = roframesClus[
layer][stop_rof] - start_clus_id;
358 return gpuSpan<const Cluster>(&(
clusters[
layer][start_clus_id]), delta);
o2::raw::RawFileWriter * raw
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