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

Function matmul

src/backend/oneapi/sparse_blas.cpp:44–91  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

42
43template<typename T>
44Array<T> matmul(const common::SparseArray<T>& lhs, const Array<T>& rhsIn,
45 af_mat_prop optLhs, af_mat_prop optRhs) {
46 int lRowDim = (optLhs == AF_MAT_NONE) ? 0 : 1;
47 static const int rColDim =
48 1; // Unsupported : (optRhs == AF_MAT_NONE) ? 1 : 0;
49
50 dim4 lDims = lhs.dims();
51 dim4 rDims = rhsIn.dims();
52 dim4 rStrides = rhsIn.strides();
53 int M = lDims[lRowDim];
54 int N = rDims[rColDim];
55
56 Array<T> out = createEmptyArray<T>(af::dim4(M, N, 1, 1));
57 dim4 oStrides = out.strides();
58
59 static const T alpha = scalar<T>(1.0);
60 static const T beta = scalar<T>(0.0);
61
62 const Array<T>& values = lhs.getValues();
63 const Array<int>& rowIdx = lhs.getRowIdx();
64 const Array<int>& colIdx = lhs.getColIdx();
65 sycl::buffer<T, 1> valBuf = values.template getBufferWithOffset<T>();
66 sycl::buffer<int, 1> rowBuf = rowIdx.template getBufferWithOffset<int>();
67 sycl::buffer<int, 1> colBuf = colIdx.template getBufferWithOffset<int>();
68
69 const auto lOpts = toBlasTranspose(optLhs);
70 const auto rOpts = toBlasTranspose(optRhs);
71
72 sycl::buffer<T, 1> rhsBuf = rhsIn.template getBufferWithOffset<T>();
73 sycl::buffer<T, 1> outBuf = out.template getBufferWithOffset<T>();
74
75 ::oneapi::mkl::sparse::matrix_handle_t CSRHandle = nullptr;
76 ::oneapi::mkl::sparse::init_matrix_handle(&CSRHandle);
77 ::oneapi::mkl::sparse::set_csr_data(
78 getQueue(), CSRHandle, lDims[0], lDims[1],
79 ::oneapi::mkl::index_base::zero, rowBuf, colBuf, valBuf);
80
81 if (N == 1) {
82 ::oneapi::mkl::sparse::gemv(getQueue(), lOpts, alpha, CSRHandle, rhsBuf,
83 beta, outBuf);
84 } else {
85 ::oneapi::mkl::sparse::gemm(
86 getQueue(), ::oneapi::mkl::layout::col_major, lOpts, rOpts, alpha,
87 CSRHandle, rhsBuf, N, rStrides[1], beta, outBuf, oStrides[1]);
88 }
89 ::oneapi::mkl::sparse::release_matrix_handle(getQueue(), &CSRHandle);
90 return out;
91}
92
93#define INSTANTIATE_SPARSE(T) \
94 template Array<T> matmul<T>(const common::SparseArray<T>& lhs, \

Callers

nothing calls this directly

Calls 6

toBlasTransposeFunction · 0.70
gemmFunction · 0.70
dim4Class · 0.50
getQueueFunction · 0.50
dimsMethod · 0.45
stridesMethod · 0.45

Tested by

no test coverage detected