1 /* Copyright 2017 The TensorFlow Authors. All Rights Reserved. 2 3 Licensed under the Apache License, Version 2.0 (the "License"); 4 you may not use this file except in compliance with the License. 5 You may obtain a copy of the License at 6 7 http://www.apache.org/licenses/LICENSE-2.0 8 9 Unless required by applicable law or agreed to in writing, software 10 distributed under the License is distributed on an "AS IS" BASIS, 11 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 See the License for the specific language governing permissions and 13 limitations under the License. 14 ==============================================================================*/ 15 16 #ifndef TENSORFLOW_CORE_DISTRIBUTED_RUNTIME_WORKER_CACHE_WRAPPER_H_ 17 #define TENSORFLOW_CORE_DISTRIBUTED_RUNTIME_WORKER_CACHE_WRAPPER_H_ 18 19 #include <string> 20 #include <vector> 21 22 #include "tensorflow/core/distributed_runtime/worker_cache.h" 23 24 namespace tensorflow { 25 26 class WorkerCacheWrapper : public WorkerCacheInterface { 27 public: WorkerCacheWrapper(WorkerCacheInterface * wrapped)28 WorkerCacheWrapper(WorkerCacheInterface* wrapped) : wrapped_(wrapped) {} 29 30 // Updates *workers with strings naming the remote worker tasks to 31 // which open channels have been established. ListWorkers(std::vector<string> * workers)32 void ListWorkers(std::vector<string>* workers) const override { 33 return wrapped_->ListWorkers(workers); 34 } ListWorkersInJob(const string & job_name,std::vector<string> * workers)35 void ListWorkersInJob(const string& job_name, 36 std::vector<string>* workers) const override { 37 return wrapped_->ListWorkersInJob(job_name, workers); 38 } 39 40 // If "target" names a remote task for which an RPC channel exists 41 // or can be constructed, returns a pointer to a WorkerInterface object 42 // wrapping that channel. The returned value must be destroyed by 43 // calling `this->ReleaseWorker(target, ret)` GetOrCreateWorker(const string & target)44 WorkerInterface* GetOrCreateWorker(const string& target) override { 45 return wrapped_->GetOrCreateWorker(target); 46 } 47 48 // Release a worker previously returned by this->GetOrCreateWorker(target). 49 // 50 // TODO(jeff,sanjay): Consider moving target into WorkerInterface. 51 // TODO(jeff,sanjay): Unify all worker-cache impls and factor out a 52 // per-rpc-subsystem WorkerInterface creator. ReleaseWorker(const string & target,WorkerInterface * worker)53 void ReleaseWorker(const string& target, WorkerInterface* worker) override { 54 return wrapped_->ReleaseWorker(target, worker); 55 } 56 GetEagerClientCache(std::unique_ptr<eager::EagerClientCache> * eager_client_cache)57 Status GetEagerClientCache( 58 std::unique_ptr<eager::EagerClientCache>* eager_client_cache) override { 59 return wrapped_->GetEagerClientCache(eager_client_cache); 60 } 61 62 // Set *locality with the DeviceLocality of the specified remote device 63 // within its local environment. Returns true if *locality 64 // was set, using only locally cached data. Returns false 65 // if status data for that device was not available. Never blocks. GetDeviceLocalityNonBlocking(const string & device,DeviceLocality * locality)66 bool GetDeviceLocalityNonBlocking(const string& device, 67 DeviceLocality* locality) override { 68 return wrapped_->GetDeviceLocalityNonBlocking(device, locality); 69 } 70 71 // Set *locality with the DeviceLocality of the specified remote device 72 // within its local environment. Callback gets Status::OK if *locality 73 // was set. GetDeviceLocalityAsync(const string & device,DeviceLocality * locality,StatusCallback done)74 void GetDeviceLocalityAsync(const string& device, DeviceLocality* locality, 75 StatusCallback done) override { 76 return wrapped_->GetDeviceLocalityAsync(device, locality, std::move(done)); 77 } 78 79 // Start/stop logging activity. SetLogging(bool active)80 void SetLogging(bool active) override { wrapped_->SetLogging(active); } 81 82 // Discard any saved log data. ClearLogs()83 void ClearLogs() override { wrapped_->ClearLogs(); } 84 85 // Return logs for the identified step in *ss. Any returned data will no 86 // longer be stored. RetrieveLogs(int64 step_id,StepStats * ss)87 bool RetrieveLogs(int64 step_id, StepStats* ss) override { 88 return wrapped_->RetrieveLogs(step_id, ss); 89 } 90 91 private: 92 WorkerCacheInterface* wrapped_; // Not owned. 93 }; 94 } // namespace tensorflow 95 #endif // TENSORFLOW_CORE_DISTRIBUTED_RUNTIME_WORKER_CACHE_WRAPPER_H_ 96