# What's the interpretation of NCHWc?

**URL:** <https://discuss.tvm.apache.org/t/whats-the-interpretation-of-nchwc/1765>\
**Category:** Questions\
**Created:** [February 26, 2019, 3:33pm UTC](https://discuss.tvm.apache.org/t/whats-the-interpretation-of-nchwc/1765 "2019-02-26T15:33:43Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![cbecker](https://discuss.tvm.apache.org/user_avatar/discuss.tvm.apache.org/cbecker/32/403_2.png) [@cbecker](https://discuss.tvm.apache.org/u/cbecker)\
**Post date:** [February 26, 2019, 3:33pm UTC](https://discuss.tvm.apache.org/t/whats-the-interpretation-of-nchwc/1765/1 "2019-02-26T15:33:43Z")

</div>

Hello,

I wanted to know what’s the reason/interpretation behind the NCHWc shape or ordering. I understand what NCHW means for a network processing 2D images, but why are we using NCHWc in TVM? and how is a tensor of shape NCHW converted to NCHWc?

(This comes at trying to implement dilation in x86’s conv2d)

Thanks.

---

<div class="post-metadata">

**Author:** ![eqy](https://discuss.tvm.apache.org/user_avatar/discuss.tvm.apache.org/eqy/32/766_2.png) [@eqy](https://discuss.tvm.apache.org/u/eqy)\
**Post date:** [February 26, 2019, 7:39pm UTC](https://discuss.tvm.apache.org/t/whats-the-interpretation-of-nchwc/1765/2 "2019-02-26T19:39:21Z")

</div>

NCHWc is one example of using data layout to improve spatial locality for a specific hardware target. In this case it is convenient to have channel as the innermost dimension as it is often a power of two and larger than the vector width x86 CPUs (both AVX-2 and AVX-512). Note that this is hardware target dependent, so not every hardware target will use NCHWc, as not every hardware target will benefit from this layout.

---

<div class="post-metadata">

**Author:** ![cbecker](https://discuss.tvm.apache.org/user_avatar/discuss.tvm.apache.org/cbecker/32/403_2.png) [@cbecker](https://discuss.tvm.apache.org/u/cbecker)\
**Post date:** [February 27, 2019, 11:01am UTC](https://discuss.tvm.apache.org/t/whats-the-interpretation-of-nchwc/1765/3 "2019-02-27T11:01:13Z")

</div>

Thanks, that was very helpful, makes sense, particularly for x86 and convolutions.

---

<div class="post-metadata">

**Author:** ![Qiu1981](https://discuss.tvm.apache.org/user_avatar/discuss.tvm.apache.org/qiu1981/32/1847_2.png) [@Qiu1981](https://discuss.tvm.apache.org/u/Qiu1981)\
**Post date:** [July 25, 2019, 3:15am UTC](https://discuss.tvm.apache.org/t/whats-the-interpretation-of-nchwc/1765/4 "2019-07-25T03:15:19Z")

</div>

> [@eqy](#):
>
> In this case it is convenient to have channel as the innermost dimension

Hi eqy, Is NCHWc equivelent with NHWC? if not, would you help give an explaination? Thank you

---

<div class="post-metadata">

**Author:** ![thierry](https://discuss.tvm.apache.org/user_avatar/discuss.tvm.apache.org/thierry/32/116_2.png) [@thierry](https://discuss.tvm.apache.org/u/thierry)\
**Post date:** [July 25, 2019, 5:29am UTC](https://discuss.tvm.apache.org/t/whats-the-interpretation-of-nchwc/1765/5 "2019-07-25T05:29:26Z")

</div>

Not quite - if you consider an example where C=512, and that your CPU has a 64-wide 8bit vector instructions, you can reshape your data layout to perform 64-wide vector operations. As eqy explained, this would result in [N][C][H][W] -\> [N][C/c][H][W][c] where c=64 and C=512. For brevity we express it as NCHWc. This requires a data layout transform (4D array re-shaped to 5D), and to process the data (e.g. matrix multiply) it requires loop splitting and reordering which are faciliated by TVM’s schedule transformations.

---

<div class="post-metadata">

**Author:** ![jiecaoyu](https://discuss.tvm.apache.org/letter_avatar_proxy/v4/letter/j/ecb155/32.png) [@jiecaoyu](https://discuss.tvm.apache.org/u/jiecaoyu)\
**Post date:** [August 14, 2019, 8:47pm UTC](https://discuss.tvm.apache.org/t/whats-the-interpretation-of-nchwc/1765/6 "2019-08-14T20:47:32Z")

</div>

For CPU backend, I wonder what is the benefit of using NCHWc over NHWC? I think one reason is, for Winograd convolution, using NCHWc can help accelerate the input and output transformation. However, I wonder whether there is some other cases that NCHWc can outperform NHWC? Thanks!

---

<div class="post-metadata">

**Author:** ![sergiomatiz](https://discuss.tvm.apache.org/letter_avatar_proxy/v4/letter/s/df788c/32.png) [@sergiomatiz](https://discuss.tvm.apache.org/u/sergiomatiz)\
**Post date:** [April 23, 2020, 8:49pm UTC](https://discuss.tvm.apache.org/t/whats-the-interpretation-of-nchwc/1765/7 "2020-04-23T20:49:53Z")

</div>

Hi everyone, I am also having a look at NCHWc. I noticed that the kernel for this configuration goes from 4D to 6D!, do you guys know why it is 6D instead of 5D? @thierry @eqy

I really appreciate any info you can provide on this issue.
