Esempio n. 1
0
File: package.go Progetto: mantyr/cl
// see https://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clCreateProgramWithBinary.html
func CreateProgramWithBinary(context Context, numDevices uint32, devices *DeviceId, lengths *uint64, binaries **uint8, binaryStatus *int32, errcode *ErrorCode) Program {
	return Program(C.clCreateProgramWithBinary(context.clContext,
		C.cl_uint(numDevices),
		(*C.cl_device_id)(unsafe.Pointer(devices)),
		(*C.size_t)(unsafe.Pointer(lengths)),
		(**C.uchar)(unsafe.Pointer(binaries)),
		(*C.cl_int)(unsafe.Pointer(binaryStatus)),
		(*C.cl_int)(unsafe.Pointer(errcode))))
}
Esempio n. 2
0
func (ctx *Context) CreateProgramWithBinary(deviceList []*Device, program_lengths []int, program_binaries []*uint8) (*Program, error) {
	var binary_in []*C.uchar
	device_list_in := make([]C.cl_device_id, len(deviceList))
	binary_lengths := make([]C.size_t, len(program_lengths))
	defer C.free(binary_in)
	defer C.free(binary_lengths)
	defer C.free(device_list_in)
	var binErr []C.cl_int
	var err C.cl_int
	for i, bin_val := range program_binaries {
		binary_lengths[i] = C.size_t(program_lengths[i])
		binary_in[i] = (*C.uchar)(bin_val)
	}
	for i, devItem := range deviceList {
		device_list_in[i] = devItem.id
	}
	clProgram := C.clCreateProgramWithBinary(ctx.clContext, C.cl_uint(len(deviceList)), &device_list_in[0], &binary_lengths[0], &binary_in[0], &binErr[0], &err)
	for i := range binary_lengths {
		if binErr[i] != C.CL_SUCCESS {
			errMsg := int(binErr[i])
			switch errMsg {
			default:
				fmt.Printf("Unknown error when loading binary %d \n", i)
			case C.CL_INVALID_VALUE:
				fmt.Printf("Loading empty binary %d \n", i)
			case C.CL_INVALID_BINARY:
				fmt.Printf("Loading an invalid binary %d \n", i)
			}
		}
	}
	if err != C.CL_SUCCESS {
		return nil, toError(err)
	}
	if clProgram == nil {
		return nil, ErrUnknown
	}
	program := &Program{clProgram: clProgram, devices: ctx.devices}
	runtime.SetFinalizer(program, releaseProgram)
	return program, nil
}
Esempio n. 3
0
func CLCreateProgramWithBinary(context CL_context,
	num_devices CL_uint,
	devices []CL_device_id,
	lengths []CL_size_t,
	binaries [][]byte,
	binary_status []CL_int,
	errcode_ret *CL_int) CL_program {

	if num_devices == 0 ||
		len(devices) != int(num_devices) ||
		len(lengths) != int(num_devices) ||
		len(binaries) != int(num_devices) ||
		len(binary_status) != int(num_devices) {
		if errcode_ret != nil {
			*errcode_ret = CL_INVALID_VALUE
		}
		return CL_program{nil}
	}

	for i := 0; i < int(num_devices); i++ {
		if binaries[i] == nil || lengths[i] == 0 {
			if errcode_ret != nil {
				*errcode_ret = CL_INVALID_VALUE
			}
			return CL_program{nil}
		}
	}

	var c_program C.cl_program
	var c_devices []C.cl_device_id
	var c_lengths []C.size_t
	var c_binaries []*C.uchar
	var c_status []C.cl_int
	var c_errcode_ret C.cl_int

	c_devices = make([]C.cl_device_id, num_devices)
	c_lengths = make([]C.size_t, num_devices)
	c_binaries = make([]*C.uchar, num_devices)
	c_status = make([]C.cl_int, num_devices)
	for i := CL_uint(0); i < num_devices; i++ {
		c_devices[i] = devices[i].cl_device_id
		c_lengths[i] = C.size_t(lengths[i])
		c_binaries[i] = (*C.uchar)(C.malloc(c_lengths[i]))
		C.memcpy(unsafe.Pointer(c_binaries[i]), unsafe.Pointer(&binaries[i][0]), c_lengths[i])
		defer C.free(unsafe.Pointer(c_binaries[i]))
	}

	c_program = C.clCreateProgramWithBinary(context.cl_context,
		C.cl_uint(num_devices),
		&c_devices[0],
		&c_lengths[0],
		&c_binaries[0],
		&c_status[0],
		&c_errcode_ret)

	for i := CL_uint(0); i < num_devices; i++ {
		binary_status[i] = CL_int(c_status[i])
	}

	if errcode_ret != nil {
		*errcode_ret = CL_int(c_errcode_ret)
	}

	return CL_program{c_program}
}