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 virtual void ListWorkers(std::vector<string>* workers) const { 33 return wrapped_->ListWorkers(workers); 34 } ListWorkersInJob(const string & job_name,std::vector<string> * workers)35 virtual void ListWorkersInJob(const string& job_name, 36 std::vector<string>* workers) const { 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)` 44 // TODO(mrry): rename this to GetOrCreateWorker() or something that 45 // makes it more obvious that this method returns a potentially 46 // shared object. CreateWorker(const string & target)47 virtual WorkerInterface* CreateWorker(const string& target) { 48 return wrapped_->CreateWorker(target); 49 } 50 51 // Release a worker previously returned by this->CreateWorker(target). 52 // 53 // TODO(jeff,sanjay): Consider moving target into WorkerInterface. 54 // TODO(jeff,sanjay): Unify all worker-cache impls and factor out a 55 // per-rpc-subsystem WorkerInterface creator. ReleaseWorker(const string & target,WorkerInterface * worker)56 virtual void ReleaseWorker(const string& target, WorkerInterface* worker) { 57 return wrapped_->ReleaseWorker(target, worker); 58 } 59 60 // Set *locality with the DeviceLocality of the specified remote device 61 // within its local environment. Returns true if *locality 62 // was set, using only locally cached data. Returns false 63 // if status data for that device was not available. Never blocks. GetDeviceLocalityNonBlocking(const string & device,DeviceLocality * locality)64 virtual bool GetDeviceLocalityNonBlocking(const string& device, 65 DeviceLocality* locality) { 66 return wrapped_->GetDeviceLocalityNonBlocking(device, locality); 67 } 68 69 // Set *locality with the DeviceLocality of the specified remote device 70 // within its local environment. Callback gets Status::OK if *locality 71 // was set. GetDeviceLocalityAsync(const string & device,DeviceLocality * locality,StatusCallback done)72 virtual void GetDeviceLocalityAsync(const string& device, 73 DeviceLocality* locality, 74 StatusCallback done) { 75 return wrapped_->GetDeviceLocalityAsync(device, locality, std::move(done)); 76 } 77 78 // Start/stop logging activity. SetLogging(bool active)79 virtual void SetLogging(bool active) { wrapped_->SetLogging(active); } 80 81 // Discard any saved log data. ClearLogs()82 virtual void ClearLogs() { wrapped_->ClearLogs(); } 83 84 // Return logs for the identified step in *ss. Any returned data will no 85 // longer be stored. RetrieveLogs(int64 step_id,StepStats * ss)86 virtual bool RetrieveLogs(int64 step_id, StepStats* ss) { 87 return wrapped_->RetrieveLogs(step_id, ss); 88 } 89 90 private: 91 WorkerCacheInterface* wrapped_; // Not owned. 92 }; 93 } // namespace tensorflow 94 #endif // TENSORFLOW_CORE_DISTRIBUTED_RUNTIME_WORKER_CACHE_WRAPPER_H_ 95