nearest.cpp 753 Bytes
Newer Older
1
#include <torch/extension.h>
rusty1s's avatar
rusty1s committed
2

rusty1s's avatar
rusty1s committed
3
4
#define CHECK_CUDA(x)                                                          \
  AT_ASSERTM(x.device().is_cuda(), #x " must be CUDA tensor")
rusty1s's avatar
rusty1s committed
5
6
#define IS_CONTIGUOUS(x) AT_ASSERTM(x.is_contiguous(), #x " is not contiguous");

rusty1s's avatar
typos  
rusty1s committed
7
8
at::Tensor nearest_cuda(at::Tensor x, at::Tensor y, at::Tensor batch_x,
                        at::Tensor batch_y);
rusty1s's avatar
rusty1s committed
9

rusty1s's avatar
typos  
rusty1s committed
10
11
at::Tensor nearest(at::Tensor x, at::Tensor y, at::Tensor batch_x,
                   at::Tensor batch_y) {
rusty1s's avatar
rusty1s committed
12
13
14
15
16
17
18
19
20
21
22
23
  CHECK_CUDA(x);
  IS_CONTIGUOUS(x);
  CHECK_CUDA(y);
  IS_CONTIGUOUS(y);
  CHECK_CUDA(batch_x);
  CHECK_CUDA(batch_y);
  return nearest_cuda(x, y, batch_x, batch_y);
}

PYBIND11_MODULE(TORCH_EXTENSION_NAME, m) {
  m.def("nearest", &nearest, "Nearest Neighbor (CUDA)");
}