From 28f77a3ae408583be311698ba8c0020cdb134eee Mon Sep 17 00:00:00 2001 From: Ryan Hill <38674843+RyanUnderhill@users.noreply.github.com> Date: Tue, 22 Oct 2024 02:14:45 -0700 Subject: [PATCH] Allow for multiple provider configs, and for merging multiple configs. (#1003) This is mostly to enable overlaying a second config on top of the first through runtime options. This now works: ``` "session_options": { "provider_options": [ { "cuda": {} }, { "rocm": {} } ] }, ``` --- src/config.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/config.cpp b/src/config.cpp index 1e07e7f9f..451fd5b64 100644 --- a/src/config.cpp +++ b/src/config.cpp @@ -33,8 +33,13 @@ struct ProviderOptionsObject_Element : JSON::Element { explicit ProviderOptionsObject_Element(std::vector& v) : v_{v} {} JSON::Element& OnObject(std::string_view name) override { - if (options_element_) - throw std::runtime_error("Each object in the provider_options array can only have one member (named value)"); + for (auto& v : v_) { + if (v.name == name) { + options_element_ = std::make_unique(v); + return *options_element_; + } + } + auto& options = v_.emplace_back(); options.name = name; options_element_ = std::make_unique(options);