Esempio n. 1
0
func (ctx *Context) GetNumberOfDevices() (int, error) {
	if ctx.clContext != nil {
		var outCount C.cl_uint
		err := C.clGetContextInfo(ctx.clContext, C.cl_context_info(ContextNumDevices), C.size_t(unsafe.Sizeof(outCount)), unsafe.Pointer(&outCount), nil)
		return int(outCount), toError(err)
	}
	return 0, toError(C.CL_INVALID_CONTEXT)
}
Esempio n. 2
0
func (context *Context) Property(prop ContextProperty) (interface{}, error) {
	var data interface{}
	var length C.size_t
	var ret C.cl_int

	switch prop {
	/*case CONTEXT_D3D10_PREFER_SHARED_RESOURCES_KHR:
	var val C.cl_bool
	ret = C.clGetContextInfo(context.id, C.cl_context_info(prop), C.size_t(unsafe.Sizeof(val)), unsafe.Pointer(&val), &length)
	data = val == C.CL_TRUE
	*/

	case CONTEXT_REFERENCE_COUNT,
		CONTEXT_NUM_DEVICES:
		var val C.cl_uint
		ret = C.clGetContextInfo(context.id, C.cl_context_info(prop), C.size_t(unsafe.Sizeof(val)), unsafe.Pointer(&val), &length)
		data = val

	case CONTEXT_DEVICES:
		if data, err := context.Property(CONTEXT_NUM_DEVICES); err != nil {
			return nil, err
		} else {
			num_devs := data.(C.cl_uint)
			c_devs := make([]C.cl_device_id, num_devs)
			if ret = C.clGetContextInfo(context.id, C.cl_context_info(prop), C.size_t(num_devs*C.cl_uint(unsafe.Sizeof(c_devs[0]))), unsafe.Pointer(&c_devs[0]), &length); ret != C.CL_SUCCESS {
				return nil, Cl_error(ret)
			}
			devs := make([]Device, length/C.size_t(unsafe.Sizeof(c_devs[0])))
			for i, val := range c_devs {
				devs[i].id = val
			}
			return devs, nil
		}

	default:
		return nil, Cl_error(C.CL_INVALID_VALUE)
	}

	if ret != C.CL_SUCCESS {
		return nil, Cl_error(ret)
	}
	return data, nil
}
Esempio n. 3
0
func (c *Context) Property(prop ContextProperty) interface{} {
	if value, ok := c.properties[prop]; ok {
		return value
	}

	var data interface{}
	var length C.size_t
	var ret C.cl_int

	switch prop {
	case CONTEXT_REFERENCE_COUNT,
		CONTEXT_NUM_DEVICES:
		var val C.cl_uint
		ret = C.clGetContextInfo(c.id, C.cl_context_info(prop), C.size_t(unsafe.Sizeof(val)), unsafe.Pointer(&val), &length)
		data = val

	case CONTEXT_DEVICES:
		if data := c.Property(CONTEXT_NUM_DEVICES); data == nil {
			return nil
		} else {
			num_devs := data.(C.cl_uint)
			c_devs := make([]C.cl_device_id, num_devs)
			if ret = C.clGetContextInfo(c.id, C.cl_context_info(prop), C.size_t(num_devs*C.cl_uint(unsafe.Sizeof(c_devs[0]))), unsafe.Pointer(&c_devs[0]), &length); ret != C.CL_SUCCESS {
				return nil
			}
			devs := make([]Device, length/C.size_t(unsafe.Sizeof(c_devs[0])))
			for i, val := range c_devs {
				devs[i].id = val
			}
			data = devs
		}

	default:
		return nil
	}

	if ret != C.CL_SUCCESS {
		return nil
	}
	c.properties[prop] = data
	return c.properties[prop]
}
Esempio n. 4
0
func (ctx *Context) GetDevices() ([]*Device, error) {
	if ctx.clContext != nil {
		var tmpCount C.cl_device_id
		var outDevices []C.cl_device_id
		var devCount C.size_t
		err := C.clGetContextInfo(ctx.clContext, C.cl_context_info(ContextDevices), C.size_t(unsafe.Sizeof(tmpCount)), unsafe.Pointer(&outDevices), &devCount)
		if int(devCount) != 0 {
			devPtr := make([]*Device, int(devCount))
			for i := range devPtr {
				devPtr[i].id = outDevices[i]
			}
			return devPtr, toError(err)
		}
		return nil, toError(err)
	}
	return nil, toError(C.CL_INVALID_CONTEXT)
}
Esempio n. 5
0
func (ctx *Context) GetProperties() ([]CLContextProperties, error) {
	if ctx.clContext != nil {
		var tmpProperty CLContextProperties
		var tmpList []C.cl_context_properties
		var tmpCount C.size_t
		err := C.clGetContextInfo(ctx.clContext, C.cl_context_info(ContextProperties), C.size_t(unsafe.Sizeof(tmpProperty)), unsafe.Pointer(&tmpList), &tmpCount)
		if toError(err) == nil {
			if tmpCount == 0 {
				return nil, nil
			} else {
				var outList []CLContextProperties
				for i := 0; i < int(tmpCount/C.size_t(unsafe.Sizeof(tmpProperty))); i++ {
					outList[i] = (CLContextProperties)(tmpList[i])
				}
				return outList, nil
			}
		}
		return []CLContextProperties{}, toError(err)
	}
	return []CLContextProperties{}, toError(C.CL_INVALID_CONTEXT)
}
Esempio n. 6
0
File: package.go Progetto: mantyr/cl
// see https://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clGetContextInfo.html
func GetContextInfo(context Context, paramName ContextInfo, paramValueSize uint64, data unsafe.Pointer, paramValueSizeRet *uint64) ErrorCode {
	return ErrorCode(C.clGetContextInfo(context.clContext, C.cl_context_info(paramName), C.size_t(paramValueSize), data, (*C.size_t)(paramValueSizeRet)))
}
Esempio n. 7
0
func CLGetContextInfo(context CL_context,
	param_name CL_context_info,
	param_value_size CL_size_t,
	param_value *interface{},
	param_value_size_ret *CL_size_t) CL_int {

	if (param_value_size == 0 || param_value == nil) && param_value_size_ret == nil {
		return CL_INVALID_VALUE
	} else {
		var c_param_value_size_ret C.size_t
		var c_errcode_ret C.cl_int

		if param_value_size == 0 || param_value == nil {
			c_errcode_ret = C.clGetContextInfo(context.cl_context,
				C.cl_context_info(param_name),
				C.size_t(param_value_size),
				nil,
				&c_param_value_size_ret)
		} else {
			switch param_name {
			case CL_CONTEXT_REFERENCE_COUNT,
				CL_CONTEXT_NUM_DEVICES:

				var value C.cl_uint
				c_errcode_ret = C.clGetContextInfo(context.cl_context,
					C.cl_context_info(param_name),
					C.size_t(param_value_size),
					unsafe.Pointer(&value),
					&c_param_value_size_ret)

				*param_value = CL_uint(value)

			case CL_CONTEXT_DEVICES:
				var param C.cl_device_id
				length := int(C.size_t(param_value_size) / C.size_t(unsafe.Sizeof(param)))

				value1 := make([]C.cl_device_id, length)
				value2 := make([]CL_device_id, length)

				c_errcode_ret = C.clGetContextInfo(context.cl_context,
					C.cl_context_info(param_name),
					C.size_t(param_value_size),
					unsafe.Pointer(&value1[0]),
					&c_param_value_size_ret)

				for i := 0; i < length; i++ {
					value2[i].cl_device_id = value1[i]
				}

				*param_value = value2

			default:
				return CL_INVALID_VALUE
			}
		}

		if param_value_size_ret != nil {
			*param_value_size_ret = CL_size_t(c_param_value_size_ret)
		}

		return CL_int(c_errcode_ret)
	}
}