masahi commented on a change in pull request #10663:
URL: https://github.com/apache/tvm/pull/10663#discussion_r829430684



##########
File path: src/tir/transforms/common_subexpr_elim_tools.cc
##########
@@ -743,13 +743,30 @@ bool EquivalentTerms(const PrimExpr& a, const PrimExpr& 
b) {
 std::vector<std::pair<PrimExpr, size_t>> SyntacticToSemanticComputations(
     const ComputationTable& table) {
   std::vector<std::pair<PrimExpr, size_t>> result;
+
   // table.size() is an upper-bound of the number of elements in the resulting 
vector,
   // as we might merge semantically equivalent computations.
   // We do this reservation even if it might reserve slightly more space than 
is needed in the end
   result.reserve(table.size());
 
-  // For each element in the hashtable
+  // Traverse through map in a sorted order on keys to maintain deterministic 
behavior
+  // We do this by comparing the string repr of each PrimExpr to get a 
determinstic ordering
+  std::vector<std::pair<PrimExpr, size_t>> sorted_map_items;
+  sorted_map_items.reserve(table.size());
   for (auto elem : table) {
+    sorted_map_items.push_back(elem);
+  }

Review comment:
       I think you can initialize directly by `sorted_map_items(table.begin(), 
table.end())`. Can you try it?




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to