已合并
新增算子:MaxPool3DWithArgmaxV2 #1525
小王!创建于 2月4日
新增算子:MaxPool3DWithArgmaxV2 #1525
已合并
从已删除 :migrate合入到cann/ops-nnmaster
共 48 个文件变更+70469-100
| @@ -1,5 +1,5 @@ | |||
| 1 | /** | 1 | /** |
| 2 | - * Copyright (c) 2025 Huawei Technologies Co., Ltd. | 2 | + * Copyright (c) 2025-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 | 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. |
| @@ -17,7 +17,8 @@ namespace l0op { | |||
| 17 | const std::tuple<const aclTensor*, const aclTensor*> MaxPool3DWithArgmaxV2Ncdhw(const aclTensor* self, const aclIntArray* kernelSize, | 17 | const std::tuple<const aclTensor*, const aclTensor*> MaxPool3DWithArgmaxV2Ncdhw(const aclTensor* self, const aclIntArray* kernelSize, |
| 18 | const aclIntArray* stride, const aclIntArray* padding, | 18 | const aclIntArray* stride, const aclIntArray* padding, |
| 19 | const aclIntArray* dilation, bool ceilMode, | 19 | const aclIntArray* dilation, bool ceilMode, |
| 20 | - std::string dataFormat, aclOpExecutor* executor); | 20 | + std::string dataFormat, aclOpExecutor* executor, |
| 21 | + op::DataType indicesDtype = op::DataType::DT_INT32); | ||
| 21 | } // namespace l0op | 22 | } // namespace l0op |
| 22 | 23 | ||
| 23 | 24 | ||
| @@ -1,5 +1,5 @@ | |||
| 1 | /** | 1 | /** |
| 2 | - * Copyright (c) 2025 Huawei Technologies Co., Ltd. | 2 | + * Copyright (c) 2025-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 | 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. |
| @@ -24,6 +24,7 @@ | |||
| 24 | 24 | ||
| 25 | 25 | ||
| 26 | 26 | ||
| 27 | + | ||
| 27 | 28 | ||
| 28 | using namespace op; | 29 | using namespace op; |
| 29 | 30 | ||
| @@ -34,6 +35,7 @@ static const std::initializer_list<DataType> NULL_SUPPORT_LIST = {}; | |||
| 34 | static const std::initializer_list<DataType> OUT_DTYPE_SUPPORT_LIST = { | 35 | static const std::initializer_list<DataType> OUT_DTYPE_SUPPORT_LIST = { |
| 35 | DataType::DT_BF16, DataType::DT_FLOAT16, DataType::DT_FLOAT}; | 36 | DataType::DT_BF16, DataType::DT_FLOAT16, DataType::DT_FLOAT}; |
| 36 | static const std::initializer_list<op::DataType> INDICES_DTYPE_SUPPORT_LIST = {op::DataType::DT_INT32}; | 37 | static const std::initializer_list<op::DataType> INDICES_DTYPE_SUPPORT_LIST = {op::DataType::DT_INT32}; |
| 38 | +static const std::initializer_list<op::DataType> INDICES_DTYPE_SUPPORT_LIST_REGBASE = {op::DataType::DT_INT32, op::DataType::DT_INT64}; | ||
| 37 | 39 | ||
| 38 | static const size_t CDHW_DIMS = 4; | 40 | static const size_t CDHW_DIMS = 4; |
| 39 | static const size_t NCDHW_DIMS = 5; | 41 | static const size_t NCDHW_DIMS = 5; |
| @@ -55,9 +57,8 @@ static bool CheckNotNullPtr( | |||
| 55 | 57 | ||
| 56 | static const std::initializer_list<DataType>& GetDtypeSupportList() | 58 | static const std::initializer_list<DataType>& GetDtypeSupportList() |
| 57 | { | 59 | { |
| 58 | - if (GetCurrentPlatformInfo().GetSocVersion() == SocVersion::ASCEND910B || | 60 | + auto curArch = GetCurrentPlatformInfo().GetCurNpuArch(); |
| 59 | - GetCurrentPlatformInfo().GetSocVersion() == SocVersion::ASCEND910_93 || | 61 | + if (curArch == NpuArch::DAV_2201 || Ops::NN::AclnnUtil::IsRegbase(curArch)) { |
| 60 | - Ops::NN::AclnnUtil::IsRegbase()) { | ||
| 61 | return OUT_DTYPE_SUPPORT_LIST; | 62 | return OUT_DTYPE_SUPPORT_LIST; |
| 62 | } else { | 63 | } else { |
| 63 | return NULL_SUPPORT_LIST; | 64 | return NULL_SUPPORT_LIST; |
| @@ -68,7 +69,11 @@ static bool CheckDtypeValid(const aclTensor* self, const aclTensor* out, const a | |||
| 68 | { | 69 | { |
| 69 | auto dtypeSupportList = GetDtypeSupportList(); | 70 | auto dtypeSupportList = GetDtypeSupportList(); |
| 70 | OP_CHECK_DTYPE_NOT_SUPPORT(self, dtypeSupportList, return false); | 71 | OP_CHECK_DTYPE_NOT_SUPPORT(self, dtypeSupportList, return false); |
| 71 | - OP_CHECK_DTYPE_NOT_SUPPORT(indices, INDICES_DTYPE_SUPPORT_LIST, return false); | 72 | + if (Ops::NN::AclnnUtil::IsRegbase()) { |
| 73 | + OP_CHECK_DTYPE_NOT_SUPPORT(indices, INDICES_DTYPE_SUPPORT_LIST_REGBASE, return false); | ||
| 74 | + } else { | ||
| 75 | + OP_CHECK_DTYPE_NOT_SUPPORT(indices, INDICES_DTYPE_SUPPORT_LIST, return false); | ||
| 76 | + } | ||
| 72 | OP_CHECK_DTYPE_NOT_SAME(self, out, return false); | 77 | OP_CHECK_DTYPE_NOT_SAME(self, out, return false); |
| 73 | return true; | 78 | return true; |
| 74 | } | 79 | } |
| @@ -95,6 +100,16 @@ static bool CheckFormat(const aclTensor* self, const aclTensor* out, const aclTe | |||
| 95 | return false; | 100 | return false; |
| 96 | } | 101 | } |
| 97 | 102 | ||
| 103 | + if (Ops::NN::AclnnUtil::IsRegbase()) { | ||
| 104 | + if (self->GetStorageFormat() != ge::FORMAT_NDHWC && self->GetStorageFormat() != ge::FORMAT_NCDHW && | ||
| 105 | + self->GetStorageFormat() != ge::FORMAT_NCHW && self->GetStorageFormat() != ge::FORMAT_ND) { | ||
| 106 | + OP_LOGE( | ||
| 107 | + ACLNN_ERR_PARAM_INVALID, "Format of input is not supported, self [%s].", | ||
| 108 | + op::ToString(self->GetStorageFormat()).GetString()); | ||
| 109 | + return false; | ||
| 110 | + } | ||
| 111 | + } | ||
| 112 | + | ||
| 98 | return true; | 113 | return true; |
| 99 | } | 114 | } |
| 100 | 115 | ||
| @@ -168,13 +183,16 @@ static bool CheckParamsValid( | |||
| 168 | const int64_t dilationD = dilationRef[0]; | 183 | const int64_t dilationD = dilationRef[0]; |
| 169 | const int64_t dilationH = (dilationRef.Size() == 1) ? dilationD : dilationRef[1]; | 184 | const int64_t dilationH = (dilationRef.Size() == 1) ? dilationD : dilationRef[1]; |
| 170 | const int64_t dilationW = (dilationRef.Size() == 1) ? dilationD : dilationRef[2]; | 185 | const int64_t dilationW = (dilationRef.Size() == 1) ? dilationD : dilationRef[2]; |
| 171 | - OP_CHECK( | 186 | + auto curArch = GetCurrentPlatformInfo().GetCurNpuArch(); |
| 172 | - ((dilationD == 1) && (dilationH == 1) && (dilationW == 1)), | 187 | + if (curArch == NpuArch::DAV_2201 || curArch == NpuArch::DAV_1001) { |
| 173 | - OP_LOGE( | 188 | + OP_CHECK( |
| 174 | - ACLNN_ERR_PARAM_INVALID, | 189 | + ((dilationD == 1) && (dilationH == 1) && (dilationW == 1)), |
| 175 | - "The value of dilation should be equal 1, but got dilationD:%ld, dilationH:%ld, dilationW:%ld", dilationD, | 190 | + OP_LOGE( |
| 176 | - dilationH, dilationW), | 191 | + ACLNN_ERR_PARAM_INVALID, |
| 177 | - return false); | 192 | + "The value of dilation should be equal 1, but got dilationD:%ld, dilationH:%ld, dilationW:%ld", dilationD, |
| 193 | + dilationH, dilationW), | ||
| 194 | + return false); | ||
| 195 | + } | ||
| 178 | 196 | ||
| 179 | return true; | 197 | return true; |
| 180 | } | 198 | } |
| @@ -192,9 +210,8 @@ static aclnnStatus CheckParams( | |||
| 192 | 210 | ||
| 193 | static bool CheckPlatform() | 211 | static bool CheckPlatform() |
| 194 | { | 212 | { |
| 195 | - if (GetCurrentPlatformInfo().GetSocVersion() == SocVersion::ASCEND910B || | 213 | + auto curArch = GetCurrentPlatformInfo().GetCurNpuArch(); |
| 196 | - GetCurrentPlatformInfo().GetSocVersion() == SocVersion::ASCEND910_93 || | 214 | + if (curArch == NpuArch::DAV_2201 || Ops::NN::AclnnUtil::IsRegbase(curArch)) { |
| 197 | - Ops::NN::AclnnUtil::IsRegbase()) { | ||
| 198 | return true; | 215 | return true; |
| 199 | } else { | 216 | } else { |
| 200 | OP_LOGE(ACLNN_ERR_PARAM_INVALID, "aclnnMaxPool3dWithArgmax is not supported on this platform"); | 217 | OP_LOGE(ACLNN_ERR_PARAM_INVALID, "aclnnMaxPool3dWithArgmax is not supported on this platform"); |
| @@ -251,7 +268,8 @@ aclnnStatus aclnnMaxPool3dWithArgmaxGetWorkspaceSize( | |||
| 251 | auto ret = CheckParams(self, kernelSize, stride, padding, dilation, out, indices); | 268 | auto ret = CheckParams(self, kernelSize, stride, padding, dilation, out, indices); |
| 252 | CHECK_RET(ret == ACLNN_SUCCESS, ret); | 269 | CHECK_RET(ret == ACLNN_SUCCESS, ret); |
| 253 | 270 | ||
| 254 | - std::string dataFormat = "NCDHW"; | 271 | + // Default to NCDHW |
| 272 | + std::string dataFormat = (self->GetStorageFormat() == ge::FORMAT_NDHWC) ? "NDHWC" : "NCDHW"; | ||
| 255 | 273 | ||
| 256 | // Check whether the tensor is empty (the operator does not support empty tensors) | 274 | // Check whether the tensor is empty (the operator does not support empty tensors) |
| 257 | if (self->IsEmpty() || out->IsEmpty()) { | 275 | if (self->IsEmpty() || out->IsEmpty()) { |
| @@ -272,8 +290,9 @@ aclnnStatus aclnnMaxPool3dWithArgmaxGetWorkspaceSize( | |||
| 272 | CHECK_RET(selfUnsqueezed != nullptr, ACLNN_ERR_INNER_NULLPTR); | 290 | CHECK_RET(selfUnsqueezed != nullptr, ACLNN_ERR_INNER_NULLPTR); |
| 273 | 291 | ||
| 274 | // Returns a tuple containing out and indices | 292 | // Returns a tuple containing out and indices |
| 293 | + auto indicesDtype = indices->GetDataType(); | ||
| 275 | auto [outResult, indicesResult] = l0op::MaxPool3DWithArgmaxV2Ncdhw( | 294 | auto [outResult, indicesResult] = l0op::MaxPool3DWithArgmaxV2Ncdhw( |
| 276 | - selfUnsqueezed, kernelSize, stride, padding, dilation, ceilMode, dataFormat, uniqueExecutor.get()); | 295 | + selfUnsqueezed, kernelSize, stride, padding, dilation, ceilMode, dataFormat, uniqueExecutor.get(), indicesDtype); |
| 277 | 296 | ||
| 278 | CHECK_RET(outResult != nullptr, ACLNN_ERR_INNER_NULLPTR); | 297 | CHECK_RET(outResult != nullptr, ACLNN_ERR_INNER_NULLPTR); |
| 279 | CHECK_RET(indicesResult != nullptr, ACLNN_ERR_INNER_NULLPTR); | 298 | CHECK_RET(indicesResult != nullptr, ACLNN_ERR_INNER_NULLPTR); |
| @@ -313,4 +332,4 @@ aclnnStatus aclnnMaxPool3dWithArgmax( | |||
| 313 | 332 | ||
| 314 | 333 | ||
| 315 | } | 334 | } |
| 316 | -#endif | 335 | +#endif |
| @@ -1,5 +1,5 @@ | |||
| 1 | /** | 1 | /** |
| 2 | - * Copyright (c) 2025 Huawei Technologies Co., Ltd. | 2 | + * Copyright (c) 2025-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 | 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. |
| @@ -1,5 +1,5 @@ | |||
| 1 | /** | 1 | /** |
| 2 | - * Copyright (c) 2025 Huawei Technologies Co., Ltd. | 2 | + * Copyright (c) 2025-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 | 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. |
| @@ -34,12 +34,15 @@ static const uint32_t NC = 2; | |||
| 34 | static const int64_t TWO_SIDED = 2; | 34 | static const int64_t TWO_SIDED = 2; |
| 35 | static const size_t DHW_DIMS = 3; | 35 | static const size_t DHW_DIMS = 3; |
| 36 | static const int64_t NCDHW_DIMS = 5; | 36 | static const int64_t NCDHW_DIMS = 5; |
| 37 | +static const int64_t NCDHW_D_OFFSET = 3; // Get D-index by totalDim - offset | ||
| 38 | +static const int64_t NDHWC_D_OFFSET = 4; | ||
| 39 | +static const int32_t DTYPE_INT32 = 3; | ||
| 40 | +static const int32_t DTYPE_INT64 = 9; | ||
| 37 | 41 | ||
| 38 | static const std::initializer_list<DataType> GetDtypeSupportListBySocVersion() | 42 | static const std::initializer_list<DataType> GetDtypeSupportListBySocVersion() |
| 39 | { | 43 | { |
| 40 | - if (GetCurrentPlatformInfo().GetSocVersion() == SocVersion::ASCEND910B || | 44 | + auto curArch = GetCurrentPlatformInfo().GetCurNpuArch(); |
| 41 | - GetCurrentPlatformInfo().GetSocVersion() == SocVersion::ASCEND910_93 || | 45 | + if (curArch == NpuArch::DAV_2201 || Ops::NN::AclnnUtil::IsRegbase(curArch)) { |
| 42 | - Ops::NN::AclnnUtil::IsRegbase()) { | ||
| 43 | return SELF_DTYPE_SUPPORT_LIST; | 46 | return SELF_DTYPE_SUPPORT_LIST; |
| 44 | } else { | 47 | } else { |
| 45 | return NULL_SUPPORT_LIST; | 48 | return NULL_SUPPORT_LIST; |
| @@ -55,6 +58,9 @@ static bool IsMaxPool3DWithArgmaxV2NcdhwAiCoreSupported(const aclTensor* self) | |||
| 55 | op::ToString(dtypeSupportList).GetString()); | 58 | op::ToString(dtypeSupportList).GetString()); |
| 56 | return false; | 59 | return false; |
| 57 | } | 60 | } |
| 61 | + if (Ops::NN::AclnnUtil::IsRegbase()) { | ||
| 62 | + return true; // Support for DHW exceeding max int32 | ||
| 63 | + } | ||
| 58 | op::Shape input_shape = self->GetViewShape(); | 64 | op::Shape input_shape = self->GetViewShape(); |
| 59 | int64_t dims = input_shape.GetDimNum(); | 65 | int64_t dims = input_shape.GetDimNum(); |
| 60 | const uint32_t batchesDims = dims == NCDHW_DIMS ? NC : C; | 66 | const uint32_t batchesDims = dims == NCDHW_DIMS ? NC : C; |
| @@ -76,9 +82,16 @@ static const std::tuple<aclTensor*, aclTensor*> MaxPool3DWithArgmaxV2NcdhwAiCore | |||
| 76 | MaxPool3DWithArgmaxV2NcdhwAiCore, self, kernelSize, stride, padding, dilation, ceilMode, dataFormat, out, | 82 | MaxPool3DWithArgmaxV2NcdhwAiCore, self, kernelSize, stride, padding, dilation, ceilMode, dataFormat, out, |
| 77 | indices); | 83 | indices); |
| 78 | 84 | ||
| 79 | - ADD_TO_LAUNCHER_LIST_AICORE( | 85 | + if (Ops::NN::AclnnUtil::IsRegbase()) { |
| 80 | - MaxPool3DWithArgmaxV2, OP_INPUT(self), OP_OUTPUT(out, indices), | 86 | + int32_t dtype = (indices->GetDataType() == op::DataType::DT_INT64) ? DTYPE_INT64 : DTYPE_INT32; |
| 81 | - OP_ATTR(kernelSize, stride, padding, dilation, ceilMode, dataFormat)); | 87 | + ADD_TO_LAUNCHER_LIST_AICORE( |
| 88 | + MaxPool3DWithArgmaxV2, OP_INPUT(self), OP_OUTPUT(out, indices), | ||
| 89 | + OP_ATTR(kernelSize, stride, padding, dilation, ceilMode, dataFormat, dtype)); | ||
| 90 | + } else { | ||
| 91 | + ADD_TO_LAUNCHER_LIST_AICORE( | ||
| 92 | + MaxPool3DWithArgmaxV2, OP_INPUT(self), OP_OUTPUT(out, indices), | ||
| 93 | + OP_ATTR(kernelSize, stride, padding, dilation, ceilMode, dataFormat)); | ||
| 94 | + } | ||
| 82 | return std::tuple<aclTensor*, aclTensor*>(out, indices); | 95 | return std::tuple<aclTensor*, aclTensor*>(out, indices); |
| 83 | } | 96 | } |
| 84 | 97 | ||
| @@ -114,7 +127,7 @@ static int64_t PoolingOutShape( | |||
| 114 | 127 | ||
| 115 | static op::Shape GetOutputShape( | 128 | static op::Shape GetOutputShape( |
| 116 | const aclTensor* self, const aclIntArray* kernelSize, const aclIntArray* stride, const aclIntArray* padding, | 129 | const aclTensor* self, const aclIntArray* kernelSize, const aclIntArray* stride, const aclIntArray* padding, |
| 117 | - const aclIntArray* dilation, bool ceilMode) | 130 | + const aclIntArray* dilation, bool ceilMode, std::string dataFormat) |
| 118 | { | 131 | { |
| 119 | op::Shape input_shape = self->GetViewShape(); | 132 | op::Shape input_shape = self->GetViewShape(); |
| 120 | int64_t dims = input_shape.GetDimNum(); | 133 | int64_t dims = input_shape.GetDimNum(); |
| @@ -123,7 +136,7 @@ static op::Shape GetOutputShape( | |||
| 123 | const aclIntArray& paddingRef = *padding; | 136 | const aclIntArray& paddingRef = *padding; |
| 124 | const aclIntArray& dilationRef = *dilation; | 137 | const aclIntArray& dilationRef = *dilation; |
| 125 | op::Shape outputShape; | 138 | op::Shape outputShape; |
| 126 | - const uint32_t batchesDims = dims == NCDHW_DIMS ? NC : C; | 139 | + const uint32_t batchesDims = dataFormat == "NDHWC" ? dims - NDHWC_D_OFFSET : dims - NCDHW_D_OFFSET; |
| 127 | int64_t curDim[DHW_DIMS]; | 140 | int64_t curDim[DHW_DIMS]; |
| 128 | 141 | ||
| 129 | curDim[0] = PoolingOutShape( | 142 | curDim[0] = PoolingOutShape( |
| @@ -133,17 +146,24 @@ static op::Shape GetOutputShape( | |||
| 133 | curDim[NC] = PoolingOutShape( | 146 | curDim[NC] = PoolingOutShape( |
| 134 | input_shape.GetDim(batchesDims + NC), kernelRef[NC], strideRef[NC], paddingRef[NC], dilationRef[NC], ceilMode); | 147 | input_shape.GetDim(batchesDims + NC), kernelRef[NC], strideRef[NC], paddingRef[NC], dilationRef[NC], ceilMode); |
| 135 | 148 | ||
| 136 | - if (dims == NCDHW_DIMS) { | 149 | + if (dataFormat == "NDHWC") { |
| 137 | - outputShape = {input_shape.GetDim(0), input_shape.GetDim(1), curDim[0], curDim[1], curDim[NC]}; | 150 | + if (dims == NCDHW_DIMS) { |
| 151 | + outputShape = {input_shape.GetDim(0), curDim[0], curDim[1], curDim[NC], input_shape.GetDim(4)}; | ||
| 152 | + } | ||
| 138 | } else { | 153 | } else { |
| 139 | - outputShape = {input_shape.GetDim(0), curDim[0], curDim[1], curDim[NC]}; | 154 | + if (dims == NCDHW_DIMS) { |
| 155 | + outputShape = {input_shape.GetDim(0), input_shape.GetDim(1), curDim[0], curDim[1], curDim[NC]}; | ||
| 156 | + } else { | ||
| 157 | + outputShape = {input_shape.GetDim(0), curDim[0], curDim[1], curDim[NC]}; | ||
| 158 | + } | ||
| 140 | } | 159 | } |
| 141 | return outputShape; | 160 | return outputShape; |
| 142 | } | 161 | } |
| 143 | 162 | ||
| 144 | const std::tuple<const aclTensor*, const aclTensor*> MaxPool3DWithArgmaxV2Ncdhw( | 163 | const std::tuple<const aclTensor*, const aclTensor*> MaxPool3DWithArgmaxV2Ncdhw( |
| 145 | const aclTensor* self, const aclIntArray* kernelSize, const aclIntArray* stride, const aclIntArray* padding, | 164 | const aclTensor* self, const aclIntArray* kernelSize, const aclIntArray* stride, const aclIntArray* padding, |
| 146 | - const aclIntArray* dilation, bool ceilMode, std::string dataFormat, aclOpExecutor* executor) | 165 | + const aclIntArray* dilation, bool ceilMode, std::string dataFormat, aclOpExecutor* executor, |
| 166 | + op::DataType indicesDtype) | ||
| 147 | { | 167 | { |
| 148 | const aclIntArray& kernelRef = *kernelSize; | 168 | const aclIntArray& kernelRef = *kernelSize; |
| 149 | const int64_t kernelD = kernelRef[0]; | 169 | const int64_t kernelD = kernelRef[0]; |
| @@ -175,10 +195,10 @@ const std::tuple<const aclTensor*, const aclTensor*> MaxPool3DWithArgmaxV2Ncdhw( | |||
| 175 | aclIntArray* padding3 = executor->AllocIntArray(paddingSizeData.data(), DHW_DIMS); | 195 | aclIntArray* padding3 = executor->AllocIntArray(paddingSizeData.data(), DHW_DIMS); |
| 176 | aclIntArray* dilation3 = executor->AllocIntArray(dilationSizeData.data(), DHW_DIMS); | 196 | aclIntArray* dilation3 = executor->AllocIntArray(dilationSizeData.data(), DHW_DIMS); |
| 177 | 197 | ||
| 178 | - op::Shape outShape = GetOutputShape(self, kernelSize3, stride3, padding3, dilation3, ceilMode); | 198 | + op::Shape outShape = GetOutputShape(self, kernelSize3, stride3, padding3, dilation3, ceilMode, dataFormat); |
| 179 | op::DataType outType = self->GetDataType(); | 199 | op::DataType outType = self->GetDataType(); |
| 180 | auto out = executor->AllocTensor(outShape, outType, self->GetViewFormat()); | 200 | auto out = executor->AllocTensor(outShape, outType, self->GetViewFormat()); |
| 181 | - auto indices = executor->AllocTensor(outShape, op::DataType::DT_INT32, self->GetViewFormat()); | 201 | + auto indices = executor->AllocTensor(outShape, indicesDtype, self->GetViewFormat()); |
| 182 | 202 | ||
| 183 | if (IsMaxPool3DWithArgmaxV2NcdhwAiCoreSupported(self)) { | 203 | if (IsMaxPool3DWithArgmaxV2NcdhwAiCoreSupported(self)) { |
| 184 | return MaxPool3DWithArgmaxV2NcdhwAiCore( | 204 | return MaxPool3DWithArgmaxV2NcdhwAiCore( |
| @@ -1,5 +1,5 @@ | |||
| 1 | /** | 1 | /** |
| 2 | - * Copyright (c) 2025 Huawei Technologies Co., Ltd. | 2 | + * Copyright (c) 2025-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 | 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. |
| @@ -16,7 +16,8 @@ | |||
| 16 | namespace l0op { | 16 | namespace l0op { |
| 17 | const std::tuple<const aclTensor*, const aclTensor*> MaxPool3DWithArgmaxV2Ncdhw( | 17 | const std::tuple<const aclTensor*, const aclTensor*> MaxPool3DWithArgmaxV2Ncdhw( |
| 18 | const aclTensor* self, const aclIntArray* kernelSize, const aclIntArray* stride, const aclIntArray* padding, | 18 | const aclTensor* self, const aclIntArray* kernelSize, const aclIntArray* stride, const aclIntArray* padding, |
| 19 | - const aclIntArray* dilation, bool ceilMode, std::string dataFormat, aclOpExecutor* executor); | 19 | + const aclIntArray* dilation, bool ceilMode, std::string dataFormat, aclOpExecutor* executor, |
| 20 | + op::DataType indicesDtype = op::DataType::DT_INT32); | ||
| 20 | } // namespace l0op | 21 | } // namespace l0op |
| 21 | 22 | ||
| 22 | 23 | ||
| @@ -0,0 +1,45 @@ | |||
| 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 common_dtype.h | ||
| 13 | + * \brief | ||
| 14 | + */ | ||
| 15 | + | ||
| 16 | + | ||
| 17 | + | ||
| 18 | + | ||
| 19 | + | ||
| 20 | + | ||
| 21 | + | ||
| 22 | +namespace optiling | ||
| 23 | +{ | ||
| 24 | +/** | ||
| 25 | + ** function: ConcatString | ||
| 26 | + */ | ||
| 27 | +template <typename T> | ||
| 28 | +std::string ConcatString(const T& arg) | ||
| 29 | +{ | ||
| 30 | + std::ostringstream oss; | ||
| 31 | + oss << arg; | ||
| 32 | + return oss.str(); | ||
| 33 | +} | ||
| 34 | + | ||
| 35 | +template <typename T, typename... Ts> | ||
| 36 | +std::string ConcatString(const T& arg, const Ts&... argLeft) | ||
| 37 | +{ | ||
| 38 | + std::ostringstream oss; | ||
| 39 | + oss << arg; | ||
| 40 | + oss << ConcatString(argLeft...); | ||
| 41 | + return oss.str(); | ||
| 42 | +} | ||
| 43 | +} //namespace optiling | ||
| 44 | + | ||
| 45 | + | ||
Mpooling/max_pool3d_with_argmax_v2/op_host/config/ascend910_93/max_pool3d_with_argmax_v2_binary.json+15-0
| @@ -67,6 +67,11 @@ | |||
| 67 | "name": "data_format", | 67 | "name": "data_format", |
| 68 | "dtype": "string", | 68 | "dtype": "string", |
| 69 | "value": "NCDHW" | 69 | "value": "NCDHW" |
| 70 | + }, | ||
| 71 | + { | ||
| 72 | + "name": "dtype", | ||
| 73 | + "dtype": "int", | ||
| 74 | + "value": 3 | ||
| 70 | } | 75 | } |
| 71 | ] | 76 | ] |
| 72 | }, | 77 | }, |
| @@ -136,6 +141,11 @@ | |||
| 136 | "name": "data_format", | 141 | "name": "data_format", |
| 137 | "dtype": "string", | 142 | "dtype": "string", |
| 138 | "value": "NCDHW" | 143 | "value": "NCDHW" |
| 144 | + }, | ||
| 145 | + { | ||
| 146 | + "name": "dtype", | ||
有新增attr,所有版本的二进制json都得对应修改,否则kernel会编译失败 ![]() ![]() | |||
| 147 | + "dtype": "int", | ||
| 148 | + "value": 3 | ||
| 139 | } | 149 | } |
| 140 | ] | 150 | ] |
| 141 | }, | 151 | }, |
| @@ -205,6 +215,11 @@ | |||
| 205 | "name": "data_format", | 215 | "name": "data_format", |
| 206 | "dtype": "string", | 216 | "dtype": "string", |
| 207 | "value": "NCDHW" | 217 | "value": "NCDHW" |
| 218 | + }, | ||
| 219 | + { | ||
| 220 | + "name": "dtype", | ||
| 221 | + "dtype": "int", | ||
| 222 | + "value": 3 | ||
| 208 | } | 223 | } |
| 209 | ] | 224 | ] |
| 210 | } | 225 | } |
Mpooling/max_pool3d_with_argmax_v2/op_host/config/ascend910b/max_pool3d_with_argmax_v2_binary.json+15-0
| @@ -67,6 +67,11 @@ | |||
| 67 | "name": "data_format", | 67 | "name": "data_format", |
| 68 | "dtype": "string", | 68 | "dtype": "string", |
| 69 | "value": "NCDHW" | 69 | "value": "NCDHW" |
| 70 | + }, | ||
| 71 | + { | ||
| 72 | + "name": "dtype", | ||
| 73 | + "dtype": "int", | ||
| 74 | + "value": 3 | ||
| 70 | } | 75 | } |
| 71 | ] | 76 | ] |
| 72 | }, | 77 | }, |
| @@ -136,6 +141,11 @@ | |||
| 136 | "name": "data_format", | 141 | "name": "data_format", |
| 137 | "dtype": "string", | 142 | "dtype": "string", |
| 138 | "value": "NCDHW" | 143 | "value": "NCDHW" |
| 144 | + }, | ||
| 145 | + { | ||
| 146 | + "name": "dtype", | ||
| 147 | + "dtype": "int", | ||
| 148 | + "value": 3 | ||
| 139 | } | 149 | } |
| 140 | ] | 150 | ] |
| 141 | }, | 151 | }, |
| @@ -205,6 +215,11 @@ | |||
| 205 | "name": "data_format", | 215 | "name": "data_format", |
| 206 | "dtype": "string", | 216 | "dtype": "string", |
| 207 | "value": "NCDHW" | 217 | "value": "NCDHW" |
| 218 | + }, | ||
| 219 | + { | ||
| 220 | + "name": "dtype", | ||
| 221 | + "dtype": "int", | ||
| 222 | + "value": 3 | ||
| 208 | } | 223 | } |
| 209 | ] | 224 | ] |
| 210 | } | 225 | } |
Mpooling/max_pool3d_with_argmax_v2/op_host/config/kirin9030/max_pool3d_with_argmax_v2_binary.json+10-0
| @@ -67,6 +67,11 @@ | |||
| 67 | "name": "data_format", | 67 | "name": "data_format", |
| 68 | "dtype": "string", | 68 | "dtype": "string", |
| 69 | "value": "NCDHW" | 69 | "value": "NCDHW" |
| 70 | + }, | ||
| 71 | + { | ||
| 72 | + "name": "dtype", | ||
| 73 | + "dtype": "int", | ||
| 74 | + "value": 3 | ||
| 70 | } | 75 | } |
| 71 | ] | 76 | ] |
| 72 | }, | 77 | }, |
| @@ -136,6 +141,11 @@ | |||
| 136 | "name": "data_format", | 141 | "name": "data_format", |
| 137 | "dtype": "string", | 142 | "dtype": "string", |
| 138 | "value": "NCDHW" | 143 | "value": "NCDHW" |
| 144 | + }, | ||
| 145 | + { | ||
| 146 | + "name": "dtype", | ||
| 147 | + "dtype": "int", | ||
| 148 | + "value": 3 | ||
| 139 | } | 149 | } |
| 140 | ] | 150 | ] |
| 141 | } | 151 | } |
Mpooling/max_pool3d_with_argmax_v2/op_host/config/kirinx90/max_pool3d_with_argmax_v2_binary.json+10-0
| @@ -67,6 +67,11 @@ | |||
| 67 | "name": "data_format", | 67 | "name": "data_format", |
| 68 | "dtype": "string", | 68 | "dtype": "string", |
| 69 | "value": "NCDHW" | 69 | "value": "NCDHW" |
| 70 | + }, | ||
| 71 | + { | ||
| 72 | + "name": "dtype", | ||
| 73 | + "dtype": "int", | ||
| 74 | + "value": 3 | ||
| 70 | } | 75 | } |
| 71 | ] | 76 | ] |
| 72 | }, | 77 | }, |
| @@ -136,6 +141,11 @@ | |||
| 136 | "name": "data_format", | 141 | "name": "data_format", |
| 137 | "dtype": "string", | 142 | "dtype": "string", |
| 138 | "value": "NCDHW" | 143 | "value": "NCDHW" |
| 144 | + }, | ||
| 145 | + { | ||
| 146 | + "name": "dtype", | ||
| 147 | + "dtype": "int", | ||
| 148 | + "value": 3 | ||
| 139 | } | 149 | } |
| 140 | ] | 150 | ] |
| 141 | } | 151 | } |
| @@ -0,0 +1,211 @@ | |||
| 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 max_pool3d_with_argmax_v2_gather_tiling.h | ||
| 13 | + * \brief | ||
| 14 | + */ | ||
| 15 | + | ||
| 16 | + | ||
| 17 | + | ||
| 18 | + | ||
| 19 | + | ||
| 20 | + | ||
| 21 | + | ||
| 22 | +namespace optiling | ||
| 23 | +{ | ||
| 24 | +struct MaxPool3DWithArgmaxV2GatherBaseInfo { | ||
| 25 | + int64_t inputBytes = 0; | ||
| 26 | + int64_t indexBytes = 0; | ||
| 27 | + int64_t availableUb = 0; | ||
| 28 | + int64_t totalCoreNum = 0; | ||
| 29 | + int64_t oneBlockNumT1 = 0; | ||
| 30 | + int64_t oneBlockNumT2 = 0; | ||
| 31 | + int64_t coreUsedForBestPerformance = 0; | ||
| 32 | + | ||
| 33 | + int64_t padFront = 0; | ||
| 34 | + int64_t padTop = 0; | ||
| 35 | + int64_t padLeft = 0; | ||
| 36 | + int64_t dStride = 0; | ||
| 37 | + int64_t hStride = 0; | ||
| 38 | + int64_t wStride = 0; | ||
| 39 | + int64_t dKernel = 0; | ||
| 40 | + int64_t hKernel = 0; | ||
| 41 | + int64_t wKernel = 0; | ||
| 42 | + int64_t dInput = 0; | ||
| 43 | + int64_t hInput = 0; | ||
| 44 | + int64_t wInput = 0; | ||
| 45 | + int64_t dOutput = 0; | ||
| 46 | + int64_t hOutput = 0; | ||
| 47 | + int64_t wOutput = 0; | ||
| 48 | + int64_t highAxisTotal = 0; | ||
| 49 | + int64_t isPad = 0; | ||
| 50 | + int64_t dDilation = 0; | ||
| 51 | + int64_t hDilation = 0; | ||
| 52 | + int64_t wDilation = 0; | ||
| 53 | + std::string ToString() const | ||
| 54 | + { | ||
| 55 | + std::stringstream info; | ||
| 56 | + info << "MaxPool3DWithArgmaxV2GatherBaseInfo {"; | ||
| 57 | + | ||
| 58 | + info << "inputBytes:" << inputBytes | ||
| 59 | + << ", indexBytes:" << indexBytes | ||
| 60 | + << ", availableUb:" << availableUb | ||
| 61 | + << ", totalCoreNum:" << totalCoreNum | ||
| 62 | + << ", oneBlockNumT1:" << oneBlockNumT1 | ||
| 63 | + << ", oneBlockNumT2:" << oneBlockNumT2 | ||
| 64 | + << ", coreUsedForBestPerformance:" << coreUsedForBestPerformance; | ||
| 65 | + | ||
| 66 | + info << ", padFront:" << padFront | ||
| 67 | + << ", padTop:" << padTop | ||
| 68 | + << ", padLeft:" << padLeft; | ||
| 69 | + | ||
| 70 | + info << ", dStride:" << dStride | ||
| 71 | + << ", hStride:" << hStride | ||
| 72 | + << ", wStride:" << wStride; | ||
| 73 | + | ||
| 74 | + info << ", dKernel:" << dKernel | ||
| 75 | + << ", hKernel:" << hKernel | ||
| 76 | + << ", wKernel:" << wKernel; | ||
| 77 | + | ||
| 78 | + info << ", dInput:" << dInput | ||
| 79 | + << ", hInput:" << hInput | ||
| 80 | + << ", wInput:" << wInput; | ||
| 81 | + | ||
| 82 | + info << ", dOutput:" << dOutput | ||
| 83 | + << ", hOutput:" << hOutput | ||
| 84 | + << ", wOutput:" << wOutput; | ||
| 85 | + | ||
| 86 | + info << ", highAxisTotal:" << highAxisTotal | ||
| 87 | + << ", isPad:" << isPad; | ||
| 88 | + | ||
| 89 | + info << ", dDilation:" << dDilation | ||
| 90 | + << ", hDilation:" << hDilation | ||
| 91 | + << ", wDilation:" << wDilation; | ||
| 92 | + info << " }"; | ||
| 93 | + return info.str(); | ||
| 94 | + } | ||
| 95 | +}; | ||
| 96 | + | ||
| 97 | +struct MaxPool3DWithArgmaxV2GatherSplitInfo { | ||
| 98 | + // InitializationVars | ||
| 99 | + int64_t highAxisInner = 0; | ||
| 100 | + int64_t highAxisTail = 0; | ||
| 101 | + int64_t highAxisOuter = 0; | ||
| 102 | + int64_t highAxisAligned = 0; | ||
| 103 | + | ||
| 104 | + // DoUBTiling | ||
| 105 | + int64_t dOutputInner = 0; | ||
| 106 | + int64_t dOutputTail = 0; | ||
| 107 | + int64_t dOutputOuter = 0; | ||
| 108 | + int64_t hOutputInner = 0; | ||
| 109 | + int64_t hOutputTail = 0; | ||
| 110 | + int64_t hOutputOuter = 0; | ||
| 111 | + int64_t wOutputInner = 0; | ||
| 112 | + int64_t wOutputTail = 0; | ||
| 113 | + int64_t wOutputOuter = 0; | ||
| 114 | + | ||
| 115 | + // DoBlockTiling | ||
| 116 | + int64_t normalCoreProcessNum = 0; | ||
| 117 | + int64_t tailCoreProcessNum = 0; | ||
| 118 | + int64_t usedCoreNum = 0; | ||
| 119 | + int64_t totalBaseBlockNum = 0; | ||
| 120 | + | ||
| 121 | + // DoBufferCalculate | ||
| 122 | + int64_t dInputInner = 0; | ||
| 123 | + int64_t hInputInner = 0; | ||
| 124 | + int64_t wInputInner = 0; | ||
| 125 | + int64_t baseBlockPlaneSizeAligned = 0; | ||
| 126 | + int64_t inputBufferSize = 0; | ||
| 127 | + int64_t maxValueBufferSize = 0; | ||
| 128 | + int64_t argmaxBufferSize = 0; | ||
| 129 | + int64_t totalBufferSize = 0; | ||
| 130 | + std::string ToString() const | ||
| 131 | + { | ||
| 132 | + std::stringstream info; | ||
| 133 | + info << "MaxPool3DWithArgmaxV2GatherSplitInfo {"; | ||
| 134 | + | ||
| 135 | + info << " highAxisInner:" << highAxisInner | ||
| 136 | + << ", highAxisTail:" << highAxisTail | ||
| 137 | + << ", highAxisOuter:" << highAxisOuter | ||
| 138 | + << ", highAxisAligned:" << highAxisAligned; | ||
| 139 | + | ||
| 140 | + info << ", dOutputInner:" << dOutputInner | ||
| 141 | + << ", dOutputTail:" << dOutputTail | ||
| 142 | + << ", dOutputOuter:" << dOutputOuter | ||
| 143 | + << ", hOutputInner:" << hOutputInner | ||
| 144 | + << ", hOutputTail:" << hOutputTail | ||
| 145 | + << ", hOutputOuter:" << hOutputOuter | ||
| 146 | + << ", wOutputInner:" << wOutputInner | ||
| 147 | + << ", wOutputTail:" << wOutputTail | ||
| 148 | + << ", wOutputOuter:" << wOutputOuter; | ||
| 149 | + | ||
| 150 | + info << ", normalCoreProcessNum:" << normalCoreProcessNum | ||
| 151 | + << ", tailCoreProcessNum:" << tailCoreProcessNum | ||
| 152 | + << ", usedCoreNum:" << usedCoreNum | ||
| 153 | + << ", totalBaseBlockNum:" << totalBaseBlockNum; | ||
| 154 | + | ||
| 155 | + info << ", dInputInner:" << dInputInner | ||
| 156 | + << ", hInputInner:" << hInputInner | ||
| 157 | + << ", wInputInner:" << wInputInner | ||
| 158 | + << ", baseBlockPlaneSizeAligned:" << baseBlockPlaneSizeAligned | ||
| 159 | + << ", inputBufferSize:" << inputBufferSize | ||
| 160 | + << ", maxValueBufferSize:" << maxValueBufferSize | ||
| 161 | + << ", argmaxBufferSize:" << argmaxBufferSize | ||
| 162 | + << ", totalBufferSize:" << totalBufferSize; | ||
| 163 | + | ||
| 164 | + info << " }"; | ||
| 165 | + return info.str(); | ||
| 166 | + } | ||
| 167 | +}; | ||
| 168 | + | ||
| 169 | +class MaxPool3DWithArgmaxV2GatherTiling : public MaxPool3DWithArgmaxV2BaseTiling | ||
| 170 | +{ | ||
| 171 | +public: | ||
| 172 | + explicit MaxPool3DWithArgmaxV2GatherTiling(gert::TilingContext* context) : MaxPool3DWithArgmaxV2BaseTiling(context) | ||
| 173 | + { | ||
| 174 | + } | ||
| 175 | + | ||
| 176 | + ~MaxPool3DWithArgmaxV2GatherTiling() override | ||
| 177 | + { | ||
| 178 | + } | ||
| 179 | + | ||
| 180 | +private: | ||
| 181 | + void DoUBTiling(); | ||
| 182 | + void InitializationVars(); | ||
| 183 | + bool IsMeetTargetCoreNum() const; | ||
| 184 | + void SearchBestTiling(); | ||
| 185 | + bool IsMeetUBSize(); | ||
| 186 | + void SetTilingData(); | ||
| 187 | + void BinarySearch(int64_t start, int64_t end, int64_t* value); | ||
| 188 | + bool TrySplitNC(); | ||
| 189 | + bool TrySplitD(); | ||
| 190 | + bool TrySplitH(); | ||
| 191 | + bool TrySplitW(); | ||
| 192 | + uint64_t GetTilingKey() const override; | ||
| 193 | + void PrintBaseData() const; | ||
| 194 | + void PrintSplitData() const; | ||
| 195 | + void DoBlockTiling(); | ||
| 196 | + void DoBufferCalculate(); | ||
| 197 | + bool IsCapable() override; | ||
| 198 | + ge::graphStatus GetPlatformInfo() override; | ||
| 199 | + ge::graphStatus DoOpTiling() override; | ||
| 200 | + ge::graphStatus PostTiling() override; | ||
| 201 | + ge::graphStatus GetShapeAttrsInfo() override; | ||
| 202 | + | ||
| 203 | + MaxPool3DWithArgmaxV2Tiling::MaxPool3DWithArgmaxV2GatherTilingData* tilingData_ = | ||
| 204 | + context_->GetTilingData<MaxPool3DWithArgmaxV2Tiling::MaxPool3DWithArgmaxV2GatherTilingData>(); | ||
| 205 | + MaxPool3DWithArgmaxV2GatherBaseInfo baseData_; | ||
| 206 | + MaxPool3DWithArgmaxV2GatherSplitInfo splitData_; | ||
| 207 | +}; | ||
| 208 | + | ||
| 209 | +} // namespace optiling | ||
| 210 | + | ||
| 211 | + | ||
| @@ -0,0 +1,217 @@ | |||
| 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 max_pool3d_with_argmax_v2_infershape.cpp | ||
| 13 | + * \brief | ||
| 14 | + */ | ||
| 15 | + | ||
| 16 | + | ||
| 17 | + | ||
| 18 | + | ||
| 19 | + | ||
| 20 | + | ||
| 21 | + | ||
| 22 | + | ||
| 23 | + | ||
| 24 | + | ||
| 25 | +using namespace ge; | ||
| 26 | + | ||
| 27 | +namespace ops | ||
| 28 | +{ | ||
| 29 | +static constexpr size_t INDEX_KSIZE = 0; | ||
| 30 | +static constexpr size_t INDEX_STRIDES = 1; | ||
| 31 | +static constexpr size_t INDEX_PADS = 2; | ||
| 32 | +static constexpr size_t INDEX_DILATION = 3; | ||
| 33 | +static constexpr size_t INDEX_CEIL_MODE = 4; | ||
| 34 | +static constexpr size_t INDEX_DATA_FORMAT = 5; | ||
| 35 | +static constexpr size_t INDEX_DTYPE = 6; | ||
| 36 | +static constexpr size_t ATTR_LIST_SHAPE_SIZE = 3; | ||
| 37 | +static constexpr size_t INDEX_OUT_MAX = 0; | ||
| 38 | +static constexpr size_t INDEX_OUT_INDICES = 1; | ||
| 39 | +static constexpr size_t PARAM_NUM = 4; | ||
| 40 | +static constexpr size_t PARAM_D_DIM = 0; | ||
| 41 | +static constexpr size_t PARAM_H_DIM = 1; | ||
| 42 | +static constexpr size_t PARAM_W_DIM = 2; | ||
| 43 | +static constexpr size_t SHAPE_D_DIM = 2; | ||
| 44 | +static constexpr size_t SHAPE_H_DIM = 3; | ||
| 45 | +static constexpr size_t SHAPE_W_DIM = 4; | ||
| 46 | +static constexpr size_t CDHW_DIM = 4; | ||
| 47 | +static constexpr size_t INT32_DTYPE = 3; | ||
| 48 | +static constexpr size_t INT64_DTYPE = 9; | ||
| 49 | + | ||
| 50 | +static int64_t DivRtn(int64_t x, int64_t y) | ||
| 51 | +{ | ||
| 52 | + if (y == 0) { | ||
| 53 | + OP_LOGE("MaxPool3DWithArgmaxV2", "strides value cannot be zero."); | ||
| 54 | + return GRAPH_FAILED; | ||
| 55 | + } | ||
| 56 | + if (x < 0) { | ||
| 57 | + OP_LOGE("MaxPool3DWithArgmaxV2", "x value cannot small than zero."); | ||
| 58 | + return GRAPH_FAILED; | ||
| 59 | + } | ||
| 60 | + int64_t q = x / y; | ||
| 61 | + return q; | ||
| 62 | +} | ||
| 63 | + | ||
| 64 | +static void UpdateMaxShape(const int64_t (¶m)[PARAM_NUM], bool ceil_mode, const int64_t& dim_size, | ||
| 65 | + int64_t& out_max_shape) | ||
| 66 | +{ | ||
| 67 | + int64_t ksize = param[INDEX_KSIZE]; | ||
| 68 | + int64_t strides = param[INDEX_STRIDES]; | ||
| 69 | + int64_t pad = param[INDEX_PADS]; | ||
| 70 | + int64_t dilation = param[PARAM_NUM - 1]; | ||
| 71 | + int64_t exact_size = dim_size + 2 * pad - dilation * (ksize - 1) - 1 + (ceil_mode ? (strides - 1) : 0); | ||
| 72 | + out_max_shape = DivRtn(exact_size, strides) + 1; | ||
| 73 | + if (ceil_mode) { | ||
| 74 | + if ((out_max_shape - 1) * strides >= dim_size + pad) { | ||
| 75 | + out_max_shape = out_max_shape - 1; | ||
| 76 | + } | ||
| 77 | + } | ||
| 78 | +} | ||
| 79 | + | ||
| 80 | +ge::graphStatus InferShape4MaxPool3DWithArgmaxV2(gert::InferShapeContext* context) | ||
| 81 | +{ | ||
| 82 | + OP_LOGD(context->GetNodeName(), "runtime2.0 MaxPool3DWithArgmaxV2 infershape running"); | ||
| 83 | + auto src_td = context->GetInputDesc(0); | ||
| 84 | + OPS_CHECK_NULL_WITH_CONTEXT(context, src_td); | ||
| 85 | + auto input_format = src_td->GetOriginFormat(); | ||
| 86 | + auto indices_td = context->GetOutputDesc(INDEX_OUT_INDICES); | ||
| 87 | + OPS_CHECK_NULL_WITH_CONTEXT(context, indices_td); | ||
| 88 | + auto indices_dtype = indices_td->GetDataType(); | ||
| 89 | + OP_LOGD(context->GetNodeName(), "indices_dtype = %d", indices_dtype); | ||
| 90 | + OP_CHECK_IF(input_format != FORMAT_ND && input_format != FORMAT_NCDHW && input_format != FORMAT_NDHWC, | ||
| 91 | + OP_LOGE(context->GetNodeName(), "format only supports ND, NCDHW, NDHWC"), | ||
| 92 | + return GRAPH_FAILED); | ||
| 93 | + | ||
| 94 | + size_t param_d_dim = PARAM_D_DIM; | ||
| 95 | + size_t param_h_dim = PARAM_H_DIM; | ||
| 96 | + size_t param_w_dim = PARAM_W_DIM; | ||
| 97 | + size_t input_d_dim = SHAPE_D_DIM; | ||
| 98 | + size_t input_h_dim = SHAPE_H_DIM; | ||
| 99 | + size_t input_w_dim = SHAPE_W_DIM; | ||
| 100 | + | ||
| 101 | + auto attrs = context->GetAttrs(); | ||
| 102 | + OPS_CHECK_NULL_WITH_CONTEXT(context, attrs); | ||
| 103 | + | ||
| 104 | + auto ksize = attrs->GetAttrPointer<gert::ContinuousVector>(INDEX_KSIZE); | ||
| 105 | + OPS_CHECK_NULL_WITH_CONTEXT(context, ksize); | ||
| 106 | + std::string errMsg4Ksize = optiling::ConcatString("Length of ksize ", ksize->GetSize(), " must be 3!"); | ||
| 107 | + OP_CHECK_IF(ksize->GetSize() != ATTR_LIST_SHAPE_SIZE, | ||
| 108 | + OP_LOGE(context->GetNodeName(), "%s", errMsg4Ksize.c_str()), return GRAPH_FAILED); | ||
| 109 | + auto ksize_data = reinterpret_cast<const int64_t*>(ksize->GetData()); | ||
| 110 | + | ||
| 111 | + auto strides = attrs->GetAttrPointer<gert::ContinuousVector>(INDEX_STRIDES); | ||
| 112 | + OPS_CHECK_NULL_WITH_CONTEXT(context, strides); | ||
| 113 | + std::string errMsg4Strides = optiling::ConcatString("Length of strides ", strides->GetSize(), " must be 3!"); | ||
| 114 | + OP_CHECK_IF(strides->GetSize() != ATTR_LIST_SHAPE_SIZE, | ||
| 115 | + OP_LOGE(context->GetNodeName(), "%s", errMsg4Strides.c_str()), return GRAPH_FAILED); | ||
| 116 | + auto strides_data = reinterpret_cast<const int64_t*>(strides->GetData()); | ||
| 117 | + | ||
| 118 | + auto pads = attrs->GetAttrPointer<gert::ContinuousVector>(INDEX_PADS); | ||
| 119 | + OPS_CHECK_NULL_WITH_CONTEXT(context, pads); | ||
| 120 | + std::string errMsg4Pads = optiling::ConcatString("Length of pads ", pads->GetSize(), " must be 3!"); | ||
| 121 | + OP_CHECK_IF(pads->GetSize() != ATTR_LIST_SHAPE_SIZE, | ||
| 122 | + OP_LOGE(context->GetNodeName(), "%s", errMsg4Pads.c_str()), return GRAPH_FAILED); | ||
| 123 | + auto pads_data = reinterpret_cast<const int64_t*>(pads->GetData()); | ||
| 124 | + | ||
| 125 | + auto dilation = attrs->GetAttrPointer<gert::ContinuousVector>(INDEX_DILATION); | ||
| 126 | + OPS_CHECK_NULL_WITH_CONTEXT(context, dilation); | ||
| 127 | + std::string errMsg4Dilation = optiling::ConcatString("Length of dilation ", dilation->GetSize(), " must be 3!"); | ||
| 128 | + OP_CHECK_IF(dilation->GetSize() != ATTR_LIST_SHAPE_SIZE, | ||
| 129 | + OP_LOGE(context->GetNodeName(), "%s", errMsg4Dilation.c_str()), return GRAPH_FAILED); | ||
| 130 | + auto dilation_data = reinterpret_cast<const int64_t*>(dilation->GetData()); | ||
| 131 | + | ||
| 132 | + auto ceil_mode = attrs->GetAttrPointer<bool>(INDEX_CEIL_MODE); | ||
| 133 | + OPS_CHECK_NULL_WITH_CONTEXT(context, ceil_mode); | ||
| 134 | + | ||
| 135 | + const char* data_format = attrs->GetAttrPointer<char>(INDEX_DATA_FORMAT); | ||
| 136 | + OPS_CHECK_NULL_WITH_CONTEXT(context, data_format); | ||
| 137 | + | ||
| 138 | + std::string data_format_str = data_format; | ||
| 139 | + if (data_format_str == "NDHWC") { | ||
| 140 | + input_d_dim = input_d_dim - 1; | ||
| 141 | + input_h_dim = input_h_dim - 1; | ||
| 142 | + input_w_dim = input_w_dim - 1; | ||
| 143 | + } | ||
| 144 | + | ||
| 145 | + const gert::Shape* in_shape = context->GetInputShape(0); | ||
| 146 | + OPS_CHECK_NULL_WITH_CONTEXT(context, in_shape); | ||
| 147 | + gert::Shape* out_max_shape = context->GetOutputShape(INDEX_OUT_MAX); | ||
| 148 | + OPS_CHECK_NULL_WITH_CONTEXT(context, out_max_shape); | ||
| 149 | + *out_max_shape = *in_shape; | ||
| 150 | + gert::Shape* out_indices_shape = context->GetOutputShape(INDEX_OUT_INDICES); | ||
| 151 | + OPS_CHECK_NULL_WITH_CONTEXT(context, out_indices_shape); | ||
| 152 | + *out_indices_shape = *in_shape; | ||
| 153 | + | ||
| 154 | + if (Ops::Base::IsUnknownRank(*in_shape) || Ops::Base::IsUnknownShape(*in_shape)) { | ||
| 155 | + OP_LOGD(context->GetNodeName(), "runtime2.0 MaxPool3DWithArgmaxV2 infershape handle unknown rank or shape."); | ||
| 156 | + return ge::GRAPH_SUCCESS; | ||
| 157 | + } | ||
| 158 | + | ||
| 159 | + size_t dim_num = in_shape->GetDimNum(); | ||
| 160 | + int64_t max_dim = 0; | ||
| 161 | + if (dim_num == CDHW_DIM) { | ||
| 162 | + input_d_dim = input_d_dim - 1; | ||
| 163 | + input_h_dim = input_h_dim - 1; | ||
| 164 | + input_w_dim = input_w_dim - 1; | ||
| 165 | + } | ||
| 166 | + for (size_t i = 0; i < dim_num; i++) { | ||
| 167 | + int64_t input_dim = in_shape->GetDim(i); | ||
| 168 | + if (i == input_d_dim) { | ||
| 169 | + int64_t param[PARAM_NUM] = {ksize_data[param_d_dim], strides_data[param_d_dim], pads_data[param_d_dim], | ||
| 170 | + dilation_data[param_d_dim]}; | ||
| 171 | + UpdateMaxShape(param, *ceil_mode, input_dim, max_dim); | ||
| 172 | + out_max_shape->SetDim(i, max_dim); | ||
| 173 | + out_indices_shape->SetDim(i, max_dim); | ||
| 174 | + } else if (i == input_h_dim) { | ||
| 175 | + int64_t param[PARAM_NUM] = {ksize_data[param_h_dim], strides_data[param_h_dim], pads_data[param_h_dim], | ||
| 176 | + dilation_data[param_h_dim]}; | ||
| 177 | + UpdateMaxShape(param, *ceil_mode, input_dim, max_dim); | ||
| 178 | + out_max_shape->SetDim(i, max_dim); | ||
| 179 | + out_indices_shape->SetDim(i, max_dim); | ||
| 180 | + } else if (i == input_w_dim) { | ||
| 181 | + int64_t param[PARAM_NUM] = {ksize_data[param_w_dim], strides_data[param_w_dim], pads_data[param_w_dim], | ||
| 182 | + dilation_data[param_w_dim]}; | ||
| 183 | + UpdateMaxShape(param, *ceil_mode, input_dim, max_dim); | ||
| 184 | + out_max_shape->SetDim(i, max_dim); | ||
| 185 | + out_indices_shape->SetDim(i, max_dim); | ||
| 186 | + } else { | ||
| 187 | + out_max_shape->SetDim(i, input_dim); | ||
| 188 | + out_indices_shape->SetDim(i, input_dim); | ||
| 189 | + } | ||
| 190 | + } | ||
| 191 | + OP_LOGD(context->GetNodeName(), "runtime2.0 MaxPool3DWithArgmaxV2 infershape run success."); | ||
| 192 | + return GRAPH_SUCCESS; | ||
| 193 | +} | ||
| 194 | + | ||
| 195 | +static ge::graphStatus InferDataType4MaxPool3DWithArgmaxV2(gert::InferDataTypeContext* context) | ||
| 196 | +{ | ||
| 197 | + if (context == nullptr) { | ||
| 198 | + return GRAPH_FAILED; | ||
| 199 | + } | ||
| 200 | + const ge::DataType x = context->GetInputDataType(0); | ||
| 201 | + context->SetOutputDataType(INDEX_OUT_MAX, x); | ||
| 202 | + | ||
| 203 | + auto attrsPtr = context->GetAttrs(); | ||
| 204 | + OPS_CHECK_NULL_WITH_CONTEXT(context, attrsPtr); | ||
| 205 | + const int64_t* dstDtype = attrsPtr->GetAttrPointer<int64_t>(INDEX_DTYPE); | ||
| 206 | + OPS_CHECK_NULL_WITH_CONTEXT(context, dstDtype); | ||
| 207 | + ge::DataType indicesDtype = *dstDtype == INT32_DTYPE ? ge::DT_INT32 : ge::DT_INT64; | ||
| 208 | + | ||
| 209 | + context->SetOutputDataType(INDEX_OUT_INDICES, indicesDtype); | ||
| 210 | + | ||
| 211 | + return GRAPH_SUCCESS; | ||
| 212 | +} | ||
| 213 | + | ||
| 214 | +IMPL_OP_INFERSHAPE(MaxPool3DWithArgmaxV2) | ||
| 215 | + .InferShape(InferShape4MaxPool3DWithArgmaxV2) | ||
| 216 | + .InferDataType(InferDataType4MaxPool3DWithArgmaxV2); | ||
| 217 | +} // namespace ops | ||
Mpooling/max_pool3d_with_argmax_v2/op_host/max_pool3d_with_argmax_v2_no_expand_indices_tiling.cpp+9-2
| @@ -1,5 +1,5 @@ | |||
| 1 | /** | 1 | /** |
| 2 | - * Copyright (c) 2025 Huawei Technologies Co., Ltd. | 2 | + * Copyright (c) 2025-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 | 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. |
| @@ -13,6 +13,7 @@ | |||
| 13 | * \brief | 13 | * \brief |
| 14 | */ | 14 | */ |
| 15 | 15 | ||
| 16 | + | ||
| 16 | 17 | ||
| 17 | 18 | ||
| 18 | namespace optiling { | 19 | namespace optiling { |
| @@ -122,6 +123,12 @@ void MaxPool3DWithArgmaxV2NoExpandIndicesTiling::DoOutputPadAdjustment() | |||
| 122 | 123 | ||
| 123 | bool MaxPool3DWithArgmaxV2NoExpandIndicesTiling::IsCapable() | 124 | bool MaxPool3DWithArgmaxV2NoExpandIndicesTiling::IsCapable() |
| 124 | { | 125 | { |
| 126 | + auto platformInfo = context_->GetPlatformInfo(); | ||
| 127 | + OP_CHECK_NULL_WITH_CONTEXT(context_, platformInfo); | ||
| 128 | + auto ascendcPlatform = platform_ascendc::PlatformAscendC(platformInfo); | ||
| 129 | + if (Ops::NN::OpTiling::IsRegbaseSocVersion(context_)){ | ||
| 130 | + return false; | ||
| 131 | + } | ||
| 125 | if (inputData.dilation[D_DIM] != 1 || inputData.dilation[H_DIM] != 1 || inputData.dilation[W_DIM] != 1) { | 132 | if (inputData.dilation[D_DIM] != 1 || inputData.dilation[H_DIM] != 1 || inputData.dilation[W_DIM] != 1) { |
| 126 | return false; | 133 | return false; |
| 127 | } | 134 | } |
| @@ -371,6 +378,6 @@ ge::graphStatus MaxPool3DWithArgmaxV2NoExpandIndicesTiling::PostTiling() | |||
| 371 | return ge::GRAPH_SUCCESS; | 378 | return ge::GRAPH_SUCCESS; |
| 372 | } | 379 | } |
| 373 | 380 | ||
| 374 | -REGISTER_TILING_TEMPLATE("MaxPool3DWithArgmaxV2", MaxPool3DWithArgmaxV2NoExpandIndicesTiling, 0); | 381 | +REGISTER_TILING_TEMPLATE("MaxPool3DWithArgmaxV2", MaxPool3DWithArgmaxV2NoExpandIndicesTiling, 10); |
| 375 | 382 | ||
| 376 | } // namespace optiling | 383 | } // namespace optiling |
| @@ -0,0 +1,102 @@ | |||
| 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 max_pool3d_with_argmax_v2_simt_tiling.h | ||
| 13 | + * \brief simt imply for max_pool3d_with_argmax | ||
| 14 | + */ | ||
| 15 | + | ||
| 16 | + | ||
| 17 | + | ||
| 18 | + | ||
| 19 | + | ||
| 20 | + | ||
| 21 | + | ||
| 22 | +namespace optiling | ||
| 23 | +{ | ||
| 24 | +const int64_t NCDHW_DIMS = 5; | ||
| 25 | +const int64_t KERNEL_POS = 0; | ||
| 26 | +const int64_t STRIDE_POS = 1; | ||
| 27 | +const int64_t PADDING_POS = 2; | ||
| 28 | +const int64_t DILATION_POS = 3; | ||
| 29 | +const int64_t CEIL_POS = 4; | ||
| 30 | +const int64_t FORMAT_POS = 5; | ||
| 31 | +const int64_t N_DIM_ = 0; | ||
| 32 | +const int64_t C_DIM_ = 1; | ||
| 33 | +const int64_t D_DIM_ = 2; | ||
| 34 | +const int64_t H_DIM_ = 3; | ||
| 35 | +const int64_t W_DIM_ = 4; | ||
| 36 | +const int64_t D_IDX_ = 0; | ||
| 37 | +const int64_t H_IDX_ = 1; | ||
| 38 | +const int64_t W_IDX_ = 2; | ||
| 39 | +const int64_t DOUB = 2; | ||
| 40 | +const int64_t FIRPOS = 0; | ||
| 41 | +const int64_t SECPOS = 1; | ||
| 42 | +constexpr int64_t MAX_INT32 = 2147483647; | ||
| 43 | +constexpr uint64_t SIMT_NCDHW_TILING_KEY_INT32 = 600001; | ||
| 44 | +constexpr uint64_t SIMT_NDHWC_TILING_KEY_INT32 = 600002; | ||
| 45 | +constexpr uint64_t SIMT_NCDHW_TILING_KEY_INT64 = 600011; | ||
| 46 | +constexpr uint64_t SIMT_NDHWC_TILING_KEY_INT64 = 600012; | ||
| 47 | +constexpr int64_t MAX_THREAD_NUM = 256; | ||
| 48 | +constexpr size_t SYS_WORKSPACE_SIZE = 16 * 1024 * 1024; | ||
| 49 | + | ||
| 50 | +struct InputSIMTInfo { | ||
| 51 | + array<uint64_t, NCDHW_DIMS> inputShape; | ||
| 52 | + array<uint64_t, NCDHW_DIMS> outShape; | ||
| 53 | + array<uint64_t, DHW_DIMS> kernelSize; | ||
| 54 | + array<uint64_t, DHW_DIMS> stride; | ||
| 55 | + array<uint64_t, DHW_DIMS> pad; | ||
| 56 | + array<uint64_t, DHW_DIMS> dilation; | ||
| 57 | + bool ceilMode; | ||
| 58 | + std::string data_format; | ||
| 59 | +}; | ||
| 60 | + | ||
| 61 | +class MaxPool3DWithArgmaxV2TilingSIMT : public MaxPool3DWithArgmaxV2BaseTiling | ||
| 62 | +{ | ||
| 63 | +public: | ||
| 64 | + explicit MaxPool3DWithArgmaxV2TilingSIMT(gert::TilingContext* context) : MaxPool3DWithArgmaxV2BaseTiling(context) | ||
| 65 | + { | ||
| 66 | + } | ||
| 67 | + | ||
| 68 | + ~MaxPool3DWithArgmaxV2TilingSIMT() override | ||
| 69 | + { | ||
| 70 | + } | ||
| 71 | + | ||
| 72 | +protected: | ||
| 73 | + bool IsCapable() override; | ||
| 74 | + ge::graphStatus GetPlatformInfo() override; | ||
| 75 | + // 获取INPUT/OUTPUT/ATTR信息 | ||
| 76 | + ge::graphStatus GetShapeAttrsInfo() override; | ||
| 77 | + // 计算数据切分TilingData | ||
| 78 | + ge::graphStatus DoOpTiling() override; | ||
| 79 | + // 计算TilingKey | ||
| 80 | + uint64_t GetTilingKey() const override; | ||
| 81 | + // 分配workspace | ||
| 82 | + ge::graphStatus GetWorkspaceSize() override; | ||
| 83 | + // 保存Tiling数据 | ||
| 84 | + ge::graphStatus PostTiling() override; | ||
| 85 | + // tiling信息打屏 | ||
| 86 | + void DumpTilingInfo() override; | ||
| 87 | + | ||
| 88 | +private: | ||
| 89 | + uint64_t GenerateTilingKey(uint64_t innerKey); | ||
| 90 | + MaxPool3DWithArgmaxV2Tiling::MaxPool3DWithArgmaxV2SimtTilingData* tilingData_ = | ||
| 91 | + context_->GetTilingData<MaxPool3DWithArgmaxV2Tiling::MaxPool3DWithArgmaxV2SimtTilingData>(); | ||
| 92 | + InputSIMTInfo inputData; | ||
| 93 | + int nDimPos = 0; | ||
| 94 | + int cDimPos = 1; | ||
| 95 | + int dDimPos = 2; | ||
| 96 | + int hDimPos = 3; | ||
| 97 | + int wDimPos = 4; | ||
| 98 | + int64_t outputDataCount = 0; | ||
| 99 | +}; | ||
| 100 | + | ||
| 101 | +} // namespace optiling | ||
| 102 | + | ||
| @@ -1,5 +1,5 @@ | |||
| 1 | /** | 1 | /** |
| 2 | - * Copyright (c) 2025 Huawei Technologies Co., Ltd. | 2 | + * Copyright (c) 2025-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 | 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. |
| @@ -1,5 +1,5 @@ | |||
| 1 | /** | 1 | /** |
| 2 | - * Copyright (c) 2025 Huawei Technologies Co., Ltd. | 2 | + * Copyright (c) 2025-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 | 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. |
| @@ -1,5 +1,5 @@ | |||
| 1 | /** | 1 | /** |
| 2 | - * Copyright (c) 2025 Huawei Technologies Co., Ltd. | 2 | + * Copyright (c) 2025-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 | 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. |
| @@ -356,6 +356,10 @@ struct InputInfo { | |||
| 356 | array<uint64_t, DHW_DIMS> pad; | 356 | array<uint64_t, DHW_DIMS> pad; |
| 357 | array<uint64_t, DHW_DIMS> dilation; | 357 | array<uint64_t, DHW_DIMS> dilation; |
| 358 | bool ceilMode; | 358 | bool ceilMode; |
| 359 | + ge::DataType indexDtype; | ||
| 360 | + ge::Format inputFormat; | ||
| 361 | + uint64_t nInput; | ||
| 362 | + uint64_t cInput; | ||
| 359 | }; | 363 | }; |
| 360 | 364 | ||
| 361 | struct PadInputInfo { | 365 | struct PadInputInfo { |
| @@ -1,5 +1,5 @@ | |||
| 1 | /** | 1 | /** |
| 2 | - * Copyright (c) 2025 Huawei Technologies Co., Ltd. | 2 | + * Copyright (c) 2025-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 | 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. |
Apooling/max_pool3d_with_argmax_v2/op_host/max_pool3d_with_argmax_v2_tiling_big_kernel_regbase.cpp+330-0
| @@ -0,0 +1,330 @@ | |||
| 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 max_pool3d_with_argmax_v2_tiling_big_kernel_regbase.cpp | ||
| 13 | + * \brief big kernel imply for max_pool3d_with_argmax_v2 | ||
| 14 | + */ | ||
| 15 | + | ||
| 16 | + | ||
| 17 | + | ||
| 18 | + | ||
| 19 | + | ||
| 20 | +using namespace std; | ||
| 21 | +static const gert::Shape g_vec_1_shape = {1}; | ||
| 22 | + | ||
| 23 | +namespace optiling | ||
| 24 | +{ | ||
| 25 | +static const gert::Shape &EnsureNotScalar(const gert::Shape &inShape) { | ||
| 26 | + if (inShape.IsScalar()) { | ||
| 27 | + return g_vec_1_shape; | ||
| 28 | + } | ||
| 29 | + return inShape; | ||
| 30 | +} | ||
| 31 | + | ||
| 32 | +ge::graphStatus MaxPool3DWithArgmaxV2BigKernelRegbaseTiling::GetShapeAttrsInfo() | ||
| 33 | +{ | ||
| 34 | + auto platformInfo = context_->GetPlatformInfo(); | ||
| 35 | + OP_CHECK_NULL_WITH_CONTEXT(context_, platformInfo); | ||
| 36 | + auto ascendcPlatform = platform_ascendc::PlatformAscendC(platformInfo); | ||
| 37 | + if (!Ops::NN::OpTiling::IsRegbaseSocVersion(context_)){ | ||
| 38 | + return ge::GRAPH_PARAM_INVALID; | ||
| 39 | + } | ||
| 40 | + auto inputX = context_->GetInputShape(0); | ||
| 41 | + OP_CHECK_NULL_WITH_CONTEXT(context_, inputX); | ||
| 42 | + auto inputShape = EnsureNotScalar(inputX->GetStorageShape()); | ||
| 43 | + | ||
| 44 | + OP_CHECK_IF(inputShape.GetDimNum() != NCDHW_DIMS, | ||
| 45 | + OP_LOGE(context_->GetNodeName(), | ||
| 46 | + "MaxPool3DWithArgmaxV2: input shape dim = %zu, should be equal 5", | ||
| 47 | + inputShape.GetDimNum()), | ||
| 48 | + return ge::GRAPH_FAILED); | ||
| 49 | + OP_CHECK_IF(inputShape.GetShapeSize() <= 0, | ||
| 50 | + OP_LOGE(context_->GetNodeName(), | ||
| 51 | + "MaxPool3DWithArgmaxV2: input shape size %ld less than zero failed", | ||
| 52 | + inputShape.GetShapeSize()), | ||
| 53 | + return ge::GRAPH_FAILED); | ||
| 54 | + auto inputDesc = context_->GetInputDesc(0); | ||
| 55 | + OP_CHECK_NULL_WITH_CONTEXT(context_, inputDesc); | ||
| 56 | + dtype = inputDesc->GetDataType(); | ||
| 57 | + if (dtype != ge::DataType::DT_BF16 && dtype != ge::DataType::DT_FLOAT16 && dtype != ge::DataType::DT_FLOAT) { | ||
| 58 | + OP_LOGE(context_->GetNodeName(), "MaxPool3DWithArgmaxV2: invalid dtype"); | ||
| 59 | + return ge::GRAPH_FAILED; | ||
| 60 | + } | ||
| 61 | + | ||
| 62 | + auto outX = context_->GetOutputShape(0); | ||
| 63 | + OP_CHECK_NULL_WITH_CONTEXT(context_, outX); | ||
| 64 | + auto outShape = EnsureNotScalar(outX->GetStorageShape()); | ||
| 65 | + auto indicesX = context_->GetOutputShape(1); | ||
| 66 | + OP_CHECK_NULL_WITH_CONTEXT(context_, indicesX); | ||
| 67 | + auto indicesShape = EnsureNotScalar(indicesX->GetStorageShape()); | ||
| 68 | + if (indicesShape != outShape) { | ||
| 69 | + OP_LOGE(context_->GetNodeName(), | ||
| 70 | + "MaxPool3DWithArgmaxV2: indices shape and values shape is different"); | ||
| 71 | + return ge::GRAPH_FAILED; | ||
| 72 | + } | ||
| 73 | + auto runtimeAttrs = context_->GetAttrs(); | ||
| 74 | + OP_CHECK_NULL_WITH_CONTEXT(context_, runtimeAttrs); | ||
| 75 | + | ||
| 76 | + std::string inputFormatStr("NCDHW"); | ||
| 77 | + const char* inputFormat = runtimeAttrs->GetAttrPointer<char>(FORMAT_POS); | ||
| 78 | + if (inputFormat != nullptr) { | ||
| 79 | + inputFormatStr = inputFormat; | ||
| 80 | + } | ||
| 81 | + int d_dim = MP_MAX_3D_DIM_TWO, h_dim = MP_MAX_3D_DIM_THREE, w_dim = MP_MAX_3D_DIM_FOUR; | ||
| 82 | + if (inputFormatStr == "NCDHW") { | ||
| 83 | + inputData.inputFormat = ge::Format::FORMAT_NCDHW; | ||
| 84 | + inputData.batches = inputShape.GetDim(MP_MAX_3D_DIM_ZERO) * inputShape.GetDim(MP_MAX_3D_DIM_ONE); | ||
| 85 | + inputData.nInput = inputShape.GetDim(MP_MAX_3D_DIM_ZERO); | ||
| 86 | + inputData.cInput = inputShape.GetDim(MP_MAX_3D_DIM_ONE); | ||
| 87 | + } else { | ||
| 88 | + return ge::GRAPH_PARAM_INVALID; | ||
| 89 | + } | ||
| 90 | + | ||
| 91 | + OP_CHECK_IF(outShape.GetDim(d_dim) < 1 || outShape.GetDim(h_dim) < 1 || outShape.GetDim(w_dim) < 1, | ||
| 92 | + OP_LOGE(context_->GetNodeName(), | ||
| 93 | + "MaxPool3DWithArgmaxV2: output shape [%ld, %ld, %ld] not support", | ||
| 94 | + outShape.GetDim(d_dim), outShape.GetDim(h_dim), outShape.GetDim(w_dim)), | ||
| 95 | + return ge::GRAPH_FAILED); | ||
| 96 | + | ||
| 97 | + inputData.inputShape = | ||
| 98 | + array<uint64_t, DHW_DIMS>{uint64_t(inputShape.GetDim(d_dim)), uint64_t(inputShape.GetDim(h_dim)), uint64_t(inputShape.GetDim(w_dim))}; | ||
| 99 | + inputData.outShape = array<uint64_t, DHW_DIMS>{uint64_t(outShape.GetDim(d_dim)), uint64_t(outShape.GetDim(h_dim)), uint64_t(outShape.GetDim(w_dim))}; | ||
| 100 | + | ||
| 101 | + int32_t dValue = 0; | ||
| 102 | + int32_t hValue = 0; | ||
| 103 | + int32_t wValue = 0; | ||
| 104 | + const gert::TypedContinuousVector<int64_t>* kernelSize = runtimeAttrs->GetListInt(KERNEL_POS); | ||
| 105 | + OP_CHECK_NULL_WITH_CONTEXT(context_, kernelSize); | ||
| 106 | + dValue = *(kernelSize->GetData()); | ||
| 107 | + hValue = *(kernelSize->GetData() + 1); | ||
| 108 | + wValue = *(kernelSize->GetData() + 2); | ||
| 109 | + inputData.kernelSize = array<uint64_t, DHW_DIMS>{uint64_t(dValue), uint64_t(hValue), uint64_t(wValue)}; | ||
| 110 | + OP_CHECK_IF( | ||
| 111 | + dValue <= 0 || hValue <= 0 || wValue <= 0, | ||
| 112 | + OP_LOGE(context_->GetNodeName(), | ||
| 113 | + "MaxPool3DWithArgmaxV2: not support kernel shape [%d, %d, %d]", dValue, hValue, wValue), | ||
| 114 | + return ge::GRAPH_FAILED); | ||
| 115 | + | ||
| 116 | + int32_t kdValue = dValue; | ||
| 117 | + int32_t khValue = hValue; | ||
| 118 | + int32_t kwValue = wValue; | ||
| 119 | + const gert::TypedContinuousVector<int64_t>* stride = runtimeAttrs->GetListInt(STRIDE_POS); | ||
| 120 | + OP_CHECK_NULL_WITH_CONTEXT(context_, stride); | ||
| 121 | + dValue = *(stride->GetData()); | ||
| 122 | + hValue = *(stride->GetData() + 1); | ||
| 123 | + wValue = *(stride->GetData() + 2); | ||
| 124 | + inputData.stride = array<uint64_t, DHW_DIMS>{uint64_t(dValue), uint64_t(hValue), uint64_t(wValue)}; | ||
| 125 | + OP_CHECK_IF( | ||
| 126 | + dValue <= 0 || hValue <= 0 || wValue <= 0, | ||
| 127 | + OP_LOGE(context_->GetNodeName(), | ||
| 128 | + "MaxPool3DWithArgmaxV2: not support stride shape [%d, %d, %d]", dValue, hValue, wValue), | ||
| 129 | + return ge::GRAPH_FAILED); | ||
| 130 | + | ||
| 131 | + const gert::TypedContinuousVector<int64_t>* padding = runtimeAttrs->GetListInt(PADDING_POS); | ||
| 132 | + OP_CHECK_NULL_WITH_CONTEXT(context_, padding); | ||
| 133 | + dValue = *(padding->GetData()); | ||
| 134 | + hValue = *(padding->GetData() + 1); | ||
| 135 | + wValue = *(padding->GetData() + 2); | ||
| 136 | + inputData.pad = array<uint64_t, DHW_DIMS>{uint64_t(dValue), uint64_t(hValue), uint64_t(wValue)}; | ||
| 137 | + OP_CHECK_IF( | ||
| 138 | + dValue > kdValue / 2 || hValue > khValue / 2 || wValue > kwValue / 2, | ||
| 139 | + OP_LOGE(context_->GetNodeName(), | ||
| 140 | + "MaxPool3DWithArgmaxV2: not support pad shape [%d, %d, %d] kernel shape [%d, %d, %d]", | ||
| 141 | + dValue, hValue, wValue, kdValue, khValue, kwValue), | ||
| 142 | + return ge::GRAPH_FAILED); | ||
| 143 | + | ||
| 144 | + inputData.dilation = array<uint64_t, DHW_DIMS>{1, 1, 1}; | ||
| 145 | + dValue = 1; | ||
| 146 | + hValue = 1; | ||
| 147 | + wValue = 1; | ||
| 148 | + const gert::TypedContinuousVector<int64_t>* dilation = runtimeAttrs->GetListInt(DILATION_POS); | ||
| 149 | + if (dilation != nullptr) { | ||
| 150 | + dValue = *(dilation->GetData()); | ||
| 151 | + hValue = *(dilation->GetData() + 1); | ||
| 152 | + wValue = *(dilation->GetData() + 2); | ||
| 153 | + inputData.dilation = array<uint64_t, DHW_DIMS>{uint64_t(dValue), uint64_t(hValue), uint64_t(wValue)}; | ||
| 154 | + OP_CHECK_IF( | ||
| 155 | + dValue <= 0 || hValue <= 0 || wValue <= 0, | ||
| 156 | + OP_LOGE(context_->GetNodeName(), | ||
| 157 | + "MaxPool3DWithArgmaxV2: not support dilation shape [%d, %d, %d]", dValue, hValue, wValue), | ||
| 158 | + return ge::GRAPH_FAILED); | ||
| 159 | + } | ||
| 160 | + | ||
| 161 | + inputData.ceilMode = false; | ||
| 162 | + const bool* ceilModePtr = runtimeAttrs->GetAttrPointer<bool>(CEIL_POS); | ||
| 163 | + if (ceilModePtr != nullptr) { | ||
| 164 | + inputData.ceilMode = *ceilModePtr; | ||
| 165 | + } | ||
| 166 | + | ||
| 167 | + int indexDtype = THREE; | ||
| 168 | + const int* indexDtypePtr = runtimeAttrs->GetAttrPointer<int>(DTYPE_POS); | ||
| 169 | + if (indexDtypePtr != nullptr) { | ||
| 170 | + indexDtype = *indexDtypePtr; | ||
| 171 | + } | ||
| 172 | + switch (indexDtype) { | ||
| 173 | + case MP_MAX_3D_TYPE_INT32: | ||
| 174 | + inputData.indexDtype = ge::DataType::DT_INT32; | ||
| 175 | + break; | ||
| 176 | + case MP_MAX_3D_TYPE_INT64: | ||
| 177 | + inputData.indexDtype = ge::DataType::DT_INT64; | ||
| 178 | + break; | ||
| 179 | + default: | ||
| 180 | + inputData.indexDtype = ge::DataType::DT_INT32; | ||
| 181 | + break; | ||
| 182 | + } | ||
| 183 | + return ge::GRAPH_SUCCESS; | ||
| 184 | +} | ||
| 185 | + | ||
| 186 | +ge::graphStatus MaxPool3DWithArgmaxV2BigKernelRegbaseTiling::GetPlatformInfo() | ||
| 187 | +{ | ||
| 188 | + auto platformPtr = context_->GetPlatformInfo(); | ||
| 189 | + if (platformPtr == nullptr) { | ||
| 190 | + auto compileInfoPtr = reinterpret_cast<const MaxPool3DWithArgmaxV2CompileInfo*>(context_->GetCompileInfo()); | ||
| 191 | + OP_CHECK_IF(compileInfoPtr == nullptr, CUBE_INNER_ERR_REPORT(context_, "compile info is null"), | ||
| 192 | + return ge::GRAPH_FAILED); | ||
| 193 | + coreNum = compileInfoPtr->coreNum; | ||
| 194 | + ubSize = compileInfoPtr->ubSize; | ||
| 195 | + } else { | ||
| 196 | + auto ascendcPlatform = platform_ascendc::PlatformAscendC(platformPtr); | ||
| 197 | + coreNum = ascendcPlatform.GetCoreNumAiv(); | ||
| 198 | + uint64_t ubSizePlatform; | ||
| 199 | + ascendcPlatform.GetCoreMemSize(platform_ascendc::CoreMemType::UB, ubSizePlatform); | ||
| 200 | + ubSize = static_cast<int64_t>(ubSizePlatform); | ||
| 201 | + } | ||
| 202 | + OP_CHECK_IF(coreNum == 0, CUBE_INNER_ERR_REPORT(context_, "coreNum is 0"), return ge::GRAPH_FAILED); | ||
| 203 | + return ge::GRAPH_SUCCESS; | ||
| 204 | +} | ||
| 205 | + | ||
| 206 | +bool MaxPool3DWithArgmaxV2BigKernelRegbaseTiling::IsCapable() | ||
| 207 | +{ | ||
| 208 | + int64_t ubAvailable = ubSize - (BYTES_FOUR + BYTES_EIGHT) * OUT_BUFFER_LEN; | ||
| 209 | + maxCount_ = ubAvailable / BUFFER_NUM; | ||
| 210 | + int64_t vRegSize = Ops::Base::GetVRegSize(context_); | ||
| 211 | + maxCount_ = Ops::Base::FloorAlign(maxCount_, vRegSize); | ||
| 212 | + int64_t dtypeSize = ge::GetSizeByDataType(dtype); | ||
| 213 | + OP_CHECK_IF( | ||
| 214 | + dtypeSize <= 0, | ||
| 215 | + OP_LOGE(context_, "dtypeSize must be greater than 0, dtypeSize: %ld", dtypeSize), | ||
| 216 | + return false); | ||
| 217 | + if (dtypeSize != 0) { | ||
| 218 | + maxCount_ = maxCount_ / dtypeSize; | ||
| 219 | + } | ||
| 220 | + if (inputData.dilation[D_DIM] == 1 && inputData.dilation[H_DIM] == 1 && inputData.dilation[W_DIM] == 1 && maxCount_ > MIN_COUNT && | ||
| 221 | + inputData.inputFormat == ge::Format::FORMAT_NCDHW && inputData.kernelSize[W_DIM] * dtypeSize >= KW_THRESHOLD) { | ||
| 222 | + return true; | ||
| 223 | + } | ||
| 224 | + return false; | ||
| 225 | +} | ||
| 226 | + | ||
| 227 | +void MaxPool3DWithArgmaxV2BigKernelRegbaseTiling::DoUBTiling() | ||
| 228 | +{ | ||
| 229 | + totalIdx_ = inputData.batches * inputData.outShape[D_DIM] * inputData.outShape[H_DIM] * inputData.outShape[W_DIM]; | ||
| 230 | + blockFactor_ = totalIdx_ / coreNum; | ||
| 231 | + blockTail_ = totalIdx_ % coreNum; | ||
| 232 | + if (blockFactor_ == 0) { | ||
| 233 | + coreNums_ = totalIdx_; | ||
| 234 | + } else { | ||
| 235 | + coreNums_ = coreNum; | ||
| 236 | + } | ||
| 237 | + isSigOut_ = (inputData.outShape[D_DIM] == 1 && inputData.outShape[H_DIM] == 1 && inputData.outShape[W_DIM] == 1) ? 1 : 0; | ||
| 238 | +} | ||
| 239 | + | ||
| 240 | +void MaxPool3DWithArgmaxV2BigKernelRegbaseTiling::SetTilingData() | ||
| 241 | +{ | ||
| 242 | + tilingData_->dOutDim = inputData.outShape[D_DIM]; | ||
| 243 | + tilingData_->hOutDim = inputData.outShape[H_DIM]; | ||
| 244 | + tilingData_->wOutDim = inputData.outShape[W_DIM]; | ||
| 245 | + tilingData_->dInDim = inputData.inputShape[D_DIM]; | ||
| 246 | + tilingData_->hInDim = inputData.inputShape[H_DIM]; | ||
| 247 | + tilingData_->wInDim = inputData.inputShape[W_DIM]; | ||
| 248 | + tilingData_->kD = inputData.kernelSize[D_DIM]; | ||
| 249 | + tilingData_->kH = inputData.kernelSize[H_DIM]; | ||
| 250 | + tilingData_->kW = inputData.kernelSize[W_DIM]; | ||
| 251 | + tilingData_->sD = inputData.stride[D_DIM]; | ||
| 252 | + tilingData_->sH = inputData.stride[H_DIM]; | ||
| 253 | + tilingData_->sW = inputData.stride[W_DIM]; | ||
| 254 | + tilingData_->pD = inputData.pad[D_DIM]; | ||
| 255 | + tilingData_->pH = inputData.pad[H_DIM]; | ||
| 256 | + tilingData_->pW = inputData.pad[W_DIM]; | ||
| 257 | + tilingData_->dD = inputData.dilation[D_DIM]; | ||
| 258 | + tilingData_->dH = inputData.dilation[H_DIM]; | ||
| 259 | + tilingData_->dW = inputData.dilation[W_DIM]; | ||
| 260 | + tilingData_->blockFactor = blockFactor_; | ||
| 261 | + tilingData_->blockTail = blockTail_; | ||
| 262 | + tilingData_->totalIdx = totalIdx_; | ||
| 263 | + tilingData_->coreNums = coreNums_; | ||
| 264 | + tilingData_->maxCount = maxCount_; | ||
| 265 | + tilingData_->isSigOut = isSigOut_; | ||
| 266 | +} | ||
| 267 | + | ||
| 268 | +ge::graphStatus MaxPool3DWithArgmaxV2BigKernelRegbaseTiling::DoOpTiling() | ||
| 269 | +{ | ||
| 270 | + DoUBTiling(); | ||
| 271 | + SetTilingData(); | ||
| 272 | + return ge::GRAPH_SUCCESS; | ||
| 273 | +} | ||
| 274 | + | ||
| 275 | +ge::graphStatus MaxPool3DWithArgmaxV2BigKernelRegbaseTiling::DoLibApiTiling() | ||
| 276 | +{ | ||
| 277 | + return ge::GRAPH_SUCCESS; | ||
| 278 | +} | ||
| 279 | + | ||
| 280 | +ge::graphStatus MaxPool3DWithArgmaxV2BigKernelRegbaseTiling::GetWorkspaceSize() | ||
| 281 | +{ | ||
| 282 | + auto sys_workspace = WS_SYS_SIZE; | ||
| 283 | + size_t* currentWorkspace = context_->GetWorkspaceSizes(1); | ||
| 284 | + OP_CHECK_NULL_WITH_CONTEXT(context_, currentWorkspace); | ||
| 285 | + currentWorkspace[0] = sys_workspace; | ||
| 286 | + | ||
| 287 | + return ge::GRAPH_SUCCESS; | ||
| 288 | +} | ||
| 289 | + | ||
| 290 | +ge::graphStatus MaxPool3DWithArgmaxV2BigKernelRegbaseTiling::PostTiling() | ||
| 291 | +{ | ||
| 292 | + context_->SetBlockDim(coreNums_); | ||
| 293 | + return ge::GRAPH_SUCCESS; | ||
| 294 | +} | ||
| 295 | + | ||
| 296 | +uint64_t MaxPool3DWithArgmaxV2BigKernelRegbaseTiling::GetTilingKey() const | ||
| 297 | +{ | ||
| 298 | + return MAX_POOL_WITH_ARGMAX_V2_TILING_KEY_BIG_KERNEL_REGBASE_NCDHW; | ||
| 299 | +} | ||
| 300 | + | ||
| 301 | +void MaxPool3DWithArgmaxV2BigKernelRegbaseTiling::DumpTilingInfo() | ||
| 302 | +{ | ||
| 303 | + std::string str; | ||
| 304 | + str += " dInDim:" + std::to_string(tilingData_->dInDim); | ||
| 305 | + str += " hInDim:" + std::to_string(tilingData_->hInDim); | ||
| 306 | + str += " wInDim:" + std::to_string(tilingData_->wInDim); | ||
| 307 | + str += " dOutDim:" + std::to_string(tilingData_->dOutDim); | ||
| 308 | + str += " hOutDim:" + std::to_string(tilingData_->hOutDim); | ||
| 309 | + str += " wOutDim:" + std::to_string(tilingData_->wOutDim); | ||
| 310 | + str += " kD:" + std::to_string(tilingData_->kD); | ||
| 311 | + str += " kH:" + std::to_string(tilingData_->kH); | ||
| 312 | + str += " kW:" + std::to_string(tilingData_->kW); | ||
| 313 | + str += " sD:" + std::to_string(tilingData_->sD); | ||
| 314 | + str += " sH:" + std::to_string(tilingData_->sH); | ||
| 315 | + str += " sW:" + std::to_string(tilingData_->sW); | ||
| 316 | + str += " pD:" + std::to_string(tilingData_->pD); | ||
| 317 | + str += " pH:" + std::to_string(tilingData_->pH); | ||
| 318 | + str += " pW:" + std::to_string(tilingData_->pW); | ||
| 319 | + str += " blockFactor:" + std::to_string(tilingData_->blockFactor); | ||
| 320 | + str += " blockTail:" + std::to_string(tilingData_->blockTail); | ||
| 321 | + str += " totalIdx:" + std::to_string(tilingData_->totalIdx); | ||
| 322 | + str += " coreNums:" + std::to_string(tilingData_->coreNums); | ||
| 323 | + str += " maxCount:" + std::to_string(tilingData_->maxCount); | ||
| 324 | + str += " isSigOut:" + std::to_string(tilingData_->isSigOut); | ||
| 325 | + OP_LOGI(context_, "%s", str.c_str()); | ||
| 326 | +} | ||
| 327 | + | ||
| 328 | +REGISTER_TILING_TEMPLATE("MaxPool3DWithArgmaxV2", MaxPool3DWithArgmaxV2BigKernelRegbaseTiling, 1); | ||
| 329 | + | ||
| 330 | +} | ||
Apooling/max_pool3d_with_argmax_v2/op_host/max_pool3d_with_argmax_v2_tiling_big_kernel_regbase.h+109-0
| @@ -1,5 +1,5 @@ | |||
| 1 | /** | 1 | /** |
| 2 | - * Copyright (c) 2025 Huawei Technologies Co., Ltd. | 2 | + * Copyright (c) 2025-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 | 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. |
| @@ -13,6 +13,7 @@ | |||
| 13 | * \brief | 13 | * \brief |
| 14 | */ | 14 | */ |
| 15 | 15 | ||
| 16 | + | ||
| 16 | 17 | ||
| 17 | 18 | ||
| 18 | // 3, splitD=1, splitH=1, splitW=1, splitKernel = 1, dtype=float | 19 | // 3, splitD=1, splitH=1, splitW=1, splitKernel = 1, dtype=float |
| @@ -27,6 +28,12 @@ namespace optiling { | |||
| 27 | 28 | ||
| 28 | bool MaxPool3DWithArgmaxV2BigKernelTiling::IsCapable() | 29 | bool MaxPool3DWithArgmaxV2BigKernelTiling::IsCapable() |
| 29 | { | 30 | { |
| 31 | + auto platformInfo = context_->GetPlatformInfo(); | ||
| 32 | + OP_CHECK_NULL_WITH_CONTEXT(context_, platformInfo); | ||
| 33 | + auto ascendcPlatform = platform_ascendc::PlatformAscendC(platformInfo); | ||
| 34 | + if (Ops::NN::OpTiling::IsRegbaseSocVersion(context_)){ | ||
| 35 | + return false; | ||
| 36 | + } | ||
| 30 | if (inputData.dilation[D_DIM] == 1 && inputData.dilation[H_DIM] == 1 && inputData.dilation[W_DIM] == 1) { | 37 | if (inputData.dilation[D_DIM] == 1 && inputData.dilation[H_DIM] == 1 && inputData.dilation[W_DIM] == 1) { |
| 31 | return true; | 38 | return true; |
| 32 | } | 39 | } |
| @@ -100,6 +107,6 @@ ge::graphStatus MaxPool3DWithArgmaxV2BigKernelTiling::PostTiling() | |||
| 100 | return ge::GRAPH_SUCCESS; | 107 | return ge::GRAPH_SUCCESS; |
| 101 | } | 108 | } |
| 102 | 109 | ||
| 103 | -REGISTER_TILING_TEMPLATE("MaxPool3DWithArgmaxV2", MaxPool3DWithArgmaxV2BigKernelTiling, 1); | 110 | +REGISTER_TILING_TEMPLATE("MaxPool3DWithArgmaxV2", MaxPool3DWithArgmaxV2BigKernelTiling, 11); |
| 104 | 111 | ||
| 105 | } // namespace optiling | 112 | } // namespace optiling |
| @@ -1,5 +1,5 @@ | |||
| 1 | /** | 1 | /** |
| 2 | - * Copyright (c) 2025 Huawei Technologies Co., Ltd. | 2 | + * Copyright (c) 2025-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 | 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. |
| @@ -13,6 +13,7 @@ | |||
| 13 | * \brief | 13 | * \brief |
| 14 | */ | 14 | */ |
| 15 | 15 | ||
| 16 | + | ||
| 16 | 17 | ||
| 17 | 18 | ||
| 18 | // 1, splitD=1, splitH=1, splitW=1, splitKernel = 1, dtype=float | 19 | // 1, splitD=1, splitH=1, splitW=1, splitKernel = 1, dtype=float |
| @@ -27,6 +28,12 @@ namespace optiling { | |||
| 27 | 28 | ||
| 28 | bool MaxPool3DWithArgmaxV2HugeKernelTiling::IsCapable() | 29 | bool MaxPool3DWithArgmaxV2HugeKernelTiling::IsCapable() |
| 29 | { | 30 | { |
| 31 | + auto platformInfo = context_->GetPlatformInfo(); | ||
| 32 | + OP_CHECK_NULL_WITH_CONTEXT(context_, platformInfo); | ||
| 33 | + auto ascendcPlatform = platform_ascendc::PlatformAscendC(platformInfo); | ||
| 34 | + if (Ops::NN::OpTiling::IsRegbaseSocVersion(context_)){ | ||
| 35 | + return false; | ||
| 36 | + } | ||
| 30 | array<uint64_t, DHW_DIMS> parts{ | 37 | array<uint64_t, DHW_DIMS> parts{ |
| 31 | inputData.kernelSize[D_DIM], inputData.kernelSize[H_DIM], inputData.kernelSize[W_DIM]}; | 38 | inputData.kernelSize[D_DIM], inputData.kernelSize[H_DIM], inputData.kernelSize[W_DIM]}; |
| 32 | LargeKernelCalcParts(parts, parts.size(), bufSizes, D_DIM); | 39 | LargeKernelCalcParts(parts, parts.size(), bufSizes, D_DIM); |
| @@ -224,6 +231,6 @@ ge::graphStatus MaxPool3DWithArgmaxV2HugeKernelTiling::PostTiling() | |||
| 224 | return ge::GRAPH_SUCCESS; | 231 | return ge::GRAPH_SUCCESS; |
| 225 | } | 232 | } |
| 226 | 233 | ||
| 227 | -REGISTER_TILING_TEMPLATE("MaxPool3DWithArgmaxV2", MaxPool3DWithArgmaxV2HugeKernelTiling, 6); | 234 | +REGISTER_TILING_TEMPLATE("MaxPool3DWithArgmaxV2", MaxPool3DWithArgmaxV2HugeKernelTiling, 16); |
| 228 | 235 | ||
| 229 | } // namespace optiling | 236 | } // namespace optiling |
| @@ -1,5 +1,5 @@ | |||
| 1 | /** | 1 | /** |
| 2 | - * Copyright (c) 2025 Huawei Technologies Co., Ltd. | 2 | + * Copyright (c) 2025-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 | 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. |
| @@ -13,6 +13,7 @@ | |||
| 13 | * \brief | 13 | * \brief |
| 14 | */ | 14 | */ |
| 15 | 15 | ||
| 16 | + | ||
| 16 | 17 | ||
| 17 | 18 | ||
| 18 | // 1, splitD=0, splitH=0, splitW=0, splitKernel = 0, dtype=float | 19 | // 1, splitD=0, splitH=0, splitW=0, splitKernel = 0, dtype=float |
| @@ -27,6 +28,12 @@ namespace optiling { | |||
| 27 | 28 | ||
| 28 | bool MaxPool3DWithArgmaxV2NoSplitTiling::IsCapable() | 29 | bool MaxPool3DWithArgmaxV2NoSplitTiling::IsCapable() |
| 29 | { | 30 | { |
| 31 | + auto platformInfo = context_->GetPlatformInfo(); | ||
| 32 | + OP_CHECK_NULL_WITH_CONTEXT(context_, platformInfo); | ||
| 33 | + auto ascendcPlatform = platform_ascendc::PlatformAscendC(platformInfo); | ||
| 34 | + if (Ops::NN::OpTiling::IsRegbaseSocVersion(context_)){ | ||
| 35 | + return false; | ||
| 36 | + } | ||
| 30 | array<uint64_t, DHW_DIMS> tmpOutShape{ | 37 | array<uint64_t, DHW_DIMS> tmpOutShape{ |
| 31 | inputData.outShape[D_DIM], inputData.outShape[H_DIM], inputData.outShape[W_DIM]}; | 38 | inputData.outShape[D_DIM], inputData.outShape[H_DIM], inputData.outShape[W_DIM]}; |
| 32 | auto summaryMemory = CalcBufferSizes( | 39 | auto summaryMemory = CalcBufferSizes( |
| @@ -103,6 +110,6 @@ ge::graphStatus MaxPool3DWithArgmaxV2NoSplitTiling::PostTiling() | |||
| 103 | return ge::GRAPH_SUCCESS; | 110 | return ge::GRAPH_SUCCESS; |
| 104 | } | 111 | } |
| 105 | 112 | ||
| 106 | -REGISTER_TILING_TEMPLATE("MaxPool3DWithArgmaxV2", MaxPool3DWithArgmaxV2NoSplitTiling, 2); | 113 | +REGISTER_TILING_TEMPLATE("MaxPool3DWithArgmaxV2", MaxPool3DWithArgmaxV2NoSplitTiling, 12); |
| 107 | 114 | ||
| 108 | } // namespace optiling | 115 | } // namespace optiling |
| @@ -1,5 +1,5 @@ | |||
| 1 | /** | 1 | /** |
| 2 | - * Copyright (c) 2025 Huawei Technologies Co., Ltd. | 2 | + * Copyright (c) 2025-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 | 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. |
| @@ -13,6 +13,7 @@ | |||
| 13 | * \brief | 13 | * \brief |
| 14 | */ | 14 | */ |
| 15 | 15 | ||
| 16 | + | ||
| 16 | 17 | ||
| 17 | 18 | ||
| 18 | // 1, splitD=1, splitH=0, splitW=0, splitKernel = 0, dtype=float | 19 | // 1, splitD=1, splitH=0, splitW=0, splitKernel = 0, dtype=float |
| @@ -27,6 +28,12 @@ namespace optiling { | |||
| 27 | 28 | ||
| 28 | bool MaxPool3DWithArgmaxV2SplitDTiling::IsCapable() | 29 | bool MaxPool3DWithArgmaxV2SplitDTiling::IsCapable() |
| 29 | { | 30 | { |
| 31 | + auto platformInfo = context_->GetPlatformInfo(); | ||
| 32 | + OP_CHECK_NULL_WITH_CONTEXT(context_, platformInfo); | ||
| 33 | + auto ascendcPlatform = platform_ascendc::PlatformAscendC(platformInfo); | ||
| 34 | + if (Ops::NN::OpTiling::IsRegbaseSocVersion(context_)){ | ||
| 35 | + return false; | ||
| 36 | + } | ||
| 30 | array<uint64_t, DHW_DIMS> parts{ | 37 | array<uint64_t, DHW_DIMS> parts{ |
| 31 | padInputData.padInputShape[D_DIM], padInputData.padInputShape[H_DIM], padInputData.padInputShape[W_DIM]}; | 38 | padInputData.padInputShape[D_DIM], padInputData.padInputShape[H_DIM], padInputData.padInputShape[W_DIM]}; |
| 32 | array<uint64_t, DHW_DIMS> partOuts{inputData.outShape[D_DIM], inputData.outShape[H_DIM], inputData.outShape[W_DIM]}; | 39 | array<uint64_t, DHW_DIMS> partOuts{inputData.outShape[D_DIM], inputData.outShape[H_DIM], inputData.outShape[W_DIM]}; |
| @@ -161,6 +168,6 @@ ge::graphStatus MaxPool3DWithArgmaxV2SplitDTiling::PostTiling() | |||
| 161 | return ge::GRAPH_SUCCESS; | 168 | return ge::GRAPH_SUCCESS; |
| 162 | } | 169 | } |
| 163 | 170 | ||
| 164 | -REGISTER_TILING_TEMPLATE("MaxPool3DWithArgmaxV2", MaxPool3DWithArgmaxV2SplitDTiling, 3); | 171 | +REGISTER_TILING_TEMPLATE("MaxPool3DWithArgmaxV2", MaxPool3DWithArgmaxV2SplitDTiling, 13); |
| 165 | 172 | ||
| 166 | } // namespace optiling | 173 | } // namespace optiling |
| @@ -1,5 +1,5 @@ | |||
| 1 | /** | 1 | /** |
| 2 | - * Copyright (c) 2025 Huawei Technologies Co., Ltd. | 2 | + * Copyright (c) 2025-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 | 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. |
| @@ -13,6 +13,7 @@ | |||
| 13 | * \brief | 13 | * \brief |
| 14 | */ | 14 | */ |
| 15 | 15 | ||
| 16 | + | ||
| 16 | 17 | ||
| 17 | 18 | ||
| 18 | // 1, splitD=1, splitH=1, splitW=0, splitKernel = 0, dtype=float | 19 | // 1, splitD=1, splitH=1, splitW=0, splitKernel = 0, dtype=float |
| @@ -26,6 +27,12 @@ namespace optiling { | |||
| 26 | 27 | ||
| 27 | bool MaxPool3DWithArgmaxV2SplitHTiling::IsCapable() | 28 | bool MaxPool3DWithArgmaxV2SplitHTiling::IsCapable() |
| 28 | { | 29 | { |
| 30 | + auto platformInfo = context_->GetPlatformInfo(); | ||
| 31 | + OP_CHECK_NULL_WITH_CONTEXT(context_, platformInfo); | ||
| 32 | + auto ascendcPlatform = platform_ascendc::PlatformAscendC(platformInfo); | ||
| 33 | + if (Ops::NN::OpTiling::IsRegbaseSocVersion(context_)){ | ||
| 34 | + return false; | ||
| 35 | + } | ||
| 29 | splitData.partD = inputData.dilation[D_DIM] * (inputData.kernelSize[D_DIM] - 1) + 1; | 36 | splitData.partD = inputData.dilation[D_DIM] * (inputData.kernelSize[D_DIM] - 1) + 1; |
| 30 | splitData.partOutD = 1UL; | 37 | splitData.partOutD = 1UL; |
| 31 | array<uint64_t, DHW_DIMS> parts{ | 38 | array<uint64_t, DHW_DIMS> parts{ |
| @@ -167,6 +174,6 @@ ge::graphStatus MaxPool3DWithArgmaxV2SplitHTiling::PostTiling() | |||
| 167 | return ge::GRAPH_SUCCESS; | 174 | return ge::GRAPH_SUCCESS; |
| 168 | } | 175 | } |
| 169 | 176 | ||
| 170 | -REGISTER_TILING_TEMPLATE("MaxPool3DWithArgmaxV2", MaxPool3DWithArgmaxV2SplitHTiling, 4); | 177 | +REGISTER_TILING_TEMPLATE("MaxPool3DWithArgmaxV2", MaxPool3DWithArgmaxV2SplitHTiling, 14); |
| 171 | 178 | ||
| 172 | } // namespace optiling | 179 | } // namespace optiling |
| @@ -1,5 +1,5 @@ | |||
| 1 | /** | 1 | /** |
| 2 | - * Copyright (c) 2025 Huawei Technologies Co., Ltd. | 2 | + * Copyright (c) 2025-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 | 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. |
| @@ -13,6 +13,7 @@ | |||
| 13 | * \brief | 13 | * \brief |
| 14 | */ | 14 | */ |
| 15 | 15 | ||
| 16 | + | ||
| 16 | 17 | ||
| 17 | 18 | ||
| 18 | // 1, splitD=1, splitH=1, splitW=1, splitKernel = 0, dtype=float | 19 | // 1, splitD=1, splitH=1, splitW=1, splitKernel = 0, dtype=float |
| @@ -26,6 +27,12 @@ namespace optiling { | |||
| 26 | 27 | ||
| 27 | bool MaxPool3DWithArgmaxV2SplitWTiling::IsCapable() | 28 | bool MaxPool3DWithArgmaxV2SplitWTiling::IsCapable() |
| 28 | { | 29 | { |
| 30 | + auto platformInfo = context_->GetPlatformInfo(); | ||
| 31 | + OP_CHECK_NULL_WITH_CONTEXT(context_, platformInfo); | ||
| 32 | + auto ascendcPlatform = platform_ascendc::PlatformAscendC(platformInfo); | ||
| 33 | + if (Ops::NN::OpTiling::IsRegbaseSocVersion(context_)){ | ||
| 34 | + return false; | ||
| 35 | + } | ||
| 29 | splitData.partD = inputData.dilation[D_DIM] * (inputData.kernelSize[D_DIM] - 1) + 1; | 36 | splitData.partD = inputData.dilation[D_DIM] * (inputData.kernelSize[D_DIM] - 1) + 1; |
| 30 | splitData.partOutD = 1UL; | 37 | splitData.partOutD = 1UL; |
| 31 | splitData.partH = inputData.dilation[H_DIM] * (inputData.kernelSize[H_DIM] - 1) + 1; | 38 | splitData.partH = inputData.dilation[H_DIM] * (inputData.kernelSize[H_DIM] - 1) + 1; |
| @@ -176,6 +183,6 @@ ge::graphStatus MaxPool3DWithArgmaxV2SplitWTiling::PostTiling() | |||
| 176 | return ge::GRAPH_SUCCESS; | 183 | return ge::GRAPH_SUCCESS; |
| 177 | } | 184 | } |
| 178 | 185 | ||
| 179 | -REGISTER_TILING_TEMPLATE("MaxPool3DWithArgmaxV2", MaxPool3DWithArgmaxV2SplitWTiling, 5); | 186 | +REGISTER_TILING_TEMPLATE("MaxPool3DWithArgmaxV2", MaxPool3DWithArgmaxV2SplitWTiling, 15); |
| 180 | 187 | ||
| 181 | } // namespace optiling | 188 | } // namespace optiling |
| @@ -0,0 +1,120 @@ | |||
| 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 max_pool3d_with_argmax_v2_base.h | ||
| 13 | + * \brief | ||
| 14 | + */ | ||
| 15 | + | ||
| 16 | + | ||
| 17 | + | ||
| 18 | + | ||
| 19 | + | ||
| 20 | + | ||
| 21 | + | ||
| 22 | + | ||
| 23 | +using namespace AscendC; | ||
| 24 | + | ||
| 25 | +template <typename T> | ||
| 26 | +__aicore__ inline void CalGatterIndex2D(MicroAPI::RegTensor<T>& indexReg, T rate2D, T num1D, T rate1D = 1) | ||
| 27 | +{ | ||
| 28 | + AscendC::MicroAPI::Arange(indexReg, 0); | ||
| 29 | + AscendC::MicroAPI::RegTensor<T> segScalarReg; | ||
| 30 | + AscendC::MicroAPI::RegTensor<T> tmpReg; | ||
| 31 | + AscendC::MicroAPI::RegTensor<T> constReg; | ||
| 32 | + AscendC::MicroAPI::MaskReg preg = AscendC::MicroAPI::CreateMask<T, AscendC::MicroAPI::MaskPattern::ALL>(); | ||
| 33 | + AscendC::MicroAPI::Duplicate(constReg, T(num1D)); | ||
| 34 | + AscendC::MicroAPI::Div(segScalarReg, indexReg, constReg, preg); | ||
| 35 | + AscendC::MicroAPI::Muls(tmpReg, segScalarReg, T(num1D), preg); | ||
| 36 | + AscendC::MicroAPI::Sub(indexReg, indexReg, tmpReg, preg); | ||
| 37 | + AscendC::MicroAPI::Muls(indexReg, indexReg, T(rate1D), preg); | ||
| 38 | + AscendC::MicroAPI::Muls(segScalarReg, segScalarReg, T(rate2D), preg); | ||
| 39 | + AscendC::MicroAPI::Add(indexReg, indexReg, segScalarReg, preg); | ||
| 40 | +} | ||
| 41 | + | ||
| 42 | +template <typename T> | ||
| 43 | +__aicore__ inline void CalGatterIndex3D(MicroAPI::RegTensor<T>& indexReg, T rate3D, T num2D, T rate2D, T num1D, T rate1D = 1) | ||
| 44 | +{ | ||
| 45 | + AscendC::MicroAPI::Arange(indexReg, 0); | ||
| 46 | + AscendC::MicroAPI::RegTensor<T> segScalarReg; | ||
| 47 | + AscendC::MicroAPI::RegTensor<T> segScalarReg2; | ||
| 48 | + AscendC::MicroAPI::RegTensor<T> tmpReg; | ||
| 49 | + AscendC::MicroAPI::RegTensor<T> constReg; | ||
| 50 | + AscendC::MicroAPI::MaskReg preg = AscendC::MicroAPI::CreateMask<T, AscendC::MicroAPI::MaskPattern::ALL>(); | ||
| 51 | + AscendC::MicroAPI::Duplicate(constReg, T(num2D)); | ||
| 52 | + AscendC::MicroAPI::Div(segScalarReg2, indexReg, constReg, preg); | ||
| 53 | + AscendC::MicroAPI::Muls(tmpReg, segScalarReg2, T(num2D), preg); | ||
| 54 | + AscendC::MicroAPI::Sub(indexReg, indexReg, tmpReg, preg); | ||
| 55 | + AscendC::MicroAPI::Muls(segScalarReg2, segScalarReg2, T(rate3D), preg); | ||
| 56 | + | ||
| 57 | + AscendC::MicroAPI::Duplicate(constReg, T(num1D)); | ||
| 58 | + AscendC::MicroAPI::Div(segScalarReg, indexReg, constReg, preg); | ||
| 59 | + AscendC::MicroAPI::Muls(tmpReg, segScalarReg, T(num1D), preg); | ||
| 60 | + AscendC::MicroAPI::Sub(indexReg, indexReg, tmpReg, preg); | ||
| 61 | + AscendC::MicroAPI::Muls(indexReg, indexReg, T(rate1D), preg); | ||
| 62 | + AscendC::MicroAPI::Muls(segScalarReg, segScalarReg, T(rate2D), preg); | ||
| 63 | + | ||
| 64 | + AscendC::MicroAPI::Add(indexReg, indexReg, segScalarReg, preg); | ||
| 65 | + AscendC::MicroAPI::Add(indexReg, indexReg, segScalarReg2, preg); | ||
| 66 | +} | ||
| 67 | + | ||
| 68 | +template <typename T> | ||
| 69 | +__aicore__ inline void CalGatterIndex4D(MicroAPI::RegTensor<T>& indexReg, T rate4D, T num3D, T rate3D, T num2D, T rate2D, T num1D, T rate1D = 1) | ||
| 70 | +{ | ||
| 71 | + AscendC::MicroAPI::Arange(indexReg, 0); | ||
| 72 | + AscendC::MicroAPI::RegTensor<T> segScalarReg; | ||
| 73 | + AscendC::MicroAPI::RegTensor<T> segScalarReg2; | ||
| 74 | + AscendC::MicroAPI::RegTensor<T> segScalarReg3; | ||
| 75 | + AscendC::MicroAPI::RegTensor<T> tmpReg; | ||
| 76 | + AscendC::MicroAPI::RegTensor<T> constReg; | ||
| 77 | + AscendC::MicroAPI::MaskReg preg = AscendC::MicroAPI::CreateMask<T, AscendC::MicroAPI::MaskPattern::ALL>(); | ||
| 78 | + AscendC::MicroAPI::Duplicate(constReg, T(num3D)); | ||
| 79 | + AscendC::MicroAPI::Div(segScalarReg3, indexReg, constReg, preg); | ||
| 80 | + AscendC::MicroAPI::Muls(tmpReg, segScalarReg3, T(num3D), preg); | ||
| 81 | + AscendC::MicroAPI::Sub(indexReg, indexReg, tmpReg, preg); | ||
| 82 | + AscendC::MicroAPI::Muls(segScalarReg3, segScalarReg3, T(rate4D), preg); | ||
| 83 | + | ||
| 84 | + AscendC::MicroAPI::Duplicate(constReg, T(num2D)); | ||
| 85 | + AscendC::MicroAPI::Div(segScalarReg2, indexReg, constReg, preg); | ||
| 86 | + AscendC::MicroAPI::Muls(tmpReg, segScalarReg2, T(num2D), preg); | ||
| 87 | + AscendC::MicroAPI::Sub(indexReg, indexReg, tmpReg, preg); | ||
| 88 | + AscendC::MicroAPI::Muls(segScalarReg2, segScalarReg2, T(rate3D), preg); | ||
| 89 | + | ||
| 90 | + AscendC::MicroAPI::Duplicate(constReg, T(num1D)); | ||
| 91 | + AscendC::MicroAPI::Div(segScalarReg, indexReg, constReg, preg); | ||
| 92 | + AscendC::MicroAPI::Muls(tmpReg, segScalarReg, T(num1D), preg); | ||
| 93 | + AscendC::MicroAPI::Sub(indexReg, indexReg, tmpReg, preg); | ||
| 94 | + AscendC::MicroAPI::Muls(indexReg, indexReg, T(rate1D), preg); | ||
| 95 | + AscendC::MicroAPI::Muls(segScalarReg, segScalarReg, T(rate2D), preg); | ||
| 96 | + | ||
| 97 | + AscendC::MicroAPI::Add(indexReg, indexReg, segScalarReg, preg); | ||
| 98 | + AscendC::MicroAPI::Add(indexReg, indexReg, segScalarReg2, preg); | ||
| 99 | + AscendC::MicroAPI::Add(indexReg, indexReg, segScalarReg3, preg); | ||
| 100 | +} | ||
| 101 | + | ||
| 102 | +template <typename T> | ||
| 103 | +__aicore__ inline void SetNegInfReg(MicroAPI::RegTensor<T>& negInfReg) | ||
| 104 | +{ | ||
| 105 | + // -inf | ||
| 106 | + constexpr uint32_t FLOAT32_NEG_INF = 0xFF800000; | ||
| 107 | + constexpr uint16_t FLOAT16_NEG_INF = 0xFC00; | ||
| 108 | + constexpr uint16_t BFLOAT16_NEG_INF = 0xFF80; | ||
| 109 | + using computeType = std::conditional_t<std::is_same<T, float>::value, uint32_t, uint16_t>; | ||
| 110 | + | ||
| 111 | + if constexpr(std::is_same<T, float>::value) { | ||
| 112 | + AscendC::MicroAPI::Duplicate((AscendC::MicroAPI::RegTensor<computeType>&)negInfReg, (FLOAT32_NEG_INF)); | ||
| 113 | + } else if constexpr(std::is_same<T, half>::value) { | ||
| 114 | + AscendC::MicroAPI::Duplicate((AscendC::MicroAPI::RegTensor<computeType>&)negInfReg, (FLOAT16_NEG_INF)); | ||
| 115 | + } else { | ||
| 116 | + AscendC::MicroAPI::Duplicate((AscendC::MicroAPI::RegTensor<computeType>&)negInfReg, (BFLOAT16_NEG_INF)); | ||
| 117 | + } | ||
| 118 | +} | ||
| 119 | + | ||
| 120 | + | ||


代码结构与可维护性: 属性dtype的默认值注释中使用了魔数3和9,分别表示int32和int64。这种硬编码的魔数降低了代码的可读性和可维护性。其他开发者需要查看注释才能理解这些数字的含义,容易导致误解或错误使用。
问题类型: 代码结构与可维护性 文件路径:
pooling/max_pool3d_with_argmax_v2/op_graph/max_pool3d_with_argmax_v2_proto.h行号: 51 问题代码:修改建议:
此评论由代码审查工具自动生成