mirror of
https://github.com/fumiama/gozel.git
synced 2026-06-10 11:10:23 +08:00
feat(example): impl. vadd
This commit is contained in:
41
ze/kernel.go
Normal file
41
ze/kernel.go
Normal file
@@ -0,0 +1,41 @@
|
||||
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
|
||||
}
|
||||
Reference in New Issue
Block a user