mirror of
https://github.com/fumiama/gozel.git
synced 2026-06-05 00:10:24 +08:00
42 lines
1.3 KiB
Go
42 lines
1.3 KiB
Go
package ze
|
|
|
|
import (
|
|
"runtime"
|
|
"unsafe"
|
|
|
|
"github.com/fumiama/gozel"
|
|
)
|
|
|
|
// KernelHandle is a handle to a Level Zero kernel.
|
|
type KernelHandle gozel.ZeKernelHandle
|
|
|
|
// KernelCreate creates a kernel from the module by the given function name.
|
|
func (h ModuleHandle) KernelCreate(kernelName string) (KernelHandle, error) {
|
|
b := []byte(kernelName + "\x00")
|
|
var k gozel.ZeKernelHandle
|
|
_, err := gozel.ZeKernelCreate(gozel.ZeModuleHandle(h), &gozel.ZeKernelDesc{
|
|
Stype: gozel.ZE_STRUCTURE_TYPE_KERNEL_DESC,
|
|
Pkernelname: &b[0],
|
|
}, &k)
|
|
runtime.KeepAlive(b)
|
|
return KernelHandle(k), err
|
|
}
|
|
|
|
// SetArgumentValue sets the value of a kernel argument at the given index.
|
|
func (h KernelHandle) SetArgumentValue(argIndex uint32, argSize uintptr, pArgValue unsafe.Pointer) error {
|
|
_, err := gozel.ZeKernelSetArgumentValue(gozel.ZeKernelHandle(h), argIndex, argSize, pArgValue)
|
|
return err
|
|
}
|
|
|
|
// SetGroupSize sets the thread group size for the kernel.
|
|
func (h KernelHandle) SetGroupSize(groupSizeX uint32, groupSizeY uint32, groupSizeZ uint32) error {
|
|
_, err := gozel.ZeKernelSetGroupSize(gozel.ZeKernelHandle(h), groupSizeX, groupSizeY, groupSizeZ)
|
|
return err
|
|
}
|
|
|
|
// Destroy destroys the kernel and releases its resources.
|
|
func (h KernelHandle) Destroy() error {
|
|
_, err := gozel.ZeKernelDestroy(gozel.ZeKernelHandle(h))
|
|
return err
|
|
}
|