• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* Copyright 2022 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_HLO_PROTO_TO_GRAPH_VIEW_H_
17 #define TENSORFLOW_CORE_PROFILER_CONVERT_HLO_PROTO_TO_GRAPH_VIEW_H_
18 
19 #include <string>
20 #include <string_view>
21 #include <vector>
22 
23 #include "tensorflow/compiler/xla/service/hlo.pb.h"
24 #include "tensorflow/compiler/xla/service/hlo_graph_dumper.h"
25 #include "tensorflow/core/platform/statusor.h"
26 #include "tensorflow/core/profiler/convert/tool_options.h"
27 
28 namespace tensorflow {
29 namespace profiler {
30 
31 // All the parameters for graph viewer.
32 struct GraphViewerParams {
33   // Whether to use GraphView or TxtView.
34   std::string type;
35   // Parameters for GraphView.
36   std::string node_name;
37   int graph_width;
38   xla::HloRenderOptions render_options;
39   xla::RenderedGraphFormat format;
40   // Parameters for TxtView.
41   bool verbose;
42   bool show_metadata;
43 };
44 
45 // Parse tool options to get the parameters for graph viewer.
46 StatusOr<GraphViewerParams> ParseGraphViewerParams(const ToolOptions& options);
47 
48 // Get graph render format.
49 xla::RenderedGraphFormat GetRenderFormat(const std::string& format_string);
50 
51 // Convert `hlo_proto` to GraphView with the provided render options.
52 tensorflow::StatusOr<std::string> ConvertHloProtoToGraph(
53     const xla::HloProto& hlo_proto, const std::string& node_name,
54     int graph_width, const xla::HloRenderOptions& render_options,
55     const xla::RenderedGraphFormat& format);
56 
57 // Convert `hlo_proto` to StringView.
58 tensorflow::StatusOr<std::string> ConvertHloProtoToStringView(
59     const xla::HloProto& hlo_proto, bool verbose, bool metadata);
60 
61 }  // namespace profiler
62 }  // namespace tensorflow
63 
64 #endif  // TENSORFLOW_CORE_PROFILER_CONVERT_HLO_PROTO_TO_GRAPH_VIEW_H_
65