diff --git a/.github/actions/fetch_ctk/action.yml b/.github/actions/fetch_ctk/action.yml index 6a90c63e2..7d2aaf3b2 100644 --- a/.github/actions/fetch_ctk/action.yml +++ b/.github/actions/fetch_ctk/action.yml @@ -17,7 +17,7 @@ inputs: description: "A list of the CTK components to install as a comma-separated list. e.g. 'cuda_nvcc,cuda_nvrtc,cuda_cudart'" required: false type: string - default: "cuda_nvcc,cuda_cudart,cuda_nvrtc,cuda_profiler_api,cuda_cccl,libnvjitlink" + default: "cuda_nvcc,cuda_cudart,cuda_nvrtc,cuda_profiler_api,cuda_cccl,libnvjitlink,libcufile" runs: using: composite diff --git a/cuda_bindings/cuda/bindings/_internal/cufile.pxd b/cuda_bindings/cuda/bindings/_internal/cufile.pxd new file mode 100644 index 000000000..0249f4a0c --- /dev/null +++ b/cuda_bindings/cuda/bindings/_internal/cufile.pxd @@ -0,0 +1,43 @@ +# Copyright (c) 2025, NVIDIA CORPORATION & AFFILIATES. ALL RIGHTS RESERVED. +# +# SPDX-License-Identifier: LicenseRef-NVIDIA-SOFTWARE-LICENSE +# +# This code was automatically generated with version 12.9.0. Do not modify it directly. + +from ..cycufile cimport * + + +############################################################################### +# Wrapper functions +############################################################################### + +cdef CUfileError_t _cuFileHandleRegister(CUfileHandle_t* fh, CUfileDescr_t* descr) except?CUFILE_LOADING_ERROR nogil +cdef void _cuFileHandleDeregister(CUfileHandle_t fh) except* nogil +cdef CUfileError_t _cuFileBufRegister(const void* bufPtr_base, size_t length, int flags) except?CUFILE_LOADING_ERROR nogil +cdef CUfileError_t _cuFileBufDeregister(const void* bufPtr_base) except?CUFILE_LOADING_ERROR nogil +cdef ssize_t _cuFileRead(CUfileHandle_t fh, void* bufPtr_base, size_t size, off_t file_offset, off_t bufPtr_offset) except* nogil +cdef ssize_t _cuFileWrite(CUfileHandle_t fh, const void* bufPtr_base, size_t size, off_t file_offset, off_t bufPtr_offset) except* nogil +cdef CUfileError_t _cuFileDriverOpen() except?CUFILE_LOADING_ERROR nogil +cdef CUfileError_t _cuFileDriverClose_v2() except?CUFILE_LOADING_ERROR nogil +cdef long _cuFileUseCount() except* nogil +cdef CUfileError_t _cuFileDriverGetProperties(CUfileDrvProps_t* props) except?CUFILE_LOADING_ERROR nogil +cdef CUfileError_t _cuFileDriverSetPollMode(cpp_bool poll, size_t poll_threshold_size) except?CUFILE_LOADING_ERROR nogil +cdef CUfileError_t _cuFileDriverSetMaxDirectIOSize(size_t max_direct_io_size) except?CUFILE_LOADING_ERROR nogil +cdef CUfileError_t _cuFileDriverSetMaxCacheSize(size_t max_cache_size) except?CUFILE_LOADING_ERROR nogil +cdef CUfileError_t _cuFileDriverSetMaxPinnedMemSize(size_t max_pinned_size) except?CUFILE_LOADING_ERROR nogil +cdef CUfileError_t _cuFileBatchIOSetUp(CUfileBatchHandle_t* batch_idp, unsigned nr) except?CUFILE_LOADING_ERROR nogil +cdef CUfileError_t _cuFileBatchIOSubmit(CUfileBatchHandle_t batch_idp, unsigned nr, CUfileIOParams_t* iocbp, unsigned int flags) except?CUFILE_LOADING_ERROR nogil +cdef CUfileError_t _cuFileBatchIOGetStatus(CUfileBatchHandle_t batch_idp, unsigned min_nr, unsigned* nr, CUfileIOEvents_t* iocbp, timespec* timeout) except?CUFILE_LOADING_ERROR nogil +cdef CUfileError_t _cuFileBatchIOCancel(CUfileBatchHandle_t batch_idp) except?CUFILE_LOADING_ERROR nogil +cdef void _cuFileBatchIODestroy(CUfileBatchHandle_t batch_idp) except* nogil +cdef CUfileError_t _cuFileReadAsync(CUfileHandle_t fh, void* bufPtr_base, size_t* size_p, off_t* file_offset_p, off_t* bufPtr_offset_p, ssize_t* bytes_read_p, CUstream stream) except?CUFILE_LOADING_ERROR nogil +cdef CUfileError_t _cuFileWriteAsync(CUfileHandle_t fh, void* bufPtr_base, size_t* size_p, off_t* file_offset_p, off_t* bufPtr_offset_p, ssize_t* bytes_written_p, CUstream stream) except?CUFILE_LOADING_ERROR nogil +cdef CUfileError_t _cuFileStreamRegister(CUstream stream, unsigned flags) except?CUFILE_LOADING_ERROR nogil +cdef CUfileError_t _cuFileStreamDeregister(CUstream stream) except?CUFILE_LOADING_ERROR nogil +cdef CUfileError_t _cuFileGetVersion(int* version) except?CUFILE_LOADING_ERROR nogil +cdef CUfileError_t _cuFileGetParameterSizeT(CUFileSizeTConfigParameter_t param, size_t* value) except?CUFILE_LOADING_ERROR nogil +cdef CUfileError_t _cuFileGetParameterBool(CUFileBoolConfigParameter_t param, cpp_bool* value) except?CUFILE_LOADING_ERROR nogil +cdef CUfileError_t _cuFileGetParameterString(CUFileStringConfigParameter_t param, char* desc_str, int len) except?CUFILE_LOADING_ERROR nogil +cdef CUfileError_t _cuFileSetParameterSizeT(CUFileSizeTConfigParameter_t param, size_t value) except?CUFILE_LOADING_ERROR nogil +cdef CUfileError_t _cuFileSetParameterBool(CUFileBoolConfigParameter_t param, cpp_bool value) except?CUFILE_LOADING_ERROR nogil +cdef CUfileError_t _cuFileSetParameterString(CUFileStringConfigParameter_t param, const char* desc_str) except?CUFILE_LOADING_ERROR nogil diff --git a/cuda_bindings/cuda/bindings/_internal/cufile_linux.pyx b/cuda_bindings/cuda/bindings/_internal/cufile_linux.pyx new file mode 100644 index 000000000..2c0a98acf --- /dev/null +++ b/cuda_bindings/cuda/bindings/_internal/cufile_linux.pyx @@ -0,0 +1,734 @@ +# Copyright (c) 2025, NVIDIA CORPORATION & AFFILIATES. ALL RIGHTS RESERVED. +# +# SPDX-License-Identifier: LicenseRef-NVIDIA-SOFTWARE-LICENSE +# +# This code was automatically generated with version 12.9.0. Do not modify it directly. + +from libc.stdint cimport intptr_t, uintptr_t + +from .utils import FunctionNotFoundError, NotSupportedError + +from cuda.bindings import path_finder + +import cython + +############################################################################### +# Extern +############################################################################### + +cdef extern from "" nogil: + void* dlopen(const char*, int) + char* dlerror() + void* dlsym(void*, const char*) + int dlclose(void*) + + enum: + RTLD_LAZY + RTLD_NOW + RTLD_GLOBAL + RTLD_LOCAL + + const void* RTLD_DEFAULT 'RTLD_DEFAULT' + + +############################################################################### +# Wrapper init +############################################################################### + +cdef bint __py_cufile_init = False +cdef void* __cuDriverGetVersion = NULL + +cdef void* __cuFileHandleRegister = NULL +cdef void* __cuFileHandleDeregister = NULL +cdef void* __cuFileBufRegister = NULL +cdef void* __cuFileBufDeregister = NULL +cdef void* __cuFileRead = NULL +cdef void* __cuFileWrite = NULL +cdef void* __cuFileDriverOpen = NULL +cdef void* __cuFileDriverClose_v2 = NULL +cdef void* __cuFileUseCount = NULL +cdef void* __cuFileDriverGetProperties = NULL +cdef void* __cuFileDriverSetPollMode = NULL +cdef void* __cuFileDriverSetMaxDirectIOSize = NULL +cdef void* __cuFileDriverSetMaxCacheSize = NULL +cdef void* __cuFileDriverSetMaxPinnedMemSize = NULL +cdef void* __cuFileBatchIOSetUp = NULL +cdef void* __cuFileBatchIOSubmit = NULL +cdef void* __cuFileBatchIOGetStatus = NULL +cdef void* __cuFileBatchIOCancel = NULL +cdef void* __cuFileBatchIODestroy = NULL +cdef void* __cuFileReadAsync = NULL +cdef void* __cuFileWriteAsync = NULL +cdef void* __cuFileStreamRegister = NULL +cdef void* __cuFileStreamDeregister = NULL +cdef void* __cuFileGetVersion = NULL +cdef void* __cuFileGetParameterSizeT = NULL +cdef void* __cuFileGetParameterBool = NULL +cdef void* __cuFileGetParameterString = NULL +cdef void* __cuFileSetParameterSizeT = NULL +cdef void* __cuFileSetParameterBool = NULL +cdef void* __cuFileSetParameterString = NULL + + +cdef void* load_library(const int driver_ver) except* with gil: + cdef uintptr_t handle = path_finder._load_nvidia_dynamic_library("cufile").handle + return handle + + +cdef int _check_or_init_cufile() except -1 nogil: + global __py_cufile_init + if __py_cufile_init: + return 0 + + # Load driver to check version + cdef void* handle = NULL + handle = dlopen('libcuda.so.1', RTLD_NOW | RTLD_GLOBAL) + if handle == NULL: + with gil: + err_msg = dlerror() + raise NotSupportedError(f'CUDA driver is not found ({err_msg.decode()})') + global __cuDriverGetVersion + if __cuDriverGetVersion == NULL: + __cuDriverGetVersion = dlsym(handle, "cuDriverGetVersion") + if __cuDriverGetVersion == NULL: + with gil: + raise RuntimeError('something went wrong') + cdef int err, driver_ver + err = (__cuDriverGetVersion)(&driver_ver) + if err != 0: + with gil: + raise RuntimeError('something went wrong') + #dlclose(handle) + handle = NULL + + # Load function + global __cuFileHandleRegister + __cuFileHandleRegister = dlsym(RTLD_DEFAULT, 'cuFileHandleRegister') + if __cuFileHandleRegister == NULL: + if handle == NULL: + handle = load_library(driver_ver) + __cuFileHandleRegister = dlsym(handle, 'cuFileHandleRegister') + + global __cuFileHandleDeregister + __cuFileHandleDeregister = dlsym(RTLD_DEFAULT, 'cuFileHandleDeregister') + if __cuFileHandleDeregister == NULL: + if handle == NULL: + handle = load_library(driver_ver) + __cuFileHandleDeregister = dlsym(handle, 'cuFileHandleDeregister') + + global __cuFileBufRegister + __cuFileBufRegister = dlsym(RTLD_DEFAULT, 'cuFileBufRegister') + if __cuFileBufRegister == NULL: + if handle == NULL: + handle = load_library(driver_ver) + __cuFileBufRegister = dlsym(handle, 'cuFileBufRegister') + + global __cuFileBufDeregister + __cuFileBufDeregister = dlsym(RTLD_DEFAULT, 'cuFileBufDeregister') + if __cuFileBufDeregister == NULL: + if handle == NULL: + handle = load_library(driver_ver) + __cuFileBufDeregister = dlsym(handle, 'cuFileBufDeregister') + + global __cuFileRead + __cuFileRead = dlsym(RTLD_DEFAULT, 'cuFileRead') + if __cuFileRead == NULL: + if handle == NULL: + handle = load_library(driver_ver) + __cuFileRead = dlsym(handle, 'cuFileRead') + + global __cuFileWrite + __cuFileWrite = dlsym(RTLD_DEFAULT, 'cuFileWrite') + if __cuFileWrite == NULL: + if handle == NULL: + handle = load_library(driver_ver) + __cuFileWrite = dlsym(handle, 'cuFileWrite') + + global __cuFileDriverOpen + __cuFileDriverOpen = dlsym(RTLD_DEFAULT, 'cuFileDriverOpen') + if __cuFileDriverOpen == NULL: + if handle == NULL: + handle = load_library(driver_ver) + __cuFileDriverOpen = dlsym(handle, 'cuFileDriverOpen') + + global __cuFileDriverClose_v2 + __cuFileDriverClose_v2 = dlsym(RTLD_DEFAULT, 'cuFileDriverClose_v2') + if __cuFileDriverClose_v2 == NULL: + if handle == NULL: + handle = load_library(driver_ver) + __cuFileDriverClose_v2 = dlsym(handle, 'cuFileDriverClose_v2') + + global __cuFileUseCount + __cuFileUseCount = dlsym(RTLD_DEFAULT, 'cuFileUseCount') + if __cuFileUseCount == NULL: + if handle == NULL: + handle = load_library(driver_ver) + __cuFileUseCount = dlsym(handle, 'cuFileUseCount') + + global __cuFileDriverGetProperties + __cuFileDriverGetProperties = dlsym(RTLD_DEFAULT, 'cuFileDriverGetProperties') + if __cuFileDriverGetProperties == NULL: + if handle == NULL: + handle = load_library(driver_ver) + __cuFileDriverGetProperties = dlsym(handle, 'cuFileDriverGetProperties') + + global __cuFileDriverSetPollMode + __cuFileDriverSetPollMode = dlsym(RTLD_DEFAULT, 'cuFileDriverSetPollMode') + if __cuFileDriverSetPollMode == NULL: + if handle == NULL: + handle = load_library(driver_ver) + __cuFileDriverSetPollMode = dlsym(handle, 'cuFileDriverSetPollMode') + + global __cuFileDriverSetMaxDirectIOSize + __cuFileDriverSetMaxDirectIOSize = dlsym(RTLD_DEFAULT, 'cuFileDriverSetMaxDirectIOSize') + if __cuFileDriverSetMaxDirectIOSize == NULL: + if handle == NULL: + handle = load_library(driver_ver) + __cuFileDriverSetMaxDirectIOSize = dlsym(handle, 'cuFileDriverSetMaxDirectIOSize') + + global __cuFileDriverSetMaxCacheSize + __cuFileDriverSetMaxCacheSize = dlsym(RTLD_DEFAULT, 'cuFileDriverSetMaxCacheSize') + if __cuFileDriverSetMaxCacheSize == NULL: + if handle == NULL: + handle = load_library(driver_ver) + __cuFileDriverSetMaxCacheSize = dlsym(handle, 'cuFileDriverSetMaxCacheSize') + + global __cuFileDriverSetMaxPinnedMemSize + __cuFileDriverSetMaxPinnedMemSize = dlsym(RTLD_DEFAULT, 'cuFileDriverSetMaxPinnedMemSize') + if __cuFileDriverSetMaxPinnedMemSize == NULL: + if handle == NULL: + handle = load_library(driver_ver) + __cuFileDriverSetMaxPinnedMemSize = dlsym(handle, 'cuFileDriverSetMaxPinnedMemSize') + + global __cuFileBatchIOSetUp + __cuFileBatchIOSetUp = dlsym(RTLD_DEFAULT, 'cuFileBatchIOSetUp') + if __cuFileBatchIOSetUp == NULL: + if handle == NULL: + handle = load_library(driver_ver) + __cuFileBatchIOSetUp = dlsym(handle, 'cuFileBatchIOSetUp') + + global __cuFileBatchIOSubmit + __cuFileBatchIOSubmit = dlsym(RTLD_DEFAULT, 'cuFileBatchIOSubmit') + if __cuFileBatchIOSubmit == NULL: + if handle == NULL: + handle = load_library(driver_ver) + __cuFileBatchIOSubmit = dlsym(handle, 'cuFileBatchIOSubmit') + + global __cuFileBatchIOGetStatus + __cuFileBatchIOGetStatus = dlsym(RTLD_DEFAULT, 'cuFileBatchIOGetStatus') + if __cuFileBatchIOGetStatus == NULL: + if handle == NULL: + handle = load_library(driver_ver) + __cuFileBatchIOGetStatus = dlsym(handle, 'cuFileBatchIOGetStatus') + + global __cuFileBatchIOCancel + __cuFileBatchIOCancel = dlsym(RTLD_DEFAULT, 'cuFileBatchIOCancel') + if __cuFileBatchIOCancel == NULL: + if handle == NULL: + handle = load_library(driver_ver) + __cuFileBatchIOCancel = dlsym(handle, 'cuFileBatchIOCancel') + + global __cuFileBatchIODestroy + __cuFileBatchIODestroy = dlsym(RTLD_DEFAULT, 'cuFileBatchIODestroy') + if __cuFileBatchIODestroy == NULL: + if handle == NULL: + handle = load_library(driver_ver) + __cuFileBatchIODestroy = dlsym(handle, 'cuFileBatchIODestroy') + + global __cuFileReadAsync + __cuFileReadAsync = dlsym(RTLD_DEFAULT, 'cuFileReadAsync') + if __cuFileReadAsync == NULL: + if handle == NULL: + handle = load_library(driver_ver) + __cuFileReadAsync = dlsym(handle, 'cuFileReadAsync') + + global __cuFileWriteAsync + __cuFileWriteAsync = dlsym(RTLD_DEFAULT, 'cuFileWriteAsync') + if __cuFileWriteAsync == NULL: + if handle == NULL: + handle = load_library(driver_ver) + __cuFileWriteAsync = dlsym(handle, 'cuFileWriteAsync') + + global __cuFileStreamRegister + __cuFileStreamRegister = dlsym(RTLD_DEFAULT, 'cuFileStreamRegister') + if __cuFileStreamRegister == NULL: + if handle == NULL: + handle = load_library(driver_ver) + __cuFileStreamRegister = dlsym(handle, 'cuFileStreamRegister') + + global __cuFileStreamDeregister + __cuFileStreamDeregister = dlsym(RTLD_DEFAULT, 'cuFileStreamDeregister') + if __cuFileStreamDeregister == NULL: + if handle == NULL: + handle = load_library(driver_ver) + __cuFileStreamDeregister = dlsym(handle, 'cuFileStreamDeregister') + + global __cuFileGetVersion + __cuFileGetVersion = dlsym(RTLD_DEFAULT, 'cuFileGetVersion') + if __cuFileGetVersion == NULL: + if handle == NULL: + handle = load_library(driver_ver) + __cuFileGetVersion = dlsym(handle, 'cuFileGetVersion') + + global __cuFileGetParameterSizeT + __cuFileGetParameterSizeT = dlsym(RTLD_DEFAULT, 'cuFileGetParameterSizeT') + if __cuFileGetParameterSizeT == NULL: + if handle == NULL: + handle = load_library(driver_ver) + __cuFileGetParameterSizeT = dlsym(handle, 'cuFileGetParameterSizeT') + + global __cuFileGetParameterBool + __cuFileGetParameterBool = dlsym(RTLD_DEFAULT, 'cuFileGetParameterBool') + if __cuFileGetParameterBool == NULL: + if handle == NULL: + handle = load_library(driver_ver) + __cuFileGetParameterBool = dlsym(handle, 'cuFileGetParameterBool') + + global __cuFileGetParameterString + __cuFileGetParameterString = dlsym(RTLD_DEFAULT, 'cuFileGetParameterString') + if __cuFileGetParameterString == NULL: + if handle == NULL: + handle = load_library(driver_ver) + __cuFileGetParameterString = dlsym(handle, 'cuFileGetParameterString') + + global __cuFileSetParameterSizeT + __cuFileSetParameterSizeT = dlsym(RTLD_DEFAULT, 'cuFileSetParameterSizeT') + if __cuFileSetParameterSizeT == NULL: + if handle == NULL: + handle = load_library(driver_ver) + __cuFileSetParameterSizeT = dlsym(handle, 'cuFileSetParameterSizeT') + + global __cuFileSetParameterBool + __cuFileSetParameterBool = dlsym(RTLD_DEFAULT, 'cuFileSetParameterBool') + if __cuFileSetParameterBool == NULL: + if handle == NULL: + handle = load_library(driver_ver) + __cuFileSetParameterBool = dlsym(handle, 'cuFileSetParameterBool') + + global __cuFileSetParameterString + __cuFileSetParameterString = dlsym(RTLD_DEFAULT, 'cuFileSetParameterString') + if __cuFileSetParameterString == NULL: + if handle == NULL: + handle = load_library(driver_ver) + __cuFileSetParameterString = dlsym(handle, 'cuFileSetParameterString') + + __py_cufile_init = True + return 0 + + +cdef dict func_ptrs = None + + +cpdef dict _inspect_function_pointers(): + global func_ptrs + if func_ptrs is not None: + return func_ptrs + + _check_or_init_cufile() + cdef dict data = {} + + global __cuFileHandleRegister + data["__cuFileHandleRegister"] = __cuFileHandleRegister + + global __cuFileHandleDeregister + data["__cuFileHandleDeregister"] = __cuFileHandleDeregister + + global __cuFileBufRegister + data["__cuFileBufRegister"] = __cuFileBufRegister + + global __cuFileBufDeregister + data["__cuFileBufDeregister"] = __cuFileBufDeregister + + global __cuFileRead + data["__cuFileRead"] = __cuFileRead + + global __cuFileWrite + data["__cuFileWrite"] = __cuFileWrite + + global __cuFileDriverOpen + data["__cuFileDriverOpen"] = __cuFileDriverOpen + + global __cuFileDriverClose_v2 + data["__cuFileDriverClose_v2"] = __cuFileDriverClose_v2 + + global __cuFileUseCount + data["__cuFileUseCount"] = __cuFileUseCount + + global __cuFileDriverGetProperties + data["__cuFileDriverGetProperties"] = __cuFileDriverGetProperties + + global __cuFileDriverSetPollMode + data["__cuFileDriverSetPollMode"] = __cuFileDriverSetPollMode + + global __cuFileDriverSetMaxDirectIOSize + data["__cuFileDriverSetMaxDirectIOSize"] = __cuFileDriverSetMaxDirectIOSize + + global __cuFileDriverSetMaxCacheSize + data["__cuFileDriverSetMaxCacheSize"] = __cuFileDriverSetMaxCacheSize + + global __cuFileDriverSetMaxPinnedMemSize + data["__cuFileDriverSetMaxPinnedMemSize"] = __cuFileDriverSetMaxPinnedMemSize + + global __cuFileBatchIOSetUp + data["__cuFileBatchIOSetUp"] = __cuFileBatchIOSetUp + + global __cuFileBatchIOSubmit + data["__cuFileBatchIOSubmit"] = __cuFileBatchIOSubmit + + global __cuFileBatchIOGetStatus + data["__cuFileBatchIOGetStatus"] = __cuFileBatchIOGetStatus + + global __cuFileBatchIOCancel + data["__cuFileBatchIOCancel"] = __cuFileBatchIOCancel + + global __cuFileBatchIODestroy + data["__cuFileBatchIODestroy"] = __cuFileBatchIODestroy + + global __cuFileReadAsync + data["__cuFileReadAsync"] = __cuFileReadAsync + + global __cuFileWriteAsync + data["__cuFileWriteAsync"] = __cuFileWriteAsync + + global __cuFileStreamRegister + data["__cuFileStreamRegister"] = __cuFileStreamRegister + + global __cuFileStreamDeregister + data["__cuFileStreamDeregister"] = __cuFileStreamDeregister + + global __cuFileGetVersion + data["__cuFileGetVersion"] = __cuFileGetVersion + + global __cuFileGetParameterSizeT + data["__cuFileGetParameterSizeT"] = __cuFileGetParameterSizeT + + global __cuFileGetParameterBool + data["__cuFileGetParameterBool"] = __cuFileGetParameterBool + + global __cuFileGetParameterString + data["__cuFileGetParameterString"] = __cuFileGetParameterString + + global __cuFileSetParameterSizeT + data["__cuFileSetParameterSizeT"] = __cuFileSetParameterSizeT + + global __cuFileSetParameterBool + data["__cuFileSetParameterBool"] = __cuFileSetParameterBool + + global __cuFileSetParameterString + data["__cuFileSetParameterString"] = __cuFileSetParameterString + + func_ptrs = data + return data + + +cpdef _inspect_function_pointer(str name): + global func_ptrs + if func_ptrs is None: + func_ptrs = _inspect_function_pointers() + return func_ptrs[name] + + +############################################################################### +# Wrapper functions +############################################################################### + +cdef CUfileError_t _cuFileHandleRegister(CUfileHandle_t* fh, CUfileDescr_t* descr) except?CUFILE_LOADING_ERROR nogil: + global __cuFileHandleRegister + _check_or_init_cufile() + if __cuFileHandleRegister == NULL: + with gil: + raise FunctionNotFoundError("function cuFileHandleRegister is not found") + return (__cuFileHandleRegister)( + fh, descr) + + +@cython.show_performance_hints(False) +cdef void _cuFileHandleDeregister(CUfileHandle_t fh) except* nogil: + global __cuFileHandleDeregister + _check_or_init_cufile() + if __cuFileHandleDeregister == NULL: + with gil: + raise FunctionNotFoundError("function cuFileHandleDeregister is not found") + (__cuFileHandleDeregister)( + fh) + + +cdef CUfileError_t _cuFileBufRegister(const void* bufPtr_base, size_t length, int flags) except?CUFILE_LOADING_ERROR nogil: + global __cuFileBufRegister + _check_or_init_cufile() + if __cuFileBufRegister == NULL: + with gil: + raise FunctionNotFoundError("function cuFileBufRegister is not found") + return (__cuFileBufRegister)( + bufPtr_base, length, flags) + + +cdef CUfileError_t _cuFileBufDeregister(const void* bufPtr_base) except?CUFILE_LOADING_ERROR nogil: + global __cuFileBufDeregister + _check_or_init_cufile() + if __cuFileBufDeregister == NULL: + with gil: + raise FunctionNotFoundError("function cuFileBufDeregister is not found") + return (__cuFileBufDeregister)( + bufPtr_base) + + +cdef ssize_t _cuFileRead(CUfileHandle_t fh, void* bufPtr_base, size_t size, off_t file_offset, off_t bufPtr_offset) except* nogil: + global __cuFileRead + _check_or_init_cufile() + if __cuFileRead == NULL: + with gil: + raise FunctionNotFoundError("function cuFileRead is not found") + return (__cuFileRead)( + fh, bufPtr_base, size, file_offset, bufPtr_offset) + + +cdef ssize_t _cuFileWrite(CUfileHandle_t fh, const void* bufPtr_base, size_t size, off_t file_offset, off_t bufPtr_offset) except* nogil: + global __cuFileWrite + _check_or_init_cufile() + if __cuFileWrite == NULL: + with gil: + raise FunctionNotFoundError("function cuFileWrite is not found") + return (__cuFileWrite)( + fh, bufPtr_base, size, file_offset, bufPtr_offset) + + +cdef CUfileError_t _cuFileDriverOpen() except?CUFILE_LOADING_ERROR nogil: + global __cuFileDriverOpen + _check_or_init_cufile() + if __cuFileDriverOpen == NULL: + with gil: + raise FunctionNotFoundError("function cuFileDriverOpen is not found") + return (__cuFileDriverOpen)( + ) + + +cdef CUfileError_t _cuFileDriverClose_v2() except?CUFILE_LOADING_ERROR nogil: + global __cuFileDriverClose_v2 + _check_or_init_cufile() + if __cuFileDriverClose_v2 == NULL: + with gil: + raise FunctionNotFoundError("function cuFileDriverClose_v2 is not found") + return (__cuFileDriverClose_v2)( + ) + + +cdef long _cuFileUseCount() except* nogil: + global __cuFileUseCount + _check_or_init_cufile() + if __cuFileUseCount == NULL: + with gil: + raise FunctionNotFoundError("function cuFileUseCount is not found") + return (__cuFileUseCount)( + ) + + +cdef CUfileError_t _cuFileDriverGetProperties(CUfileDrvProps_t* props) except?CUFILE_LOADING_ERROR nogil: + global __cuFileDriverGetProperties + _check_or_init_cufile() + if __cuFileDriverGetProperties == NULL: + with gil: + raise FunctionNotFoundError("function cuFileDriverGetProperties is not found") + return (__cuFileDriverGetProperties)( + props) + + +cdef CUfileError_t _cuFileDriverSetPollMode(cpp_bool poll, size_t poll_threshold_size) except?CUFILE_LOADING_ERROR nogil: + global __cuFileDriverSetPollMode + _check_or_init_cufile() + if __cuFileDriverSetPollMode == NULL: + with gil: + raise FunctionNotFoundError("function cuFileDriverSetPollMode is not found") + return (__cuFileDriverSetPollMode)( + poll, poll_threshold_size) + + +cdef CUfileError_t _cuFileDriverSetMaxDirectIOSize(size_t max_direct_io_size) except?CUFILE_LOADING_ERROR nogil: + global __cuFileDriverSetMaxDirectIOSize + _check_or_init_cufile() + if __cuFileDriverSetMaxDirectIOSize == NULL: + with gil: + raise FunctionNotFoundError("function cuFileDriverSetMaxDirectIOSize is not found") + return (__cuFileDriverSetMaxDirectIOSize)( + max_direct_io_size) + + +cdef CUfileError_t _cuFileDriverSetMaxCacheSize(size_t max_cache_size) except?CUFILE_LOADING_ERROR nogil: + global __cuFileDriverSetMaxCacheSize + _check_or_init_cufile() + if __cuFileDriverSetMaxCacheSize == NULL: + with gil: + raise FunctionNotFoundError("function cuFileDriverSetMaxCacheSize is not found") + return (__cuFileDriverSetMaxCacheSize)( + max_cache_size) + + +cdef CUfileError_t _cuFileDriverSetMaxPinnedMemSize(size_t max_pinned_size) except?CUFILE_LOADING_ERROR nogil: + global __cuFileDriverSetMaxPinnedMemSize + _check_or_init_cufile() + if __cuFileDriverSetMaxPinnedMemSize == NULL: + with gil: + raise FunctionNotFoundError("function cuFileDriverSetMaxPinnedMemSize is not found") + return (__cuFileDriverSetMaxPinnedMemSize)( + max_pinned_size) + + +cdef CUfileError_t _cuFileBatchIOSetUp(CUfileBatchHandle_t* batch_idp, unsigned nr) except?CUFILE_LOADING_ERROR nogil: + global __cuFileBatchIOSetUp + _check_or_init_cufile() + if __cuFileBatchIOSetUp == NULL: + with gil: + raise FunctionNotFoundError("function cuFileBatchIOSetUp is not found") + return (__cuFileBatchIOSetUp)( + batch_idp, nr) + + +cdef CUfileError_t _cuFileBatchIOSubmit(CUfileBatchHandle_t batch_idp, unsigned nr, CUfileIOParams_t* iocbp, unsigned int flags) except?CUFILE_LOADING_ERROR nogil: + global __cuFileBatchIOSubmit + _check_or_init_cufile() + if __cuFileBatchIOSubmit == NULL: + with gil: + raise FunctionNotFoundError("function cuFileBatchIOSubmit is not found") + return (__cuFileBatchIOSubmit)( + batch_idp, nr, iocbp, flags) + + +cdef CUfileError_t _cuFileBatchIOGetStatus(CUfileBatchHandle_t batch_idp, unsigned min_nr, unsigned* nr, CUfileIOEvents_t* iocbp, timespec* timeout) except?CUFILE_LOADING_ERROR nogil: + global __cuFileBatchIOGetStatus + _check_or_init_cufile() + if __cuFileBatchIOGetStatus == NULL: + with gil: + raise FunctionNotFoundError("function cuFileBatchIOGetStatus is not found") + return (__cuFileBatchIOGetStatus)( + batch_idp, min_nr, nr, iocbp, timeout) + + +cdef CUfileError_t _cuFileBatchIOCancel(CUfileBatchHandle_t batch_idp) except?CUFILE_LOADING_ERROR nogil: + global __cuFileBatchIOCancel + _check_or_init_cufile() + if __cuFileBatchIOCancel == NULL: + with gil: + raise FunctionNotFoundError("function cuFileBatchIOCancel is not found") + return (__cuFileBatchIOCancel)( + batch_idp) + + +@cython.show_performance_hints(False) +cdef void _cuFileBatchIODestroy(CUfileBatchHandle_t batch_idp) except* nogil: + global __cuFileBatchIODestroy + _check_or_init_cufile() + if __cuFileBatchIODestroy == NULL: + with gil: + raise FunctionNotFoundError("function cuFileBatchIODestroy is not found") + (__cuFileBatchIODestroy)( + batch_idp) + + +cdef CUfileError_t _cuFileReadAsync(CUfileHandle_t fh, void* bufPtr_base, size_t* size_p, off_t* file_offset_p, off_t* bufPtr_offset_p, ssize_t* bytes_read_p, CUstream stream) except?CUFILE_LOADING_ERROR nogil: + global __cuFileReadAsync + _check_or_init_cufile() + if __cuFileReadAsync == NULL: + with gil: + raise FunctionNotFoundError("function cuFileReadAsync is not found") + return (__cuFileReadAsync)( + fh, bufPtr_base, size_p, file_offset_p, bufPtr_offset_p, bytes_read_p, stream) + + +cdef CUfileError_t _cuFileWriteAsync(CUfileHandle_t fh, void* bufPtr_base, size_t* size_p, off_t* file_offset_p, off_t* bufPtr_offset_p, ssize_t* bytes_written_p, CUstream stream) except?CUFILE_LOADING_ERROR nogil: + global __cuFileWriteAsync + _check_or_init_cufile() + if __cuFileWriteAsync == NULL: + with gil: + raise FunctionNotFoundError("function cuFileWriteAsync is not found") + return (__cuFileWriteAsync)( + fh, bufPtr_base, size_p, file_offset_p, bufPtr_offset_p, bytes_written_p, stream) + + +cdef CUfileError_t _cuFileStreamRegister(CUstream stream, unsigned flags) except?CUFILE_LOADING_ERROR nogil: + global __cuFileStreamRegister + _check_or_init_cufile() + if __cuFileStreamRegister == NULL: + with gil: + raise FunctionNotFoundError("function cuFileStreamRegister is not found") + return (__cuFileStreamRegister)( + stream, flags) + + +cdef CUfileError_t _cuFileStreamDeregister(CUstream stream) except?CUFILE_LOADING_ERROR nogil: + global __cuFileStreamDeregister + _check_or_init_cufile() + if __cuFileStreamDeregister == NULL: + with gil: + raise FunctionNotFoundError("function cuFileStreamDeregister is not found") + return (__cuFileStreamDeregister)( + stream) + + +cdef CUfileError_t _cuFileGetVersion(int* version) except?CUFILE_LOADING_ERROR nogil: + global __cuFileGetVersion + _check_or_init_cufile() + if __cuFileGetVersion == NULL: + with gil: + raise FunctionNotFoundError("function cuFileGetVersion is not found") + return (__cuFileGetVersion)( + version) + + +cdef CUfileError_t _cuFileGetParameterSizeT(CUFileSizeTConfigParameter_t param, size_t* value) except?CUFILE_LOADING_ERROR nogil: + global __cuFileGetParameterSizeT + _check_or_init_cufile() + if __cuFileGetParameterSizeT == NULL: + with gil: + raise FunctionNotFoundError("function cuFileGetParameterSizeT is not found") + return (__cuFileGetParameterSizeT)( + param, value) + + +cdef CUfileError_t _cuFileGetParameterBool(CUFileBoolConfigParameter_t param, cpp_bool* value) except?CUFILE_LOADING_ERROR nogil: + global __cuFileGetParameterBool + _check_or_init_cufile() + if __cuFileGetParameterBool == NULL: + with gil: + raise FunctionNotFoundError("function cuFileGetParameterBool is not found") + return (__cuFileGetParameterBool)( + param, value) + + +cdef CUfileError_t _cuFileGetParameterString(CUFileStringConfigParameter_t param, char* desc_str, int len) except?CUFILE_LOADING_ERROR nogil: + global __cuFileGetParameterString + _check_or_init_cufile() + if __cuFileGetParameterString == NULL: + with gil: + raise FunctionNotFoundError("function cuFileGetParameterString is not found") + return (__cuFileGetParameterString)( + param, desc_str, len) + + +cdef CUfileError_t _cuFileSetParameterSizeT(CUFileSizeTConfigParameter_t param, size_t value) except?CUFILE_LOADING_ERROR nogil: + global __cuFileSetParameterSizeT + _check_or_init_cufile() + if __cuFileSetParameterSizeT == NULL: + with gil: + raise FunctionNotFoundError("function cuFileSetParameterSizeT is not found") + return (__cuFileSetParameterSizeT)( + param, value) + + +cdef CUfileError_t _cuFileSetParameterBool(CUFileBoolConfigParameter_t param, cpp_bool value) except?CUFILE_LOADING_ERROR nogil: + global __cuFileSetParameterBool + _check_or_init_cufile() + if __cuFileSetParameterBool == NULL: + with gil: + raise FunctionNotFoundError("function cuFileSetParameterBool is not found") + return (__cuFileSetParameterBool)( + param, value) + + +cdef CUfileError_t _cuFileSetParameterString(CUFileStringConfigParameter_t param, const char* desc_str) except?CUFILE_LOADING_ERROR nogil: + global __cuFileSetParameterString + _check_or_init_cufile() + if __cuFileSetParameterString == NULL: + with gil: + raise FunctionNotFoundError("function cuFileSetParameterString is not found") + return (__cuFileSetParameterString)( + param, desc_str) diff --git a/cuda_bindings/cuda/bindings/cufile.pxd b/cuda_bindings/cuda/bindings/cufile.pxd new file mode 100644 index 000000000..922684597 --- /dev/null +++ b/cuda_bindings/cuda/bindings/cufile.pxd @@ -0,0 +1,75 @@ +# Copyright (c) 2025, NVIDIA CORPORATION & AFFILIATES. ALL RIGHTS RESERVED. +# +# SPDX-License-Identifier: LicenseRef-NVIDIA-SOFTWARE-LICENSE +# +# This code was automatically generated with version 12.9.0. Do not modify it directly. + +from libc.stdint cimport intptr_t + +from .cycufile cimport * + + +############################################################################### +# Types +############################################################################### + +ctypedef CUfileHandle_t Handle +ctypedef CUfileBatchHandle_t BatchHandle +ctypedef CUfileError_t Error +ctypedef cufileRDMAInfo_t RDMAInfo +ctypedef CUfileFSOps_t FSOps +ctypedef CUfileIOEvents_t IOEvents +ctypedef CUfileDrvProps_t DrvProps +ctypedef CUfileIOParams_t IOParams + + +############################################################################### +# Enum +############################################################################### + +ctypedef CUfileOpError _OpError +ctypedef CUfileDriverStatusFlags_t _DriverStatusFlags +ctypedef CUfileDriverControlFlags_t _DriverControlFlags +ctypedef CUfileFeatureFlags_t _FeatureFlags +ctypedef CUfileFileHandleType _FileHandleType +ctypedef CUfileOpcode_t _Opcode +ctypedef CUfileStatus_t _Status +ctypedef CUfileBatchMode_t _BatchMode +ctypedef CUFileSizeTConfigParameter_t _SizeTConfigParameter +ctypedef CUFileBoolConfigParameter_t _BoolConfigParameter +ctypedef CUFileStringConfigParameter_t _StringConfigParameter + + +############################################################################### +# Functions +############################################################################### + +cpdef intptr_t handle_register(intptr_t descr) except? 0 +cpdef void handle_deregister(intptr_t fh) except* +cpdef buf_register(intptr_t buf_ptr_base, size_t length, int flags) +cpdef buf_deregister(intptr_t buf_ptr_base) +cpdef read(intptr_t fh, intptr_t buf_ptr_base, size_t size, off_t file_offset, off_t buf_ptr_offset) +cpdef write(intptr_t fh, intptr_t buf_ptr_base, size_t size, off_t file_offset, off_t buf_ptr_offset) +cpdef driver_open() +cpdef use_count() +cpdef driver_get_properties(intptr_t props) +cpdef driver_set_poll_mode(bint poll, size_t poll_threshold_size) +cpdef driver_set_max_direct_io_size(size_t max_direct_io_size) +cpdef driver_set_max_cache_size(size_t max_cache_size) +cpdef driver_set_max_pinned_mem_size(size_t max_pinned_size) +cpdef intptr_t batch_io_set_up(unsigned nr) except? 0 +cpdef batch_io_submit(intptr_t batch_idp, unsigned nr, intptr_t iocbp, unsigned int flags) +cpdef batch_io_get_status(intptr_t batch_idp, unsigned min_nr, intptr_t nr, intptr_t iocbp, intptr_t timeout) +cpdef batch_io_cancel(intptr_t batch_idp) +cpdef void batch_io_destroy(intptr_t batch_idp) except* +cpdef read_async(intptr_t fh, intptr_t buf_ptr_base, intptr_t size_p, intptr_t file_offset_p, intptr_t buf_ptr_offset_p, intptr_t bytes_read_p, intptr_t stream) +cpdef write_async(intptr_t fh, intptr_t buf_ptr_base, intptr_t size_p, intptr_t file_offset_p, intptr_t buf_ptr_offset_p, intptr_t bytes_written_p, intptr_t stream) +cpdef stream_register(intptr_t stream, unsigned flags) +cpdef stream_deregister(intptr_t stream) +cpdef int get_version() except? 0 +cpdef get_parameter_size_t(int param, intptr_t value) +cpdef get_parameter_bool(int param, intptr_t value) +cpdef get_parameter_string(int param, intptr_t desc_str, int len) +cpdef set_parameter_size_t(int param, size_t value) +cpdef set_parameter_bool(int param, bint value) +cpdef set_parameter_string(int param, intptr_t desc_str) diff --git a/cuda_bindings/cuda/bindings/cufile.pyx b/cuda_bindings/cuda/bindings/cufile.pyx new file mode 100644 index 000000000..197e4ef01 --- /dev/null +++ b/cuda_bindings/cuda/bindings/cufile.pyx @@ -0,0 +1,774 @@ +# Copyright (c) 2025, NVIDIA CORPORATION & AFFILIATES. ALL RIGHTS RESERVED. +# +# SPDX-License-Identifier: LicenseRef-NVIDIA-SOFTWARE-LICENSE +# +# This code was automatically generated with version 12.9.0. Do not modify it directly. + +cimport cython # NOQA +from libc cimport errno +from ._internal.utils cimport (get_buffer_pointer, get_nested_resource_ptr, + nested_resource) +import numpy as _numpy +from cpython cimport buffer as _buffer +from cpython.memoryview cimport PyMemoryView_FromMemory +from enum import IntEnum as _IntEnum + +import cython + + +############################################################################### +# POD +############################################################################### + +_py_anon_pod1_dtype = _numpy.dtype(( + _numpy.dtype((_numpy.void, sizeof((NULL).handle))), + { + "fd": (_numpy.int32, 0), + "handle": (_numpy.intp, 0), + } + )) + + +cdef class _py_anon_pod1: + """Empty-initialize an array of `_anon_pod1`. + + The resulting object is of length `size` and of dtype `_py_anon_pod1_dtype`. + If default-constructed, the instance represents a single union. + + Args: + size (int): number of unions, default=1. + + + .. seealso:: `_anon_pod1` + """ + cdef: + readonly object _data + + def __init__(self, size=1): + arr = _numpy.empty(size, dtype=_py_anon_pod1_dtype) + self._data = arr.view(_numpy.recarray) + assert self._data.itemsize == sizeof((NULL).handle), \ + f"itemsize {self._data.itemsize} mismatches union size {sizeof((NULL).handle)}" + + def __repr__(self): + if self._data.size > 1: + return f"<{__name__}._py_anon_pod1_Array_{self._data.size} object at {hex(id(self))}>" + else: + return f"<{__name__}._py_anon_pod1 object at {hex(id(self))}>" + + @property + def ptr(self): + """Get the pointer address to the data as Python :py:`int`.""" + return self._data.ctypes.data + + def __int__(self): + if self._data.size > 1: + raise TypeError("int() argument must be a bytes-like object of size 1. " + "To get the pointer address of an array, use .ptr") + return self._data.ctypes.data + + def __len__(self): + return self._data.size + + def __eq__(self, other): + if not isinstance(other, _py_anon_pod1): + return False + if self._data.size != other._data.size: + return False + if self._data.dtype != other._data.dtype: + return False + return bool((self._data == other._data).all()) + + @property + def fd(self): + """fd (~_numpy.int32): """ + if self._data.size == 1: + return int(self._data.fd[0]) + return self._data.fd + + @fd.setter + def fd(self, val): + self._data.fd = val + + @property + def handle(self): + """handle (~_numpy.intp): """ + if self._data.size == 1: + return int(self._data.handle[0]) + return self._data.handle + + @handle.setter + def handle(self, val): + self._data.handle = val + + def __getitem__(self, key): + if isinstance(key, int): + size = self._data.size + if key >= size or key <= -(size+1): + raise IndexError("index is out of bounds") + if key < 0: + key += size + return _py_anon_pod1.from_data(self._data[key:key+1]) + out = self._data[key] + if isinstance(out, _numpy.recarray) and out.dtype == _py_anon_pod1_dtype: + return _py_anon_pod1.from_data(out) + return out + + def __setitem__(self, key, val): + self._data[key] = val + + @staticmethod + def from_data(data): + """Create an _py_anon_pod1 instance wrapping the given NumPy array. + + Args: + data (_numpy.ndarray): a 1D array of dtype `_py_anon_pod1_dtype` holding the data. + """ + cdef _py_anon_pod1 obj = _py_anon_pod1.__new__(_py_anon_pod1) + if not isinstance(data, (_numpy.ndarray, _numpy.recarray)): + raise TypeError("data argument must be a NumPy ndarray") + if data.ndim != 1: + raise ValueError("data array must be 1D") + if data.dtype != _py_anon_pod1_dtype: + raise ValueError("data array must be of dtype _py_anon_pod1_dtype") + obj._data = data.view(_numpy.recarray) + + return obj + + @staticmethod + def from_ptr(intptr_t ptr, size_t size=1, bint readonly=False): + """Create an _py_anon_pod1 instance wrapping the given pointer. + + Args: + ptr (intptr_t): pointer address as Python :py:`int` to the data. + size (int): number of unions, default=1. + readonly (bool): whether the data is read-only (to the user). default is `False`. + """ + if ptr == 0: + raise ValueError("ptr must not be null (0)") + cdef _py_anon_pod1 obj = _py_anon_pod1.__new__(_py_anon_pod1) + cdef flag = _buffer.PyBUF_READ if readonly else _buffer.PyBUF_WRITE + cdef object buf = PyMemoryView_FromMemory( + ptr, sizeof((NULL).handle) * size, flag) + data = _numpy.ndarray((size,), buffer=buf, + dtype=_py_anon_pod1_dtype) + obj._data = data.view(_numpy.recarray) + + return obj + + +descr_dtype = _numpy.dtype([ + ("type", _numpy.int32, ), + ("handle", _py_anon_pod1_dtype, ), + ("fs_ops", _numpy.intp, ), + ], align=True) + + +cdef class Descr: + """Empty-initialize an array of `CUfileDescr_t`. + + The resulting object is of length `size` and of dtype `descr_dtype`. + If default-constructed, the instance represents a single struct. + + Args: + size (int): number of structs, default=1. + + + .. seealso:: `CUfileDescr_t` + """ + cdef: + readonly object _data + + def __init__(self, size=1): + arr = _numpy.empty(size, dtype=descr_dtype) + self._data = arr.view(_numpy.recarray) + assert self._data.itemsize == sizeof(CUfileDescr_t), \ + f"itemsize {self._data.itemsize} mismatches struct size {sizeof(CUfileDescr_t)}" + + def __repr__(self): + if self._data.size > 1: + return f"<{__name__}.Descr_Array_{self._data.size} object at {hex(id(self))}>" + else: + return f"<{__name__}.Descr object at {hex(id(self))}>" + + @property + def ptr(self): + """Get the pointer address to the data as Python :py:`int`.""" + return self._data.ctypes.data + + def __int__(self): + if self._data.size > 1: + raise TypeError("int() argument must be a bytes-like object of size 1. " + "To get the pointer address of an array, use .ptr") + return self._data.ctypes.data + + def __len__(self): + return self._data.size + + def __eq__(self, other): + if not isinstance(other, Descr): + return False + if self._data.size != other._data.size: + return False + if self._data.dtype != other._data.dtype: + return False + return bool((self._data == other._data).all()) + + @property + def type(self): + """type (~_numpy.int32): """ + if self._data.size == 1: + return int(self._data.type[0]) + return self._data.type + + @type.setter + def type(self, val): + self._data.type = val + + @property + def handle(self): + """handle (_py_anon_pod1_dtype): """ + return self._data.handle + + @handle.setter + def handle(self, val): + self._data.handle = val + + @property + def fs_ops(self): + """fs_ops (~_numpy.intp): """ + if self._data.size == 1: + return int(self._data.fs_ops[0]) + return self._data.fs_ops + + @fs_ops.setter + def fs_ops(self, val): + self._data.fs_ops = val + + def __getitem__(self, key): + if isinstance(key, int): + size = self._data.size + if key >= size or key <= -(size+1): + raise IndexError("index is out of bounds") + if key < 0: + key += size + return Descr.from_data(self._data[key:key+1]) + out = self._data[key] + if isinstance(out, _numpy.recarray) and out.dtype == descr_dtype: + return Descr.from_data(out) + return out + + def __setitem__(self, key, val): + self._data[key] = val + + @staticmethod + def from_data(data): + """Create an Descr instance wrapping the given NumPy array. + + Args: + data (_numpy.ndarray): a 1D array of dtype `descr_dtype` holding the data. + """ + cdef Descr obj = Descr.__new__(Descr) + if not isinstance(data, (_numpy.ndarray, _numpy.recarray)): + raise TypeError("data argument must be a NumPy ndarray") + if data.ndim != 1: + raise ValueError("data array must be 1D") + if data.dtype != descr_dtype: + raise ValueError("data array must be of dtype descr_dtype") + obj._data = data.view(_numpy.recarray) + + return obj + + @staticmethod + def from_ptr(intptr_t ptr, size_t size=1, bint readonly=False): + """Create an Descr instance wrapping the given pointer. + + Args: + ptr (intptr_t): pointer address as Python :py:`int` to the data. + size (int): number of structs, default=1. + readonly (bool): whether the data is read-only (to the user). default is `False`. + """ + if ptr == 0: + raise ValueError("ptr must not be null (0)") + cdef Descr obj = Descr.__new__(Descr) + cdef flag = _buffer.PyBUF_READ if readonly else _buffer.PyBUF_WRITE + cdef object buf = PyMemoryView_FromMemory( + ptr, sizeof(CUfileDescr_t) * size, flag) + data = _numpy.ndarray((size,), buffer=buf, + dtype=descr_dtype) + obj._data = data.view(_numpy.recarray) + + return obj + + + +############################################################################### +# Enum +############################################################################### + +class OpError(_IntEnum): + """See `CUfileOpError`.""" + SUCCESS = CU_FILE_SUCCESS + DRIVER_NOT_INITIALIZED = CU_FILE_DRIVER_NOT_INITIALIZED + DRIVER_INVALID_PROPS = CU_FILE_DRIVER_INVALID_PROPS + DRIVER_UNSUPPORTED_LIMIT = CU_FILE_DRIVER_UNSUPPORTED_LIMIT + DRIVER_VERSION_MISMATCH = CU_FILE_DRIVER_VERSION_MISMATCH + DRIVER_VERSION_READ_ERROR = CU_FILE_DRIVER_VERSION_READ_ERROR + DRIVER_CLOSING = CU_FILE_DRIVER_CLOSING + PLATFORM_NOT_SUPPORTED = CU_FILE_PLATFORM_NOT_SUPPORTED + IO_NOT_SUPPORTED = CU_FILE_IO_NOT_SUPPORTED + DEVICE_NOT_SUPPORTED = CU_FILE_DEVICE_NOT_SUPPORTED + NVFS_DRIVER_ERROR = CU_FILE_NVFS_DRIVER_ERROR + CUDA_DRIVER_ERROR = CU_FILE_CUDA_DRIVER_ERROR + CUDA_POINTER_INVALID = CU_FILE_CUDA_POINTER_INVALID + CUDA_MEMORY_TYPE_INVALID = CU_FILE_CUDA_MEMORY_TYPE_INVALID + CUDA_POINTER_RANGE_ERROR = CU_FILE_CUDA_POINTER_RANGE_ERROR + CUDA_CONTEXT_MISMATCH = CU_FILE_CUDA_CONTEXT_MISMATCH + INVALID_MAPPING_SIZE = CU_FILE_INVALID_MAPPING_SIZE + INVALID_MAPPING_RANGE = CU_FILE_INVALID_MAPPING_RANGE + INVALID_FILE_TYPE = CU_FILE_INVALID_FILE_TYPE + INVALID_FILE_OPEN_FLAG = CU_FILE_INVALID_FILE_OPEN_FLAG + DIO_NOT_SET = CU_FILE_DIO_NOT_SET + INVALID_VALUE = CU_FILE_INVALID_VALUE + MEMORY_ALREADY_REGISTERED = CU_FILE_MEMORY_ALREADY_REGISTERED + MEMORY_NOT_REGISTERED = CU_FILE_MEMORY_NOT_REGISTERED + PERMISSION_DENIED = CU_FILE_PERMISSION_DENIED + DRIVER_ALREADY_OPEN = CU_FILE_DRIVER_ALREADY_OPEN + HANDLE_NOT_REGISTERED = CU_FILE_HANDLE_NOT_REGISTERED + HANDLE_ALREADY_REGISTERED = CU_FILE_HANDLE_ALREADY_REGISTERED + DEVICE_NOT_FOUND = CU_FILE_DEVICE_NOT_FOUND + INTERNAL_ERROR = CU_FILE_INTERNAL_ERROR + GETNEWFD_FAILED = CU_FILE_GETNEWFD_FAILED + NVFS_SETUP_ERROR = CU_FILE_NVFS_SETUP_ERROR + IO_DISABLED = CU_FILE_IO_DISABLED + BATCH_SUBMIT_FAILED = CU_FILE_BATCH_SUBMIT_FAILED + GPU_MEMORY_PINNING_FAILED = CU_FILE_GPU_MEMORY_PINNING_FAILED + BATCH_FULL = CU_FILE_BATCH_FULL + ASYNC_NOT_SUPPORTED = CU_FILE_ASYNC_NOT_SUPPORTED + IO_MAX_ERROR = CU_FILE_IO_MAX_ERROR + +class DriverStatusFlags(_IntEnum): + """See `CUfileDriverStatusFlags_t`.""" + LUSTRE_SUPPORTED = CU_FILE_LUSTRE_SUPPORTED + WEKAFS_SUPPORTED = CU_FILE_WEKAFS_SUPPORTED + NFS_SUPPORTED = CU_FILE_NFS_SUPPORTED + GPFS_SUPPORTED = CU_FILE_GPFS_SUPPORTED + NVME_SUPPORTED = CU_FILE_NVME_SUPPORTED + NVMEOF_SUPPORTED = CU_FILE_NVMEOF_SUPPORTED + SCSI_SUPPORTED = CU_FILE_SCSI_SUPPORTED + SCALEFLUX_CSD_SUPPORTED = CU_FILE_SCALEFLUX_CSD_SUPPORTED + NVMESH_SUPPORTED = CU_FILE_NVMESH_SUPPORTED + BEEGFS_SUPPORTED = CU_FILE_BEEGFS_SUPPORTED + NVME_P2P_SUPPORTED = CU_FILE_NVME_P2P_SUPPORTED + SCATEFS_SUPPORTED = CU_FILE_SCATEFS_SUPPORTED + +class DriverControlFlags(_IntEnum): + """See `CUfileDriverControlFlags_t`.""" + USE_POLL_MODE = CU_FILE_USE_POLL_MODE + ALLOW_COMPAT_MODE = CU_FILE_ALLOW_COMPAT_MODE + +class FeatureFlags(_IntEnum): + """See `CUfileFeatureFlags_t`.""" + DYN_ROUTING_SUPPORTED = CU_FILE_DYN_ROUTING_SUPPORTED + BATCH_IO_SUPPORTED = CU_FILE_BATCH_IO_SUPPORTED + STREAMS_SUPPORTED = CU_FILE_STREAMS_SUPPORTED + PARALLEL_IO_SUPPORTED = CU_FILE_PARALLEL_IO_SUPPORTED + +class FileHandleType(_IntEnum): + """See `CUfileFileHandleType`.""" + OPAQUE_FD = CU_FILE_HANDLE_TYPE_OPAQUE_FD + OPAQUE_WIN32 = CU_FILE_HANDLE_TYPE_OPAQUE_WIN32 + USERSPACE_FS = CU_FILE_HANDLE_TYPE_USERSPACE_FS + +class Opcode(_IntEnum): + """See `CUfileOpcode_t`.""" + READ = CUFILE_READ + WRITE = CUFILE_WRITE + +class Status(_IntEnum): + """See `CUfileStatus_t`.""" + WAITING = CUFILE_WAITING + PENDING = CUFILE_PENDING + INVALID = CUFILE_INVALID + CANCELED = CUFILE_CANCELED + COMPLETE = CUFILE_COMPLETE + TIMEOUT = CUFILE_TIMEOUT + FAILED = CUFILE_FAILED + +class BatchMode(_IntEnum): + """See `CUfileBatchMode_t`.""" + BATCH = CUFILE_BATCH + +class SizeTConfigParameter(_IntEnum): + """See `CUFileSizeTConfigParameter_t`.""" + PROFILE_STATS = CUFILE_PARAM_PROFILE_STATS + EXECUTION_MAX_IO_QUEUE_DEPTH = CUFILE_PARAM_EXECUTION_MAX_IO_QUEUE_DEPTH + EXECUTION_MAX_IO_THREADS = CUFILE_PARAM_EXECUTION_MAX_IO_THREADS + EXECUTION_MIN_IO_THRESHOLD_SIZE_KB = CUFILE_PARAM_EXECUTION_MIN_IO_THRESHOLD_SIZE_KB + EXECUTION_MAX_REQUEST_PARALLELISM = CUFILE_PARAM_EXECUTION_MAX_REQUEST_PARALLELISM + PROPERTIES_MAX_DIRECT_IO_SIZE_KB = CUFILE_PARAM_PROPERTIES_MAX_DIRECT_IO_SIZE_KB + PROPERTIES_MAX_DEVICE_CACHE_SIZE_KB = CUFILE_PARAM_PROPERTIES_MAX_DEVICE_CACHE_SIZE_KB + PROPERTIES_PER_BUFFER_CACHE_SIZE_KB = CUFILE_PARAM_PROPERTIES_PER_BUFFER_CACHE_SIZE_KB + PROPERTIES_MAX_DEVICE_PINNED_MEM_SIZE_KB = CUFILE_PARAM_PROPERTIES_MAX_DEVICE_PINNED_MEM_SIZE_KB + PROPERTIES_IO_BATCHSIZE = CUFILE_PARAM_PROPERTIES_IO_BATCHSIZE + POLLTHRESHOLD_SIZE_KB = CUFILE_PARAM_POLLTHRESHOLD_SIZE_KB + PROPERTIES_BATCH_IO_TIMEOUT_MS = CUFILE_PARAM_PROPERTIES_BATCH_IO_TIMEOUT_MS + +class BoolConfigParameter(_IntEnum): + """See `CUFileBoolConfigParameter_t`.""" + PROPERTIES_USE_POLL_MODE = CUFILE_PARAM_PROPERTIES_USE_POLL_MODE + PROPERTIES_ALLOW_COMPAT_MODE = CUFILE_PARAM_PROPERTIES_ALLOW_COMPAT_MODE + FORCE_COMPAT_MODE = CUFILE_PARAM_FORCE_COMPAT_MODE + FS_MISC_API_CHECK_AGGRESSIVE = CUFILE_PARAM_FS_MISC_API_CHECK_AGGRESSIVE + EXECUTION_PARALLEL_IO = CUFILE_PARAM_EXECUTION_PARALLEL_IO + PROFILE_NVTX = CUFILE_PARAM_PROFILE_NVTX + PROPERTIES_ALLOW_SYSTEM_MEMORY = CUFILE_PARAM_PROPERTIES_ALLOW_SYSTEM_MEMORY + USE_PCIP2PDMA = CUFILE_PARAM_USE_PCIP2PDMA + PREFER_IO_URING = CUFILE_PARAM_PREFER_IO_URING + FORCE_ODIRECT_MODE = CUFILE_PARAM_FORCE_ODIRECT_MODE + SKIP_TOPOLOGY_DETECTION = CUFILE_PARAM_SKIP_TOPOLOGY_DETECTION + STREAM_MEMOPS_BYPASS = CUFILE_PARAM_STREAM_MEMOPS_BYPASS + +class StringConfigParameter(_IntEnum): + """See `CUFileStringConfigParameter_t`.""" + LOGGING_LEVEL = CUFILE_PARAM_LOGGING_LEVEL + ENV_LOGFILE_PATH = CUFILE_PARAM_ENV_LOGFILE_PATH + LOG_DIR = CUFILE_PARAM_LOG_DIR + + +############################################################################### +# Error handling +############################################################################### + +ctypedef fused ReturnT: + CUfileError_t + ssize_t + + +class cuFileError(Exception): + + def __init__(self, status, cu_err=None): + self.status = status + self.cuda_error = cu_err + s = OpError(status) + cdef str err = f"{s.name} ({s.value})" + if cu_err is not None: + err += "; CUDA status: {cu_err}" + super(cuFileError, self).__init__(err) + + def __reduce__(self): + return (type(self), (self.status, self.cuda_error)) + + +@cython.profile(False) +cdef int check_status(ReturnT status) except 1 nogil: + if ReturnT is CUfileError_t: + if status.err != 0 or status.cu_err != 0: + with gil: + raise cuFileError(status.err, status.cu_err) + elif ReturnT is ssize_t: + if status == -1: + # note: this assumes cuFile already properly resets errno in each API + with gil: + raise cuFileError(errno.errno) + return 0 + + +############################################################################### +# Wrapper functions +############################################################################### + +cpdef intptr_t handle_register(intptr_t descr) except? 0: + """cuFileHandleRegister is required, and performs extra checking that is memoized to provide increased performance on later cuFile operations. + + Args: + descr (intptr_t): ``CUfileDescr_t`` file descriptor (OS agnostic). + + Returns: + intptr_t: ``CUfileHandle_t`` opaque file handle for IO operations. + + .. seealso:: `cuFileHandleRegister` + """ + cdef Handle fh + with nogil: + status = cuFileHandleRegister(&fh, descr) + check_status(status) + return fh + + +cpdef void handle_deregister(intptr_t fh) except*: + """releases a registered filehandle from cuFile. + + Args: + fh (intptr_t): ``CUfileHandle_t`` file handle. + + .. seealso:: `cuFileHandleDeregister` + """ + cuFileHandleDeregister(fh) + + +cpdef buf_register(intptr_t buf_ptr_base, size_t length, int flags): + """register an existing cudaMalloced memory with cuFile to pin for GPUDirect Storage access or register host allocated memory with cuFile. + + Args: + buf_ptr_base (intptr_t): buffer pointer allocated. + length (size_t): size of memory region from the above specified bufPtr. + flags (int): CU_FILE_RDMA_REGISTER. + + .. seealso:: `cuFileBufRegister` + """ + with nogil: + status = cuFileBufRegister(buf_ptr_base, length, flags) + check_status(status) + + +cpdef buf_deregister(intptr_t buf_ptr_base): + """deregister an already registered device or host memory from cuFile. + + Args: + buf_ptr_base (intptr_t): buffer pointer to deregister. + + .. seealso:: `cuFileBufDeregister` + """ + with nogil: + status = cuFileBufDeregister(buf_ptr_base) + check_status(status) + + +cpdef read(intptr_t fh, intptr_t buf_ptr_base, size_t size, off_t file_offset, off_t buf_ptr_offset): + """read data from a registered file handle to a specified device or host memory. + + Args: + fh (intptr_t): ``CUfileHandle_t`` opaque file handle. + buf_ptr_base (intptr_t): base address of buffer in device or host memory. + size (size_t): size bytes to read. + file_offset (off_t): file-offset from begining of the file. + buf_ptr_offset (off_t): offset relative to the buf_ptr_base pointer to read into. + + .. seealso:: `cuFileRead` + """ + with nogil: + status = cuFileRead(fh, buf_ptr_base, size, file_offset, buf_ptr_offset) + check_status(status) + + +cpdef write(intptr_t fh, intptr_t buf_ptr_base, size_t size, off_t file_offset, off_t buf_ptr_offset): + """write data from a specified device or host memory to a registered file handle. + + Args: + fh (intptr_t): ``CUfileHandle_t`` opaque file handle. + buf_ptr_base (intptr_t): base address of buffer in device or host memory. + size (size_t): size bytes to write. + file_offset (off_t): file-offset from begining of the file. + buf_ptr_offset (off_t): offset relative to the buf_ptr_base pointer to write from. + + .. seealso:: `cuFileWrite` + """ + with nogil: + status = cuFileWrite(fh, buf_ptr_base, size, file_offset, buf_ptr_offset) + check_status(status) + + +cpdef driver_open(): + """Initialize the cuFile library and open the nvidia-fs driver. + + .. seealso:: `cuFileDriverOpen` + """ + with nogil: + status = cuFileDriverOpen() + check_status(status) + + +cpdef use_count(): + """returns use count of cufile drivers at that moment by the process. + + .. seealso:: `cuFileUseCount` + """ + with nogil: + status = cuFileUseCount() + check_status(status) + + +cpdef driver_get_properties(intptr_t props): + """Gets the Driver session properties. + + Args: + props (intptr_t): to set. + + .. seealso:: `cuFileDriverGetProperties` + """ + with nogil: + status = cuFileDriverGetProperties(props) + check_status(status) + + +cpdef driver_set_poll_mode(bint poll, size_t poll_threshold_size): + """Sets whether the Read/Write APIs use polling to do IO operations. + + Args: + poll (bint): boolean to indicate whether to use poll mode or not. + poll_threshold_size (size_t): max IO size to use for POLLING mode in KB. + + .. seealso:: `cuFileDriverSetPollMode` + """ + with nogil: + status = cuFileDriverSetPollMode(poll, poll_threshold_size) + check_status(status) + + +cpdef driver_set_max_direct_io_size(size_t max_direct_io_size): + """Control parameter to set max IO size(KB) used by the library to talk to nvidia-fs driver. + + Args: + max_direct_io_size (size_t): maximum allowed direct io size in KB. + + .. seealso:: `cuFileDriverSetMaxDirectIOSize` + """ + with nogil: + status = cuFileDriverSetMaxDirectIOSize(max_direct_io_size) + check_status(status) + + +cpdef driver_set_max_cache_size(size_t max_cache_size): + """Control parameter to set maximum GPU memory reserved per device by the library for internal buffering. + + Args: + max_cache_size (size_t): The maximum GPU buffer space per device used for internal use in KB. + + .. seealso:: `cuFileDriverSetMaxCacheSize` + """ + with nogil: + status = cuFileDriverSetMaxCacheSize(max_cache_size) + check_status(status) + + +cpdef driver_set_max_pinned_mem_size(size_t max_pinned_size): + """Sets maximum buffer space that is pinned in KB for use by ``cuFileBufRegister``. + + Args: + max_pinned_size (size_t): maximum buffer space that is pinned in KB. + + .. seealso:: `cuFileDriverSetMaxPinnedMemSize` + """ + with nogil: + status = cuFileDriverSetMaxPinnedMemSize(max_pinned_size) + check_status(status) + + +cpdef intptr_t batch_io_set_up(unsigned nr) except? 0: + cdef BatchHandle batch_idp + with nogil: + status = cuFileBatchIOSetUp(&batch_idp, nr) + check_status(status) + return batch_idp + + +cpdef batch_io_submit(intptr_t batch_idp, unsigned nr, intptr_t iocbp, unsigned int flags): + with nogil: + status = cuFileBatchIOSubmit(batch_idp, nr, iocbp, flags) + check_status(status) + + +cpdef batch_io_get_status(intptr_t batch_idp, unsigned min_nr, intptr_t nr, intptr_t iocbp, intptr_t timeout): + with nogil: + status = cuFileBatchIOGetStatus(batch_idp, min_nr, nr, iocbp, timeout) + check_status(status) + + +cpdef batch_io_cancel(intptr_t batch_idp): + with nogil: + status = cuFileBatchIOCancel(batch_idp) + check_status(status) + + +cpdef void batch_io_destroy(intptr_t batch_idp) except*: + cuFileBatchIODestroy(batch_idp) + + +cpdef read_async(intptr_t fh, intptr_t buf_ptr_base, intptr_t size_p, intptr_t file_offset_p, intptr_t buf_ptr_offset_p, intptr_t bytes_read_p, intptr_t stream): + with nogil: + status = cuFileReadAsync(fh, buf_ptr_base, size_p, file_offset_p, buf_ptr_offset_p, bytes_read_p, stream) + check_status(status) + + +cpdef write_async(intptr_t fh, intptr_t buf_ptr_base, intptr_t size_p, intptr_t file_offset_p, intptr_t buf_ptr_offset_p, intptr_t bytes_written_p, intptr_t stream): + with nogil: + status = cuFileWriteAsync(fh, buf_ptr_base, size_p, file_offset_p, buf_ptr_offset_p, bytes_written_p, stream) + check_status(status) + + +cpdef stream_register(intptr_t stream, unsigned flags): + with nogil: + status = cuFileStreamRegister(stream, flags) + check_status(status) + + +cpdef stream_deregister(intptr_t stream): + with nogil: + status = cuFileStreamDeregister(stream) + check_status(status) + + +cpdef int get_version() except? 0: + cdef int version + with nogil: + status = cuFileGetVersion(&version) + check_status(status) + return version + + +cpdef get_parameter_size_t(int param, intptr_t value): + with nogil: + status = cuFileGetParameterSizeT(<_SizeTConfigParameter>param, value) + check_status(status) + + +cpdef get_parameter_bool(int param, intptr_t value): + with nogil: + status = cuFileGetParameterBool(<_BoolConfigParameter>param, value) + check_status(status) + + +cpdef get_parameter_string(int param, intptr_t desc_str, int len): + with nogil: + status = cuFileGetParameterString(<_StringConfigParameter>param, desc_str, len) + check_status(status) + + +cpdef set_parameter_size_t(int param, size_t value): + with nogil: + status = cuFileSetParameterSizeT(<_SizeTConfigParameter>param, value) + check_status(status) + + +cpdef set_parameter_bool(int param, bint value): + with nogil: + status = cuFileSetParameterBool(<_BoolConfigParameter>param, value) + check_status(status) + + +cpdef set_parameter_string(int param, intptr_t desc_str): + with nogil: + status = cuFileSetParameterString(<_StringConfigParameter>param, desc_str) + check_status(status) + + +cpdef str op_status_error(int status): + """cufileop status string. + + Args: + status (OpError): the error status to query. + + .. seealso:: `cufileop_status_error` + """ + cdef bytes _output_ + _output_ = cufileop_status_error(<_OpError>status) + return _output_.decode() + + +cpdef driver_close(): + """reset the cuFile library and release the nvidia-fs driver + """ + with nogil: + status = cuFileDriverClose_v2() + check_status(status) diff --git a/cuda_bindings/cuda/bindings/cycufile.pxd b/cuda_bindings/cuda/bindings/cycufile.pxd new file mode 100644 index 000000000..a154bce00 --- /dev/null +++ b/cuda_bindings/cuda/bindings/cycufile.pxd @@ -0,0 +1,256 @@ +# Copyright (c) 2025, NVIDIA CORPORATION & AFFILIATES. ALL RIGHTS RESERVED. +# +# SPDX-License-Identifier: LicenseRef-NVIDIA-SOFTWARE-LICENSE +# +# This code was automatically generated with version 12.9.0. Do not modify it directly. + +from libc.time cimport time_t +from libcpp cimport bool as cpp_bool + +cimport cuda.bindings.cydriver +from cuda.bindings.cydriver cimport CUresult, CUstream + + +############################################################################### +# Types (structs, enums, ...) +############################################################################### + +cdef extern from "sys/types.h": + ctypedef long off_t +cdef extern from "time.h": + cdef struct timespec: + time_t tv_sec + long tv_nsec +cdef extern from "sys/socket.h": + cdef struct sockaddr: + unsigned short sa_family + char sa_data[14] + + ctypedef sockaddr sockaddr_t + + +cdef extern from '': + # enums + ctypedef enum CUfileOpError: + CU_FILE_SUCCESS + CU_FILE_DRIVER_NOT_INITIALIZED + CU_FILE_DRIVER_INVALID_PROPS + CU_FILE_DRIVER_UNSUPPORTED_LIMIT + CU_FILE_DRIVER_VERSION_MISMATCH + CU_FILE_DRIVER_VERSION_READ_ERROR + CU_FILE_DRIVER_CLOSING + CU_FILE_PLATFORM_NOT_SUPPORTED + CU_FILE_IO_NOT_SUPPORTED + CU_FILE_DEVICE_NOT_SUPPORTED + CU_FILE_NVFS_DRIVER_ERROR + CU_FILE_CUDA_DRIVER_ERROR + CU_FILE_CUDA_POINTER_INVALID + CU_FILE_CUDA_MEMORY_TYPE_INVALID + CU_FILE_CUDA_POINTER_RANGE_ERROR + CU_FILE_CUDA_CONTEXT_MISMATCH + CU_FILE_INVALID_MAPPING_SIZE + CU_FILE_INVALID_MAPPING_RANGE + CU_FILE_INVALID_FILE_TYPE + CU_FILE_INVALID_FILE_OPEN_FLAG + CU_FILE_DIO_NOT_SET + CU_FILE_INVALID_VALUE + CU_FILE_MEMORY_ALREADY_REGISTERED + CU_FILE_MEMORY_NOT_REGISTERED + CU_FILE_PERMISSION_DENIED + CU_FILE_DRIVER_ALREADY_OPEN + CU_FILE_HANDLE_NOT_REGISTERED + CU_FILE_HANDLE_ALREADY_REGISTERED + CU_FILE_DEVICE_NOT_FOUND + CU_FILE_INTERNAL_ERROR + CU_FILE_GETNEWFD_FAILED + CU_FILE_NVFS_SETUP_ERROR + CU_FILE_IO_DISABLED + CU_FILE_BATCH_SUBMIT_FAILED + CU_FILE_GPU_MEMORY_PINNING_FAILED + CU_FILE_BATCH_FULL + CU_FILE_ASYNC_NOT_SUPPORTED + CU_FILE_IO_MAX_ERROR + + ctypedef enum CUfileDriverStatusFlags_t: + CU_FILE_LUSTRE_SUPPORTED + CU_FILE_WEKAFS_SUPPORTED + CU_FILE_NFS_SUPPORTED + CU_FILE_GPFS_SUPPORTED + CU_FILE_NVME_SUPPORTED + CU_FILE_NVMEOF_SUPPORTED + CU_FILE_SCSI_SUPPORTED + CU_FILE_SCALEFLUX_CSD_SUPPORTED + CU_FILE_NVMESH_SUPPORTED + CU_FILE_BEEGFS_SUPPORTED + CU_FILE_NVME_P2P_SUPPORTED + CU_FILE_SCATEFS_SUPPORTED + + ctypedef enum CUfileDriverControlFlags_t: + CU_FILE_USE_POLL_MODE + CU_FILE_ALLOW_COMPAT_MODE + + ctypedef enum CUfileFeatureFlags_t: + CU_FILE_DYN_ROUTING_SUPPORTED + CU_FILE_BATCH_IO_SUPPORTED + CU_FILE_STREAMS_SUPPORTED + CU_FILE_PARALLEL_IO_SUPPORTED + + ctypedef enum CUfileFileHandleType: + CU_FILE_HANDLE_TYPE_OPAQUE_FD + CU_FILE_HANDLE_TYPE_OPAQUE_WIN32 + CU_FILE_HANDLE_TYPE_USERSPACE_FS + + ctypedef enum CUfileOpcode_t: + CUFILE_READ + CUFILE_WRITE + + ctypedef enum CUfileStatus_t: + CUFILE_WAITING + CUFILE_PENDING + CUFILE_INVALID + CUFILE_CANCELED + CUFILE_COMPLETE + CUFILE_TIMEOUT + CUFILE_FAILED + + ctypedef enum CUfileBatchMode_t: + CUFILE_BATCH + + ctypedef enum CUFileSizeTConfigParameter_t: + CUFILE_PARAM_PROFILE_STATS + CUFILE_PARAM_EXECUTION_MAX_IO_QUEUE_DEPTH + CUFILE_PARAM_EXECUTION_MAX_IO_THREADS + CUFILE_PARAM_EXECUTION_MIN_IO_THRESHOLD_SIZE_KB + CUFILE_PARAM_EXECUTION_MAX_REQUEST_PARALLELISM + CUFILE_PARAM_PROPERTIES_MAX_DIRECT_IO_SIZE_KB + CUFILE_PARAM_PROPERTIES_MAX_DEVICE_CACHE_SIZE_KB + CUFILE_PARAM_PROPERTIES_PER_BUFFER_CACHE_SIZE_KB + CUFILE_PARAM_PROPERTIES_MAX_DEVICE_PINNED_MEM_SIZE_KB + CUFILE_PARAM_PROPERTIES_IO_BATCHSIZE + CUFILE_PARAM_POLLTHRESHOLD_SIZE_KB + CUFILE_PARAM_PROPERTIES_BATCH_IO_TIMEOUT_MS + + ctypedef enum CUFileBoolConfigParameter_t: + CUFILE_PARAM_PROPERTIES_USE_POLL_MODE + CUFILE_PARAM_PROPERTIES_ALLOW_COMPAT_MODE + CUFILE_PARAM_FORCE_COMPAT_MODE + CUFILE_PARAM_FS_MISC_API_CHECK_AGGRESSIVE + CUFILE_PARAM_EXECUTION_PARALLEL_IO + CUFILE_PARAM_PROFILE_NVTX + CUFILE_PARAM_PROPERTIES_ALLOW_SYSTEM_MEMORY + CUFILE_PARAM_USE_PCIP2PDMA + CUFILE_PARAM_PREFER_IO_URING + CUFILE_PARAM_FORCE_ODIRECT_MODE + CUFILE_PARAM_SKIP_TOPOLOGY_DETECTION + CUFILE_PARAM_STREAM_MEMOPS_BYPASS + + ctypedef enum CUFileStringConfigParameter_t: + CUFILE_PARAM_LOGGING_LEVEL + CUFILE_PARAM_ENV_LOGFILE_PATH + CUFILE_PARAM_LOG_DIR + + # types + ctypedef void* CUfileHandle_t 'CUfileHandle_t' + ctypedef void* CUfileBatchHandle_t 'CUfileBatchHandle_t' + ctypedef struct CUfileError_t 'CUfileError_t': + CUfileOpError err + CUresult cu_err + cdef struct _anon_pod0 '_anon_pod0': + unsigned int major_version + unsigned int minor_version + size_t poll_thresh_size + size_t max_direct_io_size + unsigned int dstatusflags + unsigned int dcontrolflags + ctypedef struct cufileRDMAInfo_t 'cufileRDMAInfo_t': + int version + int desc_len + char* desc_str + ctypedef struct CUfileFSOps_t 'CUfileFSOps_t': + char* (*fs_type)(void*) + int (*getRDMADeviceList)(void*, sockaddr_t**) + int (*getRDMADevicePriority)(void*, char*, size_t, loff_t, sockaddr_t*) + ssize_t (*read)(void*, char*, size_t, loff_t, cufileRDMAInfo_t*) + ssize_t (*write)(void*, const char*, size_t, loff_t, cufileRDMAInfo_t*) + cdef union _anon_pod1 '_anon_pod1': + int fd + void* handle + cdef struct _anon_pod3 '_anon_pod3': + void* devPtr_base + off_t file_offset + off_t devPtr_offset + size_t size + ctypedef struct CUfileIOEvents_t 'CUfileIOEvents_t': + void* cookie + CUfileStatus_t status + size_t ret + ctypedef struct CUfileDrvProps_t 'CUfileDrvProps_t': + _anon_pod0 nvfs + unsigned int fflags + unsigned int max_device_cache_size + unsigned int per_buffer_cache_size + unsigned int max_device_pinned_mem_size + unsigned int max_batch_io_size + unsigned int max_batch_io_timeout_msecs + ctypedef struct CUfileDescr_t 'CUfileDescr_t': + CUfileFileHandleType type + _anon_pod1 handle + CUfileFSOps_t* fs_ops + cdef union _anon_pod2 '_anon_pod2': + _anon_pod3 batch + ctypedef struct CUfileIOParams_t 'CUfileIOParams_t': + CUfileBatchMode_t mode + _anon_pod2 u + CUfileHandle_t fh + CUfileOpcode_t opcode + void* cookie + + +cdef extern from *: + """ + // This is the missing piece we need to supply to help Cython & C++ compilers. + inline bool operator==(const CUfileError_t& lhs, const CUfileError_t& rhs) { + return (lhs.err == rhs.err) && (lhs.cu_err == rhs.cu_err); + } + static CUfileError_t CUFILE_LOADING_ERROR{(CUfileOpError)-1, (CUresult)-1}; + """ + const CUfileError_t CUFILE_LOADING_ERROR + ctypedef void* CUstream "CUstream" + + const char* cufileop_status_error(CUfileOpError) + + +############################################################################### +# Functions +############################################################################### + +cdef CUfileError_t cuFileHandleRegister(CUfileHandle_t* fh, CUfileDescr_t* descr) except?CUFILE_LOADING_ERROR nogil +cdef void cuFileHandleDeregister(CUfileHandle_t fh) except* nogil +cdef CUfileError_t cuFileBufRegister(const void* bufPtr_base, size_t length, int flags) except?CUFILE_LOADING_ERROR nogil +cdef CUfileError_t cuFileBufDeregister(const void* bufPtr_base) except?CUFILE_LOADING_ERROR nogil +cdef ssize_t cuFileRead(CUfileHandle_t fh, void* bufPtr_base, size_t size, off_t file_offset, off_t bufPtr_offset) except* nogil +cdef ssize_t cuFileWrite(CUfileHandle_t fh, const void* bufPtr_base, size_t size, off_t file_offset, off_t bufPtr_offset) except* nogil +cdef CUfileError_t cuFileDriverOpen() except?CUFILE_LOADING_ERROR nogil +cdef CUfileError_t cuFileDriverClose_v2() except?CUFILE_LOADING_ERROR nogil +cdef long cuFileUseCount() except* nogil +cdef CUfileError_t cuFileDriverGetProperties(CUfileDrvProps_t* props) except?CUFILE_LOADING_ERROR nogil +cdef CUfileError_t cuFileDriverSetPollMode(cpp_bool poll, size_t poll_threshold_size) except?CUFILE_LOADING_ERROR nogil +cdef CUfileError_t cuFileDriverSetMaxDirectIOSize(size_t max_direct_io_size) except?CUFILE_LOADING_ERROR nogil +cdef CUfileError_t cuFileDriverSetMaxCacheSize(size_t max_cache_size) except?CUFILE_LOADING_ERROR nogil +cdef CUfileError_t cuFileDriverSetMaxPinnedMemSize(size_t max_pinned_size) except?CUFILE_LOADING_ERROR nogil +cdef CUfileError_t cuFileBatchIOSetUp(CUfileBatchHandle_t* batch_idp, unsigned nr) except?CUFILE_LOADING_ERROR nogil +cdef CUfileError_t cuFileBatchIOSubmit(CUfileBatchHandle_t batch_idp, unsigned nr, CUfileIOParams_t* iocbp, unsigned int flags) except?CUFILE_LOADING_ERROR nogil +cdef CUfileError_t cuFileBatchIOGetStatus(CUfileBatchHandle_t batch_idp, unsigned min_nr, unsigned* nr, CUfileIOEvents_t* iocbp, timespec* timeout) except?CUFILE_LOADING_ERROR nogil +cdef CUfileError_t cuFileBatchIOCancel(CUfileBatchHandle_t batch_idp) except?CUFILE_LOADING_ERROR nogil +cdef void cuFileBatchIODestroy(CUfileBatchHandle_t batch_idp) except* nogil +cdef CUfileError_t cuFileReadAsync(CUfileHandle_t fh, void* bufPtr_base, size_t* size_p, off_t* file_offset_p, off_t* bufPtr_offset_p, ssize_t* bytes_read_p, CUstream stream) except?CUFILE_LOADING_ERROR nogil +cdef CUfileError_t cuFileWriteAsync(CUfileHandle_t fh, void* bufPtr_base, size_t* size_p, off_t* file_offset_p, off_t* bufPtr_offset_p, ssize_t* bytes_written_p, CUstream stream) except?CUFILE_LOADING_ERROR nogil +cdef CUfileError_t cuFileStreamRegister(CUstream stream, unsigned flags) except?CUFILE_LOADING_ERROR nogil +cdef CUfileError_t cuFileStreamDeregister(CUstream stream) except?CUFILE_LOADING_ERROR nogil +cdef CUfileError_t cuFileGetVersion(int* version) except?CUFILE_LOADING_ERROR nogil +cdef CUfileError_t cuFileGetParameterSizeT(CUFileSizeTConfigParameter_t param, size_t* value) except?CUFILE_LOADING_ERROR nogil +cdef CUfileError_t cuFileGetParameterBool(CUFileBoolConfigParameter_t param, cpp_bool* value) except?CUFILE_LOADING_ERROR nogil +cdef CUfileError_t cuFileGetParameterString(CUFileStringConfigParameter_t param, char* desc_str, int len) except?CUFILE_LOADING_ERROR nogil +cdef CUfileError_t cuFileSetParameterSizeT(CUFileSizeTConfigParameter_t param, size_t value) except?CUFILE_LOADING_ERROR nogil +cdef CUfileError_t cuFileSetParameterBool(CUFileBoolConfigParameter_t param, cpp_bool value) except?CUFILE_LOADING_ERROR nogil +cdef CUfileError_t cuFileSetParameterString(CUFileStringConfigParameter_t param, const char* desc_str) except?CUFILE_LOADING_ERROR nogil diff --git a/cuda_bindings/cuda/bindings/cycufile.pyx b/cuda_bindings/cuda/bindings/cycufile.pyx new file mode 100644 index 000000000..38c2ac091 --- /dev/null +++ b/cuda_bindings/cuda/bindings/cycufile.pyx @@ -0,0 +1,134 @@ +# Copyright (c) 2025, NVIDIA CORPORATION & AFFILIATES. ALL RIGHTS RESERVED. +# +# SPDX-License-Identifier: LicenseRef-NVIDIA-SOFTWARE-LICENSE +# +# This code was automatically generated with version 12.9.0. Do not modify it directly. + +from ._internal cimport cufile as _cufile + +import cython + +############################################################################### +# Wrapper functions +############################################################################### + +cdef CUfileError_t cuFileHandleRegister(CUfileHandle_t* fh, CUfileDescr_t* descr) except?CUFILE_LOADING_ERROR nogil: + return _cufile._cuFileHandleRegister(fh, descr) + + +@cython.show_performance_hints(False) +cdef void cuFileHandleDeregister(CUfileHandle_t fh) except* nogil: + _cufile._cuFileHandleDeregister(fh) + + +cdef CUfileError_t cuFileBufRegister(const void* bufPtr_base, size_t length, int flags) except?CUFILE_LOADING_ERROR nogil: + return _cufile._cuFileBufRegister(bufPtr_base, length, flags) + + +cdef CUfileError_t cuFileBufDeregister(const void* bufPtr_base) except?CUFILE_LOADING_ERROR nogil: + return _cufile._cuFileBufDeregister(bufPtr_base) + + +cdef ssize_t cuFileRead(CUfileHandle_t fh, void* bufPtr_base, size_t size, off_t file_offset, off_t bufPtr_offset) except* nogil: + return _cufile._cuFileRead(fh, bufPtr_base, size, file_offset, bufPtr_offset) + + +cdef ssize_t cuFileWrite(CUfileHandle_t fh, const void* bufPtr_base, size_t size, off_t file_offset, off_t bufPtr_offset) except* nogil: + return _cufile._cuFileWrite(fh, bufPtr_base, size, file_offset, bufPtr_offset) + + +cdef CUfileError_t cuFileDriverOpen() except?CUFILE_LOADING_ERROR nogil: + return _cufile._cuFileDriverOpen() + + +cdef CUfileError_t cuFileDriverClose_v2() except?CUFILE_LOADING_ERROR nogil: + return _cufile._cuFileDriverClose_v2() + + +cdef long cuFileUseCount() except* nogil: + return _cufile._cuFileUseCount() + + +cdef CUfileError_t cuFileDriverGetProperties(CUfileDrvProps_t* props) except?CUFILE_LOADING_ERROR nogil: + return _cufile._cuFileDriverGetProperties(props) + + +cdef CUfileError_t cuFileDriverSetPollMode(cpp_bool poll, size_t poll_threshold_size) except?CUFILE_LOADING_ERROR nogil: + return _cufile._cuFileDriverSetPollMode(poll, poll_threshold_size) + + +cdef CUfileError_t cuFileDriverSetMaxDirectIOSize(size_t max_direct_io_size) except?CUFILE_LOADING_ERROR nogil: + return _cufile._cuFileDriverSetMaxDirectIOSize(max_direct_io_size) + + +cdef CUfileError_t cuFileDriverSetMaxCacheSize(size_t max_cache_size) except?CUFILE_LOADING_ERROR nogil: + return _cufile._cuFileDriverSetMaxCacheSize(max_cache_size) + + +cdef CUfileError_t cuFileDriverSetMaxPinnedMemSize(size_t max_pinned_size) except?CUFILE_LOADING_ERROR nogil: + return _cufile._cuFileDriverSetMaxPinnedMemSize(max_pinned_size) + + +cdef CUfileError_t cuFileBatchIOSetUp(CUfileBatchHandle_t* batch_idp, unsigned nr) except?CUFILE_LOADING_ERROR nogil: + return _cufile._cuFileBatchIOSetUp(batch_idp, nr) + + +cdef CUfileError_t cuFileBatchIOSubmit(CUfileBatchHandle_t batch_idp, unsigned nr, CUfileIOParams_t* iocbp, unsigned int flags) except?CUFILE_LOADING_ERROR nogil: + return _cufile._cuFileBatchIOSubmit(batch_idp, nr, iocbp, flags) + + +cdef CUfileError_t cuFileBatchIOGetStatus(CUfileBatchHandle_t batch_idp, unsigned min_nr, unsigned* nr, CUfileIOEvents_t* iocbp, timespec* timeout) except?CUFILE_LOADING_ERROR nogil: + return _cufile._cuFileBatchIOGetStatus(batch_idp, min_nr, nr, iocbp, timeout) + + +cdef CUfileError_t cuFileBatchIOCancel(CUfileBatchHandle_t batch_idp) except?CUFILE_LOADING_ERROR nogil: + return _cufile._cuFileBatchIOCancel(batch_idp) + + +@cython.show_performance_hints(False) +cdef void cuFileBatchIODestroy(CUfileBatchHandle_t batch_idp) except* nogil: + _cufile._cuFileBatchIODestroy(batch_idp) + + +cdef CUfileError_t cuFileReadAsync(CUfileHandle_t fh, void* bufPtr_base, size_t* size_p, off_t* file_offset_p, off_t* bufPtr_offset_p, ssize_t* bytes_read_p, CUstream stream) except?CUFILE_LOADING_ERROR nogil: + return _cufile._cuFileReadAsync(fh, bufPtr_base, size_p, file_offset_p, bufPtr_offset_p, bytes_read_p, stream) + + +cdef CUfileError_t cuFileWriteAsync(CUfileHandle_t fh, void* bufPtr_base, size_t* size_p, off_t* file_offset_p, off_t* bufPtr_offset_p, ssize_t* bytes_written_p, CUstream stream) except?CUFILE_LOADING_ERROR nogil: + return _cufile._cuFileWriteAsync(fh, bufPtr_base, size_p, file_offset_p, bufPtr_offset_p, bytes_written_p, stream) + + +cdef CUfileError_t cuFileStreamRegister(CUstream stream, unsigned flags) except?CUFILE_LOADING_ERROR nogil: + return _cufile._cuFileStreamRegister(stream, flags) + + +cdef CUfileError_t cuFileStreamDeregister(CUstream stream) except?CUFILE_LOADING_ERROR nogil: + return _cufile._cuFileStreamDeregister(stream) + + +cdef CUfileError_t cuFileGetVersion(int* version) except?CUFILE_LOADING_ERROR nogil: + return _cufile._cuFileGetVersion(version) + + +cdef CUfileError_t cuFileGetParameterSizeT(CUFileSizeTConfigParameter_t param, size_t* value) except?CUFILE_LOADING_ERROR nogil: + return _cufile._cuFileGetParameterSizeT(param, value) + + +cdef CUfileError_t cuFileGetParameterBool(CUFileBoolConfigParameter_t param, cpp_bool* value) except?CUFILE_LOADING_ERROR nogil: + return _cufile._cuFileGetParameterBool(param, value) + + +cdef CUfileError_t cuFileGetParameterString(CUFileStringConfigParameter_t param, char* desc_str, int len) except?CUFILE_LOADING_ERROR nogil: + return _cufile._cuFileGetParameterString(param, desc_str, len) + + +cdef CUfileError_t cuFileSetParameterSizeT(CUFileSizeTConfigParameter_t param, size_t value) except?CUFILE_LOADING_ERROR nogil: + return _cufile._cuFileSetParameterSizeT(param, value) + + +cdef CUfileError_t cuFileSetParameterBool(CUFileBoolConfigParameter_t param, cpp_bool value) except?CUFILE_LOADING_ERROR nogil: + return _cufile._cuFileSetParameterBool(param, value) + + +cdef CUfileError_t cuFileSetParameterString(CUFileStringConfigParameter_t param, const char* desc_str) except?CUFILE_LOADING_ERROR nogil: + return _cufile._cuFileSetParameterString(param, desc_str) diff --git a/cuda_bindings/setup.py b/cuda_bindings/setup.py index 776a510cb..8dff9bea8 100644 --- a/cuda_bindings/setup.py +++ b/cuda_bindings/setup.py @@ -344,6 +344,7 @@ def do_cythonize(extensions): # internal files used by generated bindings (["cuda/bindings/_internal/nvjitlink.pyx"], None), (["cuda/bindings/_internal/nvvm.pyx"], None), + (["cuda/bindings/_internal/cufile.pyx"], None), (["cuda/bindings/_internal/utils.pyx"], None), ]