forked from apache/tvm
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Collage] CombinerRule and CandidatePartition::EstimateCost (apache#1…
…2078) * [Collage] CombinerRule and CandidatePartition::EstimateCost See https://github.com/apache/tvm-rfcs/blob/main/rfcs/0062-collage.md. We complete the PartitionRule sub-class hierarchy with the addition of CombinePartitionRule, which allows disjoint candidate partitions to be unioned based on simple rules. - By TOpPattern kind, eg a kOutElemwiseFusable and kBroadcast. - A tuple argument with injective fields. - The projection from an injective group (obviously of tuple type) - Combinations of the above. These let us mimic many common fusion strategies, including TVMs, so that the candidates explored during Collage search are as large as possible to expose possible fusion opportunities but no larger. Also completes CandidatePartition with the EstimateCost method, which is used during search to construct a stand-alone IRModule for latency estimation. Finish units tests for PartitionRule and CandidatePartition. * - fix relay.collage ffi prefix.
- Loading branch information
1 parent
55f06bb
commit 1d4676f
Showing
15 changed files
with
2,167 additions
and
92 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
/*! | ||
* \file src/relay/collage/candidate_function_cache.cc | ||
* \brief A cache of the unique global name and costs for partitioned functions. | ||
*/ | ||
|
||
#include "./candidate_function_cache.h" | ||
|
||
namespace tvm { | ||
namespace relay { | ||
namespace collage { | ||
|
||
CandidateFunctionCache::Entry& CandidateFunctionCache::GetEntry(const std::string& label, | ||
const Function& function) { | ||
auto itr = cache_.find(function); | ||
if (itr == cache_.end()) { | ||
String compiler = function->GetAttr<String>(attr::kCompiler, String("tvm")).value(); | ||
std::string global_symbol_name = name_supply_->Fresh({compiler, label}); | ||
GlobalVar global_symbol(std::move(global_symbol_name), function->checked_type()); | ||
itr = cache_.emplace(function, Entry(std::move(global_symbol))).first; | ||
} | ||
return itr->second; | ||
} | ||
|
||
GlobalVar CandidateFunctionCache::GetGlobalSymbol(const Function& function) { | ||
return GetEntry(/*label=*/"", function).global_symbol; | ||
} | ||
|
||
} // namespace collage | ||
} // namespace relay | ||
} // namespace tvm |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
/*! | ||
* \file src/relay/collage/candidate_function_cache.h | ||
* \brief A cache of the unique global symbol name and cost for partitioned functions. | ||
*/ | ||
|
||
#ifndef TVM_RELAY_COLLAGE_CANDIDATE_FUNCTION_CACHE_H_ | ||
#define TVM_RELAY_COLLAGE_CANDIDATE_FUNCTION_CACHE_H_ | ||
|
||
#include <tvm/relay/function.h> | ||
|
||
#include <memory> | ||
#include <string> | ||
#include <unordered_map> | ||
#include <utility> | ||
|
||
#include "../transforms/compiler_function_utils.h" | ||
#include "./cost.h" | ||
#include "./name_supply.h" | ||
|
||
namespace tvm { | ||
namespace relay { | ||
namespace collage { | ||
|
||
/*! | ||
* \brief A cache of the unique global symbol and cost for functions extracted to represent | ||
* partitions. If two functions are structurally equal (which includes equality of their "Compiler" | ||
* attributes) then they will share the same global symbol and estimated cost. We rely on the | ||
* function's attributes to distinguish partitions which are structurally the same graph but | ||
* intended for different targets. | ||
*/ | ||
class CandidateFunctionCache : public transform::GlobalSymbolCache { | ||
public: | ||
explicit CandidateFunctionCache(std::shared_ptr<NameSupply> name_supply) | ||
: name_supply_(std::move(name_supply)) {} | ||
|
||
struct Entry { | ||
GlobalVar global_symbol; | ||
Cost cost = Cost::Unknown(); // Filled in when have estimated cost. | ||
|
||
explicit Entry(GlobalVar global_symbol) : global_symbol(std::move(global_symbol)) {} | ||
}; | ||
|
||
/*! | ||
* \brief Returns the unique entry for \p function. If no such entry already exists, create it | ||
* and assign it a unique global symbol name. | ||
*/ | ||
Entry& GetEntry(const std::string& label, const Function& function); | ||
|
||
GlobalVar GetGlobalSymbol(const Function& function) final; | ||
|
||
private: | ||
std::shared_ptr<NameSupply> name_supply_; | ||
std::unordered_map<Function, Entry, StructuralHash, StructuralEqual> cache_; | ||
}; | ||
|
||
} // namespace collage | ||
} // namespace relay | ||
} // namespace tvm | ||
|
||
#endif // TVM_RELAY_COLLAGE_CANDIDATE_FUNCTION_CACHE_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.