| 412 | } // namespace |
| 413 | |
| 414 | void PoolingForwardImpl::exec( |
| 415 | _megdnn_tensor_in src, _megdnn_tensor_out dst, _megdnn_workspace workspace) { |
| 416 | #if !MGE_BUILD_WITHOUT_NAIVE_EXEC |
| 417 | check_exec(src.layout, dst.layout, workspace.size); |
| 418 | TensorND comp_src = src; |
| 419 | TensorND comp_dst = dst; |
| 420 | |
| 421 | auto wsb = get_workspace_bundle(workspace.raw_ptr, src.layout, dst.layout); |
| 422 | if (src.layout.dtype.enumv() == DTypeEnum::QuantizedS4) { |
| 423 | float scale = src.layout.dtype.param<dtype::QuantizedS4>().scale; |
| 424 | TensorLayout src_layout{comp_src.layout, dtype::QuantizedS8(scale)}; |
| 425 | comp_src = TensorND{wsb.get(0), src_layout}; |
| 426 | TensorLayout dst_layout{comp_dst.layout, dtype::QuantizedS8(scale)}; |
| 427 | comp_dst = TensorND{wsb.get(1), dst_layout}; |
| 428 | int4_to_int8(src, comp_src); |
| 429 | } else if (src.layout.dtype.enumv() == DTypeEnum::Quantized4Asymm) { |
| 430 | float scale = src.layout.dtype.param<dtype::Quantized4Asymm>().scale; |
| 431 | uint8_t zero_point = |
| 432 | src.layout.dtype.param<dtype::Quantized4Asymm>().zero_point; |
| 433 | TensorLayout src_layout{ |
| 434 | comp_src.layout, dtype::Quantized8Asymm(scale, zero_point)}; |
| 435 | comp_src = TensorND{wsb.get(0), src_layout}; |
| 436 | TensorLayout dst_layout{ |
| 437 | comp_dst.layout, dtype::Quantized8Asymm(scale, zero_point)}; |
| 438 | comp_dst = TensorND{wsb.get(1), dst_layout}; |
| 439 | uint4_to_uint8(src, comp_src); |
| 440 | } |
| 441 | |
| 442 | size_t c_pos, spatial_pos, batch_pos = 0; |
| 443 | if (param().format == Param::Format::NCHW || |
| 444 | param().format == Param::Format::NCHW4 || |
| 445 | param().format == Param::Format::NCHW88 || |
| 446 | param().format == Param::Format::NCHW44 || |
| 447 | param().format == Param::Format::NCHW32 || |
| 448 | param().format == Param::Format::NCHW64) { |
| 449 | c_pos = 1; |
| 450 | spatial_pos = 2; |
| 451 | } else if (param().format == Param::Format::NHWC) { |
| 452 | c_pos = 3; |
| 453 | spatial_pos = 1; |
| 454 | } else if (param().format == Param::Format::CHWN4) { |
| 455 | c_pos = 0; |
| 456 | spatial_pos = 1; |
| 457 | batch_pos = 3; |
| 458 | } else { |
| 459 | megdnn_assert(param().format == Param::Format::NHWCD4); |
| 460 | c_pos = 2; |
| 461 | spatial_pos = 1; |
| 462 | } |
| 463 | size_t N = comp_src.layout.shape[batch_pos], C = comp_src.layout.shape[c_pos], |
| 464 | IH = comp_src.layout.shape[spatial_pos + 0], |
| 465 | IW = comp_src.layout.shape[spatial_pos + 1]; |
| 466 | size_t OH = comp_dst.layout.shape[spatial_pos + 0], |
| 467 | OW = comp_dst.layout.shape[spatial_pos + 1]; |
| 468 | switch (param().format) { |
| 469 | case Param::Format::NHWCD4: |
| 470 | C *= 4; |
| 471 | IW = comp_src.layout.shape[spatial_pos + 2]; |
nothing calls this directly
no test coverage detected