This is intended behavior. You could conceivably modify the code in, e.g., TensorContraction.h and TensorContractionThreadPool.h to allocate blocks on the stack.
On Tue, Sep 3, 2019 at 8:21 AM Pete Blacker <[email protected]> wrote: > 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; > } >
