mirror of
https://github.com/saymrwulf/onnxruntime.git
synced 2026-05-17 21:10:43 +00:00
Exclude affinity-setting logic from minimal build (#13967)
Comment out the affinity-setting logic which introduced an unnecessary binary size increase for the minimal build. Co-authored-by: Randy Shuai <rashuai@microsoft.com>
This commit is contained in:
parent
0ee5a5f229
commit
a061fedb5d
5 changed files with 23 additions and 2 deletions
|
|
@ -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<LogicalProcessors> ReadThreadAffinityConfig(const std::string& affinity_str) {
|
||||
static std::vector<LogicalProcessors> ReadThreadAffinityConfig(const std::string& affinity_str) {
|
||||
ORT_TRY {
|
||||
std::vector<LogicalProcessors> logical_processors_vector;
|
||||
auto affinities = utils::SplitString(affinity_str, ";");
|
||||
|
|
@ -68,6 +69,7 @@ std::vector<LogicalProcessors> ReadThreadAffinityConfig(const std::string& affin
|
|||
}
|
||||
ORT_THROW("Failed to read affinities from affinity string");
|
||||
}
|
||||
#endif
|
||||
|
||||
static std::unique_ptr<ThreadPool>
|
||||
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
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
Loading…
Reference in a new issue