This repository has been archived by the owner on Jan 28, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpipe.go
81 lines (75 loc) · 2.75 KB
/
pipe.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
package cl22
// #include "api.h"
import "C"
import "unsafe"
// PipeProperty is one entry of properties which are taken into account when creating pipes.
type PipeProperty []uintptr
// CreatePipe creates a pipe object.
//
// For the flags parameter, only MemReadWriteFlag and MemHostNoAccessFlag can be specified when creating a pipe object.
// If the value specified for flags is 0, the default is used which is MemReadWriteFlag | MemHostNoAccessFlag.
//
// Since: 2.0
// See also: https://registry.khronos.org/OpenCL/sdk/2.2/docs/man/html/clCreatePipe.html
func CreatePipe(context Context, flags MemFlags, packetSize, maxPackets uint32, properties ...PipeProperty) (MemObject, error) {
var rawPropertyList []uintptr
for _, property := range properties {
rawPropertyList = append(rawPropertyList, property...)
}
var rawProperties unsafe.Pointer
if len(properties) > 0 {
rawPropertyList = append(rawPropertyList, 0)
rawProperties = unsafe.Pointer(&rawPropertyList[0])
}
var status C.cl_int
pipe := C.clCreatePipe(
context.handle(),
C.cl_mem_flags(flags),
C.cl_uint(packetSize),
C.cl_uint(maxPackets),
(*C.cl_pipe_properties)(rawProperties),
&status)
if status != C.CL_SUCCESS {
return 0, StatusError(status)
}
return MemObject(*((*uintptr)(unsafe.Pointer(&pipe)))), nil
}
// PipeInfoName identifies properties of a pipe, which can be queried with PipeInfo().
type PipeInfoName C.cl_pipe_info
const (
// PipePacketSizeInfo returns pipe packet size specified when pipe is created with CreatePipe().
//
// Returned type: uint32
// Since: 2.0
PipePacketSizeInfo PipeInfoName = C.CL_PIPE_PACKET_SIZE
// PipeMaxPacketsInfo returns maximum number of packets specified when pipe is created with CreatePipe().
//
// Returned type: uint32
// Since: 2.0
PipeMaxPacketsInfo PipeInfoName = C.CL_PIPE_MAX_PACKETS
)
// PipeInfo queries information specific to a pipe object.
//
// The provided size need to specify the size of the available space pointed to the provided value in bytes.
//
// The returned number is the required size, in bytes, for the queried information.
// Call the function with a zero size and nil value to request the required size. This helps in determining
// the necessary space for dynamic information, such as arrays.
//
// Raw strings are with a terminating NUL character.
//
// Since: 2.0
// See also: https://registry.khronos.org/OpenCL/sdk/2.2/docs/man/html/clGetPipeInfo.html
func PipeInfo(pipe MemObject, paramName PipeInfoName, paramSize uintptr, paramValue unsafe.Pointer) (uintptr, error) {
sizeReturn := C.size_t(0)
status := C.clGetPipeInfo(
pipe.handle(),
C.cl_pipe_info(paramName),
C.size_t(paramSize),
paramValue,
&sizeReturn)
if status != C.CL_SUCCESS {
return 0, StatusError(status)
}
return uintptr(sizeReturn), nil
}