Mentions légales du service

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

Update to gpu_mod@666a08ae in order to add MatDense<FPP,GPU2>::resize, setOnes,...

Update to gpu_mod@666a08ae in order to add MatDense<FPP,GPU2>::resize, setOnes, setZeros, setEyes, clone.
parent 3376b752
No related branches found
No related tags found
No related merge requests found
Subproject commit a242b935924d849d91192e29c940f8c44cb3b5fd
Subproject commit 666a08aec40867e9ab7b3ab68c735f16abfc5e7e
......@@ -12,7 +12,6 @@ void test_mul_gpu_dense()
{
faust_unsigned_int nrows = 90, ncols = 90;
faust_unsigned_int nrows2 = 90, ncols2 = 150;
double data[100];
auto cpu_mat1 = Faust::MatDense<double,Cpu>::randMat(nrows,ncols);
MatDense<double,GPU2> gpu_mat1(nrows, ncols, cpu_mat1->getData());
auto cpu_mat2 = Faust::MatDense<double,Cpu>::randMat(nrows2,ncols2);
......@@ -55,9 +54,82 @@ void test_mul_gpu_dense()
cout << "err mul.: " << err_diff.norm()/cpu_mat1_mat2_ref.norm() << endl;
}
void test_resize()
{
cout << "Test resize()" << endl;
faust_unsigned_int nrows = 90, ncols = 90;
auto cpu_mat1 = Faust::MatDense<double,Cpu>::randMat(nrows,ncols);
MatDense<double,GPU2> gpu_mat1(nrows, ncols, cpu_mat1->getData());
gpu_mat1.resize(45, 12);
}
void test_setones()
{
cout << "Test setones()" << endl;
faust_unsigned_int nrows = 9, ncols = 11;
auto cpu_mat1 = Faust::MatDense<double,Cpu>::randMat(nrows,ncols);
MatDense<double,GPU2> gpu_mat1(nrows, ncols);
gpu_mat1.setOnes();
auto gpu_mat1_to_cpu = gpu_mat1.tocpu();
// cout << gpu_mat1_to_cpu.to_string(false, true) << endl;
cpu_mat1->setOnes();
auto err_diff = *cpu_mat1;
err_diff -= gpu_mat1_to_cpu;
cout << "err setones.: " << err_diff.norm()/cpu_mat1->norm() << endl;
}
void test_setzeros()
{
cout << "Test setzeros()" << endl;
faust_unsigned_int nrows = 9, ncols = 11;
auto cpu_mat1 = Faust::MatDense<double,Cpu>::randMat(nrows,ncols);
MatDense<double,GPU2> gpu_mat1(nrows, ncols);
gpu_mat1.setZeros();
auto gpu_mat1_to_cpu = gpu_mat1.tocpu();
// cout << gpu_mat1_to_cpu.to_string(false, true) << endl;
assert(gpu_mat1_to_cpu.norm() == 0.);
}
void test_seteyes()
{
cout << "Test seteyes()" << endl;
faust_unsigned_int nrows = 11, ncols = 9;
auto cpu_mat1 = Faust::MatDense<double,Cpu>::randMat(nrows,ncols);
MatDense<double,GPU2> gpu_mat1(nrows, ncols);
gpu_mat1.setEyes();
auto gpu_mat1_to_cpu = gpu_mat1.tocpu();
cout << gpu_mat1_to_cpu.to_string(false, true) << endl;
cpu_mat1->setEyes();
auto err_diff = *cpu_mat1;
err_diff -= gpu_mat1_to_cpu;
cout << "err seteyes.: " << err_diff.norm()/cpu_mat1->norm() << endl;
}
void test_clone()
{
cout << "Test clone()" << endl;
faust_unsigned_int nrows = 11, ncols = 9;
auto cpu_mat1 = Faust::MatDense<double,Cpu>::randMat(nrows,ncols);
MatDense<double,GPU2> gpu_mat1(nrows, ncols, cpu_mat1->getData());
auto gpu_mat1_to_cpu = gpu_mat1.tocpu();
auto gpu_mat1_clone = gpu_mat1.clone();
auto gpu_mat1_clone_to_cpu = gpu_mat1_clone->tocpu();
auto err_diff = *cpu_mat1;
err_diff -= gpu_mat1_clone_to_cpu;
// cout << gpu_mat1_to_cpu.to_string(false, true) << endl;
// cout << gpu_mat1_clone_to_cpu.to_string(false, true) << endl;
cout << "err clone: " << err_diff.norm()/cpu_mat1->norm() << endl;
}
int main(int argc, char** argv)
{
Faust::enable_gpu_mod();
test_mul_gpu_dense();
test_resize();
test_setones();
test_setzeros();
test_seteyes();
test_clone();
return EXIT_SUCCESS;
}
......@@ -14,7 +14,7 @@ namespace Faust
class MatDense<FPP, GPU2> : MatDense<FPP, Cpu>
{
public:
MatDense(const faust_unsigned_int nbRow, const faust_unsigned_int nbCol, const FPP* data = nullptr);
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);
void multiply(MatDense<FPP, GPU2> &other, const char op_this='N');
......@@ -22,6 +22,12 @@ namespace Faust
// 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 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();
MatDense<FPP, GPU2>* clone();
MatDense<FPP, Cpu> tocpu();
~MatDense<FPP, GPU2>();
private:
......
......@@ -3,7 +3,8 @@ template<>
Faust::MatDense<@FAUST_SCALAR_FOR_GM@,GPU2>::MatDense(
const faust_unsigned_int nbRow,
const faust_unsigned_int nbCol,
const @FAUST_SCALAR_FOR_GM@* data/*=nullptr*/)
const @FAUST_SCALAR_FOR_GM@* data/*=nullptr*/,
const bool no_alloc/*= false*/)
{
this->dim1 = nbRow;
this->dim2 = nbCol;
......@@ -14,7 +15,7 @@ Faust::MatDense<@FAUST_SCALAR_FOR_GM@,GPU2>::MatDense(
this->spm_funcs = FaustGPU<@FAUST_SCALAR_FOR_GM@>::spm_funcs;
if(nullptr != data)
gpu_mat = ((gm_DenseMatFunc_@GM_SCALAR@*)this->dsm_funcs)->togpu(nbRow, nbCol, const_cast<@FAUST_SCALAR_FOR_GM@*>(data));
else
else if(! no_alloc)
gpu_mat = ((gm_DenseMatFunc_@GM_SCALAR@*)this->dsm_funcs)->create(nbRow, nbCol);
}
......@@ -82,4 +83,45 @@ Faust::MatDense<@FAUST_SCALAR_FOR_GM@, Cpu> Faust::MatDense<@FAUST_SCALAR_FOR_GM
return cpu_mat; //TODO: move constructor for MatDense<FPP, Cpu>
}
template<>
void Faust::MatDense<@FAUST_SCALAR_FOR_GM@,GPU2>::resize(const faust_unsigned_int nbRow, const faust_unsigned_int nbCol)
{
auto dsm_funcs = ((gm_DenseMatFunc_@GM_SCALAR@*)this->dsm_funcs);
dsm_funcs->resize(gpu_mat, nbRow, nbCol);
this->dim1 = nbRow;
this->dim2 = nbCol;
int32_t new_nrows, new_ncols;
dsm_funcs->info(gpu_mat, &new_nrows, &new_ncols);
assert(nbRow == new_nrows && new_ncols == nbCol);
}
template<>
void Faust::MatDense<@FAUST_SCALAR_FOR_GM@,GPU2>::setOnes()
{
auto dsm_funcs = ((gm_DenseMatFunc_@GM_SCALAR@*)this->dsm_funcs);
dsm_funcs->setones(gpu_mat);
}
template<>
void Faust::MatDense<@FAUST_SCALAR_FOR_GM@,GPU2>::setZeros()
{
auto dsm_funcs = ((gm_DenseMatFunc_@GM_SCALAR@*)this->dsm_funcs);
dsm_funcs->setzeros(gpu_mat);
}
template<>
void Faust::MatDense<@FAUST_SCALAR_FOR_GM@,GPU2>::setEyes()
{
auto dsm_funcs = ((gm_DenseMatFunc_@GM_SCALAR@*)this->dsm_funcs);
dsm_funcs->seteyes(gpu_mat);
}
template<>
Faust::MatDense<@FAUST_SCALAR_FOR_GM@,GPU2>* Faust::MatDense<@FAUST_SCALAR_FOR_GM@,GPU2>::clone()
{
auto dsm_funcs = ((gm_DenseMatFunc_@GM_SCALAR@*)this->dsm_funcs);
auto gpu_mat = dsm_funcs->clone(this->gpu_mat);
auto clone_mat = new Faust::MatDense<@FAUST_SCALAR_FOR_GM@,GPU2>(dim1, dim2, nullptr, /*no_alloc*/true);
clone_mat->gpu_mat = gpu_mat;
return clone_mat;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment