1 /* Copyright 2020 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 #ifndef TENSORFLOW_CORE_TPU_KERNELS_TPU_POD_STATE_H_ 16 #define TENSORFLOW_CORE_TPU_KERNELS_TPU_POD_STATE_H_ 17 18 #include <string> 19 #include <vector> 20 21 #include "tensorflow/core/framework/resource_mgr.h" 22 #include "tensorflow/core/tpu/kernels/tpu_compilation_cache_service.h" 23 24 namespace tensorflow { 25 26 // Name of tpu pod state. 27 ABSL_CONST_INIT extern const char kTpuPodStateResourceName[]; 28 29 // Wrapper to hold centralized state for the distributed TPU in the TPU_SYSTEM 30 // device's resource manager. 31 class TpuPodState : public ResourceBase { 32 public: 33 // The port number given by isa_cache_port will be freed with 34 // RecycleUnusedPort in the destructor if it is non-negative. 35 TpuPodState(int service_port, 36 std::unique_ptr<TpuCompilationCacheService> cache_service); 37 38 ~TpuPodState() override; 39 40 string DebugString() const override; 41 42 private: 43 std::unique_ptr<TpuCompilationCacheService> cache_service_; 44 int service_port_; 45 }; 46 47 // Returns the TPU pod state or an error. 48 Status GetTPUPodState(const ResourceMgr* rmgr, TpuPodState** pod_state); 49 50 // Checks whether the TPU POD state configuration is present within the resource 51 // manager. 52 bool HasTPUPodState(const ResourceMgr* rmgr); 53 54 // Construct TpuPodState. 55 Status ConstructTpuPodState( 56 ResourceMgr* rmgr, const std::vector<int32_t>& num_devices_per_host, 57 tpu::TpuCompilationCacheInterface* compilation_cache, 58 std::string* host_config_proto); 59 60 Status GetServerAddressAndPort(std::string* server_address, int* serving_port); 61 } // namespace tensorflow 62 63 #endif // TENSORFLOW_CORE_TPU_KERNELS_TPU_POD_STATE_H_ 64