-
Notifications
You must be signed in to change notification settings - Fork 64
/
params.go
147 lines (132 loc) · 3.53 KB
/
params.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
package cu
/*
#include <cuda.h>
void handleCUDACB(void* fn);
void CallHostFunc(void* fn){
handleCUDACB(fn);
};
*/
import "C"
import "unsafe"
// KernelNodeParams represents the parameters to launch a kernel in a graph node.
type KernelNodeParams struct {
Func Function
GridDimX uint
GridDimY uint
GridDimZ uint
BlockDimX uint
BlockDimY uint
BlockDimZ uint
SharedMemBytes uint
Params []*KernelNodeParams
}
func (p *KernelNodeParams) c() *C.CUDA_KERNEL_NODE_PARAMS {
// here anonymous initialization of struct fields is used because `func` is a keyword.
// see also: https://github.com/golang/go/issues/41968
retVal := &C.CUDA_KERNEL_NODE_PARAMS{
_func: p.Func.fn,
gridDimX: C.uint(p.GridDimX),
gridDimY: C.uint(p.GridDimY),
gridDimZ: C.uint(p.GridDimZ),
blockDimX: C.uint(p.BlockDimX),
blockDimY: C.uint(p.BlockDimY),
blockDimZ: C.uint(p.BlockDimZ),
sharedMemBytes: C.uint(p.SharedMemBytes),
}
return retVal
}
// HostNodeParams are parameters passed in to a node that will call a host function (i.e. a function written in Go)
type HostNodeParams struct {
Func HostFunction
Data unsafe.Pointer
registered bool
ptr unsafe.Pointer
}
func (p *HostNodeParams) c() *C.CUDA_HOST_NODE_PARAMS {
var ptr unsafe.Pointer
if p.registered {
ptr = p.ptr
} else {
ptr = RegisterFunc(p.Func)
p.ptr = ptr
p.registered = true
}
return &C.CUDA_HOST_NODE_PARAMS{
fn: C.CUhostFn(C.CallHostFunc),
userData: ptr, // userData is basically the Go function to call.
}
}
type CopyParams struct {
SrcXInBytes uint64
SrcY uint64
SrcZ uint64
SrcLOD uint64
SrcType MemoryType
SrcHost unsafe.Pointer
SrcDevicePtr DevicePtr
SrcArray Array
Reserved0 unsafe.Pointer
SrcPitch uint64
SrcHeight uint64
DstXInBytes uint64
DstY uint64
DstZ uint64
DstLOD uint64
DstType MemoryType
DstHost unsafe.Pointer
DstDevicePtr DevicePtr
DstArray Array
Reserved1 unsafe.Pointer
DstPitch uint64
DstHeight uint64
WidthInBytes uint64
Height uint64
Depth uint64
}
func (p *CopyParams) c() *C.CUDA_MEMCPY3D {
return &C.CUDA_MEMCPY3D{
srcXInBytes: C.size_t(p.SrcXInBytes),
srcY: C.size_t(p.SrcY),
srcZ: C.size_t(p.SrcZ),
srcLOD: C.size_t(p.SrcLOD),
srcMemoryType: C.CUmemorytype(p.SrcType),
srcHost: p.SrcHost,
srcDevice: C.CUdeviceptr(p.SrcDevicePtr),
srcArray: p.SrcArray.c(),
reserved0: nil,
srcPitch: C.size_t(p.SrcPitch),
srcHeight: C.size_t(p.SrcHeight),
dstXInBytes: C.size_t(p.DstXInBytes),
dstY: C.size_t(p.DstY),
dstZ: C.size_t(p.DstZ),
dstLOD: C.size_t(p.DstLOD),
dstMemoryType: C.CUmemorytype(p.DstType),
dstHost: p.DstHost,
dstDevice: C.CUdeviceptr(p.DstDevicePtr),
dstArray: p.DstArray.c(),
reserved1: nil,
dstPitch: C.size_t(p.DstPitch),
dstHeight: C.size_t(p.DstHeight),
WidthInBytes: C.size_t(p.WidthInBytes),
Height: C.size_t(p.Height),
Depth: C.size_t(p.Depth),
}
}
type MemsetParams struct {
Dst DevicePtr
Pitch uint64
Value uint
ElementSize uint
Width uint64
Height uint64
}
func (p *MemsetParams) c() *C.CUDA_MEMSET_NODE_PARAMS {
return &C.CUDA_MEMSET_NODE_PARAMS{
dst: C.CUdeviceptr(p.Dst),
pitch: C.size_t(p.Pitch),
value: C.uint(p.Value),
elementSize: C.uint(p.ElementSize),
width: C.size_t(p.Width),
height: C.size_t(p.Height),
}
}