1/*
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing,
13 * software distributed under the License is distributed on an
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 * KIND, either express or implied. See the License for the
16 * specific language governing permissions and limitations
17 * under the License.
18 */
19
20/*!
21 * \file src/relay/collage/candidate_function_cache.cc
22 * \brief A cache of the unique global name and costs for partitioned functions.
23 */
24
25#include "./candidate_function_cache.h"
26
27namespace tvm {
28namespace relay {
29namespace collage {
30
31CandidateFunctionCache::Entry& CandidateFunctionCache::GetEntry(const std::string& label,
32 const Function& function) {
33 auto itr = cache_.find(function);
34 if (itr == cache_.end()) {
35 String compiler = function->GetAttr<String>(attr::kCompiler, String("tvm")).value();
36 std::string global_symbol_name = name_supply_->Fresh({compiler, label});
37 GlobalVar global_symbol(std::move(global_symbol_name), function->checked_type());
38 itr = cache_.emplace(function, Entry(std::move(global_symbol))).first;
39 }
40 return itr->second;
41}
42
43GlobalVar CandidateFunctionCache::GetGlobalSymbol(const Function& function) {
44 return GetEntry(/*label=*/"", function).global_symbol;
45}
46
47} // namespace collage
48} // namespace relay
49} // namespace tvm
50