Casting to larger dtype before performing arithmetic (#12568)
authorseongwoo chae <mhs4670go@naver.com>
Tue, 30 Jan 2024 21:22:50 +0000 (06:22 +0900)
committerChunseok Lee <chunseok.lee@samsung.com>
Thu, 1 Feb 2024 07:56:29 +0000 (16:56 +0900)
This commit casts to larger dtype before performing arithmetic.

ONE-DCO-1.0-Signed-off-by: seongwoo <mhs4670go@naver.com>

compiler/luci/pass/src/helpers/SparsityFormatConverter.cpp

index 72b7d60..c15df2a 100644 (file)
@@ -38,7 +38,9 @@ uint64_t GetFlattenedIndex(const std::vector<int> &indices, const std::vector<in
   int sub_elements = 1;
   for (int i = shape.size() - 1; i >= 0; i--)
   {
-    index += indices[i] * sub_elements;
+    assert(indices[i] >= 0);
+    assert(sub_elements >= 0);
+    index += static_cast<uint64_t>(indices[i]) * static_cast<uint64_t>(sub_elements);
     sub_elements *= shape[i];
   }
   return index;