Mentions légales du service

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

Add GPU2 MatButterfly get_gpu_mat_ptr, conjugate, adjoint, Display and unit tests.

parent dab3da47
No related branches found
No related tags found
No related merge requests found
......@@ -182,6 +182,69 @@ void test_transpose(MatButterfly<FPP, GPU2> &gpu_bm, MatButterfly<FPP, Cpu> &cpu
cout << "OK" << endl;
}
void test_conjugate(MatButterfly<FPP, GPU2> &gpu_bm, MatButterfly<FPP, Cpu> &cpu_bm)
{
cout << "Test MatButterfly<FPP, GPU2>::conjugate()" << endl;
auto size = cpu_bm.getNbRow();
auto rmat = MatDense<FPP, Cpu>::randMat(size, size);
MatDense<FPP, Cpu> ref_mat(*rmat);
MatDense<FPP, GPU2> test_mat(*rmat);
auto gpu_clone = gpu_bm.clone();
auto cpu_clone = cpu_bm.Clone();
cpu_clone->conjugate();
cpu_clone->multiply(ref_mat, 'N');
gpu_clone->conjugate();
gpu_clone->multiply(test_mat, 'N');
auto test_mat_cpu = test_mat.tocpu();
assert(verifyMatEq(test_mat_cpu, ref_mat));
// undo the conjugate
cpu_clone->conjugate();
cpu_clone->multiply(ref_mat, 'N');
gpu_clone->conjugate();
gpu_clone->multiply(test_mat, 'N');
test_mat_cpu = test_mat.tocpu();
assert(verifyMatEq(test_mat_cpu, ref_mat));
delete rmat;
delete gpu_clone;
delete cpu_clone;
cout << "OK" << endl;
}
void test_adjoint(MatButterfly<FPP, GPU2> &gpu_bm, MatButterfly<FPP, Cpu> &cpu_bm)
{
cout << "Test MatButterfly<FPP, GPU2>::adjoint()" << endl;
auto size = cpu_bm.getNbRow();
auto rmat = MatDense<FPP, Cpu>::randMat(size, size);
MatDense<FPP, Cpu> ref_mat(*rmat);
MatDense<FPP, GPU2> test_mat(*rmat);
auto gpu_clone = gpu_bm.clone();
auto cpu_clone = cpu_bm.Clone();
cpu_clone->adjoint();
cpu_clone->multiply(ref_mat, 'N');
gpu_clone->adjoint();
gpu_clone->multiply(test_mat, 'N');
auto test_mat_cpu = test_mat.tocpu();
assert(verifyMatEq(test_mat_cpu, ref_mat));
// undo the adjoint
cpu_clone->adjoint();
cpu_clone->multiply(ref_mat, 'N');
gpu_clone->adjoint();
gpu_clone->multiply(test_mat, 'N');
test_mat_cpu = test_mat.tocpu();
assert(verifyMatEq(test_mat_cpu, ref_mat));
delete rmat;
delete gpu_clone;
delete cpu_clone;
cout << "OK" << endl;
}
void test_display(MatButterfly<FPP, GPU2> &gpu_bm)
{
cout << "Test MatButterfly<FPP, GPU2>::Display()" << endl;
gpu_bm.Display();
cout << "OK" << endl;
}
int main(int argc, char** argv)
{
Faust::enable_gpu_mod();
......@@ -208,6 +271,9 @@ int main(int argc, char** argv)
test_clone(gpu_bm, cpu_bm);
test_getNonZeros(gpu_bm, cpu_bm);
test_transpose(gpu_bm, cpu_bm);
test_conjugate(gpu_bm, cpu_bm);
test_adjoint(gpu_bm, cpu_bm);
test_display(gpu_bm);
return 0;
}
......@@ -33,9 +33,9 @@ namespace Faust
MatButterfly<FPP,GPU2>* Clone(const bool isOptimize=false) const;
void transpose();
void init_transpose();
/* void* get_gpu_mat_ptr() const;
void conjugate();
void adjoint();*/
void conjugate();
void adjoint();
void* get_gpu_mat_ptr() const {return d1.getData();} // not only one pointer, choose d1 arbitrarily
//! \brief Returns a sub-group of rows of this matrix as the same type of matrix
MatSparse<FPP,GPU2>* get_rows(faust_unsigned_int row_id_start, faust_unsigned_int num_rows) const;
//! \brief Returns a sub-group of rows of this matrix as the same type of matrix
......@@ -45,11 +45,12 @@ namespace Faust
//! \brief Returns a sub-group of columns of this matrix as the same type of matrix
MatSparse<FPP,GPU2>* get_cols(faust_unsigned_int* col_ids, faust_unsigned_int num_cols) const;
/*void Display() const;*/
void Display() const;
Real<FPP> norm() const;
void multiply(MatDense<FPP, GPU2> &other, const char op_this);
void multiply(MatSparse<FPP, GPU2> &other, const char op_this);
MatSparse<FPP, GPU2> toMatSparse() const;
~MatButterfly();
};
}
......
......@@ -26,6 +26,8 @@ namespace Faust
template<typename FPP>
void MatButterfly<FPP, GPU2>::multiply(MatDense<FPP, GPU2> &other, const char op_this)
{
if(op_this != 'N' && op_this != 'T')
throw std::runtime_error("MatButtermfly::multiply only handle 'N' and 'T' for op_this");
bool use_d2t = is_transp ^ op_this == 'T';
butterfly_diag_prod(other, d1, use_d2t?d2t:d2, subdiag_ids);
}
......@@ -153,4 +155,48 @@ namespace Faust
d2t = cpu_d2t;
}
}
template<typename FPP>
void MatButterfly<FPP, GPU2>::conjugate()
{
d1.conjugate();
d2.conjugate();
if(d2t.size() > 0)
d2t.conjugate();
}
template<typename FPP>
void MatButterfly<FPP, GPU2>::adjoint()
{
transpose();
conjugate();
}
template<typename FPP>
void MatButterfly<FPP, GPU2>::Display() const
{
//TODO: adjust consistently with MatGeneric Display (using to_string)
std::cout << "MatButterfly on GPU: ";
std::cout << "D1: ";
d1.tocpu().Display();
std::cout << "D2: ";
d2.tocpu().Display();
if(d2t.size() > 0)
{
std::cout << "D2T: ";
d2t.tocpu().Display();
}
std::cout << "subdiag_ids: ";
for(int i=0;i < d2.size();i++)
std::cout << subdiag_ids[i] << " ";
std::cout << std::endl;
}
template<typename FPP>
MatButterfly<FPP, GPU2>::~MatButterfly()
{
delete subdiag_ids;
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment