Beispiel #1
0
func (p *Platform) getInfoString(param C.cl_platform_info) (string, error) {
	var strC [2048]byte
	var strN C.size_t
	if err := C.clGetPlatformInfo(p.id, param, 2048, unsafe.Pointer(&strC[0]), &strN); err != C.CL_SUCCESS || strN < 1 {
		return "", toError(err)
	}
	return string(strC[:strN-1]), nil
}
Beispiel #2
0
func CLGetPlatformInfo(platform CL_platform_id,
	param_name CL_platform_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.clGetPlatformInfo(platform.cl_platform_id,
				C.cl_platform_info(param_name),
				C.size_t(param_value_size),
				nil,
				&c_param_value_size_ret)
		} else {
			switch param_name {
			case CL_PLATFORM_PROFILE,
				CL_PLATFORM_VERSION,
				CL_PLATFORM_NAME,
				CL_PLATFORM_VENDOR,
				CL_PLATFORM_EXTENSIONS:

				value := make([]C.char, param_value_size)
				c_errcode_ret = C.clGetPlatformInfo(platform.cl_platform_id,
					C.cl_platform_info(param_name),
					C.size_t(param_value_size),
					unsafe.Pointer(&value[0]),
					&c_param_value_size_ret)

				*param_value = C.GoStringN(&value[0], C.int(c_param_value_size_ret-1))
			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)
	}
}
Beispiel #3
0
func (p *Platform) Property(prop PlatformProperty) string {
	if value, ok := p.properties[prop]; ok {
		return value
	}

	var count C.size_t
	if ret := C.clGetPlatformInfo(p.id, C.cl_platform_info(prop), 0, nil, &count); ret != C.CL_SUCCESS || count < 1 {
		return ""
	}

	buf := make([]C.char, count)
	if ret := C.clGetPlatformInfo(p.id, C.cl_platform_info(prop), count, unsafe.Pointer(&buf[0]), &count); ret != C.CL_SUCCESS || count < 1 {
		return ""
	}
	p.properties[prop] = C.GoStringN(&buf[0], C.int(count-1))
	return p.properties[prop]
}
Beispiel #4
0
func (pl *Platform) Info(pinfo PlatformInfo) string {
	const bufSize = 4096
	var bufReal C.size_t = 0

	var cStr unsafe.Pointer = unsafe.Pointer(C.malloc(bufSize))
	defer C.free(cStr)

	C.clGetPlatformInfo(pl.item, C.cl_platform_info(pinfo), bufSize, cStr, &bufReal)
	res := C.GoString((*C.char)(cStr))

	return res
}
Beispiel #5
0
	extensions []string
	id         C.cl_platform_id
	name       string
	profile    string
	vendor     string
	version    string
	devices    []*Device
}

const (
	maxPlatforms       = 16
	maxPlatformDevices = 64
)

var getPlatformInfo = makeGetInfo(func(id interface{}, info interface{}, size C.size_t, ptr unsafe.Pointer, retSize *C.size_t) C.cl_int {
	return C.clGetPlatformInfo(id.(C.cl_platform_id), info.(C.cl_platform_info), size, ptr, retSize)
})

func getPlatformByID(id C.cl_platform_id) (p *Platform, err error) {
	var numDevices C.cl_uint
	deviceIDs := [maxPlatformDevices]C.cl_device_id{}
	deviceIDsPtr := (*C.cl_device_id)(unsafe.Pointer(&deviceIDs))

	ret := C.clGetDeviceIDs(id, C.CL_DEVICE_TYPE_ALL, C.cl_uint(maxPlatformDevices), deviceIDsPtr, &numDevices)

	if ret != 0 {
		err = newError(ret)
		return
	}

	p = &Platform{
Beispiel #6
0
// see https://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clGetPlatformInfo.html
func GetPlatformInfo(pid PlatformID, paramName PlatformInfo, paramValueSize uint64, data unsafe.Pointer, paramValueSizeRet *uint64) ErrorCode {
	return ErrorCode(C.clGetPlatformInfo(pid, C.cl_platform_info(paramName), C.size_t(paramValueSize), data, (*C.size_t)(paramValueSizeRet)))
}