FZGPUModules 2.0
GPU-accelerated modular compression pipelines
Loading...
Searching...
No Matches
warp.h
Go to the documentation of this file.
1#pragma once
2
45#include "backend/api.h"
46
47#include <cstdint>
48
49namespace fz {
50namespace backend {
51
52#if defined(FZGMOD_BACKEND_HIP)
53using warp_mask_t = unsigned long long;
54inline constexpr warp_mask_t kFullMask = ~0ULL;
55#else
56using warp_mask_t = unsigned;
57inline constexpr warp_mask_t kFullMask = 0xffffffffu;
58#endif
59
60template <typename T>
61__device__ inline T shflUp(T val, unsigned delta, int width) {
62 return __shfl_up_sync(kFullMask, val, delta, width);
63}
64
65template <typename T>
66__device__ inline T shflDown(T val, unsigned delta, int width) {
67 return __shfl_down_sync(kFullMask, val, delta, width);
68}
69
70template <typename T>
71__device__ inline T shflXor(T val, int laneMask, int width) {
72 return __shfl_xor_sync(kFullMask, val, laneMask, width);
73}
74
75template <typename T>
76__device__ inline T shfl(T val, int srcLane, int width) {
77 return __shfl_sync(kFullMask, val, srcLane, width);
78}
79
82__device__ inline uint32_t ballotSync32(int pred) {
83#if defined(FZGMOD_BACKEND_HIP)
84 bool upper = (__lane_id() & 32u) != 0u;
85 warp_mask_t mask = upper ? 0xFFFFFFFF00000000ULL : 0x00000000FFFFFFFFULL;
86 unsigned long long b = __ballot_sync(mask, pred);
87 return static_cast<uint32_t>(upper ? (b >> 32) : b);
88#else
89 return __ballot_sync(kFullMask, pred);
90#endif
91}
92
95__device__ inline bool anySync32(int pred) {
96#if defined(FZGMOD_BACKEND_HIP)
97 bool upper = (__lane_id() & 32u) != 0u;
98 warp_mask_t mask = upper ? 0xFFFFFFFF00000000ULL : 0x00000000FFFFFFFFULL;
99 return __any_sync(mask, pred) != 0;
100#else
101 return __any_sync(kFullMask, pred) != 0;
102#endif
103}
104
105} // namespace backend
106} // namespace fz
Backend-neutral spelling of the host-side GPU runtime API.
Definition algorithms.h:48
uint32_t ballotSync32(int pred)
Definition warp.h:82
bool anySync32(int pred)
Definition warp.h:95