From c6b4acd4611b272f8509f76700ad06dd4acee4b6 Mon Sep 17 00:00:00 2001 From: Jacob Bohlin Date: Wed, 7 May 2025 15:54:02 +0100 Subject: [PATCH] MLBEDSW-10764 Invalidate buffer hash when writing new values Change-Id: Icdef37a712c708cc75418f8aa4cd8033f3f70d5c Signed-off-by: Jacob Bohlin --- ethosu/regor/common/buffer_view.hpp | 22 +++++++++++++++------ ethosu/regor/compiler/scheduler_packing.cpp | 1 - 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/ethosu/regor/common/buffer_view.hpp b/ethosu/regor/common/buffer_view.hpp index 0dc848e6..92c0dfc8 100644 --- a/ethosu/regor/common/buffer_view.hpp +++ b/ethosu/regor/common/buffer_view.hpp @@ -118,7 +118,8 @@ private: Placement _placement = Placement::Remote; LocalStorage _localStorage; DeleteFunc _deleter = nullptr; - Hash128 _dataHash; + mutable Hash128 _dataHash; + mutable bool _invalidHash = true; public: Buffer(const Buffer &) = delete; @@ -327,9 +328,18 @@ public: } } - const Hash128 &Hash() const { return _dataHash; } + const Hash128 &Hash() const + { + if ( _invalidHash ) + { + Rehash(); + } + return _dataHash; + } + + void InvalidateHash() { _invalidHash = true; } - void Rehash() + void Rehash() const { if ( Size() > 0 ) { @@ -338,10 +348,8 @@ public: sizeStr += std::to_string(Size()); sizeStr += '>'; MD5 hash; - // Make sure the const overload of Data() is called - const uint8_t *data = std::as_const(*this).Data(); hash.Combine(reinterpret_cast(sizeStr.data()), int(sizeStr.size())); - hash.Combine(data, Size()); + hash.Combine(Data(), Size()); hash.Get(_dataHash); } else @@ -352,6 +360,7 @@ public: _dataHash.v32[0] = _dataHash.v32[1] = static_cast(ptr); _dataHash.v32[2] = _dataHash.v32[3] = static_cast(ptr >> 32); } + _invalidHash = false; } private: @@ -686,6 +695,7 @@ public: { assert(HasBuffer() && _strideBytes); auto *start = _buffer->Data() + _baseOffset; + _buffer->InvalidateHash(); return BufferWriter(_strideBytes, start, _elements); } diff --git a/ethosu/regor/compiler/scheduler_packing.cpp b/ethosu/regor/compiler/scheduler_packing.cpp index 60377ce9..2030d5a3 100644 --- a/ethosu/regor/compiler/scheduler_packing.cpp +++ b/ethosu/regor/compiler/scheduler_packing.cpp @@ -441,7 +441,6 @@ int SchedulerPacking::CanPack(const SchedulerOperation *schedOp, const Scheduler } // Do not pack persistent tensors with non persistent tensors - // if ( ifmTensor->isPersistent != prevOFM->isPersistent ) if ( prevOFM->isPersistent != nextOp->OFM()->tensor->isPersistent ) { return 0; -- GitLab