microsoft / knossos-ksc

Compiler with automatic differentiation
Other
45 stars 10 forks source link

Remove special case for inclusion of prelude-aten in knossos.h #991

Closed dcrc2 closed 2 years ago

dcrc2 commented 2 years ago

This PR removes the macro KS_INLCUDE_ATEN which controlled whether the file prelude-aten.cpp was included at the bottom of knossos.h. The immediate reason for doing this is that we're going to want a different version of the ATen prelude when compiling code for the GPU.

Ideally, when the ATen prelude was used, the ksc-generated C++ would #include "prelude-aten.cpp" at the top of the file, immediately after #include "knossos.h".

This PR achieves this by modifying the C++ immediately after it has been generated by ksc. (Actually it ends up writing #include "prelude-aten.cpp" before #include "knossos.h", but that's OK because prelude-aten.cpp starts by including knossos.h anyway.)

An alternative would be to add an option to ksc to insert the correct #include for each prelude that was used. This might be cleaner because it would mean that the C++ generated by ksc was self-contained. But since we're modifying ksc's generated code anyway (adding entry point definitions and the pybind module), it seems OK to add the #include here as well.

toelli-msft commented 2 years ago

Thanks! This seems cleaner to me.

An alternative would be to add an option to ksc to insert the correct #include for each prelude that was used.

That sounds like a good ultimate goal but this PR is a good stepping stone.