Files
sglang/python/sglang/jit_kernel/include/sgl_kernel/warp.cuh
T
ba9f6d8f26 [Refactor] Clean up JIT kernel utilites (#16884)
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Co-authored-by: Xiaoyu Zhang <35585791+BBuf@users.noreply.github.com>
2026-01-13 17:54:16 +08:00

26 lines
658 B
Plaintext

#pragma once
#include <sgl_kernel/math.cuh>
// Some warp primitives
namespace device::warp {
static constexpr uint32_t kFullMask = 0xffffffffu;
template <typename T>
SGL_DEVICE T reduce_sum(T value, uint32_t active_mask = kFullMask) {
#pragma unroll
for (int mask = 16; mask > 0; mask >>= 1)
value = value + __shfl_xor_sync(active_mask, value, mask, 32);
return value;
}
template <typename T>
SGL_DEVICE T reduce_max(T value, uint32_t active_mask = kFullMask) {
#pragma unroll
for (int mask = 16; mask > 0; mask >>= 1)
value = math::max(value, __shfl_xor_sync(active_mask, value, mask, 32));
return value;
}
} // namespace device::warp