relabel.cpp 1.32 KB
Newer Older
1
#ifdef WITH_PYTHON
rusty1s's avatar
rusty1s committed
2
#include <Python.h>
3
#endif
rusty1s's avatar
rusty1s committed
4
5
6
7
8
#include <torch/script.h>

#include "cpu/relabel_cpu.h"

#ifdef _WIN32
9
#ifdef WITH_PYTHON
rusty1s's avatar
rusty1s committed
10
#ifdef WITH_CUDA
rusty1s's avatar
typo  
rusty1s committed
11
PyMODINIT_FUNC PyInit__relabel_cuda(void) { return NULL; }
rusty1s's avatar
rusty1s committed
12
13
14
#else
PyMODINIT_FUNC PyInit__relabel_cpu(void) { return NULL; }
#endif
rusty1s's avatar
rusty1s committed
15
#endif
16
#endif
rusty1s's avatar
rusty1s committed
17

Daniel Falbel's avatar
Daniel Falbel committed
18
SPARSE_API std::tuple<torch::Tensor, torch::Tensor> relabel(torch::Tensor col,
rusty1s's avatar
rusty1s committed
19
20
21
22
23
24
25
26
27
28
29
30
                                                 torch::Tensor idx) {
  if (col.device().is_cuda()) {
#ifdef WITH_CUDA
    AT_ERROR("No CUDA version supported");
#else
    AT_ERROR("Not compiled with CUDA support");
#endif
  } else {
    return relabel_cpu(col, idx);
  }
}

Daniel Falbel's avatar
Daniel Falbel committed
31
SPARSE_API std::tuple<torch::Tensor, torch::Tensor, torch::optional<torch::Tensor>,
rusty1s's avatar
rusty1s committed
32
33
34
           torch::Tensor>
relabel_one_hop(torch::Tensor rowptr, torch::Tensor col,
                torch::optional<torch::Tensor> optional_value,
rusty1s's avatar
rusty1s committed
35
                torch::Tensor idx, bool bipartite) {
rusty1s's avatar
rusty1s committed
36
37
38
39
40
41
42
  if (rowptr.device().is_cuda()) {
#ifdef WITH_CUDA
    AT_ERROR("No CUDA version supported");
#else
    AT_ERROR("Not compiled with CUDA support");
#endif
  } else {
rusty1s's avatar
rusty1s committed
43
    return relabel_one_hop_cpu(rowptr, col, optional_value, idx, bipartite);
rusty1s's avatar
rusty1s committed
44
45
46
  }
}

rusty1s's avatar
rusty1s committed
47
static auto registry =
rusty1s's avatar
rusty1s committed
48
49
50
    torch::RegisterOperators()
        .op("torch_sparse::relabel", &relabel)
        .op("torch_sparse::relabel_one_hop", &relabel_one_hop);