KvikIO (CUDA 12)

26.4.0 · active · verified Thu Apr 16

KvikIO is a Python and C++ library designed for high-performance file I/O, providing Python and C++ bindings to cuFile, which enables GPUDirect Storage (GDS). As part of the RAPIDS suite, it efficiently handles both host and device (GPU) memory I/O. The library is actively maintained with frequent, typically monthly or bi-monthly, releases aligned with the broader RAPIDS ecosystem. The current version is 26.4.0.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to write a CuPy array (GPU memory) to a file and read it back using KvikIO's CuFile API. It mimics Python's built-in `open()` and file operations, but operates on GPU device memory directly, leveraging GPUDirect Storage if available.

import os
import cupy
from kvikio.cufile import CuFile

# Ensure a temporary file path is available
file_path = os.environ.get('KVIKIO_TEST_FILE_PATH', '/tmp/kvikio-example-data.bin')

# Create a CuPy array on the GPU
a = cupy.arange(100, dtype=cupy.int64)

print(f"Writing CuPy array to {file_path} using KvikIO...")
# Write the array to a file using KvikIO
with CuFile(file_path, 'w') as f:
    f.write(a)

print(f"Reading data from {file_path} back into a CuPy array...")
# Read data back into a new CuPy array
b = cupy.empty_like(a)
with CuFile(file_path, 'r') as f:
    f.read(b)

# Verify the data
assert cupy.array_equal(a, b)
print("Data written and read successfully, and arrays match!")

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

view raw JSON →