Project
Loading...
Searching...
No Matches
GPUCommonAlgorithmThrust.h
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#ifndef GPUCOMMONALGORITHMTHRUST_H
16#define GPUCOMMONALGORITHMTHRUST_H
17
18#pragma GCC diagnostic push
19#pragma GCC diagnostic ignored "-Wshadow"
20#include <thrust/sort.h>
21#include <thrust/execution_policy.h>
22#include <thrust/device_ptr.h>
23#pragma GCC diagnostic pop
24
25#include "GPUCommonDef.h"
26
27#ifdef __CUDACC__
28#define GPUCA_THRUST_NAMESPACE thrust::cuda
29#else
30#define GPUCA_THRUST_NAMESPACE thrust::hip
31#endif
32
33namespace o2
34{
35namespace gpu
36{
37
38// - Our quicksort and bubble sort implementations are faster
39/*
40template <class T>
41GPUdi() void GPUCommonAlgorithm::sort(T* begin, T* end)
42{
43 thrust::device_ptr<T> thrustBegin(begin);
44 thrust::device_ptr<T> thrustEnd(end);
45 thrust::sort(thrust::seq, thrustBegin, thrustEnd);
46}
47
48template <class T, class S>
49GPUdi() void GPUCommonAlgorithm::sort(T* begin, T* end, const S& comp)
50{
51 thrust::device_ptr<T> thrustBegin(begin);
52 thrust::device_ptr<T> thrustEnd(end);
53 thrust::sort(thrust::seq, thrustBegin, thrustEnd, comp);
54}
55
56template <class T>
57GPUdi() void GPUCommonAlgorithm::sortInBlock(T* begin, T* end)
58{
59 if (get_local_id(0) == 0) {
60 sortDeviceDynamic(begin, end);
61 }
62}
63
64template <class T, class S>
65GPUdi() void GPUCommonAlgorithm::sortInBlock(T* begin, T* end, const S& comp)
66{
67 if (get_local_id(0) == 0) {
68 sortDeviceDynamic(begin, end, comp);
69 }
70}
71
72*/
73
74template <class T>
75GPUdi() void GPUCommonAlgorithm::sortDeviceDynamic(T* begin, T* end)
76{
77 thrust::device_ptr<T> thrustBegin(begin);
78 thrust::device_ptr<T> thrustEnd(end);
79 thrust::sort(GPUCA_THRUST_NAMESPACE::par, thrustBegin, thrustEnd);
80}
81
82template <class T, class S>
83GPUdi() void GPUCommonAlgorithm::sortDeviceDynamic(T* begin, T* end, const S& comp)
84{
85 thrust::device_ptr<T> thrustBegin(begin);
86 thrust::device_ptr<T> thrustEnd(end);
87 thrust::sort(GPUCA_THRUST_NAMESPACE::par, thrustBegin, thrustEnd, comp);
88}
89
90} // namespace gpu
91} // namespace o2
92
93#endif
GLuint GLuint end
Definition glcorearb.h:469
GPUdi() o2
Definition TrackTRD.h:38
a couple of static helper functions to create timestamp values for CCDB queries or override obsolete ...