rocm.bindings.cyhipfile

rocm.bindings.cyhipfile#

2026-09-24

15 min read time

Applies to Linux and Windows

Advanced Micro Devices, Inc.

Cython declarations for the C-level interface. Use cimport rocm.bindings.cyhipfile from your Cython code to access these declarations directly.

See also

The high-level Python API is documented at rocm.bindings.hipfile.

# MIT License
#
# Copyright (c) 2021-2026 Advanced Micro Devices, Inc.
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.


# This file has been autogenerated, do not modify.

from libc.stdint cimport *
ctypedef bint _Bool # bool is not a reserved keyword in C, _Bool is
from rocm.bindings.cyhip cimport hipStream_t, hipError_t
cdef extern from "hipfile.h":
    # Pointer-only POSIX structs (see generators_systems.py). Opaque: hipFILE
    # never dereferences them, so no field layout is bound.
    cdef struct sockaddr:
        pass
    cdef struct timespec:
        pass
cdef extern from "hipfile.h":

    cdef int HIPFILE_VERSION_MAJOR

    cdef int HIPFILE_VERSION_MINOR

    cdef int HIPFILE_VERSION_PATCH

    cdef int HIPFILE_BASE_ERR

    cdef enum hipFileOpError:
        hipFileSuccess
        hipFileDriverNotInitialized
        hipFileDriverInvalidProps
        hipFileDriverUnsupportedLimit
        hipFileDriverVersionMismatch
        hipFileDriverVersionReadError
        hipFileDriverClosing
        hipFilePlatformNotSupported
        hipFileIONotSupported
        hipFileDeviceNotSupported
        hipFileDriverError
        hipFileHipDriverError
        hipFileHipPointerInvalid
        hipFileHipMemoryTypeInvalid
        hipFileHipPointerRangeError
        hipFileHipContextMismatch
        hipFileInvalidMappingSize
        hipFileInvalidMappingRange
        hipFileInvalidFileType
        hipFileInvalidFileOpenFlag
        hipFileDIONotSet
        hipFileInvalidValue
        hipFileMemoryAlreadyRegistered
        hipFileMemoryNotRegistered
        hipFilePermissionDenied
        hipFileDriverAlreadyOpen
        hipFileHandleNotRegistered
        hipFileHandleAlreadyRegistered
        hipFileDeviceNotFound
        hipFileInternalError
        hipFileGetNewFDFailed
        hipFileDriverSetupError
        hipFileIODisabled
        hipFileBatchSubmitFailed
        hipFileGPUMemoryPinningFailed
        hipFileBatchFull
        hipFileAsyncNotSupported
        hipFileIOMaxError

    ctypedef hipFileOpError hipFileOpError_t

# 
# @brief Return a descriptive string for a hipFile error
# @ingroup error
# 
# @param [in] status Return code provided by hipFile
# 
# @return Description of the error encountered
cdef const char * hipFileGetOpErrorString(hipFileOpError status) noexcept nogil


cdef extern from "hipfile.h":

    cdef struct hipFileError:
        hipFileOpError err
        hipError_t hip_drv_err

    ctypedef hipFileError hipFileError_t

    cdef enum hipFileDriverStatusFlags:
        hipFileLustreSupported
        hipFileWekaFSSupported
        hipFileNFSSupported
        hipFileGPFSSupported
        hipFileNVMeSupported
        hipFileNVMeoFSupported
        hipFileSCSISupported
        hipFileScaleFluxCSDSupported
        hipFileNVMeshSupported
        hipFileBeeGFSSupported
        hipFileNVMeP2PSupported
        hipFileScatefsSupported

    ctypedef hipFileDriverStatusFlags hipFileDriverStatusFlags_t

    cdef enum hipFileDriverControlFlags:
        hipFileUsePollMode
        hipFileAllowCompatMode

    ctypedef hipFileDriverControlFlags hipFileDriverControlFlags_t

    cdef enum hipFileFeatureFlags:
        hipFileDynRoutingSupported
        hipFileBatchIOSupported
        hipFileStreamsSupported
        hipFileParallelIOSupported

    ctypedef hipFileFeatureFlags hipFileFeatureFlags_t

