Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
6 changes: 3 additions & 3 deletions onnxruntime/core/framework/model_metadef_id_generator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ int ModelMetadefIdGenerator::GenerateId(const onnxruntime::GraphViewer& graph_vi
// hash the bytes in the Graph instance. we can't just use the address as a new Graph instance may use
// the same memory (unit tests prove this can occur). the raw bytes of the Graph instance should be a unique
// fingerprint for the instance that can use used as the key to the hash of the model path/contents.
MurmurHash3::x86_128(&main_graph, gsl::narrow_cast<int32_t>(sizeof(Graph)), instance_hash[0], &instance_hash);
MurmurHash3::x86_128(&main_graph, sizeof(Graph), instance_hash[0], &instance_hash);
HashValue graph_instance_hash = instance_hash[0] | (uint64_t(instance_hash[1]) << 32);

// if we've already hashed this main graph instance use the cached value
Expand All @@ -42,10 +42,10 @@ int ModelMetadefIdGenerator::GenerateId(const onnxruntime::GraphViewer& graph_vi
// this may not be available if the model was loaded from a stream or in-memory bytes
const auto model_path_str = main_graph.ModelPath().string();
if (!model_path_str.empty()) {
MurmurHash3::x86_128(model_path_str.data(), gsl::narrow_cast<int32_t>(model_path_str.size()), hash[0], &hash);
MurmurHash3::x86_128(model_path_str.data(), model_path_str.size(), hash[0], &hash);
} else {
auto hash_str = [&hash](const std::string& str) {
MurmurHash3::x86_128(str.data(), gsl::narrow_cast<int32_t>(str.size()), hash[0], &hash);
MurmurHash3::x86_128(str.data(), str.size(), hash[0], &hash);
};

// fingerprint the main graph by hashing graph inputs and the ordered outputs from each node
Expand Down
24 changes: 12 additions & 12 deletions onnxruntime/core/framework/murmurhash3.cc
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ inline uint64_t rotl64(uint64_t x, int8_t r) {
//
// Changes to support big-endian from https://github.com/explosion/murmurhash/pull/27/
// were manually applied to original murmurhash3 source code.
ORT_FORCEINLINE uint32_t getblock32(const uint32_t* p, int i) {
ORT_FORCEINLINE uint32_t getblock32(const uint32_t* p, ptrdiff_t i) {
if constexpr (onnxruntime::endian::native == onnxruntime::endian::little) {
return p[i];
} else {
Expand All @@ -71,7 +71,7 @@ ORT_FORCEINLINE uint32_t getblock32(const uint32_t* p, int i) {
}
}

ORT_FORCEINLINE uint64_t getblock64(const uint64_t* p, int i) {
ORT_FORCEINLINE uint64_t getblock64(const uint64_t* p, ptrdiff_t i) {
if constexpr (onnxruntime::endian::native == onnxruntime::endian::little) {
return p[i];
} else {
Expand Down Expand Up @@ -115,10 +115,10 @@ ORT_FORCEINLINE constexpr uint64_t fmix64(uint64_t k) {
//-----------------------------------------------------------------------------

namespace onnxruntime {
void MurmurHash3::x86_32(const void* key, int len,
void MurmurHash3::x86_32(const void* key, size_t len,
uint32_t seed, void* out) {
const uint8_t* data = (const uint8_t*)key;
const int nblocks = len / 4;
const auto nblocks = static_cast<ptrdiff_t>(len / 4U);

uint32_t h1 = seed;

Expand All @@ -128,9 +128,9 @@ void MurmurHash3::x86_32(const void* key, int len,
//----------
// body

const uint32_t* blocks = (const uint32_t*)(data + static_cast<ptrdiff_t>(nblocks) * 4);
const uint32_t* blocks = (const uint32_t*)(data + nblocks * 4);

for (int i = -nblocks; i; i++) {
for (auto i = -nblocks; i; i++) {
uint32_t k1 = getblock32(blocks, i);

k1 *= c1;
Expand All @@ -145,7 +145,7 @@ void MurmurHash3::x86_32(const void* key, int len,
//----------
// tail

const uint8_t* tail = (const uint8_t*)(data + static_cast<ptrdiff_t>(nblocks) * 4);
const uint8_t* tail = (const uint8_t*)(data + nblocks * 4);

uint32_t k1 = 0;

Expand Down Expand Up @@ -176,9 +176,9 @@ void MurmurHash3::x86_32(const void* key, int len,

//-----------------------------------------------------------------------------

void MurmurHash3::x86_128(const void* key, int len, uint32_t seed, void* out) {
void MurmurHash3::x86_128(const void* key, size_t len, uint32_t seed, void* out) {
const uint8_t* data = (const uint8_t*)key;
const int nblocks = len / 16;
const auto nblocks = static_cast<ptrdiff_t>(len / 16U);

uint32_t h1 = seed;
uint32_t h2 = seed;
Expand All @@ -193,9 +193,9 @@ void MurmurHash3::x86_128(const void* key, int len, uint32_t seed, void* out) {
//----------
// body

const uint32_t* blocks = (const uint32_t*)(data + static_cast<ptrdiff_t>(nblocks) * 16);
const uint32_t* blocks = (const uint32_t*)(data + nblocks * 16);

for (int i = -nblocks; i; i++) {
for (auto i = -nblocks; i; i++) {
uint32_t k1 = getblock32(blocks, i * 4 + 0);
uint32_t k2 = getblock32(blocks, i * 4 + 1);
uint32_t k3 = getblock32(blocks, i * 4 + 2);
Expand Down Expand Up @@ -241,7 +241,7 @@ void MurmurHash3::x86_128(const void* key, int len, uint32_t seed, void* out) {
//----------
// tail

const uint8_t* tail = (const uint8_t*)(data + static_cast<ptrdiff_t>(nblocks) * 16);
const uint8_t* tail = (const uint8_t*)(data + nblocks * 16);

uint32_t k1 = 0;
uint32_t k2 = 0;
Expand Down
5 changes: 3 additions & 2 deletions onnxruntime/core/framework/murmurhash3.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@
#pragma once

#include <cstdint>
#include <cstddef>

namespace onnxruntime {
struct MurmurHash3 {
// generate 32-bit hash from input and write to 'out'
static void x86_32(const void* key, int len, uint32_t seed, void* out);
static void x86_32(const void* key, size_t len, uint32_t seed, void* out);

// generate 128-bit hash from input and write to 'out'.
static void x86_128(const void* key, int len, uint32_t seed, void* out);
static void x86_128(const void* key, size_t len, uint32_t seed, void* out);
};
} // namespace onnxruntime
4 changes: 2 additions & 2 deletions onnxruntime/core/framework/prepacked_weights.cc
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ HashValue PrePackedWeights::GetHash() const {

uint32_t hash[4] = {0, 0, 0, 0};

auto hash_int8_t_buffer = [&hash](void* data, int len) { MurmurHash3::x86_128(data, len, hash[0], &hash); };
auto hash_int8_t_buffer = [&hash](void* data, size_t len) { MurmurHash3::x86_128(data, len, hash[0], &hash); };

ORT_ENFORCE(buffers_.size() == buffer_sizes_.size());
for (size_t iter = 0; iter < buffers_.size(); ++iter) {
// some pre-packed buffers may be null if they were just "place-holders" occupying an index
// in the "buffers_" vector
if (buffers_[iter].get() != nullptr) {
hash_int8_t_buffer(buffers_[iter].get(), static_cast<int>(buffer_sizes_[iter]));
hash_int8_t_buffer(buffers_[iter].get(), buffer_sizes_[iter]);
}
}

Expand Down
2 changes: 1 addition & 1 deletion onnxruntime/core/framework/resource_accountant.cc
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ std::string IResourceAccountant::MakeUniqueNodeName(const Node& node) {

uint32_t hash[4] = {0, 0, 0, 0};
auto hash_str = [&hash](const std::string& str) {
MurmurHash3::x86_128(str.data(), narrow<int32_t>(str.size()), hash[0], &hash);
MurmurHash3::x86_128(str.data(), str.size(), hash[0], &hash);
};

const auto& node_name = (node.Name().empty()) ? node.OpType() : node.Name();
Expand Down
2 changes: 1 addition & 1 deletion onnxruntime/core/providers/cann/cann_utils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@

void GenerateHashValue(const std::string string, HashValue& hash_value) {
uint32_t hash[4] = {0, 0, 0, 0};
MurmurHash3::x86_128(string.data(), gsl::narrow_cast<int32_t>(string.size()), hash[0], &hash);
MurmurHash3::x86_128(string.data(), string.size(), hash[0], &hash);

Check warning on line 223 in onnxruntime/core/providers/cann/cann_utils.cc

View workflow job for this annotation

GitHub Actions / Optional Lint C++

[cpplint] reported by reviewdog 🐶 Add #include <string> for string [build/include_what_you_use] [4] Raw Output: onnxruntime/core/providers/cann/cann_utils.cc:223: Add #include <string> for string [build/include_what_you_use] [4]
hash_value = hash[0] | (uint64_t(hash[1]) << 32);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -775,7 +775,7 @@ std::unique_ptr<Model> CreateModel(const GraphViewer& graph_viewer, const loggin
} // namespace cann
#endif

void MurmurHash3::x86_128(const void* key, int len, uint32_t seed, void* out) {
void MurmurHash3::x86_128(const void* key, size_t len, uint32_t seed, void* out) {
return g_host->MurmurHash3__x86_128(key, len, seed, out);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1288,7 +1288,7 @@ struct ProviderHost {
virtual std::unique_ptr<Model> cann__CreateModel(const GraphViewer& graph_viewer, const logging::Logger& logger) = 0;
#endif

virtual void MurmurHash3__x86_128(const void* key, int len, uint32_t seed, void* out) = 0;
virtual void MurmurHash3__x86_128(const void* key, size_t len, uint32_t seed, void* out) = 0;

#ifdef _WIN32
virtual std::string ToUTF8String(const std::wstring& s) = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ std::string GetUniqueGraphName(const Graph& graph) {
uint32_t hash[4] = {0, 0, 0, 0};

auto hash_str = [&hash](const std::string& str) {
MurmurHash3::x86_128(str.data(), gsl::narrow_cast<int32_t>(str.size()), hash[0], &hash);
MurmurHash3::x86_128(str.data(), str.size(), hash[0], &hash);
};

// Hash all nodes' name
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -533,7 +533,7 @@ HashValue TRTGenerateId(const GraphViewer& graph_viewer, std::string trt_version
uint32_t hash[4] = {0, 0, 0, 0};

auto hash_str = [&hash](const std::string& str) {
MurmurHash3::x86_128(str.data(), gsl::narrow_cast<int32_t>(str.size()), hash[0], &hash);
MurmurHash3::x86_128(str.data(), str.size(), hash[0], &hash);
};

// Use the model's file name instead of the entire path to avoid cache regeneration if path changes
Expand Down
2 changes: 1 addition & 1 deletion onnxruntime/core/session/provider_bridge_ort.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1636,7 +1636,7 @@ struct ProviderHostImpl : ProviderHost {
}
#endif

void MurmurHash3__x86_128(const void* key, int len, uint32_t seed, void* out) override {
void MurmurHash3__x86_128(const void* key, size_t len, uint32_t seed, void* out) override {
MurmurHash3::x86_128(key, len, seed, out);
}

Expand Down
Loading