A high-throughput and memory-efficient inference and serving engine for LLMs
Mirrored from https://github.com/tduncan-lum/Nvidia-Optimization-Stack---VLLM.git
Synced Nov 17, 04:15 UTC
[ROCm] Fix warp and lane calculation in blockReduceSum (#3321)
kliuae committed
Mar 12, 2024 at 04:14 UTC
c9415c19d3df26d8ede611abefba35c6837cd934
1 file changed
+12
-2
csrc/reduction_utils.cuh
+12
-2
@@ -29,12 +29,22 @@ __inline__ __device__ T warpReduceSum(T val) {
29
return val;
30
}
31
32
+__inline__ __device__ constexpr int _calculateLaneMask(int warp_size) {
33
+ return warp_size - 1;
34
+}
35
+
36
+__inline__ __device__ constexpr int _calculateWidShift(int warp_size) {
37
+ return 5 + (warp_size >> 6);
38
+}
39
+
40
/* Calculate the sum of all elements in a block */
41
template<typename T>
42
__inline__ __device__ T blockReduceSum(T val) {
43
static __shared__ T shared[WARP_SIZE];
36
- int lane = threadIdx.x & 0x1f;
37
- int wid = threadIdx.x >> 5;
44
+ constexpr auto LANE_MASK = _calculateLaneMask(WARP_SIZE);
45
+ constexpr auto WID_SHIFT = _calculateWidShift(WARP_SIZE);
46
+ int lane = threadIdx.x & LANE_MASK;
47
+ int wid = threadIdx.x >> WID_SHIFT;
48
49
val = warpReduceSum<T>(val);
50