cdef struct hipFileDriverProps_struct_0:
    unsigned int major_version
    unsigned int minor_version
    uint64_t poll_thresh_size
    uint64_t max_direct_io_size
    unsigned int driver_status_flags
    unsigned int driver_control_flags

cdef extern from "hipfile.h":

    cdef struct hipFileDriverProps:
        hipFileDriverProps_struct_0 nvfs
        unsigned int feature_flags
        uint64_t max_device_cache_size
        uint64_t per_buffer_cache_size
        uint64_t max_device_pinned_mem_size
        unsigned int max_batch_io_count
        unsigned int max_batch_io_timeout_msecs

    ctypedef hipFileDriverProps hipFileDriverProps_t

    cdef struct hipFileRDMAInfo:
        int version
        int desc_len
        const char * desc_str

    ctypedef hipFileRDMAInfo hipFileRDMAInfo_t

ctypedef const char * (*hipFileFSOps_anon_funptr_0) (void *)

ctypedef int (*hipFileFSOps_anon_funptr_1) (void *,sockaddr **)

ctypedef int (*hipFileFSOps_anon_funptr_2) (void *,char *,size_t,int64_t,sockaddr *)

ctypedef ssize_t (*hipFileFSOps_anon_funptr_3) (void *,char *,size_t,int64_t,hipFileRDMAInfo *)

ctypedef ssize_t (*hipFileFSOps_anon_funptr_4) (void *,const char *,size_t,int64_t,hipFileRDMAInfo *)

cdef extern from "hipfile.h":

    cdef struct hipFileFSOps:
        hipFileFSOps_anon_funptr_0 fs_type
        hipFileFSOps_anon_funptr_1 getRDMADeviceList
        hipFileFSOps_anon_funptr_2 getRDMADevicePriority
        hipFileFSOps_anon_funptr_3 read
        hipFileFSOps_anon_funptr_4 write

    ctypedef hipFileFSOps hipFileFSOps_t

    cdef enum hipFileFileHandleType:
        hipFileHandleTypeOpaqueFD
        hipFileHandleTypeOpaqueWin32
        hipFileHandleTypeUserspaceFS

    ctypedef hipFileFileHandleType hipFileFileHandleType_t

cdef union hipFileDescr_union_0:
    int fd
    void * hFile

cdef extern from "hipfile.h":

    cdef struct hipFileDescr:
        hipFileFileHandleType type
        hipFileDescr_union_0 handle
        const hipFileFSOps * fs_ops

    ctypedef hipFileDescr hipFileDescr_t

    ctypedef void * hipFileHandle_t

# 
# @brief Registers an open file for GPU IO
# @ingroup file
# 
# @note If the library has not already been initialized, the first call to
#       `hipFileHandleRegister()` will initialize the library and increment
#       the reference count.
# 
# @param [out] fh    \hipfile_handle_param
# @param [in]  descr Parameters for opening the file
# 
# @return \hipfile_error_return
cdef hipFileError hipFileHandleRegister(void ** fh,hipFileDescr * descr) noexcept nogil


# 
# @brief Deregisters a file from GPU IO
# @ingroup file
# 
# @param [in] fh \hipfile_handle_param
cdef void hipFileHandleDeregister(void * fh) noexcept nogil


# 
# @brief Registers a GPU memory region to be used with GPU IO
# @ingroup file
# 
# The memory region should be allocated by the user before being passed to the API call
# 
# @note If the library has not already been initialized, the first call to
#       `hipFileBufRegister()` will initialize the library and increment
#       the reference count.
# 
# @param [in] buffer_base \buffer_base_param
# @param [in] length      Size of the allocated buffer in bytes
# @param [in] flags       Control flags for this buffer
# 
# @return \hipfile_error_return
cdef hipFileError hipFileBufRegister(const void * buffer_base,size_t length,int flags) noexcept nogil


