-
Notifications
You must be signed in to change notification settings - Fork 1
/
theta_wrapper.go
164 lines (142 loc) · 3.97 KB
/
theta_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
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 setTheta kernel
var setTheta_code cu.Function
// Stores the arguments for setTheta kernel invocation
type setTheta_args_t struct {
arg_theta unsafe.Pointer
arg_mz unsafe.Pointer
arg_Nx int
arg_Ny int
arg_Nz int
argptr [5]unsafe.Pointer
sync.Mutex
}
// Stores the arguments for setTheta kernel invocation
var setTheta_args setTheta_args_t
func init() {
// CUDA driver kernel call wants pointers to arguments, set them up once.
setTheta_args.argptr[0] = unsafe.Pointer(&setTheta_args.arg_theta)
setTheta_args.argptr[1] = unsafe.Pointer(&setTheta_args.arg_mz)
setTheta_args.argptr[2] = unsafe.Pointer(&setTheta_args.arg_Nx)
setTheta_args.argptr[3] = unsafe.Pointer(&setTheta_args.arg_Ny)
setTheta_args.argptr[4] = unsafe.Pointer(&setTheta_args.arg_Nz)
}
// Wrapper for setTheta CUDA kernel, asynchronous.
func k_setTheta_async(theta unsafe.Pointer, mz unsafe.Pointer, Nx int, Ny int, Nz int, cfg *config) {
if Synchronous { // debug
Sync()
timer.Start("setTheta")
}
setTheta_args.Lock()
defer setTheta_args.Unlock()
if setTheta_code == 0 {
setTheta_code = fatbinLoad(setTheta_map, "setTheta")
}
setTheta_args.arg_theta = theta
setTheta_args.arg_mz = mz
setTheta_args.arg_Nx = Nx
setTheta_args.arg_Ny = Ny
setTheta_args.arg_Nz = Nz
args := setTheta_args.argptr[:]
cu.LaunchKernel(setTheta_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("setTheta")
}
}
// maps compute capability on PTX code for setTheta kernel.
var setTheta_map = map[int]string{0: "",
50: setTheta_ptx_50}
// setTheta PTX code for various compute capabilities.
const (
setTheta_ptx_50 = `
.version 7.5
.target sm_50
.address_size 64
// .globl setTheta
.visible .entry setTheta(
.param .u64 setTheta_param_0,
.param .u64 setTheta_param_1,
.param .u32 setTheta_param_2,
.param .u32 setTheta_param_3,
.param .u32 setTheta_param_4
)
{
.reg .pred %p<8>;
.reg .f32 %f<27>;
.reg .b32 %r<18>;
.reg .b64 %rd<8>;
ld.param.u64 %rd1, [setTheta_param_0];
ld.param.u64 %rd2, [setTheta_param_1];
ld.param.u32 %r4, [setTheta_param_2];
ld.param.u32 %r5, [setTheta_param_3];
ld.param.u32 %r6, [setTheta_param_4];
mov.u32 %r7, %ctaid.x;
mov.u32 %r8, %ntid.x;
mov.u32 %r9, %tid.x;
mad.lo.s32 %r1, %r7, %r8, %r9;
mov.u32 %r10, %ntid.y;
mov.u32 %r11, %ctaid.y;
mov.u32 %r12, %tid.y;
mad.lo.s32 %r2, %r11, %r10, %r12;
mov.u32 %r13, %ntid.z;
mov.u32 %r14, %ctaid.z;
mov.u32 %r15, %tid.z;
mad.lo.s32 %r3, %r14, %r13, %r15;
setp.ge.s32 %p1, %r1, %r4;
setp.ge.s32 %p2, %r2, %r5;
or.pred %p3, %p1, %p2;
setp.ge.s32 %p4, %r3, %r6;
or.pred %p5, %p3, %p4;
@%p5 bra $L__BB0_2;
cvta.to.global.u64 %rd3, %rd2;
mad.lo.s32 %r16, %r3, %r5, %r2;
mad.lo.s32 %r17, %r16, %r4, %r1;
mul.wide.s32 %rd4, %r17, 4;
add.s64 %rd5, %rd3, %rd4;
ld.global.nc.f32 %f1, [%rd5];
abs.f32 %f2, %f1;
mov.f32 %f3, 0f3F800000;
sub.f32 %f4, %f3, %f2;
mul.f32 %f5, %f4, 0f3F000000;
sqrt.rn.f32 %f6, %f5;
setp.gt.f32 %p6, %f2, 0f3F11EB85;
selp.f32 %f7, %f6, %f2, %p6;
mul.f32 %f8, %f7, %f7;
mov.f32 %f9, 0f3C94D2E9;
mov.f32 %f10, 0f3D53F941;
fma.rn.f32 %f11, %f10, %f8, %f9;
mov.f32 %f12, 0f3D3F841F;
fma.rn.f32 %f13, %f11, %f8, %f12;
mov.f32 %f14, 0f3D994929;
fma.rn.f32 %f15, %f13, %f8, %f14;
mov.f32 %f16, 0f3E2AAB94;
fma.rn.f32 %f17, %f15, %f8, %f16;
mul.f32 %f18, %f8, %f17;
fma.rn.f32 %f19, %f18, %f7, %f7;
add.f32 %f20, %f19, %f19;
mov.f32 %f21, 0f3FC90FDB;
sub.f32 %f22, %f21, %f19;
selp.f32 %f23, %f20, %f22, %p6;
setp.lt.f32 %p7, %f1, 0f00000000;
mov.f32 %f24, 0f40490FDB;
sub.f32 %f25, %f24, %f23;
selp.f32 %f26, %f25, %f23, %p7;
cvta.to.global.u64 %rd6, %rd1;
add.s64 %rd7, %rd6, %rd4;
st.global.f32 [%rd7], %f26;
$L__BB0_2:
ret;
}
`
)