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

Function af_matmul

src/api/c/blas.cpp:235–315  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

233}
234
235af_err af_matmul(af_array *out, const af_array lhs, const af_array rhs,
236 const af_mat_prop optLhs, const af_mat_prop optRhs) {
237 try {
238 const ArrayInfo &lhsInfo = getInfo(lhs, false);
239 const ArrayInfo &rhsInfo = getInfo(rhs, true);
240
241 if (lhsInfo.isSparse()) {
242 return af_sparse_matmul(out, lhs, rhs, optLhs, optRhs);
243 }
244
245 const int aRowDim = (optLhs == AF_MAT_NONE) ? 0 : 1;
246 const int bColDim = (optRhs == AF_MAT_NONE) ? 1 : 0;
247
248 const af::dim4 &lDims = lhsInfo.dims();
249 const af::dim4 &rDims = rhsInfo.dims();
250 const int M = lDims[aRowDim];
251 const int N = rDims[bColDim];
252
253 const dim_t d2 = std::max(lDims[2], rDims[2]);
254 const dim_t d3 = std::max(lDims[3], rDims[3]);
255 const af::dim4 oDims = af::dim4(M, N, d2, d3);
256
257 af_dtype lhs_type = lhsInfo.getType();
258
259 af_array gemm_out = 0;
260 af_dtype gemm_out_type = (lhs_type != s8) ? lhs_type : f32;
261 AF_CHECK(af_create_handle(&gemm_out, oDims.ndims(), oDims.get(),
262 gemm_out_type));
263
264 switch (lhs_type) {
265 case f16: {
266 static const half alpha(1.0f);
267 static const half beta(0.0f);
268 AF_CHECK(af_gemm(&gemm_out, optLhs, optRhs, &alpha, lhs, rhs,
269 &beta));
270 break;
271 }
272 case f32: {
273 float alpha = 1.f;
274 float beta = 0.f;
275 AF_CHECK(af_gemm(&gemm_out, optLhs, optRhs, &alpha, lhs, rhs,
276 &beta));
277 break;
278 }
279 case c32: {
280 cfloat alpha{1.f, 0.f};
281 cfloat beta{0.f, 0.f};
282
283 AF_CHECK(af_gemm(&gemm_out, optLhs, optRhs, &alpha, lhs, rhs,
284 &beta));
285 break;
286 }
287 case f64: {
288 double alpha = 1.0;
289 double beta = 0.0;
290 AF_CHECK(af_gemm(&gemm_out, optLhs, optRhs, &alpha, lhs, rhs,
291 &beta));
292 break;

Callers 7

TESTFunction · 0.50
TESTFunction · 0.50
MatMulCheckFunction · 0.50
matmulFunction · 0.50
matmulNTFunction · 0.50
matmulTNFunction · 0.50
matmulTTFunction · 0.50

Calls 11

af_sparse_matmulFunction · 0.85
swapFunction · 0.85
isSparseMethod · 0.80
af_create_handleFunction · 0.70
af_gemmFunction · 0.70
maxFunction · 0.50
dim4Class · 0.50
dimsMethod · 0.45
getTypeMethod · 0.45
ndimsMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected