-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathplatforminfo.go
More file actions
61 lines (50 loc) · 1.46 KB
/
platforminfo.go
File metadata and controls
61 lines (50 loc) · 1.46 KB
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
// Code generated go generate DO NOT EDIT.
package opencl
/*
#include <stdlib.h>
#ifdef __APPLE__
#include <OpenCL/opencl.h>
#else
#include <CL/cl.h>
#endif
*/
import "C"
import (
"fmt"
"strings"
"unsafe"
)
func (p Platform) getInfoString(name string, id C.cl_platform_info) (string, error) {
var n C.size_t
if err := C.clGetPlatformInfo(p.id, id, 0, nil, &n); err != C.CL_SUCCESS {
return "", fmt.Errorf("error getting length of platform info %s: %d", name, err)
}
buf := make([]C.char, n)
if err := C.clGetPlatformInfo(p.id, id, n, unsafe.Pointer(&buf[0]), nil); err != C.CL_SUCCESS {
return "", fmt.Errorf("error getting platform info %s: %d", name, err)
}
return C.GoString(&buf[0]), nil
}
func (p Platform) dummyUseStrings() []string {
// a dummy function so that strings is not unused even if template space-delim is not used
return strings.Split("", "")
}
func (p Platform) Profile() (string, error) {
return p.getInfoString("Profile", C.CL_PLATFORM_PROFILE)
}
func (p Platform) Version() (string, error) {
return p.getInfoString("Version", C.CL_PLATFORM_VERSION)
}
func (p Platform) Name() (string, error) {
return p.getInfoString("Name", C.CL_PLATFORM_NAME)
}
func (p Platform) Vendor() (string, error) {
return p.getInfoString("Vendor", C.CL_PLATFORM_VENDOR)
}
func (p Platform) Extension() ([]string, error) {
str, err := p.getInfoString("Extension", C.CL_PLATFORM_EXTENSIONS)
if err != nil {
return nil, err
}
return strings.Split(str, " "), nil
}