Ejemplo n.º 1
0
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
}
Ejemplo n.º 2
0
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}
}