Skip to content

Commit 25d0bd3

Browse files
apivovarovminlu1021
authored andcommitted
Fix RelayVM for 32-bit platforms (apache#7605)
1 parent 031ddf2 commit 25d0bd3

File tree

3 files changed

+17
-13
lines changed

3 files changed

+17
-13
lines changed

src/runtime/vm/executable.cc

+3-9
Original file line numberDiff line numberDiff line change
@@ -252,11 +252,7 @@ void Executable::SaveConstantSection(dmlc::Stream* strm) {
252252
}
253253

254254
// Save the const to device mapping.
255-
std::vector<size_t> const_device_type;
256-
for (auto dev_type : this->const_device_type) {
257-
const_device_type.push_back(static_cast<size_t>(dev_type));
258-
}
259-
strm->Write(const_device_type);
255+
strm->Write(this->const_device_type);
260256
}
261257

262258
void Executable::SavePrimitiveOpNames(dmlc::Stream* strm) {
@@ -525,12 +521,10 @@ void Executable::LoadConstantSection(dmlc::Stream* strm) {
525521
}
526522

527523
// Load the const to device mapping.
528-
std::vector<size_t> const_device_type;
524+
std::vector<Index> const_device_type;
529525
STREAM_CHECK(strm->Read(&const_device_type), "constant");
530526
ICHECK_EQ(size, const_device_type.size());
531-
for (auto dev : const_device_type) {
532-
this->const_device_type.push_back(static_cast<Index>(dev));
533-
}
527+
this->const_device_type = const_device_type;
534528
}
535529

536530
void Executable::LoadPrimitiveOpNames(dmlc::Stream* strm) {

src/runtime/vm/serialize_utils.h

+5-4
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,15 @@
2424
#ifndef TVM_RUNTIME_VM_SERIALIZE_UTILS_H_
2525
#define TVM_RUNTIME_VM_SERIALIZE_UTILS_H_
2626

27-
#include <dmlc/common.h>
2827
#include <dmlc/memory_io.h>
2928
#include <tvm/runtime/vm/executable.h>
3029

3130
#include <functional>
3231
#include <string>
3332
#include <vector>
3433

34+
#include "../../support/utils.h"
35+
3536
namespace tvm {
3637
namespace runtime {
3738
namespace vm {
@@ -40,9 +41,9 @@ namespace vm {
4041
constexpr uint64_t kTVMVMBytecodeMagic = 0xD225DE2F4214151D;
4142

4243
template <typename T>
43-
static inline size_t VectorHash(size_t key, const std::vector<T>& values) {
44+
static inline uint64_t VectorHash(uint64_t key, const std::vector<T>& values) {
4445
for (const auto& it : values) {
45-
key = dmlc::HashCombine(key, it);
46+
key = support::HashCombine(key, it);
4647
}
4748
return key;
4849
}
@@ -122,7 +123,7 @@ struct VMInstructionSerializer {
122123
* instruction.
123124
*/
124125
Index Hash() const {
125-
size_t key = static_cast<size_t>(opcode);
126+
uint64_t key = static_cast<uint64_t>(opcode);
126127
key = VectorHash(key, fields);
127128
return key;
128129
}

src/support/utils.h

+9
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,15 @@ inline size_t HashCombine(size_t key, size_t value) {
162162
return key ^ (value + 0x9e3779b9 + (key << 6) + (key >> 2));
163163
}
164164

165+
/*!
166+
* \brief hash an object and combines uint64_t key with previous keys
167+
*/
168+
template <typename T>
169+
inline uint64_t HashCombine(uint64_t key, const T& value) {
170+
std::hash<T> hash_func;
171+
return key ^ (hash_func(value) + 0x9e3779b9 + (key << 6) + (key >> 2));
172+
}
173+
165174
} // namespace support
166175
} // namespace tvm
167176
#endif // TVM_SUPPORT_UTILS_H_

0 commit comments

Comments
 (0)