• 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 #include <string>
17 #include <vector>
18 
19 #include "tensorflow/core/framework/op.h"
20 #include "tensorflow/core/lib/core/status.h"
21 #include "tensorflow/core/lib/strings/str_util.h"
22 #include "tensorflow/core/platform/env.h"
23 #include "tensorflow/core/platform/init_main.h"
24 #include "tensorflow/core/util/command_line_flags.h"
25 #include "tensorflow/java/src/gen/cc/op_generator.h"
26 
27 namespace tensorflow {
28 namespace java {
29 
30 const char kUsageHeader[] =
31     "\n\nGenerator of operation wrappers in Java.\n\n"
32     "This executable generates wrappers for all registered operations it has "
33     "been compiled with. A wrapper exposes an intuitive and strongly-typed\n"
34     "interface for building its underlying operation and linking it into a "
35     "graph.\n\n"
36     "Operation wrappers are generated under the path specified by the "
37     "'--output_dir' argument. This path can be absolute or relative to the\n"
38     "current working directory and will be created if it does not exist.\n\n"
39     "Note that the operations will not be available through the "
40     "'org.tensorflow.op.Ops' API until the generated classes are compiled\n"
41     "using an appropriate annotation processor.\n\n"
42     "The '--base_package' overrides the default parent package under which "
43     "the generated subpackage and classes are to be located.\n\n"
44     "Finally, the `--api_dirs` argument takes a list of comma-separated "
45     "directories of API definitions can be provided to override default\n"
46     "values found in the ops definitions. Directories are ordered by priority "
47     "(the last having precedence over the first).\n\n";
48 
49 }  // namespace java
50 }  // namespace tensorflow
51 
main(int argc,char * argv[])52 int main(int argc, char* argv[]) {
53   tensorflow::string output_dir;
54   tensorflow::string base_package = "org.tensorflow.op";
55   tensorflow::string api_dirs_str;
56   std::vector<tensorflow::Flag> flag_list = {
57       tensorflow::Flag("output_dir", &output_dir,
58                        "Root directory into which output files are generated"),
59       tensorflow::Flag(
60           "base_package", &base_package,
61           "Package parent to the generated subpackage and classes"),
62       tensorflow::Flag(
63           "api_dirs", &api_dirs_str,
64           "List of directories that contains the ops api definitions")};
65   tensorflow::string usage = tensorflow::java::kUsageHeader;
66   usage += tensorflow::Flags::Usage(argv[0], flag_list);
67   bool parsed_flags_ok = tensorflow::Flags::Parse(&argc, argv, flag_list);
68   tensorflow::port::InitMain(usage.c_str(), &argc, &argv);
69   QCHECK(parsed_flags_ok && !output_dir.empty()) << usage;
70   std::vector<tensorflow::string> api_dirs = tensorflow::str_util::Split(
71       api_dirs_str, ",", tensorflow::str_util::SkipEmpty());
72   tensorflow::java::OpGenerator generator(api_dirs);
73   tensorflow::OpList ops;
74   tensorflow::OpRegistry::Global()->Export(false, &ops);
75   TF_CHECK_OK(generator.Run(ops, base_package, output_dir));
76 
77   return 0;
78 }
79