Skip to content

Commit 077003a

Browse files
committed
build: gate grpc eager service on android
1 parent e4a24d8 commit 077003a

1 file changed

Lines changed: 74 additions & 0 deletions

File tree

scripts/patch_tfjava.py

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -728,6 +728,78 @@ def patch_workspace(path: Path) -> None:
728728
"""
729729

730730

731+
GRPC_SERVER_LIB_ANDROID_BUILD_PATCH = """--- a/tensorflow/core/distributed_runtime/rpc/BUILD
732+
+++ b/tensorflow/core/distributed_runtime/rpc/BUILD
733+
@@ -312,8 +312,12 @@
734+
"//tensorflow/core/distributed_runtime:session_mgr",
735+
"//tensorflow/core/distributed_runtime:worker_cache_wrapper",
736+
"//tensorflow/core/distributed_runtime:worker_env",
737+
- "//tensorflow/core/distributed_runtime/rpc/eager:grpc_eager_service_impl",
738+
- ],
739+
+ ] + select({
740+
+ "//tensorflow:android": [],
741+
+ "//conditions:default": [
742+
+ "//tensorflow/core/distributed_runtime/rpc/eager:grpc_eager_service_impl",
743+
+ ],
744+
+ }),
745+
alwayslink = 1,
746+
)
747+
748+
"""
749+
750+
751+
GRPC_SERVER_LIB_ANDROID_CC_PATCH = """--- a/tensorflow/core/distributed_runtime/rpc/grpc_server_lib.cc
752+
+++ b/tensorflow/core/distributed_runtime/rpc/grpc_server_lib.cc
753+
@@ -34,7 +34,9 @@
754+
#include "tensorflow/core/distributed_runtime/master_env.h"
755+
#include "tensorflow/core/distributed_runtime/master_session.h"
756+
#include "tensorflow/core/distributed_runtime/rpc/async_service_interface.h"
757+
+#if !defined(IS_MOBILE_PLATFORM)
758+
#include "tensorflow/core/distributed_runtime/rpc/eager/grpc_eager_service_impl.h"
759+
+#endif // !defined(IS_MOBILE_PLATFORM)
760+
#include "tensorflow/core/distributed_runtime/rpc/grpc_channel.h"
761+
#include "tensorflow/core/distributed_runtime/rpc/grpc_master_service.h"
762+
#include "tensorflow/core/distributed_runtime/rpc/grpc_worker_cache.h"
763+
@@ -231,7 +233,9 @@
764+
worker_service_ = NewGrpcWorkerService(worker_impl_.get(), &builder,
765+
opts.worker_service_options)
766+
.release();
767+
+#if !defined(IS_MOBILE_PLATFORM)
768+
eager_service_ = new eager::GrpcEagerServiceImpl(&worker_env_, &builder);
769+
+#endif // !defined(IS_MOBILE_PLATFORM)
770+
771+
// extra service:
772+
if (opts.service_func != nullptr) {
773+
@@ -383,9 +387,11 @@
774+
worker_thread_.reset(
775+
env_->StartThread(ThreadOptions(), "TF_worker_service",
776+
[this] { worker_service_->HandleRPCsLoop(); }));
777+
+#if !defined(IS_MOBILE_PLATFORM)
778+
eager_thread_.reset(
779+
env_->StartThread(ThreadOptions(), "TF_eager_service",
780+
[this] { eager_service_->HandleRPCsLoop(); }));
781+
+#endif // !defined(IS_MOBILE_PLATFORM)
782+
state_ = STARTED;
783+
LOG(INFO) << "Started server with target: " << target();
784+
return Status::OK();
785+
@@ -402,9 +408,14 @@
786+
787+
Status GrpcServer::AddMasterEagerContextToEagerService(
788+
const tensorflow::uint64 context_id, tensorflow::EagerContext* context) {
789+
+#if defined(IS_MOBILE_PLATFORM)
790+
+ return errors::Unimplemented(
791+
+ "GRPC eager service is not supported on mobile builds.");
792+
+#else
793+
auto* eager_service =
794+
static_cast<eager::GrpcEagerServiceImpl*>(eager_service_);
795+
return eager_service->CreateMasterContext(context_id, context);
796+
+#endif // defined(IS_MOBILE_PLATFORM)
797+
}
798+
799+
Status GrpcServer::UpdateServerDef(const ServerDef& server_def) {
800+
"""
801+
802+
731803
TF_C_API_EXPERIMENTAL_BUILD_PATCH = """--- a/tensorflow/c/BUILD
732804
+++ b/tensorflow/c/BUILD
733805
@@ -315,10 +315,14 @@
@@ -852,6 +924,8 @@ def write_tensorflow_android_absl_patch(path: Path) -> None:
852924
text += EAGER_CONTEXT_ANDROID_DEPS_PATCH
853925
text += TF_C_BUILD_ANDROID_FULL_DEPS_PATCH
854926
text += DISTRIBUTED_EAGER_ANDROID_PATCH
927+
text += GRPC_SERVER_LIB_ANDROID_BUILD_PATCH
928+
text += GRPC_SERVER_LIB_ANDROID_CC_PATCH
855929
text += TF_C_API_EXPERIMENTAL_CC_PATCH
856930
text += SAVED_MODEL_ANDROID_LOADER_PATCH
857931
text += TENSORFLOW_FRAMEWORK_ANDROID_PATCH

0 commit comments

Comments
 (0)