Skip to content

Commit

Permalink
update the copy assignment operator for CUDA matrix
Browse files Browse the repository at this point in the history
  • Loading branch information
sjsprecious committed Aug 29, 2024
1 parent bbe1893 commit 6a1ccdb
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions include/micm/cuda/util/cuda_dense_matrix.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,10 +129,12 @@ namespace micm
CudaDenseMatrix& operator=(const CudaDenseMatrix& other)
{
VectorMatrix<T, L>::operator=(other);
if (this->param_.d_data_ != nullptr)
if (this->param_.number_of_elements_ != other.param_.number_of_elements_)
{
CHECK_CUDA_ERROR(micm::cuda::FreeVector(this->param_), "cudaFree");
this->param_ = other.param_;
CHECK_CUDA_ERROR(micm::cuda::MallocVector<T>(this->param_, this->param_.number_of_elements_), "cudaMalloc");
this->param_ = other.param_;
CHECK_CUDA_ERROR(micm::cuda::MallocVector<T>(this->param_, this->param_.number_of_elements_), "cudaMalloc");
}
CHECK_CUDA_ERROR(micm::cuda::CopyToDeviceFromDevice<T>(this->param_, other.param_), "cudaMemcpyDeviceToDevice");
return *this;
}
Expand Down

0 comments on commit 6a1ccdb

Please sign in to comment.