Documentation
¶
Overview ¶
Package hip provides low-level bindings for the AMD HIP runtime API using purego dlopen. No build tags required; use hip.Available() to check runtime availability.
Index ¶
- func Available() bool
- func Free(devPtr unsafe.Pointer) error
- func GetDeviceCount() (int, error)
- func Malloc(size int) (unsafe.Pointer, error)
- func Memcpy(dst, src unsafe.Pointer, count int, kind MemcpyKind) error
- func MemcpyAsync(dst, src unsafe.Pointer, count int, kind MemcpyKind, stream *Stream) error
- func MemcpyPeer(dst unsafe.Pointer, dstDevice int, src unsafe.Pointer, srcDevice int, ...) error
- func SetDevice(deviceID int) error
- type HIPLib
- type MemPool
- type MemcpyKind
- type Stream
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Available ¶
func Available() bool
Available returns true if HIP runtime is loadable on this machine. The result is cached after the first call.
func GetDeviceCount ¶
GetDeviceCount returns the number of HIP-capable devices.
func Memcpy ¶
func Memcpy(dst, src unsafe.Pointer, count int, kind MemcpyKind) error
Memcpy copies count bytes between host and device memory.
func MemcpyAsync ¶
MemcpyAsync copies count bytes asynchronously on the given stream.
Types ¶
type HIPLib ¶
type HIPLib struct {
// contains filtered or unexported fields
}
HIPLib holds dlopen handles and resolved function pointers for HIP runtime functions. All function pointers are resolved at Open() time via dlsym. Calls go through cuda.Ccall which uses the platform-specific zero-CGo mechanism.
type MemPool ¶
type MemPool struct {
// contains filtered or unexported fields
}
MemPool is a per-device, size-bucketed free-list allocator for HIP device memory. It caches freed allocations by (deviceID, byteSize) for reuse, avoiding the overhead of hipMalloc/hipFree on every operation and preventing cross-device pointer reuse in multi-GPU setups.
func (*MemPool) Alloc ¶
Alloc returns a device pointer of the given byte size on the specified device. If a cached allocation of the exact (deviceID, byteSize) exists, it is reused. Otherwise SetDevice is called and a fresh hipMalloc is performed.
func (*MemPool) Drain ¶
Drain releases all cached device memory back to HIP. Iterates all devices, calling SetDevice before freeing each device's pointers. Returns the first error encountered, but attempts to free all pointers.
type MemcpyKind ¶
type MemcpyKind int
MemcpyKind specifies the direction of a memory copy.
const ( // MemcpyHostToDevice copies from host to device. MemcpyHostToDevice MemcpyKind = 1 // MemcpyDeviceToHost copies from device to host. MemcpyDeviceToHost MemcpyKind = 2 // MemcpyDeviceToDevice copies from device to device. MemcpyDeviceToDevice MemcpyKind = 3 )
type Stream ¶
type Stream struct {
// contains filtered or unexported fields
}
Stream wraps a hipStream_t handle for asynchronous kernel execution.
func StreamFromPtr ¶
StreamFromPtr wraps an existing hipStream_t handle as a Stream.
func (*Stream) Synchronize ¶
Synchronize blocks until all work on this stream completes.