-
Notifications
You must be signed in to change notification settings - Fork 1
/
shiftx_wrapper.go
165 lines (140 loc) · 3.91 KB
/
shiftx_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 shiftx kernel
var shiftx_code cu.Function
// Stores the arguments for shiftx kernel invocation
type shiftx_args_t struct {
arg_dst unsafe.Pointer
arg_src unsafe.Pointer
arg_Nx int
arg_Ny int
arg_Nz int
arg_shx int
arg_clampL float32
arg_clampR float32
argptr [8]unsafe.Pointer
sync.Mutex
}
// Stores the arguments for shiftx kernel invocation
var shiftx_args shiftx_args_t
func init() {
// CUDA driver kernel call wants pointers to arguments, set them up once.
shiftx_args.argptr[0] = unsafe.Pointer(&shiftx_args.arg_dst)
shiftx_args.argptr[1] = unsafe.Pointer(&shiftx_args.arg_src)
shiftx_args.argptr[2] = unsafe.Pointer(&shiftx_args.arg_Nx)
shiftx_args.argptr[3] = unsafe.Pointer(&shiftx_args.arg_Ny)
shiftx_args.argptr[4] = unsafe.Pointer(&shiftx_args.arg_Nz)
shiftx_args.argptr[5] = unsafe.Pointer(&shiftx_args.arg_shx)
shiftx_args.argptr[6] = unsafe.Pointer(&shiftx_args.arg_clampL)
shiftx_args.argptr[7] = unsafe.Pointer(&shiftx_args.arg_clampR)
}
// Wrapper for shiftx CUDA kernel, asynchronous.
func k_shiftx_async(dst unsafe.Pointer, src unsafe.Pointer, Nx int, Ny int, Nz int, shx int, clampL float32, clampR float32, cfg *config) {
if Synchronous { // debug
Sync()
timer.Start("shiftx")
}
shiftx_args.Lock()
defer shiftx_args.Unlock()
if shiftx_code == 0 {
shiftx_code = fatbinLoad(shiftx_map, "shiftx")
}
shiftx_args.arg_dst = dst
shiftx_args.arg_src = src
shiftx_args.arg_Nx = Nx
shiftx_args.arg_Ny = Ny
shiftx_args.arg_Nz = Nz
shiftx_args.arg_shx = shx
shiftx_args.arg_clampL = clampL
shiftx_args.arg_clampR = clampR
args := shiftx_args.argptr[:]
cu.LaunchKernel(shiftx_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("shiftx")
}
}
// maps compute capability on PTX code for shiftx kernel.
var shiftx_map = map[int]string{0: "",
50: shiftx_ptx_50}
// shiftx PTX code for various compute capabilities.
const (
shiftx_ptx_50 = `
.version 7.5
.target sm_50
.address_size 64
// .globl shiftx
.visible .entry shiftx(
.param .u64 shiftx_param_0,
.param .u64 shiftx_param_1,
.param .u32 shiftx_param_2,
.param .u32 shiftx_param_3,
.param .u32 shiftx_param_4,
.param .u32 shiftx_param_5,
.param .f32 shiftx_param_6,
.param .f32 shiftx_param_7
)
{
.reg .pred %p<8>;
.reg .f32 %f<6>;
.reg .b32 %r<22>;
.reg .b64 %rd<9>;
ld.param.u64 %rd1, [shiftx_param_0];
ld.param.u64 %rd2, [shiftx_param_1];
ld.param.u32 %r5, [shiftx_param_2];
ld.param.u32 %r6, [shiftx_param_3];
ld.param.u32 %r8, [shiftx_param_4];
ld.param.u32 %r7, [shiftx_param_5];
ld.param.f32 %f5, [shiftx_param_6];
ld.param.f32 %f4, [shiftx_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, %r8;
or.pred %p5, %p3, %p4;
@%p5 bra $L__BB0_5;
sub.s32 %r4, %r1, %r7;
setp.lt.s32 %p6, %r4, 0;
@%p6 bra $L__BB0_4;
setp.ge.s32 %p7, %r4, %r5;
mov.f32 %f5, %f4;
@%p7 bra $L__BB0_4;
mad.lo.s32 %r18, %r3, %r6, %r2;
mad.lo.s32 %r19, %r18, %r5, %r4;
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;
}
`
)