From a9e956baa1e87da838b2e237faf03e44913623e0 Mon Sep 17 00:00:00 2001 From: MediaPipe Team Date: Thu, 16 Mar 2023 10:35:07 -0700 Subject: [PATCH] Add more details to the invoke call trace. It is always useful information to know if the TPU invoke is Async or not, and if the GPU invoke on the old path or new path. This can make it obvious in the perfetto trace. PiperOrigin-RevId: 517162515 --- .../tensor/inference_calculator_gl_advanced.cc | 2 +- mediapipe/framework/calculator_profile.proto | 2 ++ mediapipe/framework/profiler/trace_buffer.h | 4 ++++ mediapipe/framework/profiler/trace_builder.cc | 10 +++++++++- 4 files changed, 16 insertions(+), 2 deletions(-) diff --git a/mediapipe/calculators/tensor/inference_calculator_gl_advanced.cc b/mediapipe/calculators/tensor/inference_calculator_gl_advanced.cc index 8fd55efa7..8aee46185 100644 --- a/mediapipe/calculators/tensor/inference_calculator_gl_advanced.cc +++ b/mediapipe/calculators/tensor/inference_calculator_gl_advanced.cc @@ -141,7 +141,7 @@ InferenceCalculatorGlAdvancedImpl::GpuInferenceRunner::Process( } // Run inference. { - MEDIAPIPE_PROFILING(GPU_TASK_INVOKE, cc); + MEDIAPIPE_PROFILING(GPU_TASK_INVOKE_ADVANCED, cc); return tflite_gpu_runner_->Invoke(); } })); diff --git a/mediapipe/framework/calculator_profile.proto b/mediapipe/framework/calculator_profile.proto index d86162ea5..0b5498c4e 100644 --- a/mediapipe/framework/calculator_profile.proto +++ b/mediapipe/framework/calculator_profile.proto @@ -136,6 +136,8 @@ message GraphTrace { GPU_TASK_INVOKE = 16; TPU_TASK_INVOKE = 17; CPU_TASK_INVOKE = 18; + GPU_TASK_INVOKE_ADVANCED = 19; + TPU_TASK_INVOKE_ASYNC = 20; } // The timing for one packet set being processed at one caclulator node. diff --git a/mediapipe/framework/profiler/trace_buffer.h b/mediapipe/framework/profiler/trace_buffer.h index b44d8f0bf..b5e2d9994 100644 --- a/mediapipe/framework/profiler/trace_buffer.h +++ b/mediapipe/framework/profiler/trace_buffer.h @@ -112,6 +112,10 @@ struct TraceEvent { static constexpr EventType GPU_TASK_INVOKE = GraphTrace::GPU_TASK_INVOKE; static constexpr EventType TPU_TASK_INVOKE = GraphTrace::TPU_TASK_INVOKE; static constexpr EventType CPU_TASK_INVOKE = GraphTrace::CPU_TASK_INVOKE; + static constexpr EventType GPU_TASK_INVOKE_ADVANCED = + GraphTrace::GPU_TASK_INVOKE_ADVANCED; + static constexpr EventType TPU_TASK_INVOKE_ASYNC = + GraphTrace::TPU_TASK_INVOKE_ASYNC; }; // Packet trace log buffer. diff --git a/mediapipe/framework/profiler/trace_builder.cc b/mediapipe/framework/profiler/trace_builder.cc index ce5bf1e25..9c3661ffe 100644 --- a/mediapipe/framework/profiler/trace_builder.cc +++ b/mediapipe/framework/profiler/trace_builder.cc @@ -57,7 +57,6 @@ struct hash { namespace mediapipe { namespace { - void BasicTraceEventTypes(TraceEventRegistry* result) { // The initializer arguments below are: event_type, description, // is_packet_event, is_stream_event, id_event_data. @@ -84,6 +83,15 @@ void BasicTraceEventTypes(TraceEventRegistry* result) { "A time measured by GPU clock and by CPU clock.", true, false}, {TraceEvent::PACKET_QUEUED, "An input queue size when a packet arrives.", true, true, false}, + + {TraceEvent::GPU_TASK_INVOKE, "CPU timing for initiating a GPU task."}, + {TraceEvent::TPU_TASK_INVOKE, "CPU timing for initiating a TPU task."}, + {TraceEvent::CPU_TASK_INVOKE, "CPU timing for initiating a CPU task."}, + {TraceEvent::GPU_TASK_INVOKE_ADVANCED, + "CPU timing for initiating a GPU task bypassing the TFLite " + "interpreter."}, + {TraceEvent::TPU_TASK_INVOKE_ASYNC, + "CPU timing for async initiation of a TPU task."}, }; for (const TraceEventType& t : basic_types) { (*result)[t.event_type()] = t;