forked from Zyko0/go-opencl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
command_queue.go
144 lines (126 loc) · 4.73 KB
/
command_queue.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
package middleCL
import (
constants "github.com/opencl-pure/constantsCL"
pure "github.com/opencl-pure/pureCL"
"unsafe"
)
type CommandQueue struct {
C pure.CommandQueue
}
func (cq *CommandQueue) EnqueueBarrier() error {
return pure.StatusToErr(pure.EnqueueBarrier(cq.C))
}
func (cq *CommandQueue) EnqueueNDRangeKernel(kernel *Kernel, workDim uint, globalOffsets, globalWorkSizes, localWorkSizes []uint64) error {
var offsets, gsizes, lsizes []pure.Size
if len(globalOffsets) > 0 {
offsets = make([]pure.Size, len(globalOffsets))
for i := range globalOffsets {
offsets[i] = pure.Size(globalOffsets[i])
}
}
if len(globalWorkSizes) > 0 {
gsizes = make([]pure.Size, len(globalWorkSizes))
for i := range globalWorkSizes {
gsizes[i] = pure.Size(globalWorkSizes[i])
}
}
if len(localWorkSizes) > 0 {
lsizes = make([]pure.Size, len(localWorkSizes))
for i := range localWorkSizes {
lsizes[i] = pure.Size(localWorkSizes[i])
}
}
return pure.StatusToErr(pure.EnqueueNDRangeKernel(
cq.C, kernel.K, workDim, offsets, gsizes, lsizes, 0, nil, nil,
))
}
func (cq *CommandQueue) EnqueueReadBuffer(buffer *Buffer, blockingRead bool, data *pure.BufferData) error {
return pure.StatusToErr(pure.EnqueueReadBuffer(
cq.C, buffer.B, blockingRead, 0, pure.Size(data.DataSize), data.Pointer, 0, nil, nil,
))
}
func (cq *CommandQueue) EnqueueReadImage(image *Image, blockingRead bool, data *pure.ImageData) error {
origin := [3]pure.Size{pure.Size(data.Origin[0]), pure.Size(data.Origin[1]), pure.Size(data.Origin[2])}
region := [3]pure.Size{pure.Size(data.Region[0]), pure.Size(data.Region[1]), pure.Size(data.Region[2])}
return pure.StatusToErr(pure.EnqueueReadImage(
cq.C, image.B, blockingRead, origin, region, 0, 0, data.Pointer, 0, nil, nil,
))
}
func (cq *CommandQueue) EnqueueWriteImage(image *Image, blockingRead bool, data *pure.ImageData) error {
origin := [3]pure.Size{pure.Size(data.Origin[0]), pure.Size(data.Origin[1]), pure.Size(data.Origin[2])}
region := [3]pure.Size{pure.Size(data.Region[0]), pure.Size(data.Region[1]), pure.Size(data.Region[2])}
return pure.StatusToErr(pure.EnqueueWriteImage(
cq.C, image.B, blockingRead, origin, region, 0, 0, data.Pointer, 0, nil, nil,
))
}
func (cq *CommandQueue) EnqueueWriteBuffer(buffer *Buffer, blockingWrite bool, data *pure.BufferData) error {
return pure.StatusToErr(pure.EnqueueWriteBuffer(
cq.C, buffer.B, blockingWrite, 0, pure.Size(data.DataSize), data.Pointer, 0, nil, nil,
))
}
func (cq *CommandQueue) EnqueueMapBuffer(buffer Buffer, blockingMap bool, flags []pure.MapFlag, data *pure.BufferData) error {
var st pure.Status
mapFlags := pure.MapFlag(0)
for _, f := range flags {
mapFlags |= f
}
ptr := pure.EnqueueMapBuffer(
cq.C, buffer.B, blockingMap, mapFlags, 0, pure.Size(data.DataSize), 0, nil, nil, &st,
)
if st != constants.CL_SUCCESS {
return pure.StatusToErr(st)
}
data.Pointer = unsafe.Pointer(ptr)
return nil
}
func (cq *CommandQueue) EnqueueMapImage(image Buffer, blockingMap bool, flags []pure.MapFlag, data *pure.ImageData) error {
var st pure.Status
mapFlags := pure.MapFlag(0)
for _, f := range flags {
mapFlags |= f
}
origin := [3]pure.Size{pure.Size(data.Origin[0]), pure.Size(data.Origin[1]), pure.Size(data.Origin[2])}
region := [3]pure.Size{pure.Size(data.Region[0]), pure.Size(data.Region[1]), pure.Size(data.Region[2])}
rowpitch, slicepitch := (*pure.Size)(&data.RowPitch), (*pure.Size)(&data.SlicePitch)
ptr := pure.EnqueueMapImage(
cq.C, image.B, blockingMap, mapFlags, origin, region, rowpitch, slicepitch, 0, nil, nil, &st,
)
if st != constants.CL_SUCCESS {
return pure.StatusToErr(st)
}
data.Pointer = unsafe.Pointer(ptr)
return nil
}
func (cq *CommandQueue) EnqueueUnmapBuffer(buffer Buffer, data *pure.BufferData) error {
return pure.StatusToErr(pure.EnqueueUnmapMemObject(
cq.C, buffer.B, data.Pointer, 0, nil, nil,
))
}
func (cq *CommandQueue) Finish() error {
return pure.StatusToErr(pure.FinishCommandQueue(cq.C))
}
func (cq *CommandQueue) Flush() error {
return pure.StatusToErr(pure.FlushCommandQueue(cq.C))
}
func (cq *CommandQueue) Release() error {
return pure.StatusToErr(pure.ReleaseCommandQueue(cq.C))
}
// GL
func (cq *CommandQueue) EnqueueAcquireGLObjects(objects []Buffer) error {
obsCL := make([]pure.Buffer, len(objects))
for i := 0; i < len(obsCL); i++ {
obsCL[i] = objects[i].B
}
return pure.StatusToErr(pure.EnqueueAcquireGLObjects(
cq.C, uint32(len(objects)), unsafe.Pointer(&obsCL[0]), 0, nil, nil,
))
}
func (cq *CommandQueue) EnqueueReleaseGLObjects(objects []Buffer) error {
obsCL := make([]pure.Buffer, len(objects))
for i := 0; i < len(obsCL); i++ {
obsCL[i] = objects[i].B
}
return pure.StatusToErr(pure.EnqueueReleaseGLObjects(
cq.C, uint32(len(objects)), unsafe.Pointer(&obsCL[0]), 0, nil, nil,
))
}