In the tutorial you link, the cpp function is then used inside an autograd.Function. So you can save them in the autograd.Function that wraps your cpp implementation as you do in your current implementation.