From b14d94eac9512dad9ebd636d0fcdf1d97107a649 Mon Sep 17 00:00:00 2001 From: Philip Hall Date: Wed, 25 Jun 2025 09:50:28 +0100 Subject: [PATCH] MLBEDSW-9267: Fix incorrect Shape hash affecting tensor cache The tensor cache was seen to be holding duplicate encoded tensors all with the same parameters but a different key hash. This turned out to be a fault in the Shape hash (which always combined 4 fields regardless of actual shape rank) generating unstable values for 3-axis architecture ublocks. - Updated Shape hash to incorporate only all valid axes. Signed-off-by: Philip Hall Change-Id: Iae11eeec0eb343caf77e8149b968ba53ba7d8afc --- ethosu/regor/common/shape.hpp | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/ethosu/regor/common/shape.hpp b/ethosu/regor/common/shape.hpp index 74293bae..b2ce928e 100644 --- a/ethosu/regor/common/shape.hpp +++ b/ethosu/regor/common/shape.hpp @@ -189,7 +189,16 @@ public: return true; } - explicit operator uint32_t() const { return At(0) ^ (At(1) << 8) ^ (At(2) << 16) ^ (At(3) << 24); } + explicit operator uint32_t() const + { + uint32_t hash = 0; + auto *local = Storage(); + for ( int i = 0; i <= _last; i++ ) + { + hash = hash * 31 + local[i]; + } + return hash; + } explicit operator uint64_t() const { return uint64_t(uint32_t(*this)); } -- GitLab