SetExpandDimsRule
Description
Sets dimension expansion rules. Dimension Expansion refers to adding one or more shapes based on the original shape. For example, if the original shape [2, 2] has two axes, the final shape after adding two shapes between the two axes is [2,1,1,2]. The shape's 0th and 3rd root axes after dimension expansion are referred as the original axes, and the 1st and 2nd root axes are known as the reshaped axes.
If we use 1 and 0 to describe a dimension expansion rule, 1 indicates that the current axis needs to be reshaped, 0 indicates that the current axis is the original axis, and values from left to right indicate the source of each axis of the current shape. For details, see the following table.
Dimension Expansion Rule |
Shape Before Dimension Expansion |
Shape After Dimension Expansion |
|---|---|---|
0110 |
[2, 2] |
[2, 1, 1, 2] |
100 |
[2, 3] |
[1, 2, 3] |
1000 |
[2, 3] |
The dimension expansion rule does not match the original shape. The rule specifies that there are three original axes, but the original shape has only two axes. As a result, an error is reported. |
The GE framework allows to specify the runtime format of the input and output nodes across the entire network. This capability reduces unnecessary format conversion overhead, thereby yielding more performance gains. If you specify the runtime format, you can use either of the following methods to set the runtime shape:
- Specify the runtime shape.
- Use the framework to deduce the runtime shape. If the number of dimensions of the original shape is smaller than that of the original format, use this API to synchronously set the dimension expansion rule. Then, the framework sets the runtime shape based on the rule.
Prototype
void SetExpandDimsRule(const AscendString &expand_dims_rule)
Parameters
Parameter |
Input/Output |
Description |
|---|---|---|
expand_dims_rule |
Input |
Reshape rule to be set, which is of the AscendString type. Assume that the original shape is [2, 3], and the original format is NCHW. The dimension of the original shape (2) is smaller than the dimension of NCHW (4). In this case, you need to set a dimension expansion rule. For example, if the dimension expansion rule is set to 0110, the final shape after dimension expansion is [2,1,1,3]. |
Returns
None.
Exception Handling
None.
Restrictions
None.