I guess this should work:
x = torch.rand(4, 3, 6, 6)
k = torch.rand(3, 10, 2, 2)
(x.unfold(2, 2, 1).unfold(3, 2, 1).unsqueeze(2) * k.unsqueeze(0).unsqueeze(3).unsqueeze(4)).sum(-1).sum(-1).sum(1)

where the batch size is 4, number of input channel is 3, number of output channel is 10, and kernel size is 2, stride is 1, in this example.