Skip to content

Commit 89690ab

Browse files
committed
Expose the necessary symbols on Windows
Signed-off-by: Ryan Nett <[email protected]>
1 parent 1f1ba2c commit 89690ab

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+1452
-777
lines changed

tensorflow-core/tensorflow-core-api/WORKSPACE

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ http_archive(
1212
# ":tensorflow-macosx.patch",
1313
# ":tensorflow-windows.patch", # https://github.com/tensorflow/tensorflow/issues/25213
1414
":tensorflow-proto.patch",
15+
":custom-grad-helpers.patch",
16+
":custom-grad-symbols.patch",
1517
],
1618
patch_tool = "patch",
1719
patch_args = ["-p1"],
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
diff --git a/tensorflow/c/c_api.cc b/tensorflow/c/c_api.cc
2+
index f3bf7b98a1e6b..c9194c36c116b 100644
3+
--- a/tensorflow/c/c_api.cc
4+
+++ b/tensorflow/c/c_api.cc
5+
@@ -782,9 +782,9 @@ void TF_GraphGetTensorShape(TF_Graph* graph, TF_Output output, int64_t* dims,
6+
7+
extern "C" {
8+
9+
-static TF_OperationDescription* TF_NewOperationLocked(TF_Graph* graph,
10+
- const char* op_type,
11+
- const char* oper_name)
12+
+TF_OperationDescription* TF_NewOperationLocked(TF_Graph* graph,
13+
+ const char* op_type,
14+
+ const char* oper_name)
15+
TF_EXCLUSIVE_LOCKS_REQUIRED(graph->mu) {
16+
return new TF_OperationDescription(graph, op_type, oper_name);
17+
}
18+
@@ -1041,8 +1041,8 @@ void TF_SetAttrValueProto(TF_OperationDescription* desc, const char* attr_name,
19+
status->status = Status::OK();
20+
}
21+
22+
-static TF_Operation* TF_FinishOperationLocked(TF_OperationDescription* desc,
23+
- TF_Status* status)
24+
+TF_Operation* TF_FinishOperationLocked(TF_OperationDescription* desc,
25+
+ TF_Status* status)
26+
TF_EXCLUSIVE_LOCKS_REQUIRED(desc->graph->mu) {
27+
Node* ret = nullptr;
28+
29+
diff --git a/tensorflow/c/c_api.h b/tensorflow/c/c_api.h
30+
index 705cf85e0512f..fb746dd4af94f 100644
31+
--- a/tensorflow/c/c_api.h
32+
+++ b/tensorflow/c/c_api.h
33+
@@ -255,6 +255,12 @@ TF_CAPI_EXPORT extern void TF_GraphGetTensorShape(TF_Graph* graph,
34+
int64_t* dims, int num_dims,
35+
TF_Status* status);
36+
37+
+// TF_NewOperation, but without locking the graph.
38+
+// Should prefer TF_NewOperation when possible.
39+
+TF_CAPI_EXPORT extern TF_OperationDescription* TF_NewOperationLocked(TF_Graph* graph,
40+
+ const char* op_type,
41+
+ const char* oper_name);
42+
+
43+
// Operation will only be added to *graph when TF_FinishOperation() is
44+
// called (assuming TF_FinishOperation() does not return an error).
45+
// *graph must not be deleted until after TF_FinishOperation() is
46+
@@ -406,6 +412,11 @@ TF_CAPI_EXPORT extern void TF_SetAttrValueProto(TF_OperationDescription* desc,
47+
size_t proto_len,
48+
TF_Status* status);
49+
50+
+// TF_FinishOperation, but without locking the graph.
51+
+// TF_FinishOperation should be preferred when possible.
52+
+TF_CAPI_EXPORT extern TF_Operation* TF_FinishOperationLocked(TF_OperationDescription* desc,
53+
+ TF_Status* status);
54+
+
55+
// If this function succeeds:
56+
// * *status is set to an OK value,
57+
// * a TF_Operation is added to the graph,
Lines changed: 151 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,151 @@
1+
Index: tensorflow/tools/def_file_filter/BUILD
2+
IDEA additional info:
3+
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
4+
<+>UTF-8
5+
===================================================================
6+
diff --git a/tensorflow/tools/def_file_filter/BUILD b/tensorflow/tools/def_file_filter/BUILD
7+
--- a/tensorflow/tools/def_file_filter/BUILD (revision 5e5cc35b4c0f629a1e092b540fdf2b63367aa5ad)
8+
+++ b/tensorflow/tools/def_file_filter/BUILD (date 1629063191558)
9+
@@ -12,3 +12,8 @@
10+
name = "symbols_pybind",
11+
srcs = ["symbols_pybind.txt"],
12+
)
13+
+
14+
+filegroup(
15+
+ name = "symbols_java",
16+
+ srcs = ["symbols_java.txt"],
17+
+)
18+
Index: tensorflow/BUILD
19+
IDEA additional info:
20+
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
21+
<+>UTF-8
22+
===================================================================
23+
diff --git a/tensorflow/BUILD b/tensorflow/BUILD
24+
--- a/tensorflow/BUILD (revision 5e5cc35b4c0f629a1e092b540fdf2b63367aa5ad)
25+
+++ b/tensorflow/BUILD (date 1629063361078)
26+
@@ -1069,13 +1069,20 @@
27+
# the dynamic libraries of custom ops can find it at runtime.
28+
genrule(
29+
name = "tensorflow_filtered_def_file",
30+
- srcs = [":tensorflow_def_file"],
31+
+ srcs = [
32+
+ ":tensorflow_def_file",
33+
+ ":java_symbol_target_libs_file",
34+
+ ":win_lib_files_for_java_exported_symbols",
35+
+ "//tensorflow/tools/def_file_filter:symbols_java",
36+
+ ],
37+
outs = ["tensorflow_filtered_def_file.def"],
38+
cmd = select({
39+
"//tensorflow:windows": """
40+
$(location @local_config_def_file_filter//:def_file_filter) \\
41+
--input $(location :tensorflow_def_file) \\
42+
- --output $@
43+
+ --output $@ \\
44+
+ --symbols $(location //tensorflow/tools/def_file_filter:symbols_java) \\
45+
+ --lib_paths_file $(location :java_symbol_target_libs_file)
46+
""",
47+
"//conditions:default": "touch $@", # Just a placeholder for Unix platforms
48+
}),
49+
@@ -1083,6 +1090,34 @@
50+
visibility = ["//visibility:public"],
51+
)
52+
53+
+# Write to a file a list of all cc_library targets that we need for exporting symbols on Windows.
54+
+genrule(
55+
+ name = "java_symbol_target_libs_file",
56+
+ srcs = [":win_lib_files_for_java_exported_symbols"],
57+
+ outs = ["java_symbol_target_libs_file.txt"],
58+
+ cmd = select({
59+
+ "//tensorflow:windows": """
60+
+ for SRC in $(SRCS); do
61+
+ echo $$SRC | sed 's/third_party\\///g' >> $@
62+
+ done
63+
+ """,
64+
+ "//conditions:default": "touch $@", # Just a placeholder for Unix platforms
65+
+ }),
66+
+ visibility = ["//visibility:public"],
67+
+)
68+
+
69+
+filegroup(
70+
+ name = "win_lib_files_for_java_exported_symbols",
71+
+ srcs = [
72+
+ "//tensorflow/cc:scope",
73+
+ "//tensorflow/cc:grad_op_registry",
74+
+ "//tensorflow/c:tf_status_helper",
75+
+ "//tensorflow/cc:ops"
76+
+ ],
77+
+ visibility = ["//visibility:private"],
78+
+)
79+
+
80+
+
81+
# The interface library (tensorflow.dll.if.lib) for linking tensorflow DLL library (tensorflow.dll) on Windows.
82+
# To learn more about import library (called interface library in Bazel):
83+
# https://docs.microsoft.com/en-us/cpp/build/linking-an-executable-to-a-dll?view=vs-2017#linking-implicitly
84+
Index: tensorflow/tools/def_file_filter/BUILD.tpl
85+
IDEA additional info:
86+
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
87+
<+>UTF-8
88+
===================================================================
89+
diff --git a/tensorflow/tools/def_file_filter/BUILD.tpl b/tensorflow/tools/def_file_filter/BUILD.tpl
90+
--- a/tensorflow/tools/def_file_filter/BUILD.tpl (revision 5e5cc35b4c0f629a1e092b540fdf2b63367aa5ad)
91+
+++ b/tensorflow/tools/def_file_filter/BUILD.tpl (date 1629063191583)
92+
@@ -18,3 +18,8 @@
93+
name = "symbols_pybind",
94+
srcs = ["symbols_pybind.txt"],
95+
)
96+
+
97+
+filegroup(
98+
+ name = "symbols_java",
99+
+ srcs = ["symbols_java.txt"],
100+
+)
101+
Index: tensorflow/tools/def_file_filter/symbols_java.txt
102+
IDEA additional info:
103+
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
104+
<+>UTF-8
105+
===================================================================
106+
diff --git a/tensorflow/tools/def_file_filter/symbols_java.txt b/tensorflow/tools/def_file_filter/symbols_java.txt
107+
new file mode 100644
108+
--- /dev/null (date 1629063607794)
109+
+++ b/tensorflow/tools/def_file_filter/symbols_java.txt (date 1629063607794)
110+
@@ -0,0 +1,26 @@
111+
+[//tensorflow/cc:scope] # scope
112+
+tensorflow::Scope::graph
113+
+tensorflow::Scope::ok
114+
+tensorflow::Scope::UpdateBuilder
115+
+tensorflow::Scope::GetUniqueNameForOp
116+
+tensorflow::Scope::ExitOnError
117+
+tensorflow::Scope::WithDevice
118+
+tensorflow::Scope::WithNoControlDependencies
119+
+tensorflow::Scope::WithControlDependencies
120+
+tensorflow::Scope::NewSubScope
121+
+tensorflow::Scope::NewRootScope
122+
+tensorflow::Scope::operator=
123+
+tensorflow::Scope::~Scope
124+
+tensorflow::Scope::Scope
125+
+
126+
+[//tensorflow/cc:ops]
127+
+tensorflow::Operation::Operation
128+
+
129+
+[//tensorflow/cc:grad_op_registry] # custom gradients for graph
130+
+tensorflow::ops::GradOpRegistry::Global
131+
+tensorflow::ops::GradOpRegistry::Lookup
132+
+tensorflow::ops::GradOpRegistry::Register
133+
+
134+
+[//tensorflow/c:tf_status_helper] # status helpers
135+
+tensorflow::Set_TF_Status_from_Status
136+
+tensorflow::StatusFromTF_Status
137+
===================================================================
138+
diff --git a/tensorflow/tools/def_file_filter/def_file_filter.py.tpl b/tensorflow/tools/def_file_filter/def_file_filter.py.tpl
139+
--- a/tensorflow/tools/def_file_filter/def_file_filter.py.tpl (revision 919f693420e35d00c8d0a42100837ae3718f7927)
140+
+++ b/tensorflow/tools/def_file_filter/def_file_filter.py.tpl (date 1632048268359)
141+
@@ -143,8 +143,8 @@
142+
re_filter_comp = re.compile(r"{}".format(re_filter))
143+
144+
# Filter out symbol from the split line (`sym_split` in the for loop below).
145+
- sym_line_filter = r".*\s+\| (.*) \(.*"
146+
- sym_line_filter_anomaly = r".*\s+\| (.*)"
147+
+ sym_line_filter = r".*\s+\| (.*?) \(.*"
148+
+ sym_line_filter_anomaly = r".*\s+\| (.*?)"
149+
150+
for sym_line in sym_split:
151+
if re_filter_comp.search(sym_line):

tensorflow-core/tensorflow-core-api/src/gen/annotations/org/tensorflow/op/Ops.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8172,7 +8172,7 @@ public final Scope scope() {
81728172
* Creates an API for building operations in the provided execution environment
81738173
*/
81748174
public static Ops create(ExecutionEnvironment env) {
8175-
return new Ops(new JavaScope(env.baseScope())));
8175+
return new Ops(env.baseScope());
81768176
}
81778177

81788178
/**

tensorflow-core/tensorflow-core-api/src/gen/java/org/tensorflow/internal/c_api/GradFunc.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Targeted by JavaCPP version 1.5.6-SNAPSHOT: DO NOT EDIT THIS FILE
1+
// Targeted by JavaCPP version 1.5.6: DO NOT EDIT THIS FILE
22

33
package org.tensorflow.internal.c_api;
44

tensorflow-core/tensorflow-core-api/src/gen/java/org/tensorflow/internal/c_api/GradOpRegistry.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Targeted by JavaCPP version 1.5.6-SNAPSHOT: DO NOT EDIT THIS FILE
1+
// Targeted by JavaCPP version 1.5.6: DO NOT EDIT THIS FILE
22

33
package org.tensorflow.internal.c_api;
44

@@ -27,7 +27,7 @@ public class GradOpRegistry extends Pointer {
2727
return (GradOpRegistry)super.position(position);
2828
}
2929
@Override public GradOpRegistry getPointer(long i) {
30-
return new GradOpRegistry((Pointer)this).position(position + i);
30+
return new GradOpRegistry((Pointer)this).offsetAddress(i);
3131
}
3232

3333
/** Registers 'func' as the gradient function for 'op'.

tensorflow-core/tensorflow-core-api/src/gen/java/org/tensorflow/internal/c_api/NameMap.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Targeted by JavaCPP version 1.5.6-SNAPSHOT: DO NOT EDIT THIS FILE
1+
// Targeted by JavaCPP version 1.5.6: DO NOT EDIT THIS FILE
22

33
package org.tensorflow.internal.c_api;
44

tensorflow-core/tensorflow-core-api/src/gen/java/org/tensorflow/internal/c_api/NativeGraphPointer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Targeted by JavaCPP version 1.5.6-SNAPSHOT: DO NOT EDIT THIS FILE
1+
// Targeted by JavaCPP version 1.5.6: DO NOT EDIT THIS FILE
22

33
package org.tensorflow.internal.c_api;
44

tensorflow-core/tensorflow-core-api/src/gen/java/org/tensorflow/internal/c_api/NativeOperation.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Targeted by JavaCPP version 1.5.6-SNAPSHOT: DO NOT EDIT THIS FILE
1+
// Targeted by JavaCPP version 1.5.6: DO NOT EDIT THIS FILE
22

33
package org.tensorflow.internal.c_api;
44

@@ -25,7 +25,7 @@ public class NativeOperation extends Pointer {
2525
return (NativeOperation)super.position(position);
2626
}
2727
@Override public NativeOperation getPointer(long i) {
28-
return new NativeOperation((Pointer)this).position(position + i);
28+
return new NativeOperation((Pointer)this).offsetAddress(i);
2929
}
3030

3131
public NativeOperation() { super((Pointer)null); allocate(); }

tensorflow-core/tensorflow-core-api/src/gen/java/org/tensorflow/internal/c_api/NativeOutput.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Targeted by JavaCPP version 1.5.6-SNAPSHOT: DO NOT EDIT THIS FILE
1+
// Targeted by JavaCPP version 1.5.6: DO NOT EDIT THIS FILE
22

33
package org.tensorflow.internal.c_api;
44

@@ -22,7 +22,7 @@ public class NativeOutput extends Pointer {
2222
return (NativeOutput)super.position(position);
2323
}
2424
@Override public NativeOutput getPointer(long i) {
25-
return new NativeOutput((Pointer)this).position(position + i);
25+
return new NativeOutput((Pointer)this).offsetAddress(i);
2626
}
2727

2828
public NativeOutput() { super((Pointer)null); allocate(); }

0 commit comments

Comments
 (0)