diff --git a/mediapipe/calculators/tensor/BUILD b/mediapipe/calculators/tensor/BUILD index a966dd3fc..8246228b5 100644 --- a/mediapipe/calculators/tensor/BUILD +++ b/mediapipe/calculators/tensor/BUILD @@ -530,6 +530,7 @@ cc_library( }), visibility = ["//visibility:public"], deps = [ + "//mediapipe/framework:calculator_context", "//mediapipe/framework/formats:tensor", "@com_google_absl//absl/status:statusor", ], @@ -550,6 +551,7 @@ cc_library( visibility = ["//visibility:public"], deps = [ ":inference_runner", + "//mediapipe/framework:mediapipe_profiling", "//mediapipe/framework/api2:packet", "//mediapipe/framework/formats:tensor", "//mediapipe/framework/port:ret_check", diff --git a/mediapipe/calculators/tensor/inference_calculator_cpu.cc b/mediapipe/calculators/tensor/inference_calculator_cpu.cc index 2e90c7cc9..79df97638 100644 --- a/mediapipe/calculators/tensor/inference_calculator_cpu.cc +++ b/mediapipe/calculators/tensor/inference_calculator_cpu.cc @@ -72,7 +72,7 @@ absl::Status InferenceCalculatorCpuImpl::Process(CalculatorContext* cc) { RET_CHECK(!input_tensors.empty()); ASSIGN_OR_RETURN(std::vector output_tensors, - inference_runner_->Run(input_tensors)); + inference_runner_->Run(cc, input_tensors)); kOutTensors(cc).Send(std::move(output_tensors)); return absl::OkStatus(); } diff --git a/mediapipe/calculators/tensor/inference_calculator_xnnpack.cc b/mediapipe/calculators/tensor/inference_calculator_xnnpack.cc index 384c753ff..a9417d508 100644 --- a/mediapipe/calculators/tensor/inference_calculator_xnnpack.cc +++ b/mediapipe/calculators/tensor/inference_calculator_xnnpack.cc @@ -70,7 +70,7 @@ absl::Status InferenceCalculatorXnnpackImpl::Process(CalculatorContext* cc) { RET_CHECK(!input_tensors.empty()); ASSIGN_OR_RETURN(std::vector output_tensors, - inference_runner_->Run(input_tensors)); + inference_runner_->Run(cc, input_tensors)); kOutTensors(cc).Send(std::move(output_tensors)); return absl::OkStatus(); } diff --git a/mediapipe/calculators/tensor/inference_interpreter_delegate_runner.cc b/mediapipe/calculators/tensor/inference_interpreter_delegate_runner.cc index 1d216daf3..9ef4e822c 100644 --- a/mediapipe/calculators/tensor/inference_interpreter_delegate_runner.cc +++ b/mediapipe/calculators/tensor/inference_interpreter_delegate_runner.cc @@ -20,12 +20,15 @@ #include "absl/status/status.h" #include "absl/status/statusor.h" #include "mediapipe/framework/formats/tensor.h" +#include "mediapipe/framework/mediapipe_profiling.h" #include "mediapipe/framework/port/ret_check.h" #include "tensorflow/lite/c/c_api_types.h" #include "tensorflow/lite/interpreter.h" #include "tensorflow/lite/interpreter_builder.h" #include "tensorflow/lite/string_util.h" +#define PERFETTO_TRACK_EVENT_NAMESPACE mediapipe + namespace mediapipe { namespace { @@ -79,7 +82,7 @@ class InferenceInterpreterDelegateRunner : public InferenceRunner { delegate_(std::move(delegate)) {} absl::StatusOr> Run( - const std::vector& input_tensors) override; + CalculatorContext* cc, const std::vector& input_tensors) override; private: api2::Packet model_; @@ -88,7 +91,7 @@ class InferenceInterpreterDelegateRunner : public InferenceRunner { }; absl::StatusOr> InferenceInterpreterDelegateRunner::Run( - const std::vector& input_tensors) { + CalculatorContext* cc, const std::vector& input_tensors) { // Read CPU input into tensors. RET_CHECK_EQ(interpreter_->inputs().size(), input_tensors.size()); for (int i = 0; i < input_tensors.size(); ++i) { @@ -131,8 +134,10 @@ absl::StatusOr> InferenceInterpreterDelegateRunner::Run( } // Run inference. - RET_CHECK_EQ(interpreter_->Invoke(), kTfLiteOk); - + { + MEDIAPIPE_PROFILING(CPU_TASK_INVOKE, cc); + RET_CHECK_EQ(interpreter_->Invoke(), kTfLiteOk); + } // Output result tensors (CPU). const auto& tensor_indexes = interpreter_->outputs(); std::vector output_tensors; diff --git a/mediapipe/calculators/tensor/inference_runner.h b/mediapipe/calculators/tensor/inference_runner.h index ec9d17b8b..2283a6c19 100644 --- a/mediapipe/calculators/tensor/inference_runner.h +++ b/mediapipe/calculators/tensor/inference_runner.h @@ -2,6 +2,7 @@ #define MEDIAPIPE_CALCULATORS_TENSOR_INFERENCE_RUNNER_H_ #include "absl/status/statusor.h" +#include "mediapipe/framework/calculator_context.h" #include "mediapipe/framework/formats/tensor.h" namespace mediapipe { @@ -11,7 +12,7 @@ class InferenceRunner { public: virtual ~InferenceRunner() = default; virtual absl::StatusOr> Run( - const std::vector& inputs) = 0; + CalculatorContext* cc, const std::vector& inputs) = 0; }; } // namespace mediapipe diff --git a/mediapipe/framework/calculator_profile.proto b/mediapipe/framework/calculator_profile.proto index 1512da6af..082d0a869 100644 --- a/mediapipe/framework/calculator_profile.proto +++ b/mediapipe/framework/calculator_profile.proto @@ -135,6 +135,7 @@ message GraphTrace { PACKET_QUEUED = 15; GPU_TASK_INVOKE = 16; TPU_TASK_INVOKE = 17; + CPU_TASK_INVOKE = 18; } // //depot/mediapipe/framework/mediapipe_profiling.h:profiler_census_tags, // //depot/mediapipe/framework/profiler/trace_buffer.h:event_type_list, diff --git a/mediapipe/framework/profiler/trace_buffer.h b/mediapipe/framework/profiler/trace_buffer.h index 60352c705..9ad4314fd 100644 --- a/mediapipe/framework/profiler/trace_buffer.h +++ b/mediapipe/framework/profiler/trace_buffer.h @@ -111,6 +111,8 @@ struct TraceEvent { static constexpr EventType PACKET_QUEUED = GraphTrace::PACKET_QUEUED; 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; + // //depot/mediapipe/framework/mediapipe_profiling.h:profiler_census_tags, // //depot/mediapipe/framework/calculator_profile.proto:event_type, // )