mirror of
https://github.com/fumiama/gozel.git
synced 2026-06-12 04:20:28 +08:00
feat(examples): add image_scale (#7)
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
This commit is contained in:
@@ -148,3 +148,31 @@ func (h CommandListHandle) HostSynchronize(timeout uint64) error {
|
||||
_, err := gozel.ZeCommandListHostSynchronize(gozel.ZeCommandListHandle(h), timeout)
|
||||
return err
|
||||
}
|
||||
|
||||
// AppendImageCopyFromMemory Copies to an image from device or shared memory.
|
||||
func (h CommandListHandle) AppendImageCopyFromMemory(
|
||||
hDstImage ImageHandle, srcptr unsafe.Pointer, pDstRegion *gozel.ZeImageRegion,
|
||||
hSignalEvent EventHandle, waitEvents ...EventHandle,
|
||||
) error {
|
||||
_, err := gozel.ZeCommandListAppendImageCopyFromMemory(
|
||||
gozel.ZeCommandListHandle(h), gozel.ZeImageHandle(hDstImage), srcptr, pDstRegion,
|
||||
gozel.ZeEventHandle(hSignalEvent), uint32(len(waitEvents)),
|
||||
(*gozel.ZeEventHandle)(unsafe.SliceData(waitEvents)),
|
||||
)
|
||||
runtime.KeepAlive(waitEvents)
|
||||
return err
|
||||
}
|
||||
|
||||
// AppendImageCopyToMemory Copies from an image to device or shared memory.
|
||||
func (h CommandListHandle) AppendImageCopyToMemory(
|
||||
dstptr unsafe.Pointer, hSrcImage ImageHandle, pSrcRegion *gozel.ZeImageRegion,
|
||||
hSignalEvent EventHandle, waitEvents ...EventHandle,
|
||||
) error {
|
||||
_, err := gozel.ZeCommandListAppendImageCopyToMemory(
|
||||
gozel.ZeCommandListHandle(h), dstptr, gozel.ZeImageHandle(hSrcImage), pSrcRegion,
|
||||
gozel.ZeEventHandle(hSignalEvent), uint32(len(waitEvents)),
|
||||
(*gozel.ZeEventHandle)(unsafe.SliceData(waitEvents)),
|
||||
)
|
||||
runtime.KeepAlive(waitEvents)
|
||||
return err
|
||||
}
|
||||
|
||||
30
ze/image.go
Normal file
30
ze/image.go
Normal file
@@ -0,0 +1,30 @@
|
||||
package ze
|
||||
|
||||
import "github.com/fumiama/gozel/gozel"
|
||||
|
||||
// ImageHandle (ze_image_handle_t) Handle of driver's image object.
|
||||
type ImageHandle gozel.ZeImageHandle
|
||||
|
||||
// ImageCreate Creates a 2D image on the context.
|
||||
// flags: 0 for read-only (kernel input), ZE_IMAGE_FLAG_KERNEL_WRITE for writable (kernel output).
|
||||
func (h ContextHandle) ImageCreate(
|
||||
hDevice DeviceHandle, flags gozel.ZeImageFlags, format gozel.ZeImageFormat,
|
||||
width uint64, height uint32,
|
||||
) (ih ImageHandle, err error) {
|
||||
_, err = gozel.ZeImageCreate(gozel.ZeContextHandle(h), gozel.ZeDeviceHandle(hDevice),
|
||||
&gozel.ZeImageDesc{
|
||||
Stype: gozel.ZE_STRUCTURE_TYPE_IMAGE_DESC,
|
||||
Flags: flags,
|
||||
Type: gozel.ZE_IMAGE_TYPE_2D,
|
||||
Format: format,
|
||||
Width: width,
|
||||
Height: height,
|
||||
}, (*gozel.ZeImageHandle)(&ih))
|
||||
return
|
||||
}
|
||||
|
||||
// Destroy Deletes an image object.
|
||||
func (h ImageHandle) Destroy() error {
|
||||
_, err := gozel.ZeImageDestroy(gozel.ZeImageHandle(h))
|
||||
return err
|
||||
}
|
||||
@@ -36,6 +36,12 @@ func (h KernelHandle) SetArgumentValue(argIndex uint32, arg any) error {
|
||||
return err
|
||||
}
|
||||
|
||||
// SuggestGroupSize queries a suggested group size for the kernel given a global size for each dimension.
|
||||
func (h KernelHandle) SuggestGroupSize(globalSizeX, globalSizeY, globalSizeZ uint32) (groupSizeX, groupSizeY, groupSizeZ uint32, err error) {
|
||||
_, err = gozel.ZeKernelSuggestGroupSize(gozel.ZeKernelHandle(h), globalSizeX, globalSizeY, globalSizeZ, &groupSizeX, &groupSizeY, &groupSizeZ)
|
||||
return
|
||||
}
|
||||
|
||||
// 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)
|
||||
|
||||
26
ze/sampler.go
Normal file
26
ze/sampler.go
Normal file
@@ -0,0 +1,26 @@
|
||||
package ze
|
||||
|
||||
import "github.com/fumiama/gozel/gozel"
|
||||
|
||||
// SamplerHandle (ze_sampler_handle_t) Handle of driver's sampler object
|
||||
type SamplerHandle gozel.ZeSamplerHandle
|
||||
|
||||
// SamplerCreate Creates sampler on the context.
|
||||
func (h ContextHandle) SamplerCreate(
|
||||
hDevice DeviceHandle, addressmode gozel.ZeSamplerAddressMode,
|
||||
filtermode gozel.ZeSamplerFilterMode, isnormalized gozel.ZeBool,
|
||||
) (sh SamplerHandle, err error) {
|
||||
_, err = gozel.ZeSamplerCreate(gozel.ZeContextHandle(h), gozel.ZeDeviceHandle(hDevice), &gozel.ZeSamplerDesc{
|
||||
Stype: gozel.ZE_STRUCTURE_TYPE_SAMPLER_DESC,
|
||||
Addressmode: addressmode,
|
||||
Filtermode: filtermode,
|
||||
Isnormalized: isnormalized,
|
||||
}, (*gozel.ZeSamplerHandle)(&sh))
|
||||
return
|
||||
}
|
||||
|
||||
// Destroy Destroys sampler object.
|
||||
func (h SamplerHandle) Destroy() error {
|
||||
_, err := gozel.ZeSamplerDestroy(gozel.ZeSamplerHandle(h))
|
||||
return err
|
||||
}
|
||||
Reference in New Issue
Block a user