metis.cpp 2.17 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
16
torch::Tensor partition(torch::Tensor rowptr, torch::Tensor col,
                        torch::optional<torch::Tensor> optional_value,
                        int64_t num_parts, bool recursive) {
rusty1s's avatar
rusty1s committed
17
18
19
20
21
  if (rowptr.device().is_cuda()) {
#ifdef WITH_CUDA
    AT_ERROR("No CUDA version supported");
#else
    AT_ERROR("Not compiled with CUDA support");
22
23
#endif
  } else {
24
    return partition_cpu(rowptr, col, optional_value, torch::nullopt, num_parts,
25
26
27
28
29
30
31
32
33
34
35
36
37
                         recursive);
  }
}

torch::Tensor partition2(torch::Tensor rowptr, torch::Tensor col,
                         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
38
39
#endif
  } else {
rusty1s's avatar
rename  
rusty1s committed
40
41
    return partition_cpu(rowptr, col, optional_value, optional_node_weight,
                         num_parts, recursive);
rusty1s's avatar
rusty1s committed
42
43
44
  }
}

rusty1s's avatar
rusty1s committed
45
46
torch::Tensor mt_partition(torch::Tensor rowptr, torch::Tensor col,
                           torch::optional<torch::Tensor> optional_value,
rusty1s's avatar
rename  
rusty1s committed
47
                           torch::optional<torch::Tensor> optional_node_weight,
rusty1s's avatar
rusty1s committed
48
49
50
51
52
53
54
55
56
                           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
57
58
    return mt_partition_cpu(rowptr, col, optional_value, optional_node_weight,
                            num_parts, recursive, num_workers);
rusty1s's avatar
rusty1s committed
59
60
61
62
63
  }
}

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