# 
# @brief Deregisters a GPU memory region from being used with GPU IO
# @ingroup file
# 
# @param [in] buffer_base \buffer_base_param
# 
# @return \hipfile_error_return
cdef hipFileError hipFileBufDeregister(const void * buffer_base) noexcept nogil


# 
# @brief Synchronously read data from a file into a GPU buffer
# @ingroup sync
# 
# @param [in] fh            \hipfile_handle_param
# @param [in] buffer_base   \buffer_base_param
# @param [in] size          Number of bytes that should be read
# @param [in] file_offset   Offset into the file that should be read from
# @param [in] buffer_offset Offset of the GPU buffer that that the data should be written to
# 
# \max_io_size_note
# 
# @return if >= 0: Number of bytes read
# @return if -1:   System error (check `errno` for the specific error)
# @return else:    Negative value of the related hipFileOpError_t
cdef ssize_t hipFileRead(void * fh,void * buffer_base,size_t size,int64_t file_offset,int64_t buffer_offset) noexcept nogil


# 
# @brief Synchronously write data from a GPU buffer to a file
# @ingroup sync
# 
# @param [in] fh            \hipfile_handle_param
# @param [in] buffer_base   \buffer_base_param
# @param [in] size          Number of bytes that should be written
# @param [in] file_offset   Offset into the file that should be written to
# @param [in] buffer_offset Offset of the GPU buffer that the data should be read from
# 
# \max_io_size_note
# 
# @return if >= 0: Number of bytes written
# @return if -1:   System error (check `errno` for the specific error)
# @return else:    Negative value of the related hipFileOpError_t
cdef ssize_t hipFileWrite(void * fh,const void * buffer_base,size_t size,int64_t file_offset,int64_t buffer_offset) noexcept nogil


# 
# @brief Initialize the GPU IO driver for this process
# @ingroup driver
# 
# Each call to `hipFileDriverOpen()` increments the library's reference
# count. If a call to `hipFileDriverOpen()` results in the reference count
# transitioning from zero to one, the library's state will be initialized.
# 
# Calling `hipFileDriverOpen()` is optional. The first call to
# `hipFileBufRegister()` or `hipFileHandleRegister()` will trigger
# library initialization and increment the library's reference count.
# 
# @return \hipfile_error_return
cdef hipFileError hipFileDriverOpen() noexcept nogil


# 
# @brief Close the GPU IO driver for this process
# @ingroup driver
# 
# Each call to `hipFileDriverClose()` decrements the library's reference
# count. If a call to `hipFileDriverClose()` results in the reference count
# transitioning from one to zero, the library's state will be destroyed.
# 
# Explicitly closing the library is not required; the library's state will be
# destroyed automatically at program exit.
# 
# @return \hipfile_error_return
cdef hipFileError hipFileDriverClose() noexcept nogil


# 
# @brief Obtain the current reference count for the library
# @ingroup driver
# 
# @see hipFileDriverOpen()
# @see hipFileDriverClose()
# 
# @return The library's reference count
cdef int64_t hipFileUseCount() noexcept nogil


# 
# @brief Get a list of GPU IO driver properties
# @ingroup driver
# 
# \warn_not_implemented
# 
# @param [out] props See `hipFileDriverProps_t` for what properties are reported
# 
# @return \hipfile_error_return
cdef hipFileError hipFileDriverGetProperties(hipFileDriverProps * props) noexcept nogil


# 
# @brief Enable/disable polling mode for GPU IO
# @ingroup driver
# 
# \warn_not_implemented
# 
# @param [in] poll `true` to enable polling, `false` to disable
# @param [in] poll_threshold_size Maximum IO size (in KiB) for which polling is
#                                 used when enabled
# 
# @return \hipfile_error_return
cdef hipFileError hipFileDriverSetPollMode(_Bool poll,size_t poll_threshold_size) noexcept nogil


# 
# @brief Set the maximum IO chunk size
# @ingroup driver
# 
# \warn_not_implemented
# 
# @param [in] max_direct_io_size Maximum IO chunk size (in KiB) for each IO request
# 
# @return \hipfile_error_return
cdef hipFileError hipFileDriverSetMaxDirectIOSize(size_t max_direct_io_size) noexcept nogil


