Skip to content

Commit

Permalink
[FP16][Tensor] Remove unnecessary copy on save
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
DonghakPark committed Jul 1, 2024
1 parent 812fcf0 commit b7923fc
Showing 1 changed file with 1 addition and 6 deletions.
7 changes: 1 addition & 6 deletions nntrainer/tensor/tensor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3155,12 +3155,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
Expand Down

0 comments on commit b7923fc

Please sign in to comment.