(m,k) * (k,n) = (m,n)
| 49 | |
| 50 | // (m,k) * (k,n) = (m,n) |
| 51 | void run_sgemm_test(bool transa, bool transb) { |
| 52 | using Checker = AutoOprChecker<2, 1>; |
| 53 | auto make_graph = [&](const Checker::SymInpArray& inputs) -> Checker::SymOutArray { |
| 54 | auto param = opr::MatrixMul::Param{transa, transb}; |
| 55 | return {opr::MatrixMul::make(inputs[0], inputs[1], param)}; |
| 56 | }; |
| 57 | auto fwd = [&](Checker::NumOutArray& dest, Checker::NumInpArray inp) { |
| 58 | size_t M, N, K; |
| 59 | M = inp[0]->shape().shape[0]; |
| 60 | K = inp[0]->shape().shape[1]; |
| 61 | if (transa) |
| 62 | std::swap(M, K); |
| 63 | N = inp[1]->shape().shape[transb ? 0 : 1]; |
| 64 | |
| 65 | auto z = dest[0].comp_node(inp[0]->comp_node()).resize({M, N}).ptr<float>(); |
| 66 | // brute-force gemm |
| 67 | brute_force_gemm( |
| 68 | M, N, K, transa, transb, inp[0]->ptr<float>(), inp[1]->ptr<float>(), z); |
| 69 | }; |
| 70 | |
| 71 | auto mkshp = [](bool trans, size_t m, size_t k) { |
| 72 | TensorShape rst{m, k}; |
| 73 | if (trans) |
| 74 | std::swap(rst.shape[0], rst.shape[1]); |
| 75 | return rst; |
| 76 | }; |
| 77 | using namespace std::placeholders; |
| 78 | auto mkx = std::bind(mkshp, transa, _1, _2); |
| 79 | auto mky = std::bind(mkshp, transb, _1, _2); |
| 80 | |
| 81 | Checker::RunOptions opt; |
| 82 | opt.numdiff_eps = 1; |
| 83 | Checker(make_graph, fwd) |
| 84 | .run({mkx(4, 6), mky(6, 2)}, opt) |
| 85 | .run({mkx(2, 3), mky(3, 100)}, opt) |
| 86 | .run({mkx(20, 3), mky(3, 20)}, opt) |
| 87 | .run({mkx(10, 0), mky(0, 10)}, opt) |
| 88 | .run({mkx(0, 0), mky(0, 0)}, opt); |
| 89 | } |
| 90 | |
| 91 | #define FWD_BATCH_GEMM(dt_src, dt_dst) \ |
| 92 | [transa, transb](Checker::NumOutArray& dest, Checker::NumInpArray inp) { \ |