# 
# @brief Set the maximum amount of GPU memory that can be used for bounce buffers
# @ingroup driver
# 
# \warn_not_implemented
# 
# @param [in] max_cache_size Maximum GPU memory (in KiB) that can be reserved for bounce buffers
# 
# @return \hipfile_error_return
cdef hipFileError hipFileDriverSetMaxCacheSize(size_t max_cache_size) noexcept nogil


# 
# @brief Set the maximum amount of GPU memory that can be pinned
# @ingroup driver
# 
# \warn_not_implemented
# 
# @param [in] max_pinned_size Maximum GPU memory (in KiB) that can be pinned
# 
# @return \hipfile_error_return
cdef hipFileError hipFileDriverSetMaxPinnedMemSize(size_t max_pinned_size) noexcept nogil


cdef extern from "hipfile.h":

    cdef enum hipFileOpcode:
        hipFileBatchRead
        hipFileBatchWrite

    ctypedef hipFileOpcode hipFileOpcode_t

    cdef enum hipFileStatus:
        hipFileWaiting
        hipFilePending
        hipFileInvalid
        hipFileCanceled
        hipFileComplete
        hipFileTimeout
        hipFileFailed

    ctypedef hipFileStatus hipFileStatus_t

    cdef enum hipFileBatchMode:
        hipFileBatch

    ctypedef hipFileBatchMode hipFileBatchMode_t

cdef struct hipFileIOParams_union_0_struct_0:
    void * devPtr_base
    int64_t file_offset
    int64_t devPtr_offset
    size_t size

cdef union hipFileIOParams_union_0:
    hipFileIOParams_union_0_struct_0 batch

cdef extern from "hipfile.h":

    cdef struct hipFileIOParams:
        hipFileBatchMode mode
        hipFileIOParams_union_0 u
        void * fh
        hipFileOpcode opcode
        void * cookie

    ctypedef hipFileIOParams hipFileIOParams_t

    cdef struct hipFileIOEvents:
        void * cookie
        hipFileStatus status
        size_t ret

    ctypedef hipFileIOEvents hipFileIOEvents_t

    ctypedef void * hipFileBatchHandle_t

# 
# @brief Prepare the system to perform a batch IO operation
# @ingroup batch
# 
# @param [out] batch_idp \batch_handle_param
# @param [in] max_nr     Maximum number of requests that can be submitted to this batch handle
# 
# @return \hipfile_error_return
cdef hipFileError hipFileBatchIOSetUp(void ** batch_idp,unsigned int max_nr) noexcept nogil


# 
# @brief Enqueue a batch of IO requests for the GPU to complete asynchronously
# @ingroup batch
# 
# @param [in]     batch_idp     \batch_handle_param
# @param [in]     nr            Number of batch IO requests to submit
# @param [in]     iocbp         An array of `nr` batch IO requests to submit to the GPU.
#                               Data will be read into or written from the buffer specified in
#                               each request.
# @param [in]     flags Control Flags for the batch IO. Currently unused.
# 
# @return \hipfile_error_return
cdef hipFileError hipFileBatchIOSubmit(void * batch_idp,unsigned int nr,hipFileIOParams * iocbp,unsigned int flags) noexcept nogil


# 
# @brief Poll for the status of completed batch IO operations
# @ingroup batch
# 
# \warn_not_implemented
# 
# @param [in] batch_idp \batch_handle_param
# @param [in] min_nr Minimum number of batch operation statuses that should be returned.
#                    If `timeout` is exceeded, fewer statuses may be returned.
# @param [in,out] nr Maximum number of batch operation statuses that can be returned.
#                    This is parameter is modified to return the number of statuses returned in `iocbp`.
# 
# @param [out] iocbp An array containing up to `nr` statuses from the overall batch operation
# @param [in] timeout Maximum amount of time this function should poll for status updates
# 
# @return \hipfile_error_return
cdef hipFileError hipFileBatchIOGetStatus(void * batch_idp,unsigned int min_nr,unsigned int * nr,hipFileIOEvents * iocbp,timespec * timeout) noexcept nogil


