!40640 Fix robin_hood::map overflow

Merge pull request !40640 from hewei/fix_master
This commit is contained in:
i-robot 2022-08-23 05:04:35 +00:00 committed by Gitee
commit e4fc85c3ea
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
2 changed files with 4 additions and 15 deletions

View File

@ -1378,20 +1378,9 @@ ValuePtr AbstractKeywordArg::RealBuildValue() const {
}
std::size_t AbstractBasePtrListHash(const AbstractBasePtrList &args_spec_list) {
// Hash for empty list is zero.
if (args_spec_list.empty()) {
return 0;
}
// Hashing all elements is costly, we only calculate hash from
// the first element and last few elements base on some experiments.
constexpr size_t kMaxLastElements = 4;
const size_t n_args = args_spec_list.size();
// Hash from list size and the first element.
std::size_t hash_value = hash_combine(n_args, args_spec_list[0]->hash());
// Hash from last few elements.
const size_t start = ((n_args > kMaxLastElements) ? (n_args - kMaxLastElements) : 1);
for (size_t i = start; i < n_args; ++i) {
hash_value = hash_combine(hash_value, args_spec_list[i]->hash());
std::size_t hash_value = args_spec_list.size();
for (const auto &arg : args_spec_list) {
hash_value = hash_combine(hash_value, (arg == nullptr ? 0 : arg->hash()));
}
return hash_value;
}

View File

@ -217,7 +217,7 @@ def test_transformer():
assert per_step_mseconds <= expect_per_step_mseconds + 10
@pytest.mark.level1
@pytest.mark.level0
@pytest.mark.platform_arm_ascend_training
@pytest.mark.platform_x86_ascend_training
@pytest.mark.env_onecard