Пример #1
0
func CLGetPlatformIDs(num_entries CL_uint,
	platforms []CL_platform_id,
	num_platforms *CL_uint) CL_int {

	if (num_entries == 0 && platforms != nil) || (num_platforms == nil && platforms == nil) {
		return CL_INVALID_VALUE
	} else {
		var c_errcode_ret C.cl_int
		var c_num_platforms C.cl_uint

		if platforms == nil {
			c_errcode_ret = C.clGetPlatformIDs(C.cl_uint(num_entries),
				nil,
				&c_num_platforms)
		} else {
			c_platforms := make([]C.cl_platform_id, len(platforms))
			c_errcode_ret = C.clGetPlatformIDs(C.cl_uint(num_entries),
				&c_platforms[0],
				&c_num_platforms)
			if c_errcode_ret == C.CL_SUCCESS {
				for i := 0; i < len(platforms); i++ {
					platforms[i].cl_platform_id = c_platforms[i]
				}
			}
		}

		if num_platforms != nil {
			*num_platforms = CL_uint(c_num_platforms)
		}
		return CL_int(c_errcode_ret)
	}
}
Пример #2
0
func GetPlatforms() []Platform {
	var count C.cl_uint
	if ret := C.clGetPlatformIDs(0, (*C.cl_platform_id)(nil), &count); ret != C.CL_SUCCESS || count == 0 {
		return nil
	}

	c_platforms := make([]C.cl_platform_id, count)
	if ret := C.clGetPlatformIDs(count, &c_platforms[0], &count); ret != C.CL_SUCCESS || count == 0 {
		return nil
	}
	platforms := make([]Platform, 0, count)

	for _, pid := range c_platforms {
		if ret := C.clGetDeviceIDs(pid, C.cl_device_type(DEVICE_TYPE_ALL), 0, (*C.cl_device_id)(nil), &count); ret != C.CL_SUCCESS || count == 0 {
			continue
		}

		c_devices := make([]C.cl_device_id, count)
		if ret := C.clGetDeviceIDs(pid, C.cl_device_type(DEVICE_TYPE_ALL), count, &c_devices[0], &count); ret != C.CL_SUCCESS || count == 0 {
			continue
		}

		platform := Platform{
			id:         pid,
			Devices:    make([]Device, count),
			properties: make(map[PlatformProperty]string),
		}
		for i, did := range c_devices {
			platform.Devices[i].id = did
			platform.Devices[i].properties = make(map[DeviceProperty]interface{})
		}
		platforms = append(platforms, platform)
	}
	return platforms
}
Пример #3
0
// Obtain the list of platforms available.
func GetPlatforms() ([]*Platform, error) {
	var platformIds [maxPlatforms]C.cl_platform_id
	var nPlatforms C.cl_uint
	if err := C.clGetPlatformIDs(C.cl_uint(maxPlatforms), &platformIds[0], &nPlatforms); err != C.CL_SUCCESS {
		return nil, toError(err)
	}
	platforms := make([]*Platform, nPlatforms)
	for i := 0; i < int(nPlatforms); i++ {
		platforms[i] = &Platform{id: platformIds[i]}
	}
	return platforms, nil
}
Пример #4
0
func Platforms(num uint) []Platform {
	if num == 0 {
		num = PlatformsNumber()
	}
	platforms := make([]aPlatform, num)
	var realNum C.cl_uint = 0
	C.clGetPlatformIDs(C.cl_uint(num), (*C.cl_platform_id)(&platforms[0]), &realNum)
	res := make([]Platform, realNum)
	var i C.cl_uint
	for i = 0; i < realNum; i++ {
		res[i].item = platforms[i]
	}

	return res
}
Пример #5
0
func getPlatforms() (ps []*Platform, err error) {
	var numPlatforms C.cl_uint
	platformIDs := [maxPlatforms]C.cl_platform_id{}
	platformIDsPtr := (*C.cl_platform_id)(unsafe.Pointer(&platformIDs))

	ret := C.clGetPlatformIDs(maxPlatforms, platformIDsPtr, &numPlatforms)

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

	ps = make([]*Platform, int(numPlatforms))

	for i := 0; i < int(numPlatforms); i++ {
		if ps[i], err = getPlatformByID(platformIDs[i]); err != nil {
			break
		}
	}

	return
}
Пример #6
0
// see https://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clGetPlatformIDs.html
func GetPlatformIDs(numentries uint32, ids *PlatformID, numplatform *uint32) ErrorCode {
	return ErrorCode(C.clGetPlatformIDs(C.cl_uint(numentries), (*C.cl_platform_id)(unsafe.Pointer(ids)), (*C.cl_uint)(numplatform)))
}
Пример #7
0
func PlatformsNumber() uint {
	var numPlatforms C.cl_uint
	C.clGetPlatformIDs(0, nil, &numPlatforms)
	var res uint = uint(numPlatforms)
	return res
}