Skip to content

Commit

Permalink
doc: conv: add note for the dilation computation formula
Browse files Browse the repository at this point in the history
  • Loading branch information
shu1chen committed Jan 9, 2025
1 parent 528edb8 commit 92a8c20
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
6 changes: 6 additions & 0 deletions doc/primitives/convolution.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,12 @@ Here:
- \f$OW = \left\lfloor{\frac{IW - DKW + PW_L + PW_R}{SW}}
\right\rfloor + 1,\f$ where \f$DKW = 1 + (KW - 1) \cdot (DW + 1)\f$.

@note Some applications may use an alternative formula for dimensions computation:
\f$DKH_alt = 1 + (KH - 1) \cdot DH_alt\f$, and
\f$DKW_alt = 1 + (KW - 1) \cdot DW_alt\f$. Those applications can use the alternative
formula with the dilation parameter passed to oneDNN modified as follows:
\f$DH_onednn = DH_alt - 1\f$, and \f$DW_onednn = DW_alt - 1\f$.

#### Deconvolution (Transposed Convolution)

Deconvolutions (also called fractionally strided convolutions or transposed
Expand Down
9 changes: 8 additions & 1 deletion examples/primitives/pooling.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright 2020-2022 Intel Corporation
* Copyright 2020-2025 Intel Corporation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -66,6 +66,13 @@ void pooling_example(dnnl::engine::kind engine_kind) {
DH = 1, // height-wise dilation
DW = 1; // width-wise dilation

// oneDNN uses the following formula for dims computation:
// dst = (src - ((weights - 1) * (dilation_onednn + 1) + 1))/ stride + 1
// Some applications may use an alternative formula:
// dst = (src - ((weights - 1) * dilation_alt + 1))/ stride + 1
// oneDNN can be used in applications that use the alternative formula
// with the dilation parameter modified as follows:
// dilation_onednn = dilation_alt - 1.
const memory::dim OH = (IH - ((KH - 1) * DH + KH) + PH_L + PH_R) / SH + 1;
const memory::dim OW = (IW - ((KW - 1) * DW + KW) + PW_L + PW_R) / SW + 1;

Expand Down

0 comments on commit 92a8c20

Please sign in to comment.