Skip to content

Commit 5560e04

Browse files
jywu-msftgithub-actions[bot]
authored andcommitted
add --client_package_build option (#25351)
add a build option to enable default options more appropriate for client/on-device workloads. initial use case will be to set the default thread pool allow_spinning policy , which we want to default to 0/false for builds targeted for client/on-device workloads. --------- Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
1 parent d175b6c commit 5560e04

File tree

9 files changed

+40
-3
lines changed

9 files changed

+40
-3
lines changed

cmake/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,7 @@ option(onnxruntime_DISABLE_SPARSE_TENSORS "Disable sparse tensors data types" OF
150150
option(onnxruntime_DISABLE_OPTIONAL_TYPE "Disable optional type" OFF)
151151
option(onnxruntime_DISABLE_FLOAT8_TYPES "Disable float 8 types" OFF)
152152
option(onnxruntime_MINIMAL_BUILD "Exclude as much as possible from the build. Support ORT format models. No support for ONNX format models." OFF)
153+
option(onnxruntime_CLIENT_PACKAGE_BUILD "Enables default settings that are more appropriate for client/on-device workloads." OFF)
153154
cmake_dependent_option(onnxruntime_DISABLE_RTTI "Disable RTTI" ON "NOT onnxruntime_ENABLE_PYTHON;NOT onnxruntime_USE_CUDA" OFF)
154155
# For now onnxruntime_DISABLE_EXCEPTIONS will only work with onnxruntime_MINIMAL_BUILD, more changes (ONNX, non-CPU EP, ...) are required to run this standalone
155156
cmake_dependent_option(onnxruntime_DISABLE_EXCEPTIONS "Disable exception handling. Requires onnxruntime_MINIMAL_BUILD currently." ON "onnxruntime_MINIMAL_BUILD;NOT onnxruntime_ENABLE_PYTHON" OFF)

cmake/adjust_global_compile_flags.cmake

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,11 @@ if (onnxruntime_MINIMAL_BUILD)
9898
endif()
9999
endif()
100100

101+
# ORT build with default settings more appropriate for client/on-device workloads.
102+
if (onnxruntime_CLIENT_PACKAGE_BUILD)
103+
add_compile_definitions(ORT_CLIENT_PACKAGE_BUILD)
104+
endif()
105+
101106
if (onnxruntime_ENABLE_LTO)
102107
include(CheckIPOSupported)
103108
check_ipo_supported(RESULT ipo_enabled OUTPUT ipo_output)

include/onnxruntime/core/session/onnxruntime_session_options_config_keys.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,9 @@ static const char* const kOrtSessionOptionsUseDeviceAllocatorForInitializers = "
113113

114114
// Configure whether to allow the inter_op/intra_op threads spinning a number of times before blocking
115115
// "0": thread will block if found no job to run
116-
// "1": default, thread will spin a number of times before blocking
116+
// "1": thread will spin a number of times before blocking
117+
// The default is "0" when ORT is built with "ORT_CLIENT_PACKAGE_BUILD" and "1" otherwise.
118+
// Thread spinning is disabled by default for client/on-device workloads to reduce cpu utilization and improve power efficiency.
117119
static const char* const kOrtSessionOptionsConfigAllowInterOpSpinning = "session.inter_op.allow_spinning";
118120
static const char* const kOrtSessionOptionsConfigAllowIntraOpSpinning = "session.intra_op.allow_spinning";
119121

onnxruntime/core/session/inference_session.cc

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -423,7 +423,13 @@ void InferenceSession::ConstructorCommon(const SessionOptions& session_options,
423423
{
424424
if (!external_intra_op_thread_pool_) {
425425
bool allow_intra_op_spinning =
426+
#if !defined(ORT_CLIENT_PACKAGE_BUILD)
426427
session_options_.config_options.GetConfigOrDefault(kOrtSessionOptionsConfigAllowIntraOpSpinning, "1") == "1";
428+
#else
429+
// default KOrtSessionOptionsConfigAllowIntraOpSpinning to "0" for ORT builds targeting client/on-device workloads,
430+
// to reduce CPU utilization and improve power efficiency.
431+
session_options_.config_options.GetConfigOrDefault(kOrtSessionOptionsConfigAllowIntraOpSpinning, "0") == "1";
432+
#endif
427433
OrtThreadPoolParams to = session_options_.intra_op_param;
428434
std::basic_stringstream<ORTCHAR_T> ss;
429435
if (to.name) {
@@ -461,7 +467,13 @@ void InferenceSession::ConstructorCommon(const SessionOptions& session_options,
461467
if (session_options_.execution_mode == ExecutionMode::ORT_PARALLEL) {
462468
if (!external_inter_op_thread_pool_) {
463469
bool allow_inter_op_spinning =
470+
#if !defined(ORT_CLIENT_PACKAGE_BUILD)
464471
session_options_.config_options.GetConfigOrDefault(kOrtSessionOptionsConfigAllowInterOpSpinning, "1") == "1";
472+
#else
473+
// default kOrtSessionOptionsConfigAllowInterOpSpinning to "0" for ORT builds targeting client/on-device workloads,
474+
// to reduce CPU utilization and improve power efficiency.
475+
session_options_.config_options.GetConfigOrDefault(kOrtSessionOptionsConfigAllowInterOpSpinning, "0") == "1";
476+
#endif
465477
OrtThreadPoolParams to = session_options_.inter_op_param;
466478
to.auto_set_affinity = to.thread_pool_size == 0 && session_options_.execution_mode == ExecutionMode::ORT_SEQUENTIAL;
467479
std::basic_stringstream<ORTCHAR_T> ss;

onnxruntime/core/util/thread_utils.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,13 @@ struct OrtThreadPoolParams {
1919
bool auto_set_affinity = false;
2020

2121
// If it is true, the thread pool will spin a while after the queue became empty.
22+
#if !defined(ORT_CLIENT_PACKAGE_BUILD)
2223
bool allow_spinning = true;
24+
#else
25+
// default allow_spinning to false for ORT builds targeting client/on-device workloads,
26+
// to reduce CPU utilization and improve power efficiency.
27+
bool allow_spinning = false;
28+
#endif
2329

2430
// It it is non-negative, thread pool will split a task by a decreasing block size
2531
// of remaining_of_total_iterations / (num_of_threads * dynamic_block_base_)

tools/ci_build/build.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -461,6 +461,7 @@ def generate_build_tree(
461461
else "OFF"
462462
),
463463
"-Donnxruntime_REDUCED_OPS_BUILD=" + ("ON" if is_reduced_ops_build(args) else "OFF"),
464+
"-Donnxruntime_CLIENT_PACKAGE_BUILD=" + ("ON" if args.client_package_build else "OFF"),
464465
"-Donnxruntime_BUILD_MS_EXPERIMENTAL_OPS=" + ("ON" if args.ms_experimental else "OFF"),
465466
"-Donnxruntime_ENABLE_LTO=" + ("ON" if args.enable_lto else "OFF"),
466467
"-Donnxruntime_USE_ACL=" + ("ON" if args.use_acl else "OFF"),

tools/ci_build/build_args.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -527,6 +527,15 @@ def add_size_reduction_args(parser: argparse.ArgumentParser) -> None:
527527
)
528528

529529

530+
def add_client_package_args(parser: argparse.ArgumentParser) -> None:
531+
"""Adds arguments for client package build package."""
532+
parser.add_argument(
533+
"--client_package_build",
534+
action="store_true",
535+
help="Create ORT package with default settings more appropriate for client/on-device workloads.",
536+
)
537+
538+
530539
def add_python_binding_args(parser: argparse.ArgumentParser) -> None:
531540
"""Adds arguments for Python bindings."""
532541
parser.add_argument("--enable_pybind", action="store_true", help="Enable Python bindings.")
@@ -835,6 +844,7 @@ def convert_arg_line_to_args(self, arg_line: str) -> list[str]: # Use list[str]
835844
add_dependency_args(parser)
836845
add_extension_args(parser)
837846
add_size_reduction_args(parser)
847+
add_client_package_args(parser)
838848

839849
# Language Bindings
840850
add_python_binding_args(parser)

tools/ci_build/github/azure-pipelines/templates/qnn-ep-win.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ stages:
2020
name: ${{ parameters.qnn_ep_build_pool_name }}
2121
variables:
2222
OrtPackageId: ${{ parameters.OrtNugetPackageId }}
23-
commonBuildArgs: '--compile_no_warning_as_error --skip_submodule_sync --build_shared_lib --cmake_generator "Visual Studio 17 2022" --config ${{ parameters.build_config }} --parallel --use_vcpkg --use_vcpkg_ms_internal_asset_cache --use_binskim_compliant_compile_flags '
23+
commonBuildArgs: '--compile_no_warning_as_error --skip_submodule_sync --build_shared_lib --client_package_build --cmake_generator "Visual Studio 17 2022" --config ${{ parameters.build_config }} --parallel --use_vcpkg --use_vcpkg_ms_internal_asset_cache --use_binskim_compliant_compile_flags '
2424

2525
steps:
2626
- template: set-version-number-variables-step.yml

tools/ci_build/github/azure-pipelines/win-qnn-arm64-ci-pipeline.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ jobs:
5050
matrix:
5151
SHARED_LIB:
5252
QnnLibKind: 'shared_lib'
53-
ExtraQnnBuildArgs: ''
53+
ExtraQnnBuildArgs: '--client_package_build'
5454
STATIC_LIB:
5555
QnnLibKind: 'static_lib'
5656
ExtraQnnBuildArgs: ''

0 commit comments

Comments
 (0)