Merged
[CANNBot]ExpandIntoJaggedPermute算子支持Ascend950 #8583
陈展熹Add on Aug 12
[CANNBot]ExpandIntoJaggedPermute算子支持Ascend950 #8583
Merged
Total: 28 files changed+1465-127
| @@ -150,7 +150,7 @@ | |||
| 150 | | [aclnnEmbedding](../../index/embedding/docs/aclnnEmbedding.md) | 把数据集合映射到向量空间,进而将数据进行量化。embedding的二维权重张量为weight(m+1行,n列),对于任意输入索引张量indices(如1行3列),输出out是一个3行n列的张量。 | 默认确定性实现 | 默认确定性实现 | | 150 | | [aclnnEmbedding](../../index/embedding/docs/aclnnEmbedding.md) | 把数据集合映射到向量空间,进而将数据进行量化。embedding的二维权重张量为weight(m+1行,n列),对于任意输入索引张量indices(如1行3列),输出out是一个3行n列的张量。 | 默认确定性实现 | 默认确定性实现 | |
| 151 | | [aclnnEmbeddingBag](../../index/embedding_bag/docs/aclnnEmbeddingBag.md) | 根据indices从weight中获得一组被聚合的数,然后根据offsets的偏移和mode指定的聚合模式对获取的数进行max、sum、mean聚合。其余参数则更细化了计算过程的控制。 | 默认确定性实现 | 默认确定性实现 | | 151 | | [aclnnEmbeddingBag](../../index/embedding_bag/docs/aclnnEmbeddingBag.md) | 根据indices从weight中获得一组被聚合的数,然后根据offsets的偏移和mode指定的聚合模式对获取的数进行max、sum、mean聚合。其余参数则更细化了计算过程的控制。 | 默认确定性实现 | 默认确定性实现 | |
| 152 | | [aclnnEmbeddingDenseBackward](../../index/embedding_dense_grad_v2/docs/aclnnEmbeddingDenseBackward.md) | 实现aclnnEmbedding的反向计算,将相同索引indices对应grad的一行累加到out上。 | 默认非确定性实现,支持配置开启 | 默认确定性实现 | | 152 | | [aclnnEmbeddingDenseBackward](../../index/embedding_dense_grad_v2/docs/aclnnEmbeddingDenseBackward.md) | 实现aclnnEmbedding的反向计算,将相同索引indices对应grad的一行累加到out上。 | 默认非确定性实现,支持配置开启 | 默认确定性实现 | |
| 153 | -| [aclnnExpandIntoJaggedPermute](../../index/expand_into_jagged_permute/docs/aclnnExpandIntoJaggedPermute.md) | 将稀疏数据置换索引从表维度扩展到批次维度,适用于稀疏特征在不同rank中具有不同批次大小的情况。 | 默认确定性实现 | - | | 153 | +| [aclnnExpandIntoJaggedPermute](../../index/expand_into_jagged_permute/docs/aclnnExpandIntoJaggedPermute.md) | 将稀疏数据置换索引从表维度扩展到批次维度,适用于稀疏特征在不同rank中具有不同批次大小的情况。 | 默认确定性实现 | 默认确定性实现 | |
| 154 | | [aclnnEmbeddingRenorm](../../norm/renorm/docs/aclnnEmbeddingRenorm.md) | 根据给定的maxNorm和normType返回输入tensor在指定indices下的修正结果。 | 默认确定性实现 | 默认确定性实现 | | 154 | | [aclnnEmbeddingRenorm](../../norm/renorm/docs/aclnnEmbeddingRenorm.md) | 根据给定的maxNorm和normType返回输入tensor在指定indices下的修正结果。 | 默认确定性实现 | 默认确定性实现 | |
| 155 | | [aclnnErfinv&aclnnInplaceErfinv](../../activation/erfinv/docs/aclnnErfinv&aclnnInplaceErfinv.md) | erfinv是高斯误差函数erf的反函数。返回输入Tensor中每个元素对应在标准正态分布函数的分位数。 | 默认确定性实现 | 默认确定性实现 | | 155 | | [aclnnErfinv&aclnnInplaceErfinv](../../activation/erfinv/docs/aclnnErfinv&aclnnInplaceErfinv.md) | erfinv是高斯误差函数erf的反函数。返回输入Tensor中每个元素对应在标准正态分布函数的分位数。 | 默认确定性实现 | 默认确定性实现 | |
| 156 | | [aclnnFakeQuantPerChannelAffineCachemask](../../quant/fake_quant_affine_cachemask/docs/aclnnFakeQuantPerChannelAffineCachemask.md) | 对于输入数据self,使用scale和zero_point对输入self在指定轴axis上进行伪量化处理,并根据quant_min和quant_max对伪量化输出进行值域更新。 | 默认确定性实现 | 默认确定性实现 | | 156 | | [aclnnFakeQuantPerChannelAffineCachemask](../../quant/fake_quant_affine_cachemask/docs/aclnnFakeQuantPerChannelAffineCachemask.md) | 对于输入数据self,使用scale和zero_point对输入self在指定轴axis上进行伪量化处理,并根据quant_min和quant_max对伪量化输出进行值域更新。 | 默认确定性实现 | 默认确定性实现 | |
| @@ -1,20 +1,24 @@ | |||
| 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 of | 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"). | 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 | -message(STATUS "=== Debug: start ops.index.expand_into_jagged_permute.CMakeLists.txt ") | 11 | +set(SUPPORT_COMPUTE_UNIT "ascend910b" "ascend910_93" "ascend950") |
| 12 | -file(GLOB CURRENT_DIRS RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/*) | 12 | +set(SUPPORT_TILING_DIR "arch22" "arch22" "arch35") |
| 13 | -if(NOT ENABLE_TEST AND NOT BENCHMARK) | 13 | +add_all_modules_sources(OPTYPE expand_into_jagged_permute ACLNNTYPE aclnn |
| 14 | - list(REMOVE_ITEM CURRENT_DIRS tests) | 14 | + COMPUTE_UNIT ${SUPPORT_COMPUTE_UNIT} |
| 15 | + TILING_DIR ${SUPPORT_TILING_DIR}) | ||
| 16 | + | ||
| 17 | +add_kernel_sources( | ||
| 18 | + KERNEL_SRC arch35/expand_into_jagged_permute.cpp | ||
| 19 | + COMPUTE_UNITS ascend950 | ||
| 20 | + AUTO_SYNC false) | ||
| 21 | + | ||
| 22 | +if((UT_TEST_ALL OR OP_KERNEL_UT) AND NOT UT_DONE) | ||
| 23 | + AddOpTestCase(expand_into_jagged_permute "ascend910B1" "-DDTYPE_PERMUTE=int32_t") | ||
| 15 | endif() | 24 | endif() |
| 16 | -foreach(SUB_DIR ${CURRENT_DIRS}) | ||
| 17 | - if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/${SUB_DIR}/CMakeLists.txt") | ||
| 18 | - add_subdirectory(${SUB_DIR}) | ||
| 19 | - endif() | ||
| 20 | -endforeach() | ||
| @@ -4,7 +4,7 @@ | |||
| 4 | 4 | ||
| 5 | |产品 | 是否支持 | | 5 | |产品 | 是否支持 | |
| 6 | |:-------------------------|:----------:| | 6 | |:-------------------------|:----------:| |
| 7 | -| <term>Ascend 950PR/Ascend 950DT</term> | × | | 7 | +| <term>Ascend 950PR/Ascend 950DT</term> | √ | |
| 8 | | <term>Atlas A3 训练系列产品/Atlas A3 推理系列产品</term> | √ | | 8 | | <term>Atlas A3 训练系列产品/Atlas A3 推理系列产品</term> | √ | |
| 9 | | <term>Atlas A2 训练系列产品/Atlas A2 推理系列产品</term> | √ | | 9 | | <term>Atlas A2 训练系列产品/Atlas A2 推理系列产品</term> | √ | |
| 10 | | <term>Atlas 200I/500 A2 推理产品</term> | × | | 10 | | <term>Atlas 200I/500 A2 推理产品</term> | × | |
| @@ -3,7 +3,7 @@ | |||
| 3 | ## 产品支持情况 | 3 | ## 产品支持情况 |
| 4 | 4 | ||
| 5 | <!-- npu="950" id1 --> | 5 | <!-- npu="950" id1 --> |
| 6 | -- <term>Ascend 950PR/Ascend 950DT</term>:不支持 | 6 | +- <term>Ascend 950PR/Ascend 950DT</term>:支持 |
新增支持950,需同步刷新op_api_list.md里的确定性描述 ![]() ![]() | |||
| 7 | <!-- end id1 --> | 7 | <!-- end id1 --> |
| 8 | <!-- npu="A3" id2 --> | 8 | <!-- npu="A3" id2 --> |
| 9 | - <term>Atlas A3 训练系列产品/Atlas A3 推理系列产品</term>:支持 | 9 | - <term>Atlas A3 训练系列产品/Atlas A3 推理系列产品</term>:支持 |
| @@ -168,4 +168,4 @@ int main() | |||
| 168 | aclFinalize(); | 168 | aclFinalize(); |
| 169 | 169 | ||
| 170 | return 0; | 170 | return 0; |
| 171 | -} | 171 | +} |
| @@ -1,11 +0,0 @@ | |||
| 1 | -# ---------------------------------------------------------------------------- | ||
| 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 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 | -add_modules_sources(HOSTNAME ${OPHOST_NAME} MODE PRIVATE DIR ${CMAKE_CURRENT_SOURCE_DIR} OPTYPE expand_into_jagged_permute ACLNNTYPE aclnn) | ||
Rindex/expand_into_jagged_permute/op_host/expand_into_jagged_permute_tiling.cpp→index/expand_into_jagged_permute/op_host/arch22/expand_into_jagged_permute_tiling.cpp+1-1
| @@ -194,4 +194,4 @@ ge::graphStatus TilingPrepareExpandIntoJaggedPermute(gert::TilingParseContext* c | |||
| 194 | IMPL_OP_OPTILING(ExpandIntoJaggedPermute) | 194 | IMPL_OP_OPTILING(ExpandIntoJaggedPermute) |
| 195 | .Tiling(TilingForExpandIntoJaggedPermute) | 195 | .Tiling(TilingForExpandIntoJaggedPermute) |
| 196 | .TilingParse<ExpandIntoJaggedPermuteCompileInfo>(TilingPrepareExpandIntoJaggedPermute); | 196 | .TilingParse<ExpandIntoJaggedPermuteCompileInfo>(TilingPrepareExpandIntoJaggedPermute); |
| 197 | -} // namespace optiling | 197 | +} // namespace optiling |
Rindex/expand_into_jagged_permute/op_host/expand_into_jagged_permute_tiling.h→index/expand_into_jagged_permute/op_host/arch22/expand_into_jagged_permute_tiling.h+0-0
File renamed without changes.
| @@ -0,0 +1,401 @@ | |||
| 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 | +/*! | ||
| 12 | + * \file expand_into_jagged_permute_tiling.cpp | ||
| 13 | + * \brief Host tiling implementation for expand_into_jagged_permute. | ||
| 14 | + */ | ||
| 15 | + | ||
| 16 | +/* Generated By CANNBot */ | ||
| 17 | + | ||
| 18 | +#include <algorithm> | ||
| 19 | +#include <cstdint> | ||
| 20 | +#include <limits> | ||
| 21 | +#include <string> | ||
| 22 | + | ||
| 23 | +#include "graph/types.h" | ||
| 24 | +#include "log/log.h" | ||
| 25 | +#include "op_common/op_host/util/shape_util.h" | ||
| 26 | +#include "platform/platform_ascendc.h" | ||
| 27 | +#include "register/op_impl_registry.h" | ||
| 28 | +#include "securec.h" | ||
| 29 | +#include "util/math_util.h" | ||
| 30 | +#include "../../op_kernel/arch35/expand_into_jagged_permute_tiling_data.h" | ||
| 31 | +#include "../../op_kernel/arch35/expand_into_jagged_permute_tiling_key.h" | ||
| 32 | + | ||
| 33 | +namespace optiling { | ||
| 34 | +namespace { | ||
| 35 | +constexpr char OP_NAME[] = "ExpandIntoJaggedPermute"; | ||
| 36 | +constexpr char PERMUTE_NAME[] = "permute"; | ||
| 37 | +constexpr char INPUT_OFFSETS_NAME[] = "input_offsets"; | ||
| 38 | +constexpr char OUTPUT_OFFSETS_NAME[] = "output_offsets"; | ||
| 39 | +constexpr char OUTPUT_PERMUTE_NAME[] = "output_permute"; | ||
| 40 | +constexpr size_t PERMUTE_INDEX = 0; | ||
| 41 | +constexpr size_t INPUT_OFFSETS_INDEX = 1; | ||
| 42 | +constexpr size_t OUTPUT_OFFSETS_INDEX = 2; | ||
| 43 | +constexpr size_t OUTPUT_PERMUTE_INDEX = 0; | ||
| 44 | +constexpr size_t OUTPUT_SIZE_ATTR = 0; | ||
| 45 | +constexpr int64_t PER_CORE_MIN = 1024; | ||
| 46 | +constexpr int64_t WARP_SIZE = 32; | ||
| 47 | +constexpr uint64_t MIN_UB_BYTES = 40 * 1024; | ||
| 48 | +constexpr uint32_t WS_SYS_SIZE = 0U; // The kernel does not consume workspace, so the system workspace is always 0. | ||
| 49 | + | ||
| 50 | +struct ExpandIntoJaggedPermuteCompileInfo {}; | ||
| 51 | + | ||
| 52 | +struct PlatformInfo { | ||
| 53 | + int64_t coreNum = 0; | ||
| 54 | + uint64_t ubSize = 0; | ||
| 55 | +}; | ||
| 56 | + | ||
| 57 | +static ge::graphStatus ValidateTensorDesc(gert::TilingContext* context, const gert::CompileTimeTensorDesc* desc, | ||
| 58 | + const char* tensorName) | ||
| 59 | +{ | ||
| 60 | + OP_CHECK_NULL_WITH_CONTEXT(context, desc); | ||
| 61 | + const ge::DataType dataType = desc->GetDataType(); | ||
| 62 | + if (dataType != ge::DT_INT32) { | ||
| 63 | + OP_LOGE_FOR_INVALID_DTYPE(context->GetNodeName(), tensorName, Ops::Base::ToString(dataType).c_str(), "INT32"); | ||
| 64 | + return ge::GRAPH_FAILED; | ||
| 65 | + } | ||
| 66 | + const ge::Format primaryFormat = static_cast<ge::Format>(ge::GetPrimaryFormat(desc->GetStorageFormat())); | ||
| 67 | + if (primaryFormat != ge::FORMAT_ND) { | ||
| 68 | + OP_LOGE_FOR_INVALID_FORMAT(context->GetNodeName(), tensorName, Ops::Base::ToString(primaryFormat).c_str(), | ||
| 69 | + "ND"); | ||
| 70 | + return ge::GRAPH_FAILED; | ||
| 71 | + } | ||
| 72 | + return ge::GRAPH_SUCCESS; | ||
| 73 | +} | ||
| 74 | + | ||
| 75 | +static ge::graphStatus ValidateTensorDescriptors(gert::TilingContext* context) | ||
| 76 | +{ | ||
| 77 | + ge::graphStatus status = ValidateTensorDesc(context, context->GetInputDesc(PERMUTE_INDEX), PERMUTE_NAME); | ||
| 78 | + if (status != ge::GRAPH_SUCCESS) { | ||
| 79 | + return status; | ||
| 80 | + } | ||
| 81 | + status = ValidateTensorDesc(context, context->GetInputDesc(INPUT_OFFSETS_INDEX), INPUT_OFFSETS_NAME); | ||
| 82 | + if (status != ge::GRAPH_SUCCESS) { | ||
| 83 | + return status; | ||
| 84 | + } | ||
| 85 | + status = ValidateTensorDesc(context, context->GetInputDesc(OUTPUT_OFFSETS_INDEX), OUTPUT_OFFSETS_NAME); | ||
| 86 | + if (status != ge::GRAPH_SUCCESS) { | ||
| 87 | + return status; | ||
| 88 | + } | ||
| 89 | + return ValidateTensorDesc(context, context->GetOutputDesc(OUTPUT_PERMUTE_INDEX), OUTPUT_PERMUTE_NAME); | ||
| 90 | +} | ||
| 91 | + | ||
| 92 | +static ge::graphStatus ValidateAttr(gert::TilingContext* context, int64_t& outputSize) | ||
| 93 | +{ | ||
| 94 | + const auto* attrs = context->GetAttrs(); | ||
| 95 | + OP_CHECK_NULL_WITH_CONTEXT(context, attrs); | ||
| 96 | + const int64_t* outputSizePtr = attrs->GetAttrPointer<int64_t>(OUTPUT_SIZE_ATTR); | ||
| 97 | + OP_CHECK_NULL_WITH_CONTEXT(context, outputSizePtr); | ||
| 98 | + if (*outputSizePtr < 0 || *outputSizePtr > std::numeric_limits<int32_t>::max()) { | ||
| 99 | + OP_LOGE_FOR_INVALID_VALUE(context->GetNodeName(), "output_size", std::to_string(*outputSizePtr).c_str(), | ||
| 100 | + "an integer in [0, INT32_MAX]"); | ||
| 101 | + return ge::GRAPH_FAILED; | ||
| 102 | + } | ||
| 103 | + outputSize = *outputSizePtr; | ||
| 104 | + return ge::GRAPH_SUCCESS; | ||
| 105 | +} | ||
| 106 | + | ||
| 107 | +static ge::graphStatus ReadConcreteLength(gert::TilingContext* context, const gert::StorageShape* storageShape, | ||
| 108 | + const char* tensorName, int64_t& length) | ||
| 109 | +{ | ||
| 110 | + OP_CHECK_NULL_WITH_CONTEXT(context, storageShape); | ||
| 111 | + const gert::Shape shape = storageShape->GetStorageShape(); | ||
| 112 | + if (shape.GetDimNum() != 1) { | ||
| 113 | + const std::string actual = std::to_string(shape.GetDimNum()) + "D"; | ||
| 114 | + OP_LOGE_FOR_INVALID_SHAPEDIM(context->GetNodeName(), tensorName, actual.c_str(), "1D"); | ||
| 115 | + return ge::GRAPH_FAILED; | ||
| 116 | + } | ||
| 117 | + length = shape.GetDim(0); | ||
| 118 | + if (length < 0) { | ||
| 119 | + OP_LOGE_FOR_INVALID_SHAPES_WITH_REASON(context->GetNodeName(), tensorName, Ops::Base::ToString(shape).c_str(), | ||
| 120 | + "Tiling requires a concrete non-negative one-dimensional shape"); | ||
| 121 | + return ge::GRAPH_FAILED; | ||
| 122 | + } | ||
| 123 | + return ge::GRAPH_SUCCESS; | ||
| 124 | +} | ||
| 125 | + | ||
| 126 | +static ge::graphStatus ValidateOffsetLengths(gert::TilingContext* context, int64_t segmentCount, | ||
| 127 | + int64_t inputOffsetCount, int64_t outputOffsetCount) | ||
| 128 | +{ | ||
| 129 | + if (segmentCount == std::numeric_limits<int64_t>::max()) { | ||
| 130 | + OP_LOGE_FOR_INVALID_VALUE(context->GetNodeName(), "permute length", std::to_string(segmentCount).c_str(), | ||
| 131 | + "a value that allows permute length + 1 to fit in int64"); | ||
| 132 | + return ge::GRAPH_FAILED; | ||
| 133 | + } | ||
| 134 | + const int64_t expectedOffsetCount = segmentCount + 1; | ||
| 135 | + if (inputOffsetCount != expectedOffsetCount || outputOffsetCount != expectedOffsetCount) { | ||
| 136 | + const std::string actual = "P=" + std::to_string(segmentCount) + | ||
| 137 | + ", input_offsets=" + std::to_string(inputOffsetCount) + | ||
| 138 | + ", output_offsets=" + std::to_string(outputOffsetCount); | ||
| 139 | + OP_LOGE_FOR_INVALID_SHAPES_WITH_REASON( | ||
| 140 | + context->GetNodeName(), "permute, input_offsets and output_offsets", actual.c_str(), | ||
| 141 | + "The lengths of input_offsets and output_offsets must both equal permute length + 1"); | ||
| 142 | + return ge::GRAPH_FAILED; | ||
| 143 | + } | ||
| 144 | + return ge::GRAPH_SUCCESS; | ||
| 145 | +} | ||
| 146 | + | ||
| 147 | +static ge::graphStatus ValidateOutputLength(gert::TilingContext* context, int64_t segmentCount, int64_t outputSize, | ||
| 148 | + int64_t outputLength) | ||
| 149 | +{ | ||
| 150 | + if (outputLength != outputSize) { | ||
| 151 | + const std::string actual = "output_permute length=" + std::to_string(outputLength) + | ||
| 152 | + ", output_size=" + std::to_string(outputSize); | ||
| 153 | + OP_LOGE_FOR_INVALID_SHAPES_WITH_REASON(context->GetNodeName(), "output_permute", actual.c_str(), | ||
| 154 | + "The output_permute length must equal output_size"); | ||
| 155 | + return ge::GRAPH_FAILED; | ||
| 156 | + } | ||
| 157 | + if ((segmentCount == 0 && outputSize != 0) || (segmentCount > 0 && outputSize < segmentCount)) { | ||
| 158 | + const std::string actual = "P=" + std::to_string(segmentCount) + ", output_size=" + std::to_string(outputSize); | ||
| 159 | + OP_LOGE_FOR_INVALID_VALUES_WITH_REASON( | ||
| 160 | + context->GetNodeName(), "P and output_size", actual.c_str(), | ||
| 161 | + "output_size must be 0 when P is 0, otherwise output_size must be greater than or equal to P"); | ||
| 162 | + return ge::GRAPH_FAILED; | ||
| 163 | + } | ||
| 164 | + return ge::GRAPH_SUCCESS; | ||
| 165 | +} | ||
| 166 | + | ||
| 167 | +static ge::graphStatus ValidateShape(gert::TilingContext* context, int64_t outputSize, int64_t& segmentCount) | ||
| 168 | +{ | ||
| 169 | + int64_t inputOffsetCount = 0; | ||
| 170 | + int64_t outputOffsetCount = 0; | ||
| 171 | + int64_t outputLength = 0; | ||
| 172 | + ge::graphStatus status = ReadConcreteLength(context, context->GetInputShape(PERMUTE_INDEX), PERMUTE_NAME, | ||
| 173 | + segmentCount); | ||
| 174 | + if (status != ge::GRAPH_SUCCESS) { | ||
| 175 | + return status; | ||
| 176 | + } | ||
| 177 | + status = ReadConcreteLength(context, context->GetInputShape(INPUT_OFFSETS_INDEX), INPUT_OFFSETS_NAME, | ||
| 178 | + inputOffsetCount); | ||
| 179 | + if (status != ge::GRAPH_SUCCESS) { | ||
| 180 | + return status; | ||
| 181 | + } | ||
| 182 | + status = ReadConcreteLength(context, context->GetInputShape(OUTPUT_OFFSETS_INDEX), OUTPUT_OFFSETS_NAME, | ||
| 183 | + outputOffsetCount); | ||
| 184 | + if (status != ge::GRAPH_SUCCESS) { | ||
| 185 | + return status; | ||
| 186 | + } | ||
| 187 | + status = ReadConcreteLength(context, context->GetOutputShape(OUTPUT_PERMUTE_INDEX), OUTPUT_PERMUTE_NAME, | ||
| 188 | + outputLength); | ||
| 189 | + if (status != ge::GRAPH_SUCCESS) { | ||
| 190 | + return status; | ||
| 191 | + } | ||
| 192 | + status = ValidateOffsetLengths(context, segmentCount, inputOffsetCount, outputOffsetCount); | ||
| 193 | + return status == ge::GRAPH_SUCCESS ? ValidateOutputLength(context, segmentCount, outputSize, outputLength) : status; | ||
| 194 | +} | ||
| 195 | + | ||
| 196 | +static ge::graphStatus ValidateInputs(gert::TilingContext* context, int64_t& segmentCount, int64_t& outputSize) | ||
| 197 | +{ | ||
| 198 | + ge::graphStatus status = ValidateTensorDescriptors(context); | ||
| 199 | + if (status != ge::GRAPH_SUCCESS) { | ||
| 200 | + return status; | ||
| 201 | + } | ||
| 202 | + status = ValidateAttr(context, outputSize); | ||
| 203 | + if (status != ge::GRAPH_SUCCESS) { | ||
| 204 | + return status; | ||
| 205 | + } | ||
| 206 | + return ValidateShape(context, outputSize, segmentCount); | ||
| 207 | +} | ||
| 208 | + | ||
| 209 | +static ge::graphStatus ValidateOutputViewSpan(gert::TilingContext* context, int64_t outputSize, int64_t outputOffset, | ||
| 210 | + int64_t outputStride) | ||
| 211 | +{ | ||
| 212 | + if (outputSize == 0) { | ||
| 213 | + return ge::GRAPH_SUCCESS; | ||
| 214 | + } | ||
| 215 | + const uint64_t maxLogical = static_cast<uint64_t>(outputSize - 1); | ||
| 216 | + const uint64_t stride = static_cast<uint64_t>(outputStride); | ||
| 217 | + if (maxLogical != 0 && stride > std::numeric_limits<uint64_t>::max() / maxLogical) { | ||
| 218 | + OP_LOGE_FOR_INVALID_VALUES_WITH_REASON(context->GetNodeName(), "output_size and output stride", | ||
| 219 | + "physical index overflow", | ||
| 220 | + "The output physical element index must fit in uint64"); | ||
| 221 | + return ge::GRAPH_FAILED; | ||
| 222 | + } | ||
| 223 | + const uint64_t maxPhysical = maxLogical * stride; | ||
| 224 | + const uint64_t offset = static_cast<uint64_t>(outputOffset); | ||
| 225 | + if (offset > std::numeric_limits<uint64_t>::max() - maxPhysical || | ||
| 226 | + offset + maxPhysical > std::numeric_limits<uint64_t>::max() / sizeof(int32_t)) { | ||
| 227 | + OP_LOGE_FOR_INVALID_VALUES_WITH_REASON(context->GetNodeName(), "output offset, size and stride", | ||
| 228 | + "physical byte offset overflow", | ||
| 229 | + "The maximum output physical byte offset must fit in uint64"); | ||
| 230 | + return ge::GRAPH_FAILED; | ||
| 231 | + } | ||
| 232 | + return ge::GRAPH_SUCCESS; | ||
| 233 | +} | ||
| 234 | + | ||
| 235 | +static ge::graphStatus ValidateOutputView(gert::TilingContext* context, int64_t outputSize, int64_t& outputStride) | ||
| 236 | +{ | ||
| 237 | + outputStride = 1; | ||
| 238 | + const bool isView = context->OutputIsView(OUTPUT_PERMUTE_INDEX); | ||
| 239 | + const int64_t outputOffset = context->GetOutputOffset(OUTPUT_PERMUTE_INDEX); | ||
| 240 | + if (!isView) { | ||
| 241 | + return ge::GRAPH_SUCCESS; | ||
| 242 | + } | ||
| 243 | + if (outputOffset < 0) { | ||
| 244 | + OP_LOGE_FOR_INVALID_VALUE(context->GetNodeName(), "output view offset", std::to_string(outputOffset).c_str(), | ||
| 245 | + "a non-negative element offset"); | ||
| 246 | + return ge::GRAPH_FAILED; | ||
| 247 | + } | ||
| 248 | + const gert::Stride* stride = context->GetOutputStride(OUTPUT_PERMUTE_INDEX); | ||
| 249 | + if (stride != nullptr) { | ||
| 250 | + if (stride->GetDimNum() != 1) { | ||
| 251 | + OP_LOGE_FOR_INVALID_SHAPEDIM(context->GetNodeName(), "output view stride", | ||
| 252 | + std::to_string(stride->GetDimNum()).c_str(), "1D"); | ||
| 253 | + return ge::GRAPH_FAILED; | ||
| 254 | + } | ||
| 255 | + outputStride = stride->GetStride(0); | ||
| 256 | + } | ||
| 257 | + if (outputStride < 0 || (outputStride == 0 && outputSize > 1)) { | ||
| 258 | + OP_LOGE_FOR_INVALID_VALUE(context->GetNodeName(), "output view stride", std::to_string(outputStride).c_str(), | ||
| 259 | + "a non-negative, non-overlapping element stride"); | ||
| 260 | + return ge::GRAPH_FAILED; | ||
| 261 | + } | ||
| 262 | + const ge::graphStatus status = ValidateOutputViewSpan(context, outputSize, outputOffset, outputStride); | ||
| 263 | + OP_LOGD(context, "output view metadata: stride(elements)=%ld, offset=%ld; kernel GM_ADDR includes offset", | ||
| 264 | + outputStride, outputOffset); | ||
| 265 | + return status; | ||
| 266 | +} | ||
| 267 | + | ||
| 268 | +static ge::graphStatus GetPlatformInfo(gert::TilingContext* context, PlatformInfo& info) | ||
| 269 | +{ | ||
| 270 | + auto* platformInfo = context->GetPlatformInfo(); | ||
| 271 | + OP_CHECK_NULL_WITH_CONTEXT(context, platformInfo); | ||
| 272 | + auto platform = platform_ascendc::PlatformAscendC(platformInfo); | ||
| 273 | + info.coreNum = static_cast<int64_t>(platform.GetCoreNumAiv()); | ||
| 274 | + platform.GetCoreMemSize(platform_ascendc::CoreMemType::UB, info.ubSize); | ||
| 275 | + if (info.coreNum <= 0 || info.coreNum > std::numeric_limits<uint32_t>::max()) { | ||
| 276 | + OP_LOGE(context->GetNodeName(), | ||
| 277 | + "Invalid internal AIV core count, actual=%s, reason=expected an integer in [1, UINT32_MAX]", | ||
| 278 | + std::to_string(info.coreNum).c_str()); | ||
| 279 | + return ge::GRAPH_FAILED; | ||
| 280 | + } | ||
| 281 | + if (info.ubSize < MIN_UB_BYTES) { | ||
| 282 | + OP_LOGE(context->GetNodeName(), | ||
| 283 | + "Invalid internal UB size, actual=%s, reason=expected at least 40960 bytes for the DCache reserve", | ||
| 284 | + std::to_string(info.ubSize).c_str()); | ||
| 285 | + return ge::GRAPH_FAILED; | ||
| 286 | + } | ||
| 287 | + return ge::GRAPH_SUCCESS; | ||
| 288 | +} | ||
| 289 | + | ||
| 290 | +static ge::graphStatus ComputeTiling(gert::TilingContext* context, int64_t segmentCount, int64_t outputSize, | ||
| 291 | + int64_t outputStride, int64_t physicalCoreNum, | ||
| 292 | + ExpandIntoJaggedPermuteTilingData* tiling) | ||
| 293 | +{ | ||
| 294 | + tiling->segmentCount = segmentCount; | ||
| 295 | + tiling->outputSize = outputSize; | ||
| 296 | + tiling->outputStride = outputStride; | ||
| 297 | + if (outputSize == 0) { | ||
| 298 | + tiling->perCoreOutput = 0; | ||
| 299 | + tiling->needCoreNum = 1; | ||
| 300 | + return ge::GRAPH_SUCCESS; | ||
| 301 | + } | ||
| 302 | + const int64_t ideal = Ops::Base::CeilDiv(outputSize, physicalCoreNum); | ||
| 303 | + const int64_t unaligned = std::max(ideal, PER_CORE_MIN); | ||
| 304 | + const int64_t warpUnits = Ops::Base::CeilDiv(unaligned, WARP_SIZE); | ||
| 305 | + if (warpUnits > std::numeric_limits<int64_t>::max() / WARP_SIZE) { | ||
| 306 | + OP_LOGE(context->GetNodeName(), | ||
| 307 | + "Invalid internal per-core output size, actual=%s, " | ||
| 308 | + "reason=expected a value whose warp alignment fits in int64", | ||
| 309 | + std::to_string(unaligned).c_str()); | ||
| 310 | + return ge::GRAPH_FAILED; | ||
| 311 | + } | ||
| 312 | + const int64_t perCore = warpUnits * WARP_SIZE; | ||
| 313 | + const int64_t needed = std::min(Ops::Base::CeilDiv(outputSize, perCore), physicalCoreNum); | ||
| 314 | + if (needed <= 0 || needed > std::numeric_limits<uint32_t>::max()) { | ||
| 315 | + OP_LOGE(context->GetNodeName(), | ||
| 316 | + "Invalid internal required AIV core count, actual=%s, " | ||
| 317 | + "reason=expected an integer in [1, UINT32_MAX]", | ||
| 318 | + std::to_string(needed).c_str()); | ||
| 319 | + return ge::GRAPH_FAILED; | ||
| 320 | + } | ||
| 321 | + tiling->perCoreOutput = perCore; | ||
| 322 | + tiling->needCoreNum = static_cast<uint32_t>(needed); | ||
| 323 | + return ge::GRAPH_SUCCESS; | ||
| 324 | +} | ||
| 325 | + | ||
| 326 | +static void DumpTilingData(gert::TilingContext* context, const ExpandIntoJaggedPermuteTilingData* tiling) | ||
| 327 | +{ | ||
| 328 | + OP_LOGD(context, | ||
| 329 | + "ExpandIntoJaggedPermuteTilingData: segmentCount=%ld, outputSize=%ld, perCoreOutput=%ld, " | ||
| 330 | + "outputStride(elements)=%ld, needCoreNum=%u, reserved=%u", | ||
| 331 | + tiling->segmentCount, tiling->outputSize, tiling->perCoreOutput, tiling->outputStride, tiling->needCoreNum, | ||
| 332 | + tiling->reserved); | ||
| 333 | +} | ||
| 334 | + | ||
| 335 | +static ge::graphStatus SetRuntimeConfig(gert::TilingContext* context, const ExpandIntoJaggedPermuteTilingData* tiling) | ||
| 336 | +{ | ||
| 337 | + size_t* workspaceSizes = context->GetWorkspaceSizes(1); | ||
| 338 | + OP_CHECK_NULL_WITH_CONTEXT(context, workspaceSizes); | ||
| 339 | + workspaceSizes[0] = WS_SYS_SIZE; | ||
| 340 | + context->SetBlockDim(tiling->needCoreNum); | ||
| 341 | + const ge::graphStatus localMemoryStatus = context->SetLocalMemorySize(0); | ||
| 342 | + if (localMemoryStatus != ge::GRAPH_SUCCESS) { | ||
| 343 | + OP_LOGE(context, "SetLocalMemorySize(0) failed, status=%u", localMemoryStatus); | ||
| 344 | + return localMemoryStatus; | ||
| 345 | + } | ||
| 346 | + context->SetTilingKey(GET_TPL_TILING_KEY(EXPAND_JAGGED_MODE_OUTPUT_BLOCK)); | ||
| 347 | + return ge::GRAPH_SUCCESS; | ||
| 348 | +} | ||
| 349 | + | ||
| 350 | +static ge::graphStatus ExpandIntoJaggedPermuteTilingFunc(gert::TilingContext* context) | ||
| 351 | +{ | ||
| 352 | + if (context == nullptr) { | ||
| 353 | + OP_LOGE(OP_NAME, "tiling context is nullptr"); | ||
| 354 | + return ge::GRAPH_FAILED; | ||
| 355 | + } | ||
| 356 | + int64_t segmentCount = 0; | ||
| 357 | + int64_t outputSize = 0; | ||
| 358 | + ge::graphStatus status = ValidateInputs(context, segmentCount, outputSize); | ||
| 359 | + if (status != ge::GRAPH_SUCCESS) { | ||
| 360 | + return status; | ||
| 361 | + } | ||
| 362 | + int64_t outputStride = 1; | ||
| 363 | + status = ValidateOutputView(context, outputSize, outputStride); | ||
| 364 | + if (status != ge::GRAPH_SUCCESS) { | ||
| 365 | + return status; | ||
| 366 | + } | ||
| 367 | + PlatformInfo platform{}; | ||
| 368 | + status = GetPlatformInfo(context, platform); | ||
| 369 | + if (status != ge::GRAPH_SUCCESS) { | ||
| 370 | + return status; | ||
| 371 | + } | ||
| 372 | + auto* tiling = context->GetTilingData<ExpandIntoJaggedPermuteTilingData>(); | ||
| 373 | + OP_CHECK_NULL_WITH_CONTEXT(context, tiling); | ||
| 374 | + if (memset_s(tiling, sizeof(*tiling), 0, sizeof(*tiling)) != EOK) { | ||
| 375 | + OP_LOGE(context, "memset_s failed while initializing %zu-byte tiling data", sizeof(*tiling)); | ||
| 376 | + return ge::GRAPH_FAILED; | ||
| 377 | + } | ||
| 378 | + status = ComputeTiling(context, segmentCount, outputSize, outputStride, platform.coreNum, tiling); | ||
| 379 | + if (status != ge::GRAPH_SUCCESS) { | ||
| 380 | + return status; | ||
| 381 | + } | ||
| 382 | + DumpTilingData(context, tiling); | ||
| 383 | + return SetRuntimeConfig(context, tiling); | ||
| 384 | +} | ||
| 385 | + | ||
| 386 | +static ge::graphStatus TilingParseForExpandIntoJaggedPermute([[maybe_unused]] gert::TilingParseContext* context) | ||
| 387 | +{ | ||
| 388 | + return ge::GRAPH_SUCCESS; | ||
| 389 | +} | ||
| 390 | +} // namespace | ||
| 391 | + | ||
| 392 | +ge::graphStatus ValidateOutputViewSpanForExpandIntoJaggedPermute(gert::TilingContext* context, int64_t outputSize, | ||
这个函数在本文件没用到,确认需要吗? ![]() ![]() | |||
| 393 | + int64_t outputOffset, int64_t outputStride) | ||
| 394 | +{ | ||
| 395 | + return ValidateOutputViewSpan(context, outputSize, outputOffset, outputStride); | ||
| 396 | +} | ||
| 397 | + | ||
| 398 | +IMPL_OP_OPTILING(ExpandIntoJaggedPermute) | ||
| 399 | + .Tiling(ExpandIntoJaggedPermuteTilingFunc) | ||
| 400 | + .TilingParse<ExpandIntoJaggedPermuteCompileInfo>(TilingParseForExpandIntoJaggedPermute); | ||
| 401 | +} // namespace optiling | ||
| @@ -13,6 +13,8 @@ | |||
| 13 | * \brief | 13 | * \brief |
| 14 | */ | 14 | */ |
| 15 | 15 | ||
| 16 | +/* Generated By CANNBot */ | ||
| 17 | + | ||
| 16 | #include "register/op_def_registry.h" | 18 | #include "register/op_def_registry.h" |
| 17 | 19 | ||
| 18 | namespace ops { | 20 | namespace ops { |
| @@ -46,8 +48,18 @@ public: | |||
| 46 | this->Attr("output_size").AttrType(REQUIRED).Int(); | 48 | this->Attr("output_size").AttrType(REQUIRED).Int(); |
| 47 | this->AICore().AddConfig("ascend910b"); | 49 | this->AICore().AddConfig("ascend910b"); |
| 48 | this->AICore().AddConfig("ascend910_93"); | 50 | this->AICore().AddConfig("ascend910_93"); |
| 51 | + | ||
| 52 | + OpAICoreConfig aicoreConfig950; | ||
| 53 | + aicoreConfig950.DynamicCompileStaticFlag(true) | ||
| 54 | + .DynamicFormatFlag(false) | ||
| 55 | + .DynamicRankSupportFlag(true) | ||
| 56 | + .DynamicShapeSupportFlag(true) | ||
| 57 | + .NeedCheckSupportFlag(false) | ||
| 58 | + .PrecisionReduceFlag(true) | ||
| 59 | + .ExtendCfgInfo("opFile.value", "expand_into_jagged_permute"); | ||
| 60 | + this->AICore().AddConfig("ascend950", aicoreConfig950); | ||
| 49 | } | 61 | } |
| 50 | }; | 62 | }; |
| 51 | 63 | ||
| 52 | OP_ADD(ExpandIntoJaggedPermute); | 64 | OP_ADD(ExpandIntoJaggedPermute); |
| 53 | -} // namespace ops | 65 | +} // namespace ops |
| @@ -0,0 +1,30 @@ | |||
| 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 | +/*! | ||
| 12 | + * \file expand_into_jagged_permute_apt.cpp | ||
| 13 | + * \brief Kernel entry for expand_into_jagged_permute. | ||
| 14 | + */ | ||
| 15 | + | ||
| 16 | +/* Generated By CANNBot */ | ||
| 17 | + | ||
| 18 | +#include "expand_into_jagged_permute_simt.h" | ||
| 19 | + | ||
| 20 | +template <uint32_t schMode> | ||
| 21 | +__global__ __aicore__ void expand_into_jagged_permute(GM_ADDR permute, GM_ADDR input_offsets, GM_ADDR output_offsets, | ||
| 22 | + GM_ADDR output_permute, GM_ADDR workspace, GM_ADDR tiling) | ||
| 23 | +{ | ||
| 24 | + REGISTER_TILING_DEFAULT(ExpandIntoJaggedPermuteTilingData); | ||
| 25 | + GET_TILING_DATA_WITH_STRUCT(ExpandIntoJaggedPermuteTilingData, tilingData, tiling); | ||
| 26 | + if constexpr (schMode == EXPAND_JAGGED_MODE_OUTPUT_BLOCK) { | ||
| 27 | + NsExpandIntoJaggedPermute::Process<DTYPE_PERMUTE>(permute, input_offsets, output_offsets, output_permute, | ||
| 28 | + &tilingData); | ||
| 29 | + } | ||
| 30 | +} | ||
| @@ -0,0 +1,246 @@ | |||
| 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 | +/* Generated By CANNBot */ | ||
| 12 | + | ||
| 13 | +#ifndef EXPAND_INTO_JAGGED_PERMUTE_SIMT_H_ | ||
| 14 | +#define EXPAND_INTO_JAGGED_PERMUTE_SIMT_H_ | ||
| 15 | + | ||
| 16 | +#include "kernel_operator.h" | ||
| 17 | +#include "kernel_tiling/kernel_tiling.h" | ||
| 18 | +#include "simt_api/common_functions.h" | ||
| 19 | +#include "expand_into_jagged_permute_tiling_data.h" | ||
| 20 | +#include "expand_into_jagged_permute_tiling_key.h" | ||
| 21 | + | ||
| 22 | +namespace NsExpandIntoJaggedPermute { | ||
| 23 | +using namespace AscendC; | ||
| 24 | + | ||
| 25 | +constexpr uint32_t THREAD_NUM = 1024; | ||
| 26 | +constexpr int64_t INT32_LIMIT = 2147483647LL; | ||
| 27 | +constexpr uint64_t OUTPUT_FIXED_COST = 16; | ||
| 28 | + | ||
| 29 | +__aicore__ inline uint64_t SaturatingAddU64(uint64_t a, uint64_t b) { return a > UINT64_MAX - b ? UINT64_MAX : a + b; } | ||
| 30 | + | ||
| 31 | +__aicore__ inline uint64_t SaturatingMulU64(uint64_t a, uint64_t b) | ||
| 32 | +{ | ||
| 33 | + uint64_t multiplicand = a; | ||
| 34 | + uint64_t multiplier = b; | ||
| 35 | + if (multiplicand < multiplier) { | ||
| 36 | + const uint64_t temporary = multiplicand; | ||
| 37 | + multiplicand = multiplier; | ||
| 38 | + multiplier = temporary; | ||
| 39 | + } | ||
| 40 | + uint64_t result = 0; | ||
| 41 | + while (multiplier != 0) { | ||
| 42 | + if ((multiplier & 1U) != 0) { | ||
| 43 | + result = SaturatingAddU64(result, multiplicand); | ||
| 44 | + } | ||
| 45 | + multiplier >>= 1; | ||
| 46 | + if (multiplier != 0) { | ||
| 47 | + multiplicand = SaturatingAddU64(multiplicand, multiplicand); | ||
| 48 | + } | ||
| 49 | + } | ||
| 50 | + return result; | ||
| 51 | +} | ||
| 52 | + | ||
| 53 | +__aicore__ inline uint64_t CeilLog2U64(uint64_t x) | ||
| 54 | +{ | ||
| 55 | + if (x <= 1) { | ||
| 56 | + return 0; | ||
| 57 | + } | ||
| 58 | + uint64_t value = x - 1; | ||
| 59 | + uint64_t log = 0; | ||
| 60 | + while (value != 0) { | ||
| 61 | + value >>= 1; | ||
| 62 | + ++log; | ||
| 63 | + } | ||
| 64 | + return log; | ||
| 65 | +} | ||
| 66 | + | ||
| 67 | +__aicore__ inline bool ShouldUseOutputCentric(int64_t p, int64_t n, uint32_t needCoreNum) | ||
| 68 | +{ | ||
| 69 | + if (p <= 0 || n <= 0 || needCoreNum == 0) { | ||
| 70 | + return false; | ||
| 71 | + } | ||
| 72 | + const uint64_t pU = static_cast<uint64_t>(p); | ||
| 73 | + const uint64_t nU = static_cast<uint64_t>(n); | ||
| 74 | + const uint64_t coreNumU = static_cast<uint64_t>(needCoreNum); | ||
| 75 | + const uint64_t log = CeilLog2U64(pU); | ||
| 76 | + const uint64_t intersections = SaturatingAddU64(pU, coreNumU) - 1; | ||
| 77 | + const uint64_t segmentInner = SaturatingAddU64(intersections, SaturatingMulU64(coreNumU, log)); | ||
| 78 | + const uint64_t segmentCost = SaturatingMulU64(THREAD_NUM, segmentInner); | ||
| 79 | + const uint64_t outputCost = SaturatingMulU64(nU, SaturatingAddU64(log, OUTPUT_FIXED_COST)); | ||
| 80 | + return outputCost < segmentCost; | ||
| 81 | +} | ||
| 82 | + | ||
| 83 | +template <typename T> | ||
| 84 | +__simt_callee__ inline int64_t FindFirstSegment(int64_t segmentCount, uint64_t coreBegin, __gm__ T* outputOffsets) | ||
| 85 | +{ | ||
| 86 | + int64_t low = 0; | ||
| 87 | + int64_t high = segmentCount; | ||
| 88 | + while (low < high) { | ||
| 89 | + const int64_t middle = low + ((high - low) >> 1); | ||
| 90 | + const int64_t next = static_cast<int64_t>(outputOffsets[middle + 1]); | ||
| 91 | + if (next <= static_cast<int64_t>(coreBegin)) { | ||
| 92 | + low = middle + 1; | ||
| 93 | + } else { | ||
| 94 | + high = middle; | ||
| 95 | + } | ||
| 96 | + } | ||
| 97 | + return low; | ||
| 98 | +} | ||
| 99 | + | ||
| 100 | +template <typename T, bool STRIDED_OUTPUT> | ||
| 101 | +__simt_vf__ __aicore__ __launch_bounds__(THREAD_NUM) inline void ExpandIntoJaggedPermuteSimt( | ||
| 102 | + int64_t segmentCount, int64_t outputSize, int64_t perCoreOutput, int64_t outputStride, __gm__ T* permute, | ||
| 103 | + __gm__ T* inputOffsets, __gm__ T* outputOffsets, __gm__ T* output) | ||
| 104 | +{ | ||
| 105 | + if (segmentCount <= 0 || outputSize <= 0 || perCoreOutput <= 0) { | ||
| 106 | + return; | ||
| 107 | + } | ||
| 108 | + const uint64_t coreIdx = static_cast<uint64_t>(blockIdx.x); | ||
| 109 | + const uint64_t localTid = static_cast<uint64_t>(threadIdx.x); | ||
| 110 | + const uint64_t threadNum = static_cast<uint64_t>(blockDim.x); | ||
| 111 | + const uint64_t total = static_cast<uint64_t>(outputSize); | ||
| 112 | + const uint64_t coreBegin = coreIdx * static_cast<uint64_t>(perCoreOutput); | ||
| 113 | + const uint64_t rawCoreEnd = coreBegin + static_cast<uint64_t>(perCoreOutput); | ||
| 114 | + const uint64_t coreEnd = rawCoreEnd < total ? rawCoreEnd : total; | ||
| 115 | + if (coreBegin >= coreEnd || static_cast<int64_t>(inputOffsets[0]) != 0 || | ||
| 116 | + static_cast<int64_t>(outputOffsets[0]) != 0 || | ||
| 117 | + static_cast<int64_t>(outputOffsets[segmentCount]) != outputSize) { | ||
| 118 | + return; | ||
| 119 | + } | ||
| 120 | + const int64_t first = FindFirstSegment(segmentCount, coreBegin, outputOffsets); | ||
| 121 | + for (int64_t index = first; index < segmentCount; ++index) { | ||
| 122 | + const int64_t targetBegin = static_cast<int64_t>(outputOffsets[index]); | ||
| 123 | + const int64_t targetEnd = static_cast<int64_t>(outputOffsets[index + 1]); | ||
| 124 | + if (targetBegin >= static_cast<int64_t>(coreEnd)) { | ||
| 125 | + break; | ||
| 126 | + } | ||
| 127 | + if (targetBegin < 0 || targetEnd <= targetBegin || targetEnd > outputSize) { | ||
| 128 | + return; | ||
| 129 | + } | ||
| 130 | + const int64_t permuteId = static_cast<int64_t>(permute[index]); | ||
| 131 | + if (permuteId < 0 || permuteId >= segmentCount) { | ||
| 132 | + return; | ||
| 133 | + } | ||
| 134 | + const int64_t sourceBegin = static_cast<int64_t>(inputOffsets[permuteId]); | ||
| 135 | + // The output length defines the generated range; the next source offset is not a bound. | ||
| 136 | + const int64_t targetLength = targetEnd - targetBegin; | ||
| 137 | + if (sourceBegin < 0 || targetLength - 1 > INT32_LIMIT - sourceBegin) { | ||
| 138 | + return; | ||
| 139 | + } | ||
| 140 | + const uint64_t targetBeginU = static_cast<uint64_t>(targetBegin); | ||
| 141 | + const uint64_t writeBegin = targetBeginU > coreBegin ? targetBeginU : coreBegin; | ||
| 142 | + const uint64_t targetEndU = static_cast<uint64_t>(targetEnd); | ||
| 143 | + const uint64_t writeEnd = targetEndU < coreEnd ? targetEndU : coreEnd; | ||
| 144 | + for (uint64_t pos = writeBegin + localTid; pos < writeEnd; pos += threadNum) { | ||
| 145 | + const int64_t value = sourceBegin + static_cast<int64_t>(pos - targetBeginU); | ||
| 146 | + if (value < 0 || value > INT32_LIMIT) { | ||
| 147 | + return; | ||
| 148 | + } | ||
| 149 | + if constexpr (STRIDED_OUTPUT) { | ||
| 150 | + output[pos * static_cast<uint64_t>(outputStride)] = static_cast<T>(value); | ||
| 151 | + } else { | ||
| 152 | + output[pos] = static_cast<T>(value); | ||
| 153 | + } | ||
| 154 | + } | ||
| 155 | + } | ||
| 156 | +} | ||
| 157 | + | ||
| 158 | +template <typename T> | ||
| 159 | +__simt_vf__ __aicore__ __launch_bounds__(THREAD_NUM) inline void ExpandIntoJaggedPermuteOutputCentricSimt( | ||
| 160 | + int64_t segmentCount, int64_t outputSize, int64_t perCoreOutput, __gm__ T* permute, __gm__ T* inputOffsets, | ||
| 161 | + __gm__ T* outputOffsets, __gm__ T* output) | ||
| 162 | +{ | ||
| 163 | + if (segmentCount <= 0 || outputSize <= 0 || perCoreOutput <= 0) { | ||
| 164 | + return; | ||
| 165 | + } | ||
| 166 | + const uint64_t coreBegin = static_cast<uint64_t>(blockIdx.x) * static_cast<uint64_t>(perCoreOutput); | ||
| 167 | + const uint64_t total = static_cast<uint64_t>(outputSize); | ||
| 168 | + const uint64_t rawCoreEnd = coreBegin + static_cast<uint64_t>(perCoreOutput); | ||
| 169 | + const uint64_t coreEnd = rawCoreEnd < total ? rawCoreEnd : total; | ||
| 170 | + if (coreBegin >= coreEnd || static_cast<int64_t>(inputOffsets[0]) != 0 || | ||
| 171 | + static_cast<int64_t>(outputOffsets[0]) != 0 || | ||
| 172 | + static_cast<int64_t>(outputOffsets[segmentCount]) != outputSize) { | ||
| 173 | + return; | ||
| 174 | + } | ||
| 175 | + const uint64_t localTid = static_cast<uint64_t>(threadIdx.x); | ||
| 176 | + const uint64_t threadNum = static_cast<uint64_t>(blockDim.x); | ||
| 177 | + for (uint64_t pos = coreBegin + localTid; pos < coreEnd; pos += threadNum) { | ||
| 178 | + int64_t low = 1; | ||
| 179 | + int64_t high = segmentCount + 1; | ||
| 180 | + while (low < high) { | ||
| 181 | + const int64_t middle = low + ((high - low) >> 1); | ||
| 182 | + const int64_t boundary = static_cast<int64_t>(outputOffsets[middle]); | ||
| 183 | + if (boundary <= static_cast<int64_t>(pos)) { | ||
| 184 | + low = middle + 1; | ||
| 185 | + } else { | ||
| 186 | + high = middle; | ||
| 187 | + } | ||
| 188 | + } | ||
| 189 | + const int64_t segment = low - 1; | ||
| 190 | + if (segment < 0 || segment >= segmentCount) { | ||
| 191 | + return; | ||
| 192 | + } | ||
| 193 | + const int64_t targetBegin = static_cast<int64_t>(outputOffsets[segment]); | ||
| 194 | + const int64_t targetEnd = static_cast<int64_t>(outputOffsets[segment + 1]); | ||
| 195 | + if (targetBegin < 0 || targetEnd <= targetBegin || targetEnd > outputSize || | ||
| 196 | + static_cast<int64_t>(pos) < targetBegin || static_cast<int64_t>(pos) >= targetEnd) { | ||
| 197 | + return; | ||
| 198 | + } | ||
| 199 | + const int64_t permuteId = static_cast<int64_t>(permute[segment]); | ||
| 200 | + if (permuteId < 0 || permuteId >= segmentCount) { | ||
| 201 | + return; | ||
| 202 | + } | ||
| 203 | + const int64_t sourceBegin = static_cast<int64_t>(inputOffsets[permuteId]); | ||
| 204 | + const int64_t targetLength = targetEnd - targetBegin; | ||
| 205 | + // Check the generated indices, without imposing a source-segment length restriction. | ||
| 206 | + if (sourceBegin < 0 || targetLength - 1 > INT32_LIMIT - sourceBegin) { | ||
| 207 | + return; | ||
| 208 | + } | ||
| 209 | + const int64_t relative = static_cast<int64_t>(pos) - targetBegin; | ||
| 210 | + const int64_t value = sourceBegin + relative; | ||
| 211 | + if (relative < 0 || relative >= targetLength || value < 0 || value > INT32_LIMIT) { | ||
| 212 | + return; | ||
| 213 | + } | ||
| 214 | + output[pos] = static_cast<T>(value); | ||
| 215 | + } | ||
| 216 | +} | ||
| 217 | + | ||
| 218 | +template <typename T> | ||
| 219 | +__aicore__ inline void Process(GM_ADDR permute, GM_ADDR inputOffsets, GM_ADDR outputOffsets, GM_ADDR output, | ||
| 220 | + const ExpandIntoJaggedPermuteTilingData* tilingData) | ||
| 221 | +{ | ||
| 222 | + auto* permuteGm = reinterpret_cast<__gm__ T*>(permute); | ||
| 223 | + auto* inputOffsetsGm = reinterpret_cast<__gm__ T*>(inputOffsets); | ||
| 224 | + auto* outputOffsetsGm = reinterpret_cast<__gm__ T*>(outputOffsets); | ||
| 225 | + auto* outputGm = reinterpret_cast<__gm__ T*>(output); | ||
| 226 | + const int64_t outputStride = tilingData->outputStride; | ||
| 227 | + if (outputStride == 1) { | ||
| 228 | + if (ShouldUseOutputCentric(tilingData->segmentCount, tilingData->outputSize, tilingData->needCoreNum)) { | ||
| 229 | + asc_vf_call<ExpandIntoJaggedPermuteOutputCentricSimt<T>>( | ||
| 230 | + dim3(THREAD_NUM), tilingData->segmentCount, tilingData->outputSize, tilingData->perCoreOutput, | ||
| 231 | + permuteGm, inputOffsetsGm, outputOffsetsGm, outputGm); | ||
| 232 | + } else { | ||
| 233 | + asc_vf_call<ExpandIntoJaggedPermuteSimt<T, false>>(dim3(THREAD_NUM), tilingData->segmentCount, | ||
| 234 | + tilingData->outputSize, tilingData->perCoreOutput, 1, | ||
| 235 | + permuteGm, inputOffsetsGm, outputOffsetsGm, outputGm); | ||
| 236 | + } | ||
| 237 | + } else { | ||
| 238 | + asc_vf_call<ExpandIntoJaggedPermuteSimt<T, true>>( | ||
| 239 | + dim3(THREAD_NUM), tilingData->segmentCount, tilingData->outputSize, tilingData->perCoreOutput, outputStride, | ||
| 240 | + permuteGm, inputOffsetsGm, outputOffsetsGm, outputGm); | ||
| 241 | + } | ||
| 242 | +} | ||
| 243 | + | ||
| 244 | +} // namespace NsExpandIntoJaggedPermute | ||
| 245 | + | ||
| 246 | +#endif // EXPAND_INTO_JAGGED_PERMUTE_SIMT_H_ | ||
| @@ -0,0 +1,37 @@ | |||
| 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 | +/* Generated By CANNBot */ | ||
| 12 | + | ||
| 13 | +#ifndef EXPAND_INTO_JAGGED_PERMUTE_TILING_DATA_H_ | ||
| 14 | +#define EXPAND_INTO_JAGGED_PERMUTE_TILING_DATA_H_ | ||
| 15 | + | ||
| 16 | +#include <cstddef> | ||
| 17 | +#include <cstdint> | ||
| 18 | + | ||
| 19 | +struct ExpandIntoJaggedPermuteTilingData { | ||
| 20 | + int64_t segmentCount = 0; | ||
| 21 | + int64_t outputSize = 0; | ||
| 22 | + int64_t perCoreOutput = 0; | ||
| 23 | + int64_t outputStride = 1; | ||
| 24 | + uint32_t needCoreNum = 1; | ||
| 25 | + uint32_t reserved = 0; | ||
| 26 | +}; | ||
| 27 | + | ||
| 28 | +static_assert(offsetof(ExpandIntoJaggedPermuteTilingData, segmentCount) == 0); | ||
| 29 | +static_assert(offsetof(ExpandIntoJaggedPermuteTilingData, outputSize) == 8); | ||
| 30 | +static_assert(offsetof(ExpandIntoJaggedPermuteTilingData, perCoreOutput) == 16); | ||
| 31 | +static_assert(offsetof(ExpandIntoJaggedPermuteTilingData, outputStride) == 24); | ||
| 32 | +static_assert(offsetof(ExpandIntoJaggedPermuteTilingData, needCoreNum) == 32); | ||
| 33 | +static_assert(offsetof(ExpandIntoJaggedPermuteTilingData, reserved) == 36); | ||
| 34 | +static_assert(alignof(ExpandIntoJaggedPermuteTilingData) == 8); | ||
| 35 | +static_assert(sizeof(ExpandIntoJaggedPermuteTilingData) == 40); | ||
| 36 | + | ||
| 37 | +#endif // EXPAND_INTO_JAGGED_PERMUTE_TILING_DATA_H_ | ||
| @@ -0,0 +1,28 @@ | |||
| 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 | +/* Generated By CANNBot */ | ||
| 12 | + | ||
| 13 | +#ifndef EXPAND_INTO_JAGGED_PERMUTE_TILING_KEY_H_ | ||
| 14 | +#define EXPAND_INTO_JAGGED_PERMUTE_TILING_KEY_H_ | ||
| 15 | + | ||
| 16 | +#include "ascendc/host_api/tiling/template_argument.h" | ||
| 17 | + | ||
| 18 | +#define EXPAND_JAGGED_MODE_OUTPUT_BLOCK 0 | ||
| 19 | + | ||
| 20 | +ASCENDC_TPL_ARGS_DECL(ExpandIntoJaggedPermute, | ||
| 21 | + ASCENDC_TPL_UINT_DECL(schMode, 1, ASCENDC_TPL_UI_LIST, EXPAND_JAGGED_MODE_OUTPUT_BLOCK)); | ||
| 22 | + | ||
| 23 | +ASCENDC_TPL_SEL(ASCENDC_TPL_ARGS_SEL(ASCENDC_TPL_KERNEL_TYPE_SEL(ASCENDC_TPL_AIV_ONLY), | ||
| 24 | + ASCENDC_TPL_UINT_SEL(schMode, ASCENDC_TPL_UI_LIST, | ||
| 25 | + EXPAND_JAGGED_MODE_OUTPUT_BLOCK), | ||
| 26 | + ASCENDC_TPL_TILING_STRUCT_SEL(ExpandIntoJaggedPermuteTilingData))); | ||
| 27 | + | ||
| 28 | +#endif // EXPAND_INTO_JAGGED_PERMUTE_TILING_KEY_H_ | ||
| @@ -224,4 +224,4 @@ __aicore__ inline void ExpandIntoJaggedPermute<T, T0>::Process() | |||
| 224 | } | 224 | } |
| 225 | } | 225 | } |
| 226 | #endif | 226 | #endif |
| 227 | -// EXPEND_INTO_JAGGED_PERMUTE_H | 227 | +// EXPEND_INTO_JAGGED_PERMUTE_H |
| @@ -1,20 +0,0 @@ | |||
| 1 | -# ---------------------------------------------------------------------------- | ||
| 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 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 | -# 每个目录下需要生成的可执行文件,具体参考:ops/built-in/test/CMakeLists.txt: 50~124 | ||
| 12 | -message(STATUS "=== Debug: start ops.index.expand_into_jagged_permute.tests.CMakeLists.txt ") | ||
| 13 | -message(STATUS "=== Debug: start ops.math.linear_index.tests.CMakeLists.txt ") | ||
| 14 | -file(GLOB CURRENT_DIRS RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/*) | ||
| 15 | -message(STATUS "=== Debug: CURRENT_DIRS =${CURRENT_DIRS} ") | ||
| 16 | -foreach(SUB_DIR ${CURRENT_DIRS}) | ||
| 17 | - if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/${SUB_DIR}/CMakeLists.txt") | ||
| 18 | - add_subdirectory(${SUB_DIR}) | ||
| 19 | - endif() | ||
| 20 | -endforeach() | ||
| @@ -0,0 +1,57 @@ | |||
| 1 | +#!/usr/bin/env python3 | ||
| 2 | +# -*- coding: UTF-8 -*- | ||
| 3 | +# Copyright (c) 2026 Huawei Technologies Co., Ltd. | ||
| 4 | +# This program is free software, you can redistribute it and/or modify it under the terms and conditions of | ||
| 5 | +# CANN Open Software License Agreement Version 2.0 (the "License"). | ||
| 6 | +# Please refer to the License for details. You may not use this file except in compliance with the License. | ||
| 7 | +# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, | ||
| 8 | +# INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE. | ||
| 9 | +# See LICENSE in the root of the software repository for the full text of the License. | ||
| 10 | + | ||
| 11 | +"""FBGEMM reference for ExpandIntoJaggedPermute. | ||
| 12 | + | ||
| 13 | +Requires NumPy, PyTorch and a compatible FBGEMM package (fbgemm_gpu). | ||
| 14 | +Importing fbgemm_gpu registers the native torch.ops.fbgemm operators. | ||
| 15 | +The array golden uses CPU dispatch; the third-party callable uses the | ||
| 16 | +provided tensors' device. Inputs must satisfy FBGEMM's operator contract. | ||
| 17 | +""" | ||
| 18 | + | ||
| 19 | +import fbgemm_gpu # noqa: F401 -- registers the native FBGEMM operators | ||
| 20 | +import numpy as np | ||
| 21 | +import torch | ||
| 22 | + | ||
| 23 | +__golden__ = { | ||
| 24 | + "kernel": {"expand_into_jagged_permute": "expand_into_jagged_permute_golden"}, | ||
| 25 | +} | ||
| 26 | +__spec__ = {"expand_into_jagged_permute": "ExpandIntoJaggedPermuteSpec"} | ||
golden也需要aclnn ![]() ![]() | |||
| 27 | + | ||
| 28 | + | ||
| 29 | +def expand_into_jagged_permute_golden( | ||
| 30 | + permute, input_offsets, output_offsets, *, output_size, **kwargs | ||
| 31 | +): | ||
| 32 | + """Accept NumPy inputs in OpDef order and return the native FBGEMM result.""" | ||
| 33 | + permute_tensor = torch.from_numpy(np.ascontiguousarray(permute)) | ||
| 34 | + input_offsets_tensor = torch.from_numpy(np.ascontiguousarray(input_offsets)) | ||
| 35 | + output_offsets_tensor = torch.from_numpy(np.ascontiguousarray(output_offsets)) | ||
| 36 | + result = torch.ops.fbgemm.expand_into_jagged_permute( | ||
| 37 | + permute_tensor, input_offsets_tensor, output_offsets_tensor, int(output_size) | ||
| 38 | + ) | ||
| 39 | + return result.numpy() | ||
| 40 | + | ||
| 41 | + | ||
| 42 | +class ExpandIntoJaggedPermuteThirdParty: | ||
| 43 | + """Call FBGEMM with prepared contiguous tensors of matching dtype/device.""" | ||
| 44 | + | ||
| 45 | + def __init__(self, *, output_size, **kwargs): | ||
| 46 | + self.output_size = int(output_size) | ||
| 47 | + | ||
| 48 | + def __call__(self, permute, input_offsets, output_offsets, **kwargs): | ||
| 49 | + return torch.ops.fbgemm.expand_into_jagged_permute( | ||
| 50 | + permute, input_offsets, output_offsets, self.output_size | ||
| 51 | + ) | ||
| 52 | + | ||
| 53 | + | ||
| 54 | +class ExpandIntoJaggedPermuteSpec: | ||
| 55 | + golden = staticmethod(expand_into_jagged_permute_golden) | ||
| 56 | + third_party = {"torch": ExpandIntoJaggedPermuteThirdParty} | ||
| 57 | + tolerance = {"int32": {"standard": "binary_equal"}} | ||
| @@ -11,7 +11,6 @@ | |||
| 11 | # ---------------------------------------------------------------------------- | 11 | # ---------------------------------------------------------------------------- |
| 12 | 12 | ||
| 13 | import torch | 13 | import torch |
| 14 | -import numpy as np | ||
| 15 | from atk.configs.dataset_config import InputDataset | 14 | from atk.configs.dataset_config import InputDataset |
| 16 | from atk.configs.results_config import TaskResult | 15 | from atk.configs.results_config import TaskResult |
| 17 | from atk.tasks.api_execute import register | 16 | from atk.tasks.api_execute import register |
| @@ -25,53 +24,148 @@ class FunctionExpandIntoJaggedPermuteApi(BaseApi): | |||
| 25 | super(FunctionExpandIntoJaggedPermuteApi, self).__init__(task_result) | 24 | super(FunctionExpandIntoJaggedPermuteApi, self).__init__(task_result) |
| 26 | 25 | ||
| 27 | def init_by_input_data(self, input_data: InputDataset): | 26 | def init_by_input_data(self, input_data: InputDataset): |
| 28 | - print(f'output_offsets:{input_data.kwargs["output_offsets"]}') | 27 | + print(f"output_offsets:{input_data.kwargs['output_offsets']}") |
| 29 | - print(f'permute:{input_data.kwargs["permute"]}') | 28 | + print(f"permute:{input_data.kwargs['permute']}") |
| 30 | OpsDataset.seed_everything() | 29 | OpsDataset.seed_everything() |
| 31 | 30 | ||
| 32 | def generate_strictly_increasing_tensor_torch(n, k): | 31 | def generate_strictly_increasing_tensor_torch(n, k): |
| 33 | if k < 2 or n < k - 1: | 32 | if k < 2 or n < k - 1: |
| 34 | raise ValueError("无效的n或k") | 33 | raise ValueError("无效的n或k") |
| 35 | # 生成1到n-1的随机排列,取前k-2个并排序 | 34 | # 生成1到n-1的随机排列,取前k-2个并排序 |
| 36 | - random_points = torch.randperm(n - 1, dtype=torch.int32)[:k - 2] + 1 | 35 | + random_points = torch.randperm(n - 1, dtype=torch.int32)[: k - 2] + 1 |
| 37 | random_points, _ = torch.sort(random_points) | 36 | random_points, _ = torch.sort(random_points) |
| 38 | # 加入首尾 | 37 | # 加入首尾 |
| 39 | - tensor = torch.cat([torch.tensor([0], dtype=torch.int32), | 38 | + tensor = torch.cat( |
| 40 | - random_points, | 39 | + [ |
| 41 | - torch.tensor([n], dtype=torch.int32)]) | 40 | + torch.tensor([0], dtype=torch.int32), |
| 41 | + random_points, | ||
| 42 | + torch.tensor([n], dtype=torch.int32), | ||
| 43 | + ] | ||
| 44 | + ) | ||
| 42 | return tensor | 45 | return tensor |
| 43 | 46 | ||
| 44 | - n = input_data.kwargs['output_size'] | 47 | + n = input_data.kwargs["output_size"] |
| 45 | - k = input_data.kwargs['output_offsets'].shape[0] | 48 | + k = input_data.kwargs["output_offsets"].shape[0] |
| 46 | if k == 23: | 49 | if k == 23: |
| 47 | - input_data.kwargs['permute'] = torch.tensor( | 50 | + input_data.kwargs["permute"] = ( |
| 48 | - [0, 11, 1, 12, 2, 13, 3, 14, 4, 15, 5, 16, 6, 17, 7, 18, 8, 19, 9, 20, 10, 21]).to( | 51 | + torch.tensor( |
| 49 | - input_data.kwargs['permute'].device).to(input_data.kwargs['permute'].dtype) | 52 | + [ |
| 50 | - input_data.kwargs["input_offsets"] = torch.tensor( | 53 | + 0, |
| 51 | - [0, 4860, 9720, 14580, 19440, 24300, 29160, 34020, 38880, 43740, 48600, 53460, 58899, 64338, 69777, | 54 | + 11, |
| 52 | - 75216, 80655, 86094, 91533, 96972, 102411, 107850, 113289]).to( | 55 | + 1, |
| 53 | - input_data.kwargs['input_offsets'].device).to(input_data.kwargs['input_offsets'].dtype) | 56 | + 12, |
| 54 | - input_data.kwargs["output_offsets"] = torch.tensor( | 57 | + 2, |
| 55 | - [0, 4860, 10299, 15159, 20598, 25458, 30897, 35757, 41196, 46056, 51495, 56355, 61794, 66654, 72093, | 58 | + 13, |
| 56 | - 76953, 82392, 87252, 92691, 97551, 102990, 107850, 113289]).to( | 59 | + 3, |
| 57 | - device=input_data.kwargs['output_offsets'].device).to(dtype=input_data.kwargs['output_offsets'].dtype) | 60 | + 14, |
| 61 | + 4, | ||
| 62 | + 15, | ||
| 63 | + 5, | ||
| 64 | + 16, | ||
| 65 | + 6, | ||
| 66 | + 17, | ||
| 67 | + 7, | ||
| 68 | + 18, | ||
| 69 | + 8, | ||
| 70 | + 19, | ||
| 71 | + 9, | ||
| 72 | + 20, | ||
| 73 | + 10, | ||
| 74 | + 21, | ||
| 75 | + ] | ||
| 76 | + ) | ||
| 77 | + .to(input_data.kwargs["permute"].device) | ||
| 78 | + .to(input_data.kwargs["permute"].dtype) | ||
| 79 | + ) | ||
| 80 | + input_data.kwargs["input_offsets"] = ( | ||
| 81 | + torch.tensor( | ||
| 82 | + [ | ||
| 83 | + 0, | ||
| 84 | + 4860, | ||
| 85 | + 9720, | ||
| 86 | + 14580, | ||
| 87 | + 19440, | ||
| 88 | + 24300, | ||
| 89 | + 29160, | ||
| 90 | + 34020, | ||
| 91 | + 38880, | ||
| 92 | + 43740, | ||
| 93 | + 48600, | ||
| 94 | + 53460, | ||
| 95 | + 58899, | ||
| 96 | + 64338, | ||
| 97 | + 69777, | ||
| 98 | + 75216, | ||
| 99 | + 80655, | ||
| 100 | + 86094, | ||
| 101 | + 91533, | ||
| 102 | + 96972, | ||
| 103 | + 102411, | ||
| 104 | + 107850, | ||
| 105 | + 113289, | ||
| 106 | + ] | ||
| 107 | + ) | ||
| 108 | + .to(input_data.kwargs["input_offsets"].device) | ||
| 109 | + .to(input_data.kwargs["input_offsets"].dtype) | ||
| 110 | + ) | ||
| 111 | + input_data.kwargs["output_offsets"] = ( | ||
| 112 | + torch.tensor( | ||
| 113 | + [ | ||
| 114 | + 0, | ||
| 115 | + 4860, | ||
| 116 | + 10299, | ||
| 117 | + 15159, | ||
| 118 | + 20598, | ||
| 119 | + 25458, | ||
| 120 | + 30897, | ||
| 121 | + 35757, | ||
| 122 | + 41196, | ||
| 123 | + 46056, | ||
| 124 | + 51495, | ||
| 125 | + 56355, | ||
| 126 | + 61794, | ||
| 127 | + 66654, | ||
| 128 | + 72093, | ||
| 129 | + 76953, | ||
| 130 | + 82392, | ||
| 131 | + 87252, | ||
| 132 | + 92691, | ||
| 133 | + 97551, | ||
| 134 | + 102990, | ||
| 135 | + 107850, | ||
| 136 | + 113289, | ||
| 137 | + ] | ||
| 138 | + ) | ||
| 139 | + .to(device=input_data.kwargs["output_offsets"].device) | ||
| 140 | + .to(dtype=input_data.kwargs["output_offsets"].dtype) | ||
| 141 | + ) | ||
| 58 | input_data.kwargs["output_size"] = 113289 | 142 | input_data.kwargs["output_size"] = 113289 |
| 59 | else: | 143 | else: |
| 60 | - input_data.kwargs["output_offsets"] = generate_strictly_increasing_tensor_torch(n, k).to( | 144 | + input_data.kwargs["output_offsets"] = ( |
| 61 | - device=input_data.kwargs['output_offsets'].device).to(dtype=input_data.kwargs['output_offsets'].dtype) | 145 | + generate_strictly_increasing_tensor_torch(n, k) |
| 62 | - input_data.kwargs['permute'] = torch.randperm(k - 1).to( | 146 | + .to(device=input_data.kwargs["output_offsets"].device) |
| 63 | - input_data.kwargs['permute'].device).to(input_data.kwargs['permute'].dtype) | 147 | + .to(dtype=input_data.kwargs["output_offsets"].dtype) |
| 64 | - print(f'output_offsets:{input_data.kwargs["output_offsets"]}') | 148 | + ) |
| 65 | - print(f'permute:{input_data.kwargs["permute"]}') | 149 | + input_data.kwargs["permute"] = ( |
| 66 | - def expand_into_jagged_permute(self, permute, input_offsets, output_offsets, output_size): | 150 | + torch.randperm(k - 1) |
| 151 | + .to(input_data.kwargs["permute"].device) | ||
| 152 | + .to(input_data.kwargs["permute"].dtype) | ||
| 153 | + ) | ||
| 154 | + print(f"output_offsets:{input_data.kwargs['output_offsets']}") | ||
| 155 | + print(f"permute:{input_data.kwargs['permute']}") | ||
| 156 | + | ||
| 157 | + def expand_into_jagged_permute( | ||
| 158 | + self, permute, input_offsets, output_offsets, output_size | ||
| 159 | + ): | ||
| 67 | output2 = torch.empty(output_size, dtype=permute.dtype, device=permute.device) | 160 | output2 = torch.empty(output_size, dtype=permute.dtype, device=permute.device) |
| 68 | leni = output_offsets[1:] - output_offsets[:-1] | 161 | leni = output_offsets[1:] - output_offsets[:-1] |
| 69 | permute_length = permute.shape[0] | 162 | permute_length = permute.shape[0] |
| 70 | st = input_offsets[permute] | 163 | st = input_offsets[permute] |
| 71 | stl = st + leni | 164 | stl = st + leni |
| 72 | for i in range(permute_length): | 165 | for i in range(permute_length): |
| 73 | - output2[output_offsets[i]:output_offsets[i + 1]] = torch.arange(st[i], stl[i], dtype=permute.dtype, | 166 | + output2[output_offsets[i] : output_offsets[i + 1]] = torch.arange( |
| 74 | - device=output_offsets.device) | 167 | + st[i], stl[i], dtype=permute.dtype, device=output_offsets.device |
| 168 | + ) | ||
| 75 | output2.contiguous() | 169 | output2.contiguous() |
| 76 | return output2.to(dtype=permute.dtype) | 170 | return output2.to(dtype=permute.dtype) |
| 77 | 171 | ||
| @@ -80,6 +174,8 @@ class FunctionExpandIntoJaggedPermuteApi(BaseApi): | |||
| 80 | input_offsets = input_data.kwargs["input_offsets"] | 174 | input_offsets = input_data.kwargs["input_offsets"] |
| 81 | output_offsets = input_data.kwargs["output_offsets"] | 175 | output_offsets = input_data.kwargs["output_offsets"] |
| 82 | output_size = input_data.kwargs["output_size"] | 176 | output_size = input_data.kwargs["output_size"] |
| 83 | - cpu_res = self.expand_into_jagged_permute(permute, input_offsets, output_offsets, output_size) | 177 | + cpu_res = self.expand_into_jagged_permute( |
| 178 | + permute, input_offsets, output_offsets, output_size | ||
| 179 | + ) | ||
| 84 | 180 | ||
| 85 | return cpu_res | 181 | return cpu_res |
| @@ -1,18 +0,0 @@ | |||
| 1 | -# ---------------------------------------------------------------------------- | ||
| 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 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 | -# 每个目录下需要生成的可执行文件,具体参考:ops/built-in/test/CMakeLists.txt: 50~124 | ||
| 12 | -file(GLOB CURRENT_SOURCE_DIRS LIST_DIRECTORIES true ${CMAKE_CURRENT_SOURCE_DIR}/*) | ||
| 13 | -message(STATUS "=== Debug: CURRENT_SOURCE_DIRS =${CURRENT_SOURCE_DIRS} ") | ||
| 14 | -foreach(SUB_DIR ${CURRENT_SOURCE_DIRS}) | ||
| 15 | - if(EXISTS "${SUB_DIR}/CMakeLists.txt") | ||
| 16 | - add_subdirectory(${SUB_DIR}) | ||
| 17 | - endif() | ||
| 18 | -endforeach() | ||
| @@ -1,14 +0,0 @@ | |||
| 1 | -# ---------------------------------------------------------------------------- | ||
| 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 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 | -file(GLOB CURRENT_DIRS RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/*) | ||
| 12 | -if(UT_TEST_ALL OR OP_HOST_UT) | ||
| 13 | - add_modules_ut_sources(HOSTNAME ${OP_TILING_MODULE_NAME} MODE PRIVATE DIR ${CMAKE_CURRENT_SOURCE_DIR}) | ||
| 14 | -endif() | ||
Rindex/expand_into_jagged_permute/tests/ut/op_host/test_expand_into_jagged_permute_tiling.cpp→index/expand_into_jagged_permute/tests/ut/op_host/arch22/test_expand_into_jagged_permute_tiling.cpp+1-1
| @@ -21,7 +21,7 @@ | |||
| 21 | #include "ut_op_util.h" | 21 | #include "ut_op_util.h" |
| 22 | #include "ut_op_common.h" | 22 | #include "ut_op_common.h" |
| 23 | #include "platform/platform_infos_def.h" | 23 | #include "platform/platform_infos_def.h" |
| 24 | -#include "../../../op_host/expand_into_jagged_permute_tiling.h" | 24 | +#include "../../../../op_host/arch22/expand_into_jagged_permute_tiling.h" |
| 25 | 25 | ||
| 26 | using namespace ut_util; | 26 | using namespace ut_util; |
| 27 | using namespace std; | 27 | using namespace std; |
Aindex/expand_into_jagged_permute/tests/ut/op_host/arch35/test_expand_into_jagged_permute_tiling.cpp+286-0
| @@ -0,0 +1,286 @@ | |||
| 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 | +/* Generated By CANNBot */ | ||
| 12 | + | ||
| 13 | +#include <cstdint> | ||
| 14 | +#include <cstring> | ||
| 15 | +#include <limits> | ||
| 16 | +#include <map> | ||
| 17 | +#include <string> | ||
| 18 | + | ||
| 19 | +#include <gtest/gtest.h> | ||
| 20 | +#include "exe_graph/runtime/storage_format.h" | ||
| 21 | +#include "exe_graph/runtime/storage_shape.h" | ||
| 22 | +#include "kernel_run_context_facker.h" | ||
| 23 | +#include "platform/platform_infos_def.h" | ||
| 24 | +#include "register/op_impl_registry.h" | ||
| 25 | +#include "test_cube_util.h" | ||
| 26 | +#include "ut_op_common.h" | ||
| 27 | +#include "ut_op_util.h" | ||
| 28 | +#include "../../../../op_kernel/arch35/expand_into_jagged_permute_tiling_data.h" | ||
| 29 | +#include "../../../../op_kernel/arch35/expand_into_jagged_permute_tiling_key.h" | ||
| 30 | + | ||
| 31 | +namespace optiling { | ||
| 32 | +ge::graphStatus ValidateOutputViewSpanForExpandIntoJaggedPermute(gert::TilingContext* context, int64_t outputSize, | ||
| 33 | + int64_t outputOffset, int64_t outputStride); | ||
| 34 | +} // namespace optiling | ||
| 35 | + | ||
| 36 | +namespace { | ||
| 37 | +constexpr char OP_TYPE[] = "ExpandIntoJaggedPermute"; | ||
| 38 | +constexpr size_t TILING_CAPACITY = 4096; | ||
| 39 | + | ||
| 40 | +struct TilingResult { | ||
| 41 | + ge::graphStatus status = ge::GRAPH_FAILED; | ||
| 42 | + size_t dataSize = 0; | ||
| 43 | + size_t workspaceSize = 0; | ||
| 44 | + uint64_t tilingKey = 0; | ||
| 45 | + uint32_t blockDim = 0; | ||
| 46 | + ExpandIntoJaggedPermuteTilingData data{}; | ||
| 47 | +}; | ||
| 48 | + | ||
| 49 | +TilingResult RunTiling(gert::StorageShape& permute, gert::StorageShape& inputOffsets, gert::StorageShape& outputOffsets, | ||
| 50 | + gert::StorageShape& output, int64_t outputSize, ge::DataType permuteType = ge::DT_INT32, | ||
| 51 | + ge::Format permuteFormat = ge::FORMAT_ND, ge::DataType outputType = ge::DT_INT32, | ||
| 52 | + ge::Format outputFormat = ge::FORMAT_ND) | ||
| 53 | +{ | ||
| 54 | + const std::string platformJson = R"({ | ||
| 55 | + "hardware_info": { | ||
| 56 | + "UB_SIZE": 253952, | ||
| 57 | + "CORE_NUM": 64, | ||
| 58 | + "version": "Ascend950" | ||
| 59 | + } | ||
| 60 | + })"; | ||
| 61 | + std::map<std::string, std::string> socInfos; | ||
| 62 | + std::map<std::string, std::string> aicoreSpec; | ||
| 63 | + std::map<std::string, std::string> intrinsics; | ||
| 64 | + GetPlatFormInfos(platformJson.c_str(), socInfos, aicoreSpec, intrinsics); | ||
| 65 | + | ||
| 66 | + fe::PlatFormInfos platformInfo; | ||
| 67 | + platformInfo.Init(); | ||
| 68 | + uint8_t compileInfo = 0; | ||
| 69 | + auto tilingData = gert::TilingData::CreateCap(TILING_CAPACITY); | ||
| 70 | + auto workspaceHolder = gert::ContinuousVector::Create<size_t>(TILING_CAPACITY); | ||
| 71 | + auto* workspace = reinterpret_cast<gert::ContinuousVector*>(workspaceHolder.get()); | ||
| 72 | + | ||
| 73 | + auto holder = gert::TilingContextFaker() | ||
| 74 | + .SetOpType(OP_TYPE) | ||
| 75 | + .NodeIoNum(3, 1) | ||
| 76 | + .IrInstanceNum({1, 1, 1}) | ||
| 77 | + .InputShapes({&permute, &inputOffsets, &outputOffsets}) | ||
| 78 | + .OutputShapes({&output}) | ||
| 79 | + .CompileInfo(&compileInfo) | ||
| 80 | + .PlatformInfo(reinterpret_cast<char*>(&platformInfo)) | ||
| 81 | + .NodeInputTd(0, permuteType, permuteFormat, permuteFormat) | ||
| 82 | + .NodeInputTd(1, ge::DT_INT32, ge::FORMAT_ND, ge::FORMAT_ND) | ||
| 83 | + .NodeInputTd(2, ge::DT_INT32, ge::FORMAT_ND, ge::FORMAT_ND) | ||
| 84 | + .NodeOutputTd(0, outputType, outputFormat, outputFormat) | ||
| 85 | + .NodeAttrs({{"output_size", Ops::NN::AnyValue::CreateFrom<int64_t>(outputSize)}}) | ||
| 86 | + .TilingData(tilingData.get()) | ||
| 87 | + .Workspace(workspace) | ||
| 88 | + .Build(); | ||
| 89 | + auto* context = holder.GetContext<gert::TilingContext>(); | ||
| 90 | + TilingResult result; | ||
| 91 | + if (context == nullptr) { | ||
| 92 | + return result; | ||
| 93 | + } | ||
| 94 | + context->GetPlatformInfo()->SetPlatformRes("SoCInfo", socInfos); | ||
| 95 | + context->GetPlatformInfo()->SetPlatformRes("AICoreSpec", aicoreSpec); | ||
| 96 | + context->GetPlatformInfo()->SetCoreNumByCoreType("AICore"); | ||
| 97 | + context->GetPlatformInfo()->SetPlatformRes("AICoreintrinsicDtypeMap", intrinsics); | ||
| 98 | + | ||
| 99 | + auto* impl = gert::OpImplRegistry::GetInstance().GetOpImpl(OP_TYPE); | ||
| 100 | + if (impl == nullptr || impl->tiling == nullptr) { | ||
| 101 | + return result; | ||
| 102 | + } | ||
| 103 | + result.status = impl->tiling(context); | ||
| 104 | + if (result.status != ge::GRAPH_SUCCESS) { | ||
| 105 | + return result; | ||
| 106 | + } | ||
| 107 | + result.tilingKey = context->GetTilingKey(); | ||
| 108 | + result.blockDim = context->GetBlockDim(); | ||
| 109 | + const size_t* workspaceSizes = context->GetWorkspaceSizes(1); | ||
| 110 | + if (workspaceSizes != nullptr) { | ||
| 111 | + result.workspaceSize = workspaceSizes[0]; | ||
| 112 | + } | ||
| 113 | + const auto* raw = context->GetRawTilingData(); | ||
| 114 | + if (raw != nullptr) { | ||
| 115 | + result.dataSize = raw->GetDataSize(); | ||
| 116 | + if (result.dataSize >= sizeof(result.data)) { | ||
| 117 | + std::memcpy(&result.data, raw->GetData(), sizeof(result.data)); | ||
| 118 | + } | ||
| 119 | + } | ||
| 120 | + return result; | ||
| 121 | +} | ||
| 122 | + | ||
| 123 | +ge::graphStatus RunViewSpan(int64_t outputSize, int64_t outputOffset, int64_t outputStride) | ||
| 124 | +{ | ||
| 125 | + gert::StorageShape permute = {{3}, {3}}; | ||
| 126 | + gert::StorageShape inputOffsets = {{4}, {4}}; | ||
| 127 | + gert::StorageShape outputOffsets = {{4}, {4}}; | ||
| 128 | + gert::StorageShape output = {{6}, {6}}; | ||
| 129 | + auto tilingData = gert::TilingData::CreateCap(TILING_CAPACITY); | ||
| 130 | + auto workspaceHolder = gert::ContinuousVector::Create<size_t>(TILING_CAPACITY); | ||
| 131 | + auto* workspace = reinterpret_cast<gert::ContinuousVector*>(workspaceHolder.get()); | ||
| 132 | + fe::PlatFormInfos platformInfo; | ||
| 133 | + platformInfo.Init(); | ||
| 134 | + uint8_t compileInfo = 0; | ||
| 135 | + auto holder = gert::TilingContextFaker() | ||
| 136 | + .SetOpType(OP_TYPE) | ||
| 137 | + .NodeIoNum(3, 1) | ||
| 138 | + .IrInstanceNum({1, 1, 1}) | ||
| 139 | + .InputShapes({&permute, &inputOffsets, &outputOffsets}) | ||
| 140 | + .OutputShapes({&output}) | ||
| 141 | + .NodeInputTd(0, ge::DT_INT32, ge::FORMAT_ND, ge::FORMAT_ND) | ||
| 142 | + .NodeInputTd(1, ge::DT_INT32, ge::FORMAT_ND, ge::FORMAT_ND) | ||
| 143 | + .NodeInputTd(2, ge::DT_INT32, ge::FORMAT_ND, ge::FORMAT_ND) | ||
| 144 | + .NodeOutputTd(0, ge::DT_INT32, ge::FORMAT_ND, ge::FORMAT_ND) | ||
| 145 | + .NodeAttrs({{"output_size", Ops::NN::AnyValue::CreateFrom<int64_t>(6)}}) | ||
| 146 | + .CompileInfo(&compileInfo) | ||
| 147 | + .PlatformInfo(reinterpret_cast<char*>(&platformInfo)) | ||
| 148 | + .TilingData(tilingData.get()) | ||
| 149 | + .Workspace(workspace) | ||
| 150 | + .Build(); | ||
| 151 | + return optiling::ValidateOutputViewSpanForExpandIntoJaggedPermute(holder.GetContext<gert::TilingContext>(), | ||
| 152 | + outputSize, outputOffset, outputStride); | ||
| 153 | +} | ||
| 154 | +} // namespace | ||
| 155 | + | ||
| 156 | +TEST(ExpandIntoJaggedPermuteTiling950, ValidDataLayout) | ||
| 157 | +{ | ||
| 158 | + gert::StorageShape permute = {{3}, {3}}; | ||
| 159 | + gert::StorageShape inputOffsets = {{4}, {4}}; | ||
| 160 | + gert::StorageShape outputOffsets = {{4}, {4}}; | ||
| 161 | + gert::StorageShape output = {{6}, {6}}; | ||
| 162 | + const TilingResult result = RunTiling(permute, inputOffsets, outputOffsets, output, 6); | ||
| 163 | + ASSERT_EQ(result.status, ge::GRAPH_SUCCESS); | ||
| 164 | + EXPECT_EQ(result.dataSize, sizeof(ExpandIntoJaggedPermuteTilingData)); | ||
| 165 | + EXPECT_EQ(result.tilingKey, GET_TPL_TILING_KEY(EXPAND_JAGGED_MODE_OUTPUT_BLOCK)); | ||
| 166 | + EXPECT_EQ(result.blockDim, 1); | ||
| 167 | + EXPECT_EQ(result.data.segmentCount, 3); | ||
| 168 | + EXPECT_EQ(result.data.outputSize, 6); | ||
| 169 | + EXPECT_EQ(result.data.perCoreOutput, 1024); | ||
| 170 | + EXPECT_EQ(result.data.outputStride, 1); | ||
| 171 | + EXPECT_EQ(result.data.needCoreNum, 1); | ||
| 172 | + EXPECT_EQ(result.workspaceSize, 0u); | ||
| 173 | +} | ||
| 174 | + | ||
| 175 | +TEST(ExpandIntoJaggedPermuteTiling950, ZeroSystemWorkspace) | ||
| 176 | +{ | ||
| 177 | + gert::StorageShape permute = {{3}, {3}}; | ||
| 178 | + gert::StorageShape inputOffsets = {{4}, {4}}; | ||
| 179 | + gert::StorageShape outputOffsets = {{4}, {4}}; | ||
| 180 | + gert::StorageShape output = {{6}, {6}}; | ||
| 181 | + const TilingResult result = RunTiling(permute, inputOffsets, outputOffsets, output, 6); | ||
| 182 | + ASSERT_EQ(result.status, ge::GRAPH_SUCCESS); | ||
| 183 | + EXPECT_EQ(result.workspaceSize, 0u); | ||
| 184 | +} | ||
| 185 | + | ||
| 186 | +TEST(ExpandIntoJaggedPermuteTiling950, RejectsInvalidDataType) | ||
| 187 | +{ | ||
| 188 | + gert::StorageShape permute = {{3}, {3}}; | ||
| 189 | + gert::StorageShape inputOffsets = {{4}, {4}}; | ||
| 190 | + gert::StorageShape outputOffsets = {{4}, {4}}; | ||
| 191 | + gert::StorageShape output = {{6}, {6}}; | ||
| 192 | + EXPECT_EQ(RunTiling(permute, inputOffsets, outputOffsets, output, 6, ge::DT_INT64).status, ge::GRAPH_FAILED); | ||
| 193 | +} | ||
| 194 | + | ||
| 195 | +TEST(ExpandIntoJaggedPermuteTiling950, RejectsInvalidFormat) | ||
| 196 | +{ | ||
| 197 | + gert::StorageShape permute = {{3}, {3}}; | ||
| 198 | + gert::StorageShape inputOffsets = {{4}, {4}}; | ||
| 199 | + gert::StorageShape outputOffsets = {{4}, {4}}; | ||
| 200 | + gert::StorageShape output = {{6}, {6}}; | ||
| 201 | + EXPECT_EQ(RunTiling(permute, inputOffsets, outputOffsets, output, 6, ge::DT_INT32, ge::FORMAT_ND, ge::DT_INT32, | ||
| 202 | + ge::FORMAT_NCHW) | ||
| 203 | + .status, | ||
| 204 | + ge::GRAPH_FAILED); | ||
| 205 | +} | ||
| 206 | + | ||
| 207 | +TEST(ExpandIntoJaggedPermuteTiling950, RejectsWrongRank) | ||
| 208 | +{ | ||
| 209 | + gert::StorageShape permute = {{3, 1}, {3, 1}}; | ||
| 210 | + gert::StorageShape inputOffsets = {{4}, {4}}; | ||
| 211 | + gert::StorageShape outputOffsets = {{4}, {4}}; | ||
| 212 | + gert::StorageShape output = {{6}, {6}}; | ||
| 213 | + EXPECT_EQ(RunTiling(permute, inputOffsets, outputOffsets, output, 6).status, ge::GRAPH_FAILED); | ||
| 214 | +} | ||
| 215 | + | ||
| 216 | +TEST(ExpandIntoJaggedPermuteTiling950, RejectsOffsetLengthMismatch) | ||
| 217 | +{ | ||
| 218 | + gert::StorageShape permute = {{3}, {3}}; | ||
| 219 | + gert::StorageShape inputOffsets = {{5}, {5}}; | ||
| 220 | + gert::StorageShape outputOffsets = {{4}, {4}}; | ||
| 221 | + gert::StorageShape output = {{6}, {6}}; | ||
| 222 | + EXPECT_EQ(RunTiling(permute, inputOffsets, outputOffsets, output, 6).status, ge::GRAPH_FAILED); | ||
| 223 | +} | ||
| 224 | + | ||
| 225 | +TEST(ExpandIntoJaggedPermuteTiling950, RejectsNegativeOutputSize) | ||
| 226 | +{ | ||
| 227 | + gert::StorageShape permute = {{3}, {3}}; | ||
| 228 | + gert::StorageShape inputOffsets = {{4}, {4}}; | ||
| 229 | + gert::StorageShape outputOffsets = {{4}, {4}}; | ||
| 230 | + gert::StorageShape output = {{6}, {6}}; | ||
| 231 | + EXPECT_EQ(RunTiling(permute, inputOffsets, outputOffsets, output, -1).status, ge::GRAPH_FAILED); | ||
| 232 | +} | ||
| 233 | + | ||
| 234 | +TEST(ExpandIntoJaggedPermuteTiling950, AcceptsEmptyRelation) | ||
| 235 | +{ | ||
| 236 | + gert::StorageShape permute = {{0}, {0}}; | ||
| 237 | + gert::StorageShape inputOffsets = {{1}, {1}}; | ||
| 238 | + gert::StorageShape outputOffsets = {{1}, {1}}; | ||
| 239 | + gert::StorageShape output = {{0}, {0}}; | ||
| 240 | + const TilingResult result = RunTiling(permute, inputOffsets, outputOffsets, output, 0); | ||
| 241 | + ASSERT_EQ(result.status, ge::GRAPH_SUCCESS); | ||
| 242 | + EXPECT_EQ(result.data.segmentCount, 0); | ||
| 243 | + EXPECT_EQ(result.data.outputSize, 0); | ||
| 244 | + EXPECT_EQ(result.data.perCoreOutput, 0); | ||
| 245 | + EXPECT_EQ(result.data.needCoreNum, 1); | ||
| 246 | +} | ||
| 247 | + | ||
| 248 | +TEST(ExpandIntoJaggedPermuteTiling950, AcceptsPositiveMinimumOutput) | ||
| 249 | +{ | ||
| 250 | + gert::StorageShape permute = {{2}, {2}}; | ||
| 251 | + gert::StorageShape inputOffsets = {{3}, {3}}; | ||
| 252 | + gert::StorageShape outputOffsets = {{3}, {3}}; | ||
| 253 | + gert::StorageShape output = {{2}, {2}}; | ||
| 254 | + EXPECT_EQ(RunTiling(permute, inputOffsets, outputOffsets, output, 2).status, ge::GRAPH_SUCCESS); | ||
| 255 | +} | ||
| 256 | + | ||
| 257 | +TEST(ExpandIntoJaggedPermuteTiling950, RejectsInvalidSegmentOutputRelations) | ||
| 258 | +{ | ||
| 259 | + gert::StorageShape emptyPermute = {{0}, {0}}; | ||
| 260 | + gert::StorageShape emptyInputOffsets = {{1}, {1}}; | ||
| 261 | + gert::StorageShape emptyOutputOffsets = {{1}, {1}}; | ||
| 262 | + gert::StorageShape outputOne = {{1}, {1}}; | ||
| 263 | + EXPECT_EQ(RunTiling(emptyPermute, emptyInputOffsets, emptyOutputOffsets, outputOne, 1).status, ge::GRAPH_FAILED); | ||
| 264 | + | ||
| 265 | + gert::StorageShape permute = {{3}, {3}}; | ||
| 266 | + gert::StorageShape inputOffsets = {{4}, {4}}; | ||
| 267 | + gert::StorageShape outputOffsets = {{4}, {4}}; | ||
| 268 | + gert::StorageShape outputTwo = {{2}, {2}}; | ||
| 269 | + EXPECT_EQ(RunTiling(permute, inputOffsets, outputOffsets, outputTwo, 2).status, ge::GRAPH_FAILED); | ||
| 270 | +} | ||
| 271 | + | ||
| 272 | +TEST(ExpandIntoJaggedPermuteTiling950, RejectsOutputShapeMismatch) | ||
| 273 | +{ | ||
| 274 | + gert::StorageShape permute = {{3}, {3}}; | ||
| 275 | + gert::StorageShape inputOffsets = {{4}, {4}}; | ||
| 276 | + gert::StorageShape outputOffsets = {{4}, {4}}; | ||
| 277 | + gert::StorageShape output = {{5}, {5}}; | ||
| 278 | + EXPECT_EQ(RunTiling(permute, inputOffsets, outputOffsets, output, 6).status, ge::GRAPH_FAILED); | ||
| 279 | +} | ||
| 280 | + | ||
| 281 | +TEST(ExpandIntoJaggedPermuteTiling950, ValidatesOutputViewSpanOverflow) | ||
| 282 | +{ | ||
| 283 | + EXPECT_EQ(RunViewSpan(10, 1, 2), ge::GRAPH_SUCCESS); | ||
| 284 | + EXPECT_EQ(RunViewSpan(std::numeric_limits<int32_t>::max(), 0, std::numeric_limits<int64_t>::max()), | ||
| 285 | + ge::GRAPH_FAILED); | ||
| 286 | +} | ||
| @@ -1,13 +0,0 @@ | |||
| 1 | -# ---------------------------------------------------------------------------- | ||
| 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 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 | -if ((UT_TEST_ALL OR OP_KERNEL_UT) AND NOT UT_DONE) | ||
| 12 | - AddOpTestCase(expand_into_jagged_permute "ascend910B1" "-DDTYPE_PERMUTE=int32_t") | ||
| 13 | -endif() | ||
| @@ -0,0 +1,114 @@ | |||
| 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 | +// Execute the production SIMT functions serially to verify indexing and branch behavior. | ||
| 12 | +#include <algorithm> | ||
| 13 | +#include <cassert> | ||
| 14 | +#include <cstdint> | ||
| 15 | +#include <iostream> | ||
| 16 | +#include <numeric> | ||
| 17 | +#include <random> | ||
| 18 | +#include <vector> | ||
| 19 | +#include "expand_into_jagged_permute_simt.h" | ||
| 20 | + | ||
| 21 | +namespace { | ||
| 22 | +constexpr int32_t SENTINEL = -777; | ||
| 23 | +constexpr int64_t TEST_CORE_COUNT = 4; | ||
| 24 | +constexpr int64_t MIN_CORE_OUTPUT = 1024; | ||
| 25 | +constexpr int64_t WARP_SIZE = 32; | ||
| 26 | +constexpr size_t GUARD_ELEMENTS = 16; | ||
| 27 | +constexpr uint32_t RANDOM_SEED = 8583; | ||
| 28 | +constexpr int RANDOM_CASE_COUNT = 100; | ||
| 29 | +constexpr int MAX_SEGMENTS = 100; | ||
| 30 | +constexpr int MAX_SEGMENT_LENGTH = 500; | ||
| 31 | +constexpr int64_t STRIDED_OUTPUT = 3; | ||
| 32 | + | ||
| 33 | +void RunCase(std::vector<int32_t> permute, std::vector<int32_t> inputOffsets, std::vector<int32_t> outputOffsets, | ||
| 34 | + int64_t stride) | ||
| 35 | +{ | ||
| 36 | + const int64_t outputSize = outputOffsets.back(); | ||
| 37 | + const int64_t segments = static_cast<int64_t>(permute.size()); | ||
| 38 | + const int64_t ideal = (outputSize + TEST_CORE_COUNT - 1) / TEST_CORE_COUNT; | ||
| 39 | + const int64_t perCore = std::max(MIN_CORE_OUTPUT, (ideal + WARP_SIZE - 1) / WARP_SIZE * WARP_SIZE); | ||
| 40 | + const uint32_t cores = static_cast<uint32_t>((outputSize + perCore - 1) / perCore); | ||
| 41 | + std::vector<int32_t> actual(outputSize * stride + GUARD_ELEMENTS, SENTINEL); | ||
| 42 | + std::vector<int32_t> expected(actual.size(), SENTINEL); | ||
| 43 | + for (int64_t segment = 0; segment < segments; ++segment) { | ||
| 44 | + for (int64_t pos = outputOffsets[segment]; pos < outputOffsets[segment + 1]; ++pos) { | ||
| 45 | + expected[pos * stride] = inputOffsets[permute[segment]] + pos - outputOffsets[segment]; | ||
| 46 | + } | ||
| 47 | + } | ||
| 48 | + ExpandIntoJaggedPermuteTilingData tiling{segments, outputSize, perCore, stride, cores, 0}; | ||
| 49 | + for (uint32_t core = 0; core < cores; ++core) { | ||
| 50 | + AscendC::blockIdx.x = core; | ||
| 51 | + NsExpandIntoJaggedPermute::Process<int32_t>( | ||
| 52 | + reinterpret_cast<GM_ADDR>(permute.data()), reinterpret_cast<GM_ADDR>(inputOffsets.data()), | ||
| 53 | + reinterpret_cast<GM_ADDR>(outputOffsets.data()), reinterpret_cast<GM_ADDR>(actual.data()), &tiling); | ||
| 54 | + } | ||
| 55 | + // Also checks untouched stride padding and the trailing guard region. | ||
| 56 | + assert(actual == expected); | ||
| 57 | +} | ||
| 58 | +void CheckOverflowRejected(int64_t stride) | ||
| 59 | +{ | ||
| 60 | + // A three-element range starting at INT32_MAX - 1 cannot fit in INT32 output. | ||
| 61 | + std::vector<int32_t> permute{1, 0}; | ||
| 62 | + std::vector<int32_t> inputOffsets{0, INT32_MAX - 1, INT32_MAX}; | ||
| 63 | + std::vector<int32_t> outputOffsets{0, 3, 6}; | ||
| 64 | + constexpr int64_t OUTPUT_SIZE = 6; | ||
| 65 | + constexpr int64_t OVERFLOW_SEGMENT_LENGTH = 3; | ||
| 66 | + std::vector<int32_t> output(OUTPUT_SIZE * stride + GUARD_ELEMENTS, SENTINEL); | ||
| 67 | + ExpandIntoJaggedPermuteTilingData tiling{2, OUTPUT_SIZE, MIN_CORE_OUTPUT, stride, 1, 0}; | ||
| 68 | + AscendC::blockIdx.x = 0; | ||
| 69 | + NsExpandIntoJaggedPermute::Process<int32_t>( | ||
| 70 | + reinterpret_cast<GM_ADDR>(permute.data()), reinterpret_cast<GM_ADDR>(inputOffsets.data()), | ||
| 71 | + reinterpret_cast<GM_ADDR>(outputOffsets.data()), reinterpret_cast<GM_ADDR>(output.data()), &tiling); | ||
| 72 | + for (int64_t pos = 0; pos < OVERFLOW_SEGMENT_LENGTH * stride; ++pos) { | ||
| 73 | + assert(output[pos] == SENTINEL); | ||
| 74 | + } | ||
| 75 | + for (size_t pos = OUTPUT_SIZE * stride; pos < output.size(); ++pos) { | ||
| 76 | + assert(output[pos] == SENTINEL); | ||
| 77 | + } | ||
| 78 | +} | ||
| 79 | +} // namespace | ||
| 80 | + | ||
| 81 | +int main() | ||
| 82 | +{ | ||
| 83 | + using NsExpandIntoJaggedPermute::ShouldUseOutputCentric; | ||
| 84 | + constexpr int32_t LARGE_OUTPUT = 8192; | ||
| 85 | + constexpr int32_t HALF_OUTPUT = LARGE_OUTPUT / 2; | ||
| 86 | + constexpr int32_t INT32_MAX_VALUE = INT32_MAX; | ||
| 87 | + assert(ShouldUseOutputCentric(2, 4, 1)); | ||
| 88 | + assert(!ShouldUseOutputCentric(2, LARGE_OUTPUT, TEST_CORE_COUNT)); | ||
| 89 | + for (int64_t stride : {int64_t{1}, STRIDED_OUTPUT}) { | ||
| 90 | + // Target segments may be longer than their corresponding source segments. | ||
| 91 | + RunCase({0, 1}, {0, 1, 4}, {0, 2, 4}, stride); | ||
| 92 | + // Force segment-centric execution, including boundaries spanning multiple cores. | ||
| 93 | + RunCase({0, 1}, {0, 1, LARGE_OUTPUT}, {0, HALF_OUTPUT, LARGE_OUTPUT}, stride); | ||
| 94 | + // The final generated index may equal INT32_MAX without overflowing. | ||
| 95 | + RunCase({1, 0}, {0, INT32_MAX_VALUE - 1, INT32_MAX_VALUE}, {0, 2, 4}, stride); | ||
| 96 | + CheckOverflowRejected(stride); | ||
| 97 | + } | ||
| 98 | + std::mt19937 random(RANDOM_SEED); | ||
| 99 | + for (int trial = 0; trial < RANDOM_CASE_COUNT; ++trial) { | ||
| 100 | + const int segments = 1 + random() % MAX_SEGMENTS; | ||
| 101 | + std::vector<int32_t> permute(segments), inputOffsets(segments + 1), outputOffsets(segments + 1); | ||
| 102 | + std::iota(permute.begin(), permute.end(), 0); | ||
| 103 | + std::shuffle(permute.begin(), permute.end(), random); | ||
| 104 | + for (int i = 0; i < segments; ++i) { | ||
| 105 | + inputOffsets[i + 1] = inputOffsets[i] + 1 + random() % MAX_SEGMENT_LENGTH; | ||
| 106 | + } | ||
| 107 | + for (int i = 0; i < segments; ++i) { | ||
| 108 | + outputOffsets[i + 1] = outputOffsets[i] + inputOffsets[permute[i] + 1] - inputOffsets[permute[i]]; | ||
| 109 | + } | ||
| 110 | + RunCase(permute, inputOffsets, outputOffsets, 1); | ||
| 111 | + RunCase(permute, inputOffsets, outputOffsets, STRIDED_OUTPUT); | ||
| 112 | + } | ||
| 113 | + std::cout << "208 SIMT CPU regression cases passed (not device execution)\n"; | ||
| 114 | +} | ||
| @@ -0,0 +1,82 @@ | |||
| 1 | +#!/usr/bin/env python3 | ||
| 2 | +# | ||
| 3 | +# Copyright (c) 2026 Huawei Technologies Co., Ltd. | ||
| 4 | +# This program is free software, you can redistribute it and/or modify it under the terms and conditions of | ||
| 5 | +# CANN Open Software License Agreement Version 2.0 (the "License"). | ||
| 6 | +# Please refer to the License for details. You may not use this file except in compliance with the License. | ||
| 7 | +# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, | ||
| 8 | +# INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE. | ||
| 9 | +# See LICENSE in the root of the software repository for the full text of the License. | ||
| 10 | +# | ||
| 11 | +"""Compile and run the real SIMT header with serial CPU execution stubs. | ||
| 12 | + | ||
| 13 | +Run with python3 tests/ut/op_kernel/arch35/test_simt_cpu.py from the operator | ||
| 14 | +folder. Requires g++ (or CXX), and enables address/undefined-behavior sanitizers. | ||
| 15 | +This checks the C++ algorithm; it does not replace device compilation or testing. | ||
| 16 | +""" | ||
| 17 | + | ||
| 18 | +import os | ||
| 19 | +from pathlib import Path | ||
| 20 | +import shlex | ||
| 21 | +import subprocess | ||
| 22 | +import tempfile | ||
| 23 | +import unittest | ||
| 24 | + | ||
| 25 | + | ||
| 26 | +class SimtCpuRegression(unittest.TestCase): | ||
| 27 | + def test_index_generation(self): | ||
| 28 | + test_dir = Path(__file__).resolve().parent | ||
| 29 | + operator_dir = test_dir.parents[3] | ||
| 30 | + with tempfile.TemporaryDirectory(prefix="expand-jagged-simt-") as directory: | ||
| 31 | + build_dir = Path(directory) | ||
| 32 | + stubs = { | ||
| 33 | + "kernel_operator.h": r""" | ||
| 34 | +#pragma once | ||
| 35 | +#include <cstdint> | ||
| 36 | +#define __aicore__ | ||
| 37 | +#define __simt_callee__ | ||
| 38 | +#define __simt_vf__ | ||
| 39 | +#define __gm__ | ||
| 40 | +#define __launch_bounds__(x) | ||
| 41 | +using GM_ADDR = uint8_t*; | ||
| 42 | +namespace AscendC { | ||
| 43 | +struct dim3 { uint32_t x; explicit dim3(uint32_t value) : x(value) {} }; | ||
| 44 | +inline dim3 blockIdx(0), threadIdx(0), blockDim(1024); | ||
| 45 | +template<auto Function, typename... Args> void asc_vf_call(dim3 dims, Args... args) | ||
| 46 | +{ | ||
| 47 | + blockDim = dims; | ||
| 48 | + for (threadIdx.x = 0; threadIdx.x < dims.x; ++threadIdx.x) { | ||
| 49 | + Function(args...); | ||
| 50 | + } | ||
| 51 | +} | ||
| 52 | +} | ||
| 53 | +""", | ||
| 54 | + "kernel_tiling/kernel_tiling.h": "#pragma once\n", | ||
| 55 | + "simt_api/common_functions.h": "#pragma once\n", | ||
| 56 | + "ascendc/host_api/tiling/template_argument.h": ( | ||
| 57 | + "#pragma once\n#define ASCENDC_TPL_ARGS_DECL(...)\n#define ASCENDC_TPL_SEL(...)\n" | ||
| 58 | + ), | ||
| 59 | + } | ||
| 60 | + for relative, content in stubs.items(): | ||
| 61 | + path = build_dir / relative | ||
| 62 | + path.parent.mkdir(parents=True, exist_ok=True) | ||
| 63 | + path.write_text(content) | ||
| 64 | + executable = build_dir / "simt_cpu_cases" | ||
| 65 | + command = shlex.split(os.environ.get("CXX", "g++")) + [ | ||
| 66 | + "-std=c++17", | ||
| 67 | + "-O1", | ||
| 68 | + "-g", | ||
| 69 | + "-fsanitize=address,undefined", | ||
| 70 | + "-fno-sanitize-recover=all", | ||
| 71 | + "-I" + str(build_dir), | ||
| 72 | + "-I" + str(operator_dir / "op_kernel/arch35"), | ||
| 73 | + str(test_dir / "simt_cpu_cases.cpp"), | ||
| 74 | + "-o", | ||
| 75 | + str(executable), | ||
| 76 | + ] | ||
| 77 | + subprocess.run(command, check=True, timeout=120) | ||
| 78 | + subprocess.run([str(executable)], check=True, timeout=60) | ||
| 79 | + | ||
| 80 | + | ||
| 81 | +if __name__ == "__main__": | ||
| 82 | + unittest.main() | ||
| @@ -0,0 +1,21 @@ | |||
| 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 | +#ifndef EXPAND_INTO_JAGGED_PERMUTE_UT_TILING_DEF_H_ | ||
| 12 | +#define EXPAND_INTO_JAGGED_PERMUTE_UT_TILING_DEF_H_ | ||
| 13 | + | ||
| 14 | +#include "test_expand_into_jagged_permute_tiling_def.h" | ||
| 15 | + | ||
| 16 | +// AddOpTestCase force-includes <op_name>_tiling_def.h when present. Keep the | ||
| 17 | +// original UT data layout while providing the production type name expected by | ||
| 18 | +// the Ascend910 kernel source. | ||
| 19 | +using ExpandIntoJaggedPermuteTilingData = ExpandIntoJaggedPermuteTilingDataDef; | ||
| 20 | + | ||
| 21 | +#endif // EXPAND_INTO_JAGGED_PERMUTE_UT_TILING_DEF_H_ | ||
Mindex/expand_into_jagged_permute/tests/ut/op_kernel/test_expand_into_jagged_permute_tiling_def.h+1-1
| @@ -40,4 +40,4 @@ inline void InitExpandIntoJaggedPermuteTilingDataDef(uint8_t* tiling, ExpandInto | |||
| 40 | ExpandIntoJaggedPermuteTilingDataDef tiling_data; \ | 40 | ExpandIntoJaggedPermuteTilingDataDef tiling_data; \ |
| 41 | InitExpandIntoJaggedPermuteTilingDataDef(tiling_arg, &tiling_data) | 41 | InitExpandIntoJaggedPermuteTilingDataDef(tiling_arg, &tiling_data) |
| 42 | 42 | ||
| 43 | -#endif // _EXPAND_INTO_JAGGED_PERMUTE_TILING_H | 43 | +#endif // _EXPAND_INTO_JAGGED_PERMUTE_TILING_H |


确认下删除原因