Check out https://pytorch.org/tutorials/advanced/torch_script_custom_ops.html 23 and https://pytorch.org/tutorials/advanced/dispatcher.html 17
Reference C++ docs at https://pytorch.org/cppdocs/api/file_torch_library.h.html 17
The APIs go into the same internal machinery, but the TORCH_LIBRARY API is the newer one and you should use it instead.