mirror of
https://github.com/fumiama/gozel.git
synced 2026-06-09 18:40:28 +08:00
feat(example): impl. vadd
This commit is contained in:
91
ze/command.go
Normal file
91
ze/command.go
Normal file
@@ -0,0 +1,91 @@
|
||||
package ze
|
||||
|
||||
import (
|
||||
"math"
|
||||
"unsafe"
|
||||
|
||||
"github.com/fumiama/gozel"
|
||||
)
|
||||
|
||||
// CommandQueueHandle is a handle to a Level Zero command queue.
|
||||
type CommandQueueHandle gozel.ZeCommandQueueHandle
|
||||
|
||||
// CommandQueueCreate creates a command queue on the given device with default mode and normal priority.
|
||||
func (h ContextHandle) CommandQueueCreate(hDevice gozel.ZeDeviceHandle) (
|
||||
CommandQueueHandle, error,
|
||||
) {
|
||||
var q gozel.ZeCommandQueueHandle
|
||||
_, err := gozel.ZeCommandQueueCreate(gozel.ZeContextHandle(h), hDevice, &gozel.ZeCommandQueueDesc{
|
||||
Stype: gozel.ZE_STRUCTURE_TYPE_COMMAND_QUEUE_DESC,
|
||||
Mode: gozel.ZE_COMMAND_QUEUE_MODE_DEFAULT,
|
||||
Priority: gozel.ZE_COMMAND_QUEUE_PRIORITY_NORMAL,
|
||||
}, &q)
|
||||
return CommandQueueHandle(q), err
|
||||
}
|
||||
|
||||
// ExecuteCommandLists submits the command list for execution on the command queue.
|
||||
func (h CommandQueueHandle) ExecuteCommandLists(hCommandList CommandListHandle) error {
|
||||
cl := gozel.ZeCommandListHandle(hCommandList)
|
||||
_, err := gozel.ZeCommandQueueExecuteCommandLists(gozel.ZeCommandQueueHandle(h), 1, &cl, 0)
|
||||
return err
|
||||
}
|
||||
|
||||
// Synchronize blocks the host until all commands in the command queue have completed.
|
||||
func (h CommandQueueHandle) Synchronize() error {
|
||||
_, err := gozel.ZeCommandQueueSynchronize(gozel.ZeCommandQueueHandle(h), math.MaxUint64)
|
||||
return err
|
||||
}
|
||||
|
||||
// Destroy destroys the command queue and releases its resources.
|
||||
func (h CommandQueueHandle) Destroy() error {
|
||||
_, err := gozel.ZeCommandQueueDestroy(gozel.ZeCommandQueueHandle(h))
|
||||
return err
|
||||
}
|
||||
|
||||
// CommandListHandle is a handle to a Level Zero command list.
|
||||
type CommandListHandle gozel.ZeCommandListHandle
|
||||
|
||||
// CommandListCreate creates a command list on the given device.
|
||||
func (h ContextHandle) CommandListCreate(hDevice gozel.ZeDeviceHandle) (
|
||||
CommandListHandle, error,
|
||||
) {
|
||||
var cl gozel.ZeCommandListHandle
|
||||
_, err := gozel.ZeCommandListCreate(gozel.ZeContextHandle(h), hDevice, &gozel.ZeCommandListDesc{
|
||||
Stype: gozel.ZE_STRUCTURE_TYPE_COMMAND_LIST_DESC,
|
||||
}, &cl)
|
||||
return CommandListHandle(cl), err
|
||||
}
|
||||
|
||||
// AppendLaunchKernel appends a kernel launch command to the command list.
|
||||
func (h CommandListHandle) AppendLaunchKernel(
|
||||
hKernel KernelHandle, pLaunchFuncArgs *gozel.ZeGroupCount,
|
||||
) error {
|
||||
_, err := gozel.ZeCommandListAppendLaunchKernel(gozel.ZeCommandListHandle(h), gozel.ZeKernelHandle(hKernel), pLaunchFuncArgs, 0, 0, nil)
|
||||
return err
|
||||
}
|
||||
|
||||
// Close closes the command list, making it ready for execution.
|
||||
func (h CommandListHandle) Close() error {
|
||||
_, err := gozel.ZeCommandListClose(gozel.ZeCommandListHandle(h))
|
||||
return err
|
||||
}
|
||||
|
||||
// AppendMemoryCopy appends a memory copy command from srcptr to dstptr of the given size.
|
||||
func (h CommandListHandle) AppendMemoryCopy(
|
||||
dstptr unsafe.Pointer, srcptr unsafe.Pointer, size uintptr,
|
||||
) error {
|
||||
_, err := gozel.ZeCommandListAppendMemoryCopy(gozel.ZeCommandListHandle(h), dstptr, srcptr, size, 0, 0, nil)
|
||||
return err
|
||||
}
|
||||
|
||||
// Destroy destroys the command list and releases its resources.
|
||||
func (h CommandListHandle) Destroy() error {
|
||||
_, err := gozel.ZeCommandListDestroy(gozel.ZeCommandListHandle(h))
|
||||
return err
|
||||
}
|
||||
|
||||
// AppendBarrier appends an execution barrier to the command list.
|
||||
func (h CommandListHandle) AppendBarrier() error {
|
||||
_, err := gozel.ZeCommandListAppendBarrier(gozel.ZeCommandListHandle(h), 0, 0, nil)
|
||||
return err
|
||||
}
|
||||
Reference in New Issue
Block a user