Mentions légales du service

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

Implement MatBSR::clone/Clone, ctor copy and add their unit tests.

Update to gpu_mod@15531393.
parent b2147f1b
No related branches found
No related tags found
No related merge requests found
Subproject commit 259cefc5c3e3c8e6579ab2ac7ebce2dda194a8b1
Subproject commit 15531393a8ed3c5dbf38c5817d181bcbf7b827a8
......@@ -299,6 +299,27 @@ void test_get_nrows_ncols()
cout << "OK" << endl;
}
void test_clone()
{
std::cout << "test_clone" << 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;
auto gpu_bsr_clone = gpu_bsr_mat.clone();
gpu_bsr_clone->tocpu(cpu_bsr_mat2);
gpu_bsr_mat.Display();
gpu_bsr_clone->Display();
MatDense<FPP, Cpu> diff_mat = cpu_bsr_mat->to_dense();
diff_mat -= cpu_bsr_mat2.to_dense();
assert(diff_mat.norm() < 1e-3);
cout << "OK" << endl;
delete cpu_bsr_mat;
}
int main()
{
......@@ -315,6 +336,7 @@ int main()
test_infos();
test_set_zeros();
test_get_nrows_ncols();
test_clone();
}
......@@ -24,6 +24,26 @@ namespace Faust
gp_funcs->set_dev(cur_dev_id);
}
template<>
MatBSR<@FAUST_SCALAR_FOR_GM@, GPU2>::MatBSR(const MatBSR<@FAUST_SCALAR_FOR_GM@, GPU2>& src) : MatBSR<@FAUST_SCALAR_FOR_GM@, GPU2>()
{
if(src.gpu_mat != nullptr)
{
auto bsr_funcs = GPUModHandler::get_singleton()->bsr_funcs((@FAUST_SCALAR_FOR_GM@)(0));
gpu_mat = bsr_funcs->clone(src.gpu_mat, /* dev_id */ -1, /* stream */ nullptr);
}
}
template<>
MatBSR<@FAUST_SCALAR_FOR_GM@,GPU2>* MatBSR<@FAUST_SCALAR_FOR_GM@, GPU2>::clone(const int32_t dev_id/*=*-1*/, const void* stream/*=*nullptr*/) const
{
auto mat = new MatBSR<@FAUST_SCALAR_FOR_GM@, GPU2>();
auto bsr_funcs = GPUModHandler::get_singleton()->bsr_funcs((@FAUST_SCALAR_FOR_GM@)(0));
if(gpu_mat != nullptr)
mat->gpu_mat = bsr_funcs->clone(gpu_mat, dev_id, stream);
return mat;
}
template<>
int32_t MatBSR<@FAUST_SCALAR_FOR_GM@, GPU2>::getNbRow() const
{
......
......@@ -22,12 +22,11 @@ namespace Faust
gm_BSRMat_t gpu_mat;
public:
/*********** ctors **************/
/** \brief Inits from CPU buffers.
*
*/
public:
/*********** ctors **************/
MatBSR(const faust_unsigned_int nrows,
const faust_unsigned_int ncols,
const faust_unsigned_int bnrows,
......@@ -45,6 +44,8 @@ namespace Faust
MatBSR();
MatBSR(const MatBSR<FPP, GPU2> &);
/*********** MatGeneric member functions **************/
void setZeros();
size_t getNBytes() const;
......@@ -53,8 +54,8 @@ namespace Faust
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;
MatBSR<FPP,GPU2>* clone(const int32_t dev_id=-1, const void* stream=nullptr) const;
MatBSR<FPP,GPU2>* Clone(const bool isOptimize=false) const;
void* get_gpu_mat_ptr() const;
void transpose();
void conjugate();
......
......@@ -46,15 +46,15 @@ namespace Faust
}
template<typename FPP>
MatGeneric<FPP,GPU2>* MatBSR<FPP, GPU2>::clone(const int32_t dev_id/*=*-1*/, const void* stream/*=*nullptr*/) const
MatBSR<FPP,GPU2>* MatBSR<FPP,GPU2>::Clone(const bool isOptimize /*default value=false*/) const
{
//TODO: implement (maybe by moving into .cpp.in
}
template<typename FPP>
MatGeneric<FPP,GPU2>* MatBSR<FPP, GPU2>::Clone(const bool isOptimize/*=*false*/) const
{
//TODO: implement (maybe by moving into .cpp.in
if (isOptimize)
{
throw std::runtime_error("MatBSR doesn't handle isOptimize flag");
} else
{
return new MatBSR<FPP,GPU2>((*this));
}
}
template<typename FPP>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment