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

#include "cpu/convert_cpu.h"

limm's avatar
limm committed
8
9
#ifdef WITH_CUDA
#include "cuda/convert_cuda.h"
quyuanhao123's avatar
quyuanhao123 committed
10
11
12
13
#endif

#ifdef _WIN32
#ifdef WITH_PYTHON
limm's avatar
limm committed
14
#ifdef WITH_CUDA
quyuanhao123's avatar
quyuanhao123 committed
15
16
17
18
19
20
21
22
23
PyMODINIT_FUNC PyInit__convert_cuda(void) { return NULL; }
#else
PyMODINIT_FUNC PyInit__convert_cpu(void) { return NULL; }
#endif
#endif
#endif

SPARSE_API torch::Tensor ind2ptr(torch::Tensor ind, int64_t M) {
  if (ind.device().is_cuda()) {
limm's avatar
limm committed
24
#ifdef WITH_CUDA
quyuanhao123's avatar
quyuanhao123 committed
25
26
27
28
29
30
31
32
33
34
35
    return ind2ptr_cuda(ind, M);
#else
    AT_ERROR("Not compiled with CUDA support");
#endif
  } else {
    return ind2ptr_cpu(ind, M);
  }
}

SPARSE_API torch::Tensor ptr2ind(torch::Tensor ptr, int64_t E) {
  if (ptr.device().is_cuda()) {
limm's avatar
limm committed
36
#ifdef WITH_CUDA
quyuanhao123's avatar
quyuanhao123 committed
37
38
39
40
41
42
43
44
45
46
47
48
    return ptr2ind_cuda(ptr, E);
#else
    AT_ERROR("Not compiled with CUDA support");
#endif
  } else {
    return ptr2ind_cpu(ptr, E);
  }
}

static auto registry = torch::RegisterOperators()
                           .op("torch_sparse::ind2ptr", &ind2ptr)
                           .op("torch_sparse::ptr2ind", &ptr2ind);