Could you post the shape of your matrix?
nn.Softmax2d should apply the softmax using the channel dimension.
You could try the following code:
x = torch.randn(1, 1, 16, 16)
y = nn.Softmax(2)(x.view(1, 1, -1)).view_as(x)