metis.cpp 1.62 KB
Newer Older
rusty1s's avatar
rusty1s committed
1
2
3
#include <Python.h>
#include <torch/script.h>

rusty1s's avatar
update  
rusty1s committed
4
5
#include "cpu/metis_cpu.h"

rusty1s's avatar
rusty1s committed
6
#ifdef _WIN32
rusty1s's avatar
rusty1s committed
7
8
9
10
11
#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
12
13
#endif

rusty1s's avatar
update  
rusty1s committed
14
15
torch::Tensor partition(torch::Tensor rowptr, torch::Tensor col,
                        torch::optional<torch::Tensor> optional_value,
rusty1s's avatar
rename  
rusty1s committed
16
                        torch::optional<torch::Tensor> optional_node_weight,
rusty1s's avatar
update  
rusty1s committed
17
                        int64_t num_parts, bool recursive) {
rusty1s's avatar
rusty1s committed
18
19
20
21
22
23
24
  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
25
26
    return partition_cpu(rowptr, col, optional_value, optional_node_weight,
                         num_parts, recursive);
rusty1s's avatar
rusty1s committed
27
28
29
  }
}

rusty1s's avatar
rusty1s committed
30
31
torch::Tensor mt_partition(torch::Tensor rowptr, torch::Tensor col,
                           torch::optional<torch::Tensor> optional_value,
rusty1s's avatar
rename  
rusty1s committed
32
                           torch::optional<torch::Tensor> optional_node_weight,
rusty1s's avatar
rusty1s committed
33
34
35
36
37
38
39
40
41
                           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
42
43
    return mt_partition_cpu(rowptr, col, optional_value, optional_node_weight,
                            num_parts, recursive, num_workers);
rusty1s's avatar
rusty1s committed
44
45
46
47
48
49
  }
}

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