xref: /aosp_15_r20/external/tensorflow/tensorflow/core/profiler/convert/op_stats_to_overview_page.h (revision b6fb3261f9314811a0f4371741dbb8839866f948)
1 /* Copyright 2020 The TensorFlow Authors. All Rights Reserved.
2 
3 Licensed under the Apache License, Version 2.0 (the "License");
4 you may not use this file except in compliance with the License.
5 You may obtain a copy of the License at
6 
7     http://www.apache.org/licenses/LICENSE-2.0
8 
9 Unless required by applicable law or agreed to in writing, software
10 distributed under the License is distributed on an "AS IS" BASIS,
11 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 See the License for the specific language governing permissions and
13 limitations under the License.
14 ==============================================================================*/
15 
16 #ifndef TENSORFLOW_CORE_PROFILER_CONVERT_OP_STATS_TO_OVERVIEW_PAGE_H_
17 #define TENSORFLOW_CORE_PROFILER_CONVERT_OP_STATS_TO_OVERVIEW_PAGE_H_
18 
19 #include "absl/strings/string_view.h"
20 #include "tensorflow/core/platform/types.h"
21 #include "tensorflow/core/profiler/protobuf/hardware_types.pb.h"
22 #include "tensorflow/core/profiler/protobuf/input_pipeline.pb.h"
23 #include "tensorflow/core/profiler/protobuf/op_metrics.pb.h"
24 #include "tensorflow/core/profiler/protobuf/op_stats.pb.h"
25 #include "tensorflow/core/profiler/protobuf/overview_page.pb.h"
26 #include "tensorflow/core/profiler/protobuf/xplane.pb.h"
27 
28 namespace tensorflow {
29 namespace profiler {
30 
31 // Reports tf-function optimization opportunity in the Overview Page if the
32 // expensive-call-time percentage is over this threshold for at least one of
33 // the tf-functions profiled.
34 const double kTfFunctionReportThresholdInPercent = 20;
35 
36 // Reports eager-mode optimization opportunity in the Overview Page if the
37 // percent of Op time on host (or device) that is spent on eager mode is over
38 // this threshold.
39 const double kEagerReportThresholdInPercent = 10;
40 
41 // Reports outside-compilation opportunity in the Overview Page if the
42 // percent of Op time on device that is for outside compilation is over
43 // this threshold.
44 const double kOutsideCompilationThresholdInPercent = 5;
45 
46 void SetCommonRecommendation(
47     absl::string_view input_classification, absl::string_view input_statement,
48     absl::string_view output_statement, HardwareType hardware_type,
49     absl::string_view tf_function_statement_html,
50     absl::string_view eager_statement_html,
51     absl::string_view outside_compilation_statement_html,
52     OverviewPageRecommendation* re);
53 
54 OverviewPageRecommendation ComputeGenericRecommendation(
55     const BottleneckAnalysis& bottleneck,
56     const PrecisionStats& precision_stats);
57 
58 OverviewPageAnalysis ComputeAnalysisResult(const OpStats& op_stats);
59 
60 OverviewPageRunEnvironment ComputeRunEnvironment(
61     const RunEnvironment& run_environment);
62 
63 OverviewPage ConvertOpStatsToOverviewPage(const OpStats& op_stats);
64 
65 // Returns a html which provides tf-function related recommendation.
66 std::string TfFunctionRecommendationHtml(const TfFunctionDb& tf_function_db);
67 
68 // Returns a html which provides eager-mode related recommendation.
69 std::string EagerRecommendationHtml(double host_op_time_eager_percent,
70                                     double device_op_time_eager_percent);
71 
72 // Returns a html which provides outside-compilation related recommendation.
73 std::string OutsideCompilationRecommendationHtml(
74     double device_op_time_outside_compilation_percent);
75 
76 }  // namespace profiler
77 }  // namespace tensorflow
78 
79 #endif  // TENSORFLOW_CORE_PROFILER_CONVERT_OP_STATS_TO_OVERVIEW_PAGE_H_
80