| @@ -15,26 +15,30 @@ | |||
| 15 | 15 | ||
| 16 | ## 功能说明 | 16 | ## 功能说明 |
| 17 | 17 | ||
| 18 | -- 算子功能:对tensor的任意维度进行调换。如输入self是shape为[2, 3, 5]的tensor,dims为(2, 0, 1),则输出是shape为[5, 2, 3]的tensor。 | 18 | +- 算子功能:对tensor的任意维度进行调换。如输入x是shape为[2, 3, 5]的tensor,perm为(2, 0, 1),则输出y是shape为[5, 2, 3]的tensor。 |
| 19 | 19 | ||
| 20 | ## 参数说明 | 20 | ## 参数说明 |
| 21 | 21 | ||
| 22 | | 参数名 | 输入/输出/属性 | 描述 | 数据类型 | 数据格式 | | 22 | | 参数名 | 输入/输出/属性 | 描述 | 数据类型 | 数据格式 | |
| 23 | | :----- | :------------- | :----------------------------------------------------------- | :------- | :------- | | 23 | | :----- | :------------- | :----------------------------------------------------------- | :------- | :------- | |
| 24 | -| x | 输入张量 | 需要进行维度置换的输入张量。 | 见下方 | ND | | 24 | +| x | 输入张量 | 需要进行维度置换的输入张量。 | INT8、UINT8、INT16、UINT16、INT32、UINT32、INT64、UINT64、FLOAT、FLOAT16、BFLOAT16、BOOL、HIFLOAT8、FLOAT8_E5M2、FLOAT8_E4M3FN、FLOAT4_E2M1、FLOAT4_E1M2、HIFLOAT4、HIFLOAT4_SCALE | ND | |
| 25 | -| perm | 输入张量 | 表示x的维度的排列。取值需在[0,self的维度数量-1]范围内。 | INT64、INT32 | - | | 25 | +| perm | 输入张量 | 表示x的维度的排列。元素个数必须等于x的维度数量,取值需在[-x的维度数量,x的维度数量-1]范围内,且各元素不能重复。 | INT32、INT64 | - | |
| 26 | -| y | 输出 | 维度最大不超过8维,shape由dims和原self的shape共同决定,dtype需要与self一致。 | 同x | ND | | 26 | +| y | 输出 | 维度不超过8维,shape由perm和x的shape共同决定(y.shape[i] = x.shape[perm[i]]),dtype需要与x一致。 | 同x | ND | |
| 27 | 27 | ||
| 28 | -- <term>GPU支持的数据类型</term>:数据类型支持DT_BF16, DT_FLOAT16, DT_FLOAT, DT_DOUBLE, DT_INT64, DT_INT32, DT_UINT8, DT_UINT16, DT_UINT32, DT_UINT64, DT_INT8, DT_INT16, DT_COMPLEX32, DT_COMPLEX64, DT_COMPLEX128, DT_QINT8, DT_QUINT8, DT_QINT16, DT_QUINT16, DT_QINT32, DT_BOOL, DT_HIFLOAT8, DT_FLOAT8_E5M2, DT_FLOAT8_E4M3FN。 | 28 | +- <term>Ascend 950PR&950DT系列产品</term>、<term>Atlas A3系列产品</term>、<term>Atlas A2系列产品</term>、<term>Atlas 200I/500 A2推理产品</term>、<term>Atlas推理系列产品</term>、<term>Atlas训练系列产品</term>:数据类型不支持FLOAT4_E2M1、FLOAT4_E1M2、HIFLOAT4、HIFLOAT4_SCALE。 |
| 29 | -- <term>CPU支持的数据类型</term>:数据类型支持同GPU。 | 29 | +- <term>Kirin X90处理器系列产品</term>、<term>Kirin 9030处理器系列产品</term>:数据类型不支持INT16、UINT16、UINT32、INT64、UINT64、BFLOAT16、BOOL、HIFLOAT8、FLOAT8_E5M2、FLOAT8_E4M3FN、FLOAT4_E2M1、FLOAT4_E1M2、HIFLOAT4、HIFLOAT4_SCALE。 |
🟡 Medium Priority 变更行:README.md 第 28-29 行新增了「按产品列出不支持的数据类型」两块说明(README_en.md 第 30-31 行同义)。 受影响契约:README 声称 ①Atlas 950PR&950DT / Atlas A3 / Atlas A2 / Atlas 200I/500 A2 / Atlas 推理 / Atlas 训练 仅「不支持 FLOAT4_E2M1、FLOAT4_E1M2、HIFLOAT4、HIFLOAT4_SCALE」,言下之意 HIFLOAT8、FLOAT8_E5M2、FLOAT8_E4M3FN、BFLOAT16 在这些产品上均受支持;②Kirin X90/9030 的不支持清单。 失败模式:同一 PR 修改的 docs/aclnnPermute.md 第 128 行明确写「Atlas训练系列产品:数据类型不支持 COMPLEX128、BFLOAT16、HIFLOAT8、FLOAT8_E5M2、FLOAT8_E4M3FN」,第 131 行写「Atlas A2系列产品、Atlas A3系列产品:数据类型不支持 HIFLOAT8、FLOAT8_E5M2、FLOAT8_E4M3FN」;docs/aclnnChannelShuffle.md 第 128 行还新增了「Atlas训练系列产品:数据类型不支持 BFLOAT16」。两份文档描述的是同一 README 第 42 行指向的 aclnnPermute 接口,却给出互斥结论。用户按 README 在 A2/A3 上用 HIFLOAT8/FLOAT8_*、或在 Atlas 训练上用 BFLOAT16 调用 aclnnPermute,第一段接口会返回 ACLNN_ERR_PARAM_INVALID(161002),属于可预判的使用失败。此外 README 第 5-14 行「产品支持情况」将 Atlas 200I/500 A2、Atlas 推理列为「√」,而两份 aclnn 文档(id4/id5)写「不支持」,新增的第 28 行又以「仅部分 dtype 不支持」的口吻描述这两个产品,进一步强化了这种不一致。 建议:按算子实际注册的 dtype 统一 README 与 docs/aclnnPermute.md、docs/aclnnChannelShuffle.md 的产品差异说明:在 README 第 28-29 行补上 910 不支持 BFLOAT16、A2/A3 不支持 HIFLOAT8/FLOAT8_E5M2/FLOAT8_E4M3FN 等条目(或反向修正 aclnn 文档),并同步 README_en.md。 ![]() ![]() Incorrect? | |||
| 30 | 30 | ||
| 31 | ## 约束说明 | 31 | ## 约束说明 |
| 32 | 32 | ||
| 33 | -无 | 33 | +- x的维度数量不超过8维。 |
| 34 | +- perm的元素个数必须等于x的维度数量,取值需在[-x的维度数量,x的维度数量-1]范围内,且各元素不能重复。 | ||
| 35 | +- y的shape由perm和x的shape共同决定,dtype必须与x一致。 | ||
| 34 | 36 | ||
| 35 | ## 调用说明 | 37 | ## 调用说明 |
| 36 | 38 | ||
| 37 | | 调用方式 | 样例代码 | 说明 | | 39 | | 调用方式 | 样例代码 | 说明 | |
| 38 | | :-------- | :----------------------------------------------------------- | :----------------------------------------------------------- | | 40 | | :-------- | :----------------------------------------------------------- | :----------------------------------------------------------- | |
| 39 | -| aclnn接口 | [test_aclnn_channel_shuffle](examples/test_aclnn_channel_shuffle.cpp) | 通过[aclnn_channel_shuffle](docs/aclnnChannelShuffle.md)接口方式调用transpose算子。 | | 41 | +| aclnn接口 | [test_aclnn_channel_shuffle](examples/test_aclnn_channel_shuffle.cpp) | 通过[aclnnChannelShuffle](docs/aclnnChannelShuffle.md)接口方式调用Transpose算子。 | |
| 40 | -| aclnn接口 | [test_aclnn_permute](examples/test_aclnn_permute.cpp) | 通过[aclnn_permute](docs/aclnnPermute.md)接口方式调用transpose算子。 | | 42 | +| aclnn接口 | [test_aclnn_permute](examples/test_aclnn_permute.cpp) | 通过[aclnnPermute](docs/aclnnPermute.md)接口方式调用Transpose算子。 | |
| 43 | +| 图模式调用 | [test_geir_permute](examples/test_geir_permute.cpp) | 通过[算子IR](op_graph/permute_proto.h)构图方式调用Transpose算子。 | | ||
| 44 | +| 图模式调用 | [test_geir_transpose](examples/test_geir_transpose.cpp) | 通过[算子IR](op_graph/transpose_proto.h)构图方式调用Transpose算子。 | | ||
| @@ -17,26 +17,30 @@ English | [简体中文](./README.md) | |||
| 17 | 17 | ||
| 18 | ## Function Description | 18 | ## Function Description |
| 19 | 19 | ||
| 20 | -- Operator function: swaps arbitrary dimensions of a tensor. For example, if the input self is a tensor with shape [2, 3, 5] and dims is (2, 0, 1), the output is a tensor with shape [5, 2, 3]. | 20 | +- Operator function: swaps arbitrary dimensions of a tensor. For example, if the input x is a tensor with shape [2, 3, 5] and perm is (2, 0, 1), the output y is a tensor with shape [5, 2, 3]. |
| 21 | 21 | ||
| 22 | ## Parameter Description | 22 | ## Parameter Description |
| 23 | 23 | ||
| 24 | | Parameter Name | Input/Output/Attribute | Description | Data Type | Data Format | | 24 | | Parameter Name | Input/Output/Attribute | Description | Data Type | Data Format | |
| 25 | | :----- | :------------- | :----------------------------------------------------------- | :------- | :------- | | 25 | | :----- | :------------- | :----------------------------------------------------------- | :------- | :------- | |
| 26 | -| x | Input tensor | Input tensor for dimension permutation. | See below | ND | | 26 | +| x | Input tensor | Input tensor for dimension permutation. | INT8, UINT8, INT16, UINT16, INT32, UINT32, INT64, UINT64, FLOAT, FLOAT16, BFLOAT16, BOOL, HIFLOAT8, FLOAT8_E5M2, FLOAT8_E4M3FN, FLOAT4_E2M1, FLOAT4_E1M2, HIFLOAT4, HIFLOAT4_SCALE | ND | |
| 27 | -| perm | Input tensor | Represents the permutation of the dimensions of x. The value must be in the range [0, number of dimensions of self - 1]. | INT64, INT32 | - | | 27 | +| perm | Input tensor | Represents the permutation of the dimensions of x. The number of elements must be equal to the number of dimensions of x. Each value must be in the range [-number of dimensions of x, number of dimensions of x - 1], and the elements must not be repeated. | INT32, INT64 | - | |
| 28 | -| y | Output | Has no more than 8 dimensions. The shape is jointly determined by dims and the shape of the original self, and the dtype must be the same as that of self. | Same as x | ND | | 28 | +| y | Output | Has no more than 8 dimensions. The shape is jointly determined by perm and the shape of x (y.shape[i] = x.shape[perm[i]]), and the dtype must be the same as that of x. | Same as x | ND | |
| 29 | 29 | ||
| 30 | -- <term>Data types supported by the GPU</term>: The supported data types are DT_BF16, DT_FLOAT16, DT_FLOAT, DT_DOUBLE, DT_INT64, DT_INT32, DT_UINT8, DT_UINT16, DT_UINT32, DT_UINT64, DT_INT8, DT_INT16, DT_COMPLEX32, DT_COMPLEX64, DT_COMPLEX128, DT_QINT8, DT_QUINT8, DT_QINT16, DT_QUINT16, DT_QINT32, DT_BOOL, DT_HIFLOAT8, DT_FLOAT8_E5M2, and DT_FLOAT8_E4M3FN. | 30 | +- <term>Ascend 950PR&950DT products</term>, <term>Atlas A3 products</term>, <term>Atlas A2 products</term>, <term>Atlas 200I/500 A2 inference products</term>, <term>Atlas inference products</term>, <term>Atlas training products</term>: FLOAT4_E2M1, FLOAT4_E1M2, HIFLOAT4, and HIFLOAT4_SCALE are not supported. |
| 31 | -- <term>Data types supported by the CPU</term>: The supported data types are the same as those of the GPU. | 31 | +- <term>Kirin X90 processor series products</term>, <term>Kirin 9030 processor series products</term>: INT16, UINT16, UINT32, INT64, UINT64, BFLOAT16, BOOL, HIFLOAT8, FLOAT8_E5M2, FLOAT8_E4M3FN, FLOAT4_E2M1, FLOAT4_E1M2, HIFLOAT4, and HIFLOAT4_SCALE are not supported. |
| 32 | 32 | ||
| 33 | ## Constraint Description | 33 | ## Constraint Description |
| 34 | 34 | ||
| 35 | -None | 35 | +- The number of dimensions of x must not exceed 8. |
| 36 | +- The number of elements in perm must be equal to the number of dimensions of x. Each value must be in the range [-number of dimensions of x, number of dimensions of x - 1], and the elements must not be repeated. | ||
| 37 | +- The shape of y is jointly determined by perm and the shape of x, and the dtype must be the same as that of x. | ||
| 36 | 38 | ||
| 37 | ## Invocation Description | 39 | ## Invocation Description |
| 38 | 40 | ||
| 39 | | Invocation Method | Sample Code | Description | | 41 | | Invocation Method | Sample Code | Description | |
| 40 | | :-------- | :----------------------------------------------------------- | :----------------------------------------------------------- | | 42 | | :-------- | :----------------------------------------------------------- | :----------------------------------------------------------- | |
| 41 | -| aclnn API | [test_aclnn_channel_shuffle](examples/test_aclnn_channel_shuffle.cpp) | Invokes the transpose operator through the [aclnn_channel_shuffle](docs/aclnnChannelShuffle_en.md) API. | | 43 | +| aclnn API | [test_aclnn_channel_shuffle](examples/test_aclnn_channel_shuffle.cpp) | Invokes the Transpose operator through the [aclnnChannelShuffle](docs/aclnnChannelShuffle_en.md) API. | |
| 42 | -| aclnn API | [test_aclnn_permute](examples/test_aclnn_permute.cpp) | Invokes the transpose operator through the [aclnn_permute](docs/aclnnPermute_en.md) API. | | 44 | +| aclnn API | [test_aclnn_permute](examples/test_aclnn_permute.cpp) | Invokes the Transpose operator through the [aclnnPermute](docs/aclnnPermute_en.md) API. | |
| 45 | +| Graph mode | [test_geir_permute](examples/test_geir_permute.cpp) | Invokes the Transpose operator by building a graph with the [operator IR](op_graph/permute_proto.h). | | ||
| 46 | +| Graph mode | [test_geir_transpose](examples/test_geir_transpose.cpp) | Invokes the Transpose operator by building a graph with the [operator IR](op_graph/transpose_proto.h). | | ||
| @@ -23,7 +23,7 @@ | |||
| 23 | 23 | ||
| 24 | ## 功能说明 | 24 | ## 功能说明 |
| 25 | 25 | ||
| 26 | -将(*, C, H, W)张量的channels分成g个组,然后将每个通道组中的通道进行随机重排,最后将所有通道合并输出,同时保持最终输出张量的shape和输入张量保持一致。 | 26 | +将(N, C, *)张量按通道维(固定为第1维,下标从0开始,长度为C)分成groups个组,然后将每个通道组中的通道进行重排,最后将所有通道合并输出,同时保持输出张量的shape与输入张量一致。 |
| 27 | 27 | ||
| 28 | ## 函数原型 | 28 | ## 函数原型 |
| 29 | 29 | ||
| @@ -77,7 +77,7 @@ aclnnStatus aclnnChannelShuffle( | |||
| 77 | <td>输入</td> | 77 | <td>输入</td> |
| 78 | <td>输入Tensor。</td> | 78 | <td>输入Tensor。</td> |
| 79 | <td>数据维度大于2且不支持7维以上。</td> | 79 | <td>数据维度大于2且不支持7维以上。</td> |
| 80 | - <td>FLOAT16、FLOAT、DOUBLE、UINT8、INT8、INT16、INT32、INT64、COMPLEX64、COMPLEX128、BOOL</td> | 80 | + <td>FLOAT16、FLOAT、DOUBLE、INT8、UINT8、INT16、INT32、INT64、BOOL、COMPLEX64、COMPLEX128、BFLOAT16</td> |
| 81 | <td>ND</td> | 81 | <td>ND</td> |
| 82 | <td>3-7</td> | 82 | <td>3-7</td> |
| 83 | <td>√</td> | 83 | <td>√</td> |
| @@ -85,8 +85,8 @@ aclnnStatus aclnnChannelShuffle( | |||
| 85 | <tr> | 85 | <tr> |
| 86 | <td>groups(int64_t)</td> | 86 | <td>groups(int64_t)</td> |
| 87 | <td>输入</td> | 87 | <td>输入</td> |
| 88 | - <td>表示将输入self的channels分成多少组。</td> | 88 | + <td>表示将输入self的通道维(第1维,下标从0开始)分成多少组。</td> |
| 89 | - <td>值需要大于0且要能被self的channels整除。</td> | 89 | + <td>值需要大于0且能被self的通道维长度C整除。</td> |
| 90 | <td>INT64</td> | 90 | <td>INT64</td> |
| 91 | <td>-</td> | 91 | <td>-</td> |
| 92 | <td>-</td> | 92 | <td>-</td> |
| @@ -97,7 +97,7 @@ aclnnStatus aclnnChannelShuffle( | |||
| 97 | <td>输出</td> | 97 | <td>输出</td> |
| 98 | <td>输出Tensor。</td> | 98 | <td>输出Tensor。</td> |
| 99 | <td>数据维度大于2且不支持7维以上。</td> | 99 | <td>数据维度大于2且不支持7维以上。</td> |
| 100 | - <td>FLOAT16、FLOAT、DOUBLE、UINT8、INT8、INT16、INT32、INT64、COMPLEX64、COMPLEX128、BOOL、BFLOAT16。</td> | 100 | + <td>FLOAT16、FLOAT、DOUBLE、INT8、UINT8、INT16、INT32、INT64、BOOL、COMPLEX64、COMPLEX128、BFLOAT16</td> |
| 101 | <td>ND</td> | 101 | <td>ND</td> |
| 102 | <td>3-7</td> | 102 | <td>3-7</td> |
| 103 | <td>√</td> | 103 | <td>√</td> |
| @@ -124,6 +124,10 @@ aclnnStatus aclnnChannelShuffle( | |||
| 124 | </tr> | 124 | </tr> |
| 125 | </tbody></table> | 125 | </tbody></table> |
| 126 | 126 | ||
| 127 | + <!-- npu="910" id7 --> | ||
| 128 | + - <term>Atlas训练系列产品</term>:数据类型不支持BFLOAT16。 | ||
| 129 | + <!-- end id7 --> | ||
| 130 | + | ||
| 127 | - **返回值:** | 131 | - **返回值:** |
| 128 | 132 | ||
| 129 | aclnnStatus:返回状态码,具体参见[aclnn返回码](../../../docs/zh/context/aclnn_return_code.md)。 | 133 | aclnnStatus:返回状态码,具体参见[aclnn返回码](../../../docs/zh/context/aclnn_return_code.md)。 |
| @@ -158,7 +162,7 @@ aclnnStatus aclnnChannelShuffle( | |||
| 158 | <td>参数self、out的维度数大于7或小于3。</td> | 162 | <td>参数self、out的维度数大于7或小于3。</td> |
| 159 | </tr> | 163 | </tr> |
| 160 | <tr> | 164 | <tr> |
| 161 | - <td>参数groups值小于等于0或不能被self的channels整除。</td> | 165 | + <td>参数groups值小于等于0或不能被self的通道维长度C整除。</td> |
| 162 | </tr> | 166 | </tr> |
| 163 | </tbody> | 167 | </tbody> |
| 164 | </table> | 168 | </table> |
| @@ -25,7 +25,7 @@ | |||
| 25 | 25 | ||
| 26 | ## Function | 26 | ## Function |
| 27 | 27 | ||
| 28 | -Divides the channels of a (*, C, H, W) tensor into g groups, randomly shuffles the channels within each group, and then merges all channels for output, while keeping the shape of the final output tensor consistent with the input tensor. | 28 | +Divides the channels (the fixed dimension 1, 0-based, with length C) of an (N, C, *) tensor into groups groups, reorders the channels within each group, and then merges all channels for output, while keeping the shape of the output tensor consistent with that of the input tensor. |
| 29 | 29 | ||
| 30 | ## Function Prototype | 30 | ## Function Prototype |
| 31 | 31 | ||
| @@ -79,7 +79,7 @@ aclnnStatus aclnnChannelShuffle( | |||
| 79 | <td class="tg-0pky">Input</td> | 79 | <td class="tg-0pky">Input</td> |
| 80 | <td class="tg-0pky">Input tensor.</td> | 80 | <td class="tg-0pky">Input tensor.</td> |
| 81 | <td class="tg-0pky">The data dimension is greater than 2, and more than 7 dimensions are not supported.</td> | 81 | <td class="tg-0pky">The data dimension is greater than 2, and more than 7 dimensions are not supported.</td> |
| 82 | - <td class="tg-0pky">FLOAT16, FLOAT, DOUBLE, UINT8, INT8, INT16, INT32, INT64, COMPLEX64, COMPLEX128, BOOL</td> | 82 | + <td class="tg-0pky">FLOAT16, FLOAT, DOUBLE, INT8, UINT8, INT16, INT32, INT64, BOOL, COMPLEX64, COMPLEX128, BFLOAT16</td> |
| 83 | <td class="tg-0pky">ND</td> | 83 | <td class="tg-0pky">ND</td> |
| 84 | <td class="tg-0pky">3-7</td> | 84 | <td class="tg-0pky">3-7</td> |
| 85 | <td class="tg-0pky">√</td> | 85 | <td class="tg-0pky">√</td> |
| @@ -87,8 +87,8 @@ aclnnStatus aclnnChannelShuffle( | |||
| 87 | <tr> | 87 | <tr> |
| 88 | <td class="tg-0lax">groups (int64_t)</td> | 88 | <td class="tg-0lax">groups (int64_t)</td> |
| 89 | <td class="tg-0lax">Input</td> | 89 | <td class="tg-0lax">Input</td> |
| 90 | - <td class="tg-0lax">Specifies the number of groups to divide the channels of input self into.</td> | 90 | + <td class="tg-0lax">Specifies the number of groups into which the channel dimension (dimension 1, 0-based) of input self is divided.</td> |
| 91 | - <td class="tg-0lax">The value must be greater than 0 and divisible by the channels of self.</td> | 91 | + <td class="tg-0lax">The value must be greater than 0 and divisible by the channel dimension length C of self.</td> |
| 92 | <td class="tg-0lax">INT64</td> | 92 | <td class="tg-0lax">INT64</td> |
| 93 | <td class="tg-0lax">-</td> | 93 | <td class="tg-0lax">-</td> |
| 94 | <td class="tg-0lax">-</td> | 94 | <td class="tg-0lax">-</td> |
| @@ -99,7 +99,7 @@ aclnnStatus aclnnChannelShuffle( | |||
| 99 | <td class="tg-0pky">Output</td> | 99 | <td class="tg-0pky">Output</td> |
| 100 | <td class="tg-0pky">Output tensor.</td> | 100 | <td class="tg-0pky">Output tensor.</td> |
| 101 | <td class="tg-0pky">The dimensions must be greater than 2, and 7 or more dimensions are not supported.</td> | 101 | <td class="tg-0pky">The dimensions must be greater than 2, and 7 or more dimensions are not supported.</td> |
| 102 | - <td class="tg-0pky">FLOAT16, FLOAT, DOUBLE, UINT8, INT8, INT16, INT32, INT64, COMPLEX64, COMPLEX128, BOOL, BFLOAT16.</td> | 102 | + <td class="tg-0pky">FLOAT16, FLOAT, DOUBLE, INT8, UINT8, INT16, INT32, INT64, BOOL, COMPLEX64, COMPLEX128, BFLOAT16</td> |
| 103 | <td class="tg-0pky">ND</td> | 103 | <td class="tg-0pky">ND</td> |
| 104 | <td class="tg-0pky">3-7</td> | 104 | <td class="tg-0pky">3-7</td> |
| 105 | <td class="tg-0pky">√</td> | 105 | <td class="tg-0pky">√</td> |
| @@ -126,6 +126,10 @@ aclnnStatus aclnnChannelShuffle( | |||
| 126 | </tr> | 126 | </tr> |
| 127 | </tbody></table> | 127 | </tbody></table> |
| 128 | 128 | ||
| 129 | + <!-- npu="910" id7 --> | ||
| 130 | + - <term>Atlas training products</term>: BFLOAT16 is not supported. | ||
| 131 | + <!-- end id7 --> | ||
| 132 | + | ||
| 129 | - **Return value** | 133 | - **Return value** |
| 130 | 134 | ||
| 131 | aclnnStatus: return status code. For details, see [aclnn Return Codes](../../../docs/en/context/aclnn_return_code.md). | 135 | aclnnStatus: return status code. For details, see [aclnn Return Codes](../../../docs/en/context/aclnn_return_code.md). |
| @@ -163,7 +167,7 @@ aclnnStatus aclnnChannelShuffle( | |||
| 163 | <td class="tg-0lax">The number of dimensions of parameters self and out is greater than 7 or less than 3.</td> | 167 | <td class="tg-0lax">The number of dimensions of parameters self and out is greater than 7 or less than 3.</td> |
| 164 | </tr> | 168 | </tr> |
| 165 | <tr> | 169 | <tr> |
| 166 | - <td class="tg-0lax">The value of parameter groups is less than or equal to 0 or cannot be divided evenly by the channels of self.</td> | 170 | + <td class="tg-0lax">The value of parameter groups is less than or equal to 0 or cannot be divided evenly by the channel dimension length C of self.</td> |
| 167 | </tr> | 171 | </tr> |
| 168 | </tbody> | 172 | </tbody> |
| 169 | </table> | 173 | </table> |
| @@ -23,11 +23,11 @@ | |||
| 23 | 23 | ||
| 24 | ## 功能说明 | 24 | ## 功能说明 |
| 25 | 25 | ||
| 26 | -对 tensor 的任意维度进行调换。如输入 self 是 shape 为 [2, 3, 5] 的 tensor,dims 为 (2, 0, 1),则输出是 shape 为 [5, 2, 3] 的 tensor。 | 26 | +对tensor的任意维度进行调换。如输入self是shape为[2, 3, 5]的tensor,dims为(2, 0, 1),则输出是shape为[5, 2, 3]的tensor。 |
| 27 | 27 | ||
| 28 | ## 函数原型 | 28 | ## 函数原型 |
| 29 | 29 | ||
| 30 | -每个算子分为[两段式接口](../../../docs/zh/context/two_phase_api.md),必须先调用“aclnnPermuteGetWorkspaceSize”接口获取计算所需 workspace 大小以及包含了算子计算流程的执行器,再调用“aclnnPermute”接口执行计算。 | 30 | +每个算子分为[两段式接口](../../../docs/zh/context/two_phase_api.md),必须先调用“aclnnPermuteGetWorkspaceSize”接口获取计算所需workspace大小以及包含了算子计算流程的执行器,再调用“aclnnPermute”接口执行计算。 |
| 31 | 31 | ||
| 32 | ```cpp | 32 | ```cpp |
| 33 | aclnnStatus aclnnPermuteGetWorkspaceSize( | 33 | aclnnStatus aclnnPermuteGetWorkspaceSize( |
| @@ -68,15 +68,15 @@ aclnnStatus aclnnPermute( | |||
| 68 | <th>使用说明</th> | 68 | <th>使用说明</th> |
| 69 | <th>数据类型</th> | 69 | <th>数据类型</th> |
| 70 | <th>数据格式</th> | 70 | <th>数据格式</th> |
| 71 | - <th>维度(shape)</th> | 71 | + <th>维度(shape)</th> |
| 72 | - <th>非连续 Tensor</th> | 72 | + <th>非连续Tensor</th> |
| 73 | </tr></thead> | 73 | </tr></thead> |
| 74 | <tbody> | 74 | <tbody> |
| 75 | <tr> | 75 | <tr> |
| 76 | <td>self(aclTensor*)</td> | 76 | <td>self(aclTensor*)</td> |
| 77 | <td>输入</td> | 77 | <td>输入</td> |
| 78 | - <td>输入的 tensor</td> | 78 | + <td>输入的tensor</td> |
| 79 | - <td>-</td> | 79 | + <td>支持空Tensor,当self的shape中存在0时,输出为空Tensor。</td> |
| 80 | <td>FLOAT、FLOAT16、DOUBLE、UINT64、INT64、UINT32、INT32、UINT16、INT16、UINT8、INT8、BOOL、COMPLEX64、COMPLEX128、BFLOAT16、HIFLOAT8、FLOAT8_E5M2、FLOAT8_E4M3FN</td> | 80 | <td>FLOAT、FLOAT16、DOUBLE、UINT64、INT64、UINT32、INT32、UINT16、INT16、UINT8、INT8、BOOL、COMPLEX64、COMPLEX128、BFLOAT16、HIFLOAT8、FLOAT8_E5M2、FLOAT8_E4M3FN</td> |
| 81 | <td>ND</td> | 81 | <td>ND</td> |
| 82 | <td>≤8</td> | 82 | <td>≤8</td> |
| @@ -85,8 +85,8 @@ aclnnStatus aclnnPermute( | |||
| 85 | <tr> | 85 | <tr> |
| 86 | <td>dims(aclIntArray*)</td> | 86 | <td>dims(aclIntArray*)</td> |
| 87 | <td>输入</td> | 87 | <td>输入</td> |
| 88 | - <td>整型数组,代表原来 tensor 的维度,指定新的轴顺序。</td> | 88 | + <td>整型数组,代表原来tensor的维度,指定新的轴顺序。</td> |
| 89 | - <td>取值需在 [-self 的维度数量,self 的维度数量 - 1] 范围内。</td> | 89 | + <td>元素个数必须等于self的维度数量,取值需在[-self的维度数量,self的维度数量-1]范围内,且各元素不能重复;负数表示从尾部计数。</td> |
| 90 | <td>INT64</td> | 90 | <td>INT64</td> |
| 91 | <td>-</td> | 91 | <td>-</td> |
| 92 | <td>-</td> | 92 | <td>-</td> |
| @@ -95,9 +95,9 @@ aclnnStatus aclnnPermute( | |||
| 95 | <tr> | 95 | <tr> |
| 96 | <td>out(aclTensor*)</td> | 96 | <td>out(aclTensor*)</td> |
| 97 | <td>输出</td> | 97 | <td>输出</td> |
| 98 | - <td>输出的 tensor</td> | 98 | + <td>输出的tensor</td> |
| 99 | - <td>shape 由 dims 和原 self 的 shape 共同决定,dtype 需要与 self 一致。</td> | 99 | + <td>shape由dims和self的shape共同决定,满足out.shape[i] = self.shape[dims[i]],dtype需要与self一致。</td> |
| 100 | - <td>FLOAT、FLOAT16、DOUBLE、UINT64、INT64、UINT32、INT32、UINT16、INT16、UINT8、INT8、BOOL、COMPLEX64、COMPLEX128、BFLOAT16、HIFLOAT8、FLOAT8_E5M2、FLOAT8_E4M3FN。</td> | 100 | + <td>FLOAT、FLOAT16、DOUBLE、UINT64、INT64、UINT32、INT32、UINT16、INT16、UINT8、INT8、BOOL、COMPLEX64、COMPLEX128、BFLOAT16、HIFLOAT8、FLOAT8_E5M2、FLOAT8_E4M3FN</td> |
| 101 | <td>ND</td> | 101 | <td>ND</td> |
| 102 | <td>≤8</td> | 102 | <td>≤8</td> |
| 103 | <td>√</td> | 103 | <td>√</td> |
| @@ -105,7 +105,7 @@ aclnnStatus aclnnPermute( | |||
| 105 | <tr> | 105 | <tr> |
| 106 | <td>workspaceSize(uint64_t*)</td> | 106 | <td>workspaceSize(uint64_t*)</td> |
| 107 | <td>输出</td> | 107 | <td>输出</td> |
| 108 | - <td>返回需要在 Device 侧申请的 workspace 大小。</td> | 108 | + <td>返回需要在Device侧申请的workspace大小。</td> |
| 109 | <td>-</td> | 109 | <td>-</td> |
| 110 | <td>-</td> | 110 | <td>-</td> |
| 111 | <td>-</td> | 111 | <td>-</td> |
| @@ -115,7 +115,7 @@ aclnnStatus aclnnPermute( | |||
| 115 | <tr> | 115 | <tr> |
| 116 | <td>executor(aclOpExecutor**)</td> | 116 | <td>executor(aclOpExecutor**)</td> |
| 117 | <td>输出</td> | 117 | <td>输出</td> |
| 118 | - <td>返回 op 执行器,包含了算子计算流程。</td> | 118 | + <td>返回op执行器,包含了算子计算流程。</td> |
| 119 | <td>-</td> | 119 | <td>-</td> |
| 120 | <td>-</td> | 120 | <td>-</td> |
| 121 | <td>-</td> | 121 | <td>-</td> |
| @@ -125,15 +125,15 @@ aclnnStatus aclnnPermute( | |||
| 125 | </tbody></table> | 125 | </tbody></table> |
| 126 | 126 | ||
| 127 | <!-- npu="910" id7 --> | 127 | <!-- npu="910" id7 --> |
| 128 | - - <term>Atlas训练系列产品</term>:数据类型不支持 COMPLEX128、BFLOAT16、HIFLOAT8、FLOAT8_E5M2、FLOAT8_E4M3FN。 | 128 | + - <term>Atlas训练系列产品</term>:数据类型不支持COMPLEX128、BFLOAT16、HIFLOAT8、FLOAT8_E5M2、FLOAT8_E4M3FN。 |
| 129 | <!-- end id7 --> | 129 | <!-- end id7 --> |
| 130 | <!-- npu="A3,910b" id8 --> | 130 | <!-- npu="A3,910b" id8 --> |
| 131 | - - <term>Atlas A2系列产品</term>、<term>Atlas A3系列产品</term>:数据类型不支持 HIFLOAT8、FLOAT8_E5M2、FLOAT8_E4M3FN。 | 131 | + - <term>Atlas A2系列产品</term>、<term>Atlas A3系列产品</term>:数据类型不支持HIFLOAT8、FLOAT8_E5M2、FLOAT8_E4M3FN。 |
| 132 | <!-- end id8 --> | 132 | <!-- end id8 --> |
| 133 | 133 | ||
| 134 | - **返回值** | 134 | - **返回值** |
| 135 | 135 | ||
| 136 | - aclnnStatus:返回状态码,具体参见[aclnn 返回码](../../../docs/zh/context/aclnn_return_code.md)。 | 136 | + aclnnStatus:返回状态码,具体参见[aclnn返回码](../../../docs/zh/context/aclnn_return_code.md)。 |
| 137 | 137 | ||
| 138 | 第一段接口完成入参校验,出现以下场景时报错: | 138 | 第一段接口完成入参校验,出现以下场景时报错: |
| 139 | <table style="table-layout: fixed; width: 1150px"><colgroup> | 139 | <table style="table-layout: fixed; width: 1150px"><colgroup> |
| @@ -151,21 +151,30 @@ aclnnStatus aclnnPermute( | |||
| 151 | <tr> | 151 | <tr> |
| 152 | <td>ACLNN_ERR_PARAM_NULLPTR</td> | 152 | <td>ACLNN_ERR_PARAM_NULLPTR</td> |
| 153 | <td>161001</td> | 153 | <td>161001</td> |
| 154 | - <td>传入的 self、dims 或 out 是空指针。</td> | 154 | + <td>传入的self、dims或out是空指针。</td> |
| 155 | </tr> | 155 | </tr> |
| 156 | <tr> | 156 | <tr> |
| 157 | - <td rowspan="4">ACLNN_ERR_PARAM_INVALID</td> | 157 | + <td rowspan="7">ACLNN_ERR_PARAM_INVALID</td> |
| 158 | - <td rowspan="4">161002</td> | 158 | + <td rowspan="7">161002</td> |
| 159 | - <td>self 和 out 的数据类型不在支持的范围之内。</td> | 159 | + <td>self和out的数据类型不在支持的范围之内。</td> |
| 160 | </tr> | 160 | </tr> |
| 161 | <tr> | 161 | <tr> |
| 162 | - <td>self 和 out 的数据类型不一致。</td> | 162 | + <td>self和out的数据类型不一致。</td> |
| 163 | </tr> | 163 | </tr> |
| 164 | <tr> | 164 | <tr> |
| 165 | - <td>输入 self 的维度超过 8 维。</td> | 165 | + <td>输入self的维度超过8维。</td> |
| 166 | </tr> | 166 | </tr> |
| 167 | <tr> | 167 | <tr> |
| 168 | - <td>dims 的取值不在 [-self 的维度数量,self 的维度数量 - 1] 的范围内。</td> | 168 | + <td>dims的取值不在[-self的维度数量,self的维度数量-1]的范围内。</td> |
| 169 | + </tr> | ||
| 170 | + <tr> | ||
| 171 | + <td>dims的元素个数与self的维度数量不一致。</td> | ||
| 172 | + </tr> | ||
| 173 | + <tr> | ||
| 174 | + <td>dims中存在重复元素。</td> | ||
| 175 | + </tr> | ||
| 176 | + <tr> | ||
| 177 | + <td>out的shape与按dims重排self后的shape不一致。</td> | ||
| 169 | </tr> | 178 | </tr> |
| 170 | </tbody> | 179 | </tbody> |
| 171 | </table> | 180 | </table> |
| @@ -189,34 +198,35 @@ aclnnStatus aclnnPermute( | |||
| 189 | <tr> | 198 | <tr> |
| 190 | <td>workspace</td> | 199 | <td>workspace</td> |
| 191 | <td>输入</td> | 200 | <td>输入</td> |
| 192 | - <td>在 Device 侧申请的 workspace 内存地址。</td> | 201 | + <td>在Device侧申请的workspace内存地址。</td> |
| 193 | </tr> | 202 | </tr> |
| 194 | <tr> | 203 | <tr> |
| 195 | - <td>workspace_size</td> | 204 | + <td>workspaceSize</td> |
| 196 | <td>输入</td> | 205 | <td>输入</td> |
| 197 | - <td>在 Device 侧申请的 workspace 大小,由第一段接口 aclnnPermuteGetWorkspaceSize 获取。</td> | 206 | + <td>在Device侧申请的workspace大小,由第一段接口aclnnPermuteGetWorkspaceSize获取。</td> |
| 198 | </tr> | 207 | </tr> |
| 199 | <tr> | 208 | <tr> |
| 200 | <td>executor</td> | 209 | <td>executor</td> |
| 201 | <td>输入</td> | 210 | <td>输入</td> |
| 202 | - <td>op 执行器,包含了算子计算流程。</td> | 211 | + <td>op执行器,包含了算子计算流程。</td> |
| 203 | </tr> | 212 | </tr> |
| 204 | <tr> | 213 | <tr> |
| 205 | <td>stream</td> | 214 | <td>stream</td> |
| 206 | <td>输入</td> | 215 | <td>输入</td> |
| 207 | - <td>指定执行任务的 Stream。</td> | 216 | + <td>指定执行任务的Stream。</td> |
| 208 | </tr> | 217 | </tr> |
| 209 | </tbody> | 218 | </tbody> |
| 210 | </table> | 219 | </table> |
| 211 | 220 | ||
| 212 | - **返回值** | 221 | - **返回值** |
| 213 | 222 | ||
| 214 | - aclnnStatus:返回状态码,具体参见[aclnn 返回码](../../../docs/zh/context/aclnn_return_code.md)。 | 223 | + aclnnStatus:返回状态码,具体参见[aclnn返回码](../../../docs/zh/context/aclnn_return_code.md)。 |
| 215 | 224 | ||
| 216 | ## 约束说明 | 225 | ## 约束说明 |
| 217 | 226 | ||
| 227 | +- 输入self的维度数量不超过8维。 | ||
| 218 | - 确定性计算: | 228 | - 确定性计算: |
| 219 | - - aclnnPermute 默认确定性实现。 | 229 | + - aclnnPermute默认确定性实现。 |
| 220 | 230 | ||
| 221 | ## 调用示例 | 231 | ## 调用示例 |
| 222 | 232 | ||
| @@ -229,131 +239,135 @@ aclnnStatus aclnnPermute( | |||
| 229 | #include "aclnnop/aclnn_permute.h" | 239 | #include "aclnnop/aclnn_permute.h" |
| 230 | 240 | ||
| 231 | #define CHECK_RET(cond, return_expr) \ | 241 | #define CHECK_RET(cond, return_expr) \ |
| 232 | - do { \ | 242 | + do { \ |
| 233 | - if (!(cond)) { \ | 243 | + if (!(cond)) { \ |
| 234 | - return_expr; \ | 244 | + return_expr; \ |
| 235 | - } \ | 245 | + } \ |
| 236 | - } while (0) | 246 | + } while (0) |
| 237 | 247 | ||
| 238 | -#define LOG_PRINT(message, ...) \ | 248 | +#define LOG_PRINT(message, ...) \ |
| 239 | - do { \ | 249 | + do { \ |
| 240 | - printf(message, ##__VA_ARGS__); \ | 250 | + printf(message, ##__VA_ARGS__); \ |
| 241 | - } while (0) | 251 | + } while (0) |
| 242 | 252 | ||
| 243 | -int64_t GetShapeSize(const std::vector<int64_t>& shape) { | 253 | +int64_t GetShapeSize(const std::vector<int64_t>& shape) |
| 244 | - int64_t shapeSize = 1; | 254 | +{ |
| 245 | - for (auto i : shape) { | 255 | + int64_t shapeSize = 1; |
| 246 | - shapeSize *= i; | 256 | + for (auto i : shape) { |
| 247 | - } | 257 | + shapeSize *= i; |
| 248 | - return shapeSize; | 258 | + } |
| 259 | + return shapeSize; | ||
| 249 | } | 260 | } |
| 250 | 261 | ||
| 251 | -int Init(int32_t deviceId, aclrtStream* stream) { | 262 | +int Init(int32_t deviceId, aclrtStream* stream) |
| 252 | - // 固定写法,资源初始化 | 263 | +{ |
| 253 | - auto ret = aclInit(nullptr); | 264 | + // 固定写法,初始化 |
| 254 | - CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("aclInit failed. ERROR: %d\n", ret); return ret); | 265 | + auto ret = aclInit(nullptr); |
| 255 | - ret = aclrtSetDevice(deviceId); | 266 | + CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("aclInit failed. ERROR: %d\n", ret); return ret); |
| 256 | - CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("aclrtSetDevice failed. ERROR: %d\n", ret); return ret); | 267 | + ret = aclrtSetDevice(deviceId); |
| 257 | - ret = aclrtCreateStream(stream); | 268 | + CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("aclrtSetDevice failed. ERROR: %d\n", ret); return ret); |
| 258 | - CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("aclrtCreateStream failed. ERROR: %d\n", ret); return ret); | 269 | + ret = aclrtCreateStream(stream); |
| 259 | - return 0; | 270 | + CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("aclrtCreateStream failed. ERROR: %d\n", ret); return ret); |
| 271 | + return 0; | ||
| 260 | } | 272 | } |
| 261 | 273 | ||
| 262 | template <typename T> | 274 | template <typename T> |
| 263 | int CreateAclTensor(const std::vector<T>& hostData, const std::vector<int64_t>& shape, void** deviceAddr, | 275 | int CreateAclTensor(const std::vector<T>& hostData, const std::vector<int64_t>& shape, void** deviceAddr, |
| 264 | - aclDataType dataType, aclTensor** tensor) { | 276 | + aclDataType dataType, aclTensor** tensor) |
| 265 | - auto size = GetShapeSize(shape) * sizeof(T); | 277 | +{ |
| 266 | - // 调用aclrtMalloc申请device侧内存 | 278 | + auto size = GetShapeSize(shape) * sizeof(T); |
| 267 | - auto ret = aclrtMalloc(deviceAddr, size, ACL_MEM_MALLOC_HUGE_FIRST); | 279 | + // 调用aclrtMalloc申请device侧内存 |
| 268 | - CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("aclrtMalloc failed. ERROR: %d\n", ret); return ret); | 280 | + auto ret = aclrtMalloc(deviceAddr, size, ACL_MEM_MALLOC_HUGE_FIRST); |
| 269 | - // 调用aclrtMemcpy将host侧数据拷贝到device侧内存上 | 281 | + CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("aclrtMalloc failed. ERROR: %d\n", ret); return ret); |
| 270 | - ret = aclrtMemcpy(*deviceAddr, size, hostData.data(), size, ACL_MEMCPY_HOST_TO_DEVICE); | 282 | + // 调用aclrtMemcpy将host侧数据拷贝到device侧内存上 |
| 271 | - CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("aclrtMemcpy failed. ERROR: %d\n", ret); return ret); | 283 | + ret = aclrtMemcpy(*deviceAddr, size, hostData.data(), size, ACL_MEMCPY_HOST_TO_DEVICE); |
| 284 | + CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("aclrtMemcpy failed. ERROR: %d\n", ret); return ret); | ||
| 272 | 285 | ||
| 273 | - // 计算连续tensor的strides | 286 | + // 计算连续tensor的strides |
| 274 | - std::vector<int64_t> strides(shape.size(), 1); | 287 | + std::vector<int64_t> strides(shape.size(), 1); |
| 275 | - for (int64_t i = shape.size() - 2; i >= 0; i--) { | 288 | + for (int64_t i = shape.size() - 2; i >= 0; i--) { |
| 276 | - strides[i] = shape[i + 1] * strides[i + 1]; | 289 | + strides[i] = shape[i + 1] * strides[i + 1]; |
| 277 | - } | 290 | + } |
| 278 | 291 | ||
| 279 | - // 调用aclCreateTensor接口创建aclTensor | 292 | + // 调用aclCreateTensor接口创建aclTensor |
| 280 | - *tensor = aclCreateTensor(shape.data(), shape.size(), dataType, strides.data(), 0, aclFormat::ACL_FORMAT_ND, | 293 | + *tensor = aclCreateTensor(shape.data(), shape.size(), dataType, strides.data(), 0, aclFormat::ACL_FORMAT_ND, |
| 281 | - shape.data(), shape.size(), *deviceAddr); | 294 | + shape.data(), shape.size(), *deviceAddr); |
| 282 | - return 0; | 295 | + return 0; |
| 283 | } | 296 | } |
| 284 | 297 | ||
| 285 | -int main() { | 298 | +int main() |
| 286 | - // 1.(固定写法)device/stream初始化,参考acl API手册 | 299 | +{ |
| 287 | - // 根据自己的实际device填写deviceId | 300 | + // 1. (固定写法)device/stream初始化,参考acl API文档 |
| 288 | - int32_t deviceId = 0; | 301 | + // 根据自己的实际device填写deviceId |
| 289 | - aclrtStream stream; | 302 | + int32_t deviceId = 0; |
| 290 | - auto ret = Init(deviceId, &stream); | 303 | + aclrtStream stream; |
| 291 | - CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("Init acl failed. ERROR: %d\n", ret); return ret); | 304 | + auto ret = Init(deviceId, &stream); |
| 305 | + CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("Init acl failed. ERROR: %d\n", ret); return ret); | ||
| 292 | 306 | ||
| 293 | - // 2.构造输入与输出,需要根据API的接口自定义构造 | 307 | + // 2. 构造输入与输出,需要根据API的接口自定义构造 |
| 294 | - std::vector<int64_t> selfShape = {4, 2}; | 308 | + std::vector<int64_t> selfShape = {4, 2}; |
| 295 | - std::vector<int64_t> dimsData = {1, 0}; | 309 | + std::vector<int64_t> dimsData = {1, 0}; |
| 296 | - std::vector<int64_t> outShape = {2, 4}; | 310 | + std::vector<int64_t> outShape = {2, 4}; |
| 297 | - void* selfDeviceAddr = nullptr; | 311 | + void* selfDeviceAddr = nullptr; |
| 298 | - void* outDeviceAddr = nullptr; | 312 | + void* outDeviceAddr = nullptr; |
| 299 | - aclTensor* self = nullptr; | 313 | + aclTensor* self = nullptr; |
| 300 | - aclTensor* out = nullptr; | 314 | + aclTensor* out = nullptr; |
| 301 | - std::vector<float> selfHostData = {1, 2, 3, 4, 5, 6, 7, 8}; | 315 | + std::vector<float> selfHostData = {1, 2, 3, 4, 5, 6, 7, 8}; |
| 302 | - std::vector<float> outHostData = {0, 0, 0, 0, 0, 0, 0, 0}; | 316 | + std::vector<float> outHostData = {0, 0, 0, 0, 0, 0, 0, 0}; |
| 303 | - // 创建self aclTensor | 317 | + // 创建self aclTensor |
| 304 | - ret = CreateAclTensor(selfHostData, selfShape, &selfDeviceAddr, aclDataType::ACL_FLOAT, &self); | 318 | + ret = CreateAclTensor(selfHostData, selfShape, &selfDeviceAddr, aclDataType::ACL_FLOAT, &self); |
| 305 | - CHECK_RET(ret == ACL_SUCCESS, return ret); | 319 | + CHECK_RET(ret == ACL_SUCCESS, return ret); |
| 306 | - // 创建dims aclIntArray | 320 | + // 创建dims aclIntArray |
| 307 | - aclIntArray *dims = aclCreateIntArray(dimsData.data(), dimsData.size()); | 321 | + aclIntArray* dims = aclCreateIntArray(dimsData.data(), dimsData.size()); |
| 308 | - // 创建out aclTensor | 322 | + // 创建out aclTensor |
| 309 | - ret = CreateAclTensor(outHostData, outShape, &outDeviceAddr, aclDataType::ACL_FLOAT, &out); | 323 | + ret = CreateAclTensor(outHostData, outShape, &outDeviceAddr, aclDataType::ACL_FLOAT, &out); |
| 310 | - CHECK_RET(ret == ACL_SUCCESS, return ret); | 324 | + CHECK_RET(ret == ACL_SUCCESS, return ret); |
| 311 | 325 | ||
| 312 | - // 3.调用CANN算子库API,需要修改为具体的API名称 | 326 | + // 3. 调用CANN算子库API,需要修改为具体的Api名称 |
| 313 | - uint64_t workspaceSize = 0; | 327 | + uint64_t workspaceSize = 0; |
| 314 | - aclOpExecutor* executor; | 328 | + aclOpExecutor* executor; |
| 315 | - // 调用aclnnPermute第一段接口 | 329 | + // 调用aclnnPermute第一段接口 |
| 316 | - ret = aclnnPermuteGetWorkspaceSize(self, dims, out, &workspaceSize, &executor); | 330 | + ret = aclnnPermuteGetWorkspaceSize(self, dims, out, &workspaceSize, &executor); |
| 317 | - CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("aclnnPermuteGetWorkspaceSize failed. ERROR: %d\n", ret); return ret); | 331 | + CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("aclnnPermuteGetWorkspaceSize failed. ERROR: %d\n", ret); return ret); |
| 318 | - // 根据第一段接口计算出的workspaceSize申请device内存 | 332 | + // 根据第一段接口计算出的workspaceSize申请device内存 |
| 319 | - void* workspaceAddr = nullptr; | 333 | + void* workspaceAddr = nullptr; |
| 320 | - if (workspaceSize > 0) { | 334 | + if (workspaceSize > static_cast<uint64_t>(0)) { |
| 321 | - ret = aclrtMalloc(&workspaceAddr, workspaceSize, ACL_MEM_MALLOC_HUGE_FIRST); | 335 | + ret = aclrtMalloc(&workspaceAddr, workspaceSize, ACL_MEM_MALLOC_HUGE_FIRST); |
| 322 | - CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("allocate workspace failed. ERROR: %d\n", ret); return ret); | 336 | + CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("allocate workspace failed. ERROR: %d\n", ret); return ret); |
| 323 | - } | 337 | + } |
| 324 | - // 调用aclnnPermute第二段接口 | 338 | + // 调用aclnnPermute第二段接口 |
| 325 | - ret = aclnnPermute(workspaceAddr, workspaceSize, executor, stream); | 339 | + ret = aclnnPermute(workspaceAddr, workspaceSize, executor, stream); |
| 326 | - CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("aclnnPermute failed. ERROR: %d\n", ret); return ret); | 340 | + CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("aclnnPermute failed. ERROR: %d\n", ret); return ret); |
| 327 | 341 | ||
| 328 | - // 4.(固定写法)同步等待任务执行结束 | 342 | + // 4. (固定写法)同步等待任务执行结束 |
| 329 | - ret = aclrtSynchronizeStream(stream); | 343 | + ret = aclrtSynchronizeStream(stream); |
| 330 | - CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("aclrtSynchronizeStream failed. ERROR: %d\n", ret); return ret); | 344 | + CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("aclrtSynchronizeStream failed. ERROR: %d\n", ret); return ret); |
| 331 | 345 | ||
| 332 | - // 5.获取输出的值,将device侧内存上的结果拷贝至host侧,需要根据具体API的接口定义修改 | 346 | + // 5. 获取输出的值,将device侧内存上的结果拷贝至host侧,需要根据具体API的接口定义修改 |
| 333 | - auto size = GetShapeSize(outShape); | 347 | + auto size = GetShapeSize(outShape); |
| 334 | - std::vector<float> resultData(size, 0); | 348 | + std::vector<float> resultData(size, 0); |
| 335 | - ret = aclrtMemcpy(resultData.data(), resultData.size() * sizeof(resultData[0]), outDeviceAddr, | 349 | + ret = aclrtMemcpy(resultData.data(), resultData.size() * sizeof(resultData[0]), outDeviceAddr, |
| 336 | - size * sizeof(resultData[0]), ACL_MEMCPY_DEVICE_TO_HOST); | 350 | + size * sizeof(resultData[0]), ACL_MEMCPY_DEVICE_TO_HOST); |
| 337 | - CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("copy result from device to host failed. ERROR: %d\n", ret); return ret); | 351 | + CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("copy result from device to host failed. ERROR: %d\n", ret); return ret); |
| 338 | - for (int64_t i = 0; i < size; i++) { | 352 | + for (int64_t i = 0; i < size; i++) { |
| 339 | - LOG_PRINT("result[%ld] is: %f\n", i, resultData[i]); | 353 | + LOG_PRINT("result[%ld] is: %f\n", i, resultData[i]); |
| 340 | - } | 354 | + } |
| 341 | 355 | ||
| 342 | - // 6.释放aclTensor和aclIntArray,需要根据具体API的接口定义修改 | 356 | + // 6. 释放aclTensor和aclIntArray,需要根据具体API的接口定义修改 |
| 343 | - aclDestroyTensor(self); | 357 | + aclDestroyTensor(self); |
| 344 | - aclDestroyIntArray(dims); | 358 | + aclDestroyIntArray(dims); |
| 345 | - aclDestroyTensor(out); | 359 | + aclDestroyTensor(out); |
| 346 | 360 | ||
| 347 | - // 7.释放device资源 | 361 | + // 7. 释放device 资源 |
| 348 | - aclrtFree(selfDeviceAddr); | 362 | + aclrtFree(selfDeviceAddr); |
| 349 | - aclrtFree(outDeviceAddr); | 363 | + aclrtFree(outDeviceAddr); |
| 350 | - if (workspaceSize > 0) { | 364 | + if (workspaceSize > static_cast<uint64_t>(0)) { |
| 351 | - aclrtFree(workspaceAddr); | 365 | + aclrtFree(workspaceAddr); |
| 352 | - } | 366 | + } |
| 353 | - aclrtDestroyStream(stream); | 367 | + aclrtDestroyStream(stream); |
| 354 | - aclrtResetDevice(deviceId); | 368 | + aclrtResetDevice(deviceId); |
| 355 | - aclFinalize(); | 369 | + aclFinalize(); |
| 356 | 370 | ||
| 357 | - return 0; | 371 | + return 0; |
| 358 | } | 372 | } |
| 359 | ``` | 373 | ``` |
| @@ -78,7 +78,7 @@ aclnnStatus aclnnPermute( | |||
| 78 | <td>self (aclTensor*)</td> | 78 | <td>self (aclTensor*)</td> |
| 79 | <td>Input</td> | 79 | <td>Input</td> |
| 80 | <td>Input tensor.</td> | 80 | <td>Input tensor.</td> |
| 81 | - <td>-</td> | 81 | + <td>Supports empty tensors. When the shape of self contains 0, the output is an empty tensor.</td> |
| 82 | <td>FLOAT, FLOAT16, DOUBLE, UINT64, INT64, UINT32, INT32, UINT16, INT16, UINT8, INT8, BOOL, COMPLEX64, COMPLEX128, BFLOAT16, HIFLOAT8, FLOAT8_E5M2, FLOAT8_E4M3FN</td> | 82 | <td>FLOAT, FLOAT16, DOUBLE, UINT64, INT64, UINT32, INT32, UINT16, INT16, UINT8, INT8, BOOL, COMPLEX64, COMPLEX128, BFLOAT16, HIFLOAT8, FLOAT8_E5M2, FLOAT8_E4M3FN</td> |
| 83 | <td>ND</td> | 83 | <td>ND</td> |
| 84 | <td>≤8</td> | 84 | <td>≤8</td> |
| @@ -88,7 +88,7 @@ aclnnStatus aclnnPermute( | |||
| 88 | <td>dims (aclIntArray*)</td> | 88 | <td>dims (aclIntArray*)</td> |
| 89 | <td>Input</td> | 89 | <td>Input</td> |
| 90 | <td>Integer array that represents the dimensions of the original tensor and specifies the new axis order.</td> | 90 | <td>Integer array that represents the dimensions of the original tensor and specifies the new axis order.</td> |
| 91 | - <td>The value must be in the range [-number of dimensions of self, number of dimensions of self - 1].</td> | 91 | + <td>The number of elements must be equal to the number of dimensions of self. Each value must be in the range [-number of dimensions of self, number of dimensions of self - 1], and the elements must not be repeated. A negative value indicates counting from the end.</td> |
| 92 | <td>INT64</td> | 92 | <td>INT64</td> |
| 93 | <td>-</td> | 93 | <td>-</td> |
| 94 | <td>-</td> | 94 | <td>-</td> |
| @@ -98,8 +98,8 @@ aclnnStatus aclnnPermute( | |||
| 98 | <td>out (aclTensor*)</td> | 98 | <td>out (aclTensor*)</td> |
| 99 | <td>Output</td> | 99 | <td>Output</td> |
| 100 | <td>Output tensor.</td> | 100 | <td>Output tensor.</td> |
| 101 | - <td>The shape is determined by dims and the shape of the original self. The dtype must be the same as that of self.</td> | 101 | + <td>The shape is determined by dims and the shape of self, that is, out.shape[i] = self.shape[dims[i]]. The dtype must be the same as that of self.</td> |
| 102 | - <td>FLOAT, FLOAT16, DOUBLE, UINT64, INT64, UINT32, INT32, UINT16, INT16, UINT8, INT8, BOOL, COMPLEX64, COMPLEX128, BFLOAT16, HIFLOAT8, FLOAT8_E5M2, FLOAT8_E4M3FN.</td> | 102 | + <td>FLOAT, FLOAT16, DOUBLE, UINT64, INT64, UINT32, INT32, UINT16, INT16, UINT8, INT8, BOOL, COMPLEX64, COMPLEX128, BFLOAT16, HIFLOAT8, FLOAT8_E5M2, FLOAT8_E4M3FN</td> |
| 103 | <td>ND</td> | 103 | <td>ND</td> |
| 104 | <td>≤8</td> | 104 | <td>≤8</td> |
| 105 | <td>√</td> | 105 | <td>√</td> |
| @@ -156,8 +156,8 @@ aclnnStatus aclnnPermute( | |||
| 156 | <td>self, dims, or out is a null pointer.</td> | 156 | <td>self, dims, or out is a null pointer.</td> |
| 157 | </tr> | 157 | </tr> |
| 158 | <tr> | 158 | <tr> |
| 159 | - <td rowspan="4">ACLNN_ERR_PARAM_INVALID</td> | 159 | + <td rowspan="7">ACLNN_ERR_PARAM_INVALID</td> |
| 160 | - <td rowspan="4">161002</td> | 160 | + <td rowspan="7">161002</td> |
| 161 | <td>The data type of self or out is not in the supported range.</td> | 161 | <td>The data type of self or out is not in the supported range.</td> |
| 162 | </tr> | 162 | </tr> |
| 163 | <tr> | 163 | <tr> |
| @@ -169,6 +169,15 @@ aclnnStatus aclnnPermute( | |||
| 169 | <tr> | 169 | <tr> |
| 170 | <td>The value of dims is not in the range of [-number of dimensions of self, number of dimensions of self - 1].</td> | 170 | <td>The value of dims is not in the range of [-number of dimensions of self, number of dimensions of self - 1].</td> |
| 171 | </tr> | 171 | </tr> |
| 172 | + <tr> | ||
| 173 | + <td>The number of elements in dims is inconsistent with the number of dimensions of self.</td> | ||
| 174 | + </tr> | ||
| 175 | + <tr> | ||
| 176 | + <td>dims contains duplicate elements.</td> | ||
| 177 | + </tr> | ||
| 178 | + <tr> | ||
| 179 | + <td>The shape of out is inconsistent with the shape of self permuted by dims.</td> | ||
| 180 | + </tr> | ||
| 172 | </tbody> | 181 | </tbody> |
| 173 | </table> | 182 | </table> |
| 174 | 183 | ||
| @@ -194,14 +203,14 @@ aclnnStatus aclnnPermute( | |||
| 194 | <td>Memory address of the workspace allocated on the Device.</td> | 203 | <td>Memory address of the workspace allocated on the Device.</td> |
| 195 | </tr> | 204 | </tr> |
| 196 | <tr> | 205 | <tr> |
| 197 | - <td>workspace_size</td> | 206 | + <td>workspaceSize</td> |
| 198 | <td>Input</td> | 207 | <td>Input</td> |
| 199 | - <td>Size of the workspace allocated on the Device. The value is obtained by calling the first-phase API aclnnPermuteGetWorkspaceSize.</td> | 208 | + <td>Size of the workspace allocated on the Device, obtained by the first-phase API aclnnPermuteGetWorkspaceSize.</td> |
| 200 | </tr> | 209 | </tr> |
| 201 | <tr> | 210 | <tr> |
| 202 | <td>executor</td> | 211 | <td>executor</td> |
| 203 | <td>Input</td> | 212 | <td>Input</td> |
| 204 | - <td>Op executor, containing the operator computation process.</td> | 213 | + <td>op executor, which contains the operator computation process.</td> |
| 205 | </tr> | 214 | </tr> |
| 206 | <tr> | 215 | <tr> |
| 207 | <td>stream</td> | 216 | <td>stream</td> |
| @@ -217,6 +226,7 @@ aclnnStatus aclnnPermute( | |||
| 217 | 226 | ||
| 218 | ## Constraints | 227 | ## Constraints |
| 219 | 228 | ||
| 229 | +- The number of dimensions of input self must not exceed 8. | ||
| 220 | - Deterministic computation: | 230 | - Deterministic computation: |
| 221 | - aclnnPermute defaults to a deterministic implementation. | 231 | - aclnnPermute defaults to a deterministic implementation. |
| 222 | 232 | ||
| @@ -242,7 +252,8 @@ The following sample code is for reference only. For details about compilation a | |||
| 242 | printf(message, ##__VA_ARGS__); \ | 252 | printf(message, ##__VA_ARGS__); \ |
| 243 | } while (0) | 253 | } while (0) |
| 244 | 254 | ||
| 245 | -int64_t GetShapeSize(const std::vector<int64_t>& shape) { | 255 | +int64_t GetShapeSize(const std::vector<int64_t>& shape) |
| 256 | +{ | ||
| 246 | int64_t shapeSize = 1; | 257 | int64_t shapeSize = 1; |
| 247 | for (auto i : shape) { | 258 | for (auto i : shape) { |
| 248 | shapeSize *= i; | 259 | shapeSize *= i; |
| @@ -250,7 +261,8 @@ int64_t GetShapeSize(const std::vector<int64_t>& shape) { | |||
| 250 | return shapeSize; | 261 | return shapeSize; |
| 251 | } | 262 | } |
| 252 | 263 | ||
| 253 | -int Init(int32_t deviceId, aclrtStream* stream) { | 264 | +int Init(int32_t deviceId, aclrtStream* stream) |
| 265 | +{ | ||
| 254 | // Boilerplate for resource initialization | 266 | // Boilerplate for resource initialization |
| 255 | auto ret = aclInit(nullptr); | 267 | auto ret = aclInit(nullptr); |
| 256 | CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("aclInit failed. ERROR: %d\n", ret); return ret); | 268 | CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("aclInit failed. ERROR: %d\n", ret); return ret); |
| @@ -263,7 +275,8 @@ int Init(int32_t deviceId, aclrtStream* stream) { | |||
| 263 | 275 | ||
| 264 | template <typename T> | 276 | template <typename T> |
| 265 | int CreateAclTensor(const std::vector<T>& hostData, const std::vector<int64_t>& shape, void** deviceAddr, | 277 | int CreateAclTensor(const std::vector<T>& hostData, const std::vector<int64_t>& shape, void** deviceAddr, |
| 266 | - aclDataType dataType, aclTensor** tensor) { | 278 | + aclDataType dataType, aclTensor** tensor) |
| 279 | +{ | ||
| 267 | auto size = GetShapeSize(shape) * sizeof(T); | 280 | auto size = GetShapeSize(shape) * sizeof(T); |
| 268 | // Call aclrtMalloc to apply for device-side memory | 281 | // Call aclrtMalloc to apply for device-side memory |
| 269 | auto ret = aclrtMalloc(deviceAddr, size, ACL_MEM_MALLOC_HUGE_FIRST); | 282 | auto ret = aclrtMalloc(deviceAddr, size, ACL_MEM_MALLOC_HUGE_FIRST); |
| @@ -284,7 +297,8 @@ int CreateAclTensor(const std::vector<T>& hostData, const std::vector<int64_t>& | |||
| 284 | return 0; | 297 | return 0; |
| 285 | } | 298 | } |
| 286 | 299 | ||
| 287 | -int main() { | 300 | +int main() |
| 301 | +{ | ||
| 288 | // 1. (Boilerplate) Device/stream initialization. For details, see the acl API documentation | 302 | // 1. (Boilerplate) Device/stream initialization. For details, see the acl API documentation |
| 289 | // Set deviceId based on the actual device | 303 | // Set deviceId based on the actual device |
| 290 | int32_t deviceId = 0; | 304 | int32_t deviceId = 0; |
| @@ -306,7 +320,7 @@ int main() { | |||
| 306 | ret = CreateAclTensor(selfHostData, selfShape, &selfDeviceAddr, aclDataType::ACL_FLOAT, &self); | 320 | ret = CreateAclTensor(selfHostData, selfShape, &selfDeviceAddr, aclDataType::ACL_FLOAT, &self); |
| 307 | CHECK_RET(ret == ACL_SUCCESS, return ret); | 321 | CHECK_RET(ret == ACL_SUCCESS, return ret); |
| 308 | // Create the dims aclIntArray | 322 | // Create the dims aclIntArray |
| 309 | - aclIntArray *dims = aclCreateIntArray(dimsData.data(), dimsData.size()); | 323 | + aclIntArray* dims = aclCreateIntArray(dimsData.data(), dimsData.size()); |
| 310 | // Create the out aclTensor. | 324 | // Create the out aclTensor. |
| 311 | ret = CreateAclTensor(outHostData, outShape, &outDeviceAddr, aclDataType::ACL_FLOAT, &out); | 325 | ret = CreateAclTensor(outHostData, outShape, &outDeviceAddr, aclDataType::ACL_FLOAT, &out); |
| 312 | CHECK_RET(ret == ACL_SUCCESS, return ret); | 326 | CHECK_RET(ret == ACL_SUCCESS, return ret); |
| @@ -319,7 +333,7 @@ int main() { | |||
| 319 | CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("aclnnPermuteGetWorkspaceSize failed. ERROR: %d\n", ret); return ret); | 333 | CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("aclnnPermuteGetWorkspaceSize failed. ERROR: %d\n", ret); return ret); |
| 320 | // Allocate device memory based on the workspaceSize calculated by the first-phase API. | 334 | // Allocate device memory based on the workspaceSize calculated by the first-phase API. |
| 321 | void* workspaceAddr = nullptr; | 335 | void* workspaceAddr = nullptr; |
| 322 | - if (workspaceSize > 0) { | 336 | + if (workspaceSize > static_cast<uint64_t>(0)) { |
| 323 | ret = aclrtMalloc(&workspaceAddr, workspaceSize, ACL_MEM_MALLOC_HUGE_FIRST); | 337 | ret = aclrtMalloc(&workspaceAddr, workspaceSize, ACL_MEM_MALLOC_HUGE_FIRST); |
| 324 | CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("allocate workspace failed. ERROR: %d\n", ret); return ret); | 338 | CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("allocate workspace failed. ERROR: %d\n", ret); return ret); |
| 325 | } | 339 | } |
| @@ -349,7 +363,7 @@ int main() { | |||
| 349 | // 7. Release device resources. | 363 | // 7. Release device resources. |
| 350 | aclrtFree(selfDeviceAddr); | 364 | aclrtFree(selfDeviceAddr); |
| 351 | aclrtFree(outDeviceAddr); | 365 | aclrtFree(outDeviceAddr); |
| 352 | - if (workspaceSize > 0) { | 366 | + if (workspaceSize > static_cast<uint64_t>(0)) { |
| 353 | aclrtFree(workspaceAddr); | 367 | aclrtFree(workspaceAddr); |
| 354 | } | 368 | } |
| 355 | aclrtDestroyStream(stream); | 369 | aclrtDestroyStream(stream); |
| @@ -0,0 +1,257 @@ | |||
| 1 | +/** | ||
| 2 | + * Copyright (c) 2026 Huawei Technologies Co., Ltd. | ||
| 3 | + * This program is free software, you can redistribute it and/or modify it under the terms and conditions of | ||
| 4 | + * CANN Open Software License Agreement Version 2.0 (the "License"). | ||
| 5 | + * Please refer to the License for details. You may not use this file except in compliance with the License. | ||
| 6 | + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, | ||
| 7 | + * INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE. | ||
| 8 | + * See LICENSE in the root of the software repository for the full text of the License. | ||
| 9 | + */ | ||
| 10 | + | ||
| 11 | +#include <cstdio> | ||
| 12 | +#include <cstring> | ||
| 13 | +#include <ctime> | ||
| 14 | +#include <map> | ||
| 15 | +#include <memory> | ||
| 16 | +#include <new> | ||
| 17 | +#include <string> | ||
| 18 | +#include <vector> | ||
| 19 | + | ||
| 20 | +#include "ge_api.h" | ||
| 21 | +#include "ge_api_types.h" | ||
| 22 | +#include "ge_error_codes.h" | ||
| 23 | +#include "ge_ir_build.h" | ||
| 24 | +#include "graph.h" | ||
| 25 | +#include "tensor.h" | ||
| 26 | +#include "types.h" | ||
| 27 | + | ||
| 28 | +#include "../op_graph/transpose_proto.h" | ||
| 29 | + | ||
| 30 | +#define FAILED -1 | ||
| 31 | +#define SUCCESS 0 | ||
| 32 | + | ||
| 33 | +using namespace ge; | ||
| 34 | +using std::map; | ||
| 35 | +using std::string; | ||
| 36 | +using std::vector; | ||
| 37 | + | ||
| 38 | +#define LOG_PRINT(message, ...) \ | ||
| 39 | + do { \ | ||
| 40 | + printf(message, ##__VA_ARGS__); \ | ||
| 41 | + } while (0) | ||
| 42 | + | ||
| 43 | +namespace ge { | ||
| 44 | +REG_OP(Data).INPUT(x, TensorType::ALL()).OUTPUT(y, TensorType::ALL()).ATTR(index, Int, 0).OP_END_FACTORY_REG(Data); | ||
| 45 | +REG_OP(Const).OUTPUT(y, TensorType::ALL()).ATTR(value, Tensor, Tensor()).OP_END_FACTORY_REG(Const); | ||
| 46 | +} // namespace ge | ||
| 47 | + | ||
| 48 | +namespace { | ||
| 49 | +string GetTime() | ||
| 50 | +{ | ||
| 51 | + time_t timep; | ||
| 52 | + time(&timep); | ||
| 53 | + char tmp[64] = {0}; | ||
| 54 | + struct tm tm_info; | ||
| 55 | + strftime(tmp, sizeof(tmp), "%Y-%m-%d %H:%M:%S,000", localtime_r(&timep, &tm_info)); | ||
| 56 | + return tmp; | ||
| 57 | +} | ||
| 58 | + | ||
| 59 | +int32_t WriteDataToFile(const string& bin_file, uint64_t data_size, const uint8_t* input_data) | ||
| 60 | +{ | ||
| 61 | + FILE* fp = fopen(bin_file.c_str(), "wb"); | ||
| 62 | + if (fp == nullptr) { | ||
| 63 | + printf("Failed to open file: %s\n", bin_file.c_str()); | ||
| 64 | + return FAILED; | ||
| 65 | + } | ||
| 66 | + size_t written = fwrite(input_data, sizeof(uint8_t), data_size, fp); | ||
| 67 | + fclose(fp); | ||
| 68 | + if (written != data_size) { | ||
| 69 | + printf("Failed to write file: %s\n", bin_file.c_str()); | ||
| 70 | + return FAILED; | ||
| 71 | + } | ||
| 72 | + return SUCCESS; | ||
| 73 | +} | ||
| 74 | + | ||
| 75 | +template <typename T> | ||
| 76 | +ge::Tensor CreateTensor(vector<int64_t> shape, ge::DataType d_type, const vector<T>& values) | ||
| 77 | +{ | ||
| 78 | + TensorDesc desc(ge::Shape(shape), ge::FORMAT_ND, d_type); | ||
| 79 | + desc.SetPlacement(ge::kPlacementHost); | ||
| 80 | + desc.SetRealDimCnt(shape.size()); | ||
| 81 | + size_t size = 1; | ||
| 82 | + for (size_t i = 0; i < shape.size(); ++i) { | ||
| 83 | + size *= static_cast<size_t>(shape[i]); | ||
| 84 | + } | ||
| 85 | + if (values.size() != size) { | ||
| 86 | + printf("%s - ERROR - [XIR]: Generate input tensor failed\n", GetTime().c_str()); | ||
| 87 | + return ge::Tensor{}; | ||
| 88 | + } | ||
| 89 | + | ||
| 90 | + return ge::Tensor(desc, reinterpret_cast<const uint8_t*>(values.data()), values.size() * sizeof(T)); | ||
| 91 | +} | ||
| 92 | + | ||
| 93 | +ge::Operator CreateInputNode(size_t i, TensorDesc desc) | ||
| 94 | +{ | ||
| 95 | + auto node = op::Data("placeholder" + std::to_string(i)).set_attr_index(i); | ||
| 96 | + node.update_input_desc_x(desc); | ||
| 97 | + node.update_output_desc_y(desc); | ||
| 98 | + return node; | ||
| 99 | +} | ||
| 100 | + | ||
| 101 | +// perm 为数据依赖输入,形状推导阶段需要其取值,因此用 Const 节点提供。 | ||
| 102 | +ge::Operator CreateConstNode(const string& name, TensorDesc desc, const vector<int32_t>& values) | ||
| 103 | +{ | ||
| 104 | + auto node = op::Const(name); | ||
| 105 | + ge::Tensor tensor(desc, reinterpret_cast<const uint8_t*>(values.data()), values.size() * sizeof(int32_t)); | ||
| 106 | + node.SetAttr("value", tensor); | ||
| 107 | + node.update_output_desc_y(desc); | ||
| 108 | + return node; | ||
| 109 | +} | ||
| 110 | + | ||
| 111 | +int CreateOppInGraph(vector<ge::Tensor>& input, vector<Operator>& inputs, vector<Operator>& outputs, Graph& graph) | ||
| 112 | +{ | ||
| 113 | + ge::DataType d_type = ge::DT_FLOAT; | ||
| 114 | + auto node_transpose = op::Transpose("transpose"); | ||
| 115 | + | ||
| 116 | + vector<int64_t> x_shape = {2, 3}; | ||
| 117 | + vector<int64_t> perm_shape = {2}; | ||
| 118 | + vector<int64_t> y_shape = {3, 2}; | ||
| 119 | + | ||
| 120 | + auto tensor_x = CreateTensor<float>(x_shape, d_type, {1.0F, 2.0F, 3.0F, 4.0F, 5.0F, 6.0F}); | ||
| 121 | + if (tensor_x.GetSize() == 0) { | ||
| 122 | + return FAILED; | ||
| 123 | + } | ||
| 124 | + auto node_x = CreateInputNode(0, tensor_x.GetTensorDesc()); | ||
| 125 | + input.push_back(tensor_x); | ||
| 126 | + graph.AddOp(node_x); | ||
| 127 | + inputs.push_back(node_x); | ||
| 128 | + node_transpose.set_input_x(node_x); | ||
| 129 | + node_transpose.update_input_desc_x(tensor_x.GetTensorDesc()); | ||
| 130 | + | ||
| 131 | + TensorDesc perm_desc(ge::Shape(perm_shape), ge::FORMAT_ND, ge::DT_INT32); | ||
| 132 | + perm_desc.SetPlacement(ge::kPlacementHost); | ||
| 133 | + perm_desc.SetRealDimCnt(perm_shape.size()); | ||
| 134 | + auto node_perm = CreateConstNode("perm", perm_desc, {1, 0}); | ||
| 135 | + graph.AddOp(node_perm); | ||
| 136 | + node_transpose.set_input_perm(node_perm); | ||
| 137 | + node_transpose.update_input_desc_perm(perm_desc); | ||
| 138 | + | ||
| 139 | + TensorDesc y_desc(ge::Shape(y_shape), ge::FORMAT_ND, d_type); | ||
| 140 | + node_transpose.update_output_desc_y(y_desc); | ||
| 141 | + outputs.push_back(node_transpose); | ||
| 142 | + return SUCCESS; | ||
| 143 | +} | ||
| 144 | + | ||
| 145 | +int SaveInput(const vector<ge::Tensor>& input) | ||
| 146 | +{ | ||
| 147 | + for (size_t i = 0; i < input.size(); ++i) { | ||
| 148 | + string input_file = "./tc_ge_irrun_example_npu_input_" + std::to_string(i) + ".bin"; | ||
| 149 | + const uint8_t* input_data = input[i].GetData(); | ||
| 150 | + int64_t shape_size = input[i].GetTensorDesc().GetShape().GetShapeSize(); | ||
| 151 | + uint32_t data_size = static_cast<uint32_t>(shape_size) * | ||
| 152 | + ge::GetSizeByDataType(input[i].GetTensorDesc().GetDataType()); | ||
| 153 | + if (WriteDataToFile(input_file, data_size, input_data) != SUCCESS) { | ||
| 154 | + return FAILED; | ||
| 155 | + } | ||
| 156 | + } | ||
| 157 | + return SUCCESS; | ||
| 158 | +} | ||
| 159 | + | ||
| 160 | +int SaveOutput(const vector<ge::Tensor>& output) | ||
| 161 | +{ | ||
| 162 | + for (size_t i = 0; i < output.size(); ++i) { | ||
| 163 | + string output_file = "./tc_ge_irrun_example_npu_output_" + std::to_string(i) + ".bin"; | ||
| 164 | + const uint8_t* output_data = output[i].GetData(); | ||
| 165 | + int64_t shape_size = output[i].GetTensorDesc().GetShape().GetShapeSize(); | ||
| 166 | + uint32_t data_size = static_cast<uint32_t>(shape_size) * | ||
| 167 | + ge::GetSizeByDataType(output[i].GetTensorDesc().GetDataType()); | ||
| 168 | + if (WriteDataToFile(output_file, data_size, output_data) != SUCCESS) { | ||
| 169 | + return FAILED; | ||
| 170 | + } | ||
| 171 | + | ||
| 172 | + const float* result = reinterpret_cast<const float*>(output_data); | ||
| 173 | + for (int64_t j = 0; j < shape_size; j++) { | ||
| 174 | + LOG_PRINT("result[%ld] is: %f\n", j, result[j]); | ||
| 175 | + } | ||
| 176 | + } | ||
| 177 | + return SUCCESS; | ||
| 178 | +} | ||
| 179 | +} // namespace | ||
| 180 | + | ||
| 181 | +int main(int argc, char* argv[]) | ||
| 182 | +{ | ||
| 183 | + (void)argc; | ||
| 184 | + (void)argv; | ||
| 185 | + | ||
| 186 | + const char* graph_name = "tc_ge_irrun_transpose"; | ||
| 187 | + Graph graph(graph_name); | ||
| 188 | + vector<ge::Tensor> input; | ||
| 189 | + | ||
| 190 | + printf("%s - INFO - [XIR]: Start to initialize ge using ge global options\n", GetTime().c_str()); | ||
| 191 | + map<AscendString, AscendString> global_options = {{"ge.exec.deviceId", "0"}, {"ge.graphRunMode", "1"}}; | ||
| 192 | + Status ret = ge::GEInitialize(global_options); | ||
| 193 | + if (ret != SUCCESS) { | ||
| 194 | + printf("%s - ERROR - [XIR]: Initialize ge using ge global options failed\n", GetTime().c_str()); | ||
| 195 | + return FAILED; | ||
| 196 | + } | ||
| 197 | + | ||
| 198 | + vector<Operator> inputs; | ||
| 199 | + vector<Operator> outputs; | ||
| 200 | + ret = CreateOppInGraph(input, inputs, outputs, graph); | ||
| 201 | + if (ret != SUCCESS) { | ||
| 202 | + ge::GEFinalize(); | ||
| 203 | + return FAILED; | ||
| 204 | + } | ||
| 205 | + | ||
| 206 | + if (!inputs.empty() && !outputs.empty()) { | ||
| 207 | + graph.SetInputs(inputs).SetOutputs(outputs); | ||
| 208 | + } | ||
| 209 | + | ||
| 210 | + map<AscendString, AscendString> build_options; | ||
| 211 | + std::unique_ptr<ge::Session> session(new (std::nothrow) Session(build_options)); | ||
| 212 | + if (session == nullptr) { | ||
| 213 | + printf("%s - ERROR - [XIR]: Create ir session failed\n", GetTime().c_str()); | ||
| 214 | + ge::GEFinalize(); | ||
| 215 | + return FAILED; | ||
| 216 | + } | ||
| 217 | + | ||
| 218 | + map<AscendString, AscendString> graph_options = {}; | ||
| 219 | + uint32_t graph_id = 0; | ||
| 220 | + ret = session->AddGraph(graph_id, graph, graph_options); | ||
| 221 | + if (ret != SUCCESS) { | ||
| 222 | + printf("%s - ERROR - [XIR]: Add graph failed\n", GetTime().c_str()); | ||
| 223 | + ge::GEFinalize(); | ||
| 224 | + return FAILED; | ||
| 225 | + } | ||
| 226 | + | ||
| 227 | + vector<ge::Tensor> output; | ||
| 228 | + ret = session->RunGraph(graph_id, input, output); | ||
| 229 | + if (ret != SUCCESS) { | ||
| 230 | + printf("%s - ERROR - [XIR]: Run graph failed\n", GetTime().c_str()); | ||
| 231 | + ge::GEFinalize(); | ||
| 232 | + return FAILED; | ||
| 233 | + } | ||
| 234 | + printf("%s - INFO - [XIR]: Run graph success\n", GetTime().c_str()); | ||
| 235 | + | ||
| 236 | + ret = SaveInput(input); | ||
| 237 | + if (ret != SUCCESS) { | ||
| 238 | + printf("%s - ERROR - [XIR]: Save graph input failed\n", GetTime().c_str()); | ||
| 239 | + ge::GEFinalize(); | ||
| 240 | + return FAILED; | ||
| 241 | + } | ||
| 242 | + | ||
| 243 | + ret = SaveOutput(output); | ||
| 244 | + if (ret != SUCCESS) { | ||
| 245 | + printf("%s - ERROR - [XIR]: Save graph output failed\n", GetTime().c_str()); | ||
| 246 | + ge::GEFinalize(); | ||
| 247 | + return FAILED; | ||
| 248 | + } | ||
| 249 | + | ||
| 250 | + ret = ge::GEFinalize(); | ||
| 251 | + if (ret != SUCCESS) { | ||
| 252 | + printf("%s - ERROR - [XIR]: GE Finalize failed\n", GetTime().c_str()); | ||
| 253 | + return FAILED; | ||
| 254 | + } | ||
| 255 | + printf("%s - INFO - [XIR]: Run graph over\n", GetTime().c_str()); | ||
| 256 | + return SUCCESS; | ||
| 257 | +} | ||
| @@ -77,7 +77,7 @@ | |||
| 77 | | [aclnnCdist](../../math/cdist/docs/aclnnCdist.md) | 计算两个向量集合中每个点之间的p范数距离。 | 默认确定性实现| 默认确定性实现| | 77 | | [aclnnCdist](../../math/cdist/docs/aclnnCdist.md) | 计算两个向量集合中每个点之间的p范数距离。 | 默认确定性实现| 默认确定性实现| |
| 78 | | [aclnnCdistBackward](../../math/cdist_grad/docs/aclnnCdistBackward.md) | 完成aclnnCdist的反向。 | 默认确定性实现| 默认确定性实现 | | 78 | | [aclnnCdistBackward](../../math/cdist_grad/docs/aclnnCdistBackward.md) | 完成aclnnCdist的反向。 | 默认确定性实现| 默认确定性实现 | |
| 79 | | [aclnnCeil&aclnnInplaceCeil](../../math/ceil/docs/aclnnCeil&aclnnInplaceCeil.md) | 返回输入tensor中每个元素向上取整的结果。 | 默认确定性实现| 默认确定性实现| | 79 | | [aclnnCeil&aclnnInplaceCeil](../../math/ceil/docs/aclnnCeil&aclnnInplaceCeil.md) | 返回输入tensor中每个元素向上取整的结果。 | 默认确定性实现| 默认确定性实现| |
| 80 | -| [aclnnChannelShuffle](../../conversion/transpose/docs/aclnnChannelShuffle.md) | 将(\*, C, H, W)张量的channels分成g个组,然后将每个通道组中的通道进行随机重排,最后将所有通道合并输出,同时保持最终输出张量的shape和输入张量保持一致。 | 默认确定性实现| 默认确定性实现| | 80 | +| [aclnnChannelShuffle](../../conversion/transpose/docs/aclnnChannelShuffle.md) | 将(N, C, \*)张量按通道维(固定为第1维,下标从0开始,长度为C)分成groups个组,然后将每个通道组中的通道进行重排,最后将所有通道合并输出,同时保持输出张量的shape与输入张量一致。 | 默认确定性实现| 默认确定性实现| |
| 81 | | [aclnnChunkCat](../../conversion/chunk_cat/docs/aclnnChunkCat.md) | 将tensors中所有tensor先按照维度dim切分为numChunks块,再按照dim后一维进行级联,最后转换为out的数据类型。 | 默认确定性实现| 默认确定性实现| | 81 | | [aclnnChunkCat](../../conversion/chunk_cat/docs/aclnnChunkCat.md) | 将tensors中所有tensor先按照维度dim切分为numChunks块,再按照dim后一维进行级联,最后转换为out的数据类型。 | 默认确定性实现| 默认确定性实现| |
| 82 | | [aclnnCircularPad2d](../../conversion/circular_pad/docs/aclnnCircularPad2d.md) | 使用输入循环填充输入tensor的最后两维。 | 默认确定性实现| 默认确定性实现| | 82 | | [aclnnCircularPad2d](../../conversion/circular_pad/docs/aclnnCircularPad2d.md) | 使用输入循环填充输入tensor的最后两维。 | 默认确定性实现| 默认确定性实现| |
| 83 | | [aclnnCircularPad2dBackward](../../conversion/circular_pad_grad/docs/aclnnCircularPad2dBackward.md) | circular_pad2d的反向传播,前向计算参考aclnnCircularPad2d。 | 默认确定性实现| 默认确定性实现| | 83 | | [aclnnCircularPad2dBackward](../../conversion/circular_pad_grad/docs/aclnnCircularPad2dBackward.md) | circular_pad2d的反向传播,前向计算参考aclnnCircularPad2d。 | 默认确定性实现| 默认确定性实现| |


🟡 Medium Priority
变更行:README.md 第 24 行把 FLOAT4_E2M1、FLOAT4_E1M2、HIFLOAT4、HIFLOAT4_SCALE 四种低位宽类型列入 x 的「支持数据类型」;同一改动的新增行第 28 行又声明 Atlas 950PR&950DT、Atlas A3、Atlas A2、Atlas 200I/500 A2、Atlas 推理、Atlas 训练 均「不支持」这四种类型,第 29 行再声明 Kirin X90/9030 也「不支持」这四种类型。
受影响契约:README 的「参数说明」dtype 列表 ∪「产品支持情况」表(第 5-14 行共 8 个产品)共同决定该算子实际可用的 dtype。
失败模式:README 第 5-14 行的 8 个产品已被第 28-29 行全部覆盖,且每一行都把这 4 种类型划为不支持,因此按文档自身逻辑,FLOAT4_E2M1/FLOAT4_E1M2/HIFLOAT4/HIFLOAT4_SCALE 在所有受支持产品上都不可用,第 24 行把它们列为「支持」即自相矛盾。用户若据第 24 行在 950 系列上构造 FLOAT4/HIFLOAT4 输入调用算子,会直接命中 dtype 校验失败(aclnnPermute 返回 ACLNN_ERR_PARAM_INVALID 161002)或 tiling 侧不支持分支。另外 HIFLOAT4 系列通常正是 950 系列的低精度格式,把 950PR&950DT 整体列入不支持清单也值得复核。
建议:确认 FLOAT4_E2M1/FLOAT4_E1M2/HIFLOAT4/HIFLOAT4_SCALE 的真实产品支持范围:若有产品支持(如 Ascend 950 系列),从第 28 行的排除清单中移除并保持第 24 行不变;若均不支持,从第 24 行 dtype 列表中删除这 4 种类型。同步修改 README_en.md。