Pytorch source code csrc and aten in v2.2.0

Hello, I learned code of pytorch 2.2.0 recently, and I am confused in python invoking c++ backend.
I know pytorch us pybind11 to register c++ function to python, and different divices use dispatcher to register their implementation in aten directory。But what does csrc in torch directory do? If I invoke conv2d in python, follow the trace I find there is a torch::conv2d in csrc directory(torch/csrc/api/include/torch/nn/functional/conv.h), but the implementation of aten have the namespace torch::aten::xxxx , so I am confused, does torch::conv2d in csrc invoke function in aten ?

Namespace is exported from c10 to aten in pytorch cuda.

I don’t understand, if we choose one from following two graph, which is right?

Graph 2 is slightly off. after csrc it directly go to c++ functions. Try to read python files under torch/cuda/*.py.
As the following code:


will directly go to corresponding c++ functions registered in Module.cpp.

Note that other than pybind11, ctypes is also used,

For torch.rand like ops, it is indeed registered with pybind11, try compile pytorch from source and check torch/csrc/autograd/generated/python_torch_functionsEverything.cpp.

In these generated file, the call will be dispatched to target specific native implementation.

OK, I will check these files, Thank you very much for your detailed explanation. close question.