spspmm.cpp 1.08 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
#define CHECK_CUDA(x) AT_ASSERTM(x.type().is_cuda(), #x " must be CUDA tensor")
rusty1s's avatar
rusty1s committed
4

rusty1s's avatar
rusty1s committed
5
6
7
8
9
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
10

rusty1s's avatar
rusty1s committed
11
12
13
14
15
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
16
17
18
19
20
21
22
23
24
  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
25
26
}

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