Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Calculate model weights hash in parallel #23605

Merged
merged 3 commits into from
Mar 22, 2024
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 30 additions & 2 deletions src/inference/src/compilation_context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#endif

#include "itt.hpp"
#include "openvino/core/parallel.hpp"
#include "openvino/pass/manager.hpp"
#include "openvino/util/file_util.hpp"
#include "openvino/util/xml_parse_utils.hpp"
Expand Down Expand Up @@ -121,8 +122,35 @@ std::string ModelCache::compute_hash(const std::string& modelStr,

auto ptr = static_cast<size_t*>(tensor.data());
size_t size = tensor.get_size() / sizeof(size_t);
for (size_t i = 0; i < size; i++)
seed = hash_combine(seed, ptr[i]);

// 1MB block size in size_t
ilya-lavrenov marked this conversation as resolved.
Show resolved Hide resolved
const size_t block_size = 1000000 / sizeof(size_t);
size_t blocks_num = size / block_size;
std::vector<uint64_t> block_hashes(blocks_num + 1, 0);

ov::parallel_for(blocks_num, [&](size_t block_idx) {
uint64_t local_hash = 0;
auto local_ptr = ptr + block_size * block_idx;
for (size_t i = 0; i < block_size; i++) {
local_hash = hash_combine(local_hash, local_ptr[i]);
}
block_hashes[block_idx] = local_hash;
});

{
uint64_t local_hash = 0;
auto local_ptr = ptr + block_size * blocks_num;
auto elements_left = size - block_size * blocks_num;
for (size_t i = 0; i < elements_left; i++) {
local_hash = hash_combine(local_hash, local_ptr[i]);
}
block_hashes[blocks_num] = local_hash;
}

for (auto hash : block_hashes) {
seed = hash_combine(seed, hash);
}

auto size_done = size * sizeof(size_t);
auto ptr_left = static_cast<uint8_t*>(tensor.data()) + size_done;
size_t size_left = tensor.get_size() - size_done;
Expand Down
Loading