|
15 | 15 |
|
16 | 16 | #include <string>
|
17 | 17 | #include <vector>
|
| 18 | +#include <iostream> |
| 19 | +#include <fstream> |
18 | 20 | #include <stdio.h>
|
19 | 21 |
|
20 | 22 | #include "tensorflow/core/framework/op.h"
|
@@ -43,7 +45,9 @@ const char kUsageHeader[] =
|
43 | 45 | "The first argument is the location of the tensorflow binary built for TF-"
|
44 | 46 | "Java.\nFor example, `bazel-out/k8-opt/bin/external/org_tensorflow/tensorfl"
|
45 | 47 | "ow/libtensorflow_cc.so`.\n\n"
|
46 |
| - "Finally, the `--api_dirs` argument takes a list of comma-separated " |
| 48 | + "The second and third arguments are the binary and text output files, respectively.\n" |
| 49 | + "The text output file will not include ApiDefs, like tensorflow's ops.pbtxt.\n\n" |
| 50 | + "Finally, the rest of the arguments are used as " |
47 | 51 | "directories of API definitions can be provided to override default\n"
|
48 | 52 | "values found in the ops definitions. Directories are ordered by priority "
|
49 | 53 | "(the last having precedence over the first).\nFor example, `bazel-tensorf"
|
@@ -86,32 +90,45 @@ Status UpdateOpDefs(OpList* op_list, const std::vector<tensorflow::string>& api_
|
86 | 90 | // See usage header.
|
87 | 91 | // Writes an OpList proto to stdout, with each OpDef having its ApiDef in field 100
|
88 | 92 | int main(int argc, char* argv[]) {
|
89 |
| - tensorflow::string api_dirs_str; |
90 |
| - std::vector<tensorflow::Flag> flag_list = { |
91 |
| - tensorflow::Flag( |
92 |
| - "api_dirs", &api_dirs_str, |
93 |
| - "List of directories that contain the ops API definitions protos")}; |
94 |
| - tensorflow::string usage = tensorflow::java::kUsageHeader; |
95 |
| - usage += tensorflow::Flags::Usage( |
96 |
| - tensorflow::string(argv[0]) + " <ops library paths...>", flag_list); |
97 |
| - bool parsed_flags_ok = tensorflow::Flags::Parse(&argc, argv, flag_list); |
98 |
| - tensorflow::port::InitMain(usage.c_str(), &argc, &argv); |
99 |
| - QCHECK(parsed_flags_ok && argc > 1) << usage; |
100 |
| - std::vector<tensorflow::string> api_dirs = tensorflow::str_util::Split( |
101 |
| - api_dirs_str, ",", tensorflow::str_util::SkipEmpty()); |
| 93 | + tensorflow::port::InitMain(tensorflow::java::kUsageHeader, &argc, &argv); |
| 94 | + std::vector<tensorflow::string> api_dirs; |
102 | 95 |
|
103 |
| - tensorflow::Env* env = tensorflow::Env::Default(); |
104 |
| - void* ops_libs_handles[50]; |
105 |
| - for (int i = 1; i < argc; ++i) { |
106 |
| - TF_CHECK_OK(env->LoadDynamicLibrary(argv[1], &ops_libs_handles[i - 1])); |
| 96 | + if(argc < 4) { |
| 97 | + std::cerr << "Must specify <library_path> <binary_output> <text_output>" << "\n"; |
| 98 | + std::cerr << tensorflow::java::kUsageHeader; |
| 99 | + return 1; |
| 100 | + } |
| 101 | + |
| 102 | + for(int i = 4 ; i < argc ; i++){ |
| 103 | + api_dirs.push_back(argv[i]); |
| 104 | + } |
| 105 | + |
| 106 | + std::ofstream binary_output (argv[2], std::ios::out | std::ios::trunc | std::ios::binary); |
| 107 | + std::ofstream text_output (argv[3], std::ios::out | std::ios::trunc); |
| 108 | + |
| 109 | + if(!binary_output.is_open()){ |
| 110 | + std::cerr << "Error opening file " << argv[2] << "\n"; |
| 111 | + return 1; |
| 112 | + } |
| 113 | + |
| 114 | + if(!text_output.is_open()){ |
| 115 | + std::cerr << "Error opening file " << argv[3] << "\n"; |
| 116 | + return 1; |
107 | 117 | }
|
| 118 | + |
| 119 | + tensorflow::Env* env = tensorflow::Env::Default(); |
| 120 | + void* ops_libs_handles[1]; |
| 121 | + TF_CHECK_OK(env->LoadDynamicLibrary(argv[1], &ops_libs_handles[0])); |
108 | 122 | tensorflow::OpList ops;
|
109 | 123 | tensorflow::OpRegistry::Global()->Export(false, &ops);
|
110 |
| - TF_CHECK_OK(tensorflow::java::UpdateOpDefs(&ops, api_dirs, env)); |
111 | 124 |
|
| 125 | + text_output << ops.DebugString(); |
| 126 | + text_output.close(); |
| 127 | + |
| 128 | + TF_CHECK_OK(tensorflow::java::UpdateOpDefs(&ops, api_dirs, env)); |
112 | 129 |
|
113 |
| - std::ostream & out = std::cout; |
114 |
| - ops.SerializeToOstream(&out); |
| 130 | + ops.SerializeToOstream(&binary_output); |
| 131 | + binary_output.close(); |
115 | 132 |
|
116 | 133 | return 0;
|
117 | 134 | }
|
0 commit comments