main
h 76 lines 1.85 KB
Raw
1 #pragma once
2
3 #ifdef USE_ROCM
4 #include <hip/hip_runtime.h>
5 #endif
6
7 #ifdef USE_ROCM
8 struct Utils {
9 static __host__ int get_warp_size() {
10 static bool is_cached = false;
11 static int result;
12
13 if (!is_cached) {
14 int device_id;
15 cudaDeviceProp deviceProp;
16 cudaGetDevice(&device_id);
17 cudaGetDeviceProperties(&deviceProp, device_id);
18
19 result = deviceProp.warpSize;
20 is_cached = true;
21 }
22
23 return result;
24 }
25
26 static __device__ constexpr int get_warp_size() {
27 #ifdef __GFX9__
28 return 64;
29 #else
30 return 32;
31 #endif
32 }
33 };
34
35 #define WARP_SIZE Utils::get_warp_size()
36 #else
37 #define WARP_SIZE 32
38 #endif
39
40 #ifndef USE_ROCM
41 #define VLLM_LDG(arg) __ldg(arg)
42 #else
43 #define VLLM_LDG(arg) *(arg)
44 #endif
45
46 #ifndef USE_ROCM
47 #define VLLM_SHFL_XOR_SYNC(var, lane_mask) \
48 __shfl_xor_sync(uint32_t(-1), var, lane_mask)
49 #define VLLM_SHFL_XOR_SYNC_WIDTH(var, lane_mask, width) \
50 __shfl_xor_sync(uint32_t(-1), var, lane_mask, width)
51 #else
52 #define VLLM_SHFL_XOR_SYNC(var, lane_mask) __shfl_xor(var, lane_mask)
53 #define VLLM_SHFL_XOR_SYNC_WIDTH(var, lane_mask, width) \
54 __shfl_xor(var, lane_mask, width)
55 #endif
56
57 #ifndef USE_ROCM
58 #define VLLM_SHFL_SYNC(var, src_lane) __shfl_sync(uint32_t(-1), var, src_lane)
59 #else
60 #define VLLM_SHFL_SYNC(var, src_lane) __shfl(var, src_lane)
61 #endif
62
63 #ifndef USE_ROCM
64 #define VLLM_SHFL_DOWN_SYNC(var, lane_delta) \
65 __shfl_down_sync(uint32_t(-1), var, lane_delta)
66 #else
67 #define VLLM_SHFL_DOWN_SYNC(var, lane_delta) __shfl_down(var, lane_delta)
68 #endif
69
70 #ifndef USE_ROCM
71 #define VLLM_DevFuncAttribute_SET_MaxDynamicSharedMemorySize(FUNC, VAL) \
72 cudaFuncSetAttribute(FUNC, cudaFuncAttributeMaxDynamicSharedMemorySize, VAL)
73 #else
74 #define VLLM_DevFuncAttribute_SET_MaxDynamicSharedMemorySize(FUNC, VAL) \
75 hipFuncSetAttribute(FUNC, hipFuncAttributeMaxDynamicSharedMemorySize, VAL)
76 #endif