sddmm.cu 3.75 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
/*!
 *  Copyright (c) 2020 by Contributors
 * \file array/cuda/sddmm.cu
 * \brief SDDMM C APIs and definitions.
 */
#include <dgl/array.h>
#include "./sddmm.cuh"
#include "./functor.cuh"

namespace dgl {
namespace aten {

/*!
 * \brief CUDA implementation of g-SDDMM on Csr format.
 */
16
template <int XPU, typename IdType, int bits>
17
18
19
void SDDMMCsr(const std::string& op,
              const BcastOff& bcast,
              const CSRMatrix& csr,
20
21
22
23
24
              NDArray lhs,
              NDArray rhs,
              NDArray out,
              int lhs_target,
              int rhs_target) {
25
26
27
28
29
  SWITCH_BITS(bits, DType, {
    SWITCH_OP(op, Op, {
      SWITCH_TARGET(lhs_target, rhs_target, LhsTarget, RhsTarget, {
        cuda::SDDMMCsr<IdType, DType, Op, LhsTarget, RhsTarget>(bcast, csr, lhs, rhs, out);
      });
30
    });
31
32
33
  });
}

34

35
36
37
/*!
 * \brief CUDA implementation of g-SDDMM on Coo format.
 */
38
template <int XPU, typename IdType, int bits>
39
40
41
void SDDMMCoo(const std::string& op,
              const BcastOff& bcast,
              const COOMatrix& coo,
42
43
44
45
46
              NDArray lhs,
              NDArray rhs,
              NDArray out,
              int lhs_target,
              int rhs_target) {
47
48
49
50
51
  SWITCH_BITS(bits, DType, {
    SWITCH_OP(op, Op, {
      SWITCH_TARGET(lhs_target, rhs_target, LhsTarget, RhsTarget, {
        cuda::SDDMMCoo<IdType, DType, Op, LhsTarget, RhsTarget>(bcast, coo, lhs, rhs, out);
      });
52
    });
53
54
55
  });
}

56

57
template void SDDMMCsr<kDLGPU, int32_t, 16>(
58
    const std::string& op, const BcastOff& bcast, const CSRMatrix& csr,
59
60
    NDArray lhs, NDArray rhs, NDArray out,
    int lhs_target, int rhs_target);
61
template void SDDMMCsr<kDLGPU, int64_t, 16>(
62
    const std::string& op, const BcastOff& bcast, const CSRMatrix& csr,
63
64
    NDArray lhs, NDArray rhs, NDArray out,
    int lhs_target, int rhs_target);
65
template void SDDMMCsr<kDLGPU, int32_t, 32>(
66
    const std::string& op, const BcastOff& bcast, const CSRMatrix& csr,
67
68
    NDArray lhs, NDArray rhs, NDArray out,
    int lhs_target, int rhs_target);
69
70
71
72
73
74
75
76
77
template void SDDMMCsr<kDLGPU, int64_t, 32>(
    const std::string& op, const BcastOff& bcast, const CSRMatrix& csr,
    NDArray lhs, NDArray rhs, NDArray out,
    int lhs_target, int rhs_target);
template void SDDMMCsr<kDLGPU, int32_t, 64>(
    const std::string& op, const BcastOff& bcast, const CSRMatrix& csr,
    NDArray lhs, NDArray rhs, NDArray out,
    int lhs_target, int rhs_target);
template void SDDMMCsr<kDLGPU, int64_t, 64>(
78
    const std::string& op, const BcastOff& bcast, const CSRMatrix& csr,
79
80
    NDArray lhs, NDArray rhs, NDArray out,
    int lhs_target, int rhs_target);
81

82
83
84
85
86
87
88
89
90
template void SDDMMCoo<kDLGPU, int32_t, 16>(
    const std::string& op, const BcastOff& bcast, const COOMatrix& coo,
    NDArray lhs, NDArray rhs, NDArray out,
    int lhs_target, int rhs_target);
template void SDDMMCoo<kDLGPU, int64_t, 16>(
    const std::string& op, const BcastOff& bcast, const COOMatrix& coo,
    NDArray lhs, NDArray rhs, NDArray out,
    int lhs_target, int rhs_target);
template void SDDMMCoo<kDLGPU, int32_t, 32>(
91
    const std::string& op, const BcastOff& bcast, const COOMatrix& coo,
92
93
    NDArray lhs, NDArray rhs, NDArray out,
    int lhs_target, int rhs_target);
94
template void SDDMMCoo<kDLGPU, int64_t, 32>(
95
    const std::string& op, const BcastOff& bcast, const COOMatrix& coo,
96
97
    NDArray lhs, NDArray rhs, NDArray out,
    int lhs_target, int rhs_target);
98
template void SDDMMCoo<kDLGPU, int32_t, 64>(
99
    const std::string& op, const BcastOff& bcast, const COOMatrix& coo,
100
101
    NDArray lhs, NDArray rhs, NDArray out,
    int lhs_target, int rhs_target);
102
template void SDDMMCoo<kDLGPU, int64_t, 64>(
103
    const std::string& op, const BcastOff& bcast, const COOMatrix& coo,
104
105
    NDArray lhs, NDArray rhs, NDArray out,
    int lhs_target, int rhs_target);
106
107
108

}  // namespace aten
}  // namespace dgl