[eigen] Can't seem to use Eigen::Tensor::contract at all with EIGEN_NO_MALLOC on v3.3.90

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


Hi everyone,

I've just been chasing down all the heap buffers that a ML model I'm working on it using, so I started compiling with the EIGEN_NO_MALLOC macro. As far as I can tell there must be some internal heap allocation going on inside the contract operation. I've made a minimal example shown below that uses a contraction to calculate a matrix multiplication, it crashes with a Eigen::internal::check_that_malloc_is_allowed(): Assertion failure if compiled with -DEIGEN_NO_MALLOC

Is this expected behaviour? Is there any way of removing the heap allocation from within this operation, maybe using a existing buffer on the stack instead?

Thanks,

Pete

------------------------------------------------------------------------------------------------
#include <iostream>
#include <unsupported/Eigen/CXX11/Tensor>

int main()
{
std::cout << "Testing Eigen v" << EIGEN_WORLD_VERSION << "." << EIGEN_MAJOR_VERSION << "." << EIGEN_MINOR_VERSION << std::endl;

int tensorSize = 300;

Eigen::Tensor<float, 2> tensorA(tensorSize, tensorSize), tensorB(tensorSize, tensorSize);
Eigen::Tensor<float, 2> contractionResult(tensorSize, tensorSize);

tensorA.setRandom();
tensorB.setRandom();

contractionResult = tensorA.contract(tensorB, Eigen::array<Eigen::IndexPair<int>, 1>{Eigen::IndexPair < int > (1, 0)});

std::cout << "Contraction Result:\n" << contractionResult << std::endl;
}


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