Repository navigation
Expand file tree
/
Copy pathshfl.h
More file actions
60 lines (48 loc) · 1.67 KB
/
Copy pathshfl.h
File metadata and controls
60 lines (48 loc) · 1.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#if defined(__CUDA_ARCH__) & (__CUDA_ARCH__ < 300)
#define MAX_BLOCK 256
template <class T>
__device__ inline T __shfl_down(T var, const unsigned int delta, const unsigned int width=32) {
__shared__ volatile T shfl_array[MAX_BLOCK];
unsigned int x=threadIdx.x%width;
unsigned int wg=x%32/width;
shfl_array[threadIdx.y*blockDim.x+wg*width+x]=var;
unsigned int srcLane=x+delta;
if(srcLane<width) {
var=shfl_array[threadIdx.y*blockDim.x+wg*width+srcLane];
}
return var;
}
template <class T>
__device__ inline T __shfl_up(T var, const unsigned int delta, const unsigned int width=32) {
__shared__ volatile T shfl_array[MAX_BLOCK];
unsigned int x=threadIdx.x%width;
unsigned int wg=x%32/width;
shfl_array[threadIdx.y*blockDim.x+wg*width+x]=var;
unsigned int srcLane=x-delta;
if(srcLane<width) {
var=shfl_array[threadIdx.y*blockDim.x+wg*width+srcLane];
}
return var;
}
template <class T>
__device__ inline T __shfl(T var, const unsigned int srcLane, const unsigned int width=32) {
__shared__ volatile T shfl_array[MAX_BLOCK];
unsigned int x=threadIdx.x%width;
unsigned int wg=x%32/width;
shfl_array[threadIdx.y*blockDim.x+wg*width+x]=var;
if(srcLane<width)
var=shfl_array[threadIdx.y*blockDim.x+wg*width+srcLane];
return var;
}
template <class T>
__device__ inline T __shfl_xor(T var, const unsigned int laneMask, const unsigned int width=32) {
__shared__ volatile T shfl_array[MAX_BLOCK];
unsigned int x=threadIdx.x%width;
unsigned int wg=x%32/width;
unsigned int srcLane=laneMask^x;
shfl_array[threadIdx.y*blockDim.x+wg*width+x]=var;
if(srcLane<width)
var=shfl_array[threadIdx.y*blockDim.x+wg*width+srcLane];
return var;
}
#endif