void OCLAcceleratorMatrixCOO<ValueType>::CopyFrom(const BaseMatrix<ValueType> &src) { const OCLAcceleratorMatrixCOO<ValueType> *ocl_cast_mat; const HostMatrix<ValueType> *host_cast_mat; // copy only in the same format assert(this->get_mat_format() == src.get_mat_format()); // OCL to OCL copy if ((ocl_cast_mat = dynamic_cast<const OCLAcceleratorMatrixCOO<ValueType>*> (&src)) != NULL) { if (this->get_nnz() == 0) this->AllocateCOO(src.get_nnz(), src.get_nrow(), src.get_ncol() ); assert((this->get_nnz() == src.get_nnz()) && (this->get_nrow() == src.get_nrow()) && (this->get_ncol() == src.get_ncol()) ); if (this->get_nnz() > 0) { // Copy object from device to device memory (internal copy) ocl_dev2dev<int>(this->get_nnz(), // size ocl_cast_mat->mat_.row, // src this->mat_.row, // dst OCL_HANDLE(this->local_backend_.OCL_handle)->OCL_cmdQueue ); // Copy object from device to device memory (internal copy) ocl_dev2dev<int>(this->get_nnz(), // size ocl_cast_mat->mat_.col, // src this->mat_.col, // dst OCL_HANDLE(this->local_backend_.OCL_handle)->OCL_cmdQueue ); // Copy object from device to device memory (internal copy) ocl_dev2dev<ValueType>(this->get_nnz(), // size ocl_cast_mat->mat_.val, // src this->mat_.val, // dst OCL_HANDLE(this->local_backend_.OCL_handle)->OCL_cmdQueue ); } } else { //CPU to OCL if ((host_cast_mat = dynamic_cast<const HostMatrix<ValueType>*> (&src)) != NULL) { this->CopyFromHost(*host_cast_mat); } else { LOG_INFO("Error unsupported OCL matrix type"); this->info(); src.info(); FATAL_ERROR(__FILE__, __LINE__); } } }
void MICAcceleratorMatrixCOO<ValueType>::CopyFrom(const BaseMatrix<ValueType> &src) { const MICAcceleratorMatrixCOO<ValueType> *mic_cast_mat; const HostMatrix<ValueType> *host_cast_mat; // copy only in the same format assert(this->get_mat_format() == src.get_mat_format()); // MIC to MIC copy if ((mic_cast_mat = dynamic_cast<const MICAcceleratorMatrixCOO<ValueType>*> (&src)) != NULL) { if (this->get_nnz() == 0) this->AllocateCOO(src.get_nnz(), src.get_nrow(), src.get_ncol() ); assert((this->get_nnz() == src.get_nnz()) && (this->get_nrow() == src.get_nrow()) && (this->get_ncol() == src.get_ncol()) ); if (this->get_nnz() > 0) { copy_mic_mic(this->local_backend_.MIC_dev, mic_cast_mat->mat_.row, this->mat_.row, this->get_nnz()); copy_mic_mic(this->local_backend_.MIC_dev, mic_cast_mat->mat_.col, this->mat_.col, this->get_nnz()); copy_mic_mic(this->local_backend_.MIC_dev, mic_cast_mat->mat_.val, this->mat_.val, this->get_nnz()); } } else { //CPU to MIC if ((host_cast_mat = dynamic_cast<const HostMatrix<ValueType>*> (&src)) != NULL) { this->CopyFromHost(*host_cast_mat); } else { LOG_INFO("Error unsupported MIC matrix type"); this->info(); src.info(); FATAL_ERROR(__FILE__, __LINE__); } } }
bool HostMatrixCOO<ValueType>::ConvertFrom(const BaseMatrix<ValueType> &mat) { this->Clear(); // empty matrix is empty matrix if (mat.get_nnz() == 0) return true; if (const HostMatrixCOO<ValueType> *cast_mat = dynamic_cast<const HostMatrixCOO<ValueType>*> (&mat)) { this->CopyFrom(*cast_mat); return true; } if (const HostMatrixCSR<ValueType> *cast_mat = dynamic_cast<const HostMatrixCSR<ValueType>*> (&mat)) { this->Clear(); csr_to_coo(this->local_backend_.OpenMP_threads, cast_mat->get_nnz(), cast_mat->get_nrow(), cast_mat->get_ncol(), cast_mat->mat_, &this->mat_); this->nrow_ = cast_mat->get_nrow(); this->ncol_ = cast_mat->get_ncol(); this->nnz_ = cast_mat->get_nnz(); return true; } return false; }
void HostMatrixCOO<ValueType>::CopyFrom(const BaseMatrix<ValueType> &mat) { // copy only in the same format assert(this->get_mat_format() == mat.get_mat_format()); if (const HostMatrixCOO<ValueType> *cast_mat = dynamic_cast<const HostMatrixCOO<ValueType>*> (&mat)) { if (this->get_nnz() == 0) this->AllocateCOO(mat.get_nnz(), mat.get_nrow(), mat.get_ncol() ); assert((this->get_nnz() == mat.get_nnz()) && (this->get_nrow() == mat.get_nrow()) && (this->get_ncol() == mat.get_ncol()) ); if (this->get_nnz() > 0) { omp_set_num_threads(this->local_backend_.OpenMP_threads); #pragma omp parallel for for (int j=0; j<this->get_nnz(); ++j) this->mat_.row[j] = cast_mat->mat_.row[j]; #pragma omp parallel for for (int j=0; j<this->get_nnz(); ++j) this->mat_.col[j] = cast_mat->mat_.col[j]; #pragma omp parallel for for (int j=0; j<this->get_nnz(); ++j) this->mat_.val[j] = cast_mat->mat_.val[j]; } } else { // Host matrix knows only host matrices // -> dispatching mat.CopyTo(this); } }
void OCLAcceleratorMatrixBCSR<ValueType>::CopyFrom(const BaseMatrix<ValueType> &src) { const OCLAcceleratorMatrixBCSR<ValueType> *ocl_cast_mat; const HostMatrix<ValueType> *host_cast_mat; // copy only in the same format assert(this->get_mat_format() == src.get_mat_format()); // OCL to OCL copy if ((ocl_cast_mat = dynamic_cast<const OCLAcceleratorMatrixBCSR<ValueType>*> (&src)) != NULL) { if (this->get_nnz() == 0) this->AllocateBCSR(src.get_nnz(), src.get_nrow(), src.get_ncol() ); assert((this->get_nnz() == src.get_nnz()) && (this->get_nrow() == src.get_nrow()) && (this->get_ncol() == src.get_ncol()) ); ocl_cast_mat->get_nnz(); FATAL_ERROR(__FILE__, __LINE__); } else { //CPU to OCL if ((host_cast_mat = dynamic_cast<const HostMatrix<ValueType>*> (&src)) != NULL) { this->CopyFromHost(*host_cast_mat); } else { LOG_INFO("Error unsupported OCL matrix type"); this->info(); src.info(); FATAL_ERROR(__FILE__, __LINE__); } } }
void MICAcceleratorMatrixDIA<ValueType>::CopyFrom(const BaseMatrix<ValueType> &src) { const MICAcceleratorMatrixDIA<ValueType> *mic_cast_mat; const HostMatrix<ValueType> *host_cast_mat; // copy only in the same format assert(this->get_mat_format() == src.get_mat_format()); // MIC to MIC copy if ((mic_cast_mat = dynamic_cast<const MICAcceleratorMatrixDIA<ValueType>*> (&src)) != NULL) { if (this->get_nnz() == 0) this->AllocateDIA(mic_cast_mat->get_nnz(), mic_cast_mat->get_nrow(), mic_cast_mat->get_ncol(), mic_cast_mat->get_ndiag()); assert((this->get_nnz() == src.get_nnz()) && (this->get_nrow() == src.get_nrow()) && (this->get_ncol() == src.get_ncol()) ); if (this->get_nnz() > 0) { copy_mic_mic(mic_cast_mat->mat_.val, this->mat_.val, this->get_nnz()); copy_mic_mic(mic_cast_mat->mat_.offset, this->mat_.offset, this->mat_.num_diag); /* // TODO for (int j=0; j<this->get_nnz(); ++j) this->mat_.val[j] = mic_cast_mat->mat_.val[j]; for (int j=0; j<this->mat_.num_diag; ++j) this->mat_.offset[j] = mic_cast_mat->mat_.offset[j]; */ } } else { //CPU to MIC if ((host_cast_mat = dynamic_cast<const HostMatrix<ValueType>*> (&src)) != NULL) { this->CopyFromHost(*host_cast_mat); } else { LOG_INFO("Error unsupported MIC matrix type"); this->info(); src.info(); FATAL_ERROR(__FILE__, __LINE__); } } }
bool MICAcceleratorMatrixHYB<ValueType>::ConvertFrom(const BaseMatrix<ValueType> &mat) { this->Clear(); // empty matrix is empty matrix if (mat.get_nnz() == 0) return true; const MICAcceleratorMatrixHYB<ValueType> *cast_mat_hyb; if ((cast_mat_hyb = dynamic_cast<const MICAcceleratorMatrixHYB<ValueType>*> (&mat)) != NULL) { this->CopyFrom(*cast_mat_hyb); return true; } return false; }
bool OCLAcceleratorMatrixBCSR<ValueType>::ConvertFrom(const BaseMatrix<ValueType> &mat) { this->Clear(); // empty matrix is empty matrix if (mat.get_nnz() == 0) return true; const OCLAcceleratorMatrixBCSR<ValueType> *cast_mat_bcsr; if ((cast_mat_bcsr = dynamic_cast<const OCLAcceleratorMatrixBCSR<ValueType>*> (&mat)) != NULL) { this->CopyFrom(*cast_mat_bcsr); return true; } /* const OCLAcceleratorMatrixCSR<ValueType> *cast_mat_csr; if ((cast_mat_csr = dynamic_cast<const OCLAcceleratorMatrixCSR<ValueType>*> (&mat)) != NULL) { this->Clear(); FATAL_ERROR(__FILE__, __LINE__); this->nrow_ = cast_mat_csr->get_nrow(); this->ncol_ = cast_mat_csr->get_ncol(); this->nnz_ = cast_mat_csr->get_nnz(); return 0; } */ return false; }
void MICAcceleratorMatrixHYB<ValueType>::CopyFrom(const BaseMatrix<ValueType> &src) { const MICAcceleratorMatrixHYB<ValueType> *mic_cast_mat; const HostMatrix<ValueType> *host_cast_mat; // copy only in the same format assert(this->get_mat_format() == src.get_mat_format()); // MIC to MIC copy if ((mic_cast_mat = dynamic_cast<const MICAcceleratorMatrixHYB<ValueType>*> (&src)) != NULL) { if (this->get_nnz() == 0) this->AllocateHYB(mic_cast_mat->get_ell_nnz(), mic_cast_mat->get_coo_nnz(), mic_cast_mat->get_ell_max_row(), mic_cast_mat->get_nrow(), mic_cast_mat->get_ncol()); assert((this->get_nnz() == src.get_nnz()) && (this->get_nrow() == src.get_nrow()) && (this->get_ncol() == src.get_ncol()) ); // TODO if (this->get_ell_nnz() > 0) { copy_mic_mic(mic_cast_mat->mat_.ELL.val, this->mat_.ELL.val, this->get_ell_nnz()); copy_mic_mic(mic_cast_mat->mat_.ELL.col, this->mat_.ELL.col, this->get_ell_nnz()); /* // ELL for (int i=0; i<this->get_ell_nnz(); ++i) this->mat_.ELL.col[i] = mic_cast_mat->mat_.ELL.col[i]; for (int i=0; i<this->get_ell_nnz(); ++i) this->mat_.ELL.val[i] = mic_cast_mat->mat_.ELL.val[i]; */ } if (this->get_coo_nnz() > 0) { copy_mic_mic(mic_cast_mat->mat_.COO.row, this->mat_.COO.row, this->get_coo_nnz()); copy_mic_mic(mic_cast_mat->mat_.COO.col, this->mat_.COO.col, this->get_coo_nnz()); copy_mic_mic(mic_cast_mat->mat_.COO.val, this->mat_.COO.val, this->get_coo_nnz()); /* // COO for (int i=0; i<this->get_coo_nnz(); ++i) this->mat_.COO.row[i] = mic_cast_mat->mat_.COO.row[i]; for (int i=0; i<this->get_coo_nnz(); ++i) this->mat_.COO.col[i] = mic_cast_mat->mat_.COO.col[i]; for (int i=0; i<this->get_coo_nnz(); ++i) this->mat_.COO.val[i] = mic_cast_mat->mat_.COO.val[i]; */ } } else { //CPU to MIC if ((host_cast_mat = dynamic_cast<const HostMatrix<ValueType>*> (&src)) != NULL) { this->CopyFromHost(*host_cast_mat); } else { LOG_INFO("Error unsupported MIC matrix type"); this->info(); src.info(); FATAL_ERROR(__FILE__, __LINE__); } } }
void OCLAcceleratorMatrixHYB<ValueType>::CopyFrom(const BaseMatrix<ValueType> &src) { const OCLAcceleratorMatrixHYB<ValueType> *ocl_cast_mat; const HostMatrix<ValueType> *host_cast_mat; // copy only in the same format assert(this->get_mat_format() == src.get_mat_format()); // OCL to OCL copy if ((ocl_cast_mat = dynamic_cast<const OCLAcceleratorMatrixHYB<ValueType>*> (&src)) != NULL) { if (this->get_nnz() == 0) this->AllocateHYB(ocl_cast_mat->get_ell_nnz(), ocl_cast_mat->get_coo_nnz(), ocl_cast_mat->get_ell_max_row(), ocl_cast_mat->get_nrow(), ocl_cast_mat->get_ncol()); assert((this->get_nnz() == src.get_nnz()) && (this->get_nrow() == src.get_nrow()) && (this->get_ncol() == src.get_ncol()) ); if (this->get_ell_nnz() > 0) { // ELL // must be within same opencl context ocl_dev2dev<int>(this->get_ell_nnz(), // size ocl_cast_mat->mat_.ELL.col, // src this->mat_.ELL.col, // dst OCL_HANDLE(this->local_backend_.OCL_handle)->OCL_cmdQueue ); ocl_dev2dev<ValueType>(this->get_ell_nnz(), // size ocl_cast_mat->mat_.ELL.val, // src this->mat_.ELL.val, // dst OCL_HANDLE(this->local_backend_.OCL_handle)->OCL_cmdQueue ); } if (this->get_coo_nnz() > 0) { // COO // must be within same opencl context ocl_dev2dev<int>(this->get_coo_nnz(), // size ocl_cast_mat->mat_.COO.row, // src this->mat_.COO.row, // dst OCL_HANDLE(this->local_backend_.OCL_handle)->OCL_cmdQueue ); ocl_dev2dev<int>(this->get_coo_nnz(), // size ocl_cast_mat->mat_.COO.col, // src this->mat_.COO.col, // dst OCL_HANDLE(this->local_backend_.OCL_handle)->OCL_cmdQueue ); ocl_dev2dev<ValueType>(this->get_coo_nnz(), // size ocl_cast_mat->mat_.COO.val, // src this->mat_.COO.val, // dst OCL_HANDLE(this->local_backend_.OCL_handle)->OCL_cmdQueue ); } } else { //CPU to OCL if ((host_cast_mat = dynamic_cast<const HostMatrix<ValueType>*> (&src)) != NULL) { this->CopyFromHost(*host_cast_mat); } else { LOG_INFO("Error unsupported OCL matrix type"); this->info(); src.info(); FATAL_ERROR(__FILE__, __LINE__); } } }