-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathplatform.go
40 lines (33 loc) · 823 Bytes
/
platform.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
package opencl
/*
#ifdef __APPLE__
#include <OpenCL/opencl.h>
#else
#include <CL/cl.h>
#endif
*/
import "C"
import (
"fmt"
)
type Platform struct {
id C.cl_platform_id
}
func GetPlatforms() ([]Platform, error) {
var num_platforms C.cl_uint
if err := C.clGetPlatformIDs(0, nil, &num_platforms); err != C.CL_SUCCESS {
return nil, fmt.Errorf("error getting number of platforms: %d", err)
}
ids := make([]C.cl_platform_id, num_platforms)
if err := C.clGetPlatformIDs(num_platforms, &ids[0], nil); err != C.CL_SUCCESS {
return nil, fmt.Errorf("error getting platforms: %d", err)
}
platforms := make([]Platform, num_platforms)
for i, id := range ids {
platforms[i].id = id
}
return platforms, nil
}
func (p Platform) Devices(deviceType DeviceType) ([]Device, error) {
return getDevices(p, deviceType)
}