Mentions légales du service

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

Implement GPU MatDense::real() and add a unit test for it.

Update to gpu_mod@97e4ce3b.
parent 52c1efae
Branches
Tags
No related merge requests found
Subproject commit 746033d0f6406e8361b5d785873b2f664b742981
Subproject commit 97e4ce3b76bcb4057b9e4d8dc16a8f7ee1f3cd7b
......@@ -14,7 +14,8 @@ typedef @TEST_FPP@ FPP;
using namespace std;
using namespace Faust;
double calc_err(MatDense<FPP, GPU2> &gpu_mat, MatDense<FPP, Cpu> &cpu_mat)
template<typename U>
double calc_err(MatDense<U, GPU2> &gpu_mat, MatDense<U, Cpu> &cpu_mat)
{
auto gpu_mat_to_cpu = gpu_mat.tocpu();
auto err_diff = cpu_mat;
......@@ -479,9 +480,31 @@ void test_trace()
{
}
void test_real()
{
cout << "test real()" << endl;
faust_unsigned_int nrows = 10, ncols = 10;
auto cpu_mat1 = Faust::MatDense<FPP,Cpu>::randMat(nrows,ncols);
cout << "cpu_mat1" << endl;
cpu_mat1->Display();
MatDense<Real<FPP>, Cpu> cpu_mat_ref;
cpu_mat1->real(cpu_mat_ref);
cout << "cpu_mat_ref" << endl;
cpu_mat_ref.Display();
cout << cpu_mat_ref.norm() << endl;
MatDense<FPP,GPU2> gpu_mat1(nrows, ncols, cpu_mat1->getData());
MatDense<Real<FPP>, GPU2> gpu_mat2;
gpu_mat1.real(gpu_mat2);
cout << "gpu_mat2" << endl;
gpu_mat2.Display();
cout << gpu_mat2.norm() << endl;
assert(calc_err<Real<FPP>>(gpu_mat2, cpu_mat_ref) < 1e-6);
}
int main(int argc, char** argv)
{
Faust::enable_gpu_mod();
test_real();
test_mul_gpu_dense();
test_resize();
test_setones();
......
......@@ -737,4 +737,15 @@ namespace Faust
auto dsm_funcs = GPUModHandler::get_singleton()->dsm_funcs(@FAUST_SCALAR_FOR_GM@(0));
dsm_funcs->prox_spcol(gpu_mat, k, normalized, pos);
}
template<>
void Faust::MatDense<@FAUST_SCALAR_FOR_GM@,GPU2>::real(Faust::MatDense<Real<@FAUST_SCALAR_FOR_GM@>, GPU2>& real_mat) const
{
auto dsm_funcs = GPUModHandler::get_singleton()->dsm_funcs(@FAUST_SCALAR_FOR_GM@(0));
auto real_gpu_mat = dsm_funcs->real(gpu_mat);
if(real_mat.gpu_mat != nullptr)
dsm_funcs->free(real_mat.gpu_mat);
real_mat.gpu_mat = real_gpu_mat;
}
};
......@@ -19,6 +19,7 @@ namespace Faust
{
friend Transform<FPP,GPU2>; // need to access to get_gpu_mat_ptr
friend MatSparse<FPP,GPU2>;
friend MatDense<std::complex<double>,GPU2>; // TODO limit to real function
// friend void gemm<>(const MatDense<FPP, GPU2> &A, const MatDense<FPP, GPU2> &B, MatDense<FPP, GPU2> &C, const FPP& alpha, const FPP& beta, const char opA, const char opB);
//
// friend void gemv<>(const MatDense<FPP, GPU2> &A, const Vect<FPP, GPU2> &B, Vect<FPP, GPU2> &C, const FPP& alpha, const FPP& beta, const char opA, const char opB);
......@@ -128,6 +129,7 @@ namespace Faust
void prox_sp(int32_t k, bool normalized=false, bool pos=false) const;
void prox_spcol(int32_t k, bool normalized=false, bool pos=false) const;
void prox_splin(int32_t k, bool normalized=false, bool pos=false) const;
void real(MatDense<Real<FPP>, GPU2>& real_mat) const;
static void gemm(const MatDense<FPP, GPU2> &A, const MatDense<FPP, GPU2> &B, MatDense<FPP, GPU2> &C, const FPP& alpha, const FPP& beta, const char opA, const char opB);
static void gemv(const MatDense<FPP, GPU2> &A, const Vect<FPP, GPU2> &B, Vect<FPP, GPU2> &C, const FPP& alpha, const FPP& beta, const char opA, const char opB='N');
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment