Home | History | Annotate | Download | only in api_def
      1 /* Copyright 2018 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 // This program can be used to automatically create an api_def_*.pbtxt
     16 // file based on op definition.
     17 //
     18 // To run, use the following script:
     19 // tensorflow/core/api_def/update_api_def.sh
     20 //
     21 // There are 2 ways to use this script:
     22 //   1. Define a REGISTER_OP call without a .Doc() call. Then, run
     23 //      this script and add summaries and descriptions in the generated
     24 //      api_def_*.pbtxt file manually.
     25 //   2. Add .Doc() call to a REGISTER_OP call. Then run this script
     26 //      to remove that .Doc() call and instead add corresponding summaries
     27 //      and descriptions in api_def_*.pbtxt file automatically.
     28 //      Note that .Doc() call must have the following format for this to work:
     29 //      .Doc(R"doc(<doc goes here>)doc").
     30 #include "tensorflow/core/api_def/update_api_def.h"
     31 #include "tensorflow/core/framework/op.h"
     32 #include "tensorflow/core/platform/init_main.h"
     33 #include "tensorflow/core/util/command_line_flags.h"
     34 
     35 int main(int argc, char** argv) {
     36   tensorflow::string api_files_dir;
     37   tensorflow::string op_file_pattern;
     38   std::vector<tensorflow::Flag> flag_list = {
     39       tensorflow::Flag("api_def_dir", &api_files_dir,
     40                        "Base directory of api_def*.pbtxt files."),
     41       tensorflow::Flag("op_file_pattern", &op_file_pattern,
     42                        "Pattern that matches C++ files containing REGISTER_OP "
     43                        "calls. If specified, we will try to remove .Doc() "
     44                        "calls for new ops defined in these files.")};
     45   std::string usage = tensorflow::Flags::Usage(argv[0], flag_list);
     46   bool parsed_values_ok = tensorflow::Flags::Parse(&argc, argv, flag_list);
     47   if (!parsed_values_ok) {
     48     std::cerr << usage << std::endl;
     49     return 2;
     50   }
     51   tensorflow::port::InitMain(argv[0], &argc, &argv);
     52 
     53   tensorflow::OpList ops;
     54   tensorflow::OpRegistry::Global()->Export(false, &ops);
     55   tensorflow::CreateApiDefs(ops, api_files_dir, op_file_pattern);
     56 }
     57