How to custom padding layer?

I want to build a custom padding layer, how to implement this without breaking autograd ?

http://pytorch.org/docs/0.3.1/notes/extending.html