From fb9066c3e802e1695105188d268adc920220a825 Mon Sep 17 00:00:00 2001 From: Andi Drebes Date: Tue, 26 Jul 2022 11:26:13 +0200 Subject: [PATCH] fix(compiler): Fix calculation of indexes for result memrefs with non-zero offsets The function `tensorDataFromMemRef` reading elements from a result memref and copying them to an instance of `TensorData` fails to handle memrefs with non-zero offsets as it adds the offset twice when calculating indexes. This may result in out-of-bounds memory accesses and incorrect results. This patch fixes the calculation of indexes by removing the second addition of the offset. --- compiler/lib/ClientLib/PublicArguments.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/lib/ClientLib/PublicArguments.cpp b/compiler/lib/ClientLib/PublicArguments.cpp index 9f4ddfe1c..188d4ebf7 100644 --- a/compiler/lib/ClientLib/PublicArguments.cpp +++ b/compiler/lib/ClientLib/PublicArguments.cpp @@ -192,7 +192,7 @@ TensorData tensorDataFromMemRef(size_t memref_rank, // TODO: add a fast path for dense result (no real strides) for (size_t i = 0; i < len; i++) { int g_index = offset + global_index(index, sizes, strides, memref_rank); - result.values[i] = aligned[offset + g_index]; + result.values[i] = aligned[g_index]; next_coord_index(index, sizes, memref_rank); } delete[] index;