spmm.cpp 749 Bytes
Newer Older
rusty1s's avatar
rusty1s committed
1
2
3
4
#include <torch/extension.h>

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

rusty1s's avatar
rusty1s committed
5
6
7
std::tuple<at::Tensor, at::optional<at::Tensor>>
spmm_cuda(at::Tensor rowptr, at::Tensor col, at::optional<at::Tensor> value_opt,
          at::Tensor mat, std::string reduce);
rusty1s's avatar
rusty1s committed
8

rusty1s's avatar
rusty1s committed
9
10
11
std::tuple<at::Tensor, at::optional<at::Tensor>>
spmm(at::Tensor rowptr, at::Tensor col, at::optional<at::Tensor> value_opt,
     at::Tensor mat, std::string reduce) {
rusty1s's avatar
rusty1s committed
12
13
  CHECK_CUDA(rowptr);
  CHECK_CUDA(col);
rusty1s's avatar
rusty1s committed
14
15
  if (value_opt.has_value())
    CHECK_CUDA(value_opt.value());
rusty1s's avatar
rusty1s committed
16
  CHECK_CUDA(mat);
rusty1s's avatar
rusty1s committed
17
  return spmm_cuda(rowptr, col, value_opt, mat, reduce);
rusty1s's avatar
rusty1s committed
18
19
20
21
22
}

PYBIND11_MODULE(TORCH_EXTENSION_NAME, m) {
  m.def("spmm", &spmm, "Sparse Matrix Multiplication (CUDA)");
}