Exemple #1
0
///////////////////////////////////////////////
//OpenCL 1.2
///////////////////////////////////////////////
func CLCreateSubDevices(in_device CL_device_id,
	properties []CL_device_partition_property,
	num_devices CL_uint,
	out_devices []CL_device_id,
	num_devices_ret *CL_uint) CL_int {

	if (num_devices == 0 && out_devices != nil) || (out_devices == nil && num_devices_ret == nil) {
		return CL_INVALID_VALUE
	} else {
		var c_properties []C.cl_device_partition_property
		var c_properties_ptr *C.cl_device_partition_property

		if properties != nil {
			c_properties = make([]C.cl_device_partition_property, len(properties))
			for i := 0; i < len(properties); i++ {
				c_properties[i] = C.cl_device_partition_property(properties[i])
			}
			c_properties_ptr = &c_properties[0]
		} else {
			c_properties_ptr = nil
		}

		var c_errcode_ret C.cl_int
		var c_num_devices_ret C.cl_uint

		if out_devices == nil {
			c_errcode_ret = C.clCreateSubDevices(in_device.cl_device_id,
				c_properties_ptr,
				C.cl_uint(num_devices),
				nil,
				&c_num_devices_ret)
		} else {
			c_out_devices := make([]C.cl_device_id, len(out_devices))
			c_errcode_ret = C.clCreateSubDevices(in_device.cl_device_id,
				c_properties_ptr,
				C.cl_uint(num_devices),
				&c_out_devices[0],
				&c_num_devices_ret)
			if c_errcode_ret == C.CL_SUCCESS {
				for i := 0; i < len(out_devices); i++ {
					out_devices[i].cl_device_id = c_out_devices[i]
				}
			}
		}

		if num_devices_ret != nil {
			*num_devices_ret = CL_uint(c_num_devices_ret)
		}
		return CL_int(c_errcode_ret)
	}
}
Exemple #2
0
func (d *Device) PartitionDeviceEqually(n int) ([]*Device, error) {
	var deviceList []C.cl_device_id
	var deviceCount C.cl_uint
	defer C.free(deviceList)
	defer C.free(deviceCount)
	err := C.clCreateSubDevices(d.nullableId(), C.partitionDeviceEqually((C.uint)(n)), 1, &deviceList[0], &deviceCount)
	if toError(err) != nil {
		return nil, toError(err)
	}
	val := make([]*Device, int(deviceCount))
	for idx := range val {
		val[idx].id = deviceList[idx]
	}
	return val, nil
}
Exemple #3
0
func (d *Device) PartitionDeviceByNextPartitionableDomain(n []int) ([]*Device, error) {
	var deviceList []C.cl_device_id
	var deviceCount C.cl_uint
	defer C.free(deviceList)
	defer C.free(deviceCount)

	Counts := make([]C.uint, len(n))
	defer C.free(Counts)
	for ii, nn := range n {
		Counts[ii] = (C.uint)(nn)
	}
	err := C.clCreateSubDevices(d.nullableId(), C.partitionDeviceByNextPartitionable(), 1, &deviceList[0], &deviceCount)
	if toError(err) != nil {
		return nil, toError(err)
	}
	val := make([]*Device, int(deviceCount))
	for idx := range val {
		val[idx].id = deviceList[idx]
	}
	return val, nil
}