# 
# @brief Cancels all pending batch IO operations
# @ingroup batch
# 
# \warn_not_implemented
# 
# @param [in] batch_idp \batch_handle_param
# 
# @return \hipfile_error_return
cdef hipFileError hipFileBatchIOCancel(void * batch_idp) noexcept nogil


# 
# @brief Destroys the batch IO handle and frees the associated resources
# @ingroup batch
# 
# \warn_not_implemented_void
# 
# @param [in] batch_idp \batch_handle_param
cdef void hipFileBatchIODestroy(void * batch_idp) noexcept nogil


# 
# @brief Perform an asynchronous read from a stream
# @ingroup async
# 
# @param [in]  fh              \hipfile_handle_param
# @param [in]  buffer_base     \buffer_base_param
# @param [in]  size_p          Number of bytes that should be read
# @param [in]  file_offset_p   Offset into the file that should be read from
# @param [in]  buffer_offset_p Offset of the GPU buffer that that the data should be written to
# @param [out] bytes_read_p    Number of bytes read
# @param [in]  stream          \hipstream_param. \hipstream_if_null.
# 
# \max_io_size_note
# 
# @return \hipfile_error_return
cdef hipFileError hipFileReadAsync(void * fh,void * buffer_base,size_t * size_p,int64_t * file_offset_p,int64_t * buffer_offset_p,ssize_t * bytes_read_p,hipStream_t stream) noexcept nogil


# 
# @brief Perform an asynchronous write to a stream
# @ingroup async
# 
# @param [in]  fh              \hipfile_handle_param
# @param [in]  buffer_base     \buffer_base_param
# @param [in]  size_p          Number of bytes that should be written
# @param [in]  file_offset_p   Offset into the file that should be written to
# @param [in]  buffer_offset_p Offset of the GPU buffer that that the data should be read from
# @param [out] bytes_written_p Number of bytes written
# @param [in]  stream          \hipstream_param. \hipstream_if_null.
# 
# \max_io_size_note
# 
# @return \hipfile_error_return
cdef hipFileError hipFileWriteAsync(void * fh,void * buffer_base,size_t * size_p,int64_t * file_offset_p,int64_t * buffer_offset_p,ssize_t * bytes_written_p,hipStream_t stream) noexcept nogil


# 
# @brief Register a stream to be used by for asynchronous GPU IO
# @ingroup async
# 
# @param [in] stream \hipstream_param
# @param [in] flags Flags that can optimize stream processing if parameters
#                   are known/are aligned at time of request submission
# 
# @return \hipfile_error_return
cdef hipFileError hipFileStreamRegister(hipStream_t stream,unsigned int flags) noexcept nogil


# 
# @brief Deregister a stream and free the associated resources
# @ingroup async
# 
# @param [in] stream \hipstream_param
# 
# @return \hipfile_error_return
cdef hipFileError hipFileStreamDeregister(hipStream_t stream) noexcept nogil


# 
# @brief Get the version of the hipFile library
# @ingroup core
# 
# @param [out] major The major version
# @param [out] minor The minor version
# @param [out] patch The patch version
# 
# @note Parameters can be set to NULL to ignore that part of the version
# 
# @return \hipfile_error_return
cdef hipFileError hipFileGetVersion(unsigned int * major,unsigned int * minor,unsigned int * patch) noexcept nogil


