Mentions légales du service

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

Add GPU2 MatButterfly::get_cols/rows, norm, clone and their unit tests.

parent 3f42c120
No related branches found
No related tags found
No related merge requests found
......@@ -91,6 +91,60 @@ void test_toMatSparse(MatButterfly<FPP, GPU2> &gpu_bm, MatButterfly<FPP, Cpu> &c
cout << "OK" << endl;
}
void test_get_colsrows(MatButterfly<FPP, GPU2> &gpu_bm, MatButterfly<FPP, Cpu> &cpu_bm)
{
cout << "Test MatButterfly<FPP, GPU2>::get_rows/cols" << endl;
faust_unsigned_int start_id = cpu_bm.getNbRow()/2;
faust_unsigned_int n = cpu_bm.getNbRow()/2;
auto gpu_rows = gpu_bm.get_rows(start_id, n);
auto cpu_rows = cpu_bm.get_rows(start_id, n);
assert(verifyMatEq(MatDense<FPP, Cpu>(*dynamic_cast<MatSparse<FPP, Cpu>*>(cpu_rows)), MatDense<FPP, GPU2>(*gpu_rows)));
auto gpu_cols = gpu_bm.get_cols(start_id, n);
auto cpu_cols = cpu_bm.get_cols(start_id, n);
assert(verifyMatEq(MatDense<FPP, Cpu>(*dynamic_cast<MatSparse<FPP, Cpu>*>(cpu_cols)), MatDense<FPP, GPU2>(*gpu_cols)));
delete gpu_rows;
delete cpu_rows;
delete gpu_cols;
delete cpu_cols;
faust_unsigned_int ids[3] = {0, n, cpu_bm.getNbRow()-1};
n =3;
gpu_rows = gpu_bm.get_rows(ids, n);
cpu_rows = cpu_bm.get_rows(ids, n);
assert(verifyMatEq(MatDense<FPP, Cpu>(*dynamic_cast<MatSparse<FPP, Cpu>*>(cpu_rows)), MatDense<FPP, GPU2>(*gpu_rows)));
gpu_cols = gpu_bm.get_cols(ids, n);
cpu_cols = cpu_bm.get_cols(ids, n);
assert(verifyMatEq(MatDense<FPP, Cpu>(*dynamic_cast<MatSparse<FPP, Cpu>*>(cpu_cols)), MatDense<FPP, GPU2>(*gpu_cols)));
delete gpu_rows;
delete cpu_rows;
delete gpu_cols;
delete cpu_cols;
cout << "OK" << endl;
}
void test_norm(MatButterfly<FPP, GPU2> &gpu_bm, MatButterfly<FPP, Cpu> &cpu_bm)
{
cout << "Test MatButterfly<FPP, GPU2>::norm()" << endl;
assert(gpu_bm.norm() == cpu_bm.norm());
cout << "OK" << endl;
}
void test_clone(MatButterfly<FPP, GPU2> &gpu_bm, MatButterfly<FPP, Cpu> &cpu_bm)
{
cout << "Test MatButterfly<FPP, GPU2>::clone()" << endl;
MatSparse<FPP, Cpu> sp_test;
auto gpu_clone = gpu_bm.clone();
auto cpu_clone = cpu_bm.Clone();
gpu_clone->toMatSparse().tocpu(sp_test);
MatDense<FPP, Cpu> ds_test(sp_test);
MatDense<FPP, Cpu> ds_ref(dynamic_cast<MatButterfly<FPP, Cpu>*>(cpu_clone)->toMatSparse());
assert(verifyMatEq(ds_ref, ds_test));
delete cpu_clone;
delete gpu_clone;
cout << "OK" << endl;
}
int main(int argc, char** argv)
{
Faust::enable_gpu_mod();
......@@ -112,6 +166,9 @@ int main(int argc, char** argv)
test_get_type(gpu_bm, cpu_bm);
test_mul_matsparse(gpu_bm, cpu_bm);
test_toMatSparse(gpu_bm, cpu_bm);
test_get_colsrows(gpu_bm, cpu_bm);
test_norm(gpu_bm, cpu_bm);
test_clone(gpu_bm, cpu_bm);
return 0;
}
......@@ -28,27 +28,27 @@ namespace Faust
MatType getType() const {return Butterfly;} //TODO: move def in hpp
int32_t getNbRow() const {return d1.size();} //TODO: move def in hpp
int32_t getNbCol() const {return d1.size();} //TODO: move def in hpp
/*MatGeneric<FPP,GPU2>* clone(const int32_t dev_id=-1, const void* stream=nullptr) const;
MatGeneric<FPP,GPU2>* Clone(const bool isOptimize=false) const;
void* get_gpu_mat_ptr() const;
MatButterfly<FPP,GPU2>* clone(const int32_t dev_id=-1, const void* stream=nullptr) const;
MatButterfly<FPP,GPU2>* Clone(const bool isOptimize=false) const;
/* void* get_gpu_mat_ptr() const;
faust_unsigned_int getNonZeros() const;
void transpose();
void conjugate();
void adjoint();
void adjoint();*/
//! \brief Returns a sub-group of rows of this matrix as the same type of matrix
MatGeneric<FPP,GPU2>* get_rows(faust_unsigned_int row_id_start, faust_unsigned_int num_rows) const;
MatSparse<FPP,GPU2>* get_rows(faust_unsigned_int row_id_start, faust_unsigned_int num_rows) const;
//! \brief Returns a sub-group of rows of this matrix as the same type of matrix
MatGeneric<FPP,GPU2>* get_rows(faust_unsigned_int* row_ids, faust_unsigned_int num_rows) const;
MatSparse<FPP,GPU2>* get_rows(faust_unsigned_int* row_ids, faust_unsigned_int num_rows) const;
//! \brief Returns a sub-group of columns of this matrix as the same type of matrix
Faust::MatGeneric<FPP,GPU2>* get_cols(faust_unsigned_int col_id_start, faust_unsigned_int num_cols) const;
MatSparse<FPP,GPU2>* get_cols(faust_unsigned_int col_id_start, faust_unsigned_int num_cols) const;
//! \brief Returns a sub-group of columns of this matrix as the same type of matrix
Faust::MatGeneric<FPP,GPU2>* get_cols(faust_unsigned_int* col_ids, faust_unsigned_int num_cols) const;
MatSparse<FPP,GPU2>* get_cols(faust_unsigned_int* col_ids, faust_unsigned_int num_cols) const;
void Display() const;
Real<FPP> norm() const;*/
/*void Display() const;*/
Real<FPP> norm() const;
void multiply(MatDense<FPP, GPU2> &other, const char op_this);
void multiply(MatSparse<FPP, GPU2> &other, const char op_this);
MatSparse<FPP, GPU2> toMatSparse();
MatSparse<FPP, GPU2> toMatSparse() const;
};
}
......
......@@ -45,11 +45,66 @@ namespace Faust
template<typename FPP>
MatSparse<FPP, GPU2> MatButterfly<FPP, GPU2>::toMatSparse()
MatSparse<FPP, GPU2> MatButterfly<FPP, GPU2>::toMatSparse() const
{
MatSparse<FPP, GPU2> sp(this->getNbRow(), this->getNbCol());
sp.setEyes();
multiply(sp, 'N');
const_cast<MatButterfly<FPP, GPU2>*>(this)->multiply(sp, 'N');
return sp;
}
template<typename FPP>
MatSparse<FPP,GPU2>* MatButterfly<FPP, GPU2>::get_cols(faust_unsigned_int col_id_start, faust_unsigned_int num_cols) const
{
return toMatSparse().get_cols(col_id_start, num_cols);
}
template<typename FPP>
MatSparse<FPP,GPU2>* MatButterfly<FPP, GPU2>::get_rows(faust_unsigned_int row_id_start, faust_unsigned_int num_rows) const
{
return toMatSparse().get_rows(row_id_start, num_rows);
}
template<typename FPP>
MatSparse<FPP,GPU2>* MatButterfly<FPP, GPU2>::get_cols(faust_unsigned_int* col_ids, faust_unsigned_int num_cols) const
{
return toMatSparse().get_cols(col_ids, num_cols);
}
template<typename FPP>
MatSparse<FPP,GPU2>* MatButterfly<FPP, GPU2>::get_rows(faust_unsigned_int* row_ids, faust_unsigned_int num_rows) const
{
return toMatSparse().get_rows(row_ids, num_rows);
}
template<typename FPP>
Real<FPP> MatButterfly<FPP, GPU2>::norm() const
{
return toMatSparse().norm();
}
template<typename FPP>
MatButterfly<FPP,GPU2>* MatButterfly<FPP, GPU2>::clone(const int32_t dev_id/*=-1*/, const void* stream/*=nullptr*/) const
{
//TODO: dev_id and stream should be used
MatSparse<FPP, Cpu> cpu_sp;
toMatSparse().tocpu(cpu_sp);
//TODO/ without going throug cpu mem
return new MatButterfly<FPP, GPU2>(cpu_sp, level);
}
template<typename FPP>
MatButterfly<FPP,GPU2>* MatButterfly<FPP, GPU2>::Clone(const bool isOptimize/*=false*/) const
{
if (isOptimize)
{
throw std::runtime_error("MatButterfly doesn't handle isOptimize flag");
} else
{
return clone();
}
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment