-
Notifications
You must be signed in to change notification settings - Fork 1
/
shiftz_wrapper.go
165 lines (140 loc) · 3.91 KB
/
shiftz_wrapper.go
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
package cuda
/*
THIS FILE IS AUTO-GENERATED BY CUDA2GO.
EDITING IS FUTILE.
*/
import (
"github.com/kuchkin/mumax3-gneb/cuda/cu"
"github.com/kuchkin/mumax3-gneb/timer"
"sync"
"unsafe"
)
// CUDA handle for shiftz kernel
var shiftz_code cu.Function
// Stores the arguments for shiftz kernel invocation
type shiftz_args_t struct {
arg_dst unsafe.Pointer
arg_src unsafe.Pointer
arg_Nx int
arg_Ny int
arg_Nz int
arg_shz int
arg_clampL float32
arg_clampR float32
argptr [8]unsafe.Pointer
sync.Mutex
}
// Stores the arguments for shiftz kernel invocation
var shiftz_args shiftz_args_t
func init() {
// CUDA driver kernel call wants pointers to arguments, set them up once.
shiftz_args.argptr[0] = unsafe.Pointer(&shiftz_args.arg_dst)
shiftz_args.argptr[1] = unsafe.Pointer(&shiftz_args.arg_src)
shiftz_args.argptr[2] = unsafe.Pointer(&shiftz_args.arg_Nx)
shiftz_args.argptr[3] = unsafe.Pointer(&shiftz_args.arg_Ny)
shiftz_args.argptr[4] = unsafe.Pointer(&shiftz_args.arg_Nz)
shiftz_args.argptr[5] = unsafe.Pointer(&shiftz_args.arg_shz)
shiftz_args.argptr[6] = unsafe.Pointer(&shiftz_args.arg_clampL)
shiftz_args.argptr[7] = unsafe.Pointer(&shiftz_args.arg_clampR)
}
// Wrapper for shiftz CUDA kernel, asynchronous.
func k_shiftz_async(dst unsafe.Pointer, src unsafe.Pointer, Nx int, Ny int, Nz int, shz int, clampL float32, clampR float32, cfg *config) {
if Synchronous { // debug
Sync()
timer.Start("shiftz")
}
shiftz_args.Lock()
defer shiftz_args.Unlock()
if shiftz_code == 0 {
shiftz_code = fatbinLoad(shiftz_map, "shiftz")
}
shiftz_args.arg_dst = dst
shiftz_args.arg_src = src
shiftz_args.arg_Nx = Nx
shiftz_args.arg_Ny = Ny
shiftz_args.arg_Nz = Nz
shiftz_args.arg_shz = shz
shiftz_args.arg_clampL = clampL
shiftz_args.arg_clampR = clampR
args := shiftz_args.argptr[:]
cu.LaunchKernel(shiftz_code, cfg.Grid.X, cfg.Grid.Y, cfg.Grid.Z, cfg.Block.X, cfg.Block.Y, cfg.Block.Z, 0, stream0, args)
if Synchronous { // debug
Sync()
timer.Stop("shiftz")
}
}
// maps compute capability on PTX code for shiftz kernel.
var shiftz_map = map[int]string{0: "",
50: shiftz_ptx_50}
// shiftz PTX code for various compute capabilities.
const (
shiftz_ptx_50 = `
.version 7.5
.target sm_50
.address_size 64
// .globl shiftz
.visible .entry shiftz(
.param .u64 shiftz_param_0,
.param .u64 shiftz_param_1,
.param .u32 shiftz_param_2,
.param .u32 shiftz_param_3,
.param .u32 shiftz_param_4,
.param .u32 shiftz_param_5,
.param .f32 shiftz_param_6,
.param .f32 shiftz_param_7
)
{
.reg .pred %p<8>;
.reg .f32 %f<6>;
.reg .b32 %r<22>;
.reg .b64 %rd<9>;
ld.param.u64 %rd1, [shiftz_param_0];
ld.param.u64 %rd2, [shiftz_param_1];
ld.param.u32 %r5, [shiftz_param_2];
ld.param.u32 %r6, [shiftz_param_3];
ld.param.u32 %r7, [shiftz_param_4];
ld.param.u32 %r8, [shiftz_param_5];
ld.param.f32 %f5, [shiftz_param_6];
ld.param.f32 %f4, [shiftz_param_7];
mov.u32 %r9, %ntid.x;
mov.u32 %r10, %ctaid.x;
mov.u32 %r11, %tid.x;
mad.lo.s32 %r1, %r10, %r9, %r11;
mov.u32 %r12, %ntid.y;
mov.u32 %r13, %ctaid.y;
mov.u32 %r14, %tid.y;
mad.lo.s32 %r2, %r13, %r12, %r14;
mov.u32 %r15, %ntid.z;
mov.u32 %r16, %ctaid.z;
mov.u32 %r17, %tid.z;
mad.lo.s32 %r3, %r16, %r15, %r17;
setp.ge.s32 %p1, %r1, %r5;
setp.ge.s32 %p2, %r2, %r6;
or.pred %p3, %p1, %p2;
setp.ge.s32 %p4, %r3, %r7;
or.pred %p5, %p3, %p4;
@%p5 bra $L__BB0_5;
sub.s32 %r4, %r3, %r8;
setp.lt.s32 %p6, %r4, 0;
@%p6 bra $L__BB0_4;
setp.ge.s32 %p7, %r4, %r7;
mov.f32 %f5, %f4;
@%p7 bra $L__BB0_4;
mad.lo.s32 %r18, %r4, %r6, %r2;
mad.lo.s32 %r19, %r18, %r5, %r1;
cvta.to.global.u64 %rd3, %rd2;
mul.wide.s32 %rd4, %r19, 4;
add.s64 %rd5, %rd3, %rd4;
ld.global.nc.f32 %f5, [%rd5];
$L__BB0_4:
mad.lo.s32 %r20, %r3, %r6, %r2;
mad.lo.s32 %r21, %r20, %r5, %r1;
cvta.to.global.u64 %rd6, %rd1;
mul.wide.s32 %rd7, %r21, 4;
add.s64 %rd8, %rd6, %rd7;
st.global.f32 [%rd8], %f5;
$L__BB0_5:
ret;
}
`
)