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 #include "tensorflow/core/tpu/kernels/tpu_compilation_cache_local_lookup.h"
16
17 namespace tensorflow {
18 namespace tpu {
19
TpuCompilationCacheLocalLookup(TpuCompilationCacheInterface * cache)20 TpuCompilationCacheLocalLookup::TpuCompilationCacheLocalLookup(
21 TpuCompilationCacheInterface* cache)
22 : cache_(cache) {
23 cache_->Ref();
24 }
25
~TpuCompilationCacheLocalLookup()26 TpuCompilationCacheLocalLookup::~TpuCompilationCacheLocalLookup() {
27 cache_->Unref();
28 }
29
Lookup(const string & proto_key,std::unique_ptr<CompilationCacheEntryRef> * entry,CompilationCacheFetchTarget fetch_target)30 Status TpuCompilationCacheLocalLookup::Lookup(
31 const string& proto_key, std::unique_ptr<CompilationCacheEntryRef>* entry,
32 CompilationCacheFetchTarget fetch_target) {
33 profiler::TraceMe proto_lookup_traceme("Local TPU proto cache lookup",
34 /*level=*/2);
35 Status s = cache_->Lookup(proto_key, entry);
36 VLOG(1) << "Looked up key " << proto_key << " in local subgraph cache status "
37 << s;
38 if (!s.ok()) {
39 return s;
40 }
41 s = (*entry)->ToSubEntryRef(fetch_target);
42 VLOG(1) << "Fetched subentry: "
43 << CompilationCacheFetchTarget_Name(fetch_target) << " with status "
44 << s;
45 return s;
46 }
47
Lookup(int64 uid,int proto_index,std::unique_ptr<CompilationCacheEntryRef> * entry,CompilationCacheFetchTarget fetch_target)48 Status TpuCompilationCacheLocalLookup::Lookup(
49 int64 uid, int proto_index,
50 std::unique_ptr<CompilationCacheEntryRef>* entry,
51 CompilationCacheFetchTarget fetch_target) {
52 profiler::TraceMe proto_lookup_traceme("Local TPU proto cache lookup by uid",
53 /*level=*/2);
54 Status s = cache_->Lookup(uid, proto_index, entry);
55 VLOG(1) << "Looked up uid " << uid << ", index " << proto_index
56 << " in local subgraph cache status " << s;
57 if (!s.ok()) {
58 return s;
59 }
60 s = (*entry)->ToSubEntryRef(fetch_target);
61 VLOG(1) << "Fetched subentry: "
62 << CompilationCacheFetchTarget_Name(fetch_target) << " with status "
63 << s;
64 return s;
65 }
66
DebugString() const67 string TpuCompilationCacheLocalLookup::DebugString() const {
68 return "TpuCompilationCacheLocalLookup";
69 }
70 } // namespace tpu
71 } // namespace tensorflow
72