Mentions légales du service

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

Add MatSparse<FPP,GPU2>::to_bsr and an associated unit test.

parent 2decb3c5
Branches
Tags
No related merge requests found
...@@ -108,6 +108,23 @@ void test_bsr_to_sparse() ...@@ -108,6 +108,23 @@ void test_bsr_to_sparse()
std::cout << "OK" << std::endl; std::cout << "OK" << std::endl;
} }
void test_sparse_to_bsr()
{
std::cout << "test_sparse_to_bsr" << std::endl;
auto cpu_smat = MatSparse<double, Cpu>::randMat(10, 15, .01);
MatSparse<FPP, GPU2> gpu_smat(*cpu_smat);
auto gpu_bmat = gpu_smat.to_bsr(5);
MatBSR<FPP, Cpu> cpu_bmat;
gpu_bmat.tocpu(cpu_bmat);
MatDense<FPP, Cpu> cpu_dmat_test = cpu_bmat.to_dense();
MatDense<FPP, Cpu> cpu_dmat_ref = *cpu_smat;;
MatDense<FPP, Cpu> diff = cpu_dmat_ref;
diff -= cpu_dmat_test;
assert(diff.norm() / cpu_dmat_ref.norm() < 1e-3);
std::cout << "OK" << std::endl;
}
int main() int main()
{ {
Faust::enable_gpu_mod(); Faust::enable_gpu_mod();
...@@ -115,6 +132,7 @@ int main() ...@@ -115,6 +132,7 @@ int main()
test_gpu_mul_dense(); test_gpu_mul_dense();
test_gpu_mul_vec(); test_gpu_mul_vec();
test_bsr_to_sparse(); test_bsr_to_sparse();
test_sparse_to_bsr();
} }
...@@ -514,4 +514,12 @@ namespace Faust ...@@ -514,4 +514,12 @@ namespace Faust
real_mat.gpu_mat = real_gpu_mat; real_mat.gpu_mat = real_gpu_mat;
} }
template<>
MatBSR<@FAUST_SCALAR_FOR_GM@, GPU2> MatSparse<@FAUST_SCALAR_FOR_GM@, GPU2>::to_bsr(int bsize) const
{
auto spm_funcs = GPUModHandler::get_singleton()->spm_funcs(@FAUST_SCALAR_FOR_GM@(0));
MatBSR<@FAUST_SCALAR_FOR_GM@, GPU2> bsr_mat;
bsr_mat.set_gpu_mat_ptr(spm_funcs->to_bsr(this->gpu_mat, bsize));
return bsr_mat;
}
}; };
...@@ -101,6 +101,7 @@ namespace Faust ...@@ -101,6 +101,7 @@ namespace Faust
MatType getType() const; MatType getType() const;
void multiply(Vect<FPP,GPU2>& vec, char opThis='N') const; void multiply(Vect<FPP,GPU2>& vec, char opThis='N') const;
void multiply(MatDense<FPP,GPU2>& vec, char opThis='N') const; void multiply(MatDense<FPP,GPU2>& vec, char opThis='N') const;
MatBSR<FPP, GPU2> to_bsr(int bsize) const;
~MatSparse(); ~MatSparse();
MatSparse<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;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment