metis.cpp 2.26 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
#include <torch/script.h>

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

rusty1s's avatar
rusty1s committed
8
#ifdef _WIN32
9
#ifdef WITH_PYTHON
rusty1s's avatar
rusty1s committed
10
11
12
13
14
#ifdef WITH_CUDA
PyMODINIT_FUNC PyInit__metis_cuda(void) { return NULL; }
#else
PyMODINIT_FUNC PyInit__metis_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 torch::Tensor partition(torch::Tensor rowptr, torch::Tensor col,
rusty1s's avatar
update  
rusty1s committed
19
20
                        torch::optional<torch::Tensor> optional_value,
                        int64_t num_parts, bool recursive) {
rusty1s's avatar
rusty1s committed
21
22
23
24
25
  if (rowptr.device().is_cuda()) {
#ifdef WITH_CUDA
    AT_ERROR("No CUDA version supported");
#else
    AT_ERROR("Not compiled with CUDA support");
26
27
#endif
  } else {
28
    return partition_cpu(rowptr, col, optional_value, torch::nullopt, num_parts,
29
30
31
32
                         recursive);
  }
}

Daniel Falbel's avatar
Daniel Falbel committed
33
SPARSE_API torch::Tensor partition2(torch::Tensor rowptr, torch::Tensor col,
34
35
36
37
38
39
40
41
                         torch::optional<torch::Tensor> optional_value,
                         torch::optional<torch::Tensor> optional_node_weight,
                         int64_t num_parts, bool recursive) {
  if (rowptr.device().is_cuda()) {
#ifdef WITH_CUDA
    AT_ERROR("No CUDA version supported");
#else
    AT_ERROR("Not compiled with CUDA support");
rusty1s's avatar
rusty1s committed
42
43
#endif
  } else {
rusty1s's avatar
rename  
rusty1s committed
44
45
    return partition_cpu(rowptr, col, optional_value, optional_node_weight,
                         num_parts, recursive);
rusty1s's avatar
rusty1s committed
46
47
48
  }
}

Daniel Falbel's avatar
Daniel Falbel committed
49
SPARSE_API torch::Tensor mt_partition(torch::Tensor rowptr, torch::Tensor col,
rusty1s's avatar
rusty1s committed
50
                           torch::optional<torch::Tensor> optional_value,
rusty1s's avatar
rename  
rusty1s committed
51
                           torch::optional<torch::Tensor> optional_node_weight,
rusty1s's avatar
rusty1s committed
52
53
54
55
56
57
58
59
60
                           int64_t num_parts, bool recursive,
                           int64_t num_workers) {
  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
rename  
rusty1s committed
61
62
    return mt_partition_cpu(rowptr, col, optional_value, optional_node_weight,
                            num_parts, recursive, num_workers);
rusty1s's avatar
rusty1s committed
63
64
65
66
67
  }
}

static auto registry = torch::RegisterOperators()
                           .op("torch_sparse::partition", &partition)
68
                           .op("torch_sparse::partition2", &partition2)
rusty1s's avatar
rusty1s committed
69
                           .op("torch_sparse::mt_partition", &mt_partition);