forked from Zyko0/go-opencl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpurego_library_windows.go
148 lines (141 loc) · 3.96 KB
/
purego_library_windows.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
//go:build windows
package pureCL
import (
"errors"
"syscall"
"unsafe"
)
func loadLibrary(paths []string) error {
paths = append(paths, "opencl.dll")
var resultError error
for i := 0; i < len(paths); i++ {
library, err := syscall.LoadLibrary(paths)
if err == nil {
handle = uintptr(library)
return nil
}
resultError = ErrJoin(resultError, err)
}
return errors.New("no path has passed: " + resultError)
}
func initUnsupported(handle syscall.Handle, errIn error) error {
// purego unsupported functions
dll := syscall.DLL{
Name: "opencl.dll",
Handle: handle,
}
// Note: Functions with unsupported arguments requiring syscall loading
readImg, err := dll.FindProc("clEnqueueReadImage")
if err != nil {
errIn = errors.Join(err)
}
mapImg, err := dll.FindProc("clEnqueueMapImage")
if err != nil {
errIn = errors.Join(err)
}
mapBuffer, err := dll.FindProc("clEnqueueMapBuffer")
if err != nil {
errIn = errors.Join(err)
}
writeImg, err := dll.FindProc("clEnqueueWriteImage")
if err != nil {
errIn = errors.Join(err)
}
EnqueueReadImage = func(queue CommandQueue, image Buffer, blockingRead bool, origin, region [3]Size, row_pitch, slice_pitch Size, ptr unsafe.Pointer, numEventsWaitList uint, eventWaitList []Event, event *Event) Status {
block := uintptr(0)
if blockingRead {
block = 1
}
eventList := uintptr(0)
if eventWaitList != nil {
eventList = uintptr(unsafe.Pointer(&eventWaitList[0]))
}
r1, _, _ := readImg.Call(
uintptr(queue),
uintptr(image),
uintptr(block),
uintptr(unsafe.Pointer(&origin[0])),
uintptr(unsafe.Pointer(®ion[0])),
uintptr(row_pitch),
uintptr(slice_pitch),
uintptr(ptr),
uintptr(numEventsWaitList),
eventList,
uintptr(unsafe.Pointer(event)),
)
return Status(r1)
}
EnqueueMapImage = func(queue CommandQueue, image Buffer, blockingMap bool, mapFlags MapFlag, origin, region [3]Size, imageRowPitch, imageSlicePitch *Size, numEventsWaitList uint, eventWaitList []Event, event *Event, errCodeRet *Status) uintptr {
block := uintptr(0)
if blockingMap {
block = 1
}
eventList := uintptr(0)
if eventWaitList != nil {
eventList = uintptr(unsafe.Pointer(&eventWaitList[0]))
}
r1, _, _ := mapImg.Call(
uintptr(queue),
uintptr(image),
uintptr(block),
uintptr(mapFlags),
uintptr(unsafe.Pointer(&origin[:][0])),
uintptr(unsafe.Pointer(®ion[:][0])),
uintptr(unsafe.Pointer(imageRowPitch)),
uintptr(unsafe.Pointer(imageSlicePitch)),
uintptr(numEventsWaitList),
eventList,
uintptr(unsafe.Pointer(event)),
uintptr(unsafe.Pointer(errCodeRet)),
)
return r1
}
EnqueueMapBuffer = func(queue CommandQueue, buffer Buffer, blockingMap bool, mapFlags MapFlag, offset, size Size, numEventsWaitList uint, eventWaitList []Event, event *Event, errCodeRet *Status) uintptr {
block := uintptr(0)
if blockingMap {
block = 1
}
eventList := uintptr(0)
if eventWaitList != nil {
eventList = uintptr(unsafe.Pointer(&eventWaitList[0]))
}
r1, _, _ := mapBuffer.Call(
uintptr(queue),
uintptr(buffer),
uintptr(block),
uintptr(mapFlags),
uintptr(offset),
uintptr(size),
uintptr(numEventsWaitList),
eventList,
uintptr(unsafe.Pointer(event)),
uintptr(unsafe.Pointer(errCodeRet)),
)
return r1
}
EnqueueWriteImage = func(queue CommandQueue, image Buffer, blockingRead bool, origin, region [3]Size, row_pitch, slice_pitch Size, ptr unsafe.Pointer, numEventsWaitList uint, eventWaitList []Event, event *Event) Status {
block := uintptr(0)
if blockingRead {
block = 1
}
eventList := uintptr(0)
if eventWaitList != nil {
eventList = uintptr(unsafe.Pointer(&eventWaitList[0]))
}
r1, _, _ := writeImg.Call(
uintptr(queue),
uintptr(image),
uintptr(block),
uintptr(unsafe.Pointer(&origin[0])),
uintptr(unsafe.Pointer(®ion[0])),
uintptr(row_pitch),
uintptr(slice_pitch),
uintptr(ptr),
uintptr(numEventsWaitList),
eventList,
uintptr(unsafe.Pointer(event)),
)
return Status(r1)
}
return errIn
}