-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathdevice.go
57 lines (46 loc) · 1.34 KB
/
device.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
package opencl
import (
"errors"
"strings"
)
type DeviceType uint32
const (
DeviceTypeDefault DeviceType = 1 << 0
DeviceTypeCPU DeviceType = 1 << 1
DeviceTypeGPU DeviceType = 1 << 2
DeviceTypeAccelerator DeviceType = 1 << 3
DeviceTypeCustom DeviceType = 1 << 4
DeviceTypeAll DeviceType = 0xFFFFFFFF
)
type Device uint
type deviceInfo uint32
const (
deviceInfoType deviceInfo = 0x1000
deviceInfoAddressBits deviceInfo = 0x100D
deviceInfoAvailable deviceInfo = 0x1027
deviceInfoCompilerAvailable deviceInfo = 0x1028
deviceInfoBuiltInKernels deviceInfo = 0x103F
deviceInfoVendor deviceInfo = 0x102C
deviceInfoDriverVersion deviceInfo = 0x102D
deviceInfoExtensions deviceInfo = 0x1030
)
func (d Device) getInfo(name deviceInfo) (string, error) {
size := clSize(0)
st := getDeviceInfo(d, name, clSize(0), nil, &size)
if st != CL_SUCCESS {
return "", errors.New("oops at 1st get device info")
}
info := make([]byte, size)
st = getDeviceInfo(d, name, size, info, nil)
if st != CL_SUCCESS {
return "", errors.New("oops at 2nd get device info")
}
return string(info), nil
}
func (d Device) GetExtensions() ([]Extension, error) {
extensions, err := d.getInfo(deviceInfoExtensions)
if err != nil {
return nil, err
}
return strings.Split(extensions, " "), nil
}