[Bug] Fix generating nan values in tensor
authorDonghyeon Jeong <djeong20@illinois.edu>
Tue, 1 Aug 2023 02:42:00 +0000 (11:42 +0900)
committerJijoong Moon <jijoong.moon@samsung.com>
Mon, 21 Aug 2023 06:29:23 +0000 (15:29 +0900)
- Gradient tensor values are inconsistently set to NaN
- NaN values caused incorrect backwarding in Neural Net
- Replacing malloc with calloc prevents memory allocation with value set to NaN

Signed-off-by: Donghyeon Jeong <djeong20@illinois.edu>
nntrainer/tensor/memory_pool.cpp

index 5be93ea..782dce1 100644 (file)
@@ -95,7 +95,7 @@ void MemoryPool::allocate() {
   if (mem_pool != nullptr)
     throw std::runtime_error("Memory pool is already allocated");
 
-  mem_pool = malloc(pool_size);
+  mem_pool = calloc(pool_size, 1);
   if (mem_pool == nullptr)
     throw std::runtime_error(
       "Failed to allocate memory: " + std::to_string(pool_size) + "bytes");