• 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 ==============================================================================*/
15 
16 #include "tensorflow/cc/framework/cc_op_gen.h"
17 #include "tensorflow/core/framework/op.h"
18 #include "tensorflow/core/framework/op_def.pb.h"
19 #include "tensorflow/core/framework/op_gen_lib.h"
20 #include "tensorflow/core/lib/core/stringpiece.h"
21 #include "tensorflow/core/lib/io/path.h"
22 #include "tensorflow/core/lib/strings/str_util.h"
23 #include "tensorflow/core/platform/env.h"
24 #include "tensorflow/core/platform/init_main.h"
25 #include "tensorflow/core/platform/types.h"
26 
27 namespace tensorflow {
28 namespace {
29 
PrintAllCCOps(const std::string & dot_h,const std::string & dot_cc,bool include_internal,const std::vector<string> & api_def_dirs)30 void PrintAllCCOps(const std::string& dot_h, const std::string& dot_cc,
31                    bool include_internal,
32                    const std::vector<string>& api_def_dirs) {
33   OpList ops;
34   OpRegistry::Global()->Export(include_internal, &ops);
35   ApiDefMap api_def_map(ops);
36   if (!api_def_dirs.empty()) {
37     Env* env = Env::Default();
38     // Only load files that correspond to "ops".
39     for (const auto& op : ops.op()) {
40       for (const auto& api_def_dir : api_def_dirs) {
41         const std::string api_def_file_pattern =
42             io::JoinPath(api_def_dir, "api_def_" + op.name() + ".pbtxt");
43         if (env->FileExists(api_def_file_pattern).ok()) {
44           TF_CHECK_OK(api_def_map.LoadFile(env, api_def_file_pattern));
45         }
46       }
47     }
48   }
49 
50   api_def_map.UpdateDocs();
51 
52   WriteCCOps(ops, api_def_map, dot_h, dot_cc);
53 }
54 
55 }  // namespace
56 }  // namespace tensorflow
57 
main(int argc,char * argv[])58 int main(int argc, char* argv[]) {
59   tensorflow::port::InitMain(argv[0], &argc, &argv);
60   if (argc != 5) {
61     for (int i = 1; i < argc; ++i) {
62       fprintf(stderr, "Arg %d = %s\n", i, argv[i]);
63     }
64     fprintf(stderr,
65             "Usage: %s out.h out.cc include_internal "
66             "api_def_dirs1,api_def_dir2 ...\n"
67             "  include_internal: 1 means include internal ops\n",
68             argv[0]);
69     exit(1);
70   }
71 
72   bool include_internal = tensorflow::StringPiece("1") == argv[3];
73   std::vector<tensorflow::string> api_def_dirs = tensorflow::str_util::Split(
74       argv[4], ",", tensorflow::str_util::SkipEmpty());
75   tensorflow::PrintAllCCOps(argv[1], argv[2], include_internal, api_def_dirs);
76   return 0;
77 }
78