cdef extern from "hipfile.h":

    cdef enum hipFileSizeTConfigParameter_t:
        hipFileParamProfileStats
        hipFileParamExecutionMaxIOQueueDepth
        hipFileParamExecutionMaxIOThreads
        hipFileParamExecutionMinIOThresholdSizeKB
        hipFileParamExecutionMaxRequestParallelism
        hipFileParamPropertiesMaxDirectIOSizeKB
        hipFileParamPropertiesMaxDeviceCacheSizeKB
        hipFileParamPropertiesPerBufferCacheSizeKB
        hipFileParamPropertiesMaxDevicePinnedMemSizeKB
        hipFileParamPropertiesIOBatchsize
        hipFileParamPollthresholdSizeKB
        hipFileParamPropertiesBatchIOTimeoutMs

    cdef enum hipFileBoolConfigParameter_t:
        hipFileParamPropertiesUsePollMode
        hipFileParamPropertiesAllowCompatMode
        hipFileParamForceCompatMode
        hipFileParamFsMiscApiCheckAggressive
        hipFileParamExecutionParallelIO
        hipFileParamProfileNvtx
        hipFileParamPropertiesAllowSystemMemory
        hipFileParamUsePcip2pdma
        hipFileParamPreferIOUring
        hipFileParamForceOdirectMode
        hipFileParamSkipTopologyDetection
        hipFileParamStreamMemopsBypass

    cdef enum hipFileStringConfigParameter_t:
        hipFileParamLoggingLevel
        hipFileParamEnvLogfilePath
        hipFileParamLogDir

# 
# @brief Get the value of a size_t configuration parameter
# @ingroup core
# 
# \warn_not_implemented
# 
# @param param The configuration parameter
# @param value The location to store the value of the configuration parameter
# 
# @return \hipfile_error_return
# 
# @note If the driver is open, the value returned is the value currently in use by the driver.
# @note If the driver is closed, the value returned is the value that was last set by hipFileSetParameter*.
cdef hipFileError hipFileGetParameterSizeT(hipFileSizeTConfigParameter_t param,size_t * value) noexcept nogil


# 
# @brief Get the value of a Boolean configuration parameter
# @ingroup core
# 
# \warn_not_implemented
# 
# @param param The configuration parameter
# @param value The location to store the value of the configuration parameter
# 
# @return \hipfile_error_return
# 
# @note If the driver is open, the value returned is the value currently in use by the driver.
# @note If the driver is closed, the value returned is the value that was last set by hipFileSetParameter*.
cdef hipFileError hipFileGetParameterBool(hipFileBoolConfigParameter_t param,_Bool * value) noexcept nogil


# 
# @brief Get the value of a string configuration parameter
# @ingroup core
# 
# \warn_not_implemented
# 
# @param param    The configuration parameter
# @param desc_str The location to store the value of the configuration parameter
# @param len      The length of the desc_str parameter
# 
# @return \hipfile_error_return
# 
# @note If the driver is open, the value returned is the value currently in use by the driver.
# @note If the driver is closed, the value returned is the value that was last set by hipFileSetParameter*.
cdef hipFileError hipFileGetParameterString(hipFileStringConfigParameter_t param,char * desc_str,int len) noexcept nogil


# 
# @brief Set the value of a size_t configuration parameter
# @ingroup core
# 
# \warn_not_implemented
# 
# @param param The configuration parameter
# @param value The value of the configuration parameter
# 
# @return \hipfile_error_return
# 
# @note Configuration parameter values may only be set when the driver is closed. Values are applied when the
# driver is opened.
cdef hipFileError hipFileSetParameterSizeT(hipFileSizeTConfigParameter_t param,size_t value) noexcept nogil


# 
# @brief Set the value of a Boolean configuration parameter
# @ingroup core
# 
# \warn_not_implemented
# 
# @param param The configuration parameter
# @param value The value of the configuration parameter
# 
# @return \hipfile_error_return
# 
# @note Configuration parameter values may only be set when the driver is closed. Values are applied when the
# driver is opened.
cdef hipFileError hipFileSetParameterBool(hipFileBoolConfigParameter_t param,_Bool value) noexcept nogil


# 
# @brief Set the value of a string configuration parameter
# @ingroup core
# 
# \warn_not_implemented
# 
# @param param    The configuration parameter
# @param desc_str The value of the configuration parameter
# 
# @return \hipfile_error_return
# 
# @note Configuration parameter values may only be set when the driver is closed. Values are applied when the
# driver is opened.
cdef hipFileError hipFileSetParameterString(hipFileStringConfigParameter_t param,const char * desc_str) noexcept nogil


cdef bint __hipfile_has_symbol(const char* name) noexcept nogil