| 51 | class BatchMatMulTest : public MNNTestCase { |
| 52 | public: |
| 53 | virtual bool run(int precision) { |
| 54 | int e = 5, h = 4, l = 6; |
| 55 | if (true) { |
| 56 | // Test MatMul |
| 57 | std::unique_ptr<MNN::OpT> op(new MNN::OpT); |
| 58 | op->type = MNN::OpType_MatMul; |
| 59 | op->main.type = MNN::OpParameter_MatMul; |
| 60 | op->main.value = new MNN::MatMulT; |
| 61 | auto matmulParam = op->main.AsMatMul(); |
| 62 | matmulParam->transposeA = false; |
| 63 | matmulParam->transposeB = false; |
| 64 | |
| 65 | auto x0 = _Input({}, NHWC, halide_type_of<float>()); |
| 66 | auto x1 = _Input({}, NHWC, halide_type_of<float>()); |
| 67 | auto y = Variable::create(Expr::create(op.get(), {x0, x1})); |
| 68 | x0->resize({h, l}); |
| 69 | x1->resize({l, e}); |
| 70 | fillFloat(x0->writeMap<float>(), h, l, FP32Converter[precision]); |
| 71 | fillFloat(x1->writeMap<float>(), l, e, FP32Converter[precision]); |
| 72 | |
| 73 | auto res = checkMatMul(y->readMap<float>(), x0->readMap<float>(), x1->readMap<float>(), e, l, h, FP32Converter[precision]); |
| 74 | if (!res) { |
| 75 | FUNC_PRINT(1); |
| 76 | return false; |
| 77 | } |
| 78 | auto tranposeA = _Transpose(x0, {1, 0}); |
| 79 | matmulParam->transposeA = true; |
| 80 | matmulParam->transposeB = false; |
| 81 | y = Variable::create(Expr::create(op.get(), {tranposeA, x1})); |
| 82 | res = checkMatMul(y->readMap<float>(), x0->readMap<float>(), x1->readMap<float>(), e, l, h, FP32Converter[precision]); |
| 83 | if (!res) { |
| 84 | FUNC_PRINT(1); |
| 85 | return false; |
| 86 | } |
| 87 | auto tranposeB = _Transpose(x1, {1, 0}); |
| 88 | matmulParam->transposeA = true; |
| 89 | matmulParam->transposeB = true; |
| 90 | y = Variable::create(Expr::create(op.get(), {tranposeA, tranposeB})); |
| 91 | res = checkMatMul(y->readMap<float>(), x0->readMap<float>(), x1->readMap<float>(), e, l, h, FP32Converter[precision]); |
| 92 | if (!res) { |
| 93 | FUNC_PRINT(1); |
| 94 | return false; |
| 95 | } |
| 96 | matmulParam->transposeA = false; |
| 97 | matmulParam->transposeB = true; |
| 98 | y = Variable::create(Expr::create(op.get(), {x0, tranposeB})); |
| 99 | res = checkMatMul(y->readMap<float>(), x0->readMap<float>(), x1->readMap<float>(), e, l, h, FP32Converter[precision]); |
| 100 | if (!res) { |
| 101 | FUNC_PRINT(1); |
| 102 | return false; |
| 103 | } |
| 104 | } |
| 105 | if (true) { |
| 106 | std::unique_ptr<MNN::OpT> op(new MNN::OpT); |
| 107 | op->type = MNN::OpType_BatchMatMul; |
| 108 | op->main.type = MNN::OpParameter_BatchMatMulParam; |
| 109 | op->main.value = new MNN::BatchMatMulParamT; |
| 110 | auto param = op->main.AsBatchMatMulParam(); |
nothing calls this directly
no test coverage detected