| Files | Last commit | Last update |
|---|---|---|
| 14 days ago | ||
| 28 days ago | ||
| 2 months ago | ||
| 2 months ago | ||
| 28 days ago | ||
| 1 month ago | ||
| 12 days ago |
Power
English | 简体中文
Product Support Status
| Product | Supported |
|---|---|
| Ascend 950PR&950DT products | √ |
| Atlas A3 products | √ |
| Atlas A2 products | √ |
| Atlas 200I/500 A2 inference products | √ |
| Atlas inference products | √ |
| Atlas training products | × |
Function Description
-
Operator function: performs a linear transformation on each element of the input tensor
xand then performs the power computation. -
Computation formula:
yi=(scale⋅xi+shift)powery_i = \big(\text{scale} \cdot x_i + \text{shift}\big)^{\text{power}}
where power / scale / shift are all scalar attributes. All branch decisions and precomputable constant folding are completed in the tiling phase on the host side, and the kernel side routes to the corresponding DAG based on tilingKey without runtime branches.
-
Equivalent PyTorch expression:
base = scale * x + shift y = torch.pow(base, power) -
Implementation notes:
Category Content Computation template Elementwise ( ElewiseBaseTiling+ElementwiseSch+DAGSch)Computation precision fp16/bf16are cast tofp32in the kernel for computation and then written back to the original dtypeBranch hoisting culType×dtype×schModeare encoded intotilingKeyin three segments, and the DAG has been selected when the kernel template is instantiatedPerformance optimization power ∈ {1,2,3}uses multiplication expansion;power ∉ {0,1,2,3}uses the general path of `exp(power·log( -
Internal operator branches (
culTypeEnumon the host side):culType Trigger Condition Computation ALL_ZEROSscale·power == 0andshift==0andpower>0y = 0BROADCAST_SCALARpower==0, orscale==0andpower≠0y = bcastVal(the host side precomputes one ofpow(shift,power),1.0,NaN, and+inf)LINEARscale·power≠0andpower==1y = x·scale + shiftSQUAREscale·power≠0andpower==2y = (x·scale + shift)^2CUBEscale·power≠0andpower==3y = (x·scale + shift)^3GENERIC_POW_POSscale·power≠0andpower>0andpower∉{1,2,3}General power computation. Outputs 0whenbase==0GENERIC_POW_NEGscale·power≠0andpower<0General power computation. Outputs +infwhenbase==0For
power∈{0,1,2,3}, theIsCloseequality tolerance isatol=1e-8andrtol=1e-5, aligned withmath/is_close.
Operator Parameter Description
| Parameter Name | Input/Output | Description | Usage Instructions | Data Type | Data Format | Dimension (shape) | Non-contiguous Tensor |
|---|---|---|---|---|---|---|---|
| x (Tensor) | Input | Base pre-transform quantity for the power computation, which is x in the formula. | The shape is exactly the same as that of y; broadcasting is not supported. | FLOAT16, BFLOAT16, FLOAT | ND | No limit (including the 0-dimension scalar; a scalar is processed as [1]) | × |
| y (Tensor) | Output | Power computation result, which is y in the formula. | The dtype is the same as that of x, and the shape is the same as that of x. | FLOAT16, BFLOAT16, FLOAT | ND | Same as x | × |
| power (attr, float) | Attribute | Power exponent, which is power in the formula. | Optional, default 1.0. |
FLOAT | - | Scalar | - |
| scale (attr, float) | Attribute | Linear scaling factor of the input, which is scale in the formula. | Optional, default 1.0. |
FLOAT | - | Scalar | - |
| shift (attr, float) | Attribute | Linear shift amount of the input, which is shift in the formula. | Optional, default 0.0. |
FLOAT | - | Scalar | - |
Special Value Conventions
Each element follows the following table (base = scale·x + shift; an integer power means power == floor(power) and is finite):
| Scenario | Output Value | Description |
|---|---|---|
base > 0 |
exp(power · log(base)) |
General main path |
base < 0 and power is an integer |
`(-1)^power · exp(power · log( | base |
base < 0 and power is not an integer |
NaN |
Undefined in the real number domain. The host presets negScalar = NaN, and the multiply-add propagation yields NaN |
base == 0 and power > 0 |
0 |
GENERIC_POW_POS / ALL_ZEROS |
base == 0 and power < 0 |
+inf |
GENERIC_POW_NEG / BROADCAST_SCALAR, IEEE 754 semantics |
power == 0 (including 0^0) |
1 |
By convention, the BROADCAST_SCALAR path is used, and the host presets bcastVal = 1.0 |
Constraint Description
- Data type: The input
xand outputymust be one ofFLOAT16/BFLOAT16/FLOAT, and the two must be exactly the same. The tiling on the host side rejects other dtypes and returnsGRAPH_FAILED. - Same shape: Broadcasting is not supported. The shapes of
xandymust be exactly the same. A 0-dimension scalar is regarded as[1]on the host side. - Platform: Currently, only the kernel binary for the
ascend950platform is generated. When compiling other platforms, this operator is not delivered. - API form: This operator does not provide an aclnn single-operator API. It exists only as a graph operator node and must be integrated through GE IR or a graph compiler. For host direct invocation (kernel-launch) scenarios, directly reuse the kernel source code in this repository instead of the aclnn APIs.
- Attribute default values: By default,
power=1.0,scale=1.0, andshift=0.0, which is equivalent to the identity mapping (y = x). In this case, theLINEARpath is used. - Deterministic computation: This operator uses a deterministic implementation by default. The outputs are the same for each execution with the same inputs and attributes.
Invocation Method
Invoking this operator through the aclnn API is not yet supported. The recommended integration method:
Graph operator method: When building a graph through GE IR / ATC, add Power as a node to the computation graph, and the graph compiler automatically completes tiling, kernel selection, and delivery. The attributes power / scale / shift are injected through node attrs.