You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Add Layout field to Conv and Pool nodes and remove OCL specific versions (#3367)
Summary:
For convolutions in glow we use NHWC layout, but it's more efficient to use NCHW on GPUS. To enable this the OCL backend adds some specific OCLConvolution, OCLMaxPool and OCLAvgPool nodes and transforms general Conv and Pool nodes into them by shuffling dimensions and adding TransposeNodes.
This PR adds a field `Layout` to ConvolutionNode, MaxPoolNode and AvgPoolNode which can be either NHWC or NCHW. The OCL backend still transforms these nodes but into the same node type with the layout set to NCHW (we still add transposes). This will allow us to reuse this logic in other backends with the same NCHW preference without needing multiple identical BackendConvolutionNodes (etc).
This **DOES NOT** add NCHW convolution support to any backends, or change any OCL kernels - it just removes OCL specific nodes in favour of more general ones.
This was a consensus decision, but worth thinking about whether or no the code is clearer after this change or not too.
Documentation: deleted the section in docs referencing these nodes.
Pull Request resolved: #3367
Test Plan: ninja test in various modes (debug, release, asan). Ran resnet-runtime on OCL, ran image-classifier on OCL, tracing-compare across interp, cpu and ocl.
Differential Revision: D16631421
Pulled By: nickgg
fbshipit-source-id: 3005a0cfda474db95020f2c1f162aebe4b016a59
Copy file name to clipboardExpand all lines: docs/NewBackendSpecificNode.md
-41Lines changed: 0 additions & 41 deletions
Original file line number
Diff line number
Diff line change
@@ -48,47 +48,6 @@ ReLU is max between zero and the input value. Glow lowers `ReLUNode` to two basi
48
48
49
49
Please refer to the document in [Backend](https://github.com/pytorch/glow/blob/master/docs/Backends.md#backend-specific-nodes-and-instructions) part for source code details on adding a new backend-specific CPUMaxSplatNode on CPU.
50
50
51
-
#### Data Layout Transformation for Conv Operator in OpenCL
52
-
53
-
OpenCL Conv is faster in layout `NCHW`, but the default layout of convolution operator in Glow is `NHWC`. So we transpose the inputs/output and replace the `ConvolutionNode` with a backend-specific `OCLConvolutionNode` that uses `NCHW`. The transposes mostly can get optimized away thanks to the high-level graph optimizations.
54
-
55
-
The OpenCL backend defines `OCLConvolution` in `tools/ClassGen/OpenCL/OpenCLSpecificNodes.h` to support layout `NCHW` input.
56
-
57
-
```cpp
58
-
BB.newNode("OCLConvolution")
59
-
.addInput("Input")
60
-
.addInput("Filter")
61
-
.addInput("Bias")
62
-
.addMember(MemberType::VectorUnsigned, "Kernels")
63
-
.addMember(MemberType::VectorUnsigned, "Strides")
64
-
.addMember(MemberType::VectorUnsigned, "Pads")
65
-
.addMember(MemberType::Unsigned, "Group")
66
-
.addResultFromCtorArg()
67
-
.setDocstring(
68
-
"This is an OpenCL-specific convolution implementation where the "
69
-
"filter, the bias and the input are in the NCHW format");
70
-
```
71
-
72
-
During `transformPostLowering()`, this `convertConvToNCHWConv` node which contains a `NCHWConvNode` node and multiple`Transpose` nodes for `Input`, `Filter` and `Result` replaces the aforementioned pattern.
73
-
74
-
A corresponding backend-specific `OCLConvolution` instruction is also needed, defined in
0 commit comments