예제 #1
0
// Enqueues a command to execute a kernel on a device.
func (q *CommandQueue) EnqueueNDRangeKernel(kernel *Kernel, globalWorkOffset, globalWorkSize, localWorkSize []int, eventWaitList []*Event) (*Event, error) {
	workDim := len(globalWorkSize)
	var globalWorkOffsetList []C.size_t
	var globalWorkOffsetPtr *C.size_t
	if globalWorkOffset != nil {
		globalWorkOffsetList = make([]C.size_t, len(globalWorkOffset))
		for i, off := range globalWorkOffset {
			globalWorkOffsetList[i] = C.size_t(off)
		}
		globalWorkOffsetPtr = &globalWorkOffsetList[0]
	}
	var globalWorkSizeList []C.size_t
	var globalWorkSizePtr *C.size_t
	if globalWorkSize != nil {
		globalWorkSizeList = make([]C.size_t, len(globalWorkSize))
		for i, off := range globalWorkSize {
			globalWorkSizeList[i] = C.size_t(off)
		}
		globalWorkSizePtr = &globalWorkSizeList[0]
	}
	var localWorkSizeList []C.size_t
	var localWorkSizePtr *C.size_t
	if localWorkSize != nil {
		localWorkSizeList = make([]C.size_t, len(localWorkSize))
		for i, off := range localWorkSize {
			localWorkSizeList[i] = C.size_t(off)
		}
		localWorkSizePtr = &localWorkSizeList[0]
	}
	var event C.cl_event
	err := toError(C.clEnqueueNDRangeKernel(q.clQueue, kernel.clKernel, C.cl_uint(workDim), globalWorkOffsetPtr, globalWorkSizePtr, localWorkSizePtr, C.cl_uint(len(eventWaitList)), eventListPtr(eventWaitList), &event))
	return newEvent(event), err
}
예제 #2
0
func (cq *CommandQueue) EnqueueKernel(k *Kernel, offset, gsize, lsize []Size) error {

	cptr := func(w []Size) *C.size_t {
		if len(w) == 0 {
			return nil
		}
		return (*C.size_t)(unsafe.Pointer(&w[0]))
	}

	c_offset := cptr(offset)
	c_gsize := cptr(gsize)
	c_lsize := cptr(lsize)

	if ret := C.clEnqueueNDRangeKernel(cq.id, k.id, C.cl_uint(len(gsize)), c_offset, c_gsize, c_lsize, 0, nil, nil); ret != C.CL_SUCCESS {
		return Cl_error(ret)
	}
	return nil
}
예제 #3
0
파일: kernel.go 프로젝트: Dirbaio/gominer
func CLEnqueueNDRangeKernel(command_queue CL_command_queue,
	kernel CL_kernel,
	work_dim CL_uint,
	global_work_offset []CL_size_t,
	global_work_size []CL_size_t,
	local_work_size []CL_size_t,
	num_events_in_wait_list CL_uint,
	event_wait_list []CL_event,
	event *CL_event) CL_int {

	if work_dim > 3 || work_dim < 1 {
		return CL_INVALID_WORK_DIMENSION
	}

	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_global_work_offset_ptr, c_global_work_size_ptr, c_local_work_size_ptr *C.size_t
	var c_global_work_offset, c_global_work_size, c_local_work_size []C.size_t
	var c_event C.cl_event
	var c_errcode_ret C.cl_int

	if global_work_offset != nil {
		c_global_work_offset = make([]C.size_t, len(global_work_offset))
		for i := 0; i < len(global_work_offset); i++ {
			c_global_work_offset[i] = C.size_t(global_work_offset[i])
		}
		c_global_work_offset_ptr = &c_global_work_offset[0]
	} else {
		c_global_work_offset_ptr = nil
	}

	if global_work_size != nil {
		c_global_work_size = make([]C.size_t, len(global_work_size))
		for i := 0; i < len(global_work_size); i++ {
			c_global_work_size[i] = C.size_t(global_work_size[i])
		}
		c_global_work_size_ptr = &c_global_work_size[0]
	} else {
		c_global_work_size_ptr = nil
	}

	if local_work_size != nil {
		c_local_work_size = make([]C.size_t, len(local_work_size))
		for i := 0; i < len(local_work_size); i++ {
			c_local_work_size[i] = C.size_t(local_work_size[i])
		}
		c_local_work_size_ptr = &c_local_work_size[0]
	} else {
		c_local_work_size_ptr = nil
	}

	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.clEnqueueNDRangeKernel(command_queue.cl_command_queue,
			kernel.cl_kernel,
			C.cl_uint(work_dim),
			c_global_work_offset_ptr,
			c_global_work_size_ptr,
			c_local_work_size_ptr,
			C.cl_uint(num_events_in_wait_list),
			&c_event_wait_list[0],
			&c_event)
	} else {
		c_errcode_ret = C.clEnqueueNDRangeKernel(command_queue.cl_command_queue,
			kernel.cl_kernel,
			C.cl_uint(work_dim),
			c_global_work_offset_ptr,
			c_global_work_size_ptr,
			c_local_work_size_ptr,
			0,
			nil,
			&c_event)
	}

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

	return CL_int(c_errcode_ret)
}
예제 #4
0
파일: package.go 프로젝트: mantyr/cl
// see https://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clEnqueueNDRangeKernel.html
func EnqueueNDRangeKernel(cq CommandQueue, kernel Kernel, work_dim uint32, global_work_offset *uint64, global_work_size *uint64, local_work_size *uint64, num_events_in_wait_list uint32, event_wait_list *Event, event *Event) ErrorCode {
	return ErrorCode(C.clEnqueueNDRangeKernel(cq, kernel, C.cl_uint(work_dim), (*C.size_t)(unsafe.Pointer(global_work_offset)), (*C.size_t)(unsafe.Pointer(global_work_size)), (*C.size_t)(unsafe.Pointer(local_work_size)), C.cl_uint(num_events_in_wait_list), (*C.cl_event)(unsafe.Pointer(event_wait_list)), (*C.cl_event)(unsafe.Pointer(event))))
}