-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge two helpers involving the kernel def hashes into one file (#10609)
* Merge two helpers involving the kernel def hashes used by ORT format models. Add codeowners entry to ensure updates involving hashes are checked.
- Loading branch information
1 parent
ea7f773
commit e0d1d69
Showing
9 changed files
with
101 additions
and
91 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
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,71 @@ | ||
#include "core/framework/kernel_def_hash_helpers.h" | ||
|
||
namespace onnxruntime { | ||
namespace utils { | ||
std::optional<HashValue> GetHashValueFromStaticKernelHashMap(const std::string& op_type, int since_version) { | ||
// Layout tranformer can add new nodes to the graph. | ||
// Since layout transformation can happen in an extended build, if these nodes are not picked up and compiled by | ||
// NNAPI or other compiling EPs then we need a way to get the hashes for these nodes. Since the infrastructure | ||
// as well as op_schema required to generate these hashes is not available in an extended minimal build, | ||
// we maintain a static map of nodes to hash value. This hash value can then be used to retireive the | ||
// kernel for the given op. | ||
static std::unordered_map<std::string, HashValue> static_kernel_hashes{ | ||
{"Transpose_1", 4324835766923221184ULL}, | ||
{"Transpose_13", 17267477159887372848ULL}, | ||
{"Squeeze_1", 12889825108950034784ULL}, | ||
{"Squeeze_11", 14725795030460042064ULL}, | ||
{"Squeeze_13", 16122603335179721968ULL}, | ||
{"UnSqueeze_1", 15964030255371555232ULL}, | ||
{"UnSqueeze_11", 16989589986691430224ULL}, | ||
{"UnSqueeze_13", 9466011545409597224ULL}, | ||
{"Gather_1", 625186873870077080ULL}, | ||
{"Gather_11", 11761559382112736008ULL}, | ||
{"Gather_13", 7462749543760614528ULL}, | ||
{"Identity_1", 18001636502361632792ULL}, | ||
{"Identity_13", 16879814636194901248ULL}, | ||
{"Identity_14", 16515685968327103576ULL}, | ||
{"Identity_16", 17661628575887109792ULL}, | ||
}; | ||
|
||
auto key = op_type + "_" + std::to_string(since_version); | ||
auto iter = static_kernel_hashes.find(key); | ||
if (iter != static_kernel_hashes.end()) { | ||
return iter->second; | ||
} | ||
|
||
return std::nullopt; | ||
} | ||
|
||
void UpdateHashForBackwardsCompatibility(HashValue& hash) { | ||
// map of old hash to new hash if we were forced to break backwards compatibility for a kernel registration | ||
// | ||
// If we need to update the hash for an existing registration, an entry needs to be added here to map the | ||
// old hash to the new. This should rarely be required as historically the only need for it was fixing | ||
// kernel registrations with invalid type constraints. Please carefully read through the information at the top of | ||
// onnxruntime/test/providers/kernel_def_hash_test.cc regarding how/when hashes might change and the best way to | ||
// address that. | ||
static const std::unordered_map<HashValue, HashValue> hashes{ | ||
// old new domain, operator, opset[, type] | ||
{2832535737534577496ULL, 16708009824840936392ULL}, // kOnnxDomain, Dropout, 7 | ||
{12198479371038564912ULL, 1718418059112844640ULL}, // kOnnxDomain, Scan, 9 | ||
{2560955351529676608ULL, 3668627007850399040ULL}, // kOnnxDomain, Scan, 11 | ||
{10232409728231027688ULL, 5212043150202938416ULL}, // kOnnxDomain, Not, 1 | ||
{11912523891622051440ULL, 10225383741733918632ULL}, // kOnnxDomain, RoiAlign, 10, float | ||
{18084231515768318048ULL, 17022700455473327752ULL}, // kOnnxDomain, RoiAlign, 10, double | ||
{14033689580222898712ULL, 634727773751317256ULL}, // kOnnxDomain, GatherND, 11 | ||
{646512416908411600ULL, 3064028185911332496ULL}, // kOnnxDomain, GatherND, 12 | ||
{15019893097608892000ULL, 11311962292460032936ULL}, // kOnnxDomain, GatherND, 13 | ||
{14259324427750852648ULL, 7767393334034626736ULL}, // kOnnxDomain, StringNormalizer, 10 | ||
// contrib ops | ||
{7642430665819070720ULL, 8620498355864235632ULL}, // kMSDomain, CropAndResize, 1 | ||
{15019666093341768288ULL, 11924582339825775592ULL}}; // kMSDomain, GridSample, 1 | ||
|
||
auto iter = hashes.find(hash); | ||
if (iter != hashes.cend()) { | ||
// hash was updated in newer version of ORT kernel registrations | ||
hash = iter->second; | ||
} | ||
} | ||
|
||
} // namespace utils | ||
} // namespace onnxruntime |
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
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
This file was deleted.
Oops, something went wrong.
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