-
Notifications
You must be signed in to change notification settings - Fork 332
Decouple plugin execution providers (EPs) from the USE_WINML pre-processor macro #2038
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
Merged
Changes from 10 commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
58e3bff
Remove USE_WINML macro
baijumeswani 1cca7b0
Support WebGPU with older version of onnxruntime
baijumeswani b7bb816
Review pull-request review comments
baijumeswani bdf468f
Update function name
baijumeswani d95609e
Address pull-request review comments
baijumeswani 22ebd46
Another round of pull-request review comments
baijumeswani ad9a510
More comments:
baijumeswani d53bcd0
Address more review comments
baijumeswani 2fd3d8b
Refactor changes for appending session options
baijumeswani bc654fd
Fix CUDA arena cfg lifetime, add ROCm dispatch, harden VitisAI LoadLi…
Copilot da3e3f6
Update src/dml/session_options.cpp
baijumeswani 9cbe6fa
Update src/openvino/session_options.cpp
baijumeswani a7961ee
Solve build issues
baijumeswani b75615a
Merge branch 'main' of https://github.com/microsoft/onnxruntime-genai…
baijumeswani 0d2dbaf
clang-format and remove build definition
baijumeswani a90c41a
Must be primary session options for device to be set
baijumeswani 5133472
memoryinfo inside try catch
baijumeswani 668f7c4
Merge branch 'main' of https://github.com/microsoft/onnxruntime-genai…
baijumeswani 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,98 @@ | ||
| // Copyright (c) Microsoft Corporation. All rights reserved. | ||
| // Licensed under the MIT License. | ||
|
|
||
| #include "session_options.h" | ||
| #include "../models/session_options.h" | ||
|
|
||
| namespace Generators::CUDAExecutionProvider { | ||
|
|
||
| namespace { | ||
|
|
||
| void AppendProviderBridgeExecutionProvider( | ||
| OrtSessionOptions& session_options, | ||
| const Config::ProviderOptions& provider_options, | ||
| DeviceInterface*& device) { | ||
| auto ort_provider_options = OrtCUDAProviderOptionsV2::Create(); | ||
| std::vector<const char*> keys, values; | ||
|
|
||
| // Memory management settings | ||
| const char* arena_keys[] = { | ||
| "max_mem", | ||
| "arena_extend_strategy", | ||
| "initial_chunk_size_bytes", | ||
| "max_dead_bytes_per_chunk", | ||
| "initial_growth_chunk_size_bytes"}; | ||
| size_t arena_values[] = { | ||
| static_cast<size_t>(0), | ||
| static_cast<size_t>(-1), | ||
| static_cast<size_t>(-1), | ||
| static_cast<size_t>(-1), | ||
| static_cast<size_t>(-1)}; | ||
| bool use_arena_management = false; | ||
|
|
||
| for (auto& option : provider_options.options) { | ||
| auto it = std::find(std::begin(arena_keys), std::end(arena_keys), option.first); | ||
|
|
||
| if (it == std::end(arena_keys)) { | ||
| keys.emplace_back(option.first.c_str()); | ||
| values.emplace_back(option.second.c_str()); | ||
| } else { | ||
| const size_t idx = std::distance(std::begin(arena_keys), it); | ||
| long long parsed_value = std::stoll(option.second); | ||
| if (parsed_value < -1) { | ||
| throw std::out_of_range("Arena configuration option value is out of range"); | ||
| } | ||
| arena_values[idx] = (parsed_value == -1) | ||
| ? static_cast<size_t>(-1) | ||
| : static_cast<size_t>(parsed_value); | ||
| use_arena_management = true; | ||
| } | ||
| } | ||
| ort_provider_options->Update(keys.data(), values.data(), keys.size()); | ||
|
|
||
| // Device type determines the scoring device. | ||
| // Create and set our cudaStream_t | ||
| ort_provider_options->UpdateValue("user_compute_stream", device->GetCudaStream()); | ||
|
|
||
| // Use fine-grained memory management of BFC Arena. | ||
| // The arena_cfg must outlive the AppendExecutionProvider_CUDA_V2 call below, | ||
| // so it is declared outside the if block. | ||
| std::unique_ptr<OrtArenaCfg> arena_cfg; | ||
| if (use_arena_management) { | ||
| arena_cfg = OrtArenaCfg::Create(arena_keys, arena_values, std::size(arena_keys)); | ||
| ort_provider_options->UpdateValue("default_memory_arena_cfg", arena_cfg.get()); | ||
| } | ||
|
|
||
| session_options.AppendExecutionProvider_CUDA_V2(*ort_provider_options); | ||
| } | ||
|
|
||
| } // namespace | ||
|
|
||
| void AddCudaStreamConfig(OrtSessionOptions& session_options, DeviceInterface* device, | ||
| const std::string& config_key) { | ||
| if (device) { | ||
| void* stream_ptr = device->GetCudaStream(); | ||
| std::stringstream stream_value; | ||
| stream_value << reinterpret_cast<uintptr_t>(stream_ptr); | ||
| session_options.AddConfigEntry(config_key.c_str(), stream_value.str().c_str()); | ||
| } | ||
| } | ||
|
|
||
| DeviceInterface* AppendExecutionProvider(OrtSessionOptions& session_options, | ||
| const Config::ProviderOptions& provider_options, | ||
| const Config& /*config*/, | ||
| bool /*disable_graph_capture*/) { | ||
| auto device = GetDeviceInterface(DeviceType::CUDA); | ||
| AddCudaStreamConfig(session_options, device); | ||
| // Try pre-registered plugin path first | ||
| if (!AppendExecutionProviderV2(session_options, provider_options, | ||
| DeviceType::CUDA, "CUDAExecutionProvider")) { | ||
| // Register the CUDA execution provider as a provider-bridge provider. | ||
| CUDAExecutionProvider::AppendProviderBridgeExecutionProvider( | ||
| session_options, provider_options, device); | ||
| } | ||
|
|
||
| return device; | ||
| } | ||
|
|
||
| } // namespace Generators::CUDAExecutionProvider | ||
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,22 @@ | ||
| // Copyright (c) Microsoft Corporation. All rights reserved. | ||
| // Licensed under the MIT License. | ||
| #pragma once | ||
|
|
||
| #include "../generators.h" | ||
|
|
||
| namespace Generators::CUDAExecutionProvider { | ||
|
|
||
| // Writes the CUDA compute stream pointer (as a stringified integer) into a | ||
| // session config entry keyed by |config_key|. This is used by both the CUDA | ||
| // and NvTensorRtRtx providers so that the EP can share the same stream. | ||
| void AddCudaStreamConfig(OrtSessionOptions& session_options, DeviceInterface* device, | ||
| const std::string& config_key = "user_compute_stream"); | ||
|
|
||
| // Registers the CUDA execution provider on |session_options|. Tries the V2 | ||
| // plugin path first; falls back to the provider-bridge (CUDA V2 options) path. | ||
| DeviceInterface* AppendExecutionProvider(OrtSessionOptions& session_options, | ||
| const Config::ProviderOptions& provider_options, | ||
| const Config& config, | ||
| bool disable_graph_capture = false); | ||
|
|
||
| } // namespace Generators::CUDAExecutionProvider |
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,51 @@ | ||
| // Copyright (c) Microsoft Corporation. All rights reserved. | ||
| // Licensed under the MIT License. | ||
|
|
||
| #include "session_options.h" | ||
| #include "../models/session_options.h" | ||
|
|
||
|
baijumeswani marked this conversation as resolved.
|
||
| namespace Generators::DMLExecutionProvider { | ||
|
|
||
| DeviceInterface* AppendExecutionProvider(OrtSessionOptions& session_options, | ||
| const Config::ProviderOptions& provider_options, | ||
| const Config& /*config*/, | ||
| bool disable_graph_capture) { | ||
| #if USE_DML | ||
| if (!GetDmlInterface()) { | ||
| LUID device_luid{}; | ||
| LUID* p_device_luid{}; | ||
| uint32_t device_index{}; | ||
| uint32_t* p_device_index{}; | ||
| for (const auto& [name, value] : provider_options.options) { | ||
| if (name == "luid") { | ||
| if (auto separator_position = value.find(":"); separator_position != std::string::npos) { | ||
| device_luid.HighPart = std::stol(value.substr(0, separator_position)); | ||
| device_luid.LowPart = std::stol(value.substr(separator_position + 1)); | ||
| p_device_luid = &device_luid; | ||
| } | ||
| } else if (name == "device_index") { | ||
| device_index = std::stoi(value); | ||
| p_device_index = &device_index; | ||
| } | ||
| } | ||
|
|
||
| InitDmlInterface(p_device_luid, p_device_index); | ||
| } | ||
|
|
||
| // Non-decoder sessions (vision, speech, embedding) have control-flow nodes | ||
| // that are incompatible with graph capture, so the caller sets | ||
| // disable_graph_capture=true for those sessions. | ||
| if (!disable_graph_capture) { | ||
| session_options.AddConfigEntry("ep.dml.enable_graph_capture", "1"); | ||
| } | ||
|
|
||
| SetDmlProvider(session_options); | ||
|
|
||
| auto device = GetDeviceInterface(DeviceType::DML); // We use a DML allocator for input/output caches, but other tensors will use CPU tensors | ||
| return device; | ||
| #else | ||
| throw std::runtime_error("DML provider requested, but the installed GenAI has not been built with DML support"); | ||
| #endif | ||
| } | ||
|
|
||
| } // namespace Generators::DMLExecutionProvider | ||
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,16 @@ | ||
| // Copyright (c) Microsoft Corporation. All rights reserved. | ||
| // Licensed under the MIT License. | ||
| #pragma once | ||
|
|
||
| #include "../generators.h" | ||
|
|
||
| namespace Generators::DMLExecutionProvider { | ||
|
|
||
| // Initialises the DML interface (if not already done), optionally enables graph | ||
| // capture, and registers the DirectML execution provider on |session_options|. | ||
| DeviceInterface* AppendExecutionProvider(OrtSessionOptions& session_options, | ||
| const Config::ProviderOptions& provider_options, | ||
| const Config& config, | ||
| bool disable_graph_capture = false); | ||
|
|
||
| } // namespace Generators::DMLExecutionProvider |
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
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.
Uh oh!
There was an error while loading. Please reload this page.