hipFile buffer registration

hipFile buffer registration#

Buffer registration stores the buffer’s base pointer and length in bytes in an internal map. During hipFileRead() and hipFileWrite(), offsets and sizes are validated against the map without requiring HIP pointer lookup. This is useful for situations where the buffer is reused in multiple transfers or when predictable bounds checks are needed. The advantage is that buffer metadata is already loaded and doesn’t need to be extracted at the time of the I/O operation.

Buffers are registered with hipFileBufRegister(). If hipFileBufRegister() is called, it must be done before any calls to hipFileRead() or hipFileWrite(). Buffers with either hipMemoryTypeDevice or hipMemoryTypeHost can be registered.

Buffers referring to host memory must always be registered. Registering a buffer located in device memory is optional:

  • When an unregistered device buffer is passed to hipFileRead() or hipFileWrite(), hipFile resolves the pointer at the time of the I/O operation.

  • When a registered device buffer is passed, hipFile looks up the tracked entry and validates the I/O range against the registered length.

Call hipFileBufDeregister() when the buffer is no longer needed.