Mentions légales du service

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

Add MatBSR<FPP, GPU2>::to_sparse and its unit test.

Update to gpu_mod@a308a07e
parent 77281694
No related branches found
No related tags found
No related merge requests found
......@@ -81,19 +81,40 @@ 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;
// std::cout << gpu_vec_cpu.mean_relative_error(*cpu_vec) << std::endl;
assert(gpu_vec_cpu.mean_relative_error(*cpu_vec) < 1e-1);
delete cpu_bmat;
delete cpu_vec;
std::cout << "OK" << std::endl;
}
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);
MatBSR<FPP, GPU2> gpu_bmat(*cpu_bmat);
auto gpu_spmat = gpu_bmat.to_sparse();
MatSparse<FPP, Cpu> cpu_spmat_test;
gpu_spmat.tocpu(cpu_spmat_test);
auto cpu_spmat_ref = cpu_bmat->to_sparse();
MatDense<FPP, Cpu> cpu_dmat_test = cpu_spmat_test;
MatDense<FPP, Cpu> cpu_dmat_ref = cpu_spmat_ref;
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()
{
Faust::enable_gpu_mod();
test_gpu_ctor_and_tocpu();
test_gpu_mul_dense();
test_gpu_mul_vec();
test_bsr_to_sparse();
}
......@@ -66,5 +66,14 @@ namespace Faust
bsr_funcs->tocpu(gpu_mat, const_cast<int*>(M.get_browptr()), const_cast<int*>(M.get_bcolinds()), (@GM_SCALAR@*) reinterpret_cast<const @GM_REINTERPRET_CAST_SCALAR@*>(const_cast<@FAUST_SCALAR_FOR_GM@*>(M.get_bdata())), nullptr, nullptr, nullptr, nullptr, nullptr);
cpu_mat = std::move(M);
}
template<>
MatSparse<@FAUST_SCALAR_FOR_GM@, GPU2> MatBSR<@FAUST_SCALAR_FOR_GM@,GPU2>::to_sparse() const
{
MatSparse<@FAUST_SCALAR_FOR_GM@, GPU2> spm;
auto bsr_funcs = GPUModHandler::get_singleton()->bsr_funcs((@FAUST_SCALAR_FOR_GM@)(0));
spm.set_gpu_mat_ptr(bsr_funcs->to_csr(gpu_mat));
return spm;
}
}
......@@ -6,6 +6,7 @@
#include "faust_constant.h"
#include "faust_MatGeneric_gpu.h"
#include "faust_MatBSR.h"
namespace Faust
{
template<typename FPP, FDevice DEVICE>
......@@ -70,6 +71,7 @@ namespace Faust
void tocpu(int32_t* browptr, int32_t* bcolinds, FPP* bdata, int32_t* nrows=nullptr, int32_t* ncols=nullptr, int32_t *bnrows=nullptr, int32_t *bncol=nullptr, int32_t* bnnz=nullptr) const;
void tocpu(MatBSR<FPP, Cpu> &cpu_mat) const;
MatSparse<FPP, GPU2> to_sparse() const;
};
}
......
......@@ -11,6 +11,9 @@ namespace Faust
class MatSparse;
template<typename FPP, FDevice DEVICE>
class MatDense;
template<typename FPP, FDevice DEVICE>
class MatBSR;
template<typename FPP>
class MatSparse<FPP, GPU2> : public MatGeneric<FPP,GPU2>
......@@ -19,6 +22,7 @@ namespace Faust
friend Transform<FPP,GPU2>; // need to access to get_gpu_mat_ptr
friend MatDense<FPP,GPU2>;
friend MatSparse<std::complex<double>,GPU2>; // TODO limit to real function
friend MatBSR<FPP, GPU2>;
public:
/** \brief Inits from CPU buffers.
*
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment