Skip to content

Commit c675bb0

Browse files
committed
[TIR][USMP] Greedy algorithms for USMP
Changed sorting criteria use alphabetic ordering as opposed to hashes of string as it seemed different accross different platforms. Change-Id: Ia7938d1b0d1374924c3ec7287526ccf374c54eb7
1 parent 7c93c60 commit c675bb0

File tree

2 files changed

+5
-9
lines changed

2 files changed

+5
-9
lines changed

src/tir/usmp/algo/greedy.cc

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -167,9 +167,7 @@ class GreedySize : public GreedyBase {
167167
[](const BufferInfo& a, const BufferInfo& b) {
168168
if (a->size_bytes->value == b->size_bytes->value) {
169169
if (a->conflicts.size() == b->conflicts.size()) {
170-
auto a_name_hash = std::hash<std::string>{}(a->name_hint->data);
171-
auto b_name_hash = std::hash<std::string>{}(b->name_hint->data);
172-
return a_name_hash > b_name_hash;
170+
return std::string(a->name_hint->data) > std::string(b->name_hint->data);
173171
} else {
174172
return a->conflicts.size() > b->conflicts.size();
175173
}
@@ -198,9 +196,7 @@ class GreedyConflicts : public GreedyBase {
198196
[](const BufferInfo& a, const BufferInfo& b) {
199197
if (a->conflicts.size() == b->conflicts.size()) {
200198
if (a->size_bytes->value == b->size_bytes->value) {
201-
auto a_name_hash = std::hash<std::string>{}(a->name_hint->data);
202-
auto b_name_hash = std::hash<std::string>{}(b->name_hint->data);
203-
return a_name_hash > b_name_hash;
199+
return std::string(a->name_hint->data) > std::string(b->name_hint->data);
204200
} else {
205201
return a->size_bytes->value > b->size_bytes->value;
206202
}

tests/python/unittest/test_tir_usmp_algo.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -149,9 +149,9 @@ def _test():
149149
buffer_info_arr = [bi_a, bi_b, bi_c]
150150
fusmp_algo = tvm.get_global_func(f"tir.usmp.algo.{algorithm}")
151151
buffer_pool_allocations = fusmp_algo(buffer_info_arr)
152-
assert buffer_pool_allocations[bi_a].byte_offset == 0
153-
assert buffer_pool_allocations[bi_b].byte_offset == 20
154-
assert buffer_pool_allocations[bi_c].byte_offset == 10
152+
assert buffer_pool_allocations[bi_a].byte_offset == 20
153+
assert buffer_pool_allocations[bi_b].byte_offset == 10
154+
assert buffer_pool_allocations[bi_c].byte_offset == 0
155155

156156
# This is tested for several times to check stability
157157
for x in range(0, 10):

0 commit comments

Comments
 (0)