| 338 | )"; |
| 339 | |
| 340 | inline KernelCode createMatmul4(const char *shaderTemplate, const size_t M, |
| 341 | const size_t K, const size_t N, const size_t BM, |
| 342 | const size_t BK, const size_t BN, |
| 343 | const size_t TM, const size_t TN, |
| 344 | const Shape &workgroupSize = {256, 1, 1}, |
| 345 | NumType precision = kf32, |
| 346 | bool unrolling = false) { |
| 347 | assert(BM % TM == 0); |
| 348 | assert(BN % TN == 0); |
| 349 | assert(K % BK == 0); |
| 350 | assert(M % BM == 0); |
| 351 | assert(N % BN == 0); |
| 352 | // # threads = tile A size == tile B size == # threads for computing C |
| 353 | int num_threads = BM * BN / (TM * TN); |
| 354 | std::string codeString(shaderTemplate); |
| 355 | replaceAll(codeString, {{"{{workgroupSize}}", toString(workgroupSize)}, |
| 356 | {"{{precision}}", toString(precision)}, |
| 357 | {"{{M}}", toString(M)}, |
| 358 | {"{{K}}", toString(K)}, |
| 359 | {"{{N}}", toString(N)}, |
| 360 | {"{{BM}}", toString(BM)}, |
| 361 | {"{{BK}}", toString(BK)}, |
| 362 | {"{{BN}}", toString(BN)}, |
| 363 | {"{{TM}}", toString(TM)}, |
| 364 | {"{{TN}}", toString(TN)}, |
| 365 | {"{{NUM_TILEA}}", toString(BM * BK / num_threads)}, |
| 366 | {"{{NUM_TILEB}}", toString(BN * BK / num_threads)} |
| 367 | }); |
| 368 | if (unrolling) { |
| 369 | std::string unrolledCode = loopUnrolling(codeString); |
| 370 | // LOG(kDefLog, kInfo, "Unrolled code:\n%s", unrolledCode.c_str()); |
| 371 | return {unrolledCode, workgroupSize, precision}; |
| 372 | } else { |
| 373 | return {codeString, workgroupSize, precision}; |
| 374 | } |
| 375 | } |
| 376 | |
| 377 | /* 2D block-tiling with vectorization |
| 378 | * |
no test coverage detected