diff --git a/onnxruntime/core/util/thread_utils.cc b/onnxruntime/core/util/thread_utils.cc index fcf9f65adb..1535b52aa5 100644 --- a/onnxruntime/core/util/thread_utils.cc +++ b/onnxruntime/core/util/thread_utils.cc @@ -16,10 +16,11 @@ namespace onnxruntime { namespace concurrency { +#if !defined(ORT_MINIMAL_BUILD) && !defined(ORT_EXTENDED_MINIMAL_BUILD) // Extract affinity from affinity string. // Processor id from affinity string starts from 1, // but internally, processor id starts from 0, so here we minus the id by 1 -std::vector ReadThreadAffinityConfig(const std::string& affinity_str) { +static std::vector ReadThreadAffinityConfig(const std::string& affinity_str) { ORT_TRY { std::vector logical_processors_vector; auto affinities = utils::SplitString(affinity_str, ";"); @@ -68,6 +69,7 @@ std::vector ReadThreadAffinityConfig(const std::string& affin } ORT_THROW("Failed to read affinities from affinity string"); } +#endif static std::unique_ptr CreateThreadPoolHelper(Env* env, OrtThreadPoolParams options) { @@ -87,6 +89,10 @@ CreateThreadPoolHelper(Env* env, OrtThreadPoolParams options) { } // override affinity setting if specified from customer if (!options.affinity_str.empty()) { +#if defined(ORT_MINIMAL_BUILD) || defined(ORT_EXTENDED_MINIMAL_BUILD) + ORT_THROW("Setting thread affinity is not implemented in this build."); + return nullptr; +#else to.affinities = ReadThreadAffinityConfig(options.affinity_str); // Limiting the number of affinities to be of thread_pool_size - 1, // for the fact that the main thread is a special "member" of the threadpool, @@ -101,6 +107,7 @@ CreateThreadPoolHelper(Env* env, OrtThreadPoolParams options) { // prepend with an empty affinity as placeholder for the main thread, // it will be dropped later during threadpool creation. to.affinities.insert(to.affinities.begin(), LogicalProcessors{}); +#endif } to.set_denormal_as_zero = options.set_denormal_as_zero; @@ -205,6 +212,12 @@ ORT_API_STATUS_IMPL(SetGlobalCustomJoinThreadFn, _Inout_ OrtThreadingOptions* tp } ORT_API_STATUS_IMPL(SetGlobalIntraOpThreadAffinity, _Inout_ OrtThreadingOptions* tp_options, const char* affinity_string) { +#if defined(ORT_MINIMAL_BUILD) || defined(ORT_EXTENDED_MINIMAL_BUILD) + ORT_UNUSED_PARAMETER(tp_options); + ORT_UNUSED_PARAMETER(affinity_string); + return OrtApis::CreateStatus(ORT_NOT_IMPLEMENTED, + "Setting thread affinity is not implemented in this build."); +#else if (!tp_options) { return OrtApis::CreateStatus(ORT_INVALID_ARGUMENT, "Received null OrtThreadingOptions"); } @@ -220,6 +233,7 @@ ORT_API_STATUS_IMPL(SetGlobalIntraOpThreadAffinity, _Inout_ OrtThreadingOptions* } tp_options->intra_op_thread_pool_params.affinity_str = affinity_string; return nullptr; + #endif } } // namespace OrtApis diff --git a/onnxruntime/test/global_thread_pools/test_main.cc b/onnxruntime/test/global_thread_pools/test_main.cc index 86b909e466..6ac2256342 100644 --- a/onnxruntime/test/global_thread_pools/test_main.cc +++ b/onnxruntime/test/global_thread_pools/test_main.cc @@ -94,8 +94,10 @@ int main(int argc, char** argv) { st_ptr.reset(g_ort->SetGlobalIntraOpThreadAffinity(tp_options, long_affinity_str.c_str())); ORT_RETURN_IF_NULL_STATUS(st_ptr); +#if !defined(ORT_MINIMAL_BUILD) && !defined(ORT_EXTENDED_MINIMAL_BUILD) st_ptr.reset(g_ort->SetGlobalIntraOpThreadAffinity(tp_options, affinity_stream.str().c_str())); ORT_RETURN_IF_NON_NULL_STATUS(st_ptr); +#endif st_ptr.reset(g_ort->SetGlobalCustomCreateThreadFn(tp_options, CreateThreadCustomized)); ORT_RETURN_IF_NON_NULL_STATUS(st_ptr); diff --git a/onnxruntime/test/platform/threadpool_test.cc b/onnxruntime/test/platform/threadpool_test.cc index 648926a16c..5c989fe3a8 100644 --- a/onnxruntime/test/platform/threadpool_test.cc +++ b/onnxruntime/test/platform/threadpool_test.cc @@ -544,6 +544,8 @@ TEST(ThreadPoolTest, TestStackSize) { #endif #endif +#if !defined(ORT_MINIMAL_BUILD) && !defined(ORT_EXTENDED_MINIMAL_BUILD) + #ifndef ORT_NO_EXCEPTIONS TEST(ThreadPoolTest, TestAffinityStringMisshaped) { OrtThreadPoolParams tp_params; @@ -667,5 +669,6 @@ TEST(ThreadPoolTest, TestDefaultAffinity) { } } #endif +#endif } // namespace onnxruntime diff --git a/onnxruntime/test/shared_lib/test_model_loading.cc b/onnxruntime/test/shared_lib/test_model_loading.cc index 30f33ac4d1..19609943d4 100644 --- a/onnxruntime/test/shared_lib/test_model_loading.cc +++ b/onnxruntime/test/shared_lib/test_model_loading.cc @@ -56,6 +56,7 @@ TEST(CApiTest, model_from_array) { #endif } +#if !defined(ORT_MINIMAL_BUILD) && !defined(ORT_EXTENDED_MINIMAL_BUILD) TEST(CApiTest, session_options_empty_affinity_string) { Ort::SessionOptions options; options.AddConfigEntry(kOrtSessionOptionsConfigIntraOpThreadAffinities, ""); @@ -68,6 +69,7 @@ TEST(CApiTest, session_options_empty_affinity_string) { ASSERT_THAT(ex.what(), testing::HasSubstr("Affinity string must not be empty")); } } +#endif #endif diff --git a/onnxruntime/test/shared_lib/test_session_options.cc b/onnxruntime/test/shared_lib/test_session_options.cc index 13dc7926f9..d4c1b34991 100644 --- a/onnxruntime/test/shared_lib/test_session_options.cc +++ b/onnxruntime/test/shared_lib/test_session_options.cc @@ -15,7 +15,7 @@ TEST(CApiTest, session_options_graph_optimization_level) { options.SetGraphOptimizationLevel(ORT_ENABLE_EXTENDED); } -#if !defined(ORT_MINIMAL_BUILD) && !defined(ORT_NO_EXCEPTIONS) +#if !defined(ORT_MINIMAL_BUILD) && !defined(ORT_EXTENDED_MINIMAL_BUILD) && !defined(ORT_NO_EXCEPTIONS) TEST(CApiTest, session_options_oversized_affinity_string) { Ort::SessionOptions options;