[eigen] Eigen containers cannot be vectorized |
[ Thread Index | Date Index | More lists.tuxfamily.org/eigen Archives ]
Hi, I have found that Eigen containers cannot be vectorized. For instance, the following code: #include <Eigen/Dense> void f(Eigen::Matrix<Eigen::Index, Eigen::Dynamic, Eigen::Dynamic>& A) { for (Eigen::Index j = 0; j < A.cols(); ++j) { for(Eigen::Index i = 0; i < A.rows(); ++i) { A(i, j) = i + j; } } } is not vectorized by the Intel compiler. It says that the iteration count cannot be computed before the execution of the loop. It is due to the fact that A is made of: Eigen::Index* data_; Eigen::Index cols_; Eigen::Index rows_; The compiler has no way of knowing that data_ does not point to rows_. As a consequence, it does not know that the operation A(i, j) = i + j does not change the number of rows of A. As a consequence, the loop is not countable and cannot be vectorized. One way to fix this, would be to store the number of columns as a pointer. If cols_ becomes a Eigen::Index* such that the number of columns is cols_ - data_, the problems get fixed, and compilers can know vectorize the inner loop. Best regards, François Fayard
Founder & Consultant - Inside Loop PS: I have found that if you change the type to double, it does not get vectorized too, but I have no idea why. |
Mail converted by MHonArc 2.6.19+ | http://listengine.tuxfamily.org/ |