Exemplo n.º 1
0
func CLEnqueueReadBuffer(command_queue CL_command_queue,
	buffer CL_mem,
	blocking_read CL_bool,
	offset CL_size_t,
	cb CL_size_t,
	ptr unsafe.Pointer,
	num_events_in_wait_list CL_uint,
	event_wait_list []CL_event,
	event *CL_event) CL_int {

	if (num_events_in_wait_list == 0 && event_wait_list != nil) ||
		(num_events_in_wait_list != 0 && event_wait_list == nil) ||
		int(num_events_in_wait_list) != len(event_wait_list) {
		return CL_INVALID_EVENT_WAIT_LIST
	}

	var c_event C.cl_event
	var c_errcode_ret C.cl_int

	if num_events_in_wait_list != 0 {
		var c_event_wait_list []C.cl_event
		c_event_wait_list = make([]C.cl_event, num_events_in_wait_list)
		for i := 0; i < int(num_events_in_wait_list); i++ {
			c_event_wait_list[i] = event_wait_list[i].cl_event
		}

		c_errcode_ret = C.clEnqueueReadBuffer(command_queue.cl_command_queue,
			buffer.cl_mem,
			C.cl_bool(blocking_read),
			C.size_t(offset),
			C.size_t(cb),
			ptr,
			C.cl_uint(num_events_in_wait_list),
			&c_event_wait_list[0],
			&c_event)
	} else {
		c_errcode_ret = C.clEnqueueReadBuffer(command_queue.cl_command_queue,
			buffer.cl_mem,
			C.cl_bool(blocking_read),
			C.size_t(offset),
			C.size_t(cb),
			ptr,
			0,
			nil,
			&c_event)
	}

	if event != nil {
		event.cl_event = c_event
	}

	return CL_int(c_errcode_ret)
}
Exemplo n.º 2
0
Arquivo: svm20.go Projeto: xfong/gocl
func CLEnqueueSVMMap(command_queue CL_command_queue,
	blocking_map CL_bool,
	map_flags CL_map_flags,
	svm_ptr unsafe.Pointer,
	size CL_size_t,
	num_events_in_wait_list CL_uint,
	event_wait_list []CL_event,
	event *CL_event) CL_int {

	if (num_events_in_wait_list == 0 && event_wait_list != nil) ||
		(num_events_in_wait_list != 0 && event_wait_list == nil) ||
		int(num_events_in_wait_list) != len(event_wait_list) {
		return CL_INVALID_EVENT_WAIT_LIST
	}

	var c_event C.cl_event
	var c_errcode_ret C.cl_int

	if num_events_in_wait_list != 0 {
		var c_event_wait_list []C.cl_event
		c_event_wait_list = make([]C.cl_event, num_events_in_wait_list)
		for i := 0; i < int(num_events_in_wait_list); i++ {
			c_event_wait_list[i] = event_wait_list[i].cl_event
		}

		c_errcode_ret = C.clEnqueueSVMMap(command_queue.cl_command_queue,
			C.cl_bool(blocking_map),
			C.cl_map_flags(map_flags),
			svm_ptr,
			C.size_t(size),
			C.cl_uint(num_events_in_wait_list),
			&c_event_wait_list[0],
			&c_event)
	} else {
		c_errcode_ret = C.clEnqueueSVMMap(command_queue.cl_command_queue,
			C.cl_bool(blocking_map),
			C.cl_map_flags(map_flags),
			svm_ptr,
			C.size_t(size),
			0,
			nil,
			&c_event)
	}

	if event != nil {
		event.cl_event = c_event
	}

	return CL_int(c_errcode_ret)
}
Exemplo n.º 3
0
func (cq *CommandQueue) EnqueueReadImage(i *Image, blocking bool, origin, region [3]Size, rowPitch, slicePitch Size) ([]byte, error) {
	c_blocking := C.cl_bool(C.CL_FALSE)
	if blocking {
		c_blocking = C.CL_TRUE
	}

	size := Size(0)
	if i.Property(IMAGE_DEPTH) == 0 || i.Property(IMAGE_DEPTH) == 1 { // 2D image
		if rowPitch == 0 {
			rowPitch = i.Property(IMAGE_WIDTH) * i.Property(IMAGE_ELEMENT_SIZE)
		}
		size = rowPitch * i.Property(IMAGE_HEIGHT)
	} else {
		if slicePitch == 0 {
			if rowPitch == 0 {
				rowPitch = i.Property(IMAGE_WIDTH) * i.Property(IMAGE_ELEMENT_SIZE)
			}
			slicePitch = rowPitch * i.Property(IMAGE_DEPTH)
		}
		size = slicePitch * i.Property(IMAGE_DEPTH)
	}
	bytes := make([]byte, size)

	if ret := C.clEnqueueReadImage(
		cq.id, i.id, c_blocking,
		(*C.size_t)(unsafe.Pointer(&origin[0])), (*C.size_t)(unsafe.Pointer(&region[0])),
		C.size_t(rowPitch), C.size_t(slicePitch), unsafe.Pointer(&bytes[0]),
		0, nil, nil); ret != C.CL_SUCCESS {
		return nil, Cl_error(ret)
	}
	return bytes, nil
}
Exemplo n.º 4
0
func (cq *CommandQueue) EnqueueWriteImage(img *Image, blocking bool, origin, region [3]Size, rowPitch, slicePitch Size, data []byte) error {
	c_blocking := C.cl_bool(C.CL_FALSE)
	if blocking {
		c_blocking = C.CL_TRUE
	}

	if ret := C.clEnqueueWriteImage(
		cq.id, img.id, c_blocking,
		(*C.size_t)(unsafe.Pointer(&origin[0])), (*C.size_t)(unsafe.Pointer(&region[0])),
		C.size_t(rowPitch), C.size_t(slicePitch),
		unsafe.Pointer(&data[0]),
		C.cl_uint(0), nil, nil); ret != C.CL_SUCCESS {
		return Cl_error(ret)
	}
	return nil
}
Exemplo n.º 5
0
func (c *Context) NewSampler(normalizedCoords bool, addressingMode AddressingMode, filterMode FilterMode) (*Sampler, error) {
	var c_sampler C.cl_sampler
	var err C.cl_int

	cNormalizedCoords := C.cl_bool(C.CL_FALSE)
	if normalizedCoords {
		cNormalizedCoords = C.CL_TRUE
	}

	if c_sampler = C.clCreateSampler(c.id, cNormalizedCoords, C.cl_addressing_mode(addressingMode), C.cl_filter_mode(filterMode), &err); err != C.CL_SUCCESS {
		return nil, Cl_error(err)
	}

	sampler := &Sampler{id: c_sampler}
	runtime.SetFinalizer(sampler, (*Sampler).release)

	return sampler, nil
}
Exemplo n.º 6
0
func CLCreateSampler(context CL_context,
	normalized_coords CL_bool,
	addressing_mode CL_addressing_mode,
	filter_mode CL_filter_mode,
	errcode_ret *CL_int) CL_sampler {

	var c_errcode_ret C.cl_int
	var c_sampler C.cl_sampler

	c_sampler = C.clCreateSampler(context.cl_context,
		C.cl_bool(normalized_coords),
		C.cl_addressing_mode(addressing_mode),
		C.cl_filter_mode(filter_mode),
		&c_errcode_ret)

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

	return CL_sampler{c_sampler}
}
Exemplo n.º 7
0
Arquivo: package.go Projeto: mantyr/cl
// see https://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clEnqueueMapImage.html
func EnqueueMapImage(cq CommandQueue, image Mem, blocking_map Bool, map_flags MapFlags, origin3 *uint64, region3 *uint64, image_row_pitch *uint64, image_slice_pitch *uint64, num_events_in_wait_list uint32, event_wait_list *Event, event *Event, errcode_ret *int32) unsafe.Pointer {
	return unsafe.Pointer(C.clEnqueueMapImage(cq, image, C.cl_bool(blocking_map), C.cl_map_flags(map_flags), (*C.size_t)(unsafe.Pointer(origin3)), (*C.size_t)(unsafe.Pointer(region3)), (*C.size_t)(unsafe.Pointer(image_row_pitch)), (*C.size_t)(unsafe.Pointer(image_slice_pitch)), C.cl_uint(num_events_in_wait_list), (*C.cl_event)(unsafe.Pointer(event_wait_list)), (*C.cl_event)(unsafe.Pointer(event)), (*C.cl_int)(unsafe.Pointer(errcode_ret))))
}
Exemplo n.º 8
0
Arquivo: package.go Projeto: mantyr/cl
// see https://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clEnqueueMapBuffer.html
func EnqueueMapBuffer(cq CommandQueue, buffer Mem, blocking_map Bool, map_flags uint64, offset uint64, size uint64, num_events_in_wait_list uint32, event_wait_list *Event, event *Event, errcode_ret *int32) unsafe.Pointer {
	return unsafe.Pointer(C.clEnqueueMapBuffer(cq, buffer, C.cl_bool(blocking_map), C.cl_map_flags(map_flags), C.size_t(offset), C.size_t(size), C.cl_uint(num_events_in_wait_list), (*C.cl_event)(unsafe.Pointer(event_wait_list)), (*C.cl_event)(unsafe.Pointer(event)), (*C.cl_int)(unsafe.Pointer(errcode_ret))))
}
Exemplo n.º 9
0
Arquivo: package.go Projeto: mantyr/cl
// see https://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clEnqueueWriteImage.html
func EnqueueWriteImage(cq CommandQueue, image Mem, blocking_write Bool, origin3 *uint64, region3 *uint64, input_row_pitch uint64, input_slice_pitch uint64, ptr unsafe.Pointer, num_events_in_wait_list uint32, event_wait_list *Event, event *Event) ErrorCode {
	return ErrorCode(C.clEnqueueWriteImage(cq, image, C.cl_bool(blocking_write), (*C.size_t)(unsafe.Pointer(origin3)), (*C.size_t)(unsafe.Pointer(region3)), C.size_t(input_row_pitch), C.size_t(input_slice_pitch), unsafe.Pointer(ptr), C.cl_uint(num_events_in_wait_list), (*C.cl_event)(unsafe.Pointer(event_wait_list)), (*C.cl_event)(unsafe.Pointer(event))))
}
Exemplo n.º 10
0
Arquivo: package.go Projeto: mantyr/cl
// see https://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clEnqueueWriteBuffer.html
func EnqueueWriteBuffer(cq CommandQueue, buffer Mem, blocking_write Bool, offset uint64, size uint64, ptr unsafe.Pointer, num_events_in_wait_list uint32, event_wait_list *Event, event *Event) ErrorCode {
	return ErrorCode(C.clEnqueueWriteBuffer(cq, buffer, C.cl_bool(blocking_write), C.size_t(offset), C.size_t(size), unsafe.Pointer(ptr), C.cl_uint(num_events_in_wait_list), (*C.cl_event)(unsafe.Pointer(event_wait_list)), (*C.cl_event)(unsafe.Pointer(event))))
}
Exemplo n.º 11
0
Arquivo: package.go Projeto: mantyr/cl
// see https://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clCreateSampler.html
func CreateSampler(context Context, normalizedCoords Bool, addressingMode AddressingMode, filterMode FilterMode, errcode *ErrorCode) Sampler {
	return Sampler(C.clCreateSampler(context.clContext, C.cl_bool(normalizedCoords), C.cl_addressing_mode(addressingMode), C.cl_filter_mode(filterMode), (*C.cl_int)(unsafe.Pointer(errcode))))
}
Exemplo n.º 12
0
Arquivo: package.go Projeto: mantyr/cl
// see https://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clSetCommandQueueProperty.html
func SetCommandQueueProperty(cq CommandQueue, properties CommandQueueProperties, enable BOOL, oldproperties *CommandQueueProperties) int {
	return ErrorCode(C.clSetCommandQueueProperty(cq, C.cl_command_queue_properties(properties), C.cl_bool(enable), (*C.cl_command_queue_properties)(oldproperties)))
}
Exemplo n.º 13
0
func CLEnqueueMapBuffer(command_queue CL_command_queue,
	buffer CL_mem,
	blocking_map CL_bool,
	map_flags CL_map_flags,
	offset CL_size_t,
	cb CL_size_t,
	num_events_in_wait_list CL_uint,
	event_wait_list []CL_event,
	event *CL_event,
	errcode_ret *CL_int) unsafe.Pointer {

	if (num_events_in_wait_list == 0 && event_wait_list != nil) ||
		(num_events_in_wait_list != 0 && event_wait_list == nil) ||
		int(num_events_in_wait_list) != len(event_wait_list) {

		if errcode_ret != nil {
			*errcode_ret = CL_INVALID_EVENT_WAIT_LIST
		}
		return nil
	}

	var c_event C.cl_event
	var c_errcode_ret C.cl_int
	var c_ptr_ret unsafe.Pointer

	if num_events_in_wait_list != 0 {
		var c_event_wait_list []C.cl_event
		c_event_wait_list = make([]C.cl_event, num_events_in_wait_list)
		for i := 0; i < int(num_events_in_wait_list); i++ {
			c_event_wait_list[i] = event_wait_list[i].cl_event
		}

		c_ptr_ret = C.clEnqueueMapBuffer(command_queue.cl_command_queue,
			buffer.cl_mem,
			C.cl_bool(blocking_map),
			C.cl_map_flags(map_flags),
			C.size_t(offset),
			C.size_t(cb),
			C.cl_uint(num_events_in_wait_list),
			&c_event_wait_list[0],
			&c_event,
			&c_errcode_ret)
	} else {
		c_ptr_ret = C.clEnqueueMapBuffer(command_queue.cl_command_queue,
			buffer.cl_mem,
			C.cl_bool(blocking_map),
			C.cl_map_flags(map_flags),
			C.size_t(offset),
			C.size_t(cb),
			0,
			nil,
			&c_event,
			&c_errcode_ret)
	}

	if event != nil {
		event.cl_event = c_event
	}

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

	return c_ptr_ret
}
Exemplo n.º 14
0
func CLEnqueueWriteBufferRect(command_queue CL_command_queue,
	buffer CL_mem,
	blocking_write CL_bool,
	buffer_origin [3]CL_size_t,
	host_origin [3]CL_size_t,
	region [3]CL_size_t,
	buffer_row_pitch CL_size_t,
	buffer_slice_pitch CL_size_t,
	host_row_pitch CL_size_t,
	host_slice_pitch CL_size_t,
	ptr unsafe.Pointer,
	num_events_in_wait_list CL_uint,
	event_wait_list []CL_event,
	event *CL_event) CL_int {

	if (num_events_in_wait_list == 0 && event_wait_list != nil) ||
		(num_events_in_wait_list != 0 && event_wait_list == nil) ||
		int(num_events_in_wait_list) != len(event_wait_list) {
		return CL_INVALID_EVENT_WAIT_LIST
	}

	var c_buffer_origin [3]C.size_t
	var c_host_origin [3]C.size_t
	var c_region [3]C.size_t

	for i := 0; i < 3; i++ {
		c_buffer_origin[i] = C.size_t(buffer_origin[i])
		c_host_origin[i] = C.size_t(host_origin[i])
		c_region[i] = C.size_t(region[i])
	}

	var c_event C.cl_event
	var c_errcode_ret C.cl_int

	if num_events_in_wait_list != 0 {
		var c_event_wait_list []C.cl_event
		c_event_wait_list = make([]C.cl_event, num_events_in_wait_list)
		for i := 0; i < int(num_events_in_wait_list); i++ {
			c_event_wait_list[i] = event_wait_list[i].cl_event
		}

		c_errcode_ret = C.clEnqueueWriteBufferRect(command_queue.cl_command_queue,
			buffer.cl_mem,
			C.cl_bool(blocking_write),
			&c_buffer_origin[0],
			&c_host_origin[0],
			&c_region[0],
			C.size_t(buffer_row_pitch),
			C.size_t(buffer_slice_pitch),
			C.size_t(host_row_pitch),
			C.size_t(host_slice_pitch),
			ptr,
			C.cl_uint(num_events_in_wait_list),
			&c_event_wait_list[0],
			&c_event)
	} else {
		c_errcode_ret = C.clEnqueueWriteBufferRect(command_queue.cl_command_queue,
			buffer.cl_mem,
			C.cl_bool(blocking_write),
			&c_buffer_origin[0],
			&c_host_origin[0],
			&c_region[0],
			C.size_t(buffer_row_pitch),
			C.size_t(buffer_slice_pitch),
			C.size_t(host_row_pitch),
			C.size_t(host_slice_pitch),
			ptr,
			0,
			nil,
			&c_event)
	}

	if event != nil {
		event.cl_event = c_event
	}

	return CL_int(c_errcode_ret)
}
Exemplo n.º 15
0
Arquivo: image.go Projeto: xfong/gocl
func CLEnqueueMapImage(command_queue CL_command_queue,
	image CL_mem,
	blocking_map CL_bool,
	map_flags CL_map_flags,
	origin [3]CL_size_t,
	region [3]CL_size_t,
	image_row_pitch *CL_size_t,
	image_slice_pitch *CL_size_t,
	num_events_in_wait_list CL_uint,
	event_wait_list []CL_event,
	event *CL_event,
	errcode_ret *CL_int) unsafe.Pointer {

	if (num_events_in_wait_list == 0 && event_wait_list != nil) ||
		(num_events_in_wait_list != 0 && event_wait_list == nil) ||
		int(num_events_in_wait_list) != len(event_wait_list) {

		if errcode_ret != nil {
			*errcode_ret = CL_INVALID_EVENT_WAIT_LIST
		}
		return nil
	}

	var c_origin, c_region [3]C.size_t
	var c_image_row_pitch, c_image_slice_pitch C.size_t
	var c_event C.cl_event
	var c_errcode_ret C.cl_int
	var c_ptr_ret unsafe.Pointer

	for i := 0; i < 3; i++ {
		c_origin[i] = C.size_t(origin[i])
		c_region[i] = C.size_t(region[i])
	}

	if num_events_in_wait_list != 0 {
		var c_event_wait_list []C.cl_event
		c_event_wait_list = make([]C.cl_event, num_events_in_wait_list)
		for i := 0; i < int(num_events_in_wait_list); i++ {
			c_event_wait_list[i] = event_wait_list[i].cl_event
		}

		c_ptr_ret = C.clEnqueueMapImage(command_queue.cl_command_queue,
			image.cl_mem,
			C.cl_bool(blocking_map),
			C.cl_map_flags(map_flags),
			&c_origin[0],
			&c_region[0],
			&c_image_row_pitch,
			&c_image_slice_pitch,
			C.cl_uint(num_events_in_wait_list),
			&c_event_wait_list[0],
			&c_event,
			&c_errcode_ret)
	} else {
		c_ptr_ret = C.clEnqueueMapImage(command_queue.cl_command_queue,
			image.cl_mem,
			C.cl_bool(blocking_map),
			C.cl_map_flags(map_flags),
			&c_origin[0],
			&c_region[0],
			&c_image_row_pitch,
			&c_image_slice_pitch,
			0,
			nil,
			&c_event,
			&c_errcode_ret)
	}

	if image_row_pitch != nil {
		*image_row_pitch = CL_size_t(c_image_row_pitch)
	}
	if image_slice_pitch != nil {
		*image_slice_pitch = CL_size_t(c_image_slice_pitch)
	}

	if event != nil {
		event.cl_event = c_event
	}
	if errcode_ret != nil {
		*errcode_ret = CL_int(c_errcode_ret)
	}

	return c_ptr_ret
}
Exemplo n.º 16
0
Arquivo: image.go Projeto: xfong/gocl
func CLEnqueueReadImage(command_queue CL_command_queue,
	image CL_mem,
	blocking_read CL_bool,
	origin [3]CL_size_t,
	region [3]CL_size_t,
	row_pitch CL_size_t,
	slice_pitch CL_size_t,
	ptr unsafe.Pointer,
	num_events_in_wait_list CL_uint,
	event_wait_list []CL_event,
	event *CL_event) CL_int {

	if (num_events_in_wait_list == 0 && event_wait_list != nil) ||
		(num_events_in_wait_list != 0 && event_wait_list == nil) ||
		int(num_events_in_wait_list) != len(event_wait_list) {
		return CL_INVALID_EVENT_WAIT_LIST
	}

	var c_origin, c_region [3]C.size_t
	var c_event C.cl_event
	var c_errcode_ret C.cl_int

	for i := 0; i < 3; i++ {
		c_origin[i] = C.size_t(origin[i])
		c_region[i] = C.size_t(region[i])
	}
	if num_events_in_wait_list != 0 {
		var c_event_wait_list []C.cl_event
		c_event_wait_list = make([]C.cl_event, num_events_in_wait_list)
		for i := 0; i < int(num_events_in_wait_list); i++ {
			c_event_wait_list[i] = event_wait_list[i].cl_event
		}

		c_errcode_ret = C.clEnqueueReadImage(command_queue.cl_command_queue,
			image.cl_mem,
			C.cl_bool(blocking_read),
			&c_origin[0],
			&c_region[0],
			C.size_t(row_pitch),
			C.size_t(slice_pitch),
			ptr,
			C.cl_uint(num_events_in_wait_list),
			&c_event_wait_list[0],
			&c_event)
	} else {
		c_errcode_ret = C.clEnqueueReadImage(command_queue.cl_command_queue,
			image.cl_mem,
			C.cl_bool(blocking_read),
			&c_origin[0],
			&c_region[0],
			C.size_t(row_pitch),
			C.size_t(slice_pitch),
			ptr,
			0,
			nil,
			&c_event)
	}

	if event != nil {
		event.cl_event = c_event
	}

	return CL_int(c_errcode_ret)
}