Visible to Intel only — GUID: GUID-86EC1564-49FE-4F4F-9622-A65FDFF1E721
Visible to Intel only — GUID: GUID-86EC1564-49FE-4F4F-9622-A65FDFF1E721
Resampling
General
The resampling primitive computes forward or backward resampling operation on 1D, 2D, or 3D spatial data. Resampling performs spatial scaling of original tensor using one of the supported interpolation algorithms:
Nearest Neighbor
Linear (or Bilinear for 2D spatial tensor, Trilinear for 3D spatial tensor).
Resampling operation is defined by the source tensor and scaling factors in each spatial dimension. Upsampling and downsampling are the alternative terms for resampling that are used when all scaling factors are greater (upsampling) or less (downsampling) than one.
The resampling operation is defined by the following formulas. We show formulas only for 2D spatial data which are straightforward to generalize to cases of higher and lower dimensions. Variable names follow the standard Naming Conventions.
Let and be and tensors respectively. Let and define scaling factors in each spatial dimension.
The following formulas show how oneDNN computes resampling for nearest neighbor and bilinear interpolation methods. To further simplify the formulas, we assume the following:
Same assumptions apply for . Definitions of and are provided below with a correspondent algorithm.
Forward
Nearest Neighbor Resampling
where
,
.
Bilinear Resampling
where
,
,
,
,
,
.
Difference Between Forward Training and Forward Inference
There is no difference between the dnnl_forward_training and dnnl_forward_inference propagation kinds.
Backward
The backward propagation computes based on .
Execution Arguments
When executed, the inputs and outputs should be mapped to an execution argument index as specified by the following table.
Primitive input/output |
Execution argument index |
---|---|
DNNL_ARG_SRC |
|
DNNL_ARG_DST |
|
DNNL_ARG_DIFF_SRC |
|
DNNL_ARG_DIFF_DST |
|
DNNL_ARG_ATTR_MULTIPLE_POST_OP(binary_post_op_position) | DNNL_ARG_SRC_1 |
Implementation Details
General Notes
Resampling implementation supports data with arbitrary data tag (nchw, nhwc, nChw16c, etc.) but memory tags for src and dst are expected to be the same. Resampling primitive supports dst and diff_src memory tag dnnl::memory::format_tag::any and can define destination format based on source format.
Resampling primitive descriptor can be created by specifying the source and destination memory descriptors, only the source descriptor and floating point factors, or the source and destination memory descriptors and factors. In case when user does not provide the destination descriptor, the destination dimensions are deduced using the factors: .
Data Types
Resampling primitive supports the following combination of data types for source and destination memory objects:
Propagation |
Source |
Destination |
---|---|---|
forward / backward |
f32, bf16, f16, s32, s8, u8 |
f32, s32, bf16, s8, u8, f16 |
Post-Ops and Attributes
The following attributes are supported:
Implementation Limitations
No primitive specific limitations. Refer to Data Types for limitations related to data types support.
Performance Tips
N/A
Example
This C++ API example demonstrates how to create and execute a Resampling primitive in forward training propagation mode.