[FP16][Tensor] Remove unnecessary copy on save
authorDonghak PARK <donghak.park@samsung.com>
Mon, 1 Jul 2024 05:51:37 +0000 (14:51 +0900)
committerMyungJoo Ham <myungjoo.ham@samsung.com>
Wed, 3 Jul 2024 04:41:25 +0000 (13:41 +0900)
There are unnecessary copy of tensor, in case of fp16

It seems that when developing previously, the tensor structure was not accurately established, so it attempted to save by forcibly converting to FP16.

Now, when performing getData<_FP16>(), it is automatically converted, so the process of putting every tensor one by one in the temp array is unnecessary and only slows down the speed.

**Self evaluation:**
1. Build test:  [X]Passed [ ]Failed [ ]Skipped
2. Run test:  [X]Passed [ ]Failed [ ]Skipped

Signed-off-by: Donghak PARK <donghak.park@samsung.com>
nntrainer/tensor/tensor.cpp

index c3c2362b5be8dd36a02dbc41db809dd7a2a6bab0..0997a5ee37da9d42fec89871a4b657f4c80d84b8 100644 (file)
@@ -3150,12 +3150,7 @@ void Tensor::save(std::ostream &file) {
                  "[Tensor::save] operation failed");
   } else if (this->getDataType() == ml::train::TensorDim::DataType::FP16) {
 #ifdef ENABLE_FP16
-    std::vector<_FP16> temp(size());
-    for (unsigned int i = 0; i < size(); ++i) {
-      temp[i] = static_cast<_FP16>(getData<_FP16>()[i]);
-    }
-
-    checkedWrite(file, (char *)temp.data(),
+    checkedWrite(file, (char *)getData<_FP16>(),
                  static_cast<std::streamsize>(size() * sizeof(_FP16)),
                  "[Tensor::save] operation failed");
 #else