CompositeExplicitAutogradFunctions.h 1.9 KB

1234567891011121314151617181920212223242526272829
  1. #include <ATen/core/TensorBody.h>
  2. // TODO Undo all logic introduced for Note [Avoiding Include Cycles In Static Dispatch]
  3. // Code introduced to avoid cyclic dependency in static dispatch is no longer
  4. // needed as static dispatch logic is moved from TensorBody.h, which caused cycles in the first place,
  5. // to Operators.cpp for supporting multiple backends with multiple kernels.
  6. //
  7. // Note [Avoiding Include Cycles In Static Dispatch]
  8. // In order to avoid #include cycles in the static dispatch build, we've carefully split out
  9. // the static function definition files into {DispatchKey}Functions.h and {DispatchKey}Functions_inl.h.
  10. //
  11. // Without this split, the include cycle looks like TensorBody.h -> CPUFunctions.h -> TensorBody.h.
  12. // - TensorBody.h #includes CPUFunctions.h in the static dispatch build, because the tensor methods
  13. // all need to call into the fastpath C++ API defined in CPUFunctions.h. The methods are also all
  14. // directly inlined into TensorBody.h.
  15. // - CPUFunctions.h #includes TensorBody.h because it contains function declarations for the entire C++ API,
  16. // which include functions that have defaultable optional<Tensor> arguments.
  17. // That requires knowing the full Tensor class definition.
  18. //
  19. // We break the cycle by doing the following:
  20. // - Split out CPUFunction.h into two files: CPUFunctions.h and CPUFunctions_inl.h
  21. // - CPUFunction.h is a dummy file that just includes the Tensor class and includes CPUFunctions_inl.,
  22. // - CPUFunctions_inl.h includes everything else
  23. // - (only in the static dispatch build) TensorBody.h makes sure to finish defining the Tensor class,
  24. // and then it includes CPUFunctions_inl.h.
  25. // - All other files that want the cpu fastpath functions can include CPUFunctions.h directly.
  26. // - This also means that static dispatch build, CPUFunctions.h only needs to
  27. // #include TensorBody.h, and it will automatically bring in CPUFunctions_inl.h.
  28. #include <ATen/CompositeExplicitAutogradFunctions_inl.h>