-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Stephen Nicholas Swatman
committed
Mar 8, 2023
1 parent
50a02e2
commit 5bc9530
Showing
6 changed files
with
240 additions
and
176 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
/** TRACCC library, part of the ACTS project (R&D line) | ||
* | ||
* (c) 2021 CERN for the benefit of the ACTS project | ||
* | ||
* Mozilla Public License Version 2.0 | ||
*/ | ||
|
||
#pragma once | ||
|
||
namespace traccc::cuda { | ||
template <typename T> | ||
__device__ void swap(T& a, T& b) { | ||
T t = a; | ||
a = b; | ||
b = t; | ||
} | ||
|
||
template <typename K, typename C> | ||
__device__ void blockOddEvenKeySort(K* keys, uint32_t num_keys, | ||
C&& comparison) { | ||
bool sorted; | ||
|
||
do { | ||
sorted = true; | ||
|
||
for (uint32_t j = 2 * threadIdx.x + 1; j < num_keys - 1; | ||
j += 2 * blockDim.x) { | ||
if (comparison(keys[j + 1], keys[j])) { | ||
swap(keys[j + 1], keys[j]); | ||
sorted = false; | ||
} | ||
} | ||
|
||
__syncthreads(); | ||
|
||
for (uint32_t j = 2 * threadIdx.x; j < num_keys - 1; | ||
j += 2 * blockDim.x) { | ||
if (comparison(keys[j + 1], keys[j])) { | ||
swap(keys[j + 1], keys[j]); | ||
sorted = false; | ||
} | ||
} | ||
} while (__syncthreads_or(!sorted)); | ||
} | ||
|
||
template <typename K, typename C> | ||
__device__ void warpOddEvenKeySort(K* keys, uint32_t num_keys, C&& comparison) { | ||
bool sorted; | ||
|
||
do { | ||
sorted = true; | ||
|
||
for (uint32_t j = 2 * (threadIdx.x % WARP_SIZE) + 1; j < num_keys - 1; | ||
j += 2 * WARP_SIZE) { | ||
if (comparison(keys[j + 1], keys[j])) { | ||
swap(keys[j + 1], keys[j]); | ||
sorted = false; | ||
} | ||
} | ||
|
||
__syncwarp(__activemask()); | ||
|
||
for (uint32_t j = 2 * (threadIdx.x % WARP_SIZE); j < num_keys - 1; | ||
j += 2 * WARP_SIZE) { | ||
if (comparison(keys[j + 1], keys[j])) { | ||
swap(keys[j + 1], keys[j]); | ||
sorted = false; | ||
} | ||
} | ||
} while (__any_sync(__activemask(), !sorted)); | ||
} | ||
} // namespace traccc::cuda |
Oops, something went wrong.