[Doc] Cuda Plugin EP integration#2236
Draft
tianleiwu wants to merge 1 commit into
Draft
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Adds a new documentation page describing how ONNX Runtime GenAI integrates the CUDA Execution Provider when used as a V2 plugin, including intended selection flow, deployment layouts, build knobs, and testing guidance.
Changes:
- Introduces
docs/cuda_plugin_ep_integration.mdto document CUDA plugin EP registration and selection behavior. - Includes diagrams and step-by-step guidance for deployment and validation scenarios.
Comment on lines
+10
to
+14
| - **CUDA plugin EP** — a standalone shared library | ||
| (`libonnxruntime_providers_cuda_plugin.so` / `onnxruntime_providers_cuda_plugin.dll`) | ||
| registered with the `OrtEnv` and consumed through the **V2 plugin API** | ||
| (`AppendExecutionProvider_V2` over `OrtEpDevice`s), discovered under the EP name | ||
| `CudaPluginExecutionProvider`. |
Comment on lines
+41
to
+53
| ``` | ||
| GetDeviceInterface(CUDA) // genai-owned device + compute stream | ||
| AddCudaStreamConfig(...) // share genai's stream via user_compute_stream | ||
|
|
||
| [bundled build only] TryRegisterBundledCudaPluginEp() // self-register default library | ||
|
|
||
| if AppendExecutionProviderV2("CudaPluginExecutionProvider") // plugin EP, if present | ||
| -> done | ||
| else if AppendExecutionProviderV2("CUDAExecutionProvider") // built-in plugged in | ||
| -> done | ||
| else | ||
| AppendProviderBridgeExecutionProvider(...) // built-in provider bridge | ||
| ``` |
Comment on lines
+59
to
+70
| ```mermaid | ||
| flowchart TD | ||
| A[AppendExecutionProvider cuda] --> B[GetDeviceInterface CUDA<br/>AddCudaStreamConfig] | ||
| B --> C{bundled build?} | ||
| C -- yes --> D[TryRegisterBundledCudaPluginEp<br/>register default library name] | ||
| C -- no --> E | ||
| D --> E{plugin EP registered?<br/>CudaPluginExecutionProvider} | ||
| E -- yes --> F[AppendExecutionProvider_V2<br/>plugin EP] | ||
| E -- no --> G{built-in plugged in?<br/>CUDAExecutionProvider} | ||
| G -- yes --> H[AppendExecutionProvider_V2<br/>built-in EP] | ||
| G -- no --> I[AppendProviderBridgeExecutionProvider<br/>CUDA_V2 options] | ||
| ``` |
Comment on lines
+86
to
+88
| - C API: `OgaRegisterExecutionProviderLibrary("CudaPluginExecutionProvider", path)` | ||
| - Python: `og.register_execution_provider_library("CudaPluginExecutionProvider", path)` | ||
| - C#: `OrtEnv.Instance().RegisterExecutionProviderLibrary("CudaPluginExecutionProvider", path)` |
Comment on lines
+90
to
+96
| In the bundled layout genai calls `TryRegisterBundledCudaPluginEp()`, which registers the | ||
| platform default library file name (`libonnxruntime_providers_cuda_plugin.so` / | ||
| `.dylib` / `.dll`). The bare file name is resolved by the OS loader through the | ||
| genai/onnxruntime RPATH (`$ORIGIN` on Linux), so the plugin is found next to | ||
| `libonnxruntime`. Registration is idempotent (deduped by | ||
| `EnsureExecutionProviderLibraryRegistered`) and best-effort: if the library is missing or | ||
| fails to load, a warning is logged and the flow falls back to the built-in CUDA EP. |
Comment on lines
+98
to
+122
| ### Build option | ||
|
|
||
| Declared in [`cmake/options.cmake`](../cmake/options.cmake): | ||
|
|
||
| ```cmake | ||
| cmake_dependent_option(REGISTER_BUNDLED_CUDA_PLUGIN_EP | ||
| "Auto-register the bundled CUDA plugin EP library" OFF "USE_CUDA" OFF) | ||
| ``` | ||
|
|
||
| When `ON`, [`cmake/check_cuda.cmake`](../cmake/check_cuda.cmake) adds the compile | ||
| definition `ORTGENAI_REGISTER_BUNDLED_CUDA_PLUGIN_EP=1`, which gates the | ||
| `TryRegisterBundledCudaPluginEp()` call and the default-library-name constants in | ||
| `session_options.cpp`. The option depends on `USE_CUDA` and defaults to `OFF`, so the | ||
| default build is the clean "caller registers out-of-band" model. | ||
|
|
||
| Build examples: | ||
|
|
||
| ```bash | ||
| # Default: separate-directory layout, caller registers the plugin out-of-band. | ||
| python build.py --use_cuda | ||
|
|
||
| # Bundled layout: genai self-registers the plugin shipped next to libonnxruntime. | ||
| python build.py --use_cuda --cmake_extra_defines REGISTER_BUNDLED_CUDA_PLUGIN_EP=ON | ||
| ``` | ||
|
|
Comment on lines
+152
to
+156
| | EP | V2 registration name | V1 / built-in fallback | Library registration | | ||
| | --- | --- | --- | --- | | ||
| | WebGPU | `WebGpuExecutionProvider` | legacy by name | auto-surfaced by libonnxruntime (in-tree) | | ||
| | NvTensorRtRtx | `NvTensorRTRTXExecutionProvider` | legacy by name | caller, out-of-band | | ||
| | CUDA | `CudaPluginExecutionProvider` | built-in provider bridge | caller out-of-band (default) **or** genai bundled (build option) | |
Comment on lines
+162
to
+168
| ## Files changed | ||
|
|
||
| | File | Change | | ||
| | --- | --- | | ||
| | [`cmake/options.cmake`](../cmake/options.cmake) | Added `REGISTER_BUNDLED_CUDA_PLUGIN_EP` option (default `OFF`). | | ||
| | [`cmake/check_cuda.cmake`](../cmake/check_cuda.cmake) | Emits `ORTGENAI_REGISTER_BUNDLED_CUDA_PLUGIN_EP=1` when the option is `ON`. | | ||
| | [`src/cuda/session_options.cpp`](../src/cuda/session_options.cpp) | Try-plugin-then-built-in selection; bundled self-registration guarded by the compile definition. | |
Comment on lines
+172
to
+178
| - **Separate-directory layout (default build):** register the plugin out-of-band, e.g. | ||
| `og.register_execution_provider_library("CudaPluginExecutionProvider", "<plugin dir>/libonnxruntime_providers_cuda_plugin.so")`, | ||
| then run a model with the `cuda` provider and confirm the plugin EP is selected (the | ||
| graph capture/replay log lines mention `CudaPluginExecutionProvider`). | ||
| - **Bundled layout (`REGISTER_BUNDLED_CUDA_PLUGIN_EP=ON`):** place the plugin library next | ||
| to `libonnxruntime`, run a model with no caller-side registration, and confirm the plugin | ||
| EP is selected automatically. |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
No description provided.