metis.cpp 1.31 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
PyMODINIT_FUNC PyInit__metis(void) { return NULL; }
rusty1s's avatar
rusty1s committed
8
9
#endif

rusty1s's avatar
update  
rusty1s committed
10
11
12
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
13
14
15
16
17
18
19
  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
update  
rusty1s committed
20
    return partition_cpu(rowptr, col, optional_value, num_parts, recursive);
rusty1s's avatar
rusty1s committed
21
22
23
  }
}

rusty1s's avatar
rusty1s committed
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
torch::Tensor mt_partition(torch::Tensor rowptr, torch::Tensor col,
                           torch::optional<torch::Tensor> optional_value,
                           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 {
    return mt_partition_cpu(rowptr, col, optional_value, num_parts, recursive,
                            num_workers);
  }
}

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