Fix robin_hood::map overflow

Calculating hash from all elements in AbstractBasePtrList.
This commit is contained in:
He Wei 2022-08-19 18:57:26 +08:00
parent 1c4e2a0d41
commit 8d76635e49
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