Pairwise distance between two tensor

I have two tensors A and B

A= 8X340X340X21X512 and B=8X340X340X21X512

How do i calculate pair wise distance between A and B?

Output tensor C is of size 8X340X340X21

Depending on your distance metric, you can write different code. For simple L1, it would be (A-B).abs()