1 /* Copyright 2016 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_PARTIAL_H_ 17 #define TENSORFLOW_CORE_DISTRIBUTED_RUNTIME_WORKER_CACHE_PARTIAL_H_ 18 19 #include <string> 20 #include <unordered_map> 21 22 #include "tensorflow/core/distributed_runtime/worker_cache.h" 23 #include "tensorflow/core/platform/mutex.h" 24 #include "tensorflow/core/platform/thread_annotations.h" 25 #include "tensorflow/core/platform/types.h" 26 #include "tensorflow/core/protobuf/worker.pb.h" 27 28 namespace tensorflow { 29 30 // Implements the part of the interface that caches and returns remote 31 // device status attributes. 32 class WorkerCachePartial : public WorkerCacheInterface { 33 public: 34 bool GetDeviceLocalityNonBlocking(const string& device, 35 DeviceLocality* locality) override; 36 37 void GetDeviceLocalityAsync(const string& device, DeviceLocality* locality, 38 StatusCallback) override; 39 40 ~WorkerCachePartial() override {} 41 42 // Clear all entries from the DeviceStatus cache. 43 void FlushStatusCache(); 44 45 private: 46 mutex mu_; 47 48 // Initiate a GetStatusAsync to the remote task named by "task", and 49 // update the cache with all the DeviceAttributes reported. 50 Status RefreshDeviceStatus(const string& device_name); 51 52 typedef std::unordered_map<string, DeviceAttributes> StatusMap; 53 StatusMap device_status_cache_ GUARDED_BY(mu_); 54 }; 55 56 } // namespace tensorflow 57 #endif // TENSORFLOW_CORE_DISTRIBUTED_RUNTIME_WORKER_CACHE_PARTIAL_H_ 58