aboutsummaryrefslogtreecommitdiff
path: root/src/TosaSerialize.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/TosaSerialize.cpp')
-rw-r--r--src/TosaSerialize.cpp15
1 files changed, 12 insertions, 3 deletions
diff --git a/src/TosaSerialize.cpp b/src/TosaSerialize.cpp
index 5699ffe..0557520 100644
--- a/src/TosaSerialize.cpp
+++ b/src/TosaSerialize.cpp
@@ -24,6 +24,7 @@
#include "tosa_serialization_handler.h"
#include <functional>
#include <unordered_map>
+#include <map>
// The namespace might be confusing here. We have mlir::tosa:: defined in MLIR
// and tosa:: defined in serialization library
@@ -1510,9 +1511,17 @@ mlir::LogicalResult TosaSerializationBlockBuilder::BuildAllOpsInRegion(
}
// Build tensor
- for (auto pair : tensor_map) {
- ser_tensor = BuildTosaSerializationTensor(pair.first /* val */,
- pair.second /* name */);
+
+ // The tensor_map is sorted by hashed mlir::Value types.
+ // For serialization, sort tensors alphabetically by name for a deterministic
+ // and human-friendly ordering.
+ std::map<std::string, mlir::Value> tensor_name_sort;
+ for (auto pair : tensor_map)
+ tensor_name_sort[pair.second] = pair.first;
+
+ for (auto pair : tensor_name_sort) {
+ ser_tensor = BuildTosaSerializationTensor(pair.second /* val */,
+ pair.first /* name */);
if (!ser_tensor) {
llvm::errs() << "ERROR: Failed to build TosaSerializationTensor\n";
return mlir::failure();