[Bug] Fix memory access error in addValue
authorDonghyeon Jeong <dhyeon.jeong@samsung.com>
Thu, 20 Jul 2023 07:51:37 +0000 (16:51 +0900)
committerJijoong Moon <jijoong.moon@samsung.com>
Mon, 21 Aug 2023 06:29:23 +0000 (15:29 +0900)
- Previously memory access to tensor data was incorrect
- Change to direct access to data with index instead of calculating the index

Signed-off-by: Donghyeon Jeong <dhyeon.jeong@samsung.com>
nntrainer/tensor/tensor.h

index ad68f37..eb1279f 100644 (file)
@@ -1315,9 +1315,11 @@ public:
                 unsigned int w, float value, float beta) noexcept {
     auto const &idx = getIndex(batch, c, h, w);
     if (dim.getDataType() == Tdatatype::FP32) {
-      *(float *)(getData(idx)) = value + *(float *)(getData(idx)) * beta;
+      getData<float>()[idx] *= beta;
+      getData<float>()[idx] += value;
     } else if (dim.getDataType() == Tdatatype::FP16) {
-      *(__fp16 *)(getData(idx)) = value + *(__fp16 *)(getData(idx)) * beta;
+      getData<__fp16>()[idx] *= beta;
+      getData<__fp16>()[idx] += value;
     }
   }