diff --git a/src/runtime/hexagon/hexagon/hexagon_buffer.cc b/src/runtime/hexagon/hexagon/hexagon_buffer.cc index b1de44df330c..fc8cfa4efb3a 100644 --- a/src/runtime/hexagon/hexagon/hexagon_buffer.cc +++ b/src/runtime/hexagon/hexagon/hexagon_buffer.cc @@ -150,17 +150,24 @@ HexagonBuffer::HexagonBuffer(size_t nallocs, size_t nbytes, size_t alignment, Optional scope) : ndim_(2), nbytes_per_allocation_(nbytes) { SetStorageScope(scope); + + size_t nbytes_aligned = ((nbytes + (alignment - 1)) / alignment) * alignment; + size_t nbytes_monolithic = nallocs * nbytes_aligned; + + std::unique_ptr alloca = nullptr; + if (GetStorageScope() == StorageScope::kDDR) { + alloca = Allocator(nbytes_monolithic, alignment); + } else if (GetStorageScope() == StorageScope::kVTCM) { + alloca = Allocator(nbytes_monolithic, alignment); + } + CHECK(alloca) << "could not create allocation"; + for (size_t i = 0; i < nallocs; ++i) { - std::unique_ptr alloca = nullptr; - if (GetStorageScope() == StorageScope::kDDR) { - alloca = Allocator(nbytes, alignment); - } else if (GetStorageScope() == StorageScope::kVTCM) { - alloca = Allocator(nbytes, alignment); - } - CHECK(alloca != nullptr); - allocations_.push_back(alloca->data_); - managed_allocations_.push_back(std::move(alloca)); + void* alloc_offset = static_cast(alloca->data_) + i * nbytes_aligned; + allocations_.push_back(alloc_offset); } + + managed_allocations_.push_back(std::move(alloca)); } HexagonBuffer::HexagonBuffer(void* data, size_t nbytes, Optional scope)