Skip to content

Commit 248edca

Browse files
Add cufile bindings (#684)
* Draft: Add cufile bindings(Not building currently) * make the project buildable * try to build cufile in the CI * fix multiple issues at once * regenerate with latest codegen * skip fetching cufile on windows * skip building cufile bindings on Windows * fix * glob pattern needs to be expanded manually * after expanding glob we expect a certain structure * clean up extern/cimport; fix redefinition warning * Update tests to include handle/buf register and sync read/write * enhance error msg * WAR: patch the wrong dtype for now * ensure we can get size of nested POD members * Add Async Tests * Merge conflict * Add batch tests * Add get/set tests * add docs * Pre-commit fixes * add cufile wheel dependency * fix fetch_ctk failure * Add skipif checks * cufile wheel only available on linux * Review Comments * fix cuFile API ref not rendered * pre commit fixes * point to cufile C docs * skip tests on windows * fix api refs * fix linter * Update Get/SetParameter APIs * Fix Tests and also remove one unnecessary test * fix linter errors * document that the cufile bindings currently need NumPy * fix doc rendering --------- Co-authored-by: Leo Fang <[email protected]>
1 parent ed12c83 commit 248edca

File tree

14 files changed

+4490
-12
lines changed

14 files changed

+4490
-12
lines changed

.github/actions/fetch_ctk/action.yml

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,37 @@ inputs:
1717
description: "A list of the CTK components to install as a comma-separated list. e.g. 'cuda_nvcc,cuda_nvrtc,cuda_cudart'"
1818
required: false
1919
type: string
20-
default: "cuda_nvcc,cuda_cudart,cuda_nvrtc,cuda_profiler_api,cuda_cccl,libnvjitlink"
20+
default: "cuda_nvcc,cuda_cudart,cuda_nvrtc,cuda_profiler_api,cuda_cccl,libnvjitlink,libcufile"
2121

2222
runs:
2323
using: composite
2424
steps:
2525
- name: Set up CTK cache variable
2626
shell: bash --noprofile --norc -xeuo pipefail {0}
2727
run: |
28-
HASH=$(echo -n "${{ inputs.cuda-components }}" | sha256sum | awk '{print $1}')
28+
# Pre-process the component list to ensure hash uniqueness
29+
CTK_CACHE_COMPONENTS=${{ inputs.cuda-components }}
30+
# Conditionally strip out libnvjitlink for CUDA versions < 12
31+
CUDA_MAJOR_VER="$(cut -d '.' -f 1 <<< ${{ inputs.cuda-version }})"
32+
if [[ "$CUDA_MAJOR_VER" -lt 12 ]]; then
33+
CTK_CACHE_COMPONENTS="${CTK_CACHE_COMPONENTS//libnvjitlink/}"
34+
fi
35+
# Conditionally strip out libcufile since it does not support Windows
36+
if [[ "${{ inputs.host-platform }}" == win-* ]]; then
37+
CTK_CACHE_COMPONENTS="${CTK_CACHE_COMPONENTS//libcufile/}"
38+
fi
39+
# Conditionally strip out libcufile for CUDA versions < 12.2.0 + aarch64 (redist not available)
40+
CUDA_MINOR_VER="$(cut -d '.' -f 2 <<< ${{ inputs.cuda-version }})"
41+
if [[ ("$CUDA_MAJOR_VER" -lt 12 || "$CUDA_MINOR_VER" -lt 2) && "${{ inputs.host-platform }}" == "linux-aarch64" ]]; then
42+
CTK_CACHE_COMPONENTS="${CTK_CACHE_COMPONENTS//libcufile/}"
43+
fi
44+
# Cleanup stray commas after removing components
45+
CTK_CACHE_COMPONENTS="${CTK_CACHE_COMPONENTS//,,/,}"
46+
47+
HASH=$(echo -n "${CTK_CACHE_COMPONENTS}" | sha256sum | awk '{print $1}')
2948
echo "CTK_CACHE_KEY=mini-ctk-${{ inputs.cuda-version }}-${{ inputs.host-platform }}-$HASH" >> $GITHUB_ENV
3049
echo "CTK_CACHE_FILENAME=mini-ctk-${{ inputs.cuda-version }}-${{ inputs.host-platform }}-$HASH.tar.gz" >> $GITHUB_ENV
31-
echo "CTK_CACHE_COMPONENTS=${{ inputs.cuda-components }}" >> $GITHUB_ENV
50+
echo "CTK_CACHE_COMPONENTS=${CTK_CACHE_COMPONENTS}" >> $GITHUB_ENV
3251
3352
- name: Install dependencies
3453
uses: ./.github/actions/install_unix_deps
@@ -94,12 +113,6 @@ runs:
94113
rm $CTK_COMPONENT_COMPONENT_FILENAME
95114
}
96115
97-
# Conditionally strip out libnvjitlink for CUDA versions < 12
98-
if [[ "$(cut -d '.' -f 1 <<< ${{ inputs.cuda-version }})" -lt 12 ]]; then
99-
CTK_CACHE_COMPONENTS="${CTK_CACHE_COMPONENTS//libnvjitlink/}"
100-
fi
101-
# Cleanup stray commas after removing components
102-
CTK_CACHE_COMPONENTS="${CTK_CACHE_COMPONENTS//,,/,}"
103116
# Get headers and shared libraries in place
104117
for item in $(echo $CTK_CACHE_COMPONENTS | tr ',' ' '); do
105118
populate_cuda_path "$item"
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# SPDX-FileCopyrightText: Copyright (c) 2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
2+
#
3+
# SPDX-License-Identifier: LicenseRef-NVIDIA-SOFTWARE-LICENSE
4+
#
5+
# This code was automatically generated with version 12.9.0. Do not modify it directly.
6+
7+
from ..cycufile cimport *
8+
9+
10+
###############################################################################
11+
# Wrapper functions
12+
###############################################################################
13+
14+
cdef CUfileError_t _cuFileHandleRegister(CUfileHandle_t* fh, CUfileDescr_t* descr) except?<CUfileError_t>CUFILE_LOADING_ERROR nogil
15+
cdef void _cuFileHandleDeregister(CUfileHandle_t fh) except* nogil
16+
cdef CUfileError_t _cuFileBufRegister(const void* bufPtr_base, size_t length, int flags) except?<CUfileError_t>CUFILE_LOADING_ERROR nogil
17+
cdef CUfileError_t _cuFileBufDeregister(const void* bufPtr_base) except?<CUfileError_t>CUFILE_LOADING_ERROR nogil
18+
cdef ssize_t _cuFileRead(CUfileHandle_t fh, void* bufPtr_base, size_t size, off_t file_offset, off_t bufPtr_offset) except* nogil
19+
cdef ssize_t _cuFileWrite(CUfileHandle_t fh, const void* bufPtr_base, size_t size, off_t file_offset, off_t bufPtr_offset) except* nogil
20+
cdef CUfileError_t _cuFileDriverOpen() except?<CUfileError_t>CUFILE_LOADING_ERROR nogil
21+
cdef CUfileError_t _cuFileDriverClose_v2() except?<CUfileError_t>CUFILE_LOADING_ERROR nogil
22+
cdef long _cuFileUseCount() except* nogil
23+
cdef CUfileError_t _cuFileDriverGetProperties(CUfileDrvProps_t* props) except?<CUfileError_t>CUFILE_LOADING_ERROR nogil
24+
cdef CUfileError_t _cuFileDriverSetPollMode(cpp_bool poll, size_t poll_threshold_size) except?<CUfileError_t>CUFILE_LOADING_ERROR nogil
25+
cdef CUfileError_t _cuFileDriverSetMaxDirectIOSize(size_t max_direct_io_size) except?<CUfileError_t>CUFILE_LOADING_ERROR nogil
26+
cdef CUfileError_t _cuFileDriverSetMaxCacheSize(size_t max_cache_size) except?<CUfileError_t>CUFILE_LOADING_ERROR nogil
27+
cdef CUfileError_t _cuFileDriverSetMaxPinnedMemSize(size_t max_pinned_size) except?<CUfileError_t>CUFILE_LOADING_ERROR nogil
28+
cdef CUfileError_t _cuFileBatchIOSetUp(CUfileBatchHandle_t* batch_idp, unsigned nr) except?<CUfileError_t>CUFILE_LOADING_ERROR nogil
29+
cdef CUfileError_t _cuFileBatchIOSubmit(CUfileBatchHandle_t batch_idp, unsigned nr, CUfileIOParams_t* iocbp, unsigned int flags) except?<CUfileError_t>CUFILE_LOADING_ERROR nogil
30+
cdef CUfileError_t _cuFileBatchIOGetStatus(CUfileBatchHandle_t batch_idp, unsigned min_nr, unsigned* nr, CUfileIOEvents_t* iocbp, timespec* timeout) except?<CUfileError_t>CUFILE_LOADING_ERROR nogil
31+
cdef CUfileError_t _cuFileBatchIOCancel(CUfileBatchHandle_t batch_idp) except?<CUfileError_t>CUFILE_LOADING_ERROR nogil
32+
cdef void _cuFileBatchIODestroy(CUfileBatchHandle_t batch_idp) except* nogil
33+
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?<CUfileError_t>CUFILE_LOADING_ERROR nogil
34+
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?<CUfileError_t>CUFILE_LOADING_ERROR nogil
35+
cdef CUfileError_t _cuFileStreamRegister(CUstream stream, unsigned flags) except?<CUfileError_t>CUFILE_LOADING_ERROR nogil
36+
cdef CUfileError_t _cuFileStreamDeregister(CUstream stream) except?<CUfileError_t>CUFILE_LOADING_ERROR nogil
37+
cdef CUfileError_t _cuFileGetVersion(int* version) except?<CUfileError_t>CUFILE_LOADING_ERROR nogil
38+
cdef CUfileError_t _cuFileGetParameterSizeT(CUFileSizeTConfigParameter_t param, size_t* value) except?<CUfileError_t>CUFILE_LOADING_ERROR nogil
39+
cdef CUfileError_t _cuFileGetParameterBool(CUFileBoolConfigParameter_t param, cpp_bool* value) except?<CUfileError_t>CUFILE_LOADING_ERROR nogil
40+
cdef CUfileError_t _cuFileGetParameterString(CUFileStringConfigParameter_t param, char* desc_str, int len) except?<CUfileError_t>CUFILE_LOADING_ERROR nogil
41+
cdef CUfileError_t _cuFileSetParameterSizeT(CUFileSizeTConfigParameter_t param, size_t value) except?<CUfileError_t>CUFILE_LOADING_ERROR nogil
42+
cdef CUfileError_t _cuFileSetParameterBool(CUFileBoolConfigParameter_t param, cpp_bool value) except?<CUfileError_t>CUFILE_LOADING_ERROR nogil
43+
cdef CUfileError_t _cuFileSetParameterString(CUFileStringConfigParameter_t param, const char* desc_str) except?<CUfileError_t>CUFILE_LOADING_ERROR nogil

0 commit comments

Comments
 (0)