コード例 #1
0
ファイル: context.go プロジェクト: xfong/tmpCL
func CreateContextUnsafe(properties *C.cl_context_properties, devices []*Device, pfn_notify CL_ctx_notify, user_data unsafe.Pointer) (*Context, error) {
	deviceIds := buildDeviceIdList(devices)
	var err C.cl_int
	var clContext C.cl_context
	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

		clContext = C.CLCreateContext(properties, C.cl_uint(len(devices)), &deviceIds[0], unsafe.Pointer(&c_user_data), &err)
	} else {
		clContext = C.clCreateContext(properties, C.cl_uint(len(devices)), &deviceIds[0], nil, nil, &err)
	}
	if err != C.CL_SUCCESS {
		return nil, toError(err)
	}
	if clContext == nil {
		return nil, ErrUnknown
	}
	context := &Context{clContext: clContext, devices: devices}
	runtime.SetFinalizer(context, releaseContext)
	return context, nil
}
コード例 #2
0
ファイル: package.go プロジェクト: mantyr/cl
// see https://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clCreateContext.html
func CreateContext(properties *ContextProperties, numDevices uint32, devices *DeviceId, notify func(string, unsafe.Pointer, uint64, interface{}), userdata interface{}, errcode *ErrorCode) Context {
	ctx := gocontext{nil, notify, userdata}
	var f *[0]byte
	var u unsafe.Pointer
	if notify != nil {
		f = (*[0]byte)(C.contextErrorCallback)
		u = unsafe.Pointer(&ctx)
	}
	ctx.clContext = C.clCreateContext((*C.cl_context_properties)(unsafe.Pointer(properties)), C.cl_uint(numDevices), (*C.cl_device_id)(unsafe.Pointer(devices)), f, u, (*C.cl_int)(unsafe.Pointer(errcode)))
	return Context(&ctx)
}
コード例 #3
0
ファイル: context.go プロジェクト: xfong/go-opencl
// TODO: properties
func CreateContext(devices []*Device) (*Context, error) {
	deviceIds := buildDeviceIdList(devices)
	var err C.cl_int
	clContext := C.clCreateContext(nil, C.cl_uint(len(devices)), &deviceIds[0], nil, nil, &err)
	if err != C.CL_SUCCESS {
		return nil, toError(err)
	}
	if clContext == nil {
		return nil, ErrUnknown
	}
	context := &Context{clContext: clContext, devices: devices}
	runtime.SetFinalizer(context, releaseContext)
	return context, nil
}
コード例 #4
0
ファイル: context.go プロジェクト: salviati/go-opencl
func NewContextOfDevices(params map[ContextParameter]interface{}, devices []Device) (*Context, error) {
	var c_params []C.cl_context_properties
	var propErr error
	if c_params, propErr = createParameters(params); propErr != nil {
		return nil, propErr
	}

	c_devices := make([]C.cl_device_id, len(devices))
	for i, device := range devices {
		c_devices[i] = device.id
	}

	var c_context C.cl_context
	var err C.cl_int
	if c_context = C.clCreateContext(&c_params[0], C.cl_uint(len(c_devices)), &c_devices[0], nil, nil, &err); err != C.CL_SUCCESS {
		return nil, Cl_error(err)
	}
	context := &Context{id: c_context}
	runtime.SetFinalizer(context, (*Context).release)

	return context, nil
}
コード例 #5
0
ファイル: context.go プロジェクト: xfong/gocl
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}
}