enoki icon indicating copy to clipboard operation
enoki copied to clipboard

Infinite recursion in matrix vector product with DiffArray

Open eliemichel opened this issue 5 years ago • 4 comments

The following snippet leads a stack overflow because of an infinite recursion:

using Vector2fD = Array<DiffArray<float>, 2>;
using Matrix2x2f = Matrix<float, 2>;

Vector2fD y(.2f, .3f);

auto [s, c] = sincos(0.7853981633974483f);
Matrix2x2f m(c, s, -s, c);

Vector2fD z = m * y; // here

Here is a the beginning of the call stack:

callstack

Built with MSVC16, without CUDA, commit e240a4b

eliemichel avatar Jun 28 '20 10:06 eliemichel

Hi @eliemichel , For your information, DiffArray have only been tested with CUDAArray. I doubt they work with simple float.

Could you try this code with CUDAArray instead?

Speierers avatar Jul 06 '20 08:07 Speierers

Hi Sebastien, Don't have CUDA set up here. I understand DiffArrays with simple floats received less attention, nevertheless they are explicitly implemented here https://github.com/mitsuba-renderer/enoki/blob/master/src/autodiff/autodiff.cpp#L1223 which means somebody though about supporting them. It worked for me most of the time, except for the two issues I reported, and since it is templated code issues on the CPU implementation may reveal flaws that affect the CUDA implementation as well.

eliemichel avatar Jul 06 '20 13:07 eliemichel

We are currently working on a major patch for enoki that will affect most of the codebase. Unfortunately I won't have the time to look into this at the moment as what you are trying to do isn't "officially" supported by the current version of the library.

You will need to dig a bit further yourself and I will be happy to help if you can provide some more insight on this bug.

Speierers avatar Jul 07 '20 06:07 Speierers

I understand, no worry, I worked it around by replacing the matrix vector product by a series of dot products for now.

eliemichel avatar Jul 07 '20 08:07 eliemichel