Skip to content

Expose CPU inference thread count via BaseOptions.num_threads - #6322

Open
velonica0 wants to merge 1 commit into
google-ai-edge:masterfrom
velonica0:expose-cpu-num-threads
Open

Expose CPU inference thread count via BaseOptions.num_threads#6322
velonica0 wants to merge 1 commit into
google-ai-edge:masterfrom
velonica0:expose-cpu-num-threads

Conversation

@velonica0

Copy link
Copy Markdown

Close #3644 #6151

Description:

MediaPipe Tasks CPU inference runs single-threaded on non-mobile platforms with no way to change it from the public API. This adds a num_threads field to BaseOptions across the Python, C, and C++ layers. When set (> 0) with the CPU delegate, it emits an XNNPACK delegate with that thread count; unset keeps the current single-threaded default, so existing behavior is unchanged.

Changed

base_options.py, base_options_c.py, c/core/base_options.h, base_options_converter.cc, cc/core/base_options.h, base_options.cc, and base_options_test.cc (unit tests for the new field).

Testing:

Base_options_test passes; a real-model run confirmed output is bit-identical across 1/2/4 threads.

Related issues:

Adds a num_threads field to BaseOptions (Python/C/C++) that sets the XNNPACK
delegate thread count for CPU inference; unset keeps the current
single-threaded default.
@velonica0

Copy link
Copy Markdown
Author

Hi, @HarishPermal
Could you help me review this PR? Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

How to set xnnpack num_threads in mediapipe python?

1 participant