1
0
mirror of https://github.com/fumiama/gozel.git synced 2026-06-19 00:55:34 +08:00

feat(example): impl. vadd

This commit is contained in:
源文雨
2026-03-25 00:25:24 +08:00
parent 1111b0ecc1
commit 25cb3b9741
16 changed files with 531 additions and 24 deletions

35
ze/mem.go Normal file
View File

@@ -0,0 +1,35 @@
package ze
import (
"unsafe"
"github.com/fumiama/gozel"
)
// MemAllocDevice allocates device memory on the given device with the specified size and alignment.
func (h ContextHandle) MemAllocDevice(hDevice gozel.ZeDeviceHandle, size uintptr, alignment uintptr) (
unsafe.Pointer, error,
) {
var p unsafe.Pointer
_, err := gozel.ZeMemAllocDevice(gozel.ZeContextHandle(h), &gozel.ZeDeviceMemAllocDesc{
Stype: gozel.ZE_STRUCTURE_TYPE_DEVICE_MEM_ALLOC_DESC,
}, size, alignment, hDevice, &p)
return p, err
}
// MemAllocHost allocates host memory with the specified size and alignment.
func (h ContextHandle) MemAllocHost(size uintptr, alignment uintptr) (
unsafe.Pointer, error,
) {
var p unsafe.Pointer
_, err := gozel.ZeMemAllocHost(gozel.ZeContextHandle(h), &gozel.ZeHostMemAllocDesc{
Stype: gozel.ZE_STRUCTURE_TYPE_DEVICE_MEM_ALLOC_DESC,
}, size, alignment, &p)
return p, err
}
// MemFree frees memory previously allocated with MemAllocDevice or MemAllocHost.
func (h ContextHandle) MemFree(ptr unsafe.Pointer) error {
_, err := gozel.ZeMemFree(gozel.ZeContextHandle(h), ptr)
return err
}