Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Does the thread pool need at least 2 threads when profiling is enabled? #5734

Open
o7si opened this issue Nov 16, 2024 · 3 comments
Open

Does the thread pool need at least 2 threads when profiling is enabled? #5734

o7si opened this issue Nov 16, 2024 · 3 comments
Assignees
Labels
os:macOS Issues on MacOS platform:c++ Issues specific to C++ framework in mediapipe stat:awaiting googler Waiting for Google Engineer's Response type:bug Bug in the Source Code of MediaPipe Solution

Comments

@o7si
Copy link

o7si commented Nov 16, 2024

Have I written custom code (as opposed to using a stock example script provided in MediaPipe)

None

OS Platform and Distribution

macOS 14.5 (Apple M1)

Mobile device if the issue happens on mobile device

No response

Browser and version if the issue happens on browser

No response

Programming Language and version

C++

MediaPipe version

No response

Bazel version

6.5.0

Solution

HelloWorld

Android Studio, NDK, SDK versions (if issue is related to building in Android environment)

No response

Xcode & Tulsi version (if issue is related to building for iOS)

No response

Describe the actual behavior

When there is only one Calculator and PROFILING is enabled, the Graph does not execute.

Describe the expected behaviour

The Graph should execute normally even when there is only one Calculator and PROFILING is enabled.

Standalone code/steps you may have used to try to get what you need

Detailed steps to reproduce can be found in the main body.

Other info / Complete Logs

No response

@o7si o7si added the type:bug Bug in the Source Code of MediaPipe Solution label Nov 16, 2024
@o7si
Copy link
Author

o7si commented Nov 16, 2024

Bug Description

In the process of using MediaPipe, I found that when only one Calculator is configured in the Graph and the PROFILING function is enabled, the Graph will not be able to process the data stream normally. The specific reason is that since there is only one Calculator configured, the size of the ThreadPool will only be allocated as 1, but the PROFILING function also relies on the thread pool (and is a long-running loop), so when the Graph receives the data stream, there is no thread to schedule the Calculator's Process function.

Reproduction Steps

  1. Modify the mediapipe/examples/desktop/hello_world/hello_world.cc file with the following diff:
    diff --git a/mediapipe/examples/desktop/hello_world/hello_world.cc b/mediapipe/examples/desktop/hello_world/hello_world.cc
    index 50c49d4f..14e779f2 100644
    --- a/mediapipe/examples/desktop/hello_world/hello_world.cc
    +++ b/mediapipe/examples/desktop/hello_world/hello_world.cc
    @@ -26,16 +26,18 @@ absl::Status PrintHelloWorld() {
       // Configures a simple graph, which concatenates 2 PassThroughCalculators.
       CalculatorGraphConfig config =
           ParseTextProtoOrDie<CalculatorGraphConfig>(R"pb(
    +        profiler_config {
    +          trace_enabled: true
    +          enable_profiler: true
    +          trace_log_interval_count: 200
    +          trace_log_path: "./"
    +        }
    +
             input_stream: "in"
             output_stream: "out"
             node {
               calculator: "PassThroughCalculator"
               input_stream: "in"
    -          output_stream: "out1"
    -        }
    -        node {
    -          calculator: "PassThroughCalculator"
    -          input_stream: "out1"
               output_stream: "out"
             }
           )pb");
    
  2. Build and execute using the following commands:
    bazel run --define MEDIAPIPE_PROFILING=1 mediapipe/examples/desktop/hello_world:hello_world
    

Observed Behavior

The following output is observed, indicating that the program failed to execute properly (no threads available for scheduling) as there is no expected “Hello World!” message in the logs:

INFO: Analyzed target //mediapipe/examples/desktop/hello_world:hello_world (0 packages loaded, 0 targets configured).
INFO: Found 1 target...
Target //mediapipe/examples/desktop/hello_world:hello_world up-to-date:
  bazel-bin/mediapipe/examples/desktop/hello_world/hello_world
INFO: Elapsed time: 0.097s, Critical Path: 0.00s
INFO: 1 process: 1 internal.
INFO: Build completed successfully, 1 total action
INFO: Running command line: bazel-bin/mediapipe/examples/desktop/hello_world/hello_world
WARNING: All log messages before absl::InitializeLog() is called are written to STDERR
I0000 00:00:1731757077.208439 32035708 graph_profiler.cc:256] trace_log_path: ./

@o7si
Copy link
Author

o7si commented Nov 16, 2024

Of course, this issue is unlikely to occur under normal circumstances, as projects relying on MediaPipe usually consist of dozens of Calculators, making it highly improbable to have only one. I attempted to fix this issue; see: #5735 for details.

Additionally, I am not particularly familiar with MediaPipe’s implementation, so the root cause I identified might be incorrect. Please pardon any inaccuracies.

@kuaashish kuaashish added os:macOS Issues on MacOS platform:c++ Issues specific to C++ framework in mediapipe labels Nov 18, 2024
@kuaashish
Copy link
Collaborator

Hi @schmidt-sebastian,

Could you please look into this issue? The relevant PR is available here #5735.

Thank you!!

@kuaashish kuaashish added the stat:awaiting googler Waiting for Google Engineer's Response label Nov 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
os:macOS Issues on MacOS platform:c++ Issues specific to C++ framework in mediapipe stat:awaiting googler Waiting for Google Engineer's Response type:bug Bug in the Source Code of MediaPipe Solution
Projects
None yet
Development

No branches or pull requests

3 participants