accel: Add configurable ORT intra-op thread count.#64
Open
andrewleech wants to merge 2 commits intocjpais:mainfrom
Open
accel: Add configurable ORT intra-op thread count.#64andrewleech wants to merge 2 commits intocjpais:mainfrom
andrewleech wants to merge 2 commits intocjpais:mainfrom
Conversation
Global atomic setting (set_ort_intra_threads / get_ort_intra_threads) that build_session and create_decoder_session read when no explicit thread count is provided. 0 = ORT default (all cores). Allows host applications to tune thread count for optimal performance.
3a95cb2 to
dc103f9
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
ORT defaults to using all available CPU cores for intra-op parallelism, but this isn't always optimal — on some machines (particularly those with SMT/hyperthreading), fewer threads gives better throughput for autoregressive decoding workloads. There was no way for host applications to override this.
I added a global atomic setting (
set_ort_intra_threads/get_ort_intra_threads) thatbuild_sessionreads when no explicit thread count is provided. This follows the same pattern as the existingset_ort_accelerator— a process-wide preference set once at startup.The setting applies to all sessions created via
create_session(). Sessions created viacreate_session_with_threads()(used by Moonshine streaming) still take their explicit parameter.create_decoder_session()has its own thread management for sequential autoregressive decode and is not affected.Also added
set_decoder_gpu/get_decoder_gpufor controlling whether decoder sessions use GPU execution providers (useful for benchmarking GPU vs CPU decode).Used by Handy PR #1120 which adds a user-facing thread count setting with auto-tune benchmark.
Testing
accel.rspass (including 2 new round-trip tests for the thread count get/set)AccelGuardtest helper updated to restoreORT_INTRA_THREADSon dropTrade-offs and Alternatives
The alternative was a per-session parameter threaded through every
Model::load()call, but that would require API changes across all engines. The global atomic matches the existing accelerator pattern and lets host apps set it once without modifying engine-specific code. The downside is it's process-wide — you can't have different thread counts for different models loaded simultaneously. In practice this isn't a real limitation since Handy loads one model at a time.