Mentions légales du service

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

Update to gpu_mod@d9bda3c8 and add functions to MatDense<FPP,GPU2>:...

Update to gpu_mod@d9bda3c8 and add functions to MatDense<FPP,GPU2>: multiply(Vect<FPP,CPU>), scalarMultiply, transpose, adjoint, conjugate, spectralNorm, norm, normalize and associated tests.
parent c4f42d45
No related branches found
No related tags found
No related merge requests found
......@@ -16,17 +16,25 @@ namespace Faust
public:
MatDense(const faust_unsigned_int nbRow, const faust_unsigned_int nbCol, const FPP* data = nullptr, const bool no_alloc=false);
// multiply(const Vect<Cpu,FPP> &vec);
// vec = this * vec
Vect<FPP, Cpu> multiply(const Vect<FPP, Cpu> &vec);
void multiply(MatDense<FPP, GPU2> &other, const char op_this='N');
void multiply(MatDense<FPP,Cpu> &other, const char op_this='N');
// void multiply(MatSparse<FPP, Cpu> &other, MatDense<FPP, GPU2>& output, const char op_this='N');
void multiply(const MatSparse<FPP, Cpu> &other, MatDense<FPP, Cpu>& output, const char op_this='N');
void multiply(const MatSparse<FPP, Cpu> &other, MatDense<FPP, GPU2>& output, const char op_this='N');
void scalarMultiply(const FPP& lambda);
void resize(const faust_unsigned_int nbRow, const faust_unsigned_int nbCol);
void resize(const faust_unsigned_int nbRow){resize(nbRow,nbRow);}
void setOnes();
void setZeros();
void setEyes();
void transpose();
void conjugate();
void adjoint();
Real<FPP> spectralNorm(const faust_unsigned_int nbr_iter_max, const float threshold);
Real<FPP> norm();
void normalize();
MatDense<FPP, GPU2>* clone();
MatDense<FPP, Cpu> tocpu();
~MatDense<FPP, GPU2>();
......
......@@ -47,6 +47,16 @@ void Faust::MatDense<@FAUST_SCALAR_FOR_GM@,GPU2>::multiply(MatDense<@FAUST_SCALA
other.dim1 = dim1;
}
template<>
Faust::Vect<@FAUST_SCALAR_FOR_GM@,Cpu> Faust::MatDense<@FAUST_SCALAR_FOR_GM@,GPU2>::multiply(const Faust::Vect<@FAUST_SCALAR_FOR_GM@, Cpu> &vec)
{
auto dsm_funcs = ((gm_DenseMatFunc_@GM_SCALAR@*)this->dsm_funcs);
MatDense<@FAUST_SCALAR_FOR_GM@, GPU2> gpu_vec(vec.size(), 1, vec.getData());
Faust::Vect<@FAUST_SCALAR_FOR_GM@, Cpu> out_v(dim2);
dsm_funcs->mul_gpu_dsm_tocpu_ext(this->gpu_mat, gpu_vec.gpu_mat, out_v.getData(), OP_NOTRANSP, OP_NOTRANSP);
return out_v;
}
template<>
void Faust::MatDense<@FAUST_SCALAR_FOR_GM@,GPU2>::multiply(const MatSparse<@FAUST_SCALAR_FOR_GM@, Cpu> &other, MatDense<@FAUST_SCALAR_FOR_GM@,Cpu>& output, const char op_this)
{
......@@ -74,6 +84,13 @@ void Faust::MatDense<@FAUST_SCALAR_FOR_GM@,GPU2>::multiply(const MatSparse<@FAUS
spm_funcs->free(other_gpu);
}
template<>
void Faust::MatDense<@FAUST_SCALAR_FOR_GM@,GPU2>::scalarMultiply(const @FAUST_SCALAR_FOR_GM@& lambda)
{
auto dsm_funcs = ((gm_DenseMatFunc_@GM_SCALAR@*)this->dsm_funcs);
dsm_funcs->mul_scalar(gpu_mat, &lambda);
}
template<>
Faust::MatDense<@FAUST_SCALAR_FOR_GM@, Cpu> Faust::MatDense<@FAUST_SCALAR_FOR_GM@,GPU2>::tocpu()
{
......@@ -125,3 +142,51 @@ Faust::MatDense<@FAUST_SCALAR_FOR_GM@,GPU2>* Faust::MatDense<@FAUST_SCALAR_FOR_G
clone_mat->gpu_mat = gpu_mat;
return clone_mat;
}
template<>
void Faust::MatDense<@FAUST_SCALAR_FOR_GM@,GPU2>::transpose()
{
auto dsm_funcs = ((gm_DenseMatFunc_@GM_SCALAR@*)this->dsm_funcs);
dsm_funcs->transpose(this->gpu_mat);
auto tmp = dim1;
dim1 = dim2;
dim2 = tmp;
}
template<>
void Faust::MatDense<@FAUST_SCALAR_FOR_GM@,GPU2>::adjoint()
{
auto dsm_funcs = ((gm_DenseMatFunc_@GM_SCALAR@*)this->dsm_funcs);
dsm_funcs->adjoint(this->gpu_mat);
auto tmp = dim1;
dim1 = dim2;
dim2 = tmp;
}
template<>
void Faust::MatDense<@FAUST_SCALAR_FOR_GM@,GPU2>::conjugate()
{
auto dsm_funcs = ((gm_DenseMatFunc_@GM_SCALAR@*)this->dsm_funcs);
dsm_funcs->conjugate(this->gpu_mat);
}
template<>
Real<@FAUST_SCALAR_FOR_GM@> Faust::MatDense<@FAUST_SCALAR_FOR_GM@,GPU2>::spectralNorm(const faust_unsigned_int nbr_iter_max, const float threshold)
{
auto dsm_funcs = ((gm_DenseMatFunc_@GM_SCALAR@*)this->dsm_funcs);
return dsm_funcs->norm_spectral(gpu_mat, threshold, nbr_iter_max);
}
template<>
Real<@FAUST_SCALAR_FOR_GM@> Faust::MatDense<@FAUST_SCALAR_FOR_GM@,GPU2>::norm()
{
auto dsm_funcs = ((gm_DenseMatFunc_@GM_SCALAR@*)this->dsm_funcs);
return dsm_funcs->norm_frob(gpu_mat);
}
template<>
void Faust::MatDense<@FAUST_SCALAR_FOR_GM@,GPU2>::normalize()
{
auto dsm_funcs = ((gm_DenseMatFunc_@GM_SCALAR@*)this->dsm_funcs);
dsm_funcs->normalize(gpu_mat);
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment