• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* Copyright 2017 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 // Usage: show_signature some_binary_snapshot_proto*
17 //
18 // Shows the signature (ProgramShape) of binary snapshot proto(s) on the command
19 // line.
20 //
21 // some_binary_snapshot_proto is obtained by serializing the HloSnapshot from
22 // ServiceInterface::SnapshotComputation to disk.
23 //
24 // The output format is:
25 //
26 // file_path: computation_name :: program_shape_str
27 
28 #include <stdio.h>
29 #include <memory>
30 #include <string>
31 
32 #include "absl/types/span.h"
33 #include "tensorflow/compiler/xla/client/client.h"
34 #include "tensorflow/compiler/xla/client/client_library.h"
35 #include "tensorflow/compiler/xla/client/local_client.h"
36 #include "tensorflow/compiler/xla/service/hlo.pb.h"
37 #include "tensorflow/compiler/xla/shape_util.h"
38 #include "tensorflow/compiler/xla/statusor.h"
39 #include "tensorflow/compiler/xla/types.h"
40 #include "tensorflow/core/platform/env.h"
41 #include "tensorflow/core/platform/init_main.h"
42 #include "tensorflow/core/platform/logging.h"
43 
44 namespace xla {
45 namespace tools {
46 
RealMain(absl::Span<char * const> args)47 void RealMain(absl::Span<char* const> args) {
48   Client* client = ClientLibrary::LocalClientOrDie();
49   for (char* arg : args) {
50     HloSnapshot module;
51     TF_CHECK_OK(
52         tensorflow::ReadBinaryProto(tensorflow::Env::Default(), arg, &module));
53     auto computation = client->LoadSnapshot(module).ConsumeValueOrDie();
54     std::unique_ptr<ProgramShape> shape =
55         client->GetComputationShape(computation).ConsumeValueOrDie();
56     fprintf(stdout, "%s: %s :: %s\n", arg,
57             module.hlo().hlo_module().name().c_str(),
58             ShapeUtil::HumanString(*shape).c_str());
59   }
60 }
61 
62 }  // namespace tools
63 }  // namespace xla
64 
main(int argc,char ** argv)65 int main(int argc, char** argv) {
66   tensorflow::port::InitMain(argv[0], &argc, &argv);
67 
68   absl::Span<char* const> args(argv, argc);
69   args.remove_prefix(1);  // Pop off the binary name, argv[0]
70   xla::tools::RealMain(args);
71   return 0;
72 }
73