scatter.cpp 926 Bytes
Newer Older
rusty1s's avatar
rusty1s committed
1
#include <Python.h>
rusty1s's avatar
rusty1s committed
2
3
4
#include <torch/script.h>

#include "cpu/scatter_cpu.h"
5
#include "utils.h"
rusty1s's avatar
rusty1s committed
6
7
8
9
10

#ifdef WITH_CUDA
#include "cuda/scatter_cuda.h"
#endif

rusty1s's avatar
rusty1s committed
11
12
13
14
15
16
17
18
#ifdef _WIN32
#if PY_MAJOR_VERSION < 3
PyMODINIT_FUNC init_C(void) { return NULL; }
#else
PyMODINIT_FUNC PyInit__C(void) { return NULL; }
#endif
#endif

rusty1s's avatar
rusty1s committed
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
std::tuple<torch::Tensor, torch::optional<torch::Tensor>>
scatter_fw(torch::Tensor src, torch::Tensor index, int64_t dim,
           torch::optional<torch::Tensor> optional_out,
           torch::optional<int64_t> dim_size, std::string reduce) {
  if (src.device().is_cuda()) {
#ifdef WITH_CUDA
    return scatter_cuda(src, index, dim, optional_out, dim_size, reduce);
#else
    AT_ERROR("Not compiled with CUDA support");
#endif
  } else {
    return scatter_cpu(src, index, dim, optional_out, dim_size, reduce);
  }
}

rusty1s's avatar
rusty1s committed
34
35
static auto registry =
    torch::RegisterOperators().op("torch_scatter::scatter_fw", &scatter_fw);