Mentions légales du service

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

Add (disabled) pythonic (pythran) code for the Faust-vector multiplication in...

Add (disabled) pythonic (pythran) code for the Faust-vector multiplication in TransformHelperButterfly code + disable use of Eigen::placeholders::all for old eigen versions.
parent 8611c5d6
Branches
Tags
No related merge requests found
...@@ -2,6 +2,25 @@ ...@@ -2,6 +2,25 @@
#define __FAUST_TRANSFORM_HELPER_DFT__ #define __FAUST_TRANSFORM_HELPER_DFT__
#include "faust_TransformHelper.h" #include "faust_TransformHelper.h"
#ifdef USE_PYTHONIC
#include "numpy/_numpyconfig.h"
#include "ButFactor_matmul.hpp"
#include <pythonic/include/numpy/array.hpp>
#include <pythonic/numpy/array.hpp>
#include "pythonic/include/utils/array_helper.hpp"
#include "pythonic/include/types/ndarray.hpp"
using namespace pythonic;
// Helper to create a float 1D array from a pointer
template <typename T>
types::ndarray<T, types::pshape<long>> arrayFromBuf1D(T* fPtr, long size)
{
auto shape = types::pshape<long>(size);
return types::ndarray<T, types::pshape<long>>(fPtr,shape,types::ownership::external);
}
#endif
namespace Faust namespace Faust
{ {
template<typename FPP, FDevice DEV> template<typename FPP, FDevice DEV>
...@@ -45,6 +64,9 @@ namespace Faust ...@@ -45,6 +64,9 @@ namespace Faust
DiagMat D1; DiagMat D1;
DiagMat D2; DiagMat D2;
std::vector<int> subdiag_ids; std::vector<int> subdiag_ids;
#ifdef USE_PYTHONIC
long *subdiag_ids_ptr;
#endif
int level; int level;
// \param level: is a 0-base index. // \param level: is a 0-base index.
......
...@@ -108,7 +108,7 @@ namespace Faust ...@@ -108,7 +108,7 @@ namespace Faust
using MatMap = Eigen::Map<Eigen::Matrix<FPP, Eigen::Dynamic, Eigen::Dynamic>>; using MatMap = Eigen::Map<Eigen::Matrix<FPP, Eigen::Dynamic, Eigen::Dynamic>>;
MatMap X_mat(const_cast<FPP*>(X) /* harmless, no modification*/, this->getNbCol(), X_ncols); MatMap X_mat(const_cast<FPP*>(X) /* harmless, no modification*/, this->getNbCol(), X_ncols);
MatMap Y_mat(Y, this->getNbRow(), X_ncols); MatMap Y_mat(Y, this->getNbRow(), X_ncols);
#ifdef BUTTERFLY_MUL_MAT_OMP_LOOP #ifdef BUTTERFLY_MUL_MAT_OMP_LOOP || ! (EIGEN_WORLD_VERSION > 3 || EIGEN_WORLD_VERSION >= 4 && EIGEN_MAJOR_VERSION >= 0)
// this is slower // this is slower
#pragma parallel omp for #pragma parallel omp for
for(int i=0;i < this->getNbRow(); i ++) for(int i=0;i < this->getNbRow(); i ++)
...@@ -213,6 +213,10 @@ namespace Faust ...@@ -213,6 +213,10 @@ namespace Faust
copy(seq.begin()+i+d_offset, seq.begin()+i+2*d_offset, subdiag_ids.begin()+i); copy(seq.begin()+i+d_offset, seq.begin()+i+2*d_offset, subdiag_ids.begin()+i);
copy(seq.begin()+i, seq.begin()+i+d_offset, subdiag_ids.begin()+i+d_offset); copy(seq.begin()+i, seq.begin()+i+d_offset, subdiag_ids.begin()+i+d_offset);
} }
#ifdef USE_PYTHONIC
subdiag_ids_ptr = new long[size];
copy(subdiag_ids.begin(), subdiag_ids.end(),subdiag_ids_ptr);
#endif
this->level = level; this->level = level;
} }
...@@ -241,6 +245,16 @@ namespace Faust ...@@ -241,6 +245,16 @@ namespace Faust
void ButterflyMat<FPP>::multiply(const FPP* x, FPP* y, size_t size) const void ButterflyMat<FPP>::multiply(const FPP* x, FPP* y, size_t size) const
{ {
const FPP *d1_ptr = D1.diagonal().data(), *d2_ptr = D2.diagonal().data(); const FPP *d1_ptr = D1.diagonal().data(), *d2_ptr = D2.diagonal().data();
#ifdef USE_PYTHONIC
auto xArray = arrayFromBuf1D(x, size);
auto d1Array = arrayFromBuf1D(d1_ptr, size);
auto d2Array = arrayFromBuf1D(d2_ptr, size);
auto x_ids = arrayFromBuf1D(subdiag_ids_ptr, size);
// auto yArray = __pythran_ButFactor_matmul::__matmul__()(d1Array, d2Array, xArray, x_ids);
auto yArray = arrayFromBuf1D(y, size);
yArray = pythonic::operator_::add(pythonic::operator_::mul(d1Array, xArray), pythonic::operator_::mul(d2Array, xArray[x_ids]));
memcpy(y, yArray.buffer, sizeof(FPP)*size);
#endif
#define BMAT_MULTIPLY_VEC_OMP_LOOP #define BMAT_MULTIPLY_VEC_OMP_LOOP
#ifdef BMAT_MULTIPLY_VEC_OMP_LOOP #ifdef BMAT_MULTIPLY_VEC_OMP_LOOP
#pragma omp parallel for #pragma omp parallel for
...@@ -261,7 +275,7 @@ namespace Faust ...@@ -261,7 +275,7 @@ namespace Faust
MatMap X_mat(const_cast<FPP*>(X) /* harmless, no modification*/, Y_nrows, X_ncols); MatMap X_mat(const_cast<FPP*>(X) /* harmless, no modification*/, Y_nrows, X_ncols);
MatMap Y_mat(Y, Y_nrows, X_ncols); MatMap Y_mat(Y, Y_nrows, X_ncols);
const FPP *d1_ptr = D1.diagonal().data(), *d2_ptr = D2.diagonal().data(); const FPP *d1_ptr = D1.diagonal().data(), *d2_ptr = D2.diagonal().data();
#ifdef BMAT_MULTIPLY_MAT_OMP_LOOP #ifdef BMAT_MULTIPLY_MAT_OMP_LOOP || ! (EIGEN_WORLD_VERSION > 3 || EIGEN_WORLD_VERSION >= 4 && EIGEN_MAJOR_VERSION >= 0)
// this is slower // this is slower
#pragma omp parallel for #pragma omp parallel for
for(int i=0;i < Y_nrows; i++) for(int i=0;i < Y_nrows; i++)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment