已合并
sortwithindex算子UT用例补齐 #3538
cy_hw创建于 6月25日
sortwithindex算子UT用例补齐 #3538
已合并
共 1 个文件变更+302-3
| @@ -10,7 +10,7 @@ | |||
| 10 | 10 | ||
| 11 | /*! | 11 | /*! |
| 12 | * \file test_sort_with_index_tiling_arch35.cpp | 12 | * \file test_sort_with_index_tiling_arch35.cpp |
| 13 | - * \brief | 13 | + * \brief SortWithIndex算子arch35架构Tiling测试用例 |
| 14 | */ | 14 | */ |
| 15 | 15 | ||
| 16 | 16 | ||
| @@ -34,7 +34,171 @@ protected: | |||
| 34 | } | 34 | } |
| 35 | }; | 35 | }; |
| 36 | 36 | ||
| 37 | -TEST_F(SortWithIndexTilingTest, test_tiling_int32) { | 37 | +/** |
| 38 | + * 测试用例:FLOAT16小规模归并排序 | ||
| 39 | + * | ||
| 40 | + * 测试目的:验证FLOAT16数据类型在排序轴长度<=512时触发SMALL_SIZE_OPTIM_MODE归并排序模式 | ||
| 41 | + * | ||
| 42 | + * 数据类型:DT_FLOAT16 (tilingKey基数=3002) | ||
| 43 | + * | ||
| 44 | + * 输入形状:[4, 128] - 4行数据,每行128个元素需要排序 | ||
| 45 | + * unsortedDimNum=4(待排序行数),sortAxisNum=128(排序轴长度) | ||
| 46 | + * | ||
| 47 | + * 算子属性: | ||
| 48 | + * - axis: -1(最后一维,即axis=1) | ||
| 49 | + * - descending: true(降序排序) | ||
| 50 | + * - stable: true(稳定排序) | ||
| 51 | + * | ||
| 52 | + * 排序模式:SMALL_SIZE_OPTIM_MODE(小规模优化模式,使用归并排序) | ||
| 53 | + * - 触发条件:sortAxisNum <= 512 && dataType in [FLOAT, FLOAT16, BF16] | ||
| 54 | + * - tilingKey计算:baseKey + MERGE_SORT_TILING_OFFSET = 3002 + 10000 = 13002 | ||
| 55 | + * | ||
| 56 | + */ | ||
| 57 | +TEST_F(SortWithIndexTilingTest, test_tiling_float16_small_size_merge_sort) { | ||
| 58 | + optiling::SortWithIndexCompileInfo compileInfo; | ||
| 59 | + compileInfo.core_num = 64; | ||
| 60 | + | ||
| 61 | + gert::TilingContextPara tilingContextPara("SortWithIndex", | ||
| 62 | + { | ||
| 63 | + {{{4, 128}, {4, 128}}, ge::DT_FLOAT16, ge::FORMAT_ND}, | ||
| 64 | + {{{4, 128}, {4, 128}}, ge::DT_FLOAT16, ge::FORMAT_ND}, | ||
| 65 | + }, | ||
| 66 | + { | ||
| 67 | + {{{}, {}}, ge::DT_FLOAT16, ge::FORMAT_ND}, | ||
| 68 | + {{{}, {}}, ge::DT_INT32, ge::FORMAT_ND}, | ||
| 69 | + }, | ||
| 70 | + { | ||
| 71 | + {"axis", Ops::Math::AnyValue::CreateFrom<int64_t>(-1)}, | ||
| 72 | + {"descending", Ops::Math::AnyValue::CreateFrom<bool>(true)}, | ||
| 73 | + {"stable", Ops::Math::AnyValue::CreateFrom<bool>(true)}, | ||
| 74 | + }, | ||
| 75 | + &compileInfo); | ||
| 76 | + | ||
| 77 | + uint64_t expectTilingKey = 13002; | ||
| 78 | + string expectTilingData = "4294967297 1 4 4294967297 128 68719476736 4294967424 128 0 0 0 0 "; | ||
| 79 | + std::vector<size_t> expectWorkspaces = {16777216}; | ||
| 80 | + ExecuteTestCase(tilingContextPara, ge::GRAPH_SUCCESS, expectTilingKey, expectTilingData, expectWorkspaces); | ||
| 81 | +} | ||
| 82 | + | ||
| 83 | +/** | ||
| 84 | + * 测试用例:FLOAT小规模归并排序 | ||
| 85 | + * | ||
| 86 | + * 测试目的:验证FLOAT数据类型在排序轴长度<=512时触发SMALL_SIZE_OPTIM_MODE归并排序模式 | ||
| 87 | + * | ||
| 88 | + * 数据类型:DT_FLOAT (tilingKey基数=3003) | ||
| 89 | + * | ||
| 90 | + * 输入形状:[2, 256] - 2行数据,每行256个元素需要排序 | ||
| 91 | + * unsortedDimNum=2,sortAxisNum=256 | ||
| 92 | + * | ||
| 93 | + * 算子属性: | ||
| 94 | + * - axis: -1(最后一维) | ||
| 95 | + * - descending: true(降序排序) | ||
| 96 | + * - stable: true(稳定排序) | ||
| 97 | + * | ||
| 98 | + * 排序模式:SMALL_SIZE_OPTIM_MODE(归并排序) | ||
| 99 | + * - 触发条件:sortAxisNum=256 <= 512 && dataType=FLOAT | ||
| 100 | + * - tilingKey = 3003 + 10000 = 13003 | ||
| 101 | + * | ||
| 102 | + */ | ||
| 103 | +TEST_F(SortWithIndexTilingTest, test_tiling_float_small_size_merge_sort) { | ||
| 104 | + optiling::SortWithIndexCompileInfo compileInfo; | ||
| 105 | + compileInfo.core_num = 64; | ||
| 106 | + | ||
| 107 | + gert::TilingContextPara tilingContextPara("SortWithIndex", | ||
| 108 | + { | ||
| 109 | + {{{2, 256}, {2, 256}}, ge::DT_FLOAT, ge::FORMAT_ND}, | ||
| 110 | + {{{2, 256}, {2, 256}}, ge::DT_FLOAT, ge::FORMAT_ND}, | ||
| 111 | + }, | ||
| 112 | + { | ||
| 113 | + {{{}, {}}, ge::DT_FLOAT, ge::FORMAT_ND}, | ||
| 114 | + {{{}, {}}, ge::DT_INT32, ge::FORMAT_ND}, | ||
| 115 | + }, | ||
| 116 | + { | ||
| 117 | + {"axis", Ops::Math::AnyValue::CreateFrom<int64_t>(-1)}, | ||
| 118 | + {"descending", Ops::Math::AnyValue::CreateFrom<bool>(true)}, | ||
| 119 | + {"stable", Ops::Math::AnyValue::CreateFrom<bool>(true)}, | ||
| 120 | + }, | ||
| 121 | + &compileInfo); | ||
| 122 | + | ||
| 123 | + uint64_t expectTilingKey = 13003; | ||
| 124 | + string expectTilingData = "4294967297 1 2 4294967297 256 34359738368 4294967552 256 0 0 0 0 "; | ||
| 125 | + std::vector<size_t> expectWorkspaces = {16777216}; | ||
| 126 | + ExecuteTestCase(tilingContextPara, ge::GRAPH_SUCCESS, expectTilingKey, expectTilingData, expectWorkspaces); | ||
| 127 | +} | ||
| 128 | + | ||
| 129 | +/** | ||
| 130 | + * 测试用例:BF16小规模归并排序 | ||
| 131 | + * | ||
| 132 | + * 测试目的:验证BF16数据类型在排序轴长度<=512时触发SMALL_SIZE_OPTIM_MODE归并排序模式 | ||
| 133 | + * 并验证INT64索引输出类型的支持 | ||
| 134 | + * | ||
| 135 | + * 数据类型:DT_BF16 (tilingKey基数=4002) | ||
| 136 | + * 输出索引类型:DT_INT64 | ||
| 137 | + * | ||
| 138 | + * 输入形状:[2, 512] - 2行数据,每行512个元素需要排序 | ||
| 139 | + * unsortedDimNum=2,sortAxisNum=512(边界值,刚好触发归并排序) | ||
| 140 | + * | ||
| 141 | + * 算子属性: | ||
| 142 | + * - axis: -1(最后一维) | ||
| 143 | + * - descending: false(升序排序) | ||
| 144 | + * - stable: true(稳定排序) | ||
| 145 | + * | ||
| 146 | + * 排序模式:SMALL_SIZE_OPTIM_MODE(归并排序) | ||
| 147 | + * - 触发条件:sortAxisNum=512 <= 512 && dataType=BF16 | ||
| 148 | + * - tilingKey = 4002 + 10000 = 14002 | ||
| 149 | + * - BF16归并排序会在内部转换为FP32进行排序 | ||
| 150 | + * | ||
| 151 | + */ | ||
| 152 | +TEST_F(SortWithIndexTilingTest, test_tiling_bf16_small_size_merge_sort) { | ||
| 153 | + optiling::SortWithIndexCompileInfo compileInfo; | ||
| 154 | + compileInfo.core_num = 64; | ||
| 155 | + | ||
| 156 | + gert::TilingContextPara tilingContextPara("SortWithIndex", | ||
| 157 | + { | ||
| 158 | + {{{2, 512}, {2, 512}}, ge::DT_BF16, ge::FORMAT_ND}, | ||
| 159 | + {{{2, 512}, {2, 512}}, ge::DT_BF16, ge::FORMAT_ND}, | ||
| 160 | + }, | ||
| 161 | + { | ||
| 162 | + {{{}, {}}, ge::DT_BF16, ge::FORMAT_ND}, | ||
| 163 | + {{{}, {}}, ge::DT_INT64, ge::FORMAT_ND}, | ||
| 164 | + }, | ||
| 165 | + { | ||
| 166 | + {"axis", Ops::Math::AnyValue::CreateFrom<int64_t>(-1)}, | ||
| 167 | + {"descending", Ops::Math::AnyValue::CreateFrom<bool>(false)}, | ||
| 168 | + {"stable", Ops::Math::AnyValue::CreateFrom<bool>(true)}, | ||
| 169 | + }, | ||
| 170 | + &compileInfo); | ||
| 171 | + | ||
| 172 | + uint64_t expectTilingKey = 14002; | ||
| 173 | + string expectTilingData = "4294967296 1 2 4294967297 512 17179869184 4294967808 512 0 0 0 0 "; | ||
| 174 | + std::vector<size_t> expectWorkspaces = {16777216}; | ||
| 175 | + ExecuteTestCase(tilingContextPara, ge::GRAPH_SUCCESS, expectTilingKey, expectTilingData, expectWorkspaces); | ||
| 176 | +} | ||
| 177 | + | ||
| 178 | +/** | ||
| 179 | + * 测试用例:INT32小规模单块基数排序 | ||
| 180 | + * | ||
| 181 | + * 测试目的:验证INT32数据类型在小规模排序轴时触发SMALL_SIZE_MODE基数排序模式 | ||
| 182 | + * INT类型不支持归并排序优化,始终使用基数排序 | ||
| 183 | + * | ||
| 184 | + * 数据类型:DT_INT32 (tilingKey基数=1003) | ||
| 185 | + * 输出索引类型:DT_INT32 | ||
| 186 | + * | ||
| 187 | + * 输入形状:[2, 2] - 2行数据,每行仅2个元素需要排序(极小规模) | ||
| 188 | + * unsortedDimNum=2,sortAxisNum=2 | ||
| 189 | + * | ||
| 190 | + * 算子属性: | ||
| 191 | + * - axis: -1(最后一维) | ||
| 192 | + * - descending: true(降序排序) | ||
| 193 | + * - stable: true(稳定排序) | ||
| 194 | + * | ||
| 195 | + * 排序模式:SMALL_SIZE_MODE(小规模基数排序) | ||
| 196 | + * - 触发条件:sortAxisNum <= tileData(4096 for INT32) | ||
| 197 | + * - 注意:INT32不满足归并排序条件(dataType不在optDataTypeBitMap中) | ||
| 198 | + * - tilingKey = 1003(不加MERGE_SORT_TILING_OFFSET) | ||
| 199 | + * | ||
| 200 | + */ | ||
| 201 | +TEST_F(SortWithIndexTilingTest, test_tiling_int32_small_size_single_block) { | ||
| 38 | optiling::SortWithIndexCompileInfo compileInfo; | 202 | optiling::SortWithIndexCompileInfo compileInfo; |
| 39 | compileInfo.core_num = 64; | 203 | compileInfo.core_num = 64; |
| 40 | 204 | ||
| @@ -48,7 +212,6 @@ TEST_F(SortWithIndexTilingTest, test_tiling_int32) { | |||
| 48 | {{{}, {}}, ge::DT_INT32, ge::FORMAT_ND}, | 212 | {{{}, {}}, ge::DT_INT32, ge::FORMAT_ND}, |
| 49 | }, | 213 | }, |
| 50 | { | 214 | { |
| 51 | - // attr | ||
| 52 | {"axis", Ops::Math::AnyValue::CreateFrom<int64_t>(-1)}, | 215 | {"axis", Ops::Math::AnyValue::CreateFrom<int64_t>(-1)}, |
| 53 | {"descending", Ops::Math::AnyValue::CreateFrom<bool>(true)}, | 216 | {"descending", Ops::Math::AnyValue::CreateFrom<bool>(true)}, |
| 54 | {"stable", Ops::Math::AnyValue::CreateFrom<bool>(true)}, | 217 | {"stable", Ops::Math::AnyValue::CreateFrom<bool>(true)}, |
| @@ -60,3 +223,139 @@ TEST_F(SortWithIndexTilingTest, test_tiling_int32) { | |||
| 60 | std::vector<size_t> expectWorkspaces = {16777216}; | 223 | std::vector<size_t> expectWorkspaces = {16777216}; |
| 61 | ExecuteTestCase(tilingContextPara, ge::GRAPH_SUCCESS, expectTilingKey, expectTilingData, expectWorkspaces); | 224 | ExecuteTestCase(tilingContextPara, ge::GRAPH_SUCCESS, expectTilingKey, expectTilingData, expectWorkspaces); |
| 62 | } | 225 | } |
| 226 | + | ||
| 227 | +/** | ||
| 228 | + * 测试用例:INT64小规模单块基数排序 | ||
| 229 | + * | ||
| 230 | + * 测试目的:验证INT64数据类型在小规模排序轴时触发SMALL_SIZE_MODE基数排序模式 | ||
| 231 | + * 并验证INT64数据类型的字节大小为8,tileData调整为2048 | ||
| 232 | + * | ||
| 233 | + * 数据类型:DT_INT64 (tilingKey基数=1004,字节大小=8) | ||
| 234 | + * 输出索引类型:DT_INT64 | ||
| 235 | + * | ||
| 236 | + * | ||
| 237 | + * 算子属性: | ||
| 238 | + * - axis: -1(最后一维) | ||
| 239 | + * - descending: false(升序排序) | ||
| 240 | + * - stable: true(稳定排序) | ||
| 241 | + * | ||
| 242 | + * 排序模式:SMALL_SIZE_MODE(小规模基数排序) | ||
| 243 | + * - 触发条件:sortAxisNum=2 <= tileData=2048(INT64专用tileData) | ||
| 244 | + * - tilingKey = 1004 | ||
| 245 | + * | ||
| 246 | + */ | ||
| 247 | +TEST_F(SortWithIndexTilingTest, test_tiling_int64_small_size_single_block) { | ||
| 248 | + optiling::SortWithIndexCompileInfo compileInfo; | ||
| 249 | + compileInfo.core_num = 64; | ||
| 250 | + | ||
| 251 | + gert::TilingContextPara tilingContextPara("SortWithIndex", | ||
| 252 | + { | ||
| 253 | + {{{2, 2}, {2, 2}}, ge::DT_INT64, ge::FORMAT_ND}, | ||
| 254 | + {{{2, 2}, {2, 2}}, ge::DT_INT64, ge::FORMAT_ND}, | ||
| 255 | + }, | ||
| 256 | + { | ||
| 257 | + {{{}, {}}, ge::DT_INT64, ge::FORMAT_ND}, | ||
| 258 | + {{{}, {}}, ge::DT_INT64, ge::FORMAT_ND}, | ||
| 259 | + }, | ||
| 260 | + { | ||
| 261 | + {"axis", Ops::Math::AnyValue::CreateFrom<int64_t>(-1)}, | ||
| 262 | + {"descending", Ops::Math::AnyValue::CreateFrom<bool>(false)}, | ||
| 263 | + {"stable", Ops::Math::AnyValue::CreateFrom<bool>(true)}, | ||
| 264 | + }, | ||
| 265 | + &compileInfo); | ||
| 266 | + | ||
| 267 | + uint64_t expectTilingKey = 1004; | ||
| 268 | + string expectTilingData = "4294967296 2 2 4294967297 2 4294967296 4294967298 2 0 0 0 4294967296 "; | ||
| 269 | + std::vector<size_t> expectWorkspaces = {16777216}; | ||
| 270 | + ExecuteTestCase(tilingContextPara, ge::GRAPH_SUCCESS, expectTilingKey, expectTilingData, expectWorkspaces); | ||
| 271 | +} | ||
| 272 | + | ||
| 273 | +/** | ||
| 274 | + * 测试用例:UINT32小规模单块基数排序 | ||
| 275 | + * | ||
| 276 | + * 测试目的:验证UINT32数据类型在小规模排序轴时触发SMALL_SIZE_MODE基数排序模式 | ||
| 277 | + * UINT类型与INT类型一样不支持归并排序优化 | ||
| 278 | + * | ||
| 279 | + * 数据类型:DT_UINT32 (tilingKey基数=2003) | ||
| 280 | + * 输出索引类型:DT_UINT32 | ||
| 281 | + * | ||
| 282 | + * | ||
| 283 | + * 排序模式:SMALL_SIZE_MODE(小规模基数排序) | ||
| 284 | + * - 触发条件:sortAxisNum <= tileData=4096 | ||
| 285 | + * - tilingKey = 2003(UINT类型使用2000系列基数) | ||
| 286 | + * | ||
| 287 | + */ | ||
| 288 | +TEST_F(SortWithIndexTilingTest, test_tiling_uint32_small_size_single_block) { | ||
| 289 | + optiling::SortWithIndexCompileInfo compileInfo; | ||
| 290 | + compileInfo.core_num = 64; | ||
| 291 | + | ||
| 292 | + gert::TilingContextPara tilingContextPara("SortWithIndex", | ||
| 293 | + { | ||
| 294 | + {{{2, 2}, {2, 2}}, ge::DT_UINT32, ge::FORMAT_ND}, | ||
| 295 | + {{{2, 2}, {2, 2}}, ge::DT_UINT32, ge::FORMAT_ND}, | ||
| 296 | + }, | ||
| 297 | + { | ||
| 298 | + {{{}, {}}, ge::DT_UINT32, ge::FORMAT_ND}, | ||
| 299 | + {{{}, {}}, ge::DT_UINT32, ge::FORMAT_ND}, | ||
| 300 | + }, | ||
| 301 | + { | ||
| 302 | + {"axis", Ops::Math::AnyValue::CreateFrom<int64_t>(-1)}, | ||
| 303 | + {"descending", Ops::Math::AnyValue::CreateFrom<bool>(false)}, | ||
| 304 | + {"stable", Ops::Math::AnyValue::CreateFrom<bool>(true)}, | ||
| 305 | + }, | ||
| 306 | + &compileInfo); | ||
| 307 | + | ||
| 308 | + uint64_t expectTilingKey = 2003; | ||
| 309 | + string expectTilingData = "4294967296 2 2 4294967297 2 4294967296 4294967298 2 0 0 0 4294967296 "; | ||
| 310 | + std::vector<size_t> expectWorkspaces = {16777216}; | ||
| 311 | + ExecuteTestCase(tilingContextPara, ge::GRAPH_SUCCESS, expectTilingKey, expectTilingData, expectWorkspaces); | ||
| 312 | +} | ||
| 313 | + | ||
| 314 | +/** | ||
| 315 | + * 测试用例:INT64大规模多块基数排序 | ||
| 316 | + * | ||
| 317 | + * 测试目的:验证INT64数据类型在大规模排序轴时触发MULT_CORE_MODE多核基数排序模式 | ||
| 318 | + * 验证排序轴长度超过tileData时的多块切分策略 | ||
| 319 | + * | ||
| 320 | + * 数据类型:DT_INT64 (tilingKey基数=1004) | ||
| 321 | + * 输出索引类型:DT_INT64 | ||
| 322 | + * | ||
| 323 | + * 输入形状:[1, 8192] - 1行数据,8192个元素需要排序(大规模) | ||
| 324 | + * unsortedDimNum=1,sortAxisNum=8192 | ||
| 325 | + * | ||
| 326 | + * 算子属性: | ||
| 327 | + * - axis: -1(最后一维) | ||
| 328 | + * - descending: true(降序排序) | ||
| 329 | + * - stable: true(稳定排序) | ||
| 330 | + * | ||
| 331 | + * 排序模式:MULT_CORE_MODE(多核基数排序) | ||
| 332 | + * - 触发条件:sortAxisNum=8192 > tileData=2048(INT64) | ||
| 333 | + * - 排序轴切分为多个块,每个块由一个核处理 | ||
| 334 | + * - tilingKey = 1004 | ||
| 335 | + * | ||
| 336 | + */ | ||
| 337 | +TEST_F(SortWithIndexTilingTest, test_tiling_int64_large_size_radix_multi_block) { | ||
| 338 | + optiling::SortWithIndexCompileInfo compileInfo; | ||
| 339 | + compileInfo.core_num = 64; | ||
| 340 | + | ||
| 341 | + gert::TilingContextPara tilingContextPara("SortWithIndex", | ||
| 342 | + { | ||
| 343 | + {{{1, 8192}, {1, 8192}}, ge::DT_INT64, ge::FORMAT_ND}, | ||
| 344 | + {{{1, 8192}, {1, 8192}}, ge::DT_INT64, ge::FORMAT_ND}, | ||
| 345 | + }, | ||
| 346 | + { | ||
| 347 | + {{{}, {}}, ge::DT_INT64, ge::FORMAT_ND}, | ||
| 348 | + {{{}, {}}, ge::DT_INT64, ge::FORMAT_ND}, | ||
| 349 | + }, | ||
| 350 | + { | ||
| 351 | + {"axis", Ops::Math::AnyValue::CreateFrom<int64_t>(-1)}, | ||
| 352 | + {"descending", Ops::Math::AnyValue::CreateFrom<bool>(true)}, | ||
| 353 | + {"stable", Ops::Math::AnyValue::CreateFrom<bool>(true)}, | ||
| 354 | + }, | ||
| 355 | + &compileInfo); | ||
| 356 | + | ||
| 357 | + uint64_t expectTilingKey = 1004; | ||
| 358 | + string expectTilingData = "4294967297 1 1 34359738376 1024 4294967296 4294975488 8192 34359738376 4294969344 8796093022464 8590137312 "; | ||
| 359 | + std::vector<size_t> expectWorkspaces = {16998400}; | ||
| 360 | + ExecuteTestCase(tilingContextPara, ge::GRAPH_SUCCESS, expectTilingKey, expectTilingData, expectWorkspaces); | ||
| 361 | +} | ||
🟡 Medium Priority
变更行:第 268 行(INT64 测试的 expectTilingData)与第 309 行(UINT32 测试的 expectTilingData)内容完全一致,均为:
"4294967296 2 2 4294967297 2 4294967296 4294967298 2 0 0 0 4294967296 "这两个测试用例分别使用 DT_INT64(8 字节元素)和 DT_UINT32(4 字节元素)作为输入数据类型,均进入 SMALL_SIZE_MODE 分支。在 Tiling 流程中,
SetSortTmpSizeOfIdx(sort_with_index_tiling.cpp 第 104-124 行)会调用AscendC::GetSortMaxMinTmpSize,传入各自的实际 dataType,该函数返回的maxValue会影响sortAcApiNeedBufferSize和tmpUbSize字段。由于 INT64 和 UINT32 的元素大小不同(8B vs 4B),排序 API 所需的临时缓冲区大小通常也会不同。两份预期数据完全一致可能意味着:某个测试的预期值未经独立验证,直接复制了另一个测试的预期数据。若预期数据本身有误,该测试将无法有效捕获对应数据类型的 Tiling 回归。
建议:分别验证 INT64 和 UINT32 在 shape [2,2], descending=false 条件下 Tiling 函数的实际输出,确保两份 expectTilingData 分别反映各自数据类型的真实 Tiling 结果。若确认两者确实输出相同,则可在注释中说明原因。