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 
27 namespace tensorflow {
28 namespace profiler {
29 
30 // Reports tf-function optimization opportunity in the Overview Page if the
31 // expensive-call-time percentage is over this threshold for at least one of
32 // the tf-functions profiled.
33 const double kTfFunctionReportThresholdInPercent = 20;
34 
35 // Reports eager-mode optimization opportunity in the Overview Page if the
36 // percent of Op time on host (or device) that is spent on eager mode is over
37 // this threshold.
38 const double kEagerReportThresholdInPercent = 10;
39 
40 // Reports outside-compilation opportunity in the Overview Page if the
41 // percent of Op time on device that is for outside compilation is over
42 // this threshold.
43 const double kOutsideCompilationThresholdInPercent = 5;
44 
45 void SetCommonRecommendation(
46     absl::string_view input_classification, absl::string_view input_statement,
47     absl::string_view output_statement, HardwareType hardware_type,
48     absl::string_view tf_function_statement_html,
49     absl::string_view eager_statement_html,
50     absl::string_view outside_compilation_statement_html,
51     OverviewPageRecommendation* re);
52 
53 OverviewPageRecommendation ComputeGenericRecommendation(
54     const BottleneckAnalysis& bottleneck,
55     const PrecisionStats& precision_stats);
56 
57 OverviewPageAnalysis ComputeAnalysisResult(const OpStats& op_stats);
58 
59 OverviewPageRunEnvironment ComputeRunEnvironment(
60     const RunEnvironment& run_environment);
61 
62 OverviewPage ConvertOpStatsToOverviewPage(const OpStats& op_stats);
63 
64 // Returns a html which provides tf-function related recommendation.
65 std::string TfFunctionRecommendationHtml(const TfFunctionDb& tf_function_db);
66 
67 // Returns a html which provides eager-mode related recommendation.
68 std::string EagerRecommendationHtml(double host_op_time_eager_percent,
69                                     double device_op_time_eager_percent);
70 
71 // Returns a html which provides outside-compilation related recommendation.
72 std::string OutsideCompilationRecommendationHtml(
73     double device_op_time_outside_compilation_percent);
74 
75 }  // namespace profiler
76 }  // namespace tensorflow
77 
78 #endif  // TENSORFLOW_CORE_PROFILER_CONVERT_OP_STATS_TO_OVERVIEW_PAGE_H_
79