1. Usage#
This section describes the operation of the cuFile APIs.
Because the functionality is part of the CUDA Driver C API, the APIs use the cuFile prefix and camel case motif of the CUDA Driver.
All APIs are thread-safe.
The fork system call should not be used after the library is initialized. The behavior of the APIs after the fork system call is undefined in the child process.
The APIs with GPU buffers should be called in a valid CUDA context and stream if applicable.
All APIs are issued from the CPU, not the GPU.
Note
Starting from CUDA toolkit 12.2 (GDS version 1.7.x) release cuFile APIs support memory allocated on GPU device as well as host memory. peer to peer transfer using GPUDirect is supported to and from device memory on supported file system and hardware configurations. The APIs will refer to this memory address as buffer pointer unless the API specifically applies to a particular type of memory.
1.1. Dynamic Interactions#
The following describes the dynamic interactions between the cuFile APIs.
Some of the cuFile APIs are optional. If they are not called proactively, their actions will occur reactively:
If cuFile{DriverOpen, HandleRegister, BufRegister} `` is called on a driver, file, or buffer, respectively that has been
opened or registered by a previous ``cuFile* API call, this will result in an error. Calling cuFile{BufDeregister, HandleDeregister, DriverClose}
on a buffer, file, or driver, respectively that has never been opened or registered by a previous cuFile* API
call results in an error. For these errors, the output parameters of the APIs are left in an undefined state,
and there are no other side effects.
cuFileDriverOpenexplicitly causes driver initialization.Its use is optional. If it is not used, driver initialization happens implicitly at the first use of the
cuFile{HandleRegister, Read, Write, BufRegister}APIs.(Mandatory)
cuFileHandleRegisterturns an OS-specific file descriptor into aCUfileHandle_tand performs checking on the GDS supportability based on the mount point and the way that the file was opened.cuFileBufRegisterexplicitly registers a memory buffer.If this API is not called, an internal registered memory is used if required on the first time the buffer is used, for example, in
cuFile{Read, Write}.cuFile{BufDeregister, HandleDeregister}explicitly frees a buffer and file resources, respectively.If this API is not called, the buffer and resources are implicitly freed when the driver is closed using
cuFileDriverClose.cuFileDriverCloseexplicitly frees driver resources.If this API is not called, the driver resources are implicitly freed when
dlclose()is performed on the library handle or when the process is terminated.
Note
In GDS v1.20 (CUDA 13.5), cuFile and cuObject have separate configuration files and environment variables but share a runtime within a process. The first successful initialization, whether explicit or implicit, determines which configuration is loaded. Subsequent initialization calls reuse that configuration without loading the other interface’s configuration, until the shared runtime is fully shut down.
Calling cuFileDriverOpen() after cuObject has initialized the shared runtime logs a warning and continues using the cuObject configuration.
Direct application use of both cuFile and cuObject APIs in the same process is not supported in this release. This restriction does not apply to cuObject’s internal use of cuFile. Applications requiring independent cuFile and cuObject configurations must use separate processes.
1.2. Driver, File, and Buffer Management#
This section describes the overall workflow to manage the driver, the file, and buffer management:
Call
cuFileDriverOpen()to initialize the state of the critical performance path.Allocate GPU memory with cudaMalloc,
cudaMallocManaged,cuMem*APIs or host memory usingcudaMallocHost,mallocormmap.To register the buffer, call
cuFileBufRegisterto initialize the buffer state of the critical performance path.Complete the following IO workflow:
For Linux, open a file with POSIX open.
Call
cuFileHandleRegisterto wrap an existing file descriptor in an OS-agnosticCUfileHandle_t. This step evaluates the suitability of the file state and the file mount for GDS and initializes the file state of the critical performance path.Call IO APIs such as
cuFileRead/cuFileWriteon an existing cuFile handle and existing buffer.If the
cuFileBufRegisterhas not been previously called on the buffer pointer,cuFileRead/cuFileWritewill use internal registered buffers when required.Not using cuFileBufRegister might not be performant for small IO sizes.
Refer to the GPUDirect Best Practices Guide for more information.
Unless an error condition is returned, the IO is performed successfully.
Call
cuFileBufDeregisterto free the buffer-specific cuFile state.Call
cuFileHandleDeregisterto free the file-specific cuFile state.Call
cuFileDriverCloseto free up the cuFile state.
Note
Not using the cuFileDeregister and cuFileDriverClose APIs (steps 5, 6, and 7) might unnecessarily consume
resources, as shown by tools such as valgrind. The best practice is to always call these APIs in the application cleanup paths.
1.3. cuFile Compatibility Mode#
Use Cases
cuFile APIs can be used in different scenarios:
Developers building GPUDirect Storage applications with cuFile APIs, but don’t have the supported hardware configurations.
Developers building applications running on GPU cards that have CUDA compute capability > 6, but don’t have BAR space exposed.
Deployments where
nvidia-fs.kois not loaded or cannot be loaded.Deployments where the Linux distribution does not support GPUDirect Storage.
Deployments where the filesystem may be not supported with GPUDirect Storage.
Deployments where the network links are not enabled with RDMA support.
Deployment where the configuration is not optimal for GPUDirect Storage.
Behavior
The cuFile library provides a mechanism for cuFile reads and writes to use compatibility mode using POSIX pread,
pwrite, and aio_submit APIS respectively to host memory and copying to GPU memory when applicable. The behavior
of compatibility mode with cuFile APIs is determined by the following configuration parameters.
Configuration Option (default) |
cuFile IO Behavior |
|---|---|
“allow_compat_mode”: true |
If |
“force_compat_mode”: false |
If |
“gds_rdma_write_support”: true |
If |
“posix_unaligned_writes” : false |
If |
“lustre:posix_gds_min_kb” : 0 |
For a lustre filesystem, if greater than Note: This option will force posix mode even if |
“weka:rdma_write_support” : false |
If this option is Note: If the option is set to |
“gpfs:gds_write_support” : false |
If this option is false, all writes to IBM Spectrum Scale will use compatibility mode. Note: If the option is set to |
“rdma_dynamic_routing”: false, “rdma_dynamic_routing_order”: [ “ “SYS_MEM” ] |
If |
In addition to the above configuration options, compatibility mode will be used as a fallback option for following use cases.
Use Case |
cuFile IO Behavior |
|---|---|
No BAR1 memory in GPU. |
Use compatibility mode. |
For wekaFS or IBM Spectrum Scale mounts: If there are no |
Use compatibility mode. |
Bounce buffers cannot be allocated in GPU memory. |
Use compatibility mode. |
For WekaFS and IBM Spectrum Scale: If the kernel returns |
Retry the IO operation internally using compatibility mode. |
cuFile Stream and cuFile Batch APIs on IBM Spectrum Scale or WekaFS |
All Async and batch operations will internally use compatibility mode IO. |
The |
All IO operations will use compatibility mode. |
Limitations
Compatible mode does not work in cases where the GPUs have CUDA compute capability less than 6.
GDS Compat mode has been tested and works with GDS enabled file systems and environments. It has not been tested to work on all other filesystems.