cuSBF
Loading...
Searching...
No Matches
helpers.cuh
Go to the documentation of this file.
1#pragma once
2
3#include <cuda_runtime.h>
4
5#include <cuda/std/bit>
6#include <cuda/std/concepts>
7
8#include <cstddef>
9#include <cstdint>
10
11#include <cusbf/cuda_error.hpp>
12
13namespace cusbf::detail {
14
15#if __CUDA_ARCH__ >= 1000
16
31template <typename T>
33 static_assert(sizeof(T) == 4 || sizeof(T) == 8, "T must be uint32_t or uint64_t");
34
35 if constexpr (sizeof(T) == 8) {
36 asm volatile("ld.global.nc.v4.u64 {%0, %1, %2, %3}, [%4];"
37 : "=l"(out[0]), "=l"(out[1]), "=l"(out[2]), "=l"(out[3])
38 : "l"(ptr));
39 } else {
40 asm volatile("ld.global.nc.v8.u32 {%0, %1, %2, %3, %4, %5, %6, %7}, [%8];"
41 : "=r"(out[0]),
42 "=r"(out[1]),
43 "=r"(out[2]),
44 "=r"(out[3]),
45 "=r"(out[4]),
46 "=r"(out[5]),
47 "=r"(out[6]),
48 "=r"(out[7])
49 : "l"(ptr));
50 }
51}
52
55 const uint64_t* ptr,
60) {
61 asm volatile("ld.global.nc.v4.u64 {%0, %1, %2, %3}, [%4];"
62 : "=l"(out0), "=l"(out1), "=l"(out2), "=l"(out3)
63 : "l"(ptr));
64}
65
66#endif
67
75 asm volatile("ld.global.nc.v2.u64 {%0, %1}, [%2];" : "=l"(out0), "=l"(out1) : "l"(ptr));
76}
77
85#if __CUDA_ARCH__ >= 800
86 auto lo = __reduce_or_sync(peers, static_cast<uint32_t>(value));
87 auto hi = __reduce_or_sync(peers, static_cast<uint32_t>(value >> 32));
88 return (static_cast<uint64_t>(hi) << 32) | lo;
89#else
90 // Shuffle-based reduction across the lanes set in `peers`.
92 while (remaining) {
93 int src = __ffs(remaining) - 1;
95 (static_cast<uint64_t>(__shfl_sync(peers, static_cast<uint32_t>(value >> 32), src))
96 << 32) |
97 __shfl_sync(peers, static_cast<uint32_t>(value), src);
98 value |= other;
99 remaining &= remaining - 1; // clear lowest set bit
100 }
101 return value;
102#endif
103}
104
114template <typename Kernel>
129
130} // namespace cusbf::detail
__device__ __forceinline__ void load128BitGlobalNC(const uint64_t *ptr, uint64_t &out0, uint64_t &out1)
Loads 128 bits from global memory using the non-coherent cache path.
Definition helpers.cuh:74
__device__ __forceinline__ uint64_t warpReduceOr(uint32_t peers, uint64_t value)
OR-reduce a uint64_t across the lanes in a peer mask.
Definition helpers.cuh:84
__device__ __forceinline__ void load256BitGlobalNC(const T *ptr, T *out)
Loads 256 bits from global memory using the non-coherent cache path.
Definition helpers.cuh:32
consteval bool separatorPositionAlwaysEncodesInvalid(char *input, uint64_t separatorPosition, uint64_t index)
Recursively tests whether placing the separator byte at any position in an input of valid bytes alway...
Definition Alphabet.cuh:37
uint64_t maxOccupancyGridSize(int32_t blockSize, Kernel kernel, uint64_t dynamicSMemSize)
Calculates the maximum occupancy grid size for a kernel.
Definition helpers.cuh:115