gather.cpp 1.02 KB
Newer Older
rusty1s's avatar
rusty1s committed
1
2
3
4
5
6
#include <torch/extension.h>

#define CHECK_CUDA(x) AT_ASSERTM(x.type().is_cuda(), #x " must be CUDA tensor")

at::Tensor gather_csr_cuda(at::Tensor src, at::Tensor indptr,
                           at::optional<at::Tensor> out_opt);
rusty1s's avatar
rusty1s committed
7
8
at::Tensor gather_coo_cuda(at::Tensor src, at::Tensor index,
                           at::optional<at::Tensor> out_opt);
rusty1s's avatar
rusty1s committed
9
10
11
12
13
14
15
16
17
18

at::Tensor gather_csr(at::Tensor src, at::Tensor indptr,
                      at::optional<at::Tensor> out_opt) {
  CHECK_CUDA(src);
  CHECK_CUDA(indptr);
  if (out_opt.has_value())
    CHECK_CUDA(out_opt.value());
  return gather_csr_cuda(src, indptr, out_opt);
}

rusty1s's avatar
rusty1s committed
19
20
21
22
23
24
25
26
27
at::Tensor gather_coo(at::Tensor src, at::Tensor index,
                      at::optional<at::Tensor> out_opt) {
  CHECK_CUDA(src);
  CHECK_CUDA(index);
  if (out_opt.has_value())
    CHECK_CUDA(out_opt.value());
  return gather_coo_cuda(src, index, out_opt);
}

rusty1s's avatar
rusty1s committed
28
29
PYBIND11_MODULE(TORCH_EXTENSION_NAME, m) {
  m.def("gather_csr", &gather_csr, "Gather CSR (CUDA)");
rusty1s's avatar
rusty1s committed
30
  m.def("gather_coo", &gather_coo, "Gather COO (CUDA)");
rusty1s's avatar
rusty1s committed
31
}