Skip to content

Commit a4b7bb9

Browse files
dmansfieldcalberti
authored andcommitted
Compatibility with tensorflow master (tensorflow#204)
* TF defines the same external repositories but with different commit and BUILD * Fix a bunch of bazel namespace issues @tf changed to @org_tensorflow Tensorflow stopped using protobuf as submodule, now it's external, so use @protobuf * Sync to master of tensorflow submodule: - local version of is_cuda in syntaxnet.bzl, - using unique_ptr in file api.
1 parent ec1e573 commit a4b7bb9

File tree

9 files changed

+62
-70
lines changed

9 files changed

+62
-70
lines changed

syntaxnet/WORKSPACE

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,36 @@
11
local_repository(
2-
name = "tf",
2+
name = "org_tensorflow",
33
path = __workspace_dir__ + "/tensorflow",
44
)
55

66
load('//tensorflow/tensorflow:workspace.bzl', 'tf_workspace')
7-
tf_workspace("tensorflow/", "@tf")
7+
tf_workspace("tensorflow/", "@org_tensorflow")
88

99
# Specify the minimum required Bazel version.
10-
load("@tf//tensorflow:tensorflow.bzl", "check_version")
10+
load("@org_tensorflow//tensorflow:tensorflow.bzl", "check_version")
1111
check_version("0.2.0")
1212

1313
# ===== gRPC dependencies =====
1414

1515
bind(
1616
name = "libssl",
17-
actual = "@boringssl_git//:ssl",
17+
actual = "@ts_boringssl_git//:ssl",
1818
)
1919

2020
git_repository(
21-
name = "boringssl_git",
21+
name = "ts_boringssl_git",
2222
commit = "436432d849b83ab90f18773e4ae1c7a8f148f48d",
2323
init_submodules = True,
2424
remote = "https://github.com/mdsteele/boringssl-bazel.git",
2525
)
2626

2727
bind(
2828
name = "zlib",
29-
actual = "@zlib_archive//:zlib",
29+
actual = "@ts_zlib_archive//:zlib",
3030
)
3131

3232
new_http_archive(
33-
name = "zlib_archive",
33+
name = "ts_zlib_archive",
3434
build_file = "zlib.BUILD",
3535
sha256 = "879d73d8cd4d155f31c1f04838ecd567d34bebda780156f0e82a20721b3973d5",
3636
strip_prefix = "zlib-1.2.8",

syntaxnet/syntaxnet/BUILD

+11-11
Original file line numberDiff line numberDiff line change
@@ -77,15 +77,15 @@ cc_library(
7777
visibility = ["//visibility:public"],
7878
deps = [
7979
"@re2//:re2",
80-
"@tf//google/protobuf",
81-
"@tf//third_party/eigen3",
80+
"@protobuf//:protobuf",
81+
"@org_tensorflow//third_party/eigen3",
8282
] + select({
8383
"//conditions:default": [
84-
"@tf//tensorflow/core:framework",
85-
"@tf//tensorflow/core:lib",
84+
"@org_tensorflow//tensorflow/core:framework",
85+
"@org_tensorflow//tensorflow/core:lib",
8686
],
87-
"@tf//tensorflow:darwin": [
88-
"@tf//tensorflow/core:framework_headers_lib",
87+
"@org_tensorflow//tensorflow:darwin": [
88+
"@org_tensorflow//tensorflow/core:framework_headers_lib",
8989
],
9090
}),
9191
)
@@ -108,8 +108,8 @@ cc_library(
108108
srcs = ["test_main.cc"],
109109
linkopts = ["-lm"],
110110
deps = [
111-
"@tf//tensorflow/core:lib",
112-
"@tf//tensorflow/core:testlib",
111+
"@org_tensorflow//tensorflow/core:lib",
112+
"@org_tensorflow//tensorflow/core:testlib",
113113
"//external:gtest",
114114
],
115115
)
@@ -409,7 +409,7 @@ cc_binary(
409409
name = "parser_ops.so",
410410
linkopts = select({
411411
"//conditions:default": ["-lm"],
412-
"@tf//tensorflow:darwin": [],
412+
"@org_tensorflow//tensorflow:darwin": [],
413413
}),
414414
linkshared = 1,
415415
linkstatic = 1,
@@ -519,8 +519,8 @@ py_library(
519519
name = "graph_builder",
520520
srcs = ["graph_builder.py"],
521521
deps = [
522-
"@tf//tensorflow:tensorflow_py",
523-
"@tf//tensorflow/core:protos_all_py",
522+
"@org_tensorflow//tensorflow:tensorflow_py",
523+
"@org_tensorflow//tensorflow/core:protos_all_py",
524524
":load_parser_ops_py",
525525
":parser_ops",
526526
],

syntaxnet/syntaxnet/proto_io.h

+17-15
Original file line numberDiff line numberDiff line change
@@ -43,18 +43,19 @@ namespace syntaxnet {
4343
// A convenience wrapper to read protos with a RecordReader.
4444
class ProtoRecordReader {
4545
public:
46-
explicit ProtoRecordReader(tensorflow::RandomAccessFile *file)
47-
: file_(file), reader_(new tensorflow::io::RecordReader(file_)) {}
46+
explicit ProtoRecordReader(tensorflow::RandomAccessFile *file) {
47+
file_.reset(file);
48+
reader_.reset(new tensorflow::io::RecordReader(file_.get()));
49+
}
4850

4951
explicit ProtoRecordReader(const string &filename) {
5052
TF_CHECK_OK(
5153
tensorflow::Env::Default()->NewRandomAccessFile(filename, &file_));
52-
reader_.reset(new tensorflow::io::RecordReader(file_));
54+
reader_.reset(new tensorflow::io::RecordReader(file_.get()));
5355
}
5456

5557
~ProtoRecordReader() {
5658
reader_.reset();
57-
delete file_;
5859
}
5960

6061
template <typename T>
@@ -70,22 +71,22 @@ class ProtoRecordReader {
7071
}
7172

7273
private:
73-
tensorflow::RandomAccessFile *file_ = nullptr;
7474
uint64 offset_ = 0;
7575
std::unique_ptr<tensorflow::io::RecordReader> reader_;
76+
std::unique_ptr<tensorflow::RandomAccessFile> file_;
7677
};
7778

7879
// A convenience wrapper to write protos with a RecordReader.
7980
class ProtoRecordWriter {
8081
public:
8182
explicit ProtoRecordWriter(const string &filename) {
8283
TF_CHECK_OK(tensorflow::Env::Default()->NewWritableFile(filename, &file_));
83-
writer_.reset(new tensorflow::io::RecordWriter(file_));
84+
writer_.reset(new tensorflow::io::RecordWriter(file_.get()));
8485
}
8586

8687
~ProtoRecordWriter() {
8788
writer_.reset();
88-
delete file_;
89+
file_.reset();
8990
}
9091

9192
template <typename T>
@@ -94,8 +95,8 @@ class ProtoRecordWriter {
9495
}
9596

9697
private:
97-
tensorflow::WritableFile *file_ = nullptr;
9898
std::unique_ptr<tensorflow::io::RecordWriter> writer_;
99+
std::unique_ptr<tensorflow::WritableFile> file_;
99100
};
100101

101102
// A file implementation to read from stdin.
@@ -176,22 +177,24 @@ class TextReader {
176177

177178
void Reset() {
178179
sentence_count_ = 0;
179-
tensorflow::RandomAccessFile *file;
180180
if (filename_ == "-") {
181181
static const int kInputBufferSize = 8 * 1024; /* bytes */
182-
file = new StdIn();
183-
buffer_.reset(new tensorflow::io::InputBuffer(file, kInputBufferSize));
182+
file_.reset(new StdIn());
183+
buffer_.reset(
184+
new tensorflow::io::InputBuffer(file_.get(), kInputBufferSize));
184185
} else {
185186
static const int kInputBufferSize = 1 * 1024 * 1024; /* bytes */
186187
TF_CHECK_OK(
187-
tensorflow::Env::Default()->NewRandomAccessFile(filename_, &file));
188-
buffer_.reset(new tensorflow::io::InputBuffer(file, kInputBufferSize));
188+
tensorflow::Env::Default()->NewRandomAccessFile(filename_, &file_));
189+
buffer_.reset(
190+
new tensorflow::io::InputBuffer(file_.get(), kInputBufferSize));
189191
}
190192
}
191193

192194
private:
193195
string filename_;
194196
int sentence_count_ = 0;
197+
std::unique_ptr<tensorflow::RandomAccessFile> file_;
195198
std::unique_ptr<tensorflow::io::InputBuffer> buffer_;
196199
std::unique_ptr<DocumentFormat> format_;
197200
};
@@ -217,7 +220,6 @@ class TextWriter {
217220
~TextWriter() {
218221
if (file_) {
219222
file_->Close();
220-
delete file_;
221223
}
222224
}
223225

@@ -234,7 +236,7 @@ class TextWriter {
234236
private:
235237
string filename_;
236238
std::unique_ptr<DocumentFormat> format_;
237-
tensorflow::WritableFile *file_ = nullptr;
239+
std::unique_ptr<tensorflow::WritableFile> file_;
238240
};
239241

240242
} // namespace syntaxnet

syntaxnet/syntaxnet/reader_ops.cc

+2-5
Original file line numberDiff line numberDiff line change
@@ -514,19 +514,16 @@ class WordEmbeddingInitializer : public OpKernel {
514514
static tensorflow::Status CopyToTmpPath(const string &source_path,
515515
string *tmp_path) {
516516
// Opens source file.
517-
tensorflow::RandomAccessFile *source_file;
517+
std::unique_ptr<tensorflow::RandomAccessFile> source_file;
518518
TF_RETURN_IF_ERROR(tensorflow::Env::Default()->NewRandomAccessFile(
519519
source_path, &source_file));
520-
std::unique_ptr<tensorflow::RandomAccessFile> source_file_deleter(
521-
source_file);
522520

523521
// Creates destination file.
524-
tensorflow::WritableFile *target_file;
522+
std::unique_ptr<tensorflow::WritableFile> target_file;
525523
*tmp_path = tensorflow::strings::Printf(
526524
"/tmp/%d.%lld", getpid(), tensorflow::Env::Default()->NowMicros());
527525
TF_RETURN_IF_ERROR(
528526
tensorflow::Env::Default()->NewWritableFile(*tmp_path, &target_file));
529-
std::unique_ptr<tensorflow::WritableFile> target_file_deleter(target_file);
530527

531528
// Performs copy.
532529
tensorflow::Status s;

syntaxnet/syntaxnet/sentence_features.cc

+2-2
Original file line numberDiff line numberDiff line change
@@ -120,9 +120,9 @@ string AffixTableFeature::WorkspaceName() const {
120120
static AffixTable *CreateAffixTable(const string &filename,
121121
AffixTable::Type type) {
122122
AffixTable *affix_table = new AffixTable(type, 1);
123-
tensorflow::RandomAccessFile *file;
123+
std::unique_ptr<tensorflow::RandomAccessFile> file;
124124
TF_CHECK_OK(tensorflow::Env::Default()->NewRandomAccessFile(filename, &file));
125-
ProtoRecordReader reader(file);
125+
ProtoRecordReader reader(file.release());
126126
affix_table->Read(&reader);
127127
return affix_table;
128128
}

syntaxnet/syntaxnet/syntaxnet.bzl

+15-20
Original file line numberDiff line numberDiff line change
@@ -13,26 +13,21 @@
1313
# limitations under the License.
1414
# ==============================================================================
1515

16-
load("@tf//google/protobuf:protobuf.bzl", "cc_proto_library")
17-
load("@tf//google/protobuf:protobuf.bzl", "py_proto_library")
16+
load("@protobuf//:protobuf.bzl", "cc_proto_library")
17+
load("@protobuf//:protobuf.bzl", "py_proto_library")
1818

1919
def if_cuda(if_true, if_false = []):
20-
"""Shorthand for select()'ing on whether we're building with CUDA.
21-
22-
Returns a select statement which evaluates to if_true if we're building
23-
with CUDA enabled. Otherwise, the select statement evaluates to if_false.
24-
25-
"""
20+
"""Shorthand for select()'ing on whether we're building with CUDA."""
2621
return select({
27-
"@tf//third_party/gpus/cuda:using_nvcc": if_true,
28-
"@tf//third_party/gpus/cuda:using_gcudacc": if_true,
22+
"@org_tensorflow//third_party/gpus/cuda:using_nvcc": if_true,
23+
"@org_tensorflow//third_party/gpus/cuda:using_gcudacc": if_true,
2924
"//conditions:default": if_false
3025
})
3126

3227
def tf_copts():
3328
return (["-fno-exceptions", "-DEIGEN_AVOID_STL_ARRAY",] +
3429
if_cuda(["-DGOOGLE_CUDA=1"]) +
35-
select({"@tf//tensorflow:darwin": [],
30+
select({"@org_tensorflow//tensorflow:darwin": [],
3631
"//conditions:default": ["-pthread"]}))
3732

3833
def tf_proto_library(name, srcs=[], has_services=False,
@@ -47,9 +42,9 @@ def tf_proto_library(name, srcs=[], has_services=False,
4742
cc_proto_library(name=name,
4843
srcs=srcs,
4944
deps=deps,
50-
cc_libs = ["@tf//google/protobuf:protobuf"],
51-
protoc="@tf//google/protobuf:protoc",
52-
default_runtime="@tf//google/protobuf:protobuf",
45+
cc_libs = ["@protobuf//:protobuf"],
46+
protoc="@protobuf//:protoc",
47+
default_runtime="@protobuf//:protobuf",
5348
testonly=testonly,
5449
visibility=visibility,)
5550

@@ -58,8 +53,8 @@ def tf_proto_library_py(name, srcs=[], deps=[], visibility=None, testonly=0):
5853
srcs=srcs,
5954
srcs_version = "PY2AND3",
6055
deps=deps,
61-
default_runtime="@tf//google/protobuf:protobuf_python",
62-
protoc="@tf//google/protobuf:protoc",
56+
default_runtime="@protobuf//:protobuf_python",
57+
protoc="@protobuf//:protoc",
6358
visibility=visibility,
6459
testonly=testonly,)
6560

@@ -72,7 +67,7 @@ def tf_gen_op_libs(op_lib_names):
7267
native.cc_library(name=n + "_op_lib",
7368
copts=tf_copts(),
7469
srcs=["ops/" + n + ".cc"],
75-
deps=(["@tf//tensorflow/core:framework"]),
70+
deps=(["@org_tensorflow//tensorflow/core:framework"]),
7671
visibility=["//visibility:public"],
7772
alwayslink=1,
7873
linkstatic=1,)
@@ -89,8 +84,8 @@ def tf_gen_op_wrapper_py(name, out=None, hidden=[], visibility=None, deps=[],
8984
linkopts = ["-lm"],
9085
copts = tf_copts(),
9186
linkstatic = 1, # Faster to link this one-time-use binary dynamically
92-
deps = (["@tf//tensorflow/core:framework",
93-
"@tf//tensorflow/python:python_op_gen_main"] + deps),
87+
deps = (["@org_tensorflow//tensorflow/core:framework",
88+
"@org_tensorflow//tensorflow/python:python_op_gen_main"] + deps),
9489
)
9590

9691
# Invoke the previous cc_binary to generate a python file.
@@ -110,5 +105,5 @@ def tf_gen_op_wrapper_py(name, out=None, hidden=[], visibility=None, deps=[],
110105
srcs_version="PY2AND3",
111106
visibility=visibility,
112107
deps=[
113-
"@tf//tensorflow/python:framework_for_generated_wrappers",
108+
"@org_tensorflow//tensorflow/python:framework_for_generated_wrappers",
114109
],)

syntaxnet/syntaxnet/term_frequency_map.cc

+6-8
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,10 @@ void TermFrequencyMap::Load(const string &filename, int min_frequency,
5858
if (max_num_terms <= 0) max_num_terms = std::numeric_limits<int>::max();
5959

6060
// Read the first line (total # of terms in the mapping).
61-
tensorflow::RandomAccessFile *file;
61+
std::unique_ptr<tensorflow::RandomAccessFile> file;
6262
TF_CHECK_OK(tensorflow::Env::Default()->NewRandomAccessFile(filename, &file));
6363
static const int kInputBufferSize = 1 * 1024 * 1024; /* bytes */
64-
tensorflow::io::InputBuffer input(file, kInputBufferSize);
64+
tensorflow::io::InputBuffer input(file.get(), kInputBufferSize);
6565
string line;
6666
TF_CHECK_OK(input.ReadLine(&line));
6767
int32 total = -1;
@@ -119,7 +119,7 @@ void TermFrequencyMap::Save(const string &filename) const {
119119
std::sort(sorted_data.begin(), sorted_data.end(), SortByFrequencyThenTerm());
120120

121121
// Write the number of terms.
122-
tensorflow::WritableFile *file;
122+
std::unique_ptr<tensorflow::WritableFile> file;
123123
TF_CHECK_OK(tensorflow::Env::Default()->NewWritableFile(filename, &file));
124124
CHECK_LE(term_index_.size(), std::numeric_limits<int32>::max()); // overflow
125125
const int32 num_terms = term_index_.size();
@@ -136,15 +136,14 @@ void TermFrequencyMap::Save(const string &filename) const {
136136
TF_CHECK_OK(file->Close()) << "for file " << filename;
137137
LOG(INFO) << "Saved " << term_index_.size() << " terms to " << filename
138138
<< ".";
139-
delete file;
140139
}
141140

142141
TagToCategoryMap::TagToCategoryMap(const string &filename) {
143142
// Load the mapping.
144-
tensorflow::RandomAccessFile *file;
143+
std::unique_ptr<tensorflow::RandomAccessFile> file;
145144
TF_CHECK_OK(tensorflow::Env::Default()->NewRandomAccessFile(filename, &file));
146145
static const int kInputBufferSize = 1 * 1024 * 1024; /* bytes */
147-
tensorflow::io::InputBuffer input(file, kInputBufferSize);
146+
tensorflow::io::InputBuffer input(file.get(), kInputBufferSize);
148147
string line;
149148
while (input.ReadLine(&line) == tensorflow::Status::OK()) {
150149
vector<string> pair = utils::Split(line, '\t');
@@ -174,15 +173,14 @@ void TagToCategoryMap::SetCategory(const string &tag, const string &category) {
174173

175174
void TagToCategoryMap::Save(const string &filename) const {
176175
// Write tag and category on each line.
177-
tensorflow::WritableFile *file;
176+
std::unique_ptr<tensorflow::WritableFile> file;
178177
TF_CHECK_OK(tensorflow::Env::Default()->NewWritableFile(filename, &file));
179178
for (const auto &pair : tag_to_category_) {
180179
const string line =
181180
tensorflow::strings::StrCat(pair.first, "\t", pair.second, "\n");
182181
TF_CHECK_OK(file->Append(line));
183182
}
184183
TF_CHECK_OK(file->Close()) << "for file " << filename;
185-
delete file;
186184
}
187185

188186
} // namespace syntaxnet

syntaxnet/tensorflow

Submodule tensorflow updated 3257 files

syntaxnet/util/utf8/BUILD

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ cc_test(
2727
"unicodetext_unittest.cc",
2828
],
2929
deps = [
30-
"@tf//tensorflow/core:testlib",
30+
"@org_tensorflow//tensorflow/core:testlib",
3131
":unicodetext",
3232
],
3333
)

0 commit comments

Comments
 (0)