Mentions légales du service

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

Remove ButterflyMat from TransformHelperButterfly<FPP, GPU2> and use the new...

Remove ButterflyMat from TransformHelperButterfly<FPP, GPU2> and use the new independent MatButterfly<FPP, GPU2> instead.
parent 305a4392
Branches
Tags
No related merge requests found
......@@ -133,7 +133,7 @@ namespace Faust
class MatBSR;
template<typename FPP, FDevice DEV> class TransformHelperButterfly;
template<typename FPP, FDevice DEV> class ButterflyMat;
template<typename FPP, FDevice DEV> class MatButterfly;
template<typename FPP>
class MatDense<FPP,Cpu> : public MatGeneric<FPP,Cpu>
......@@ -146,7 +146,7 @@ namespace Faust
friend Transform<FPP,Cpu>; //TODO: limit to needed member functions only (multiply)
friend void MatDiag<FPP>::multiply(MatDense<FPP,Cpu> & M, char opThis) const;
friend TransformHelperButterfly<FPP, Cpu>;
friend ButterflyMat<FPP, Cpu>;
friend MatButterfly<FPP, Cpu>;
/// All derived class template of MatDense are considered as friends
template<class,FDevice> friend class MatDense;
......
......@@ -98,7 +98,7 @@ namespace Faust
template<typename FPP, FDevice DEVICE, typename FPP2> class GivensFGFTComplex;
template<typename FPP> class TransformHelperPoly;
template<typename FPP, FDevice DEV> class TransformHelperButterfly;
template<typename FPP, FDevice DEV> class ButterflyMat;
template<typename FPP, FDevice DEV> class MatButterfly;
//TODO: simplify/remove the friendship by adding/using a public setter to is_ortho
//template<typename FPP> void wht_factors(unsigned int n, std::vector<MatGeneric<FPP,Cpu>*>& factors, const bool, const bool);
template<typename FPP>
......@@ -120,7 +120,7 @@ namespace Faust
friend TransformHelper<FPP,Cpu>; // TODO: limit to needed member functions only
friend TransformHelperPoly<FPP>; // TODO: limit to needed member functions only
friend TransformHelperButterfly<FPP, Cpu>; // TODO: limit to needed member functions only
friend ButterflyMat<FPP, Cpu>; // TODO: limit to needed member functions only
friend MatButterfly<FPP, Cpu>; // TODO: limit to needed member functions only
friend void wht_factors<>(unsigned int n, std::vector<MatGeneric<FPP,Cpu>*>& factors, const bool, const bool);
friend class MatDense<FPP,Cpu>;
friend class MatSparse<std::complex<double>, Cpu>;
......
......@@ -2,22 +2,20 @@
#define __FAUST_TRANSFORM_HELPER_DFT_GPU2__
#ifdef USE_GPU_MOD
#include "faust_TransformHelper_gpu.h"
#include "faust_MatButterfly_gpu.h"
namespace Faust
{
template<typename FPP, FDevice DEV>
class TransformHelperButterfly;
template<typename FPP, FDevice DEV>
class ButterflyMat;
template<typename FPP>
class TransformHelperButterfly<FPP, GPU2> : public TransformHelper<FPP, GPU2>
{
int* perm_ids;
Vect<FPP, GPU2> d_perm;
bool has_permutation;
std::vector<ButterflyMat<FPP, GPU2>> opt_factors;
std::vector<MatButterfly<FPP, GPU2>> opt_factors;
// private ctor
......@@ -36,53 +34,7 @@ namespace Faust
};
template<typename FPP>
class ButterflyMat<FPP, GPU2>
{
Vect<FPP, GPU2> d1;
Vect<FPP, GPU2> d2;
int* subdiag_ids;
int level;
// \param level: is a 0-base index.
public:
ButterflyMat(const MatSparse<FPP, Cpu> &factor, int level);
//TODO: move defs in hpp
ButterflyMat(const ButterflyMat<FPP, GPU2>& bmat)
{
*this = bmat;
}
ButterflyMat& operator=(const ButterflyMat<FPP, GPU2>& bmat)
{
this->d1 = bmat.d1;
this->d2 = bmat.d2;
this->level = bmat.level;
this->subdiag_ids = new int[d1.size()];
std::copy(bmat.subdiag_ids, bmat.subdiag_ids+d1.size(), this->subdiag_ids);
return *this;
}
ButterflyMat() : level(-1), subdiag_ids(nullptr), d1(), d2()
{
}
//TODO: constness of multiply member functions
MatDense<FPP, GPU2> multiply(const FPP* x);
void Display() const;
MatDense<FPP, GPU2> multiply(const FPP* A, int A_ncols);
MatDense<FPP, GPU2> multiply(MatDense<FPP,GPU2> &A);
void multiply(MatDense<FPP,GPU2> &A, MatDense<FPP, Cpu> & out);
// MatDense<FPP, Cpu> multiply(const MatSparse<FPP,Cpu> &A);
const Vect<FPP, GPU2>& getD1() {return d1;};
const Vect<FPP, GPU2>& getD2() {return d2;};
~ButterflyMat() {if (subdiag_ids != nullptr) delete[] subdiag_ids;}
};
}
#include "faust_TransformHelperButterfly_gpu.hpp" //TODO
#include "faust_TransformHelperButterfly_gpu.hpp"
#endif
#endif
......@@ -24,13 +24,13 @@ namespace Faust
auto mul_csr = new MatSparse<FPP, Cpu>(*csr_fac);
*mul_csr *= lambda_;
opt_factors.insert(opt_factors.begin(),
ButterflyMat<FPP, GPU2>(*mul_csr, i++));
MatButterfly<FPP, GPU2>(*mul_csr, i++));
this->push_back(mul_csr);
}
else
{
opt_factors.insert(opt_factors.begin(),
ButterflyMat<FPP, GPU2>(*csr_fac, i++));
MatButterfly<FPP, GPU2>(*csr_fac, i++));
this->push_back(csr_fac);
}
}
......@@ -127,62 +127,4 @@ namespace Faust
return fourierFaust;
}
template<typename FPP>
ButterflyMat<FPP, GPU2>::ButterflyMat(const MatSparse<FPP, Cpu> &factor, int level) : level(level)
{
MatButterfly<FPP, Cpu> cpu_bmat(factor, level);
auto cpu_d1 = cpu_bmat.getD1();
auto cpu_d2 = cpu_bmat.getD2();
d1 = Vect<FPP, GPU2>(cpu_d1.rows(), cpu_d1.diagonal().data());
d2 = Vect<FPP, GPU2>(cpu_d2.rows(), cpu_d2.diagonal().data());
auto sd_ids_vec = cpu_bmat.get_subdiag_ids();
subdiag_ids = new int[sd_ids_vec.size()];
memcpy(subdiag_ids, sd_ids_vec.data(), sizeof(int) * sd_ids_vec.size());
}
template<typename FPP>
void ButterflyMat<FPP, GPU2>::Display() const
{
std::cout << "ButterflyMat on GPU: ";
std::cout << "D1: ";
d1.Display();
std::cout << "D2: ";
d1.Display();
cout << "subdiag_ids: ";
for(int i=0;i < d1.size();i++)
cout << subdiag_ids[i] << " ";
cout << std::endl;
}
template<typename FPP>
MatDense<FPP, GPU2> ButterflyMat<FPP, GPU2>::multiply(const FPP* X, int X_ncols)
{
MatDense<FPP, GPU2> gpu_X(d1.size(), X_ncols, X);
return multiply(gpu_X);
}
template<typename FPP>
MatDense<FPP, GPU2> ButterflyMat<FPP, GPU2>::multiply(const FPP* x)
{
return multiply(x, 1);
}
template<typename FPP>
MatDense<FPP, GPU2> ButterflyMat<FPP, GPU2>::multiply(MatDense<FPP, GPU2> &gpu_X)
{
/*MatDense<FPP, GPU2> gpu_X2(gpu_X);
gpu_X.eltwise_mul(d2, subdiag_ids);
gpu_X2.eltwise_mul(d1);
gpu_X += gpu_X2;*/
butterfly_diag_prod(gpu_X, d1, d2, subdiag_ids);
return gpu_X;
}
template<typename FPP>
void ButterflyMat<FPP, GPU2>::multiply(MatDense<FPP, GPU2> &gpu_X, MatDense<FPP, Cpu> &cpu_out)
{
multiply(gpu_X);
gpu_X.tocpu(cpu_out);
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment