-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcl.go
More file actions
92 lines (77 loc) · 2.09 KB
/
Copy pathcl.go
File metadata and controls
92 lines (77 loc) · 2.09 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
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
// A wrapper package that attempts to map the OpenCL 1.1 C API to idiomatic Go.
package cl11
import (
"errors"
"fmt"
"reflect"
"strings"
"unsafe"
)
// A reference counted OpenCL object.
type Object interface {
Retain() error
Release() error
ReferenceCount() (int, error)
}
type Profile int
func toProfile(profile string) Profile {
switch profile {
case "FULL_PROFILE":
return FullProfile
case "EMBEDDED_PROFILE":
return EmbeddedProfile
}
panic(errors.New("unknown profile"))
}
func (pp Profile) String() string {
switch pp {
case zeroProfile:
return ""
case FullProfile:
return "full profile"
case EmbeddedProfile:
return "embedded profile"
}
panic("unreachable")
}
type Version struct {
Major int
Minor int
Info string
}
func toVersion(version string) Version {
var result Version
var err error
if strings.HasPrefix(version, "OpenCL C") {
_, err = fmt.Sscanf(version, "OpenCL C %d.%d", &result.Major, &result.Minor)
result.Info = strings.TrimSpace(version[len(fmt.Sprintf("OpenCL C %d.%d", result.Major, result.Minor)):])
} else if strings.HasPrefix(version, "OpenCL") {
_, err = fmt.Sscanf(version, "OpenCL %d.%d", &result.Major, &result.Minor)
result.Info = strings.TrimSpace(version[len(fmt.Sprintf("OpenCL %d.%d", result.Major, result.Minor)):])
} else {
_, err = fmt.Sscanf(version, "%d.%d", &result.Major, &result.Minor)
}
if err != nil {
// Maybe a regexp to try and find a "\d.\d"? It works on nVidia, AMD,
// and Intel atm.
panic("could not parse version string \"" + version + "\"")
}
return result
}
func (v Version) String() string {
if v.Info != "" {
return fmt.Sprintf("%d.%d %s", v.Major, v.Minor, v.Info)
}
return fmt.Sprintf("%d.%d", v.Major, v.Minor)
}
func pointerSize(value interface{}) (unsafe.Pointer, uintptr, error) {
v := reflect.ValueOf(value)
switch v.Kind() {
// case reflect.Ptr:
case reflect.Slice:
pointer := unsafe.Pointer(&(*reflect.SliceHeader)(unsafe.Pointer(v.Pointer())).Data)
size := v.Type().Elem().Size() * uintptr(v.Len())
return pointer, size, nil
}
return unsafe.Pointer(uintptr(0)), 0, ErrNotAddressable
}