This repository has been archived by the owner on Feb 26, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9
/
tensorflow.patch
190 lines (187 loc) · 7.2 KB
/
tensorflow.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
diff --git a/tensorflow/compiler/xla/rpc/BUILD b/tensorflow/compiler/xla/rpc/BUILD
index 0d56a9a..fd83531 100644
--- a/tensorflow/compiler/xla/rpc/BUILD
+++ b/tensorflow/compiler/xla/rpc/BUILD
@@ -34,6 +34,55 @@ cc_library(
],
)
+load("//tensorflow:tensorflow.bzl", "tf_cc_shared_object")
+
+tf_cc_shared_object(
+ name = "libxla_computation_client.so",
+ visibility = ["//visibility:public"],
+ linkopts = select({
+ "//tensorflow:darwin": [
+ "-Wl,-exported_symbols_list", # This line must be directly followed by the exported_symbols.lds file
+ "//tensorflow:tf_exported_symbols.lds",
+ ],
+ "//tensorflow:windows": [],
+ "//tensorflow:windows_msvc": [],
+ "//conditions:default": [
+ "-z defs",
+ "-s",
+ "-Wl,--version-script", # This line must be directly followed by the version_script.lds file
+ "//tensorflow:tf_version_script.lds",
+ ],
+ }),
+ deps = [
+ "//tensorflow:tf_exported_symbols.lds",
+ "//tensorflow:tf_version_script.lds",
+ "computation_client_impl",
+ "grpc_stub",
+ "//tensorflow/compiler/xla:literal_util",
+ "//tensorflow/compiler/xla/client",
+ "//tensorflow/compiler/xla/client/xla_client:xla_builder",
+ "//tensorflow/compiler/xla/client:global_data",
+ "//tensorflow/compiler/xla/client/xla_client:xla_computation",
+ "//tensorflow/core:lib",
+ "@grpc//:grpc++_unsecure",
+ ],
+)
+
+cc_library(
+ name = "computation_client_impl",
+ srcs = ["computation_client.cc"],
+ hdrs = ["computation_client.h"],
+ deps = [
+ "grpc_stub",
+ "@grpc//:grpc++_unsecure",
+ "//tensorflow/compiler/xla:literal_util",
+ "//tensorflow/compiler/xla/client",
+ "//tensorflow/compiler/xla/client:global_data",
+ "//tensorflow/compiler/xla/client/xla_client:xla_computation",
+ "//tensorflow/core:lib",
+ ],
+)
+
tf_cc_binary(
name = "grpc_service_main_cpu",
srcs = ["grpc_service_main.cc"],
diff --git a/tensorflow/compiler/xla/rpc/computation_client.cc b/tensorflow/compiler/xla/rpc/computation_client.cc
new file mode 100644
index 0000000..9c17c45
--- /dev/null
+++ b/tensorflow/compiler/xla/rpc/computation_client.cc
@@ -0,0 +1,53 @@
+#include "tensorflow/compiler/xla/rpc/computation_client.h"
+#include "grpc++/support/channel_arguments.h"
+#include "grpc++/create_channel.h"
+#include "tensorflow/compiler/xla/client/client.h"
+#include "tensorflow/compiler/xla/rpc/grpc_stub.h"
+
+namespace xla {
+
+std::unique_ptr<Literal> ExecuteComputation(
+ const XlaComputation& computation,
+ tensorflow::gtl::ArraySlice<GlobalData*> arguments) {
+ constexpr int port = 51000;
+ ::grpc::ChannelArguments ch_args;
+ ch_args.SetMaxReceiveMessageSize(-1);
+ auto channel = ::grpc::CreateCustomChannel(
+ tensorflow::strings::Printf("localhost:%d", port),
+ ::grpc::InsecureChannelCredentials(), ch_args);
+ channel->WaitForConnected(gpr_time_add(
+ gpr_now(GPR_CLOCK_REALTIME), gpr_time_from_seconds(10, GPR_TIMESPAN)));
+ LOG(INFO) << "Channel to server is connected on port " << port;
+
+ std::unique_ptr<grpc::XlaService::Stub> xla_service =
+ grpc::XlaService::NewStub(channel);
+ std::unique_ptr<GRPCStub> stub(new GRPCStub(xla_service.get()));
+ std::unique_ptr<Client> client(new Client(stub.get()));
+ StatusOr<std::unique_ptr<Literal>> result_or_status =
+ client->ExecuteAndTransfer(computation, arguments, nullptr);
+ if (!result_or_status.ok()) {
+ LOG(FATAL) << result_or_status.status();
+ }
+ return std::move(result_or_status.ValueOrDie());
+}
+
+std::unique_ptr<xla::GlobalData> TransferParameterToServer(
+ const xla::Literal& literal) {
+ constexpr int port = 51000;
+ ::grpc::ChannelArguments ch_args;
+ ch_args.SetMaxReceiveMessageSize(-1);
+ auto channel = ::grpc::CreateCustomChannel(
+ tensorflow::strings::Printf("localhost:%d", port),
+ ::grpc::InsecureChannelCredentials(), ch_args);
+ channel->WaitForConnected(gpr_time_add(
+ gpr_now(GPR_CLOCK_REALTIME), gpr_time_from_seconds(10, GPR_TIMESPAN)));
+ LOG(INFO) << "Channel to server is connected on port " << port;
+
+ std::unique_ptr<grpc::XlaService::Stub> xla_service =
+ grpc::XlaService::NewStub(channel);
+ std::unique_ptr<GRPCStub> stub(new GRPCStub(xla_service.get()));
+ std::unique_ptr<Client> client(new Client(stub.get()));
+ return client->TransferToServer(literal).ValueOrDie();
+}
+
+} // namespace xla
diff --git a/tensorflow/compiler/xla/rpc/computation_client.h b/tensorflow/compiler/xla/rpc/computation_client.h
new file mode 100644
index 0000000..ff7b11c
--- /dev/null
+++ b/tensorflow/compiler/xla/rpc/computation_client.h
@@ -0,0 +1,20 @@
+#ifndef TENSORFLOW_COMPILER_XLA_RPC_COMPUTATION_CLIENT_H_
+#define TENSORFLOW_COMPILER_XLA_RPC_COMPUTATION_CLIENT_H_
+
+#include "tensorflow/compiler/xla/client/global_data.h"
+#include "tensorflow/compiler/xla/client/xla_client/xla_computation.h"
+#include "tensorflow/compiler/xla/literal_util.h"
+#include "tensorflow/core/lib/gtl/array_slice.h"
+
+namespace xla {
+
+std::unique_ptr<Literal> ExecuteComputation(
+ const XlaComputation& computation,
+ tensorflow::gtl::ArraySlice<GlobalData*> arguments);
+
+std::unique_ptr<xla::GlobalData> TransferParameterToServer(
+ const xla::Literal& literal);
+
+} // namespace xla
+
+#endif // TENSORFLOW_COMPILER_XLA_RPC_COMPUTATION_CLIENT_H_
diff --git a/tensorflow/compiler/xla/rpc/grpc_service_main.cc b/tensorflow/compiler/xla/rpc/grpc_service_main.cc
index c68c857..7110c70 100644
--- a/tensorflow/compiler/xla/rpc/grpc_service_main.cc
+++ b/tensorflow/compiler/xla/rpc/grpc_service_main.cc
@@ -48,6 +48,7 @@ int RealMain(int argc, char** argv) {
builder.AddListeningPort(server_address, ::grpc::InsecureServerCredentials());
builder.RegisterService(service.get());
+ builder.SetMaxReceiveMessageSize(INT_MAX);
std::unique_ptr<::grpc::Server> server(builder.BuildAndStart());
LOG(INFO) << "Server listening on " << server_address;
diff --git a/tensorflow/tf_exported_symbols.lds b/tensorflow/tf_exported_symbols.lds
index 3ff824e..39d1728 100644
--- a/tensorflow/tf_exported_symbols.lds
+++ b/tensorflow/tf_exported_symbols.lds
@@ -5,3 +5,4 @@
*TFE_*
*nsync_*
*pywrap_xla*
+*xla*
diff --git a/tensorflow/tf_version_script.lds b/tensorflow/tf_version_script.lds
index 6b28943..76b7454 100644
--- a/tensorflow/tf_version_script.lds
+++ b/tensorflow/tf_version_script.lds
@@ -6,6 +6,7 @@ tensorflow {
*TFE_*;
*nsync_*;
*pywrap_xla*;
+ *xla*;
local:
*;
};
diff --git a/tensorflow/workspace.bzl b/tensorflow/workspace.bzl
index 3935992..00216df 100644
--- a/tensorflow/workspace.bzl
+++ b/tensorflow/workspace.bzl
@@ -200,6 +200,7 @@ def tf_workspace(path_prefix="", tf_repo_name=""):
urls = [
"https://mirror.bazel.build/www.nasm.us/pub/nasm/releasebuilds/2.12.02/nasm-2.12.02.tar.bz2",
"http://pkgs.fedoraproject.org/repo/pkgs/nasm/nasm-2.12.02.tar.bz2/d15843c3fb7db39af80571ee27ec6fad/nasm-2.12.02.tar.bz2",
+ "http://www.nasm.us/pub/nasm/releasebuilds/2.12.02/nasm-2.12.02.tar.bz2",
],
sha256 = "00b0891c678c065446ca59bcee64719d0096d54d6886e6e472aeee2e170ae324",
strip_prefix = "nasm-2.12.02",