metis.cpp 1.4 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
22
23
  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
24
    return partition_cpu(rowptr, col, optional_value, num_parts, recursive);
rusty1s's avatar
rusty1s committed
25
26
27
  }
}

rusty1s's avatar
rusty1s committed
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
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);