Home | History | Annotate | Download | only in tools
      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 SessionModule 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 "tensorflow/compiler/xla/client/client.h"
     33 #include "tensorflow/compiler/xla/client/client_library.h"
     34 #include "tensorflow/compiler/xla/client/computation.h"
     35 #include "tensorflow/compiler/xla/client/local_client.h"
     36 #include "tensorflow/compiler/xla/service/session.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/compiler/xla/xla_data.pb.h"
     41 #include "tensorflow/core/lib/gtl/array_slice.h"
     42 #include "tensorflow/core/platform/env.h"
     43 #include "tensorflow/core/platform/init_main.h"
     44 #include "tensorflow/core/platform/logging.h"
     45 
     46 namespace xla {
     47 namespace tools {
     48 
     49 void RealMain(tensorflow::gtl::ArraySlice<char*> args) {
     50   Client* client = ClientLibrary::LocalClientOrDie();
     51   for (char* arg : args) {
     52     SessionModule module;
     53     TF_CHECK_OK(
     54         tensorflow::ReadBinaryProto(tensorflow::Env::Default(), arg, &module));
     55     Computation computation = client->LoadSnapshot(module).ConsumeValueOrDie();
     56     std::unique_ptr<ProgramShape> shape =
     57         client->GetComputationShape(computation).ConsumeValueOrDie();
     58     fprintf(stdout, "%s: %s :: %s\n", arg, module.entry().name().c_str(),
     59             ShapeUtil::HumanString(*shape).c_str());
     60   }
     61 }
     62 
     63 }  // namespace tools
     64 }  // namespace xla
     65 
     66 int main(int argc, char** argv) {
     67   tensorflow::port::InitMain(argv[0], &argc, &argv);
     68 
     69   tensorflow::gtl::ArraySlice<char*> args(argv, argc);
     70   args.pop_front();  // Pop off the binary name, argv[0]
     71   xla::tools::RealMain(args);
     72   return 0;
     73 }
     74