If your C++ op calls a C++ autograd op (i.e. a class that extends public torch::autograd::Function), it will act the same as torch.autograd.Function. For the code below, if you bind my_cool_op and call it from TorchScript, it will use the backward you defined in MyCoolOp
#include <torch/all.h>
#include <torch/python.h>

class MyCoolOp : public torch::autograd::Function<MyCoolOp> {
 public:
  static torch::autograd::variable_list forward(
      torch::autograd::AutogradContext* ctx,
      torch::autograd::Variable input) {
    // forward calculation
  }

  static torch::autograd::variable_list backward(
      torch::autograd::AutogradContext* ctx,
      torch::autograd::variable_list grad_output) {
    // backward calculation
  }
};

torch::Tensor my_cool_op(const torch::Tensor& input) {
  return MyCoolOp::apply(input);
}