sparse.h 4 KB
Newer Older
rusty1s's avatar
rusty1s committed
1
2
#pragma once

Matthias Fey's avatar
Matthias Fey committed
3
#include <torch/extension.h>
rusty1s's avatar
rusty1s committed
4

Daniel Falbel's avatar
Daniel Falbel committed
5
6
7
8
9
10
11
12
13
#ifdef _WIN32
#if defined(torchsparse_EXPORTS)
#define SPARSE_API __declspec(dllexport)
#else
#define SPARSE_API __declspec(dllimport)
#endif
#else
#define SPARSE_API
#endif
rusty1s's avatar
rusty1s committed
14

Matthias Fey's avatar
Matthias Fey committed
15
16
17
18
19
20
21
22
23
#if (defined __cpp_inline_variables) || __cplusplus >= 201703L
#define SPARSE_INLINE_VARIABLE inline
#else
#ifdef _MSC_VER
#define SPARSE_INLINE_VARIABLE __declspec(selectany)
#else
#define SPARSE_INLINE_VARIABLE __attribute__((weak))
#endif
#endif
rusty1s's avatar
rusty1s committed
24

Matthias Fey's avatar
Matthias Fey committed
25
26
27
28
29
30
31
namespace sparse {
SPARSE_API int64_t cuda_version() noexcept;

namespace detail {
SPARSE_INLINE_VARIABLE int64_t _cuda_version = cuda_version();
} // namespace detail
} // namespace sparse
Daniel Falbel's avatar
Daniel Falbel committed
32
33
34
35

SPARSE_API torch::Tensor ind2ptr(torch::Tensor ind, int64_t M);
SPARSE_API torch::Tensor ptr2ind(torch::Tensor ptr, int64_t E);

Matthias Fey's avatar
Matthias Fey committed
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
SPARSE_API torch::Tensor
partition(torch::Tensor rowptr, torch::Tensor col,
          torch::optional<torch::Tensor> optional_value, int64_t num_parts,
          bool recursive);

SPARSE_API torch::Tensor
partition2(torch::Tensor rowptr, torch::Tensor col,
           torch::optional<torch::Tensor> optional_value,
           torch::optional<torch::Tensor> optional_node_weight,
           int64_t num_parts, bool recursive);

SPARSE_API torch::Tensor
mt_partition(torch::Tensor rowptr, torch::Tensor col,
             torch::optional<torch::Tensor> optional_value,
             torch::optional<torch::Tensor> optional_node_weight,
             int64_t num_parts, bool recursive, int64_t num_workers);

Daniel Falbel's avatar
Daniel Falbel committed
53
SPARSE_API std::tuple<torch::Tensor, torch::Tensor> relabel(torch::Tensor col,
Matthias Fey's avatar
Matthias Fey committed
54
                                                            torch::Tensor idx);
rusty1s's avatar
rusty1s committed
55

Matthias Fey's avatar
Matthias Fey committed
56
57
SPARSE_API std::tuple<torch::Tensor, torch::Tensor,
                      torch::optional<torch::Tensor>, torch::Tensor>
rusty1s's avatar
rusty1s committed
58
59
relabel_one_hop(torch::Tensor rowptr, torch::Tensor col,
                torch::optional<torch::Tensor> optional_value,
Daniel Falbel's avatar
Daniel Falbel committed
60
                torch::Tensor idx, bool bipartite);
rusty1s's avatar
rusty1s committed
61

Daniel Falbel's avatar
Daniel Falbel committed
62
SPARSE_API torch::Tensor random_walk(torch::Tensor rowptr, torch::Tensor col,
Matthias Fey's avatar
Matthias Fey committed
63
                                     torch::Tensor start, int64_t walk_length);
rusty1s's avatar
rusty1s committed
64

Daniel Falbel's avatar
Daniel Falbel committed
65
SPARSE_API std::tuple<torch::Tensor, torch::Tensor, torch::Tensor>
rusty1s's avatar
rusty1s committed
66
67
68
subgraph(torch::Tensor idx, torch::Tensor rowptr, torch::Tensor row,
         torch::Tensor col);

Matthias Fey's avatar
Matthias Fey committed
69
70
SPARSE_API
std::tuple<torch::Tensor, torch::Tensor, torch::Tensor, torch::Tensor>
Daniel Falbel's avatar
Daniel Falbel committed
71
72
sample_adj(torch::Tensor rowptr, torch::Tensor col, torch::Tensor idx,
           int64_t num_neighbors, bool replace);
rusty1s's avatar
rusty1s committed
73

Daniel Falbel's avatar
Daniel Falbel committed
74
SPARSE_API torch::Tensor spmm_sum(torch::optional<torch::Tensor> opt_row,
Matthias Fey's avatar
Matthias Fey committed
75
76
77
78
79
                                  torch::Tensor rowptr, torch::Tensor col,
                                  torch::optional<torch::Tensor> opt_value,
                                  torch::optional<torch::Tensor> opt_colptr,
                                  torch::optional<torch::Tensor> opt_csr2csc,
                                  torch::Tensor mat);
rusty1s's avatar
rusty1s committed
80

Daniel Falbel's avatar
Daniel Falbel committed
81
SPARSE_API torch::Tensor spmm_mean(torch::optional<torch::Tensor> opt_row,
Matthias Fey's avatar
Matthias Fey committed
82
83
84
85
86
87
                                   torch::Tensor rowptr, torch::Tensor col,
                                   torch::optional<torch::Tensor> opt_value,
                                   torch::optional<torch::Tensor> opt_rowcount,
                                   torch::optional<torch::Tensor> opt_colptr,
                                   torch::optional<torch::Tensor> opt_csr2csc,
                                   torch::Tensor mat);
rusty1s's avatar
rusty1s committed
88

Daniel Falbel's avatar
Daniel Falbel committed
89
SPARSE_API std::tuple<torch::Tensor, torch::Tensor>
rusty1s's avatar
rusty1s committed
90
91
92
spmm_min(torch::Tensor rowptr, torch::Tensor col,
         torch::optional<torch::Tensor> opt_value, torch::Tensor mat);

Daniel Falbel's avatar
Daniel Falbel committed
93
SPARSE_API std::tuple<torch::Tensor, torch::Tensor>
rusty1s's avatar
rusty1s committed
94
95
96
spmm_max(torch::Tensor rowptr, torch::Tensor col,
         torch::optional<torch::Tensor> opt_value, torch::Tensor mat);

Matthias Fey's avatar
Matthias Fey committed
97
98
SPARSE_API
std::tuple<torch::Tensor, torch::Tensor, torch::optional<torch::Tensor>>
rusty1s's avatar
rusty1s committed
99
100
101
spspmm_sum(torch::Tensor rowptrA, torch::Tensor colA,
           torch::optional<torch::Tensor> optional_valueA,
           torch::Tensor rowptrB, torch::Tensor colB,
Matthias Fey's avatar
Matthias Fey committed
102
           torch::optional<torch::Tensor> optional_valueB, int64_t K);