示例#1
0
func CLBuildProgram(program CL_program,
	num_devices CL_uint,
	devices []CL_device_id,
	options []byte,
	pfn_notify CL_prg_notify,
	user_data unsafe.Pointer) CL_int {

	if (num_devices == 0 && devices != nil) ||
		(num_devices != 0 && devices == nil) ||
		(pfn_notify == nil && user_data != nil) {
		return CL_INVALID_VALUE
	}

	var c_devices []C.cl_device_id
	var c_options *C.char
	var c_errcode_ret C.cl_int

	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)
	}
	if options != nil {
		c_options = C.CString(string(options))
		defer C.free(unsafe.Pointer(c_options))
	} else {
		c_options = nil
	}

	if pfn_notify != nil {
		prg_notify[program.cl_program] = pfn_notify

		c_errcode_ret = C.CLBuildProgram(program.cl_program,
			C.cl_uint(num_devices),
			&c_devices[0],
			c_options,
			user_data)
	} else {
		c_errcode_ret = C.clBuildProgram(program.cl_program,
			C.cl_uint(num_devices),
			&c_devices[0],
			c_options,
			nil,
			nil)
	}

	return CL_int(c_errcode_ret)
}
示例#2
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}
}