| 172 | } |
| 173 | |
| 174 | void WarpPerspectiveForwardImpl::exec( |
| 175 | _megdnn_tensor_in ssrc, _megdnn_tensor_in smat, _megdnn_tensor_in smat_idx, |
| 176 | _megdnn_tensor_out sdst, _megdnn_workspace sworkspace) { |
| 177 | check_exec_allow_nhwc_mat_idx( |
| 178 | ssrc.layout, smat.layout, smat_idx.layout, sdst.layout, sworkspace.size); |
| 179 | |
| 180 | TensorND src = ssrc; |
| 181 | TensorND mat = smat; |
| 182 | TensorND mat_idx = smat_idx; |
| 183 | TensorND dst = sdst; |
| 184 | Param::Format inner_format = param().format; |
| 185 | auto bundle = get_workspace_bundle( |
| 186 | sworkspace.raw_ptr, ssrc.layout, smat.layout, smat_idx.layout, sdst.layout); |
| 187 | auto ctypecvt = CompTypeCvter<dtype::BFloat16, dtype::Float32>( |
| 188 | concrete_handle(this->handle()), &bundle); |
| 189 | if (ssrc.layout.dtype.enumv() == DTypeTrait<dtype::BFloat16>::enumv) { |
| 190 | ctypecvt.src_to_comp_type(ssrc, src) |
| 191 | .src_to_comp_type(smat, mat) |
| 192 | .src_to_comp_type(sdst, dst); |
| 193 | } else if ( |
| 194 | (ssrc.layout.dtype.enumv() == DTypeEnum::QuantizedS4 || |
| 195 | ssrc.layout.dtype.enumv() == DTypeEnum::Quantized4Asymm) && |
| 196 | param().format == Param::Format::NCHW) { |
| 197 | auto handle_ptr = handle(); |
| 198 | get_inner_layout( |
| 199 | ssrc.layout, sdst.layout, src.layout, dst.layout, handle_ptr, |
| 200 | param().format); |
| 201 | src = TensorND{bundle.get(0), src.layout}; |
| 202 | dst = TensorND{bundle.get(1), dst.layout}; |
| 203 | auto relayout_opr = handle_ptr->create_operator<RelayoutFormat>(); |
| 204 | RelayoutFormat::Param trans_param; |
| 205 | trans_param.mode = RelayoutFormat::Param::Mode::NCHW_NCHW64; |
| 206 | relayout_opr->param() = trans_param; |
| 207 | relayout_opr->exec(ssrc, src, {}); |
| 208 | inner_format = Param::Format::NCHW64; |
| 209 | } |
| 210 | |
| 211 | { |
| 212 | auto stream = cuda_stream(this->handle()); |
| 213 | bool is_nhwc = inner_format == param::WarpPerspective::Format::NHWC; |
| 214 | |
| 215 | if (is_nhwc && param().imode != Param::InterpolationMode::LINEAR) { |
| 216 | // use opencv impl only for nhwc and non-linear interp |
| 217 | megdnn_assert( |
| 218 | !mat_idx.raw_ptr(), |
| 219 | "mat_idx is not supported in NHWC case with " |
| 220 | "non-linear interpolation"); |
| 221 | warp_perspective::warp_perspective_cv_exec( |
| 222 | src, mat, dst, param().border_val, |
| 223 | warp_perspective::get_bmode(param().bmode), |
| 224 | warp_perspective::get_imode(param().imode), ctypecvt.workspace(), |
| 225 | stream); |
| 226 | |
| 227 | } else { |
| 228 | megdnn_assert(warp::is_dnn_available( |
| 229 | src.layout, mat.layout, dst.layout, param().imode, inner_format)); |
| 230 | size_t C, IH, IW, OH, OW; |
| 231 | if (is_nhwc) { |
nothing calls this directly
no test coverage detected