| 618 | #undef INST |
| 619 | |
| 620 | void WarpPerspectiveForwardImpl::exec( |
| 621 | _megdnn_in const TensorNDArray& srcs, _megdnn_tensor_in mat, |
| 622 | _megdnn_tensor_in mat_idx, _megdnn_tensor_out dst, |
| 623 | _megdnn_workspace workspace) { |
| 624 | #if !MGE_BUILD_WITHOUT_NAIVE_EXEC |
| 625 | TensorLayoutArray srcs_layout; |
| 626 | for (auto&& src : srcs) { |
| 627 | srcs_layout.push_back(src.layout); |
| 628 | } |
| 629 | check_exec_allow_nhwc_mat_idx( |
| 630 | srcs_layout, mat.layout, mat_idx.layout, dst.layout, workspace.size); |
| 631 | size_t batch = dst.layout[0]; |
| 632 | |
| 633 | #define KERN_NAIVE_MULTI_SRC(ct, mct) \ |
| 634 | auto kparam = KernParam<ct, mct>::from_tensors( \ |
| 635 | param().format, param().bmode, param().border_val, srcs, mat, mat_idx, \ |
| 636 | dst, workspace); \ |
| 637 | auto run = [kparam, this](size_t index, size_t) { \ |
| 638 | kern_naive_multi_src(kparam, index); \ |
| 639 | }; \ |
| 640 | MEGDNN_DISPATCH_MULTI_THREAD_CPU_KERN_OPR(run, kparam.oh* batch); |
| 641 | |
| 642 | #define DISPATCH_ST_MULTI_SRC(dt, ct, mct, kern) \ |
| 643 | if (srcs.front().layout.dtype.enumv() == DTypeTrait<dt>::enumv) { \ |
| 644 | kern(ct, mct); \ |
| 645 | return; \ |
| 646 | } |
| 647 | |
| 648 | #define DISPATCH_ST_MT_MULTI_SRC(dt, ct, kern) \ |
| 649 | if (srcs.front().layout.dtype.enumv() == DTypeTrait<dt>::enumv) { \ |
| 650 | if (mat.layout.dtype.enumv() == DTypeTrait<dtype::Float32>::enumv) { \ |
| 651 | kern(ct, float); \ |
| 652 | return; \ |
| 653 | } else { \ |
| 654 | kern(ct, ct); \ |
| 655 | return; \ |
| 656 | } \ |
| 657 | } |
| 658 | |
| 659 | megdnn_assert(warp::is_dnn_available( |
| 660 | srcs_layout, mat.layout, dst.layout, param().imode, param().format)); |
| 661 | /*! |
| 662 | * We currently use floating point for all WarpPerspective |
| 663 | * computation, so even if the input ctype is one of the integer |
| 664 | * type, mtype should always be float32. |
| 665 | * |
| 666 | * \warning It's different with \c WarpAffine, with mtype be float16 |
| 667 | * if input type is float16. |
| 668 | */ |
| 669 | |
| 670 | DISPATCH_ST_MULTI_SRC(dtype::Float32, float, float, KERN_NAIVE_MULTI_SRC); |
| 671 | DNN_INC_FLOAT16( |
| 672 | DISPATCH_ST_MT_MULTI_SRC(dtype::Float16, dt_float16, KERN_NAIVE_MULTI_SRC)); |
| 673 | DNN_INC_FLOAT16(DISPATCH_ST_MT_MULTI_SRC( |
| 674 | dtype::BFloat16, dt_bfloat16, KERN_NAIVE_MULTI_SRC)); |
| 675 | megdnn_throw(ssprintf( |
| 676 | "Unsupported input DType in " |
| 677 | "WarpPerspective: %s", |