Mentions légales du service

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

Add MatDense<FPP,GPU2>::add(MatSparse<FPP,Cpu>) and a test (update to gpu_mod@862ed4d).

Add also missing MatDense<FPP,Cpu>::add(MatSparse<FPP,Cpu>) function.
parent 2d1487c4
No related branches found
No related tags found
No related merge requests found
Subproject commit 666a08aec40867e9ab7b3ab68c735f16abfc5e7e
Subproject commit 862ed4dc10b7d7e66329396c7023d9f213d8fd59
......@@ -7,6 +7,14 @@
using namespace std;
using namespace Faust;
double calc_err(MatDense<double, GPU2> &gpu_mat, MatDense<double, Cpu> &cpu_mat)
{
auto gpu_mat_to_cpu = gpu_mat.tocpu();
auto err_diff = cpu_mat;
err_diff -= gpu_mat_to_cpu;
auto err = err_diff.norm()/cpu_mat.norm();
return err;
}
void test_mul_gpu_dense()
{
......@@ -277,6 +285,8 @@ void test_abs()
cout << "OK" << endl;
}
void test_add()
{
cout << "test add" << endl;
......@@ -292,6 +302,24 @@ void test_add()
err_diff -= gpu_mat1_to_cpu;
auto err = err_diff.norm()/cpu_mat1->norm();
assert(err < 1e-6);
Faust::MatSparse<double, Cpu> *cpu_mat3_sp = Faust::MatSparse<double, Cpu>::randMat(nrows, ncols, .2);
cpu_mat3_sp->Display();
cout << cpu_mat3_sp->to_string(false, true) << endl;
assert(calc_err(gpu_mat1, *cpu_mat1) < 1e-6);
cout << "--- gpu_mat1 after" << endl;
cout << gpu_mat1.tocpu().to_string(false, true) << endl;
cout << "--- cpu_mat1 before" << endl;
cout << cpu_mat1->to_string(false, true) << endl;
cout << "---" << endl;
cpu_mat1->add(*cpu_mat3_sp);
gpu_mat1.add(*cpu_mat3_sp);
cout << "--- cpu_mat1 after" << endl;
cout << cpu_mat1->to_string(false, true) << endl;
cout << "--- gpu_mat1 after" << endl;
cout << gpu_mat1.tocpu().to_string(false, true) << endl;
auto err_add_sp = calc_err(gpu_mat1, *cpu_mat1);
cout << err_add_sp << endl;
assert(err_add_sp < 1e-6);
cout << "OK" << endl;
}
......
......@@ -383,6 +383,9 @@ void spgemm(const Faust::MatSparse<FPP,Cpu> & A,const Faust::MatDense<FPP,Cpu> &
//! \brief (*this) = (*this) + A
void add(MatDense<FPP,Cpu> const& A);
//
//! \brief (*this) = (*this) + A
void add(MatSparse<FPP,Cpu> const& A);
//! \brief (*this) = (*this) - A
void sub(MatDense<FPP,Cpu> const& A);
......
......@@ -672,6 +672,24 @@ void Faust::MatDense<FPP,Cpu>::add(Faust::MatDense<FPP,Cpu> const& A)
#ifdef __COMPILE_TIMERS__
t_add.stop();
#endif
}
template<typename FPP>
void Faust::MatDense<FPP,Cpu>::add(Faust::MatSparse<FPP,Cpu> const& A)
{
#ifdef __COMPILE_TIMERS__
t_add.start();
#endif
if ((this->getNbCol() != A.getNbCol()) || (this->getNbRow() != A.getNbRow()))
{
handleError(m_className, "add : matrix dimension not equal");
}
mat += A.mat;
isZeros = false;
this->is_identity = false;
#ifdef __COMPILE_TIMERS__
t_add.stop();
#endif
}
template<typename FPP>
......@@ -735,7 +753,7 @@ std::string Faust::MatDense<FPP,Cpu>::to_string(const bool transpose /* set to f
str <<"zeros matrix flag" <<std::endl;
else
{
if (displaying_small_mat_elts && this->dim1*this->dim2 < 100)
if (displaying_small_mat_elts && this->dim1*this->dim2 < 1000)
{
for (int i=0 ; i<this->dim1 ; i++)
{
......
......@@ -16,12 +16,15 @@ namespace Faust
public:
MatDense(const faust_unsigned_int nbRow, const faust_unsigned_int nbCol, const FPP* data = nullptr, const bool no_alloc=false);
void add(MatDense<FPP,Cpu> const& A);
void add(MatDense<FPP,GPU2> const& A);
// *this = *this + A
void add(const MatDense<FPP,Cpu> & A);
void add(const MatDense<FPP,GPU2> & A);
void add(const MatSparse<FPP,Cpu> & A);
//TODO: void add(MatSparse<FPP,GPU2> const& A);
// 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(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');
......
......@@ -218,3 +218,10 @@ void Faust::MatDense<@FAUST_SCALAR_FOR_GM@, GPU2>::add(MatDense<@FAUST_SCALAR_FO
auto dsm_funcs = ((gm_DenseMatFunc_@GM_SCALAR@*)this->dsm_funcs);
dsm_funcs->add_cpu_dsm(gpu_mat, A.getData(), A.getNbRow(), A.getNbCol());
}
template<>
void Faust::MatDense<@FAUST_SCALAR_FOR_GM@, GPU2>::add(MatSparse<@FAUST_SCALAR_FOR_GM@,Cpu> const& A)
{
auto dsm_funcs = ((gm_DenseMatFunc_@GM_SCALAR@*)this->dsm_funcs);
dsm_funcs->add_cpu_spm(this->gpu_mat, A.getNbRow(), A.getNbCol(), A.getNonZeros(), A.getRowPtr(), A.getColInd(), A.getValuePtr());
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment