mirror of
https://github.com/saymrwulf/onnxruntime.git
synced 2026-06-18 01:54:05 +00:00
Update Python API to allow more flexibility for setting providers and provider options. The providers argument (InferenceSession/TrainingSession constructors, InferenceSession.set_providers()) now also accepts a tuple of (name, options dict). Fix get_available_providers() API (and the corresponding function in the C API) to return the providers in default priority order. Now it can be used as a starting point for the providers argument and maintain the default priority order. Convert some usages of the deprecated global configuration functions to use EP-specific options instead. Update some EP-specific option parsing to fail on unknown options. Other clean up.
59 lines
1.5 KiB
C++
59 lines
1.5 KiB
C++
// Copyright (c) Microsoft Corporation. All rights reserved.
|
|
// Licensed under the MIT License.
|
|
|
|
#include "core/framework/provider_options_utils.h"
|
|
|
|
#include "gtest/gtest.h"
|
|
|
|
#include "asserts.h"
|
|
|
|
namespace onnxruntime {
|
|
namespace test {
|
|
|
|
namespace {
|
|
enum class TestEnum {
|
|
A,
|
|
Unmapped,
|
|
};
|
|
|
|
const EnumNameMapping<TestEnum> test_enum_mapping{
|
|
{TestEnum::A, "A"},
|
|
};
|
|
} // namespace
|
|
|
|
TEST(ProviderOptionsUtilsTest, ProviderOptionsParser) {
|
|
int i;
|
|
bool b;
|
|
TestEnum e;
|
|
ProviderOptionsParser parser{};
|
|
parser.AddAssignmentToReference("int", i);
|
|
parser.AddAssignmentToReference("bool", b);
|
|
parser.AddAssignmentToEnumReference("enum", test_enum_mapping, e);
|
|
|
|
// adding same option again should throw
|
|
ASSERT_THROW(parser.AddAssignmentToReference("int", i), OnnxRuntimeException);
|
|
|
|
ASSERT_STATUS_OK(parser.Parse({{"int", "3"}, {"bool", "true"}, {"enum", "A"}}));
|
|
EXPECT_EQ(i, 3);
|
|
EXPECT_EQ(b, true);
|
|
EXPECT_EQ(e, TestEnum::A);
|
|
|
|
ASSERT_FALSE(parser.Parse({{"unknown option", "some value"}}).IsOK());
|
|
}
|
|
|
|
TEST(ProviderOptionsUtilsTest, EnumToName) {
|
|
std::string name;
|
|
ASSERT_STATUS_OK(EnumToName(test_enum_mapping, TestEnum::A, name));
|
|
EXPECT_EQ(name, "A");
|
|
ASSERT_FALSE(EnumToName(test_enum_mapping, TestEnum::Unmapped, name).IsOK());
|
|
}
|
|
|
|
TEST(ProviderOptionsUtilsTest, NameToEnum) {
|
|
TestEnum value;
|
|
ASSERT_STATUS_OK(NameToEnum(test_enum_mapping, "A", value));
|
|
EXPECT_EQ(value, TestEnum::A);
|
|
ASSERT_FALSE(NameToEnum(test_enum_mapping, "invalid", value).IsOK());
|
|
}
|
|
|
|
} // namespace test
|
|
} // namespace onnxruntime
|