Skip to content

Commit

Permalink
Calculate model weights hash in parallel (openvinotoolkit#23605)
Browse files Browse the repository at this point in the history
### Details:
- Calculate model weights hash in parallel in case of reading model from
buffer

### Tickets:
 - CVS-134771
  • Loading branch information
olpipi authored and alvoron committed Apr 29, 2024
1 parent e653a34 commit 2db8ae9
Showing 1 changed file with 30 additions and 2 deletions.
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]);

// 10MB block size in size_t
const size_t block_size = 10000000 / 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

0 comments on commit 2db8ae9

Please sign in to comment.