-
Notifications
You must be signed in to change notification settings - Fork 1
/
reduce_kernel.h
23 lines (20 loc) · 1.04 KB
/
reduce_kernel.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
__forceinline__ __device__ float reduce_min_input(float input){
float tmp_min = input;
tmp_min = fminf(tmp_min,__shfl_down_sync(0xffffffff, tmp_min, 16));
tmp_min = fminf(tmp_min,__shfl_down_sync(0xffffffff, tmp_min, 8));
tmp_min = fminf(tmp_min,__shfl_down_sync(0xffffffff, tmp_min, 4));
tmp_min = fminf(tmp_min,__shfl_down_sync(0xffffffff, tmp_min, 2));
tmp_min = fminf(tmp_min,__shfl_down_sync(0xffffffff, tmp_min, 1));
tmp_min = __shfl_sync(0xffffffff,tmp_min,0);
return tmp_min;
}
__forceinline__ __device__ float reduce_max_input(float input){
float tmp_max = input;
tmp_max = fmaxf(tmp_max,__shfl_down_sync(0xffffffff, tmp_max, 16));
tmp_max = fmaxf(tmp_max,__shfl_down_sync(0xffffffff, tmp_max, 8));
tmp_max = fmaxf(tmp_max,__shfl_down_sync(0xffffffff, tmp_max, 4));
tmp_max = fmaxf(tmp_max,__shfl_down_sync(0xffffffff, tmp_max, 2));
tmp_max = fmaxf(tmp_max,__shfl_down_sync(0xffffffff, tmp_max, 1));
tmp_max = __shfl_sync(0xffffffff,tmp_max,0);
return tmp_max;
}