• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* Copyright 2019 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_COMPILER_XLA_SERVICE_DUMP_H_
17 #define TENSORFLOW_COMPILER_XLA_SERVICE_DUMP_H_
18 
19 #include "absl/strings/string_view.h"
20 #include "tensorflow/compiler/xla/service/hlo_module.h"
21 #include "tensorflow/compiler/xla/status.h"
22 #include "tensorflow/compiler/xla/xla.pb.h"
23 
24 // Consolidated utilities for logging information during compilation, usually
25 // based on the options specified in the DebugOptions proto.
26 //
27 // Most functions here take an HloModule and read the DebugOptions from the
28 // module's config.
29 
30 namespace xla {
31 
32 class BufferAssignment;
33 class HloExecutionProfile;
34 class HloSnapshot;
35 
36 // Writes the given string to a file in the xla_dump_to directory specified by
37 // module's DebugOptions.
38 //
39 // If module doesn't have an xla_dump_to directory, does nothing.
40 void DumpToFileInDir(const HloModule& module, absl::string_view file_suffix,
41                      absl::string_view contents);
42 
43 // Like DumpToFileInDir, except if module doesn't have an xla_dump_to directory
44 // specified, or if that directory is equal to "-", writes to stdout instead.
45 void DumpToFileInDirOrStdout(const HloModule& module,
46                              absl::string_view file_suffix,
47                              absl::string_view contents);
48 
49 // Dumps the given HLO module if dumping is enabled for the module.  Exactly
50 // where and in what formats it's dumped is determined by the module's config.
51 //
52 // If you pass an HloExecutionProfile, note that currently only DOT-based output
53 // formats (i.e. --xla_dump_as_{dot,html,url}) are able to incorporate it into
54 // their output.  Other formats will just ignore the profile.
55 void DumpHloModuleIfEnabled(const HloModule& module, absl::string_view name);
56 void DumpHloModuleIfEnabled(const HloModule& module,
57                             const BufferAssignment& buffer_assn,
58                             absl::string_view name);
59 void DumpHloModuleIfEnabled(const HloModule& module,
60                             const HloExecutionProfile& profile,
61                             absl::string_view name);
62 
63 // Dumps the given HLO module after running one HLO pass and before running
64 // another, if that's enabled.
65 void DumpHloModuleBetweenPassesIfEnabled(absl::string_view pipeline_name,
66                                          absl::string_view before_pass_name,
67                                          absl::string_view after_pass_name,
68                                          const HloModule& module);
69 
70 // Dumps the given HLO module during the given HLO pass, if that's enabled.
71 //
72 // "step" is a human-readable description of where we are in the middle of this
73 // pass.  For example, "before-assigning-layouts".
74 void DumpHloModuleDuringPassIfEnabled(absl::string_view pass_name,
75                                       absl::string_view step,
76                                       const HloModule& module);
77 
78 // Dumps the given HloSnapshot to the module's xla_dump_dir, if this is enabled.
79 //
80 // Prefer the first overload below, as this will give filenames that are
81 // consistent with the other methods here.  The second overload (which doesn't
82 // take an HloModule) is useful in the cases when you're dumping an HloSnapshot
83 // and simply don't have an HloModule.
84 void DumpHloSnapshotIfEnabled(const HloModule& module,
85                               const HloSnapshot& snapshot);
86 void DumpHloSnapshotIfEnabled(const HloSnapshot& snapshot,
87                               const DebugOptions& opts);
88 
89 // Returns true if we should dump data for an HloModule.  This is useful if you
90 // want to check if DumpToFileInDir{,OrStdout} will do anything before
91 // generating an expensive string.
92 bool DumpingEnabledForHloModule(absl::string_view hlo_module_name,
93                                 const DebugOptions& opts);
DumpingEnabledForHloModule(const HloModule & module)94 inline bool DumpingEnabledForHloModule(const HloModule& module) {
95   return DumpingEnabledForHloModule(module.name(),
96                                     module.config().debug_options());
97 }
98 
99 // Returns true if DumpToFileInDirOrStdout and DumpHloModuleIfEnabled will write
100 // to stdout, rather than to a file on disk.
101 //
102 // This is useful if you want to do something different when writing to stdout.
103 // For example, maybe you have (almost-)duplicate data that you wouldn't mind
104 // writing to two files, but you don't want to print twice.
105 bool DumpingToStdout(const DebugOptions& opts);
106 
107 }  // namespace xla
108 
109 #endif  // TENSORFLOW_COMPILER_XLA_SERVICE_DUMP_H_
110