microsoft / knossos-ksc

Compiler with automatic differentiation
Other
45 stars 10 forks source link

Avoing tupling/untupling #538

Open toelli-msft opened 3 years ago

toelli-msft commented 3 years ago

Cgen sometimes generates code like the below

tuple<tuple<tensor<2, double>,tensor<1, double>,tensor<1, double>,int>,int> s_k
    = std::make_tuple(s_karg1,s_karg2);
auto [s, k] = s_k;

We would expect a good compiler to be able to optimise away such redundancy. However, I believe that a C++ compiler cannot because of technical reasons to do with std::tuple's historical properties.

See also https://github.com/microsoft/knossos-ksc/issues/528 and https://github.com/microsoft/knossos-ksc/issues/531.

Part of the cause is the way that we unpack tuple arguments in Cgen. Here is a synthesis of ideas from @dcrc2 and @simonpj to avoid the problem.

toelli-msft commented 3 years ago

I recommend waiting for https://github.com/microsoft/knossos-ksc/issues/531 to be resolved before implementing this strategy though. It may not be needed at all.

toelli-msft commented 3 years ago

Oh, and in Cgen we can also flatten nested tuple types as function arguments, if we think that would help.