Mentions légales du service

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

Implement MatBSR<FPP,...

Implement MatBSR<FPP, GPU>::getNbRow/getNbcol/getNonZeros/getNBytes/getDevice/norm/setZeros and their unit tests.

Update to gpu_mod@3904f39e
parent f5a7f449
Branches
Tags
No related merge requests found
Subproject commit 40121cf1a95088da5223d741bf7465a896d40405
Subproject commit 3904f39eabcdf828cd474fad55e8b85882281d90
......@@ -190,6 +190,65 @@ void test_conjugate()
delete cpu_bsr_mat;
}
void test_norm()
{
std::cout << "test_norm" << std::endl;
auto nrows = 10;
auto ncols = 8;
auto bnrows = 2;
auto bncols = 2;
auto bnnz = 2;
auto cpu_bsr_mat = Faust::MatBSR<FPP, Cpu>::randMat(nrows, ncols, bnrows, bncols, bnnz);
Faust::MatBSR<FPP, GPU2> gpu_bsr_mat(*cpu_bsr_mat);
assert(std::abs(cpu_bsr_mat->norm()-gpu_bsr_mat.norm()) < 1e-3);
cout << "OK" << endl;
delete cpu_bsr_mat;
}
void test_infos()
{
std::cout << "test_infos" << std::endl;
auto nrows = 10;
auto ncols = 8;
auto bnrows = 2;
auto bncols = 2;
auto bnnz = 2;
auto cpu_bsr_mat = Faust::MatBSR<FPP, Cpu>::randMat(nrows, ncols, bnrows, bncols, bnnz);
Faust::MatBSR<FPP, GPU2> gpu_bsr_mat(*cpu_bsr_mat);
assert(cpu_bsr_mat->getType() == gpu_bsr_mat.getType());
assert(cpu_bsr_mat->getNbRow() == gpu_bsr_mat.getNbRow());
assert(cpu_bsr_mat->getNbCol() == gpu_bsr_mat.getNbCol());
assert(cpu_bsr_mat->getNonZeros() == gpu_bsr_mat.getNonZeros());
assert(cpu_bsr_mat->getNBytes() == gpu_bsr_mat.getNBytes());
cpu_bsr_mat->Display();
gpu_bsr_mat.Display();
cout << "OK" << endl;
delete cpu_bsr_mat;
}
void test_set_zeros()
{
std::cout << "test_set_zeros" << std::endl;
auto nrows = 10;
auto ncols = 8;
auto bnrows = 2;
auto bncols = 2;
auto bnnz = 2;
auto cpu_bsr_mat = Faust::MatBSR<FPP, Cpu>::randMat(nrows, ncols, bnrows, bncols, bnnz);
Faust::MatBSR<FPP, GPU2> gpu_bsr_mat(*cpu_bsr_mat);
Faust::MatBSR<FPP, Cpu> cpu_bsr_mat2;
gpu_bsr_mat.tocpu(cpu_bsr_mat2);
cpu_bsr_mat->setZeros();
gpu_bsr_mat.setZeros();
// assert(std::abs(cpu_bsr_mat->norm()-gpu_bsr_mat.norm()) < 1e-3);
// assert(std::abs(cpu_bsr_mat->norm()-cpu_bsr_mat2.norm()) < 1e-3);
cpu_bsr_mat->Display();
gpu_bsr_mat.Display();
cout << "OK" << endl;
delete cpu_bsr_mat;
}
int main()
{
Faust::enable_gpu_mod();
......@@ -201,6 +260,9 @@ int main()
test_transpose();
test_adjoint();
test_conjugate();
test_norm();
test_infos();
test_set_zeros();
}
......@@ -24,6 +24,45 @@ namespace Faust
gp_funcs->set_dev(cur_dev_id);
}
template<>
int32_t MatBSR<@FAUST_SCALAR_FOR_GM@, GPU2>::getNbRow() const
{
auto bsr_funcs = GPUModHandler::get_singleton()->bsr_funcs((@FAUST_SCALAR_FOR_GM@)(0));
int32_t nbRow;
bsr_funcs->info(gpu_mat, &nbRow, nullptr, nullptr, nullptr, nullptr); //TODO gpu_mod: add get_nrows, get_ncols
return nbRow;
}
template<>
int32_t MatBSR<@FAUST_SCALAR_FOR_GM@, GPU2>::getNbCol() const
{
auto bsr_funcs = GPUModHandler::get_singleton()->bsr_funcs((@FAUST_SCALAR_FOR_GM@)(0));
int32_t nbCol;
bsr_funcs->info(gpu_mat, nullptr, &nbCol, nullptr, nullptr, nullptr); //TODO gpu_mod: add get_nrows, get_ncols
return nbCol;
}
template<>
faust_unsigned_int MatBSR<@FAUST_SCALAR_FOR_GM@, GPU2>::getNonZeros() const
{
auto bsr_funcs = GPUModHandler::get_singleton()->bsr_funcs((@FAUST_SCALAR_FOR_GM@)(0));
return bsr_funcs->get_nnz(gpu_mat);
}
template<>
size_t MatBSR<@FAUST_SCALAR_FOR_GM@, GPU2>::getNBytes() const
{
auto bsr_funcs = GPUModHandler::get_singleton()->bsr_funcs((@FAUST_SCALAR_FOR_GM@)(0));
return bsr_funcs->get_nbytes(gpu_mat);
}
template<>
int32_t MatBSR<@FAUST_SCALAR_FOR_GM@, GPU2>::getDevice() const
{
auto bsr_funcs = GPUModHandler::get_singleton()->bsr_funcs((@FAUST_SCALAR_FOR_GM@)(0));
return bsr_funcs->get_dev(gpu_mat);
}
template<>
void MatBSR<@FAUST_SCALAR_FOR_GM@,GPU2>::multiply(MatDense<@FAUST_SCALAR_FOR_GM@,GPU2>& M, char opThis/*='N'*/) const
{
......@@ -96,5 +135,20 @@ namespace Faust
auto bsr_funcs = GPUModHandler::get_singleton()->bsr_funcs((@FAUST_SCALAR_FOR_GM@)(0));
bsr_funcs->conjugate(gpu_mat);
}
template<>
Real<@FAUST_SCALAR_FOR_GM@> MatBSR<@FAUST_SCALAR_FOR_GM@, GPU2>::norm() const
{
auto bsr_funcs = GPUModHandler::get_singleton()->bsr_funcs((@FAUST_SCALAR_FOR_GM@)(0));
return bsr_funcs->norm_frob(gpu_mat);
}
template<typename FPP>
void MatBSR<FPP, GPU2>::setZeros()
{
auto bsr_funcs = GPUModHandler::get_singleton()->bsr_funcs((@FAUST_SCALAR_FOR_GM@)(0));
bsr_funcs->set_zeros(gpu_mat);
}
}
......@@ -51,10 +51,11 @@ namespace Faust
MatType getType() const;
int32_t getNbRow() const;
int32_t getNbCol() const;
faust_unsigned_int getNonZeros() const;
int32_t getDevice() const;
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;
faust_unsigned_int getNonZeros() const;
void transpose();
void conjugate();
void adjoint();
......@@ -64,6 +65,7 @@ namespace Faust
Faust::MatGeneric<FPP,GPU2>* get_cols(faust_unsigned_int* col_ids, faust_unsigned_int num_cols) const;
void Display() const;
std::string to_string() const;
Real<FPP> norm() const;
virtual void set_gpu_mat_ptr(void*);
......
......@@ -24,34 +24,25 @@ namespace Faust
{
}
template<typename FPP>
void MatBSR<FPP, GPU2>::setZeros()
{
//TODO: implement (maybe by moving into .cpp.in
}
template<typename FPP>
size_t MatBSR<FPP, GPU2>::getNBytes() const
{
//TODO: implement (maybe by moving into .cpp.in
}
template<typename FPP>
MatType MatBSR<FPP, GPU2>::getType() const
{
//TODO: implement (maybe by moving into .cpp.in
return BSR;
}
template<typename FPP>
int32_t MatBSR<FPP, GPU2>::getNbRow() const
void MatBSR<FPP, GPU2>::Display() const
{
//TODO: implement (maybe by moving into .cpp.in
std::cout << this->to_string();
}
template<typename FPP>
int32_t MatBSR<FPP, GPU2>::getNbCol() const
std::string MatBSR<FPP, GPU2>::to_string() const
{
//TODO: implement (maybe by moving into .cpp.in
MatBSR<FPP, Cpu> bsr_mat;
tocpu(bsr_mat);
//TODO: rely on gpu_mod display function (yet to write)
return "(on GPU device: " + std::to_string(getDevice())+ ") "+ bsr_mat.to_string();
}
template<typename FPP>
......@@ -69,13 +60,7 @@ namespace Faust
template<typename FPP>
void* MatBSR<FPP, GPU2>::get_gpu_mat_ptr() const
{
//TODO: implement (maybe by moving into .cpp.in
}
template<typename FPP>
faust_unsigned_int MatBSR<FPP, GPU2>::getNonZeros() const
{
//TODO: implement (maybe by moving into .cpp.in
return this->gpu_mat;
}
template<typename FPP>
......@@ -102,22 +87,10 @@ namespace Faust
//TODO: implement (maybe by moving into .cpp.in
}
template<typename FPP>
void MatBSR<FPP, GPU2>::Display() const
{
//TODO: implement (maybe by moving into .cpp.in
}
template<typename FPP>
Real<FPP> MatBSR<FPP, GPU2>::norm() const
{
//TODO: implement (maybe by moving into .cpp.in
}
template<typename FPP>
void MatBSR<FPP, GPU2>::set_gpu_mat_ptr(void* gpu_mat)
{
this->gpu_mat = gpu_mat;
}
};
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment