示例#1
0
文件: image.go 项目: xfong/tmpCL
// Enqueues a command to read from a 2D or 3D image object to host memory.
func (q *CommandQueue) EnqueueReadImage(image *MemObject, blocking bool, origin, region [3]int, rowPitch, slicePitch int, data []byte, eventWaitList []*Event) (*Event, error) {
	cOrigin := sizeT3(origin)
	cRegion := sizeT3(region)
	var event C.cl_event
	err := toError(C.clEnqueueReadImage(q.clQueue, image.clMem, clBool(blocking), &cOrigin[0], &cRegion[0], C.size_t(rowPitch), C.size_t(slicePitch), unsafe.Pointer(&data[0]), C.cl_uint(len(eventWaitList)), eventListPtr(eventWaitList), &event))
	return newEvent(event), err
}
示例#2
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
}
示例#3
0
func (cq *CommandQueue) EnqueueReadImage(im *Image, origin, region [3]Size, rowPitch, slicePitch uint32) ([]byte, error) {

	size := 0
	if im.d == 0 {
		if rowPitch == 0 {
			elemSize, err := im.Info(IMAGE_ELEMENT_SIZE)
			if err != nil {
				return []byte{}, nil
			}
			rowPitch = uint32(elemSize) * im.w
		}
		size = int(rowPitch * im.h)
	} else {
		if slicePitch == 0 {
			if rowPitch == 0 { // ditto. ugh.
				elemSize, err := im.Info(IMAGE_ELEMENT_SIZE)
				if err != nil {
					return []byte{}, nil
				}
				rowPitch = uint32(elemSize) * im.w
			}
			slicePitch = rowPitch * im.d
		}
		size = int(slicePitch * im.d)
	}

	bytes := make([]byte, size)

	if ret := C.clEnqueueReadImage(cq.id, im.id, C.CL_TRUE, (*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
}
示例#4
0
文件: package.go 项目: mantyr/cl
// see https://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clEnqueueReadImage.html
func EnqueueReadImage(cq CommandQueue, image Mem, blocking_read Bool, origin3 *uint64, region3 *uint64, row_pitch uint64, slice_pitch uint64, ptr unsafe.Pointer, num_events_in_wait_list uint32, event_wait_list *Event, event *Event) ErrorCode {
	return ErrorCode(C.clEnqueueReadImage(cq, image, C.cl_bool(blocking_read), (*C.size_t)(unsafe.Pointer(origin3)), (*C.size_t)(unsafe.Pointer(region3)), C.size_t(row_pitch), C.size_t(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))))
}
示例#5
0
文件: image.go 项目: 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)
}