func CLCreateContextFromType(properties []CL_context_properties, device_type CL_device_type, pfn_notify CL_ctx_notify, user_data unsafe.Pointer, errcode_ret *CL_int) CL_context { var c_errcode_ret C.cl_int var c_context C.cl_context if pfn_notify == nil && user_data != nil { c_errcode_ret = CL_INVALID_VALUE c_context = nil } else { var c_properties []C.cl_context_properties var c_properties_ptr *C.cl_context_properties if properties != nil { c_properties = make([]C.cl_context_properties, len(properties)) for i := 0; i < len(properties); i++ { c_properties[i] = C.cl_context_properties(properties[i]) } c_properties_ptr = &c_properties[0] } else { c_properties_ptr = nil } if pfn_notify != nil { //var c_user_data []unsafe.Pointer //c_user_data = make([]unsafe.Pointer, 2) arr := C.allocArray(2) c_user_data := (*[2]C.pVoid)(unsafe.Pointer(arr))[:] c_user_data[0] = (C.pVoid)(user_data) c_user_data[1] = (C.pVoid)(unsafe.Pointer(&pfn_notify)) ctx_notify[unsafe.Pointer(&pfn_notify)] = pfn_notify c_context = C.CLCreateContextFromType(c_properties_ptr, C.cl_device_type(device_type), unsafe.Pointer(&c_user_data), &c_errcode_ret) C.freeArray(arr) } else { c_context = C.clCreateContextFromType(c_properties_ptr, C.cl_device_type(device_type), nil, nil, &c_errcode_ret) } } if errcode_ret != nil { *errcode_ret = CL_int(c_errcode_ret) } return CL_context{c_context} }
func CLCreateContextFromType(properties []CL_context_properties, device_type CL_device_type, pfn_notify CL_ctx_notify, user_data unsafe.Pointer, errcode_ret *CL_int) CL_context { var c_errcode_ret C.cl_int var c_context C.cl_context if pfn_notify == nil && user_data != nil { c_errcode_ret = CL_INVALID_VALUE c_context = nil } else { var c_properties []C.cl_context_properties var c_properties_ptr *C.cl_context_properties if properties != nil { c_properties = make([]C.cl_context_properties, len(properties)) for i := 0; i < len(properties); i++ { c_properties[i] = C.cl_context_properties(properties[i]) } c_properties_ptr = &c_properties[0] } else { c_properties_ptr = nil } if pfn_notify != nil { var c_user_data []unsafe.Pointer c_user_data = make([]unsafe.Pointer, 2) c_user_data[0] = user_data c_user_data[1] = unsafe.Pointer(&pfn_notify) ctx_notify[c_user_data[1]] = pfn_notify c_context = C.CLCreateContextFromType(c_properties_ptr, C.cl_device_type(device_type), unsafe.Pointer(&c_user_data), &c_errcode_ret) } else { c_context = C.clCreateContextFromType(c_properties_ptr, C.cl_device_type(device_type), nil, nil, &c_errcode_ret) } } if errcode_ret != nil { *errcode_ret = CL_int(c_errcode_ret) } return CL_context{c_context} }
func createParameters(params map[ContextParameter]interface{}) ([]C.cl_context_properties, error) { c_params := make([]C.cl_context_properties, (len(params)<<1)+1) i := 0 for param, value := range params { c_params[i] = C.cl_context_properties(param) switch param { case CONTEXT_PLATFORM: if v, ok := value.(Platform); ok { c_params[i+1] = C.PlatformToContextParameter(v.id) } else { return nil, Cl_error(C.CL_INVALID_VALUE) } default: return nil, Cl_error(C.CL_INVALID_VALUE) } i += 2 } c_params[i] = 0 return c_params, nil }
func CLCreateContext(properties []CL_context_properties, num_devices CL_uint, devices []CL_device_id, pfn_notify CL_ctx_notify, user_data unsafe.Pointer, errcode_ret *CL_int) CL_context { var c_errcode_ret C.cl_int var c_context C.cl_context if num_devices == 0 || devices == nil || (pfn_notify == nil && user_data != nil) { c_errcode_ret = CL_INVALID_VALUE c_context = nil } else { var c_properties []C.cl_context_properties var c_properties_ptr *C.cl_context_properties var c_devices []C.cl_device_id var c_devices_ptr *C.cl_device_id if properties != nil { c_properties = make([]C.cl_context_properties, len(properties)) for i := 0; i < len(properties); i++ { c_properties[i] = C.cl_context_properties(properties[i]) } c_properties_ptr = &c_properties[0] } else { c_properties_ptr = nil } if devices != nil { c_devices = make([]C.cl_device_id, len(devices)) for i := 0; i < len(devices); i++ { c_devices[i] = C.cl_device_id(devices[i].cl_device_id) } c_devices_ptr = &c_devices[0] } else { c_devices_ptr = nil } if pfn_notify != nil { var c_user_data []unsafe.Pointer c_user_data = make([]unsafe.Pointer, 2) c_user_data[0] = user_data c_user_data[1] = unsafe.Pointer(&pfn_notify) ctx_notify[c_user_data[1]] = pfn_notify c_context = C.CLCreateContext(c_properties_ptr, C.cl_uint(len(c_devices)), c_devices_ptr, unsafe.Pointer(&c_user_data), &c_errcode_ret) } else { c_context = C.clCreateContext(c_properties_ptr, C.cl_uint(len(c_devices)), c_devices_ptr, nil, nil, &c_errcode_ret) } } if errcode_ret != nil { *errcode_ret = CL_int(c_errcode_ret) } return CL_context{c_context} }
func CreateContext(platform *Platform, devType DeviceType) *Context { var ctx Context var error C.cl_int properties := []C.cl_context_properties{CL_CONTEXT_PLATFORM, C.platform2property(platform.item), C.cl_context_properties(0)} ctx.item = C.clCreateContextFromType(&properties[0], C.cl_device_type(devType), nil, nil, &error) fmt.Printf("Context error:%d\n", error) return &ctx }