Mentions légales du service

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

Rewrite Transform<FPP, GPU2> getNbRow/Col, size, multiply(const FPP&) to be...

Rewrite Transform<FPP, GPU2> getNbRow/Col, size, multiply(const FPP&) to be independent from gpu_mod.
parent 7ea21feb
No related branches found
No related tags found
No related merge requests found
...@@ -2,26 +2,6 @@ ...@@ -2,26 +2,6 @@
namespace Faust namespace Faust
{ {
template<>
int32_t Transform<@FAUST_SCALAR_FOR_GM@,GPU2>::getNbRow() const
{
auto marr_funcs = GPUModHandler::get_singleton()->marr_funcs((@FAUST_SCALAR_FOR_GM@)(0));
if(gpu_mat_arr)
return marr_funcs->nrows(gpu_mat_arr);
else
return -1;
}
template<>
int32_t Transform<@FAUST_SCALAR_FOR_GM@,GPU2>::getNbCol() const
{
auto marr_funcs = GPUModHandler::get_singleton()->marr_funcs((@FAUST_SCALAR_FOR_GM@)(0));
if(gpu_mat_arr)
return marr_funcs->ncols(gpu_mat_arr);
else
return -1;
}
template<> template<>
Transform<@FAUST_SCALAR_FOR_GM@,GPU2>::Transform() : gpu_mat_arr(nullptr), dtor_delete_data(false), dtor_disabled(false), data(std::vector<MatGeneric<@FAUST_SCALAR_FOR_GM@,GPU2>*>()) Transform<@FAUST_SCALAR_FOR_GM@,GPU2>::Transform() : gpu_mat_arr(nullptr), dtor_delete_data(false), dtor_disabled(false), data(std::vector<MatGeneric<@FAUST_SCALAR_FOR_GM@,GPU2>*>())
{ {
...@@ -68,14 +48,6 @@ namespace Faust ...@@ -68,14 +48,6 @@ namespace Faust
if(!dtor_delete_data) ref_man.acquire(const_cast<MatGeneric<@FAUST_SCALAR_FOR_GM@,GPU2>*>(pushed_M)); if(!dtor_delete_data) ref_man.acquire(const_cast<MatGeneric<@FAUST_SCALAR_FOR_GM@,GPU2>*>(pushed_M));
} }
template<>
int32_t Transform<@FAUST_SCALAR_FOR_GM@,GPU2>::size() const
{
auto marr_funcs = GPUModHandler::get_singleton()->marr_funcs((@FAUST_SCALAR_FOR_GM@)(0));
if(gpu_mat_arr == nullptr) return 0;
return marr_funcs->size(gpu_mat_arr);
}
template<> template<>
void Transform<@FAUST_SCALAR_FOR_GM@,GPU2>::Display(bool transpose/*=false*/) const void Transform<@FAUST_SCALAR_FOR_GM@,GPU2>::Display(bool transpose/*=false*/) const
{ {
...@@ -305,10 +277,4 @@ namespace Faust ...@@ -305,10 +277,4 @@ namespace Faust
return out; return out;
} }
template<>
void Transform<@FAUST_SCALAR_FOR_GM@,GPU2>::multiply(const @FAUST_SCALAR_FOR_GM@& a, const int32_t id/*=-1*/)
{
auto marr_funcs = GPUModHandler::get_singleton()->marr_funcs((@FAUST_SCALAR_FOR_GM@)(0));
marr_funcs->scalar_mul_id(this->gpu_mat_arr, reinterpret_cast<const @GM_SCALAR@*>(&a), id);
}
} }
...@@ -54,11 +54,11 @@ namespace Faust ...@@ -54,11 +54,11 @@ namespace Faust
bool is_fact_dense(int id) const; bool is_fact_dense(int id) const;
bool is_fact_bsr(int id) const; bool is_fact_bsr(int id) const;
void transpose(); void transpose();
int32_t getNbRow()const; faust_unsigned_int getNbRow()const;
int32_t getNbCol()const; faust_unsigned_int getNbCol()const;
void Display(bool transpose=false) const; void Display(bool transpose=false) const;
std::string to_string(bool transpose=false) const; std::string to_string(bool transpose=false) const;
int32_t size() const; faust_unsigned_int size() const;
faust_unsigned_int get_fact_nnz(const faust_unsigned_int id) const; faust_unsigned_int get_fact_nnz(const faust_unsigned_int id) const;
faust_unsigned_int get_total_nnz() const; faust_unsigned_int get_total_nnz() const;
void update_total_nnz() const; void update_total_nnz() const;
...@@ -70,7 +70,7 @@ namespace Faust ...@@ -70,7 +70,7 @@ namespace Faust
MatDense<FPP, GPU2> sliceMultiply(const Slice s[2], MatDense<FPP, GPU2>& gpu_X, const char opThis) const; MatDense<FPP, GPU2> sliceMultiply(const Slice s[2], MatDense<FPP, GPU2>& gpu_X, const char opThis) const;
MatDense<FPP, GPU2> indexMultiply(faust_unsigned_int* ids[2], size_t id_lens[2], MatDense<FPP, GPU2>& gpu_X, const char opThis) const; MatDense<FPP, GPU2> indexMultiply(faust_unsigned_int* ids[2], size_t id_lens[2], MatDense<FPP, GPU2>& gpu_X, const char opThis) const;
void multiplyLeft(const Transform<FPP,GPU2> & A); void multiplyLeft(const Transform<FPP,GPU2> & A);
void multiply(const FPP& a, const int32_t id=-1); void multiply(const FPP& a);
Vect<FPP,GPU2> multiply(const Vect<FPP,GPU2>& x, const char opThis='N'); Vect<FPP,GPU2> multiply(const Vect<FPP,GPU2>& x, const char opThis='N');
Real<FPP> spectralNorm(int32_t nb_iter_max, float threshold, int& flag); Real<FPP> spectralNorm(int32_t nb_iter_max, float threshold, int& flag);
FPP power_iteration(int32_t nb_iter_max, float threshold, int& flag); FPP power_iteration(int32_t nb_iter_max, float threshold, int& flag);
......
namespace Faust namespace Faust
{ {
template<typename FPP>
faust_unsigned_int Transform<FPP,GPU2>::getNbRow() const // TODO: factorize with CPU code
{
if (size() != 0)
return data[0]->getNbRow();
throw std::runtime_error("Empty Transform");
}
template<typename FPP>
faust_unsigned_int Transform<FPP,GPU2>::getNbCol() const // TODO: factorize with CPU code
{
if (size() != 0)
return data[size()-1]->getNbCol();
throw std::runtime_error("Empty Transform");
}
template<typename FPP>
faust_unsigned_int Transform<FPP,GPU2>::size() const
{
return data.size();
}
template<typename FPP> template<typename FPP>
RefManager Transform<FPP,GPU2>::ref_man([](void *fact) RefManager Transform<FPP,GPU2>::ref_man([](void *fact)
{ {
...@@ -242,6 +265,28 @@ namespace Faust ...@@ -242,6 +265,28 @@ namespace Faust
return v_out; return v_out;
} }
template<typename FPP>
void Transform<FPP,GPU2>::multiply(const FPP& scalar) //TODO: factorize with CPU code (scalarMultiply)
{
// find smallest factor
if (size() == 0)
throw std::runtime_error("Empty Transform");
auto sid = 0;
auto ssize = data[0]->getNbRow() * data[0]->getNbCol();
for(auto i = 0;i < data.size(); i++)
{
auto fac = data[i];
auto s = fac->getNbRow() * fac->getNbCol();
if(s < ssize)
{
ssize = s;
sid = i;
}
}
*(data[sid]) *= scalar;
}
template<typename FPP> template<typename FPP>
MatGeneric<FPP,GPU2>* Transform<FPP,GPU2>::iterator::operator*() const MatGeneric<FPP,GPU2>* Transform<FPP,GPU2>::iterator::operator*() const
{ {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment