NVIDIA cuFile Python Wrapper

0.2.0 · abandoned · verified Thu Apr 16

cufile-python is a basic Python wrapper for the NVIDIA cuFile API, enabling Python programs to leverage GPUDirect Storage for high-performance I/O directly from GPU memory. The current version is 0.2.0. The project appears to be unmaintained, with its last release in 2021, meaning new features or bug fixes are unlikely.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates the essential steps for interacting with cufile-python: initializing the driver, opening a file with a cuFile descriptor, and deinitializing. It highlights the use of `cufile.lib.cuFileDriver` and the requirement for `bytes` filenames. Actual GPU-direct I/O operations involving data transfer are more complex and would typically follow this setup.

import cufile.lib as lib
import os

# --- Prerequisites: NVIDIA GPU, CUDA Toolkit, and cuFile library must be installed ---
# This example assumes cuFile is correctly set up and discoverable in the system's library path.

# Ensure a dummy file exists for I/O operations
filename = "/tmp/test_cufile.txt"
with open(filename, "w") as f:
    f.write("Hello, cuFile GPU-Direct Storage!")

try:
    # Initialize cuFile library
    lib.cuFileDriver.init()
    print("cuFile driver initialized successfully.")

    # Open file with cuFile. Note: Filename must be encoded to bytes.
    # os.O_RDWR is a standard file access flag.
    fd = lib.cuFileDriver.open(filename.encode('utf-8'), os.O_RDWR)
    print(f"Opened file '{filename}' with cuFile descriptor: {fd}")

    # In a real application, you would now perform GPU-direct I/O operations 
    # using this file descriptor and GPU memory buffers.
    # For this quickstart, we just demonstrate the basic open/close workflow.

    # Close file
    lib.cuFileDriver.close(fd)
    print(f"Closed cuFile descriptor: {fd}")

except RuntimeError as e:
    print(f"Error during cuFile operation: {e}\n")
    print("HINT: Ensure NVIDIA cuFile library is correctly installed, and your GPU is configured.")
except Exception as e:
    print(f"An unexpected error occurred: {e}")
finally:
    # Deinitialize cuFile library
    try:
        lib.cuFileDriver.fini()
        print("cuFile driver deinitialized.")
    except Exception as e:
        # Fini might fail if init failed or was never called successfully
        print(f"Warning: Error during cuFile deinitialization: {e}")

    # Clean up the dummy file
    if os.path.exists(filename):
        os.remove(filename)
        print(f"Cleaned up temporary file: {filename}")

view raw JSON →