The usual route is to use an extension
Peter Goldsborough wrote a neat tutorial how to do this:

  
      
      GitHub
  
  
    

pytorch/extension-cpp 3

extension-cpp - C++ extensions in PyTorch


  
  
    
    
  
  


Best regards
Thomas