forked from llm-d/llm-d-kv-cache
-
Notifications
You must be signed in to change notification settings - Fork 3
[sync] upstream llm-d main branch 1c435cb [2026-04-02] #16
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
zdtsw
merged 6 commits into
opendatahub-io:main_2
from
zdtsw-forking:sync/upstream-1c435cb
Apr 6, 2026
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
2e90fe8
fix: increase RenderChat timeout for multimodal requests (#481)
vMaroon 08138e5
feat: add GPUDirect Storage (GDS) support to llmd_fs_backend (#419)
kfirtoledo 263005e
test: add golden test cases for deterministic pipeline output verific…
gyliu513 b248406
fix: make golden chat tokenization test date-independent (#483)
gyliu513 1c435cb
fix: single-pass []any decode for forward/backward compat
vMaroon 81290a7
Sync upstream llm-d/llm-d-kv-cache 1c435cb
zdtsw File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
146 changes: 146 additions & 0 deletions
146
kv_connectors/llmd_fs_backend/csrc/storage/backends/fs_gds/cufile_loader.hpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,146 @@ | ||
| /* | ||
| * Copyright 2025 The llm-d Authors. | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| #pragma once | ||
|
|
||
| #include <dlfcn.h> | ||
| #include <cstddef> | ||
| #include <cstdint> | ||
|
|
||
| // cuFile operation status codes | ||
| enum CUfileOpError { CU_FILE_SUCCESS = 0 }; | ||
|
|
||
| // File handle types for cuFileHandleRegister | ||
| enum CUfileFileHandleType { CU_FILE_HANDLE_TYPE_OPAQUE_FD = 1 }; | ||
|
|
||
| // Buffer registration flag for RDMA-capable memory | ||
| #define CU_FILE_RDMA_REGISTER 1 | ||
|
|
||
| // Return type for most cuFile API calls | ||
| struct CUfileError_t { | ||
| CUfileOpError err; | ||
| }; | ||
|
|
||
| // Forward declaration for filesystem operations table | ||
| struct CUfileFSOps_t; | ||
|
|
||
| // File descriptor passed to cuFileHandleRegister (layout must match cufile.h) | ||
| struct CUfileDescr_t { | ||
| CUfileFileHandleType type; | ||
| union { | ||
| int fd; | ||
| void* handle; | ||
| } handle; | ||
| const CUfileFSOps_t* fs_ops; | ||
| }; | ||
|
|
||
| // Opaque handle returned by cuFileHandleRegister | ||
| typedef void* CUfileHandle_t; | ||
|
|
||
| // Driver properties returned by cuFileDriverGetProperties | ||
| struct CUfileDrvProps_t { | ||
| size_t max_device_cache_size; | ||
| size_t max_device_pinned_mem_size; | ||
| char _reserved[256]; | ||
| }; | ||
|
|
||
| // CuFileApi is a runtime wrapper for the NVIDIA cuFile (GDS) library, | ||
| // so the same wheel works with or without GDS. Loads libcufile.so via dlopen. | ||
| // Function pointers are resolved via dlsym by symbol name (e.g. "cuFileRead"). | ||
| // Singleton — library is loaded once and function pointers are reused. | ||
| class CuFileApi { | ||
| public: | ||
| static CuFileApi& instance() { | ||
| static CuFileApi loader; | ||
| return loader; | ||
| } | ||
|
|
||
| bool is_loaded() const { return m_handle != nullptr; } | ||
|
|
||
| // Function signature types — define what each cuFile function looks like | ||
| using FnDriverOpen = CUfileError_t (*)(); | ||
| using FnDriverClose = CUfileError_t (*)(); | ||
| using FnGetVersion = CUfileError_t (*)(int*); | ||
| using FnDriverGetProperties = CUfileError_t (*)(CUfileDrvProps_t*); | ||
| using FnBufRegister = CUfileError_t (*)(const void*, size_t, int); | ||
| using FnBufDeregister = CUfileError_t (*)(const void*); | ||
| using FnHandleRegister = CUfileError_t (*)(CUfileHandle_t*, CUfileDescr_t*); | ||
| using FnHandleDeregister = void (*)(CUfileHandle_t); | ||
| using FnRead = ssize_t (*)(CUfileHandle_t, void*, size_t, off_t, off_t); | ||
| using FnWrite = | ||
| ssize_t (*)(CUfileHandle_t, const void*, size_t, off_t, off_t); | ||
|
|
||
| // Resolved function pointers — null if library not loaded, filled by | ||
| // constructor via dlsym | ||
| FnDriverOpen cuFileDriverOpen = nullptr; | ||
| FnDriverClose cuFileDriverClose = nullptr; | ||
| FnGetVersion cuFileGetVersion = nullptr; | ||
| FnDriverGetProperties cuFileDriverGetProperties = nullptr; | ||
| FnBufRegister cuFileBufRegister = nullptr; | ||
| FnBufDeregister cuFileBufDeregister = nullptr; | ||
| FnHandleRegister cuFileHandleRegister = nullptr; | ||
| FnHandleDeregister cuFileHandleDeregister = nullptr; | ||
| FnRead cuFileRead = nullptr; | ||
| FnWrite cuFileWrite = nullptr; | ||
|
|
||
| private: | ||
| void* m_handle = nullptr; | ||
|
|
||
| // Attempts to load libcufile.so and resolve all function symbols. | ||
| // If the library or any symbol is missing, m_handle stays null. | ||
| CuFileApi() { | ||
| m_handle = dlopen("libcufile.so", RTLD_NOW); | ||
| if (!m_handle) { | ||
| // Try versioned name | ||
| m_handle = dlopen("libcufile.so.0", RTLD_NOW); | ||
| } | ||
| if (!m_handle) return; | ||
|
|
||
| cuFileDriverOpen = | ||
| reinterpret_cast<FnDriverOpen>(dlsym(m_handle, "cuFileDriverOpen")); | ||
| cuFileDriverClose = | ||
| reinterpret_cast<FnDriverClose>(dlsym(m_handle, "cuFileDriverClose")); | ||
| cuFileGetVersion = | ||
| reinterpret_cast<FnGetVersion>(dlsym(m_handle, "cuFileGetVersion")); | ||
| cuFileDriverGetProperties = reinterpret_cast<FnDriverGetProperties>( | ||
| dlsym(m_handle, "cuFileDriverGetProperties")); | ||
| cuFileBufRegister = | ||
| reinterpret_cast<FnBufRegister>(dlsym(m_handle, "cuFileBufRegister")); | ||
| cuFileBufDeregister = reinterpret_cast<FnBufDeregister>( | ||
| dlsym(m_handle, "cuFileBufDeregister")); | ||
| cuFileHandleRegister = reinterpret_cast<FnHandleRegister>( | ||
| dlsym(m_handle, "cuFileHandleRegister")); | ||
| cuFileHandleDeregister = reinterpret_cast<FnHandleDeregister>( | ||
| dlsym(m_handle, "cuFileHandleDeregister")); | ||
| cuFileRead = reinterpret_cast<FnRead>(dlsym(m_handle, "cuFileRead")); | ||
| cuFileWrite = reinterpret_cast<FnWrite>(dlsym(m_handle, "cuFileWrite")); | ||
|
|
||
| // Verify all symbols resolved | ||
| if (!cuFileDriverOpen || !cuFileDriverClose || !cuFileGetVersion || | ||
| !cuFileBufRegister || !cuFileBufDeregister || !cuFileHandleRegister || | ||
| !cuFileHandleDeregister || !cuFileRead || !cuFileWrite) { | ||
| dlclose(m_handle); | ||
| m_handle = nullptr; | ||
| } | ||
| } | ||
|
|
||
| // Unloads the library when the process exits | ||
| ~CuFileApi() { | ||
| if (m_handle) { | ||
| dlclose(m_handle); | ||
| } | ||
| } | ||
| }; | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
🌐 Web query:
What is the struct layout for CUfileDescr_t and CUfileDrvProps_t in NVIDIA cuFile library version 1.x?💡 Result:
The struct layouts for CUfileDescr_t and CUfileDrvProps_t in NVIDIA cuFile library version 1.x, as documented in official NVIDIA GPUDirect Storage cuFile API references (across CUDA 11.4-11.8 and current GDS v1.16 docs), are as follows: CUfileDescr_t: typedef struct CUfileDescr_t { CUfileFileHandleType type; /* type of file being registered / union { int fd; / Linux */ void handle; / Windows */ } handle; const CUfileFSOps_t fs_ops; / file system operation table / } CUfileDescr_t; CUfileDrvProps_t: typedef struct CUfileDrvProps { struct { 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; } nvfs; CUfileFeatureFlags_t fflags; unsigned int max_device_cache_size; unsigned int per_buffer_cache_size; unsigned int max_pinned_memory_size; unsigned int max_batch_io_timeout_msecs; / present in some versions like 11.6 */ } CUfileDrvProps_t; Note: Minor variations exist across exact versions (e.g., max_batch_io_timeout_msecs appears in CUDA 11.6+ docs), but the core layout is consistent. The structure is self-describing per cuFileDriverGetProperties documentation. Layouts match across PDF docs, HTML API guides, and manpages for libcufile-dev 1.5+.
Citations:
Critical ABI mismatch in
CUfileDrvProps_tstruct definition—will cause memory corruption.The
CUfileDrvProps_tstruct defined in this file does not match NVIDIA's official cuFile API definition. According to NVIDIA's cuFile documentation (CUDA 11.4–11.8, GDS v1.16), the actual struct contains:nvfsstruct with version and configuration fieldsCUfileFeatureFlags_t fflagsunsigned intfield types (notsize_t)max_pinned_memory_sizeandper_buffer_cache_size(notmax_device_pinned_mem_size)max_batch_io_timeout_msecsin newer versionsThe code's simplified definition with
_reserved[256]padding will misalign with the actual library structure, causing memory corruption whencuFileDriverGetProperties()writes to it. Fix struct definition to match NVIDIA's headers exactly, or use the official NVIDIA-provided header directly instead of recreating it. CUfileDescr_t is correctly defined.🤖 Prompt for AI Agents