mitsuba-renderer / enoki

Enoki: structured vectorization and differentiation on modern processor architectures
Other
1.26k stars 94 forks source link

Infinite recursion in matrix vector product with DiffArray #97

Open eliemichel opened 4 years ago

eliemichel commented 4 years ago

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

Speierers commented 4 years ago

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?

eliemichel commented 4 years ago

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.

Speierers commented 4 years ago

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.

eliemichel commented 4 years ago

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