I have been studying pytorch’s custom op registration. I noticed that there are these two classes used for registration. I am wondering why there isn’t a README for using TORCH_LIBRARY(), and what is the difference betweening using TORCH_LIBRARY(my_ops,m) and static auto registry = torch::RegisterOperators()
.op(“my_ops::myrelu”, torch::RegisterOperators::options()
.kernel<decltype(myrelu), &myrelu>(c10::DispatchKey::CPU));
Check out https://pytorch.org/tutorials/advanced/torch_script_custom_ops.html and https://pytorch.org/tutorials/advanced/dispatcher.html
Reference C++ docs at https://pytorch.org/cppdocs/api/file_torch_library.h.html
The APIs go into the same internal machinery, but the TORCH_LIBRARY API is the newer one and you should use it instead.
1 Like