Merged
fix(circular_pad): 统一2d/3d为单一GEIR算子,加固负padding与索引位宽处理 #6780
wuyanAdd on 19 days ago
fix(circular_pad): 统一2d/3d为单一GEIR算子,加固负padding与索引位宽处理 #6780
Merged
wuyanAdd on 19 days ago
Total: 18 files changed+313-213
@@ -16,4 +16,5 @@ set(SUPPORT_TILING_DIR "arch22" "arch22" "arch22" "arch22" "arch35" "arch35" "ar
16add_all_modules_sources(OPTYPE circular_pad ACLNNTYPE aclnn_exclude16add_all_modules_sources(OPTYPE circular_pad ACLNNTYPE aclnn_exclude
17 COMPUTE_UNIT ${SUPPORT_COMPUTE_UNIT}17 COMPUTE_UNIT ${SUPPORT_COMPUTE_UNIT}
18 TILING_DIR ${SUPPORT_TILING_DIR}18 TILING_DIR ${SUPPORT_TILING_DIR}
19- DISABLE_IN_OPP TRUE)19+ DISABLE_IN_OPP TRUE
20+ DEPENDENCIES pad_v3)
@@ -15,14 +15,12 @@
15 15 
16## 功能说明16## 功能说明
17 17 
18-- 算子功能:使用循环填充方式对输入张量进行填充操作。18+- 算子功能:使用循环填充方式对输入张量进行填充操作。本算子为单一GEIR算子,通过paddings长度区分2d/3d模式。
19- CircularPad2d:对输入张量的最后两维进行循环填充。19- CircularPad2d:对输入张量的最后两维进行循环填充。
20- CircularPad3d:对输入张量的最后三维进行循环填充。20- CircularPad3d:对输入张量的最后三维进行循环填充。
21 21 
22## 参数说明22## 参数说明
23 23 
24-### CircularPad2d
25- 
26<table style="table-layout: fixed; width: 974px"><colgroup>24<table style="table-layout: fixed; width: 974px"><colgroup>
27<col style="width: 139px">25<col style="width: 139px">
28<col style="width: 146px">26<col style="width: 146px">
@@ -33,72 +31,30 @@
33<thead>31<thead>
34 <tr>32 <tr>
35 <th>参数名</th>33 <th>参数名</th>
36- <th>输入/输出/属性</th>34+ <th>输入/输出</th>
37 <th>描述</th>35 <th>描述</th>
38 <th>数据类型</th>36 <th>数据类型</th>
39 <th>数据格式</th>37 <th>数据格式</th>
40 </tr></thead>38 </tr></thead>
41<tbody>39<tbody>
42 <tr>40 <tr>
43- <td>self</td>41+ <td>x</td>
44- <td>输入张量</td>42+ <td>输入</td>
45- <td>待填充的原输入数据,shape支持3-4维。</td>43+ <td>待填充的原输入数据。shape支持3-5维:2d模式填充最后2维,3d模式填充最后3维。</td>
46 <td>FLOAT16、BFLOAT16、FLOAT32、INT8、INT32</td>44 <td>FLOAT16、BFLOAT16、FLOAT32、INT8、INT32</td>
47 <td>ND</td>45 <td>ND</td>
48 </tr>46 </tr>
49 <tr>47 <tr>
50- <td>padding</td>48+ <td>paddings</td>
51- <td>输入数组</td>49+ <td>输入</td>
52- <td>填充维度,长度为4,数值依次代表左右上下需要填充的值。</td>50+ <td>填充配置。长度为4时数值依次代表左右上下需要填充的值(2d模式);长度为6时数值依次代表左右上下前后需要填充的值(3d模式)。</td>
53 <td>INT64</td>51 <td>INT64</td>
54- <td>-</td>
55- </tr>
56- <tr>
57- <td>out</td>
58- <td>输出张量</td>
59- <td>填充后的输出结果,shape支持3-4维。</td>
60- <td>FLOAT16、BFLOAT16、FLOAT32、INT8、INT32</td>
61- <td>ND</td>
62- </tr>
63-</tbody>
64-</table>
65- 
66-### CircularPad3d
67- 
68-<table style="table-layout: fixed; width: 974px"><colgroup>
69-<col style="width: 139px">
70-<col style="width: 146px">
71-<col style="width: 342px">
72-<col style="width: 251px">
73-<col style="width: 96px">
74-</colgroup>
75-<thead>
76- <tr>
77- <th>参数名</th>
78- <th>输入/输出/属性</th>
79- <th>描述</th>
80- <th>数据类型</th>
81- <th>数据格式</th>
82- </tr></thead>
83-<tbody>
84- <tr>
85- <td>self</td>
86- <td>输入张量</td>
87- <td>待填充的原输入数据,shape支持4-5维。</td>
88- <td>FLOAT16、BFLOAT16、FLOAT32、INT8、INT32</td>
89 <td>ND</td>52 <td>ND</td>
90 </tr>53 </tr>
91 <tr>54 <tr>
92- <td>padding</td>55+ <td>y</td>
93- <td>输入数组</td>56+ <td>输出</td>
94- <td>填充维度,长度为6,数值依次代表左右上下前后需要填充的值。</td>57+ <td>填充后的输出结果,维度数与x一致。</td>
95- <td>INT64</td>
96- <td>-</td>
97- </tr>
98- <tr>
99- <td>out</td>
100- <td>输出张量</td>
101- <td>填充后的输出结果,shape支持4-5维。</td>
102 <td>FLOAT16、BFLOAT16、FLOAT32、INT8、INT32</td>58 <td>FLOAT16、BFLOAT16、FLOAT32、INT8、INT32</td>
103 <td>ND</td>59 <td>ND</td>
104 </tr>60 </tr>
@@ -110,16 +66,16 @@
110## 约束说明66## 约束说明
111 67 
112- Ascend 950(Arch35)的 CircularPad 正 padding 可等于校验所用的对应尺寸(图模式为负 padding 裁剪后的有效尺寸,ACLNN 接口为输入维度);超过该尺寸不支持多圈绕回。其他产品以对应版本文档约束为准。68- Ascend 950(Arch35)的 CircularPad 正 padding 可等于校验所用的对应尺寸(图模式为负 padding 裁剪后的有效尺寸,ACLNN 接口为输入维度);超过该尺寸不支持多圈绕回。其他产品以对应版本文档约束为准。
113-- out的最后一维在不同类型下的大小需满足如下约束:69+- y的最后一维在不同类型下的大小需满足如下约束(仅适用于 Atlas A2/A3、Kirin 系列产品;Ascend 950/960/350(Arch35)无此上限约束):
114 - int8:(0, 98304)70 - int8:(0, 98304)
115 - float16/bfloat16:(0, 49152)71 - float16/bfloat16:(0, 49152)
116 - int32/float32:(0, 24576)72 - int32/float32:(0, 24576)
117- 输入和输出的数据类型必须一致。73- 输入和输出的数据类型必须一致。
118-- 支持非连续的Tensor。74+- 2d 模式(paddings 长度 4)要求 x 维度数为 3 或 4;3d 模式(paddings 长度 6)要求 x 维度数为 4 或 5。即 paddings 长度必须等于 2 × 被填充维数(2d 填充末 2 维,3d 填充末 3 维)。
119 75 
120## 调用说明76## 调用说明
121 77 
122| 调用方式 | 样例代码 | 说明 |78| 调用方式 | 样例代码 | 说明 |
123| --------- | ------------------------------------------------------------ | ------------------------------------------------------------ |79| --------- | ------------------------------------------------------------ | ------------------------------------------------------------ |
124-| aclnn接口 | [test_aclnn_circular_pad](./examples/test_aclnn_circular_pad.cpp) | 通过[aclnnCircularPad2d](docs/aclnnCircularPad2d.md), [aclnnCircularPad3d](docs/aclnnCircularPad3d.md)接口方式调用CircularPad2d算子。 |80+| aclnn接口 | [test_aclnn_circular_pad](./examples/test_aclnn_circular_pad.cpp) | 通过[aclnnCircularPad2d](docs/aclnnCircularPad2d.md)、[aclnnCircularPad3d](docs/aclnnCircularPad3d.md)接口调用CircularPad算子。 |
125| 图模式调用 | [test_geir_circular_pad](./examples/test_geir_circular_pad.cpp) | 通过[算子IR](./op_graph/circular_pad_proto.h)构图方式调用CircularPad算子。 |81| 图模式调用 | [test_geir_circular_pad](./examples/test_geir_circular_pad.cpp) | 通过[算子IR](./op_graph/circular_pad_proto.h)构图方式调用CircularPad算子。 |
@@ -100,7 +100,7 @@ aclnnStatus aclnnCircularPad2d(
100 <td>padding(aclIntArray*)</td>100 <td>padding(aclIntArray*)</td>
101 <td>输入</td>101 <td>输入</td>
102 <td>长度为4,数值依次代表左右上下需要填充的值。</td>102 <td>长度为4,数值依次代表左右上下需要填充的值。</td>
103- <td><ul><li>长度为4,数值依次代表左右上下需要填充的值。</li><li>padding前两个数值对应self最后一维,后两个对应倒数第二维。</li><li>Ascend 950(Arch35)上,每侧正padding不超过对应维度大小(允许等于)。其他产品以对应版本约束为准。</li></ul></td>103+ <td><ul><li>长度为4,数值依次代表左右上下需要填充的值。</li><li>padding前两个数值对应self最后一维,后两个对应倒数第二维。</li></ul></td>
104 <td>INT64</td>104 <td>INT64</td>
105 <td>-</td>105 <td>-</td>
106 <td>1</td>106 <td>1</td>
@@ -230,10 +230,18 @@ aclnnStatus aclnnCircularPad2d(
230- 确定性计算:230- 确定性计算:
231 - aclnnCircularPad2d默认确定性实现。231 - aclnnCircularPad2d默认确定性实现。
232 232 
233-- out的最后一维在不同类型下的大小需满足如下约束:233+<!-- npu="950" id7 -->
234-int8:(0, 98176)234+- <term>Ascend 950PR&950DT系列产品</term>:padding可为负:负值表示裁剪,从对应维度边界移除|padding|个元素,裁剪后该维度大小必须大于0;每侧正padding不超过对应维度大小(允许等于)。
235-float16/bfloat16:(0, 49088)235+<!-- end id7 -->
236-int32/float32:(0, 24544)236+<!-- npu="A3,910b" id8 -->
237+- <term>Atlas A3系列产品</term>、<term>Atlas A2系列产品</term>:padding可为负:负值表示裁剪,裁剪后该维度大小必须大于0;每侧正padding不超过对应维度大小(允许等于)。
238+<!-- end id8 -->
239+<!-- npu="A3,910b" id9 -->
240+- <term>Atlas A3系列产品</term>、<term>Atlas A2系列产品</term>:out的最后一维在不同类型下的大小需满足如下上限约束:int8为(0, 98304)、float16/bfloat16为(0, 49152)、int32/float32为(0, 24576)。
241+<!-- end id9 -->
242+<!-- npu="950" id10 -->
243+- <term>Ascend 950PR&950DT系列产品</term>:out的最后一维无此上限约束。
244+<!-- end id10 -->
237 245 
238## 调用示例246## 调用示例
239 247 
@@ -326,7 +334,7 @@ int main() {
326 CHECK_RET(ret == ACL_SUCCESS, return ret);334 CHECK_RET(ret == ACL_SUCCESS, return ret);
327 // 创建padding aclIntArray335 // 创建padding aclIntArray
328 padding = aclCreateIntArray(paddingData.data(), 4);336 padding = aclCreateIntArray(paddingData.data(), 4);
329- CHECK_RET(padding != nullptr, return ret);337+ CHECK_RET(padding != nullptr, LOG_PRINT("aclCreateIntArray failed.\n"); return ACL_ERROR_INTERNAL_ERROR;);
330 // 创建out aclTensor338 // 创建out aclTensor
331 ret = CreateAclTensor(outHostData, outShape, &outDeviceAddr, aclDataType::ACL_FLOAT, &out);339 ret = CreateAclTensor(outHostData, outShape, &outDeviceAddr, aclDataType::ACL_FLOAT, &out);
332 CHECK_RET(ret == ACL_SUCCESS, return ret);340 CHECK_RET(ret == ACL_SUCCESS, return ret);
@@ -110,7 +110,7 @@ aclnnStatus aclnnCircularPad3d(
110 <td>padding(aclIntArray*)</td>110 <td>padding(aclIntArray*)</td>
111 <td>输入</td>111 <td>输入</td>
112 <td>输入中需要填充的维度。</td>112 <td>输入中需要填充的维度。</td>
113- <td><ul><li>数据格式长度为6,数值依次代表左右上下前后需要填充的值。</li><li>padding前两个数值对应self最后一维,中间两个对应倒数第二维,后两个对应倒数第三维。</li><li>Ascend 950(Arch35)上,每侧正padding不超过对应维度大小(允许等于)。其他产品以对应版本约束为准。</li></ul></td>113+ <td><ul><li>数据格式长度为6,数值依次代表左右上下前后需要填充的值。</li><li>padding前两个数值对应self最后一维,中间两个对应倒数第二维,后两个对应倒数第三维。</li></ul></td>
114 <td>INT64</td>114 <td>INT64</td>
115 <td>ND</td>115 <td>ND</td>
116 <td>-</td>116 <td>-</td>
@@ -242,10 +242,18 @@ aclnnStatus aclnnCircularPad3d(
242- 确定性计算:242- 确定性计算:
243 - aclnnCircularPad3d默认确定性实现。243 - aclnnCircularPad3d默认确定性实现。
244 244 
245- - out的最后一维在不同类型下的大小需满足如下约束:245+<!-- npu="950" id7 -->
246- - int8:(0,98176)246+- <term>Ascend 950PR&950DT系列产品</term>:padding可为负:负值表示裁剪,从对应维度边界移除|padding|个元素,裁剪后该维度大小必须大于0;每侧正padding不超过对应维度大小(允许等于)。
247- - float16/bfloat16:(0,9088)247+<!-- end id7 -->
248- - int32/float32:(0,24544)248+<!-- npu="A3,910b" id8 -->
249+- <term>Atlas A3系列产品</term>、<term>Atlas A2系列产品</term>:padding可为负:负值表示裁剪,裁剪后该维度大小必须大于0;每侧正padding不超过对应维度大小(允许等于)。
250+<!-- end id8 -->
251+<!-- npu="A3,910b" id9 -->
252+- <term>Atlas A3系列产品</term>、<term>Atlas A2系列产品</term>:out的最后一维在不同类型下的大小需满足如下上限约束:int8为(0, 98304)、float16/bfloat16为(0, 49152)、int32/float32为(0, 24576)。
253+<!-- end id9 -->
254+<!-- npu="950" id10 -->
255+- <term>Ascend 950PR&950DT系列产品</term>:out的最后一维无此上限约束。
256+<!-- end id10 -->
249 257 
250## 调用示例258## 调用示例
251 259 
@@ -1,17 +1,19 @@
1/**1/**
2- * Copyright (c) 2025 Huawei Technologies Co., Ltd.2+ * Copyright (c) 2025 Huawei Technologies Co., Ltd.
3- * This program is free software, you can redistribute it and/or modify it under the terms and conditions of3+ * 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").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.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,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.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.8+ * See LICENSE in the root of the software repository for the full text of the License.
9- */9+ */
10 10 
11+#include <iostream>
12+#include <memory>
13+#include <type_traits>
14+#include <vector>
11#include "acl/acl.h"15#include "acl/acl.h"
12#include "aclnnop/aclnn_circular_pad2d.h"16#include "aclnnop/aclnn_circular_pad2d.h"
13-#include <cstdio>
14-#include <vector>
15 17 
16#define CHECK_RET(cond, return_expr) \18#define CHECK_RET(cond, return_expr) \
17 do { \19 do { \
@@ -27,36 +29,61 @@
27 29 
28int64_t GetShapeSize(const std::vector<int64_t>& shape)30int64_t GetShapeSize(const std::vector<int64_t>& shape)
29{31{
30- int64_t shape_size = 1;32+ int64_t shapeSize = 1;
31 for (auto i : shape) {33 for (auto i : shape) {
32- shape_size *= i;34+ shapeSize *= i;
33 }35 }
34- return shape_size;36+ return shapeSize;
35}37}
36 38 
37-int Init(int32_t deviceId, aclrtStream* stream)39+// 用函数指针作为 deleter 的 unique_ptr 别名(与 test_aclnn_abs.cpp 风格一致)
40+using StreamPtr = std::unique_ptr<std::remove_pointer<aclrtStream>::type, decltype(&aclrtDestroyStream)>;
41+using DeviceMemPtr = std::unique_ptr<void, decltype(&aclrtFree)>;
42+using TensorPtr = std::unique_ptr<aclTensor, decltype(&aclDestroyTensor)>;
43+using IntArrayPtr = std::unique_ptr<aclIntArray, decltype(&aclDestroyIntArray)>;
44+ 
45+void PrintOutResult(std::vector<int64_t>& shape, DeviceMemPtr& deviceAddr)
38{46{
39- // 固定写法,AscendCL初始化47+ auto size = GetShapeSize(shape);
48+ std::vector<float> resultData(size, 0);
49+ auto ret = aclrtMemcpy(resultData.data(), resultData.size() * sizeof(resultData[0]), deviceAddr.get(),
50+ size * sizeof(resultData[0]), ACL_MEMCPY_DEVICE_TO_HOST);
51+ CHECK_RET(ret == ACL_SUCCESS,
52+ LOG_PRINT("copy result from device to host failed. ERROR: %d.\n[ERROR msg]%s", ret, aclGetRecentErrMsg());
53+ return);
54+ for (int64_t i = 0; i < size; i++) {
55+ LOG_PRINT("result[%ld] is: %f\n", i, resultData[i]);
56+ }
57+}
58+ 
59+int Init(int32_t deviceId, StreamPtr& stream, bool& initialized, bool& deviceSet)
60+{
61+ // 固定写法,初始化
40 auto ret = aclInit(nullptr);62 auto ret = aclInit(nullptr);
41 CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("aclInit failed. ERROR: %d\n", ret); return ret);63 CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("aclInit failed. ERROR: %d\n", ret); return ret);
64+ initialized = true;
42 ret = aclrtSetDevice(deviceId);65 ret = aclrtSetDevice(deviceId);
43 CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("aclrtSetDevice failed. ERROR: %d\n", ret); return ret);66 CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("aclrtSetDevice failed. ERROR: %d\n", ret); return ret);
44- ret = aclrtCreateStream(stream);67+ deviceSet = true;
68+ aclrtStream rawStream = nullptr;
69+ ret = aclrtCreateStream(&rawStream);
45 CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("aclrtCreateStream failed. ERROR: %d\n", ret); return ret);70 CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("aclrtCreateStream failed. ERROR: %d\n", ret); return ret);
71+ stream.reset(rawStream);
46 return 0;72 return 0;
47}73}
48 74 
49template <typename T>75template <typename T>
50-int CreateAclTensor(const std::vector<T>& hostData, const std::vector<int64_t>& shape, void** deviceAddr,76+int CreateAclTensor(const std::vector<T>& hostData, const std::vector<int64_t>& shape, aclDataType dataType,
51- aclDataType dataType, aclTensor** tensor)77+ DeviceMemPtr& deviceAddr, TensorPtr& tensor)
52{78{
53 auto size = GetShapeSize(shape) * sizeof(T);79 auto size = GetShapeSize(shape) * sizeof(T);
54 // 调用aclrtMalloc申请device侧内存80 // 调用aclrtMalloc申请device侧内存
55- auto ret = aclrtMalloc(deviceAddr, size, ACL_MEM_MALLOC_HUGE_FIRST);81+ void* rawDeviceAddr = nullptr;
82+ auto ret = aclrtMalloc(&rawDeviceAddr, size, ACL_MEM_MALLOC_HUGE_FIRST);
56 CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("aclrtMalloc failed. ERROR: %d\n", ret); return ret);83 CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("aclrtMalloc failed. ERROR: %d\n", ret); return ret);
57- 84+ deviceAddr.reset(rawDeviceAddr);
58 // 调用aclrtMemcpy将host侧数据拷贝到device侧内存上85 // 调用aclrtMemcpy将host侧数据拷贝到device侧内存上
59- ret = aclrtMemcpy(*deviceAddr, size, hostData.data(), size, ACL_MEMCPY_HOST_TO_DEVICE);86+ ret = aclrtMemcpy(deviceAddr.get(), size, hostData.data(), size, ACL_MEMCPY_HOST_TO_DEVICE);
60 CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("aclrtMemcpy failed. ERROR: %d\n", ret); return ret);87 CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("aclrtMemcpy failed. ERROR: %d\n", ret); return ret);
61 88 
62 // 计算连续tensor的strides89 // 计算连续tensor的strides
@@ -66,85 +93,92 @@ int CreateAclTensor(const std::vector<T>& hostData, const std::vector<int64_t>&
66 }93 }
67 94 
68 // 调用aclCreateTensor接口创建aclTensor95 // 调用aclCreateTensor接口创建aclTensor
69- *tensor = aclCreateTensor(shape.data(), shape.size(), dataType, strides.data(), 0, aclFormat::ACL_FORMAT_ND,96+ aclTensor* rawTensor = aclCreateTensor(shape.data(), shape.size(), dataType, strides.data(), 0,
70- shape.data(), shape.size(), *deviceAddr);97+ aclFormat::ACL_FORMAT_ND, shape.data(), shape.size(), deviceAddr.get());
98+ CHECK_RET(rawTensor != nullptr, LOG_PRINT("aclCreateTensor failed.\n"); return ACL_ERROR_FAILURE);
99+ tensor.reset(rawTensor);
71 return 0;100 return 0;
72}101}
73 102 
74int main()103int main()
75{104{
76- // 1. 固定写法,device/stream初始化, 参考AscendCL对外接口列表105+ // 1. (固定写法)device/stream初始化,参考acl API文档
77 // 根据自己的实际device填写deviceId106 // 根据自己的实际device填写deviceId
78 int32_t deviceId = 0;107 int32_t deviceId = 0;
79- aclrtStream stream;108+ bool initialized = false;
80- auto ret = Init(deviceId, &stream);109+ bool deviceSet = false;
81- // check根据自己的需要处理110+ // aclInit/aclFinalize 用 shared_ptr 的自定义 deleter 做 RAII 回收
82- CHECK_RET(ret == 0, LOG_PRINT("Init acl failed. ERROR: %d\n", ret); return ret);111+ std::shared_ptr<void> aclGuard(nullptr, [&](void*) {
83- // 2. 构造输入与输出,需要根据API的接口定义构造112+ if (deviceSet) {
113+ aclrtResetDevice(deviceId);
114+ }
115+ if (initialized) {
116+ aclFinalize();
117+ }
118+ });
119+ StreamPtr stream(nullptr, &aclrtDestroyStream);
120+ auto ret = Init(deviceId, stream, initialized, deviceSet);
121+ CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("Init acl failed. ERROR: %d\n", ret); return ret);
122+ 
123+ // 2. 构造输入与输出,需要根据API的接口自定义构造
84 std::vector<int64_t> selfShape = {1, 1, 2, 2};124 std::vector<int64_t> selfShape = {1, 1, 2, 2};
85 std::vector<int64_t> outShape = {1, 1, 4, 4};125 std::vector<int64_t> outShape = {1, 1, 4, 4};
86- void* selfDeviceAddr = nullptr;126+ 
87- void* outDeviceAddr = nullptr;127+ DeviceMemPtr selfDeviceAddr(nullptr, &aclrtFree);
88- aclTensor* self = nullptr;128+ DeviceMemPtr outDeviceAddr(nullptr, &aclrtFree);
89- aclIntArray* padding = nullptr;129+ TensorPtr self(nullptr, &aclDestroyTensor);
90- aclTensor* out = nullptr;130+ TensorPtr out(nullptr, &aclDestroyTensor);
131+ IntArrayPtr padding(nullptr, &aclDestroyIntArray);
91 132 
92 std::vector<float> selfHostData = {1, 2, 3, 4};133 std::vector<float> selfHostData = {1, 2, 3, 4};
93 std::vector<int64_t> paddingData = {1, 1, 1, 1};134 std::vector<int64_t> paddingData = {1, 1, 1, 1};
94 std::vector<float> outHostData = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};135 std::vector<float> outHostData = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
95 136 
96- // 创建self aclTensor137+ ret = CreateAclTensor(selfHostData, selfShape, aclDataType::ACL_FLOAT, selfDeviceAddr, self);
97- ret = CreateAclTensor(selfHostData, selfShape, &selfDeviceAddr, aclDataType::ACL_FLOAT, &self);
98 CHECK_RET(ret == ACL_SUCCESS, return ret);138 CHECK_RET(ret == ACL_SUCCESS, return ret);
99- // 创建padding aclIntArray139+ ret = CreateAclTensor(outHostData, outShape, aclDataType::ACL_FLOAT, outDeviceAddr, out);
100- padding = aclCreateIntArray(paddingData.data(), 4);
101- CHECK_RET(padding != nullptr, return ret);
102- // 创建out aclTensor
103- ret = CreateAclTensor(outHostData, outShape, &outDeviceAddr, aclDataType::ACL_FLOAT, &out);
104 CHECK_RET(ret == ACL_SUCCESS, return ret);140 CHECK_RET(ret == ACL_SUCCESS, return ret);
105 141 
106- // 3. 调用CANN算子库API,需要修改为具体的API142+ // 创建 padding aclIntArray
143+ aclIntArray* rawPadding = aclCreateIntArray(paddingData.data(), paddingData.size());
144+ CHECK_RET(rawPadding != nullptr, LOG_PRINT("aclCreateIntArray failed.\n"); return ACL_ERROR_FAILURE);
145+ padding.reset(rawPadding);
146+ 
147+ // 3. 调用CANN算子库API,需要修改为具体的Api名称
107 uint64_t workspaceSize = 0;148 uint64_t workspaceSize = 0;
108 aclOpExecutor* executor;149 aclOpExecutor* executor;
150+ 
109 // 调用aclnnCircularPad2d第一段接口151 // 调用aclnnCircularPad2d第一段接口
110- ret = aclnnCircularPad2dGetWorkspaceSize(self, padding, out, &workspaceSize, &executor);152+ ret = aclnnCircularPad2dGetWorkspaceSize(self.get(), padding.get(), out.get(), &workspaceSize, &executor);
111- CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("aclnnCircularPad2dGetWorkspaceSize failed. ERROR: %d\n", ret); return ret);153+ CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("aclnnCircularPad2dGetWorkspaceSize failed. ERROR: %d.\n[ERROR msg]%s", ret,
154+ aclGetRecentErrMsg());
155+ return ret);
156+ 
112 // 根据第一段接口计算出的workspaceSize申请device内存157 // 根据第一段接口计算出的workspaceSize申请device内存
113- void* workspaceAddr = nullptr;158+ DeviceMemPtr workspaceAddr(nullptr, &aclrtFree);
114- if (workspaceSize > 0) {159+ if (workspaceSize > static_cast<uint64_t>(0)) {
115- ret = aclrtMalloc(&workspaceAddr, workspaceSize, ACL_MEM_MALLOC_HUGE_FIRST);160+ void* rawWorkspaceAddr = nullptr;
116- CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("allocate workspace failed. ERROR: %d\n", ret); return ret;);161+ ret = aclrtMalloc(&rawWorkspaceAddr, workspaceSize, ACL_MEM_MALLOC_HUGE_FIRST);
162+ CHECK_RET(ret == ACL_SUCCESS,
163+ LOG_PRINT("allocate workspace failed. ERROR: %d.\n[ERROR msg]%s", ret, aclGetRecentErrMsg());
164+ return ret);
165+ workspaceAddr.reset(rawWorkspaceAddr);
117 }166 }
167+ 
118 // 调用aclnnCircularPad2d第二段接口168 // 调用aclnnCircularPad2d第二段接口
119- ret = aclnnCircularPad2d(workspaceAddr, workspaceSize, executor, stream);169+ ret = aclnnCircularPad2d(workspaceAddr.get(), workspaceSize, executor, stream.get());
120- CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("aclnnCircularPad2d failed. ERROR: %d\n", ret); return ret);170+ CHECK_RET(ret == ACL_SUCCESS,
121- // 4. 固定写法,同步等待任务执行结束171+ LOG_PRINT("aclnnCircularPad2d failed. ERROR: %d.\n[ERROR msg]%s", ret, aclGetRecentErrMsg());
122- ret = aclrtSynchronizeStream(stream);172+ return ret);
123- CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("aclrtSynchronizeStream failed. ERROR: %d\n", ret); return ret);
124- // 5. 获取输出的值,将device侧内存上的结果拷贝至host侧,需要根据具体API的接口定义修改
125- auto size = GetShapeSize(outShape);
126- std::vector<float> resultData(size, 0);
127- ret = aclrtMemcpy(resultData.data(), resultData.size() * sizeof(resultData[0]), outDeviceAddr, size * sizeof(float),
128- ACL_MEMCPY_DEVICE_TO_HOST);
129- CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("copy result from device to host failed. ERROR: %d\n", ret); return ret);
130 173 
131- for (int64_t i = 0; i < size; i++) {174+ // 4. (固定写法)同步等待任务执行结束
132- LOG_PRINT("result[%ld] is: %f\n", i, resultData[i]);175+ ret = aclrtSynchronizeStream(stream.get());
133- }176+ CHECK_RET(ret == ACL_SUCCESS,
177+ LOG_PRINT("aclrtSynchronizeStream failed. ERROR: %d.\n[ERROR msg]%s", ret, aclGetRecentErrMsg());
178+ return ret);
134 179 
135- // 6. 释放aclTensor和aclScalar,需要根据具体API的接口定义修改180+ // 5. 获取输出的值,将device侧内存上的结果拷贝至host侧
136- aclDestroyTensor(self);181+ PrintOutResult(outShape, outDeviceAddr);
137- aclDestroyIntArray(padding);
138- aclDestroyTensor(out);
139 182 
140- // 7. 释放device资源,需要根据具体API的接口定义修改
141- aclrtFree(selfDeviceAddr);
142- aclrtFree(outDeviceAddr);
143- if (workspaceSize > 0) {
144- aclrtFree(workspaceAddr);
145- }
146- aclrtDestroyStream(stream);
147- aclrtResetDevice(deviceId);
148- aclFinalize();
149 return 0;183 return 0;
150}184}
@@ -315,6 +315,7 @@ int main()
315 std::string warning_str(warning_msg.GetString());315 std::string warning_str(warning_msg.GetString());
316 std::cout << "Warning message: " << warning_str << std::endl;316 std::cout << "Warning message: " << warning_str << std::endl;
317 printf("%s - INFO - [XIR]: Start to finalize ir graph session\n", GetTime().c_str());317 printf("%s - INFO - [XIR]: Start to finalize ir graph session\n", GetTime().c_str());
318+ delete session;
318 ret = ge::GEFinalize();319 ret = ge::GEFinalize();
319 if (ret != SUCCESS) {320 if (ret != SUCCESS) {
320 printf("%s - ERROR - [XIR]: Finalize ir graph session failed\n", GetTime().c_str());321 printf("%s - ERROR - [XIR]: Finalize ir graph session failed\n", GetTime().c_str());
@@ -26,7 +26,7 @@ extern "C" {
26 * @param [in] self: npu device侧的aclTensor, 数据类型支持BFLOAT16,FLOAT16, FLOAT32,INT8,26 * @param [in] self: npu device侧的aclTensor, 数据类型支持BFLOAT16,FLOAT16, FLOAT32,INT8,
27 * INT32,数据格式支持ND,维度支持三维或四维。27 * INT32,数据格式支持ND,维度支持三维或四维。
28 * @param [in] padding: npu device侧的aclIntArray数组, 数据类型为INT64,长度为4,数值依次代表左右上下需要填充的值。28 * @param [in] padding: npu device侧的aclIntArray数组, 数据类型为INT64,长度为4,数值依次代表左右上下需要填充的值。
29- * 前两个数值需小于self最后一维度的数值,后两个数值需小于self倒数第二维度的数值。29+ * 前两个数值需不超过self最后一维度的数值,后两个数值需不超过self倒数第二维度的数值。
30 * @param [in] out: npu device侧的aclTensor,30 * @param [in] out: npu device侧的aclTensor,
31 * 数据类型、数据格式、维度与self一致,倒数第二维度的数值等于self倒数第二维度的31 * 数据类型、数据格式、维度与self一致,倒数第二维度的数值等于self倒数第二维度的
32 * 数值加padding后两个值,最后一维度的数值等于self最后一维度的数值加padding前两个值。32 * 数值加padding后两个值,最后一维度的数值等于self最后一维度的数值加padding前两个值。
@@ -26,7 +26,7 @@ extern "C" {
26 * @param [in] self: npu device侧的aclTensor, 数据类型支持BFLOAT16,FLOAT16, FLOAT32,INT8,26 * @param [in] self: npu device侧的aclTensor, 数据类型支持BFLOAT16,FLOAT16, FLOAT32,INT8,
27 * INT32,数据格式支持ND,维度支持四维或五维。27 * INT32,数据格式支持ND,维度支持四维或五维。
28 * @param [in] padding: npu device侧的aclIntArray数组, 数据类型为INT64,长度为6,数值依次代表左右上下前后需要填充的值。28 * @param [in] padding: npu device侧的aclIntArray数组, 数据类型为INT64,长度为6,数值依次代表左右上下前后需要填充的值。
29- * 前两个数值需小于self最后一维度的数值,中间两个数值需小于self倒数第二维度的数值,后两个数值需小于self倒数第三维度的数值。29+ * 前两个数值需不超过self最后一维度的数值,中间两个数值需不超过self倒数第二维度的数值,后两个数值需不超过self倒数第三维度的数值。
30 * @param [in] out: npu device侧的aclTensor,30 * @param [in] out: npu device侧的aclTensor,
31 * 数据类型、数据格式、维度与self一致,倒数第三维度的数值等于self倒数第三维度的31 * 数据类型、数据格式、维度与self一致,倒数第三维度的数值等于self倒数第三维度的
32 * 数值加padding后两个值,倒数第二维度的数值等于self倒数第二维度的32 * 数值加padding后两个值,倒数第二维度的数值等于self倒数第二维度的
@@ -100,12 +100,31 @@ static bool CheckShape(const aclTensor* self, const aclIntArray* padding, const
100 expectShape.SetDim(i, self->GetViewShape().GetDim(i));100 expectShape.SetDim(i, self->GetViewShape().GetDim(i));
101 }101 }
102 }102 }
103- // 通用循环处理所有padding维度的shape计算(安全求和:防溢出及每侧负向越界)103+ // 通用循环处理所有padding维度的shape计算(安全求和:防溢出及每侧负向越界 + 裁空 + 多圈绕回)
104 for (size_t k = 0; k < paddingDim; k++) {104 for (size_t k = 0; k < paddingDim; k++) {
105 int64_t expectDim;105 int64_t expectDim;
106+ int64_t dim = self->GetViewShape().GetDim(selfDimnum - 1 - k);
107+ int64_t padFront = (*padding)[k * 2];
108+ int64_t padBack = (*padding)[k * 2 + 1];
109+ // 负 padding 后有效尺寸必须 > 0(裁剪不能裁空)
110+ int64_t inSize = dim + (padFront < 0 ? padFront : 0) + (padBack < 0 ? padBack : 0);
106 OP_CHECK(111 OP_CHECK(
107- SafePadSum(self->GetViewShape().GetDim(selfDimnum - 1 - k), (*padding)[k * 2], (*padding)[k * 2 + 1],112+ inSize > 0,
108- expectDim),113+ OP_LOGE(ACLNN_ERR_PARAM_INVALID,
114+ "The effective size after negative padding must be greater than 0, input %lld, padding %lld, %lld.",
115+ static_cast<long long>(dim), static_cast<long long>(padFront), static_cast<long long>(padBack)),
116+ return false);
117+ // 正 padding 不超过裁剪后有效尺寸(多圈绕回拒绝)
118+ OP_CHECK(
119+ !(padFront > 0 && padFront > inSize) && !(padBack > 0 && padBack > inSize),
120+ OP_LOGE(ACLNN_ERR_PARAM_INVALID,
121+ "The positive padding must not exceed the effective input size %lld (input %lld, padding %lld, "
122+ "%lld).",
123+ static_cast<long long>(inSize), static_cast<long long>(dim), static_cast<long long>(padFront),
124+ static_cast<long long>(padBack)),
125+ return false);
126+ OP_CHECK(
127+ SafePadSum(dim, padFront, padBack, expectDim),
109 OP_LOGE(ACLNN_ERR_PARAM_INVALID,128 OP_LOGE(ACLNN_ERR_PARAM_INVALID,
110 "The input size plus padding resulted in a negative or overflow output size, which is invalid."),129 "The input size plus padding resulted in a negative or overflow output size, which is invalid."),
111 return false);130 return false);
@@ -19,30 +19,30 @@
19#include "graph/operator.h"19#include "graph/operator.h"
20namespace ge {20namespace ge {
21/**21/**
22-* @brief Pads the input tensor using circular padding of the input boundary.22+ * @brief Pads the input tensor using circular padding of the input boundary.
23-* Tensor values at the beginning of the dimension are used to pad the end,23+ * Tensor values at the beginning of the dimension are used to pad the end,
24-* and values at the end are used to pad the beginning.24+ * and values at the end are used to pad the beginning.
25-* If negative padding is applied then the ends of the tensor get removed.25+ * If negative padding is applied then the ends of the tensor get removed.
26-*26+ *
27-* @par Inputs:27+ * @par Inputs:
28-* @li x: A tensor, input tensor.28+ * @li x: A tensor, input tensor.
29-* @li paddings: A tensor, the size of the padding.29+ * @li paddings: A tensor, the size of the padding.
30-*30+ *
31-* @par Outputs:31+ * @par Outputs:
32-* y: A tensor, output tensor.32+ * y: A tensor, output tensor.
33-*33+ *
34-* @par Third-party framework compatibility34+ * @par Third-party framework compatibility
35-* Compatible with the PyTorch operator CircularPad2d and CircularPad3d.35+ * Compatible with the PyTorch operator CircularPad2d and CircularPad3d.
36-*36+ *
37-* @platform: KirinX90, Kirin903037+ * @platform: Ascend910B, Ascend910_93, KirinX90, Kirin9030, Ascend950, Ascend960DT, Ascend960PR, Ascend350
38-*38+ *
39-*/39+ */
40REG_OP(CircularPad)40REG_OP(CircularPad)
41 .INPUT(x, TensorType({DT_INT8, DT_FLOAT16, DT_BF16, DT_FLOAT, DT_INT32}))41 .INPUT(x, TensorType({DT_INT8, DT_FLOAT16, DT_BF16, DT_FLOAT, DT_INT32}))
42 .INPUT(paddings, TensorType({DT_INT64}))42 .INPUT(paddings, TensorType({DT_INT64}))
43 .OUTPUT(y, TensorType({DT_INT8, DT_FLOAT16, DT_BF16, DT_FLOAT, DT_INT32}))43 .OUTPUT(y, TensorType({DT_INT8, DT_FLOAT16, DT_BF16, DT_FLOAT, DT_INT32}))
44 .OP_END_FACTORY_REG(CircularPad)44 .OP_END_FACTORY_REG(CircularPad)
45 45 
46-} // namespace ge46+} // namespace ge
47 47 
48-#endif // OP_PROTO_CIRCULAR_PAD_PROTO_H_48+#endif // OP_PROTO_CIRCULAR_PAD_PROTO_H_
@@ -236,8 +236,8 @@ static ge::graphStatus ReadPaddings(gert::TilingContext* context, int64_t& left,
236// 填充 TilingData236// 填充 TilingData
237static void FillTilingData(CircularPadTilingData* tiling, int64_t inputH, int64_t inputW, int64_t inputL,237static void FillTilingData(CircularPadTilingData* tiling, int64_t inputH, int64_t inputW, int64_t inputL,
238 int64_t outputH, int64_t outputW, int64_t outputL, int64_t left, int64_t right, int64_t top,238 int64_t outputH, int64_t outputW, int64_t outputL, int64_t left, int64_t right, int64_t top,
239- int64_t bottom, int64_t front, int64_t back, int64_t totalOutputElements,239+ int64_t bottom, int64_t front, int64_t back, int64_t totalInputElements,
240- int64_t needCoreNum, int64_t availUbBytes)240+ int64_t totalOutputElements, int64_t needCoreNum, int64_t availUbBytes)
241{241{
242 tiling->inputH = inputH;242 tiling->inputH = inputH;
243 tiling->inputW = inputW;243 tiling->inputW = inputW;
@@ -251,6 +251,7 @@ static void FillTilingData(CircularPadTilingData* tiling, int64_t inputH, int64_
251 tiling->bottom = bottom;251 tiling->bottom = bottom;
252 tiling->front = front;252 tiling->front = front;
253 tiling->back = back;253 tiling->back = back;
254+ tiling->totalInputElements = totalInputElements;
254 tiling->totalOutputElements = totalOutputElements;255 tiling->totalOutputElements = totalOutputElements;
255 tiling->needCoreNum = needCoreNum;256 tiling->needCoreNum = needCoreNum;
256 tiling->ubSize = availUbBytes;257 tiling->ubSize = availUbBytes;
@@ -262,16 +263,17 @@ static void DumpTilingData(gert::TilingContext* context, const CircularPadTiling
262 "CircularPadTilingData: inputH=%ld, inputW=%ld, inputL=%ld, "263 "CircularPadTilingData: inputH=%ld, inputW=%ld, inputL=%ld, "
263 "outputH=%ld, outputW=%ld, outputL=%ld, "264 "outputH=%ld, outputW=%ld, outputL=%ld, "
264 "left=%ld, right=%ld, top=%ld, bottom=%ld, front=%ld, back=%ld, "265 "left=%ld, right=%ld, top=%ld, bottom=%ld, front=%ld, back=%ld, "
265- "totalOutputElements=%ld, needCoreNum=%ld, ubSize=%ld",266+ "totalInputElements=%ld, totalOutputElements=%ld, needCoreNum=%ld, ubSize=%ld",
266 tiling->inputH, tiling->inputW, tiling->inputL, tiling->outputH, tiling->outputW, tiling->outputL,267 tiling->inputH, tiling->inputW, tiling->inputL, tiling->outputH, tiling->outputW, tiling->outputL,
267 tiling->left, tiling->right, tiling->top, tiling->bottom, tiling->front, tiling->back,268 tiling->left, tiling->right, tiling->top, tiling->bottom, tiling->front, tiling->back,
268- tiling->totalOutputElements, tiling->needCoreNum, tiling->ubSize);269+ tiling->totalInputElements, tiling->totalOutputElements, tiling->needCoreNum, tiling->ubSize);
269}270}
270 271 
271struct CircularPadParams {272struct CircularPadParams {
272 int64_t left, right, top, bottom, front, back;273 int64_t left, right, top, bottom, front, back;
273 int64_t inputH, inputW, inputL;274 int64_t inputH, inputW, inputL;
274 int64_t outputH, outputW, outputL;275 int64_t outputH, outputW, outputL;
276+ int64_t totalInputElements;
275 int64_t totalOutputElements;277 int64_t totalOutputElements;
276 bool is3D;278 bool is3D;
277};279};
@@ -373,7 +375,8 @@ static ge::graphStatus ReadAndCheckParams(gert::TilingContext* context, [[maybe_
373 return ge::GRAPH_FAILED);375 return ge::GRAPH_FAILED);
374 }376 }
375 // 注: 输出最后一维无上限约束(SIMT kernel 逐元素 GM 访问,行宽不受 UB 限制;377 // 注: 输出最后一维无上限约束(SIMT kernel 逐元素 GM 访问,行宽不受 UB 限制;
376- // 索引类型由 totalOutputElements 自动选择 uint32_t/uint64_t 路径)378+ // 索引位宽按输入/输出总元素数共同选择 uint32_t/uint64_t 路径)
379+ p.totalInputElements = xShape.GetShapeSize();
377 p.totalOutputElements = yShape.GetShapeSize();380 p.totalOutputElements = yShape.GetShapeSize();
378 return ge::GRAPH_SUCCESS;381 return ge::GRAPH_SUCCESS;
379}382}
@@ -413,7 +416,7 @@ static ge::graphStatus CircularPadTilingFunc(gert::TilingContext* context)
413 OP_CHECK_IF(memset_s(tiling, sizeof(CircularPadTilingData), 0, sizeof(CircularPadTilingData)) != EOK,416 OP_CHECK_IF(memset_s(tiling, sizeof(CircularPadTilingData), 0, sizeof(CircularPadTilingData)) != EOK,
414 OP_LOGE(context, "memset_s failed"), return ge::GRAPH_FAILED);417 OP_LOGE(context, "memset_s failed"), return ge::GRAPH_FAILED);
415 FillTilingData(tiling, p.inputH, p.inputW, p.inputL, p.outputH, p.outputW, p.outputL, p.left, p.right, p.top,418 FillTilingData(tiling, p.inputH, p.inputW, p.inputL, p.outputH, p.outputW, p.outputL, p.left, p.right, p.top,
416- p.bottom, p.front, p.back, p.totalOutputElements, needCoreNum, availUbBytes);419+ p.bottom, p.front, p.back, p.totalInputElements, p.totalOutputElements, needCoreNum, availUbBytes);
417 DumpTilingData(context, tiling);420 DumpTilingData(context, tiling);
418 421 
419 OP_CHECK_IF(GetWorkspaceSize(context) != ge::GRAPH_SUCCESS, OP_LOGE(context, "GetWorkspaceSize failed"),422 OP_CHECK_IF(GetWorkspaceSize(context) != ge::GRAPH_SUCCESS, OP_LOGE(context, "GetWorkspaceSize failed"),
@@ -19,6 +19,8 @@
19 * paddings 不可读时,受影响维度置 -1(unknown shape)。19 * paddings 不可读时,受影响维度置 -1(unknown shape)。
20 */20 */
21 21 
22+#include <limits>
23+ 
22#include "register/op_impl_registry.h"24#include "register/op_impl_registry.h"
23#include "log/log.h"25#include "log/log.h"
24#include "util/shape_util.h"26#include "util/shape_util.h"
@@ -31,6 +33,28 @@ static constexpr size_t INPUT_IDX_PADDINGS = 1;
31static constexpr size_t OUTPUT_IDX_Y = 0;33static constexpr size_t OUTPUT_IDX_Y = 0;
32static constexpr int64_t UNKNOWN_DIM = -1;34static constexpr int64_t UNKNOWN_DIM = -1;
33 35 
36+// 安全计算 dimSize + padFront + padBack 并校验有效性:求和会溢出 int64、或任一侧负 padding
37+// 裁剪使对应维度为负时返回 false(避免有符号溢出 UB 及负输出维度)。与 aclnn 入口
38+// op_api/circular_pad_common.h 的 SafePadSum 语义对齐,保证图模式与 aclnn 通路推导一致。
39+static bool SafePadSum(int64_t dimSize, int64_t padFront, int64_t padBack, int64_t& result)
40+{
41+ const int64_t kInt64Max = std::numeric_limits<int64_t>::max();
42+ const int64_t kInt64Min = std::numeric_limits<int64_t>::min();
43+ if ((padFront > 0 && padBack > 0 && padFront > kInt64Max - padBack) ||
44+ (padFront < 0 && padBack < 0 && padFront < kInt64Min - padBack)) {
45+ return false;
46+ }
47+ int64_t padSum = padFront + padBack;
48+ if (padSum > 0 && dimSize > kInt64Max - padSum) {
49+ return false;
50+ }
51+ result = dimSize + padSum;
52+ if ((padFront < 0 && dimSize + padFront < 0) || (padBack < 0 && dimSize + padBack < 0) || result < 0) {
53+ return false;
54+ }
55+ return true;
56+}
57+ 
34static ge::graphStatus InferShape4CircularPad(gert::InferShapeContext* context)58static ge::graphStatus InferShape4CircularPad(gert::InferShapeContext* context)
35{59{
36 OP_LOGD(context->GetNodeName(), "Begin to do InferShape4CircularPad");60 OP_LOGD(context->GetNodeName(), "Begin to do InferShape4CircularPad");
@@ -75,15 +99,24 @@ static ge::graphStatus InferShape4CircularPad(gert::InferShapeContext* context)
75 yShape->SetDim(i, xShape->GetDim(i));99 yShape->SetDim(i, xShape->GetDim(i));
76 }100 }
77 101 
78- // 填充维度:output = input + pad_before + pad_after102+ // 填充维度:output = input + pad_before + pad_after(含 int64 溢出与负裁剪守卫,对齐 aclnn SafePadSum)
79 for (size_t k = 0; k < paddingDim; k++) {103 for (size_t k = 0; k < paddingDim; k++) {
80 size_t dimIdx = xDimNum - 1 - k;104 size_t dimIdx = xDimNum - 1 - k;
81 int64_t xDim = xShape->GetDim(dimIdx);105 int64_t xDim = xShape->GetDim(dimIdx);
82- if (xDim != UNKNOWN_DIM) {106+ if (xDim == UNKNOWN_DIM) {
83- yShape->SetDim(dimIdx, xDim + padValues[k * 2] + padValues[k * 2 + 1]);
84- } else {
85 yShape->SetDim(dimIdx, UNKNOWN_DIM);107 yShape->SetDim(dimIdx, UNKNOWN_DIM);
108+ continue;
86 }109 }
110+ int64_t outDim = 0;
111+ OP_CHECK_IF(!SafePadSum(xDim, padValues[k * 2], padValues[k * 2 + 1], outDim),
L
Lly_cann_coder16 days ago

与canndev的infershape实现对比下,是否存在兼容性问题

likedislike
112+ OP_LOGE_FOR_INVALID_VALUE_WITH_REASON(
113+ context->GetNodeName(), std::to_string(dimIdx).c_str(),
114+ (std::to_string(xDim) + " + " + std::to_string(padValues[k * 2]) + " + " +
115+ std::to_string(padValues[k * 2 + 1]))
116+ .c_str(),
117+ "padded dimension overflows int64 or negative padding exceeds the dimension size"),
118+ return ge::GRAPH_FAILED);
119+ yShape->SetDim(dimIdx, outDim);
87 }120 }
88 } else {121 } else {
89 // 4. paddings 不可读 → 受影响维度置 -1(unknown shape)122 // 4. paddings 不可读 → 受影响维度置 -1(unknown shape)
@@ -550,7 +550,10 @@ __aicore__ inline void ProcessSimt(GM_ADDR x, GM_ADDR y, GM_ADDR workspace, cons
550 LocalTensor<uint64_t> params = ubAlloc.Alloc<uint64_t>(PARAMS_UB_ELEMS);550 LocalTensor<uint64_t> params = ubAlloc.Alloc<uint64_t>(PARAMS_UB_ELEMS);
551 const uint64_t yAlign = reinterpret_cast<uint64_t>(y) & (VEC_ALIGN_BYTES - 1);551 const uint64_t yAlign = reinterpret_cast<uint64_t>(y) & (VEC_ALIGN_BYTES - 1);
552 const uint64_t xAlign = reinterpret_cast<uint64_t>(x) & (VEC_ALIGN_BYTES - 1);552 const uint64_t xAlign = reinterpret_cast<uint64_t>(x) & (VEC_ALIGN_BYTES - 1);
553- if (tilingData->totalOutputElements <= UINT32_INDEX_THRESHOLD) {553+ // 源索引 srcRowStart 按输入张量寻址,上界为 totalInputElements(负 padding 裁剪时输入可大于输出),
554+ // 位宽须同时满足输入与输出,避免 uint32 窄化回绕。
555+ if (tilingData->totalOutputElements <= UINT32_INDEX_THRESHOLD &&
556+ tilingData->totalInputElements <= UINT32_INDEX_THRESHOLD) {
554 ProcessDirect<T, IS_3D, uint32_t>(xGm, yGm, tilingData, d, xAlign, yAlign, params);557 ProcessDirect<T, IS_3D, uint32_t>(xGm, yGm, tilingData, d, xAlign, yAlign, params);
555 } else {558 } else {
556 ProcessDirect<T, IS_3D, uint64_t>(xGm, yGm, tilingData, d, xAlign, yAlign, params);559 ProcessDirect<T, IS_3D, uint64_t>(xGm, yGm, tilingData, d, xAlign, yAlign, params);
@@ -14,25 +14,26 @@
14 * \file circular_pad_tiling_data.h14 * \file circular_pad_tiling_data.h
15 * \brief Tiling data struct for circular_pad operator15 * \brief Tiling data struct for circular_pad operator
16 *16 *
17- * TilingData 定义: 15 个 int64_t 字段17+ * TilingData 定义: 16 个 int64_t 字段
18 */18 */
19 19 
20#ifndef CIRCULAR_PAD_TILING_DATA_H_20#ifndef CIRCULAR_PAD_TILING_DATA_H_
21#define CIRCULAR_PAD_TILING_DATA_H_21#define CIRCULAR_PAD_TILING_DATA_H_
22 22 
23struct CircularPadTilingData {23struct CircularPadTilingData {
24- int64_t inputH = 0; // 输入 H 维度大小24+ int64_t inputH = 0; // 输入 H 维度大小
25- int64_t inputW = 0; // 输入 W 维度大小25+ int64_t inputW = 0; // 输入 W 维度大小
26- int64_t inputL = 0; // 输入 D 维度大小(2D 模式为 0)26+ int64_t inputL = 0; // 输入 D 维度大小(2D 模式为 0)
27- int64_t outputH = 0; // 输出 H 维度大小27+ int64_t outputH = 0; // 输出 H 维度大小
28- int64_t outputW = 0; // 输出 W 维度大小28+ int64_t outputW = 0; // 输出 W 维度大小
29- int64_t outputL = 0; // 输出 D 维度大小(2D 模式为 0)29+ int64_t outputL = 0; // 输出 D 维度大小(2D 模式为 0)
30- int64_t left = 0; // 左填充值30+ int64_t left = 0; // 左填充值
31- int64_t right = 0; // 右填充值31+ int64_t right = 0; // 右填充值
32- int64_t top = 0; // 上填充值32+ int64_t top = 0; // 上填充值
33- int64_t bottom = 0; // 下填充值33+ int64_t bottom = 0; // 下填充值
34- int64_t front = 0; // 前填充值(2D 模式为 0)34+ int64_t front = 0; // 前填充值(2D 模式为 0)
35- int64_t back = 0; // 后填充值(2D 模式为 0)35+ int64_t back = 0; // 后填充值(2D 模式为 0)
36+ int64_t totalInputElements = 0; // 输入总元素数(SIMT 源索引位宽选择,负 padding 裁剪时可能大于输出)
36 int64_t totalOutputElements = 0; // 输出总元素数(Grid-Stride 循环上界)37 int64_t totalOutputElements = 0; // 输出总元素数(Grid-Stride 循环上界)
37 int64_t needCoreNum = 0; // 实际需要的核数38 int64_t needCoreNum = 0; // 实际需要的核数
38 int64_t ubSize = 0; // TPipe 可用 UB 字节数(host 按平台实测下发,已扣 DCache/静态占用)39 int64_t ubSize = 0; // TPipe 可用 UB 字节数(host 按平台实测下发,已扣 DCache/静态占用)
@@ -37,7 +37,28 @@ def _to_pad_tuple(paddings):
37 37 
38 38 
39def _torch_compute(x_torch, pad):39def _torch_compute(x_torch, pad):
40- return F.pad(x_torch, pad, mode="circular")40+ pad = tuple(int(p) for p in pad)
41+ if all(p >= 0 for p in pad):
42+ return F.pad(x_torch, pad, mode="circular")
43+ 
44+ # 负 padding 裁剪语义:F.pad 的 circular 模式禁止负 padding,此处先按负值裁剪两端,
45+ # 再对非负值做 circular 填充(与算子 CheckPadPair 语义一致:负值裁剪、正值绕回)。
46+ ndim = x_torch.dim()
47+ n_pairs = len(pad) // 2
48+ slices = [slice(None)] * ndim
49+ for i in range(n_pairs):
50+ pad_l, pad_r = pad[2 * i], pad[2 * i + 1]
51+ axis = ndim - 1 - i
52+ size = x_torch.shape[axis]
53+ start = -pad_l if pad_l < 0 else 0
54+ end = size + pad_r if pad_r < 0 else size
55+ slices[axis] = slice(start, end)
56+ x_cropped = x_torch[tuple(slices)]
57+ 
58+ pos_pad = [(p if p > 0 else 0) for p in pad]
59+ if any(p > 0 for p in pos_pad):
60+ return F.pad(x_cropped, tuple(pos_pad), mode="circular")
61+ return x_cropped
41 62 
42 63 
43class CircularPadKernelSpec:64class CircularPadKernelSpec:
@@ -69,9 +90,9 @@ class CircularPadKernelSpec:
69 90 
70 third_party = {"torch": ThirdPartyImpl}91 third_party = {"torch": ThirdPartyImpl}
71 tolerance = {92 tolerance = {
72- "float32": {"standard": "cross_check", "level": "L1"},93+ "float32": {"standard": "binary_equal"},
73- "float16": {"standard": "cross_check", "level": "L1"},94+ "float16": {"standard": "binary_equal"},
74- "bfloat16": {"standard": "cross_check", "level": "L1"},95+ "bfloat16": {"standard": "binary_equal"},
75 "int32": {"standard": "binary_equal"},96 "int32": {"standard": "binary_equal"},
76 "int8": {"standard": "binary_equal"},97 "int8": {"standard": "binary_equal"},
77 }98 }
@@ -84,9 +105,9 @@ class AclnnCircularPad2dSpec:
84 105 
85 third_party = {"torch": CircularPadKernelSpec.ThirdPartyImpl}106 third_party = {"torch": CircularPadKernelSpec.ThirdPartyImpl}
86 tolerance = {107 tolerance = {
87- "float32": {"standard": "cross_check", "level": "L1"},108+ "float32": {"standard": "binary_equal"},
88- "float16": {"standard": "cross_check", "level": "L1"},109+ "float16": {"standard": "binary_equal"},
89- "bfloat16": {"standard": "cross_check", "level": "L1"},110+ "bfloat16": {"standard": "binary_equal"},
90 "int32": {"standard": "binary_equal"},111 "int32": {"standard": "binary_equal"},
91 "int8": {"standard": "binary_equal"},112 "int8": {"standard": "binary_equal"},
92 }113 }
@@ -99,9 +120,9 @@ class AclnnCircularPad3dSpec:
99 120 
100 third_party = {"torch": CircularPadKernelSpec.ThirdPartyImpl}121 third_party = {"torch": CircularPadKernelSpec.ThirdPartyImpl}
101 tolerance = {122 tolerance = {
102- "float32": {"standard": "cross_check", "level": "L1"},123+ "float32": {"standard": "binary_equal"},
103- "float16": {"standard": "cross_check", "level": "L1"},124+ "float16": {"standard": "binary_equal"},
104- "bfloat16": {"standard": "cross_check", "level": "L1"},125+ "bfloat16": {"standard": "binary_equal"},
105 "int32": {"standard": "binary_equal"},126 "int32": {"standard": "binary_equal"},
106 "int8": {"standard": "binary_equal"},127 "int8": {"standard": "binary_equal"},
107 }128 }
@@ -0,0 +1,6 @@
1+testcase_name,api_name,tensor_view_shapes,tensor_dtypes,tensor_formats,scalar_dtypes,attributes,output_tensor_indexes,precision_tolerances,absolute_precision,input_data_ranges,scalar_data_ranges,remark
2+aclnnCircularPad2d_L0_001,aclnnCircularPad2d,"((80,22,85,41,),(80,22,182,76,),)","('float16','float16',)","('ND','ND',)",,"{""padding"":[11,24,57,40]}","(1,)",,,"((-1,1,),)",,
3+aclnnCircularPad2d_L0_002,aclnnCircularPad2d,"((92,238,266,),(92,434,496,),)","('bfloat16','bfloat16',)","('ND','ND',)",,"{""padding"":[14,216,150,46]}","(1,)",,,"((-100,100,),)",,
4+aclnnCircularPad2d_L0_003,aclnnCircularPad2d,"((177884,10,10,),(177884,17,19,),)","('float32','float32',)","('ND','ND',)",,"{""padding"":[9,0,3,4]}","(1,)",,,"((-1000,-10,),)",,
5+aclnnCircularPad2d_L0_004,aclnnCircularPad2d,"((2,23242428,2,),(2,51040443,3,),)","('int8','int8',)","('ND','ND',)",,"{""padding"":[0,1,16192753,11605262]}","(1,)",,,"((-10,-2,),)",,
6+aclnnCircularPad2d_L0_005,aclnnCircularPad2d,"((5,3,2,),(5,5,4,),)","('int32','int32',)","('ND','ND',)",,"{""padding"":[2,0,1,1]}","(1,)",,,"((-2147483648,2147483647,),)",,
@@ -0,0 +1,6 @@
1+testcase_name,network_name,op_name,input_shapes,input_dtypes,input_formats,output_shapes,output_dtypes,output_formats,input_ori_shapes,input_ori_formats,output_ori_shapes,output_ori_formats,attributes,input_data_ranges,precision_tolerances,absolute_precision,output_inplace_indexes,output_shape_unknown_indexes,is_enabled,remark,soc_series,priority,dump_file_prefix,manual_input_binaries,manual_golden_binaries
2+CircularPad_L0_001,UNKNOWN,CircularPad,"((25,2,10,5342,),(4,),)","('int8','int64',)","('ND','ND',)","((25,2,28,9973,),)","('int8',)","('ND',)","((25,2,10,5342,),(4,),)","('ND','ND',)","((25,2,28,9973,),)","('ND',)","{'paddings':[3192,1439,10,8]}","((-10,10,),(0,1,),)","((0,0),)",0.0,(),(),True,,,0,,(),()
3+CircularPad_L0_002,UNKNOWN,CircularPad,"((2,2,14763918,),(4,),)","('float16','int64',)","('ND','ND',)","((2,2,35271400,),)","('float16',)","('ND',)","((2,2,14763918,),(4,),)","('ND','ND',)","((2,2,35271400,),)","('ND',)","{'paddings':[7996138,12511344,-1,1]}","((6.097555160522461e-05,6.097555160522461e-05,),(0,1,),)",,1e-08,(),(),True,,,0,,(),()
4+CircularPad_L0_003,UNKNOWN,CircularPad,"((2,8828,4,2,271,),(6,),)","('bfloat16','int64',)","('ND','ND',)","((2,8828,9,2,97,),)","('bfloat16',)","('ND',)","((2,8828,4,2,271,),(6,),)","('ND','ND',)","((2,8828,9,2,97,),)","('ND',)","{'paddings':[-66,-108,1,-1,1,4]}","((10,1000,),(0,1,),)",,1e-08,(),(),True,,,0,,(),()
5+CircularPad_L0_004,UNKNOWN,CircularPad,"((1300,6505,2,),(4,),)","('float32','int64',)","('ND','ND',)","((1300,5235,2,),)","('float32',)","('ND',)","((1300,6505,2,),(4,),)","('ND','ND',)","((1300,5235,2,),)","('ND',)","{'paddings':[1,-1,-1648,378]}","((3.4028235e38,3.4028235e38,),(0,1,),)",,1e-08,(),(),True,,,0,,(),()
6+CircularPad_L0_005,UNKNOWN,CircularPad,"((6,14354660,1,),(6,),)","('int32','int64',)","('ND','ND',)","((7,28379307,1,),)","('int32',)","('ND',)","((6,14354660,1,),(6,),)","('ND','ND',)","((7,28379307,1,),)","('ND',)","{'paddings':[0,0,126568,13898079,3,-2]}","((-2147483648,-2147483648,),(0,1,),)","((0,0),)",0.0,(),(),True,,,0,,(),()
@@ -49,7 +49,7 @@ TEST_F(CircularPadTiling, circular_pad_2d_fp32)
49 262144, // the ubsize obtained in the tiling phase49 262144, // the ubsize obtained in the tiling phase
50 4096); // specifies the maximum size of the tiling data in the tiling phase50 4096); // specifies the maximum size of the tiling data in the tiling phase
51 uint64_t expectTilingKey = 4; // VF 旁路(小输出): schMode=2D | IsSimt=151 uint64_t expectTilingKey = 4; // VF 旁路(小输出): schMode=2D | IsSimt=1
52- string expectTilingData = "4 8 0 6 10 0 1 1 1 1 0 0 120 1 229376 ";52+ string expectTilingData = "4 8 0 6 10 0 1 1 1 1 0 0 64 120 1 229376 ";
53 TilingInfo tilingInfo;53 TilingInfo tilingInfo;
54 EXPECT_TRUE(ExecuteTiling(tilingContextPara, tilingInfo));54 EXPECT_TRUE(ExecuteTiling(tilingContextPara, tilingInfo));
55 EXPECT_EQ(tilingInfo.tilingKey, expectTilingKey);55 EXPECT_EQ(tilingInfo.tilingKey, expectTilingKey);
@@ -81,7 +81,7 @@ TEST_F(CircularPadTiling, circular_pad_2d_fp16)
81 },81 },
82 &compileInfo, 64, 262144, 4096);82 &compileInfo, 64, 262144, 4096);
83 uint64_t expectTilingKey = 4; // VF 旁路(小输出): schMode=2D | IsSimt=183 uint64_t expectTilingKey = 4; // VF 旁路(小输出): schMode=2D | IsSimt=1
84- string expectTilingData = "8 16 0 11 21 0 2 3 1 2 0 0 231 1 229376 ";84+ string expectTilingData = "8 16 0 11 21 0 2 3 1 2 0 0 128 231 1 229376 ";
85 TilingInfo tilingInfo;85 TilingInfo tilingInfo;
86 EXPECT_TRUE(ExecuteTiling(tilingContextPara, tilingInfo));86 EXPECT_TRUE(ExecuteTiling(tilingContextPara, tilingInfo));
87 EXPECT_EQ(tilingInfo.tilingKey, expectTilingKey);87 EXPECT_EQ(tilingInfo.tilingKey, expectTilingKey);
@@ -113,7 +113,7 @@ TEST_F(CircularPadTiling, circular_pad_3d_fp32)
113 },113 },
114 &compileInfo, 64, 262144, 4096);114 &compileInfo, 64, 262144, 4096);
115 uint64_t expectTilingKey = 5; // VF 旁路(小输出): schMode=3D | IsSimt=1115 uint64_t expectTilingKey = 5; // VF 旁路(小输出): schMode=3D | IsSimt=1
116- string expectTilingData = "8 16 4 10 18 6 1 1 1 1 1 1 1080 2 229376 ";116+ string expectTilingData = "8 16 4 10 18 6 1 1 1 1 1 1 512 1080 2 229376 ";
117 TilingInfo tilingInfo;117 TilingInfo tilingInfo;
118 EXPECT_TRUE(ExecuteTiling(tilingContextPara, tilingInfo));118 EXPECT_TRUE(ExecuteTiling(tilingContextPara, tilingInfo));
119 EXPECT_EQ(tilingInfo.tilingKey, expectTilingKey);119 EXPECT_EQ(tilingInfo.tilingKey, expectTilingKey);
@@ -145,7 +145,7 @@ TEST_F(CircularPadTiling, circular_pad_2d_int8)
145 },145 },
146 &compileInfo, 64, 262144, 4096);146 &compileInfo, 64, 262144, 4096);
147 uint64_t expectTilingKey = 4; // VF 旁路(小输出): schMode=2D | IsSimt=1147 uint64_t expectTilingKey = 4; // VF 旁路(小输出): schMode=2D | IsSimt=1
148- string expectTilingData = "4 8 0 6 8 0 0 0 1 1 0 0 96 1 229376 ";148+ string expectTilingData = "4 8 0 6 8 0 0 0 1 1 0 0 64 96 1 229376 ";
149 TilingInfo tilingInfo;149 TilingInfo tilingInfo;
150 EXPECT_TRUE(ExecuteTiling(tilingContextPara, tilingInfo));150 EXPECT_TRUE(ExecuteTiling(tilingContextPara, tilingInfo));
151 EXPECT_EQ(tilingInfo.tilingKey, expectTilingKey);151 EXPECT_EQ(tilingInfo.tilingKey, expectTilingKey);
@@ -177,7 +177,7 @@ TEST_F(CircularPadTiling, circular_pad_3d_bf16_neg_pad)
177 },177 },
178 &compileInfo, 64, 262144, 4096);178 &compileInfo, 64, 262144, 4096);
179 uint64_t expectTilingKey = 5; // VF 旁路(小输出): schMode=3D | IsSimt=1179 uint64_t expectTilingKey = 5; // VF 旁路(小输出): schMode=3D | IsSimt=1
180- string expectTilingData = "4 8 3 6 8 3 -1 1 1 1 0 0 144 1 229376 ";180+ string expectTilingData = "4 8 3 6 8 3 -1 1 1 1 0 0 96 144 1 229376 ";
181 TilingInfo tilingInfo;181 TilingInfo tilingInfo;
182 EXPECT_TRUE(ExecuteTiling(tilingContextPara, tilingInfo));182 EXPECT_TRUE(ExecuteTiling(tilingContextPara, tilingInfo));
183 EXPECT_EQ(tilingInfo.tilingKey, expectTilingKey);183 EXPECT_EQ(tilingInfo.tilingKey, expectTilingKey);
@@ -209,7 +209,7 @@ TEST_F(CircularPadTiling, circular_pad_2d_int32)
209 },209 },
210 &compileInfo, 64, 262144, 4096);210 &compileInfo, 64, 262144, 4096);
211 uint64_t expectTilingKey = 4; // VF 旁路(小输出): schMode=2D | IsSimt=1211 uint64_t expectTilingKey = 4; // VF 旁路(小输出): schMode=2D | IsSimt=1
212- string expectTilingData = "4 16 0 6 20 0 2 2 1 1 0 0 120 1 229376 ";212+ string expectTilingData = "4 16 0 6 20 0 2 2 1 1 0 0 64 120 1 229376 ";
213 TilingInfo tilingInfo;213 TilingInfo tilingInfo;
214 EXPECT_TRUE(ExecuteTiling(tilingContextPara, tilingInfo));214 EXPECT_TRUE(ExecuteTiling(tilingContextPara, tilingInfo));
215 EXPECT_EQ(tilingInfo.tilingKey, expectTilingKey);215 EXPECT_EQ(tilingInfo.tilingKey, expectTilingKey);
@@ -242,7 +242,7 @@ TEST_F(CircularPadTiling, circular_pad_2d_fp32_mte)
242 },242 },
243 &compileInfo, 64, 262144, 4096);243 &compileInfo, 64, 262144, 4096);
244 uint64_t expectTilingKey = 0; // MTE 主路径: schMode=2D | IsSimt=0244 uint64_t expectTilingKey = 0; // MTE 主路径: schMode=2D | IsSimt=0
245- string expectTilingData = "128 256 0 130 258 0 1 1 1 1 0 0 67080 64 229376 ";245+ string expectTilingData = "128 256 0 130 258 0 1 1 1 1 0 0 65536 67080 64 229376 ";
246 TilingInfo tilingInfo;246 TilingInfo tilingInfo;
247 EXPECT_TRUE(ExecuteTiling(tilingContextPara, tilingInfo));247 EXPECT_TRUE(ExecuteTiling(tilingContextPara, tilingInfo));
248 EXPECT_EQ(tilingInfo.tilingKey, expectTilingKey);248 EXPECT_EQ(tilingInfo.tilingKey, expectTilingKey);
@@ -275,7 +275,7 @@ TEST_F(CircularPadTiling, circular_pad_3d_fp16_mte)
275 },275 },
276 &compileInfo, 64, 262144, 4096);276 &compileInfo, 64, 262144, 4096);
277 uint64_t expectTilingKey = 1; // MTE 主路径: schMode=3D | IsSimt=0277 uint64_t expectTilingKey = 1; // MTE 主路径: schMode=3D | IsSimt=0
278- string expectTilingData = "128 256 4 130 258 6 1 1 1 1 1 1 201240 64 229376 ";278+ string expectTilingData = "128 256 4 130 258 6 1 1 1 1 1 1 131072 201240 64 229376 ";
279 TilingInfo tilingInfo;279 TilingInfo tilingInfo;
280 EXPECT_TRUE(ExecuteTiling(tilingContextPara, tilingInfo));280 EXPECT_TRUE(ExecuteTiling(tilingContextPara, tilingInfo));
281 EXPECT_EQ(tilingInfo.tilingKey, expectTilingKey);281 EXPECT_EQ(tilingInfo.tilingKey, expectTilingKey);
@@ -308,7 +308,7 @@ TEST_F(CircularPadTiling, circular_pad_2d_fp16_large_output_narrow_row)
308 },308 },
309 &compileInfo, 64, 262144, 4096);309 &compileInfo, 64, 262144, 4096);
310 uint64_t expectTilingKey = 4; // VF 旁路(窄行): schMode=2D | IsSimt=1310 uint64_t expectTilingKey = 4; // VF 旁路(窄行): schMode=2D | IsSimt=1
311- string expectTilingData = "8 8 0 12 8 0 0 0 2 2 0 0 98304 64 229376 ";311+ string expectTilingData = "8 8 0 12 8 0 0 0 2 2 0 0 65536 98304 64 229376 ";
312 TilingInfo tilingInfo;312 TilingInfo tilingInfo;
313 EXPECT_TRUE(ExecuteTiling(tilingContextPara, tilingInfo));313 EXPECT_TRUE(ExecuteTiling(tilingContextPara, tilingInfo));
314 EXPECT_EQ(tilingInfo.tilingKey, expectTilingKey);314 EXPECT_EQ(tilingInfo.tilingKey, expectTilingKey);