Skip to content

Commit c00f690

Browse files
authored
Add a new ORT API GetSessionOptionConfigEntries (microsoft#25277)
### Description Add a new ORT API `GetSessionOptionConfigEntries`. ### Motivation and Context microsoft#24887 allows plugin-EPs to interface with ORT using a binary stable interface. microsoft#24445 allows an EP to handle the extraction of EP options from the session option configurations. For an EP like VitisAI EP to comply with the requirements, it is necessary for a plugin-EPs to access all config entries in a session option. ```c++ OrtKeyValuePairs * kvps = nullptr; auto status = GetSessionOptionConfigEntries(session_option, &kvps); if(status) { throw status; } std::unique_ptr<OrtKeyValuePairs, void (*)(OrtKeyValuePairs*)> config_entries(kvps, ort_api.ReleaseKeyValuePairs); const char* const* keys = nullptr; const char* const* values = nullptr; size_t num_keys = 0; // Get keys and values from the config entries Ort::GetApi().GetKeyValuePairs(config_entries.get(), &keys, &values, &num_keys); for (size_t i = 0; i < num_keys; ++i) { // process keys[i] and values[i] } ```
1 parent a3c3e2f commit c00f690

File tree

4 files changed

+31
-0
lines changed

4 files changed

+31
-0
lines changed

include/onnxruntime/core/session/onnxruntime_c_api.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6074,6 +6074,18 @@ struct OrtApi {
60746074
* \since Version 1.23
60756075
*/
60766076
ORT_API2_STATUS(GetTensorData, _In_ const OrtValue* value, _Outptr_ const void** out);
6077+
6078+
/** \brief Get Session configuration entries.
6079+
*
6080+
* \param[in] options The session options.
6081+
* \param[out] out A pointer to a newly created OrtKeyValuePairs instance.
6082+
*
6083+
* An OrtKeyValuePairs instance containing all session configuration entries.
6084+
* Note: the user should call OrtApi::ReleaseKeyValuePairs.
6085+
*
6086+
* \since Version 1.23.
6087+
*/
6088+
ORT_API2_STATUS(GetSessionOptionsConfigEntries, _In_ const OrtSessionOptions* options, _Outptr_ OrtKeyValuePairs** out);
60776089
};
60786090

60796091
/*

onnxruntime/core/session/abi_session_options.cc

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,21 @@ ORT_API_STATUS_IMPL(OrtApis::GetSessionConfigEntry, _In_ const OrtSessionOptions
278278
API_IMPL_END
279279
}
280280

281+
ORT_API_STATUS_IMPL(OrtApis::GetSessionOptionsConfigEntries, _In_ const OrtSessionOptions* options, _Outptr_ OrtKeyValuePairs** out) {
282+
API_IMPL_BEGIN
283+
if (options == nullptr) {
284+
return OrtApis::CreateStatus(ORT_INVALID_ARGUMENT, "options is nullptr");
285+
}
286+
auto& config_options = options->value.config_options.GetConfigOptionsMap();
287+
auto kvps = std::make_unique<OrtKeyValuePairs>();
288+
for (auto& kv : config_options) {
289+
kvps->Add(kv.first.c_str(), kv.second.c_str());
290+
}
291+
*out = reinterpret_cast<OrtKeyValuePairs*>(kvps.release());
292+
return nullptr;
293+
API_IMPL_END
294+
}
295+
281296
ORT_API_STATUS_IMPL(OrtApis::AddInitializer, _Inout_ OrtSessionOptions* options, _In_z_ const char* name,
282297
_In_ const OrtValue* val) {
283298
API_IMPL_BEGIN

onnxruntime/core/session/onnxruntime_c_api.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3632,6 +3632,8 @@ static constexpr OrtApi ort_api_1_to_23 = {
36323632
&OrtApis::ReleaseSharedAllocator,
36333633

36343634
&OrtApis::GetTensorData,
3635+
3636+
&OrtApis::GetSessionOptionsConfigEntries,
36353637
};
36363638

36373639
// OrtApiBase can never change as there is no way to know what version of OrtApiBase is returned by OrtGetApiBase.

onnxruntime/core/session/ort_apis.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -690,4 +690,6 @@ ORT_API_STATUS_IMPL(ReleaseSharedAllocator, _In_ OrtEnv* env, _In_ const OrtEpDe
690690
_In_ OrtDeviceMemoryType mem_type);
691691

692692
ORT_API_STATUS_IMPL(GetTensorData, _In_ const OrtValue* value, _Outptr_ const void** out);
693+
694+
ORT_API_STATUS_IMPL(GetSessionOptionsConfigEntries, _In_ const OrtSessionOptions* options, _Outptr_ OrtKeyValuePairs** out);
693695
} // namespace OrtApis

0 commit comments

Comments
 (0)