| 484 | } |
| 485 | |
| 486 | void RelayoutFormatImpl::exec( |
| 487 | _megdnn_tensor_in src, _megdnn_tensor_out dst, _megdnn_workspace workspace) { |
| 488 | #if !MGE_BUILD_WITHOUT_NAIVE_EXEC |
| 489 | megdnn_assert( |
| 490 | src.layout.dtype.category() == DTypeCategory::FLOAT || |
| 491 | src.layout.dtype.enumv() == DTypeEnum::Int32 || |
| 492 | (src.layout.dtype.enumv() == DTypeEnum::Uint8 && |
| 493 | dst.layout.dtype.enumv() == DTypeEnum::QuantizedS8) || |
| 494 | (src.layout.dtype.enumv() == DTypeEnum::Uint8 && |
| 495 | dst.layout.dtype.enumv() == DTypeEnum::Uint8) || |
| 496 | src.layout.dtype.category() == DTypeCategory::QUANTIZED); |
| 497 | check_exec(src.layout, dst.layout, workspace.size); |
| 498 | HandleImpl* m_handle = static_cast<HandleImpl*>(handle()); |
| 499 | TensorLayout exec_src_layout, exec_dst_layout, exec_workspace_layout; |
| 500 | deduce_exec_layout( |
| 501 | src.layout, dst.layout, exec_workspace_layout, exec_src_layout, |
| 502 | exec_dst_layout); |
| 503 | |
| 504 | // clean dst |
| 505 | MEGDNN_DISPATCH_CPU_KERN( |
| 506 | m_handle, memset(dst.raw_ptr(), 0, dst.layout.span().dist_byte())); |
| 507 | |
| 508 | //! construct exec Tensor |
| 509 | TensorND exec_src_nd{exec_src_layout, src.get_ref_ptr()}; |
| 510 | TensorND exec_dst_nd{exec_dst_layout, dst.get_ref_ptr()}; |
| 511 | |
| 512 | // pre |
| 513 | if (param().mode == Param::Mode::NCHW_NHWCD4I) { |
| 514 | size_t N = src.layout[0]; |
| 515 | size_t IC = src.layout[1]; |
| 516 | size_t IH = src.layout[2]; |
| 517 | size_t IW = src.layout[3]; |
| 518 | //! ic % 4 != 0 |
| 519 | if ((IC & 0x3)) { |
| 520 | switch (src.layout.dtype.enumv()) { |
| 521 | #define cb(name, ctype) \ |
| 522 | case (DTypeEnum::name): { \ |
| 523 | MIDOUT_BEGIN( \ |
| 524 | megdnn_naive_relayout_format, ctype, \ |
| 525 | midout_iv(Param::Mode::NCHW_NHWCD4I)) { \ |
| 526 | MEGDNN_DISPATCH_CPU_KERN( \ |
| 527 | m_handle, padding_src_to_workspace<ctype>( \ |
| 528 | workspace.ptr<ctype>(), \ |
| 529 | src.compatible_ptr<ctype>(), N, IC, IH, IW);); \ |
| 530 | } \ |
| 531 | MIDOUT_END(); \ |
| 532 | break; \ |
| 533 | } |
| 534 | cb(Float32, dt_float32); |
| 535 | DNN_INC_FLOAT16(cb(Float16, dt_float16)); |
| 536 | cb(Quantized8Asymm, dt_uint8); |
| 537 | cb(QuantizedS8, dt_int8); |
| 538 | cb(Uint8, dt_uint8); |
| 539 | #undef cb |
| 540 | default: |
| 541 | megdnn_assert( |
| 542 | 0, "NCHW_NHWCD4I not support dtype %s", |
| 543 | src.layout.dtype.name()); |
nothing calls this directly
no test coverage detected