• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_COMPILATION_CACHE_LOOKUP_H_
16 #define TENSORFLOW_CORE_TPU_KERNELS_TPU_COMPILATION_CACHE_LOOKUP_H_
17 
18 #include "tensorflow/core/lib/core/refcount.h"
19 #include "tensorflow/core/platform/status.h"
20 #include "tensorflow/core/tpu/kernels/tpu_compilation_cache_common.pb.h"
21 #include "tensorflow/core/tpu/kernels/tpu_compilation_cache_interface.h"
22 
23 namespace tensorflow {
24 namespace tpu {
25 
26 // TODO(b/162241759): consider merging TpuCompilationCacheLookup and
27 // TpuCompilationCacheInterface.
28 // Base class allowing Execute Ops to look up TPU programs. Different subclasses
29 // are used when the execute Op is in the same address space as the compile Op,
30 // and when they need to communicate over RPC.
31 class TpuCompilationCacheLookup : public ResourceBase {
32  public:
33   ~TpuCompilationCacheLookup() override = default;
34 
35   // Looks up an executable corresponding to the model-parallel core index of
36   // the subgraph represented by key. On success a wrapper for the proto is
37   // returned in program. The wrapper is guaranteed to be valid only during the
38   // execution of the Op requesting the proto.
39   //
40   // Only one of the main, sharding, unsharding entries is fetched, as specified
41   // in fetch_target.
42   //
43   // If the compilation does not create sharding/unsharding programs, but the
44   // fetch_target requests one of them, then after this call
45   //   (*entry)->get().get_executable() will return nullptr.
46   virtual Status Lookup(const string& proto_key,
47                         std::unique_ptr<CompilationCacheEntryRef>* entry,
48                         CompilationCacheFetchTarget fetch_target) = 0;
49 
Lookup(const string & proto_key,std::unique_ptr<CompilationCacheEntryRef> * entry)50   virtual Status Lookup(const string& proto_key,
51                         std::unique_ptr<CompilationCacheEntryRef>* entry) {
52     return Lookup(proto_key, std::move(entry),
53                   CompilationCacheFetchTarget::MAIN);
54   }
55 
56   // Looks up an executable corresponding to the model-parallel core index of
57   // the subgraph represented by uid. On success a wrapper for the proto is
58   // returned in program. The wrapper is guaranteed to be valid only during the
59   // execution of the Op requesting the proto.
60   virtual Status Lookup(int64 uid, int proto_index,
61                         std::unique_ptr<CompilationCacheEntryRef>* entry,
62                         CompilationCacheFetchTarget fetch_target) = 0;
63 
Lookup(int64 uid,int proto_index,std::unique_ptr<CompilationCacheEntryRef> * entry)64   virtual Status Lookup(int64 uid, int proto_index,
65                         std::unique_ptr<CompilationCacheEntryRef>* entry) {
66     return Lookup(uid, proto_index, std::move(entry),
67                   CompilationCacheFetchTarget::MAIN);
68   }
69 };
70 }  // namespace tpu
71 }  // namespace tensorflow
72 
73 #endif  // TENSORFLOW_CORE_TPU_KERNELS_TPU_COMPILATION_CACHE_LOOKUP_H_
74