Mentions légales du service

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

Implement MatBSR<FPP, GPU2>::get_nrows/get_ncols and add their unit tests.

Update to gpu_mod@259cefc5
parent 0b8575dd
No related branches found
No related tags found
No related merge requests found
Subproject commit 3904f39eabcdf828cd474fad55e8b85882281d90 Subproject commit 259cefc5c3e3c8e6579ab2ac7ebce2dda194a8b1
...@@ -248,6 +248,57 @@ void test_set_zeros() ...@@ -248,6 +248,57 @@ void test_set_zeros()
delete cpu_bsr_mat; delete cpu_bsr_mat;
} }
void test_get_nrows_ncols()
{
cout << "test_get_nrows_ncols" << 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);
auto gpu_rows = dynamic_cast<MatSparse<FPP, GPU2>*>(gpu_bsr_mat.get_rows(4, 3));
auto cpu_rows = cpu_bsr_mat->get_rows(4, 3);
MatSparse<FPP, Cpu> test_rows;
gpu_rows->tocpu(test_rows);
auto diff = MatDense<FPP, Cpu>(test_rows);
diff -= MatDense<FPP, Cpu>(*cpu_rows);
assert(diff.norm() < 1e-6);
delete gpu_rows;
delete cpu_rows;
auto gpu_cols = dynamic_cast<MatSparse<FPP, GPU2>*>(gpu_bsr_mat.get_cols(4, 3));
auto cpu_cols = cpu_bsr_mat->get_cols(4, 3);
MatSparse<FPP, Cpu> test_cols;
gpu_cols->tocpu(test_cols);
diff = MatDense<FPP, Cpu>(test_cols);
diff -= MatDense<FPP, Cpu>(*cpu_cols);
assert(diff.norm() < 1e-6);
delete gpu_cols;
delete cpu_cols;
faust_unsigned_int row_ids[3] = {1, 4, 6};
gpu_rows = dynamic_cast<MatSparse<FPP, GPU2>*>(gpu_bsr_mat.get_rows(row_ids, 3));
cpu_rows = cpu_bsr_mat->get_rows(row_ids, 3);
gpu_rows->tocpu(test_rows);
diff = MatDense<FPP, Cpu>(test_rows);
diff -= MatDense<FPP, Cpu>(*cpu_rows);
assert(diff.norm() < 1e-6);
faust_unsigned_int col_ids[3] = {1, 4, 6};
gpu_cols = dynamic_cast<MatSparse<FPP, GPU2>*>(gpu_bsr_mat.get_cols(col_ids, 3));
cpu_cols = cpu_bsr_mat->get_cols(col_ids, 3);
gpu_cols->tocpu(test_cols);
diff = MatDense<FPP, Cpu>(test_cols);
diff -= MatDense<FPP, Cpu>(*cpu_cols);
assert(diff.norm() < 1e-6);
cout << "OK" << endl;
}
int main() int main()
{ {
...@@ -263,6 +314,7 @@ int main() ...@@ -263,6 +314,7 @@ int main()
test_norm(); test_norm();
test_infos(); test_infos();
test_set_zeros(); test_set_zeros();
test_get_nrows_ncols();
} }
...@@ -64,27 +64,51 @@ namespace Faust ...@@ -64,27 +64,51 @@ namespace Faust
} }
template<typename FPP> template<typename FPP>
MatGeneric<FPP,GPU2>* MatBSR<FPP, GPU2>::get_rows(faust_unsigned_int row_id_start, faust_unsigned_int num_rows) const Faust::MatGeneric<FPP,GPU2>* Faust::MatBSR<FPP,GPU2>::get_rows(faust_unsigned_int row_id_start, faust_unsigned_int num_rows) const
{ {
//TODO: implement (maybe by moving into .cpp.in //TODO: pure GPU impl.
MatBSR<FPP,Cpu> cpu_copy;
tocpu(cpu_copy);
auto cpu_rows = cpu_copy.get_rows(row_id_start, num_rows);
auto gpu_rows = new MatSparse<FPP,GPU2>(*cpu_rows);
delete cpu_rows;
return gpu_rows;
} }
template<typename FPP> template<typename FPP>
MatGeneric<FPP,GPU2>* MatBSR<FPP, GPU2>::get_rows(faust_unsigned_int* row_ids, faust_unsigned_int num_rows) const Faust::MatGeneric<FPP,GPU2>* Faust::MatBSR<FPP,GPU2>::get_rows(faust_unsigned_int* row_ids, faust_unsigned_int num_rows) const
{ {
//TODO: implement (maybe by moving into .cpp.in //TODO: pure GPU impl.
MatBSR<FPP,Cpu> cpu_copy;
tocpu(cpu_copy);
auto cpu_rows = cpu_copy.get_rows(row_ids, num_rows);
auto gpu_rows = new MatSparse<FPP,GPU2>(*cpu_rows);
delete cpu_rows;
return gpu_rows;
} }
template<typename FPP> template<typename FPP>
Faust::MatGeneric<FPP,GPU2>* MatBSR<FPP, GPU2>::get_cols(faust_unsigned_int col_id_start, faust_unsigned_int num_cols) const Faust::MatGeneric<FPP,GPU2>* Faust::MatBSR<FPP,GPU2>::get_cols(faust_unsigned_int col_id_start, faust_unsigned_int num_cols) const
{ {
//TODO: implement (maybe by moving into .cpp.in //TODO: pure GPU impl.
MatBSR<FPP,Cpu> cpu_copy;
tocpu(cpu_copy);
auto cpu_cols = cpu_copy.get_cols(col_id_start, num_cols);
auto gpu_cols = new MatSparse<FPP,GPU2>(*cpu_cols);
delete cpu_cols;
return gpu_cols;
} }
template<typename FPP> template<typename FPP>
Faust::MatGeneric<FPP,GPU2>* MatBSR<FPP, GPU2>::get_cols(faust_unsigned_int* col_ids, faust_unsigned_int num_cols) const Faust::MatGeneric<FPP,GPU2>* Faust::MatBSR<FPP,GPU2>::get_cols(faust_unsigned_int* col_ids, faust_unsigned_int num_cols) const
{ {
//TODO: implement (maybe by moving into .cpp.in //TODO: pure GPU impl.
MatBSR<FPP,Cpu> cpu_copy;
tocpu(cpu_copy);
auto cpu_cols = cpu_copy.get_cols(col_ids, num_cols);
auto gpu_cols = new MatSparse<FPP,GPU2>(*cpu_cols);
delete cpu_cols;
return gpu_cols;
} }
template<typename FPP> template<typename FPP>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment