[eigen] Can I force (or hint) Eigen to not vectorise a particular expression?

[ Thread Index | Date Index | More lists.tuxfamily.org/eigen Archives ]


Hi,

I've got some dynamic matrices, whose size is rather small (say 5x5) which I multiply by vectors a lot.
Eigen::Matrix<double, Eigen::Dynamic, Eigen::Dynamic> block(5, 5);

The vectorisation overhead for these small dynamic matrices is bigger than the gain (verified with -DEIGEN_DONT_VECTORIZE).
Without the DONT_VECTORIZE define (because I don't want this behaviour everywhere), is there
a way to tell Eigen not to vectorise a particular expression or operations on the matrix?

My current inner loop looks like this (SparseBlockMatrix * BlockVector)

      Eigen::Matrix<typename ResultDerived::Scalar,
        ResultDerived::ColsAtCompileTime, 1, ResultDerived::PlainObject::Options & ~Eigen::RowMajor,
        ResultDerived::MaxColsAtCompileTime, 1> blockSum(blockRows);
      for (IndexT outer = 0; outer < GetNumOuter(); ++outer)
      {
        blockSum.setZero();
        for (auto innerIt = InnerIteratorBegin(outer), end = InnerIteratorEnd(outer); innerIt != end; ++innerIt)
        {
          assert(blockRows == innerIt->rows());
          assert(blockCols == innerIt->cols());
          blockSum.noalias() += (*innerIt) * vector.row(innerIt..col()).transpose();
        }
        result.row(outer) = blockSum;
      }

The
          blockSum.noalias() += (*innerIt) * vector.row(innerIt..col()).transpose();
line leads me to Eigen::internal::general_matrix_vector_product, where ~83% of my time is spent.

For a particular test-case using various 5x5 matrices, the timings are as follows
- 13908 ms with dynamic 5x5 matrices
- 10271 ms with dynamic 5x5 matrices and EIGEN_DONT_VECTORIZE
- 4745 ms with fixed-size 5x5 matrices (not vectorized either way)


Best regards

Daniel Vollmer

--------------------------
Deutsches Zentrum für Luft- und Raumfahrt e.V. (DLR)
German Aerospace Center
Institute of Aerodynamics and Flow Technology | Lilienthalplatz 7 | 38108 Braunschweig | Germany



Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/