rocm.hipfile

Contents

rocm.hipfile#

2026-09-24

7 min read time

Applies to Linux and Windows

Advanced Micro Devices, Inc.

High-level Pythonic interface to the hipFile (Accelerated I/O Storage) library.

This sub-package wraps the lower-level hipfile auto-generated bindings with idiomatic Python classes:

  • Driver — context manager for the hipFile driver lifecycle.

  • FileHandle — context manager for an open + registered file.

  • Buffer — context manager for a registered GPU memory region.

plus the mirrored enums (OpError, FileHandleType), the HipFileException type, and the standalone driver_get_properties / get_version helpers.

The complete copy-via-GPU-memory example lives in examples/0_Basic_Usage/hipfile_copy.py.

Submodules#

Exceptions#

HipFileException

Exception raised on a non-success hipFile error.

Classes#

Buffer

Lifecycle manager for a hipFile-registered GPU memory region.

Driver

Lifecycle manager for the hipFile driver.

FileHandleType

Python enum mirroring hipFileFileHandleType_t with friendly names.

OpError

Python enum mirroring hipFileOpError_t with upstream-friendly names.

FileHandle

Lifecycle manager for a hipFile-registered open file.

Functions#

driver_get_properties()

Return the driver properties struct as set by hipFileDriverGetProperties.

get_version()

Return (major, minor, patch) for the loaded libhipfile.so.

Package Contents#

class rocm.hipfile.Buffer(buffer_ptr, length, flags)#

Lifecycle manager for a hipFile-registered GPU memory region.

The caller pre-allocates the underlying device buffer (typically via hipMalloc or any equivalent GPU-allocator) and constructs a Buffer to register it with the hipFile driver. Deregistration happens on context exit (or via explicit deregister).

Use as a context manager:

with Buffer(ptr, length, flags=0) as registered_buf:

…

classmethod from_ctypes_void_p(ctypes_void_p: ctypes.c_void_p, length, flags)#

Construct a Buffer from a ctypes.c_void_p.

property ptr#
deregister()#
register()#
class rocm.hipfile.Driver#

Lifecycle manager for the hipFile driver.

Each instance brackets one hipFileDriverOpen / hipFileDriverClose pair. The driver is reference-counted by the library; multiple Driver instances coexist safely.

Use as a context manager:

with Driver():

…

or call open / close explicitly.

static use_count()#

Return the current driver reference count.

close()#
open()#
class rocm.hipfile.FileHandleType#

Bases: enum.IntEnum

Python enum mirroring hipFileFileHandleType_t with friendly names.

OPAQUE_FD#
OPAQUE_WIN32#
USERSPACE_FS#
class rocm.hipfile.OpError#

Bases: enum.IntEnum

Python enum mirroring hipFileOpError_t with upstream-friendly names.

SUCCESS#
DRIVER_NOT_INITIALIZED#
DRIVER_INVALID_PROPS#
DRIVER_UNSUPPORTED_LIMIT#
DRIVER_VERSION_MISMATCH#
DRIVER_VERSION_READ_ERROR#
DRIVER_CLOSING#
PLATFORM_NOT_SUPPORTED#
IO_NOT_SUPPORTED#
DEVICE_NOT_SUPPORTED#
DRIVER_ERROR#
HIP_DRIVER_ERROR#
HIP_POINTER_INVALID#
HIP_MEMORY_TYPE_INVALID#
HIP_POINTER_RANGE_ERROR#
HIP_CONTEXT_MISMATCH#
INVALID_MAPPING_SIZE#
INVALID_MAPPING_RANGE#
INVALID_FILE_TYPE#
INVALID_FILE_OPEN_FLAG#
DIO_NOT_SET#
INVALID_VALUE#
MEMORY_ALREADY_REGISTERED#
MEMORY_NOT_REGISTERED#
PERMISSION_DENIED#
DRIVER_ALREADY_OPEN#
HANDLE_NOT_REGISTERED#
HANDLE_ALREADY_REGISTERED#
DEVICE_NOT_FOUND#
INTERNAL_ERROR#
GET_NEW_FD_FAILED#
DRIVER_SETUP_ERROR#
IO_DISABLED#
BATCH_SUBMIT_FAILED#
GPU_MEMORY_PINNING_FAILED#
BATCH_FULL#
ASYNC_NOT_SUPPORTED#
IO_MAX_ERROR#
exception rocm.hipfile.HipFileException(hipfile_err, hip_err)#

Bases: Exception

Exception raised on a non-success hipFile error.

Carries both the hipFile-level error code (hipfile_err) and the underlying HIP driver error (hip_err) when the former is OpError.HIP_DRIVER_ERROR.

property hipfile_err#
property hip_err#
class rocm.hipfile.FileHandle(path, flags, mode=DEFAULT_MODE, handle_type=FileHandleType.OPAQUE_FD)#

Lifecycle manager for a hipFile-registered open file.

Wraps hipFileHandleRegister / hipFileHandleDeregister plus synchronous hipFileRead / hipFileWrite.

Use as a context manager:

with FileHandle(path, os.O_RDWR | os.O_DIRECT) as fh:

fh.read(buf, size, file_offset, buffer_offset) fh.write(buf, size, file_offset, buffer_offset)

DEFAULT_MODE = 420#
property handle_type#
property flags#
property handle#
property mode#
property path#
open()#
close()#
read(buffer, size, file_offset, buffer_offset)#

Synchronous read into a registered Buffer.

Returns the number of bytes read on success. Raises HipFileException (with the parsed OpError and HIP driver error) on a hipFile-level error, or OSError (with the real errno) on a POSIX-level error.

write(buffer, size, file_offset, buffer_offset)#

Synchronous write from a registered Buffer.

Returns the number of bytes written on success. Same error semantics as read.

rocm.hipfile.driver_get_properties()#

Return the driver properties struct as set by hipFileDriverGetProperties.

rocm.hipfile.get_version()#

Return (major, minor, patch) for the loaded libhipfile.so.