MCPcopy Create free account
hub / github.com/MegEngine/MegEngine / deduce_layout_impl

Method deduce_layout_impl

dnn/src/common/pooling.cpp:7–126  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

5namespace megdnn {
6
7void PoolingBase::deduce_layout_impl(
8 const TensorLayout& src, const Param& param, TensorLayout& dst) {
9 auto pformat = param.format;
10
11 // the overhead of generating error message is about 18x of the other part of this
12 // function so we use a function to wrap the error message and get it only when need.
13 auto get_errmsg = [&](void) -> std::string {
14 std::string errmsg =
15 megdnn_layout_msg(src) + ", " + megdnn_layout_msg(dst) + ", " +
16 "pad_h=" + std::to_string(param.pad_h) + ", " +
17 "pad_w=" + std::to_string(param.pad_w) + ", " +
18 "stride_h=" + std::to_string(param.stride_h) + ", " +
19 "stride_w=" + std::to_string(param.stride_w) + ", " +
20 "window_h=" + std::to_string(param.window_h) + ", " +
21 "window_w=" + std::to_string(param.window_w) + ", " +
22 "is_max=" + std::to_string(param.mode == Mode::MAX) + ", " +
23 "is_nhwc=" + std::to_string(pformat == Param::Format::NHWC) + ", " +
24 "is_nhwcd4=" + std::to_string(pformat == Param::Format::NHWCD4);
25 return errmsg;
26 };
27
28 MEGDNN_MARK_USED_VAR(get_errmsg);
29 if (!src.is_empty()) {
30 megdnn_assert_contiguous(src);
31 } else {
32 megdnn_assert(
33 src.ndim == 4 && (pformat == Param::Format::NCHW ||
34 pformat == Param::Format::NHWC),
35 "Pooling: empty input is only support when input format is NHWC or "
36 "NCHW");
37 }
38 size_t spatial_pos, c_pos, batch_pos = 0;
39 if (pformat == Param::Format::NCHW) {
40 megdnn_assert(src.ndim == 4_z, "%s", get_errmsg().c_str());
41
42 spatial_pos = 2;
43 c_pos = 1;
44 } else if (pformat == Param::Format::NHWC) {
45 megdnn_assert(src.ndim == 4_z, "%s", get_errmsg().c_str());
46
47 spatial_pos = 1;
48 c_pos = 3;
49 } else if (
50 pformat == Param::Format::NCHW4 || pformat == Param::Format::NCHW44 ||
51 pformat == Param::Format::NCHW88 || pformat == Param::Format::NCHW32 ||
52 pformat == Param::Format::NCHW64) {
53 megdnn_assert(src.ndim == 5_z, "%s", get_errmsg().c_str());
54
55 spatial_pos = 2;
56 c_pos = 1;
57 } else if (pformat == Param::Format::CHWN4) {
58 spatial_pos = 1;
59 c_pos = 0;
60 batch_pos = 3;
61 } else {
62 megdnn_assert(
63 pformat == Param::Format::NHWCD4 && src.ndim == 5_z, "%s",
64 get_errmsg().c_str());

Callers

nothing calls this directly

Calls 5

to_stringFunction · 0.85
TensorLayoutClass · 0.85
TensorShapeClass · 0.85
get_errmsgFunction · 0.70
is_emptyMethod · 0.45

Tested by

no test coverage detected