Mentions légales du service

Skip to content
Snippets Groups Projects
Commit dbe44ab9 authored by hhakim's avatar hhakim
Browse files

Update the push_back functions in pyfaust wrapper and C++ core (CPU and GPU)...

Update the push_back functions in pyfaust wrapper and C++ core (CPU and GPU) in order to remove one avoidable copy for array/MatDense factor addition in a Faust.
parent fb24cd0d
No related branches found
No related tags found
No related merge requests found
......@@ -111,6 +111,7 @@ namespace Faust
void push_back_(Head& h, Tail&... t);
//
void push_back_();
void push_back(const FPP* data, int nrows, int ncols, const bool optimizedCopy=false, const bool transpose=false, const bool conjugate=false);
void push_back(const FPP* data, const int* row_ptr, const int* id_col, const int nnz, const int nrows, const int ncols, const bool optimizedCopy=false, const bool transpose=false, const bool conjugate=false);
void push_back(const FPP* bdata, const int* brow_ptr, const int* bcol_inds, const int nrows, const int ncols, const int bnnz, const int bnrows, const int bncols, const bool optimizedCopy=false, const bool transpose=false, const bool conjugate=false);
......
......@@ -633,6 +633,15 @@ namespace Faust {
if(copying) delete bsr_mat;
}
template<typename FPP>
void TransformHelper<FPP,Cpu>::push_back(const FPP* data, int nrows, int ncols, const bool optimizedCopy/*=famse*/, const bool transpose/*=famse*/, const bool conjugate/*=famse*/)
{
auto copying = optimizedCopy||transpose||conjugate;
auto dense_mat = new MatDense<FPP, Cpu>(data, nrows, ncols);
this->push_back(dense_mat, optimizedCopy, copying, transpose, conjugate);
if(copying) delete dense_mat;
}
template<typename FPP>
void TransformHelper<FPP,Cpu>::push_back(const FPP* data, const int* row_ptr, const int* id_col, const int nnz, const int nrows, const int ncols, const bool optimizedCopy /* false by deft */, const bool transpose/*=false*/, const bool conjugate/*=false*/)
{
......@@ -1174,13 +1183,9 @@ template<typename FPP>
int num_factors = num_fac_distr(generator);
// create factors
std::vector<MatGeneric<FPP,Cpu>*> factors(num_factors);
// std::cout << "num_factors:" << num_factors << std::endl;
// std::cout << "bnnz :" << bnnz << std::endl;
for(int i=0;i<num_factors;i++)
{
factors[i] = MatBSR<FPP, Cpu>::randMat(faust_nrows, faust_ncols, bnrows, bncols, bnnz);
// std::cout << "i=" << i << " num_factors: " << num_factors; factors[i]->Display();
}
// create the Faust
TransformHelper<FPP,Cpu>* randFaust = new TransformHelper<FPP, Cpu>(factors,1.0,false,false);
return randFaust;
}
......
......@@ -24,6 +24,7 @@ namespace Faust
template<typename ...GList> TransformHelper(GList& ... t);
#endif
void push_back(const FPP* data, int nrows, int ncols, const bool optimizedCopy=false, const bool transpose=false, const bool conjugate=false);
void push_back(const FPP* data, const int* row_ptr, const int* id_col, const int nnz, const int nrows, const int ncols, const bool optimizedCopy=false, const bool transpose=false, const bool conjugate=false);
void push_back(const FPP* bdata, const int* brow_ptr, const int* bcol_inds, const int nrows, const int ncols, const int bnnz, const int bnrows, const int bncols, const bool optimizedCopy=false, const bool transpose=false, const bool conjugate=false);
void push_back(const MatGeneric<FPP,GPU2>* M, const bool optimizedCopy=false, const bool copying=true, const bool transpose=false, const bool conjugate=false);
......
......@@ -97,13 +97,22 @@ namespace Faust
this->transform->push_back(gpu_M, false);
}
template<typename FPP>
void TransformHelper<FPP,GPU2>::push_back(const FPP* data, const int nrows, const int ncols, const bool optimizedCopy/*=false*/, const bool transpose/*=false*/, const bool conjugate/*=false*/)
{
auto dense_mat = new MatDense<FPP,GPU2>(nrows, ncols, data, /* no_alloc */ false);
auto copying = transpose || conjugate || optimizedCopy;
this->push_back(dense_mat, optimizedCopy, copying, transpose, conjugate); // optimizedCopy not supported on GPU2
if(copying) delete dense_mat;
}
template<typename FPP>
void TransformHelper<FPP,GPU2>::push_back(const FPP* data, const int* row_ptr, const int* id_col, const int nnz, const int nrows, const int ncols, const bool optimizedCopy/*=false*/, const bool transpose/*=false*/, const bool conjugate/*=false*/)
{
auto sparse_mat = new MatSparse<FPP,GPU2>(nrows, ncols, nnz, data, row_ptr, id_col);
this->push_back(sparse_mat, optimizedCopy, false, transpose, conjugate);
// if(optimizedCopy) delete sparse_mat; // optimizedCopy not supported on GPU2
auto copying = transpose || conjugate || optimizedCopy;
this->push_back(sparse_mat, optimizedCopy, copying, transpose, conjugate); // optimizedCopy not supported on GPU2
if(copying) delete sparse_mat;
}
template<typename FPP>
......
......@@ -58,11 +58,8 @@ FaustCoreCpp<FPP, DEV>::FaustCoreCpp(Faust::TransformHelper<FPP,DEV> *th)
template<typename FPP, FDevice DEV>
void FaustCoreCpp<FPP,DEV>::push_back(FPP* valueMat, unsigned int nbrow, unsigned int nbcol, bool optimizedCopy /* false by deft */)
{
Faust::MatDense<FPP,DEV> dense_mat(nbrow, nbcol, valueMat);
// Faust::MatSparse<FPP,DEV> sparse_mat(dense_mat);
// sparse_mat.Display();
if(transform == nullptr) transform = new Faust::TransformHelper<FPP,DEV>();
this->transform->push_back(&dense_mat, optimizedCopy);
this->transform->push_back(valueMat, nbrow, nbcol, optimizedCopy);
}
template<typename FPP, FDevice DEV>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment