Fast method for get the gradient of an image

One of the methods is to apply the following kernel to an image.

[0, -1, 0
 -1, 0, 1
 0,  1, 0]

I wonder how I can directly operate on the tensor(4D). If so, is it fast than applying that kernel?

torch.nn.functional.conv2d