func GetCurrentDeviceInGlContext(go_ctx_properties []ContextPropertiesId) (*Device, error) { var c_ctx_properties []C.cl_context_properties defer C.free(c_ctx_properties) for i, prop := range go_ctx_properties { c_ctx_properties[i] = (C.cl_context_properties)(prop) } var device C.cl_device_id err := C.CLGetGLContextInfo(&c_ctx_properties[0], (C.cl_gl_context_info)(GLContextCurrentDevice), C.size_t(unsafe.Sizeof(device)), unsafe.Pointer(&device), nil) return &Device{id: device}, toError(err) }
func GetAllDevicesInGlContext(go_ctx_properties []ContextPropertiesId) ([]*Device, error) { var c_ctx_properties []C.cl_context_properties defer C.free(c_ctx_properties) for i, prop := range go_ctx_properties { c_ctx_properties[i] = (C.cl_context_properties)(prop) } var devices []C.cl_device_id var devCnt C.size_t defer C.free(devices) err := C.CLGetGLContextInfo(&c_ctx_properties[0], C.CL_CURRENT_DEVICE_FOR_GL_CONTEXT_KHR, C.size_t(unsafe.Sizeof(devices)), unsafe.Pointer(&devices), &devCnt) devicesL := make([]C.cl_device_id, int(devCnt)) defer C.free(devicesL) err = C.CLGetGLContextInfo(&c_ctx_properties[0], C.CL_CURRENT_DEVICE_FOR_GL_CONTEXT_KHR, devCnt, unsafe.Pointer(&devicesL), &devCnt) if toError(err) != nil { fmt.Printf("cl: failed to get all devices in GetAllDevicesInGlContext \n") return nil, toError(err) } DeviceList := make([]*Device, len(devices)) for i, deviceId := range devicesL { DeviceList[i].id = deviceId } return DeviceList, nil }