Exemple #1
0
func CreateContextFromTypeUnsafe(properties *C.cl_context_properties, device_type C.cl_device_type, pfn_notify CL_ctx_notify, user_data unsafe.Pointer) (*Context, error) {
	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.CLCreateContextFromType(properties, device_type, unsafe.Pointer(&c_user_data), &err)
	} else {
		clContext = C.clCreateContextFromType(properties, device_type, nil, nil, &err)
	}
	if err != C.CL_SUCCESS {
		return nil, toError(err)
	}
	if clContext == nil {
		return nil, ErrUnknown
	}
	contextTmp := &Context{clContext: clContext, devices: nil}
	cDevices, errD := contextTmp.GetDevices()
	if errD != nil {
		runtime.SetFinalizer(contextTmp, releaseContext)
		return contextTmp, toError(err)
	}
	context := &Context{clContext: clContext, devices: cDevices}
	runtime.SetFinalizer(context, releaseContext)
	return context, nil
}
Exemple #2
0
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}
}
Exemple #3
0
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}
}