I checked numpy implementation in https://github.com/numpy/numpy/blob/v1.17.0/numpy/lib/histograms.py#L935-L1113 12
At the end algorithm in (step 3) is using 1D histogramming  -  np.bincount
Hovewer, numpy implementation assume non uniform binning - to find bins they use internally np.searchsorted.
In case searchsorted will be difficult to implement (I did not find it in pytorch= only external https://github.com/aliutkus/torchsearchsorted 6), uniform binning will be sufficient.
Algorithm:

Calculate bin edges if not provided
Compute the bin number each sample falls into - assuming non uniform binning
np.searchsorted

Compute the sample indices in the flattened histogram matrix
np.ravel_multi_index

Compute the number of repetitions in xy and assign it to the flattened histmat.
np.bincount

Shape into a proper matrix
hist.reshape(nbin)