".github/workflows/cuda/cu118-Windows-env.sh" did not exist on "fd95865ccbe556d82d5cbd492502da818fd02fbb"
knn.cpp 973 Bytes
Newer Older
1
#ifdef WITH_PYTHON
rusty1s's avatar
rusty1s committed
2
#include <Python.h>
3
#endif
rusty1s's avatar
rusty1s committed
4
5
#include <torch/script.h>

rusty1s's avatar
rusty1s committed
6
7
#include "cpu/knn_cpu.h"

rusty1s's avatar
rusty1s committed
8
9
10
11
12
#ifdef WITH_CUDA
#include "cuda/knn_cuda.h"
#endif

#ifdef _WIN32
13
#ifdef WITH_PYTHON
rusty1s's avatar
rusty1s committed
14
15
16
17
18
#ifdef WITH_CUDA
PyMODINIT_FUNC PyInit__knn_cuda(void) { return NULL; }
#else
PyMODINIT_FUNC PyInit__knn_cpu(void) { return NULL; }
#endif
rusty1s's avatar
rusty1s committed
19
#endif
20
#endif
rusty1s's avatar
rusty1s committed
21

YoannPitarch's avatar
YoannPitarch committed
22
CLUSTER_API torch::Tensor knn(torch::Tensor x, torch::Tensor y,
rusty1s's avatar
rusty1s committed
23
24
25
                  torch::optional<torch::Tensor> ptr_x,
                  torch::optional<torch::Tensor> ptr_y, int64_t k, bool cosine,
                  int64_t num_workers) {
rusty1s's avatar
rusty1s committed
26
27
  if (x.device().is_cuda()) {
#ifdef WITH_CUDA
rusty1s's avatar
rusty1s committed
28
    return knn_cuda(x, y, ptr_x, ptr_y, k, cosine);
rusty1s's avatar
rusty1s committed
29
30
31
32
#else
    AT_ERROR("Not compiled with CUDA support");
#endif
  } else {
rusty1s's avatar
rusty1s committed
33
    if (cosine)
34
      AT_ERROR("`cosine` argument not supported on CPU");
rusty1s's avatar
rusty1s committed
35
    return knn_cpu(x, y, ptr_x, ptr_y, k, num_workers);
rusty1s's avatar
rusty1s committed
36
37
38
39
40
  }
}

static auto registry =
    torch::RegisterOperators().op("torch_cluster::knn", &knn);