xref: /aosp_15_r20/external/tensorflow/tensorflow/core/tpu/tpu_configuration.cc (revision b6fb3261f9314811a0f4371741dbb8839866f948)
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 
16 #include "tensorflow/core/tpu/tpu_configuration.h"
17 
18 namespace tensorflow {
19 
20 namespace {
21 
GetGlobalResourceMgr()22 ResourceMgr* GetGlobalResourceMgr() {
23   static ResourceMgr* const rmgr = new ResourceMgr();
24   return rmgr;
25 }
26 
27 }  // namespace
28 
29 #if !defined(PLATFORM_GOOGLE)
30 // Used only by Google-internal tests, so deliberately left empty.
MaybeInitializeTPUSystemForTests()31 void MaybeInitializeTPUSystemForTests() {}
32 #endif
33 
GetTPUConfigResourceMgr(bool initialize_first)34 ResourceMgr* GetTPUConfigResourceMgr(bool initialize_first) {
35   if (initialize_first) {
36     MaybeInitializeTPUSystemForTests();
37   }
38 
39   // Put all TPU-related state in the global ResourceMgr. This includes the
40   // TpuPodState, compilation cache, etc. We don't use the TPU_SYSTEM
41   // ResourceMgr because there may be more than one TPU_SYSTEM ResourceMgr when
42   // DirectSession or isolate_session_state are used.
43   return GetGlobalResourceMgr();
44 }
45 
46 }  // namespace tensorflow
47