• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright 2016 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# ==============================================================================
15r"""Prints a header file to be used with SELECTIVE_REGISTRATION.
16
17An example of command-line usage is:
18  bazel build tensorflow/python/tools:print_selective_registration_header && \
19  bazel-bin/tensorflow/python/tools/print_selective_registration_header \
20    --graphs=path/to/graph.pb > ops_to_register.h
21
22Then when compiling tensorflow, include ops_to_register.h in the include search
23path and pass -DSELECTIVE_REGISTRATION and -DSUPPORT_SELECTIVE_REGISTRATION
24 - see core/framework/selective_registration.h for more details.
25
26When compiling for Android:
27  bazel build -c opt --copt="-DSELECTIVE_REGISTRATION" \
28    --copt="-DSUPPORT_SELECTIVE_REGISTRATION" \
29    //tensorflow/tools/android/inference_interface:libtensorflow_inference.so \
30    --host_crosstool_top=@bazel_tools//tools/cpp:toolchain \
31    --crosstool_top=//external:android/crosstool --cpu=armeabi-v7a
32"""
33
34from __future__ import absolute_import
35from __future__ import division
36from __future__ import print_function
37
38import argparse
39import sys
40
41from tensorflow.python.platform import app
42from tensorflow.python.tools import selective_registration_header_lib
43
44FLAGS = None
45
46
47def main(unused_argv):
48  graphs = FLAGS.graphs.split(',')
49  print(
50      selective_registration_header_lib.get_header(graphs,
51                                                   FLAGS.proto_fileformat,
52                                                   FLAGS.default_ops))
53
54
55if __name__ == '__main__':
56  parser = argparse.ArgumentParser()
57  parser.register('type', 'bool', lambda v: v.lower() == 'true')
58  parser.add_argument(
59      '--graphs',
60      type=str,
61      default='',
62      help='Comma-separated list of paths to model files to be analyzed.',
63      required=True)
64  parser.add_argument(
65      '--proto_fileformat',
66      type=str,
67      default='rawproto',
68      help='Format of proto file, either textproto, rawproto or ops_list. The '
69      'ops_list is the file contains the list of ops in JSON format. Ex: '
70      '"[["Add", "BinaryOp<CPUDevice, functor::add<float>>"]]".')
71  parser.add_argument(
72      '--default_ops',
73      type=str,
74      default='NoOp:NoOp,_Recv:RecvOp,_Send:SendOp',
75      help='Default operator:kernel pairs to always include implementation for.'
76      'Pass "all" to have all operators and kernels included; note that this '
77      'should be used only when it is useful compared with simply not using '
78      'selective registration, as it can in some cases limit the effect of '
79      'compilation caches')
80
81  FLAGS, unparsed = parser.parse_known_args()
82  app.run(main=main, argv=[sys.argv[0]] + unparsed)
83