spspmm.cpp 1.14 KB
Newer Older
rusty1s's avatar
rusty1s committed
1
#include <torch/script.h>
rusty1s's avatar
rusty1s committed
2

rusty1s's avatar
rusty1s committed
3
4
#define CHECK_CUDA(x)                                                          \
  AT_ASSERTM(x.device().is_cuda(), #x " must be CUDA tensor")
rusty1s's avatar
rusty1s committed
5

rusty1s's avatar
rusty1s committed
6
7
8
9
10
std::tuple<torch::Tensor, torch::Tensor, torch::optional<torch::Tensor>>
spspmm_cuda(torch::Tensor rowptrA, torch::Tensor colA,
            torch::optional<torch::Tensor> valueA, torch::Tensor rowptrB,
            torch::Tensor colB, torch::optional<torch::Tensor> valueB,
            int64_t M, int64_t N, int64_t K);
rusty1s's avatar
to csr  
rusty1s committed
11

rusty1s's avatar
rusty1s committed
12
13
14
15
16
std::tuple<torch::Tensor, torch::Tensor, torch::optional<torch::Tensor>>
spspmm(torch::Tensor rowptrA, torch::Tensor colA,
       torch::optional<torch::Tensor> valueA, torch::Tensor rowptrB,
       torch::Tensor colB, torch::optional<torch::Tensor> valueB, int64_t M,
       int64_t N, int64_t K) {
rusty1s's avatar
rusty1s committed
17
18
19
20
21
22
23
24
25
  CHECK_CUDA(rowptrA);
  CHECK_CUDA(colA);
  if (valueA.has_value())
    CHECK_CUDA(valueA.value());
  CHECK_CUDA(rowptrB);
  CHECK_CUDA(colB);
  if (valueB.has_value())
    CHECK_CUDA(valueB.value());
  return spspmm_cuda(rowptrA, colA, valueA, rowptrB, colB, valueB, M, N, K);
rusty1s's avatar
rusty1s committed
26
27
}

rusty1s's avatar
rusty1s committed
28
29
static auto registry =
    torch::RegisterOperators("torch_sparse_cuda::spspmm", &spspmm);