Dynamically loading symbols from libtorch.so

Hello,

I have a python module relab and a C++ extension librelab.so. The python module depends on torch and the C++ extension depends on libtorch.so. I am trying to create a package on PyPI, I believe the only way to achieve that is by dynamically loading symbols from libtorch.

To do so, I am trying to use dlopen and dlsym, but my problem start when trying to load a simple function such as torch::zeros. Indeed, there is no symbol zeros in libtorch.so, instead these symbols seems to be defined in libtorch_cpu.so and libtorch_cuda.so.

Does that means that I need to load different symbols depending on whether I want to create a tensor on the CPU or on the GPU?

Is there a way to load the symbol corresponding to the standard torch::zeros?