You could use unfold to achieve this:
A = torch.ones(10, 10) * 2
B = torch.arange(14*14).view(14, 14)
corr = torch.zeros(10, 10, 5, 5)

# Slow method
for i in range(10):
    for j in range(10):
        corr[i, j, :, :] = A[i, j] * B[i:i+5, j:j+5]

# Hopefully faster
corr2 = torch.zeros(10, 10, 5, 5)
D = B.unfold(0, 5, 1).unfold(1, 5, 1)
corr2 = D * A.unsqueeze(2).unsqueeze(3)

(corr == corr2).all()
print(corr[0, 0])
print(corr2[0, 0])