MCPcopy Create free account
hub / github.com/arrayfire/arrayfire / matmul

Function matmul

src/backend/opencl/sparse_blas.cpp:39–87  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

37
38template<typename T>
39Array<T> matmul(const common::SparseArray<T>& lhs, const Array<T>& rhsIn,
40 af_mat_prop optLhs, af_mat_prop optRhs) {
41#if defined(WITH_LINEAR_ALGEBRA)
42 if (OpenCLCPUOffload(
43 false)) { // Do not force offload gemm on OSX Intel devices
44 return cpu::matmul(lhs, rhsIn, optLhs, optRhs);
45 }
46#endif
47
48 int lRowDim = (optLhs == AF_MAT_NONE) ? 0 : 1;
49 // int lColDim = (optLhs == AF_MAT_NONE) ? 1 : 0;
50 static const int rColDim =
51 1; // Unsupported : (optRhs == AF_MAT_NONE) ? 1 : 0;
52
53 dim4 lDims = lhs.dims();
54 dim4 rDims = rhsIn.dims();
55 int M = lDims[lRowDim];
56 int N = rDims[rColDim];
57 // int K = lDims[lColDim];
58
59 const Array<T> rhs =
60 (N != 1 && optLhs == AF_MAT_NONE) ? transpose(rhsIn, false) : rhsIn;
61 Array<T> out = createEmptyArray<T>(af::dim4(M, N, 1, 1));
62
63 static const T alpha = scalar<T>(1.0);
64 static const T beta = scalar<T>(0.0);
65
66 const Array<T>& values = lhs.getValues();
67 const Array<int>& rowIdx = lhs.getRowIdx();
68 const Array<int>& colIdx = lhs.getColIdx();
69
70 if (optLhs == AF_MAT_NONE) {
71 if (N == 1) {
72 kernel::csrmv(out, values, rowIdx, colIdx, rhs, alpha, beta);
73 } else {
74 kernel::csrmm_nt(out, values, rowIdx, colIdx, rhs, alpha, beta);
75 }
76 } else {
77 // CSR transpose is a CSC matrix
78 if (N == 1) {
79 kernel::cscmv(out, values, rowIdx, colIdx, rhs, alpha, beta,
80 optLhs == AF_MAT_CTRANS);
81 } else {
82 kernel::cscmm_nn(out, values, rowIdx, colIdx, rhs, alpha, beta,
83 optLhs == AF_MAT_CTRANS);
84 }
85 }
86 return out;
87}
88
89#define INSTANTIATE_SPARSE(T) \
90 template Array<T> matmul<T>(const common::SparseArray<T>& lhs, \

Callers

nothing calls this directly

Calls 8

OpenCLCPUOffloadFunction · 0.85
csrmvFunction · 0.85
csrmm_ntFunction · 0.85
cscmvFunction · 0.85
cscmm_nnFunction · 0.85
transposeFunction · 0.70
dim4Class · 0.50
dimsMethod · 0.45

Tested by

no test coverage detected