Mentions légales du service

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

Implement MatBSR<FPP, GPU>::adjoint, conjugate and add their unit tests.

Update to gpu_mod@40121cf1.
parent f5d6c44f
No related branches found
No related tags found
No related merge requests found
Subproject commit 302ae6076497b5f86a6eb19076277c2915ec1396
Subproject commit 40121cf1a95088da5223d741bf7465a896d40405
......@@ -18,9 +18,9 @@ void test_gpu_ctor_and_tocpu()
auto bnrows = 5;
auto bncols = 5;
auto bnnz = 2;
auto cpu_bsr_mat = Faust::MatBSR<double, Cpu>::randMat(nrows, ncols, bnrows, bncols, bnnz);
Faust::MatBSR<double, Cpu> cpu_bsr_mat2;
Faust::MatBSR<double, GPU2> gpu_bsr_mat(
auto cpu_bsr_mat = Faust::MatBSR<FPP, Cpu>::randMat(nrows, ncols, bnrows, bncols, bnnz);
Faust::MatBSR<FPP, Cpu> cpu_bsr_mat2;
Faust::MatBSR<FPP, GPU2> gpu_bsr_mat(
cpu_bsr_mat->getNbRow(),
cpu_bsr_mat->getNbCol(),
cpu_bsr_mat->getNbBlockRow(),
......@@ -46,7 +46,7 @@ void test_gpu_mul_dense()
// convert it to gpu
MatDense<FPP, GPU2> gpu_dmat(*cpu_dmat);
// idem for bsr mats
auto cpu_bmat = MatBSR<double, Cpu>::randMat(10, 15, 5, 5, 2);
auto cpu_bmat = MatBSR<FPP, Cpu>::randMat(10, 15, 5, 5, 2);
MatBSR<FPP, GPU2> gpu_bmat(*cpu_bmat);
// multiply on cpu
......@@ -70,7 +70,7 @@ void test_gpu_mul_vec()
// convert it to gpu
Vect<FPP, GPU2> gpu_vec(*cpu_vec);
// idem for bsr mats
auto cpu_bmat = MatBSR<double, Cpu>::randMat(10, 15, 5, 5, 2);
auto cpu_bmat = MatBSR<FPP, Cpu>::randMat(10, 15, 5, 5, 2);
MatBSR<FPP, GPU2> gpu_bmat(*cpu_bmat);
// multiply on cpu
......@@ -82,7 +82,7 @@ void test_gpu_mul_vec()
auto gpu_vec_cpu = gpu_vec.tocpu();
// gpu_vec_cpu.Display();
// std::cout << gpu_vec_cpu.mean_relative_error(*cpu_vec) << std::endl;
assert(gpu_vec_cpu.mean_relative_error(*cpu_vec) < 1e-1);
assert(std::abs(gpu_vec_cpu.mean_relative_error(*cpu_vec)) < 1e-1);
delete cpu_bmat;
delete cpu_vec;
std::cout << "OK" << std::endl;
......@@ -91,7 +91,7 @@ void test_gpu_mul_vec()
void test_bsr_to_sparse()
{
std::cout << "test_bsr_to_sparse" << std::endl;
auto cpu_bmat = MatBSR<double, Cpu>::randMat(10, 15, 5, 5, 2);
auto cpu_bmat = MatBSR<FPP, Cpu>::randMat(10, 15, 5, 5, 2);
MatBSR<FPP, GPU2> gpu_bmat(*cpu_bmat);
auto gpu_spmat = gpu_bmat.to_sparse();
......@@ -111,7 +111,7 @@ void test_bsr_to_sparse()
void test_sparse_to_bsr()
{
std::cout << "test_sparse_to_bsr" << std::endl;
auto cpu_smat = MatSparse<double, Cpu>::randMat(10, 15, .01);
auto cpu_smat = MatSparse<FPP, 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;
......@@ -131,13 +131,13 @@ void test_transpose()
{
std::cout << "test_transpose" << std::endl;
auto nrows = 10;
auto ncols = 10;
auto ncols = 8;
auto bnrows = 2;
auto bncols = 2;
auto bnnz = 2;
auto cpu_bsr_mat = Faust::MatBSR<double, Cpu>::randMat(nrows, ncols, bnrows, bncols, bnnz);
Faust::MatBSR<double, GPU2> gpu_bsr_mat(*cpu_bsr_mat);
Faust::MatBSR<double, Cpu> cpu_bsr_mat2;
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;
cpu_bsr_mat->transpose();
gpu_bsr_mat.transpose();
gpu_bsr_mat.tocpu(cpu_bsr_mat2);
......@@ -148,6 +148,48 @@ void test_transpose()
delete cpu_bsr_mat;
}
void test_adjoint()
{
std::cout << "test_adjoint" << 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;
cpu_bsr_mat->adjoint();
gpu_bsr_mat.adjoint();
gpu_bsr_mat.tocpu(cpu_bsr_mat2);
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;
}
void test_conjugate()
{
std::cout << "test_conjugate" << 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;
cpu_bsr_mat->conjugate();
gpu_bsr_mat.conjugate();
gpu_bsr_mat.tocpu(cpu_bsr_mat2);
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()
{
Faust::enable_gpu_mod();
......@@ -157,6 +199,8 @@ int main()
test_bsr_to_sparse();
test_sparse_to_bsr();
test_transpose();
test_adjoint();
test_conjugate();
}
......@@ -82,5 +82,19 @@ namespace Faust
auto bsr_funcs = GPUModHandler::get_singleton()->bsr_funcs((@FAUST_SCALAR_FOR_GM@)(0));
bsr_funcs->transpose(gpu_mat);
}
template<>
void MatBSR<@FAUST_SCALAR_FOR_GM@, GPU2>::adjoint()
{
auto bsr_funcs = GPUModHandler::get_singleton()->bsr_funcs((@FAUST_SCALAR_FOR_GM@)(0));
bsr_funcs->adjoint(gpu_mat);
}
template<>
void MatBSR<@FAUST_SCALAR_FOR_GM@, GPU2>::conjugate()
{
auto bsr_funcs = GPUModHandler::get_singleton()->bsr_funcs((@FAUST_SCALAR_FOR_GM@)(0));
bsr_funcs->conjugate(gpu_mat);
}
}
......@@ -78,18 +78,6 @@ namespace Faust
//TODO: implement (maybe by moving into .cpp.in
}
template<typename FPP>
void MatBSR<FPP, GPU2>::conjugate()
{
//TODO: implement (maybe by moving into .cpp.in
}
template<typename FPP>
void MatBSR<FPP, GPU2>::adjoint()
{
//TODO: implement (maybe by moving into .cpp.in
}
template<typename FPP>
MatGeneric<FPP,GPU2>* MatBSR<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