已合并
err msg 整改 #5461
zhaozhoujun520创建于 5月30日
err msg 整改 #5461
已合并
共 8 个文件变更+747-298
| @@ -44,6 +44,8 @@ | |||
| 44 | 44 | ||
| 45 | 45 | ||
| 46 | 46 | ||
| 47 | + | ||
L | |||
| 48 | + | ||
| 47 | 49 | ||
| 48 | using namespace op; | 50 | using namespace op; |
| 49 | using namespace l0op; | 51 | using namespace l0op; |
| @@ -52,6 +54,8 @@ using namespace Ops::NN; | |||
| 52 | extern "C" { | 54 | extern "C" { |
| 53 | 55 | ||
| 54 | 56 | ||
| 57 | +static constexpr const char* ACLNN_CONVOLUTION_BACKWARD_NAME = "aclnnConvolutionBackwardGetWorkspaceSize"; | ||
| 58 | +static constexpr const char* ACLNN_CONV_TBC_BACKWARD_NAME = "aclnnConvTbcBackwardGetWorkspaceSize"; | ||
| 55 | constexpr int64_t DILATION_45 = 45; | 59 | constexpr int64_t DILATION_45 = 45; |
| 56 | const std::vector<DataType> REDUCESUM_SUPPORTED_DTYPES = { | 60 | const std::vector<DataType> REDUCESUM_SUPPORTED_DTYPES = { |
| 57 | DataType::DT_FLOAT16, DataType::DT_FLOAT, DataType::DT_BF16 | 61 | DataType::DT_FLOAT16, DataType::DT_FLOAT, DataType::DT_BF16 |
| @@ -111,10 +115,10 @@ static bool IsPostInsertDilation(const aclTensor *weight, const ConvolutionBackw | |||
| 111 | 115 | ||
| 112 | static bool CheckDeterministic(const int64_t deterministicValue, int groups) { | 116 | static bool CheckDeterministic(const int64_t deterministicValue, int groups) { |
| 113 | OP_CHECK(!((deterministicValue == 1) && (groups > 1)), | 117 | OP_CHECK(!((deterministicValue == 1) && (groups > 1)), |
| 114 | - OP_LOGE(ACLNN_ERR_PARAM_INVALID, "Conv3DBackpropFilter cannot support groups(%d) > 1 " | 118 | + OP_LOGE_FOR_INVALID_VALUE_WITH_REASON(ACLNN_CONVOLUTION_BACKWARD_NAME, "groups", |
| 115 | - "in deterministic calculations.", groups), | 119 | + (std::to_string(groups)).c_str(), |
| 116 | - return false; | 120 | + "the value of groups must be less than or equal to 1 when in deterministic calculations"), |
| 117 | - ); | 121 | + return false); |
| 118 | return true; | 122 | return true; |
| 119 | } | 123 | } |
| 120 | 124 | ||
| @@ -288,18 +292,21 @@ static bool CheckSupportedForConv3dBackpropFilter(ConvolutionBackwardInputTensor | |||
| 288 | } | 292 | } |
| 289 | 293 | ||
| 290 | if (params.cubeMathType == USE_FP16) { | 294 | if (params.cubeMathType == USE_FP16) { |
| 291 | - OP_LOGE(ACLNN_ERR_PARAM_INVALID, "It is not supported for Conv3DBackpropFilter when promoted input dtype is fp16/bf16, " | 295 | + OP_LOGE_FOR_INVALID_VALUE_WITH_REASON(ACLNN_CONVOLUTION_BACKWARD_NAME, "cubeMathType", |
| 292 | - "output dtype is fp32 and group > 1. cubeMathType=%d, please consider to change the cubeMathType to 0, 1 or 3." | 296 | + std::to_string(params.cubeMathType).c_str(), "the value of cubeMathType must be 0 or 1 or 3," |
| 293 | - , params.cubeMathType); | 297 | + "when promoted input dtype is fp16/bf16 and output dtype is fp32 and group > 1"); |
| 294 | return false; | 298 | return false; |
| 295 | } | 299 | } |
| 296 | 300 | ||
| 297 | auto promoteType = CalcPromoteType(inputTensor); | 301 | auto promoteType = CalcPromoteType(inputTensor); |
| 298 | if (promoteType == DataType::DT_FLOAT16 || promoteType == DataType::DT_BF16) { | 302 | if (promoteType == DataType::DT_FLOAT16 || promoteType == DataType::DT_BF16) { |
| 299 | - OP_LOGE(ACLNN_ERR_PARAM_INVALID, "It is not supported for Conv3DBackpropFilter when promoted input dtype is fp16/bf16, " | 303 | + OP_LOGE_FOR_INVALID_DTYPES_WITH_REASON(ACLNN_CONVOLUTION_BACKWARD_NAME, |
| 300 | - "output dtype is fp32 and group > 1. gradOutputDtype=%d, inputDtype=%d, weightDtype=%d, " | 304 | + "gradOutput, input, weight", |
| 301 | - "please consider to change the input dtype to fp32." | 305 | + FormatString("[%d,%d,%d]",inputTensor.gradOutput->GetDataType(), |
| 302 | - , (inputTensor.gradOutput)->GetDataType(), (inputTensor.input)->GetDataType(), (inputTensor.weight)->GetDataType()); | 306 | + inputTensor.input->GetDataType(),inputTensor.weight->GetDataType()), |
| 307 | + "when promoted input dtype is fp16/bf16, output dtype is fp32 and group > 1" | ||
| 308 | + "is not supported,please consider to change the input dtype to fp32" | ||
| 309 | + ); | ||
| 303 | return false; | 310 | return false; |
| 304 | } | 311 | } |
| 305 | 312 | ||
| @@ -467,7 +474,6 @@ static const aclTensor *ViewFZasFZ3D(const aclTensor *input, aclOpExecutor *exec | |||
| 467 | 474 | ||
| 468 | op::Strides newViewStride = op::Strides({viewStride[0], viewStride[1], viewStride[1], viewStride[2], viewStride[3]}); | 475 | op::Strides newViewStride = op::Strides({viewStride[0], viewStride[1], viewStride[1], viewStride[2], viewStride[3]}); |
| 469 | op::Shape newOriginalShape = op::Shape({originalShape[0], originalShape[1], 1, originalShape[2], originalShape[3]}); | 476 | op::Shape newOriginalShape = op::Shape({originalShape[0], originalShape[1], 1, originalShape[2], originalShape[3]}); |
| 470 | - | ||
| 471 | return CreateTensorView(input, newOriginalShape, storageShape, newViewStride, | 477 | return CreateTensorView(input, newOriginalShape, storageShape, newViewStride, |
| 472 | Format::FORMAT_NCDHW, Format::FORMAT_NCDHW, newStorageFormat, executor); | 478 | Format::FORMAT_NCDHW, Format::FORMAT_NCDHW, newStorageFormat, executor); |
| 473 | } | 479 | } |
| @@ -537,13 +543,15 @@ static aclnnStatus AttrPreProcess(ConvolutionBackwardParams ¶ms, aclOpExecut | |||
| 537 | } else if (params.padding->Size() == CONV2DINPUTDIM) { | 543 | } else if (params.padding->Size() == CONV2DINPUTDIM) { |
| 538 | params.padding = ViewPad4dAs6d(params.padding, 0, executor); | 544 | params.padding = ViewPad4dAs6d(params.padding, 0, executor); |
| 539 | } | 545 | } |
| 540 | - OP_CHECK(params.stride != nullptr, OP_LOGE(ACLNN_ERR_INNER_NULLPTR, "stride preprocess failed, get nullptr."), | 546 | + OP_CHECK(params.stride != nullptr, |
| 547 | + OP_LOGE(ACLNN_ERR_INNER_NULLPTR, "stride preprocess failed, get nullptr."), | ||
| 541 | return ACLNN_ERR_INNER_NULLPTR); | 548 | return ACLNN_ERR_INNER_NULLPTR); |
| 542 | - OP_CHECK(params.padding != nullptr, OP_LOGE(ACLNN_ERR_INNER_NULLPTR, "padding preprocess failed, get nullptr."), | 549 | + OP_CHECK(params.padding != nullptr, |
| 550 | + OP_LOGE(ACLNN_ERR_INNER_NULLPTR, "padding preprocess failed, get nullptr."), | ||
| 543 | return ACLNN_ERR_INNER_NULLPTR); | 551 | return ACLNN_ERR_INNER_NULLPTR); |
| 544 | - OP_CHECK(params.dilation != nullptr, OP_LOGE(ACLNN_ERR_INNER_NULLPTR, "dilation preprocess failed, get nullptr."), | 552 | + OP_CHECK(params.dilation != nullptr, |
| 553 | + OP_LOGE(ACLNN_ERR_INNER_NULLPTR, "dilation preprocess failed, get nullptr."), | ||
| 545 | return ACLNN_ERR_INNER_NULLPTR); | 554 | return ACLNN_ERR_INNER_NULLPTR); |
| 546 | - | ||
| 547 | return ACLNN_SUCCESS; | 555 | return ACLNN_SUCCESS; |
| 548 | } | 556 | } |
| 549 | 557 | ||
| @@ -731,8 +739,8 @@ static aclIntArray *View1dAs2d(const aclIntArray *intArray, int64_t expendValue, | |||
| 731 | int64_t data[newDimSize]; | 739 | int64_t data[newDimSize]; |
| 732 | uint64_t arraySize = intArray->Size(); | 740 | uint64_t arraySize = intArray->Size(); |
| 733 | OP_CHECK(arraySize == 1, | 741 | OP_CHECK(arraySize == 1, |
| 734 | - OP_LOGE(ACLNN_ERR_INNER_NULLPTR, "The %s's dimension can only be set to 1 with Conv1D, actually is %ld.", | 742 | + OP_LOGE_FOR_INVALID_SHAPEDIM(ACLNN_CONVOLUTION_BACKWARD_NAME, tensorName.c_str(), |
| 735 | - tensorName.c_str(), arraySize), | 743 | + std::to_string(arraySize).c_str(), "1"), |
| 736 | return nullptr); | 744 | return nullptr); |
| 737 | 745 | ||
| 738 | data[0] = expendValue; | 746 | data[0] = expendValue; |
| @@ -803,8 +811,8 @@ static aclIntArray* View1dAs2dWithGroups( | |||
| 803 | uint64_t arraySize = intArray->Size(); | 811 | uint64_t arraySize = intArray->Size(); |
| 804 | OP_CHECK( | 812 | OP_CHECK( |
| 805 | arraySize == 1, | 813 | arraySize == 1, |
| 806 | - OP_LOGE(ACLNN_ERR_INNER_NULLPTR, "The %s's dimension must be set to 1 for Conv1D, but the current value is %ld", | 814 | + OP_LOGE_FOR_INVALID_SHAPEDIM(ACLNN_CONVOLUTION_BACKWARD_NAME, tensorName.c_str(), |
| 807 | - tensorName.c_str(), arraySize), | 815 | + std::to_string(arraySize).c_str(), "1"), |
| 808 | return nullptr); | 816 | return nullptr); |
| 809 | if (groups == 1) { | 817 | if (groups == 1) { |
| 810 | data[0] = expendValue; | 818 | data[0] = expendValue; |
| @@ -1078,10 +1086,9 @@ static aclnnStatus CalculateBiasGrad(ConvolutionBackwardInputTensor &inputTensor | |||
| 1078 | bool biasSupport = std::find(REDUCESUM_SUPPORTED_DTYPES.begin(), REDUCESUM_SUPPORTED_DTYPES.end(), | 1086 | bool biasSupport = std::find(REDUCESUM_SUPPORTED_DTYPES.begin(), REDUCESUM_SUPPORTED_DTYPES.end(), |
| 1079 | outputTensor.gradBias->GetDataType()) != REDUCESUM_SUPPORTED_DTYPES.end(); | 1087 | outputTensor.gradBias->GetDataType()) != REDUCESUM_SUPPORTED_DTYPES.end(); |
| 1080 | OP_CHECK(biasSupport, | 1088 | OP_CHECK(biasSupport, |
| 1081 | - OP_LOGE(ACLNN_ERR_INNER_NULLPTR, | 1089 | + OP_LOGE_FOR_INVALID_DTYPES_WITH_REASON(ACLNN_CONVOLUTION_BACKWARD_NAME, |
| 1082 | - "When outputMask[2] = True, the gradBias current dataType[%s] is not supported. " | 1090 | + "gradBias", op::ToString(outputTensor.gradBias->GetDataType()).GetString(), |
| 1083 | - "The supported dataType include: DT_FLOAT16, DT_FLOAT, DT_BF16. Please try set outputMask[2] = False", | 1091 | + "When outputMask[2] = True, the gradBias dataType must be [DT_FLOAT16, DT_FLOAT, DT_BF16]"), |
| 1084 | - op::ToString(outputTensor.gradBias->GetDataType()).GetString()), | ||
| 1085 | return ACLNN_ERR_INNER_NULLPTR); | 1092 | return ACLNN_ERR_INNER_NULLPTR); |
| 1086 | } | 1093 | } |
| 1087 | 1094 | ||
| @@ -1322,7 +1329,8 @@ static aclnnStatus CalculateConv2DBackward(ConvolutionBackwardInputTensor &input | |||
| 1322 | auto curArch = GetCurrentPlatformInfo().GetCurNpuArch(); | 1329 | auto curArch = GetCurrentPlatformInfo().GetCurNpuArch(); |
| 1323 | // 950:无2D原型,直接抛错 | 1330 | // 950:无2D原型,直接抛错 |
| 1324 | OP_CHECK(!(Ops::NN::AclnnUtil::IsRegbase(curArch)), | 1331 | OP_CHECK(!(Ops::NN::AclnnUtil::IsRegbase(curArch)), |
| 1325 | - OP_LOGE(ACLNN_ERR_INNER_NULLPTR, "No kernel for Conv2DBackwardFiler"), | 1332 | + OP_LOGE_FOR_INVALID_VALUE_WITH_REASON(ACLNN_CONVOLUTION_BACKWARD_NAME, "npuarch", |
| 1333 | + std::to_string(static_cast<uint32_t>(curArch)).c_str(), "the value of npuarch must not be 3510, No kernel for Conv2DBackwardFiler"), | ||
| 1326 | return ACLNN_ERR_INNER_NULLPTR); | 1334 | return ACLNN_ERR_INNER_NULLPTR); |
| 1327 | // Index 为 2:进行bias grad运算 | 1335 | // Index 为 2:进行bias grad运算 |
| 1328 | aclnnStatus ret = CalculateBiasGrad(inputTensor, outputTensor, params, executor); | 1336 | aclnnStatus ret = CalculateBiasGrad(inputTensor, outputTensor, params, executor); |
| @@ -1475,7 +1483,9 @@ static aclnnStatus CalculateConv2DTransposeBackward(ConvolutionBackwardInputTens | |||
| 1475 | auto curArch = GetCurrentPlatformInfo().GetCurNpuArch(); | 1483 | auto curArch = GetCurrentPlatformInfo().GetCurNpuArch(); |
| 1476 | // 950:无2D原型,直接抛错 | 1484 | // 950:无2D原型,直接抛错 |
| 1477 | OP_CHECK(!(Ops::NN::AclnnUtil::IsRegbase()), | 1485 | OP_CHECK(!(Ops::NN::AclnnUtil::IsRegbase()), |
| 1478 | - OP_LOGE(ACLNN_ERR_INNER_NULLPTR, "No kernel for Conv2DBackwardFiler"), | 1486 | + OP_LOGE_FOR_INVALID_VALUE_WITH_REASON(ACLNN_CONVOLUTION_BACKWARD_NAME, "npuarch", |
| 1487 | + std::to_string(static_cast<uint32_t>(curArch)).c_str(), | ||
| 1488 | + "the value of npuarch must not be 3510, No kernel for Conv2DBackwardFiler"), | ||
| 1479 | return ACLNN_ERR_INNER_NULLPTR); | 1489 | return ACLNN_ERR_INNER_NULLPTR); |
| 1480 | // Index 为 2:进行bias grad运算 | 1490 | // Index 为 2:进行bias grad运算 |
| 1481 | aclnnStatus ret = CalculateBiasGrad(inputTensor, outputTensor, params, executor); | 1491 | aclnnStatus ret = CalculateBiasGrad(inputTensor, outputTensor, params, executor); |
| @@ -2905,7 +2915,8 @@ static aclnnStatus CalculateConv3DBp(ConvolutionBackwardInputTensor &inputTensor | |||
| 2905 | { | 2915 | { |
| 2906 | auto curArch = GetCurrentPlatformInfo().GetCurNpuArch(); | 2916 | auto curArch = GetCurrentPlatformInfo().GetCurNpuArch(); |
| 2907 | OP_CHECK(curArch == NpuArch::DAV_2201 || Ops::NN::AclnnUtil::IsRegbase(curArch), | 2917 | OP_CHECK(curArch == NpuArch::DAV_2201 || Ops::NN::AclnnUtil::IsRegbase(curArch), |
| 2908 | - OP_LOGE(ACLNN_ERR_PARAM_INVALID, "not implemented for %u", static_cast<uint32_t>(curArch)), | 2918 | + OP_LOGE_FOR_INVALID_VALUE_WITH_REASON(ACLNN_CONVOLUTION_BACKWARD_NAME, "npuArch", |
| 2919 | + std::to_string(static_cast<uint32_t>(curArch)).c_str(), "the value of npuarch must not be 2201 or 3510"), | ||
| 2909 | return ACLNN_ERR_PARAM_INVALID); | 2920 | return ACLNN_ERR_PARAM_INVALID); |
| 2910 | auto ret = CheckCubeMathTypeFor3D(inputTensor, params); | 2921 | auto ret = CheckCubeMathTypeFor3D(inputTensor, params); |
| 2911 | CHECK_RET(ret == ACLNN_SUCCESS, ACLNN_ERR_PARAM_INVALID); | 2922 | CHECK_RET(ret == ACLNN_SUCCESS, ACLNN_ERR_PARAM_INVALID); |
| @@ -3026,8 +3037,8 @@ static aclnnStatus CalculateConvolutionBackward(ConvolutionBackwardInputTensor & | |||
| 3026 | auto ret = CalculateConv3DBp(inputTensor, resultTensor, params, executor); | 3037 | auto ret = CalculateConv3DBp(inputTensor, resultTensor, params, executor); |
| 3027 | CHECK_RET(ret == ACLNN_SUCCESS, ret); | 3038 | CHECK_RET(ret == ACLNN_SUCCESS, ret); |
| 3028 | } else { | 3039 | } else { |
| 3029 | - OP_LOGE(ACLNN_ERR_PARAM_INVALID, | 3040 | + OP_LOGE_FOR_INVALID_SHAPEDIM(ACLNN_CONVOLUTION_BACKWARD_NAME, "input", |
| 3030 | - "aclnnConvolutionBackward only supports input with dimensions 3, 4, or 5, Actually is %ld.", inputDim); | 3041 | + std::to_string(inputDim).c_str(), "3 or 4 or 5"); |
| 3031 | return ACLNN_ERR_PARAM_INVALID; | 3042 | return ACLNN_ERR_PARAM_INVALID; |
| 3032 | } | 3043 | } |
| 3033 | auto ret = OutputViewProcess(resultTensor, outputTensor, params.outputMask, executor); | 3044 | auto ret = OutputViewProcess(resultTensor, outputTensor, params.outputMask, executor); |
| @@ -3106,8 +3117,8 @@ static aclnnStatus CalculateConvolutionTbcBackward(ConvolutionBackwardInputTenso | |||
| 3106 | CHECK_RET(ret == ACLNN_SUCCESS, ACLNN_ERR_PARAM_NULLPTR); | 3117 | CHECK_RET(ret == ACLNN_SUCCESS, ACLNN_ERR_PARAM_NULLPTR); |
| 3107 | } | 3118 | } |
| 3108 | } else { | 3119 | } else { |
| 3109 | - OP_LOGE(ACLNN_ERR_INNER_NULLPTR, | 3120 | + OP_LOGE_FOR_INVALID_SHAPEDIM(ACLNN_CONV_TBC_BACKWARD_NAME, "input", |
| 3110 | - "ConvolutionTbcBackward only supports input with dimensions 3, Actually is %ld.", inputDim); | 3121 | + std::to_string(inputDim).c_str(), "3"); |
| 3111 | return ACLNN_ERR_INNER_NULLPTR; | 3122 | return ACLNN_ERR_INNER_NULLPTR; |
| 3112 | } | 3123 | } |
| 3113 | // recover NCL to TBC | 3124 | // recover NCL to TBC |
| @@ -8,14 +8,18 @@ | |||
| 8 | * See LICENSE in the root of the software repository for the full text of the License. | 8 | * See LICENSE in the root of the software repository for the full text of the License. |
| 9 | */ | 9 | */ |
| 10 | 10 | ||
| 11 | + | ||
| 11 | 12 | ||
| 12 | using namespace op; | 13 | using namespace op; |
| 13 | using namespace l0op; | 14 | using namespace l0op; |
| 14 | using namespace Ops::NN; | 15 | using namespace Ops::NN; |
| 15 | 16 | ||
| 17 | + | ||
| 16 | 18 | ||
| 17 | extern "C" { | 19 | extern "C" { |
| 18 | 20 | ||
| 21 | + | ||
| 22 | +static constexpr const char* ACLNN_CONVOLUTION_BACKWARD_NAME = "aclnnConvolutionBackwardGetWorkspaceSize"; | ||
| 19 | // 工具方法---------------------------------------------------------------------------------------------------------- | 23 | // 工具方法---------------------------------------------------------------------------------------------------------- |
| 20 | bool CheckDtypeValid(const aclTensor *inputTensor, bool transposed) { | 24 | bool CheckDtypeValid(const aclTensor *inputTensor, bool transposed) { |
| 21 | // 检查输入aclTensor的数据类型是否在ConvolutionBackward支持列表内 | 25 | // 检查输入aclTensor的数据类型是否在ConvolutionBackward支持列表内 |
| @@ -48,20 +52,23 @@ bool CheckFormatValid(const aclTensor *inputTensor, const string &tensorName) { | |||
| 48 | auto inputDim = inputTensor->GetViewShape().GetDimNum(); | 52 | auto inputDim = inputTensor->GetViewShape().GetDimNum(); |
| 49 | if (inputDim == CONV1DINPUTDIM) { | 53 | if (inputDim == CONV1DINPUTDIM) { |
| 50 | OP_CHECK(inputFormat == op::Format::FORMAT_ND || inputFormat == op::Format::FORMAT_NCL, | 54 | OP_CHECK(inputFormat == op::Format::FORMAT_ND || inputFormat == op::Format::FORMAT_NCL, |
| 51 | - OP_LOGE(ACLNN_ERR_PARAM_INVALID, "In 1D scenes, the %s format only supports ND and NCL, but received %s.", | 55 | + OP_LOGE_FOR_INVALID_FORMAT(ACLNN_CONVOLUTION_BACKWARD_NAME, tensorName.c_str(), |
| 52 | - tensorName.c_str(), inputFormatStr.c_str()), return false); | 56 | + inputFormatStr.c_str(),"ND or NCL"), |
| 57 | + return false); | ||
| 53 | } else if (inputDim == CONV2DINPUTDIM) { | 58 | } else if (inputDim == CONV2DINPUTDIM) { |
| 54 | OP_CHECK(inputFormat == op::Format::FORMAT_NCHW, | 59 | OP_CHECK(inputFormat == op::Format::FORMAT_NCHW, |
| 55 | - OP_LOGE(ACLNN_ERR_PARAM_INVALID, "In 2D scenes, the %s format only supports NCHW, but received %s.", | 60 | + OP_LOGE_FOR_INVALID_FORMAT(ACLNN_CONVOLUTION_BACKWARD_NAME, tensorName.c_str(), |
| 56 | - tensorName.c_str(), inputFormatStr.c_str()), return false); | 61 | + inputFormatStr.c_str(),"NCHW"), |
| 62 | + return false); | ||
| 57 | } else if (inputDim == CONV3DINPUTDIM) { | 63 | } else if (inputDim == CONV3DINPUTDIM) { |
| 58 | OP_CHECK(inputFormat == op::Format::FORMAT_NCDHW, | 64 | OP_CHECK(inputFormat == op::Format::FORMAT_NCDHW, |
| 59 | - OP_LOGE(ACLNN_ERR_PARAM_INVALID, "In 3D scenes, the %s format only supports NCDHW, but received %s.", | 65 | + OP_LOGE_FOR_INVALID_FORMAT(ACLNN_CONVOLUTION_BACKWARD_NAME, tensorName.c_str(), |
| 60 | - tensorName.c_str(), inputFormatStr.c_str()), return false); | 66 | + inputFormatStr.c_str(),"NCDHW"), |
| 67 | + return false); | ||
| 61 | } else { | 68 | } else { |
| 62 | - OP_LOGE( | 69 | + OP_LOGE_FOR_INVALID_SHAPEDIM(ACLNN_CONVOLUTION_BACKWARD_NAME, tensorName.c_str(), |
| 63 | - ACLNN_ERR_PARAM_INVALID, "The %s tensor dimension of this API only supports 3~5 dimensions.", | 70 | + std::to_string(inputDim).c_str(), "3 or 4 or 5" |
| 64 | - tensorName.c_str()); | 71 | + ); |
| 65 | return false; | 72 | return false; |
| 66 | } | 73 | } |
| 67 | return true; | 74 | return true; |
| @@ -94,9 +101,12 @@ bool CheckResolutionGEKernelShape(const op::Shape &inputShape, const op::Shape & | |||
| 94 | int64_t dimInput = inputShape.GetDim(dimIdx) + (*params.padding)[dimOrder] * 2 - filterDimDilation; // 2 : pad two dim | 101 | int64_t dimInput = inputShape.GetDim(dimIdx) + (*params.padding)[dimOrder] * 2 - filterDimDilation; // 2 : pad two dim |
| 95 | bool dimInputExpect = dimInput >= 0; | 102 | bool dimInputExpect = dimInput >= 0; |
| 96 | OP_CHECK(dimInputExpect, | 103 | OP_CHECK(dimInputExpect, |
| 97 | - OP_LOGE(ACLNN_ERR_PARAM_INVALID, | 104 | + OP_LOGE_FOR_INVALID_SHAPEDIMS_WITH_REASON(ACLNN_CONVOLUTION_BACKWARD_NAME, "input, padding", |
| 98 | - "(in_dim(%ld) + pad_dim(%ld) * 2) should >= ((weight_shape(%ld) - 1) * dilation(%ld) + 1)", | 105 | + FormatString("%ld,%ld", inputShape.GetDim(dimIdx), (*params.padding)[dimOrder]), |
| 99 | - inputShape.GetDim(dimIdx), (*params.padding)[dimOrder], weightShape[dimIdx], (*params.dilation)[dimOrder]), | 106 | + FormatString("(in_dim + pad_dim * 2) should be greater than or equal to " |
| 107 | + "((weight_shape - 1) * dilation + 1), current in_dim=%d, pad_dim=%d, weight_shape=%d, dilation=%d", | ||
| 108 | + inputShape.GetDim(dimIdx), (*params.padding)[dimOrder], weightShape[dimIdx], (*params.dilation)[dimOrder] | ||
| 109 | + )), | ||
| 100 | return false); | 110 | return false); |
| 101 | return true; | 111 | return true; |
| 102 | } | 112 | } |
| @@ -148,9 +158,12 @@ bool CheckResolutionGEKernelShape_95(int64_t inputVal, int64_t weightVal, int64_ | |||
| 148 | int64_t dimInput = inputVal + (*params.padding)[dimOrder] * 2 - filterDimDilation; // 2 : pad two dim | 158 | int64_t dimInput = inputVal + (*params.padding)[dimOrder] * 2 - filterDimDilation; // 2 : pad two dim |
| 149 | bool dimInputExpect = dimInput >= 0; | 159 | bool dimInputExpect = dimInput >= 0; |
| 150 | OP_CHECK(dimInputExpect, | 160 | OP_CHECK(dimInputExpect, |
| 151 | - OP_LOGE(ACLNN_ERR_PARAM_INVALID, | 161 | + OP_LOGE_FOR_INVALID_SHAPEDIMS_WITH_REASON(ACLNN_CONVOLUTION_BACKWARD_NAME, "input, padding", |
| 152 | - "(in_dim(%ld) + pad_dim(%ld) * 2) should >= ((weight_shape(%ld) - 1) * dilation(%ld) + 1)", | 162 | + FormatString("%ld,%ld", inputVal, (*params.padding)[dimOrder]), |
| 153 | - inputVal, (*params.padding)[dimOrder], weightVal, (*params.dilation)[dimOrder]), | 163 | + FormatString("(in_dim + pad_dim * 2) should be greater than or equal to " |
| 164 | + "((weight_shape - 1) * dilation + 1), current in_dim=%d, pad_dim=%d, weight_shape=%d, dilation=%d", | ||
| 165 | + inputVal, (*params.padding)[dimOrder], weightVal, (*params.dilation)[dimOrder] | ||
| 166 | + )), | ||
| 154 | return false); | 167 | return false); |
| 155 | return true; | 168 | return true; |
| 156 | } | 169 | } |
| @@ -239,9 +252,10 @@ bool ConvolutionBackwardChecker::CheckDataTypeValidForGradInput() { | |||
| 239 | return true; | 252 | return true; |
| 240 | } | 253 | } |
| 241 | OP_CHECK(outputTensor_.gradInput->GetDataType() == inputTensor_.input->GetDataType(), | 254 | OP_CHECK(outputTensor_.gradInput->GetDataType() == inputTensor_.input->GetDataType(), |
| 242 | - OP_LOGE(ACLNN_ERR_INNER_NULLPTR, "gradInput data type[%s] should be equal to input data type[%s]", | 255 | + OP_LOGE_FOR_INVALID_DTYPES_WITH_REASON(ACLNN_CONVOLUTION_BACKWARD_NAME, "gradInput, input", |
| 243 | - op::ToString(outputTensor_.gradInput->GetDataType()).GetString(), | 256 | + FormatString("%s,%s", outputTensor_.gradInput->GetDataType(), inputTensor_.input->GetDataType()), |
| 244 | - op::ToString(inputTensor_.input->GetDataType()).GetString()), return false); | 257 | + "the dtypes of [gradInput, input] must be the same"), |
| 258 | + return false); | ||
| 245 | return true; | 259 | return true; |
| 246 | } | 260 | } |
| 247 | 261 | ||
| @@ -255,9 +269,10 @@ bool ConvolutionBackwardChecker::CheckDataTypeValidForGradWeight() { | |||
| 255 | } | 269 | } |
| 256 | 270 | ||
| 257 | OP_CHECK(outputTensor_.gradWeight->GetDataType() == inputTensor_.weight->GetDataType(), | 271 | OP_CHECK(outputTensor_.gradWeight->GetDataType() == inputTensor_.weight->GetDataType(), |
| 258 | - OP_LOGE(ACLNN_ERR_INNER_NULLPTR, "gradWeight data type[%s] should be equal to weight data type[%s]", | 272 | + OP_LOGE_FOR_INVALID_DTYPES_WITH_REASON(ACLNN_CONVOLUTION_BACKWARD_NAME, "gradWeight, weight", |
| 259 | - op::ToString(outputTensor_.gradWeight->GetDataType()).GetString(), | 273 | + FormatString("%s,%s", outputTensor_.gradWeight->GetDataType(), inputTensor_.weight->GetDataType()), |
| 260 | - op::ToString(inputTensor_.weight->GetDataType()).GetString()), return false); | 274 | + "the dtypes of [gradWeight, weight] must be the same"), |
| 275 | + return false); | ||
| 261 | return true; | 276 | return true; |
| 262 | } | 277 | } |
| 263 | 278 | ||
| @@ -266,9 +281,11 @@ bool ConvolutionBackwardChecker::CheckDataTypeValidForGradBias() { | |||
| 266 | return true; | 281 | return true; |
| 267 | } | 282 | } |
| 268 | OP_CHECK(outputTensor_.gradBias->GetDataType() == inputTensor_.gradOutput->GetDataType(), | 283 | OP_CHECK(outputTensor_.gradBias->GetDataType() == inputTensor_.gradOutput->GetDataType(), |
| 269 | - OP_LOGE(ACLNN_ERR_INNER_NULLPTR, "gradBias data type[%s] should be equal to gradOutput data type[%s]", | 284 | + OP_LOGE_FOR_INVALID_DTYPES_WITH_REASON(ACLNN_CONVOLUTION_BACKWARD_NAME, "gradBias, gradOutput", |
| 270 | - op::ToString(outputTensor_.gradBias->GetDataType()).GetString(), | 285 | + FormatString("%s,%s",op::ToString(outputTensor_.gradBias->GetDataType()).GetString(), |
| 271 | - op::ToString(inputTensor_.gradOutput->GetDataType()).GetString()), return false); | 286 | + op::ToString(inputTensor_.gradOutput->GetDataType()).GetString()), |
| 287 | + "the dtypes of [gradBias, gradOutput] must be the same"), | ||
| 288 | + return false); | ||
| 272 | return true; | 289 | return true; |
| 273 | } | 290 | } |
| 274 | 291 | ||
| @@ -281,19 +298,19 @@ bool ConvolutionBackwardChecker::CheckParamsValidForBpFilter8bit() { | |||
| 281 | // check outputpadding for transposed | 298 | // check outputpadding for transposed |
| 282 | if (params_.transposed) { | 299 | if (params_.transposed) { |
| 283 | OP_CHECK(CheckParamsValueAllZero(params_.outputPadding), | 300 | OP_CHECK(CheckParamsValueAllZero(params_.outputPadding), |
| 284 | - OP_LOGE(ACLNN_ERR_PARAM_INVALID, "When transpose is true and the input data type is %s or %s, " | 301 | + OP_LOGE_FOR_INVALID_VALUE_WITH_REASON(ACLNN_CONVOLUTION_BACKWARD_NAME, "outputPadding", |
| 285 | - "the value of outputPadding[%s] must be all 0", | 302 | + AclarrayToString(params_.outputPadding).c_str(), |
| 286 | - op::ToString(DataType::DT_HIFLOAT8).GetString(), | 303 | + "When transpose is true and the input data type is DT_HIFLOAT8 or DT_FLOAT8_E4M3FN,the value of outputPadding must be all 0" |
| 287 | - op::ToString(DataType::DT_FLOAT8_E4M3FN).GetString(), | 304 | + ), return false); |
| 288 | - AclarrayToString(params_.outputPadding).c_str()), return false); | ||
| 289 | } | 305 | } |
| 290 | 306 | ||
| 291 | // check groups | 307 | // check groups |
| 292 | OP_CHECK(params_.groups == 1, | 308 | OP_CHECK(params_.groups == 1, |
| 293 | - OP_LOGE(ACLNN_ERR_PARAM_INVALID, "When outputMask[1] = True, %s dtype only supports groups = 1, currently is %ld", | 309 | + OP_LOGE_FOR_INVALID_VALUE_WITH_REASON(ACLNN_CONVOLUTION_BACKWARD_NAME, "groups", |
| 294 | - op::ToString(inputTensor_.input->GetDataType()).GetString(), params_.groups), | 310 | + std::to_string(params_.groups).c_str(), |
| 311 | + FormatString("When outputMask[1] = True and dtype = %s,the value of groups must be 1", op::ToString(inputTensor_.input->GetDataType())) | ||
| 312 | + ), | ||
| 295 | return false); | 313 | return false); |
| 296 | - | ||
| 297 | return true; | 314 | return true; |
| 298 | } | 315 | } |
| 299 | 316 | ||
| @@ -306,18 +323,15 @@ bool ConvolutionBackwardChecker::InterceptConvFor8bit() | |||
| 306 | if((outputTensor_.gradInput != nullptr)&& (outputTensor_.gradWeight !=nullptr)){ | 323 | if((outputTensor_.gradInput != nullptr)&& (outputTensor_.gradWeight !=nullptr)){ |
| 307 | if (IsConv8bit(inputTensor_.gradOutput->GetDataType()) || IsConv8bit(inputTensor_.input->GetDataType()) || | 324 | if (IsConv8bit(inputTensor_.gradOutput->GetDataType()) || IsConv8bit(inputTensor_.input->GetDataType()) || |
| 308 | IsConv8bit(inputTensor_.weight->GetDataType()) || IsConv8bit(outputTensor_.gradInput->GetDataType()) || | 325 | IsConv8bit(inputTensor_.weight->GetDataType()) || IsConv8bit(outputTensor_.gradInput->GetDataType()) || |
| 309 | - IsConv8bit(outputTensor_.gradWeight->GetDataType())) { | 326 | + IsConv8bit(outputTensor_.gradWeight->GetDataType())) { |
| 310 | - OP_LOGE( | 327 | + OP_LOGE_FOR_INVALID_DTYPES_WITH_REASON(ACLNN_CONVOLUTION_BACKWARD_NAME, |
| 311 | - ACLNN_ERR_PARAM_INVALID, | 328 | + "gradOutput, input, weight, gradInput, gradWeight", |
| 312 | - "The dtype of DT_HIFLOAT8 or DT_FLOAT8_E4M3FN is not supported now, " | 329 | + FormatString("%s,%s,%s,%s,%s", inputTensor_.gradOutput->GetDataType(), |
| 313 | - "currently gradOutput is %s, input is %s, weight is %s, gradInput is %s, " | 330 | + inputTensor_.input->GetDataType(), inputTensor_.weight->GetDataType(), |
| 314 | - "gradWeight is %s. ", | 331 | + outputTensor_.gradInput->GetDataType(), outputTensor_.gradWeight->GetDataType() |
| 315 | - op::ToString(inputTensor_.gradOutput->GetDataType()).GetString(), | 332 | + ), |
| 316 | - op::ToString(inputTensor_.input->GetDataType()).GetString(), | 333 | + "the dtypes of [gradBias, gradOutput] must not be the DT_HIFLOAT8 or DT_FLOAT8_E4M3FN"); |
| 317 | - op::ToString(inputTensor_.weight->GetDataType()).GetString(), | 334 | + return false; |
| 318 | - op::ToString(outputTensor_.gradInput->GetDataType()).GetString(), | ||
| 319 | - op::ToString(outputTensor_.gradWeight->GetDataType()).GetString()); | ||
| 320 | - return false; | ||
| 321 | } | 335 | } |
| 322 | } | 336 | } |
| 323 | 337 | ||
| @@ -343,25 +357,24 @@ bool ConvolutionBackwardChecker::CheckDtypeValidFor8bit(const DataType& dType) { | |||
| 343 | } | 357 | } |
| 344 | 358 | ||
| 345 | if (outputTensor_.gradBias != nullptr) { | 359 | if (outputTensor_.gradBias != nullptr) { |
| 346 | - OP_CHECK(!is8bitFlag || all8bitFlag, | 360 | + OP_CHECK(!is8bitFlag || all8bitFlag, |
| 347 | - OP_LOGE(ACLNN_ERR_PARAM_INVALID, "When any input or output data types is %s, all of them must be %s, " | 361 | + OP_LOGE_FOR_INVALID_DTYPES_WITH_REASON(ACLNN_CONVOLUTION_BACKWARD_NAME, |
| 348 | - "currently gradOutput is %s, input is %s, weight is %s, gradInput is %s, gradBias is %s", | 362 | + "gradOutput, input, weight, gradInput, gradBias", |
| 349 | - op::ToString(dType).GetString(), op::ToString(dType).GetString(), | 363 | + FormatString("%s,%s,%s,%s,%s", inputTensor_.gradOutput->GetDataType(), |
| 350 | - op::ToString(inputTensor_.gradOutput->GetDataType()).GetString(), | 364 | + inputTensor_.input->GetDataType(), inputTensor_.weight->GetDataType(), |
| 351 | - op::ToString(inputTensor_.input->GetDataType()).GetString(), | 365 | + outputTensor_.gradInput->GetDataType(), outputTensor_.gradBias->GetDataType() |
| 352 | - op::ToString(inputTensor_.weight->GetDataType()).GetString(), | 366 | + ), FormatString("the dtypes of [gradOutput, input, weight, gradInput, gradBias] must be the %s," |
| 353 | - op::ToString(outputTensor_.gradInput->GetDataType()).GetString(), | 367 | + "when any input or output data types is %s", op::ToString(dType).GetString(), op::ToString(dType).GetString())), |
| 354 | - op::ToString(outputTensor_.gradBias->GetDataType()).GetString()), | ||
| 355 | return false); | 368 | return false); |
| 356 | } else { | 369 | } else { |
| 357 | OP_CHECK(!is8bitFlag || all8bitFlag, | 370 | OP_CHECK(!is8bitFlag || all8bitFlag, |
| 358 | - OP_LOGE(ACLNN_ERR_PARAM_INVALID, "When any input or output data types is %s, all of them must be %s, " | 371 | + OP_LOGE_FOR_INVALID_DTYPES_WITH_REASON(ACLNN_CONVOLUTION_BACKWARD_NAME, |
| 359 | - "currently gradOutput is %s, input is %s, weight is %s, gradInput is %s", | 372 | + "gradOutput, input, weight, gradInput", |
| 360 | - op::ToString(dType).GetString(), op::ToString(dType).GetString(), | 373 | + FormatString("%s,%s,%s,%s", inputTensor_.gradOutput->GetDataType(), |
| 361 | - op::ToString(inputTensor_.gradOutput->GetDataType()).GetString(), | 374 | + inputTensor_.input->GetDataType(), inputTensor_.weight->GetDataType(), |
| 362 | - op::ToString(inputTensor_.input->GetDataType()).GetString(), | 375 | + outputTensor_.gradInput->GetDataType()), |
| 363 | - op::ToString(inputTensor_.weight->GetDataType()).GetString(), | 376 | + FormatString("the dtypes of [gradOutput, input, weight, gradInput] must be the %s," |
| 364 | - op::ToString(outputTensor_.gradInput->GetDataType()).GetString()), | 377 | + "when any input or output data types is %s", op::ToString(dType).GetString(), op::ToString(dType).GetString())), |
| 365 | return false); | 378 | return false); |
| 366 | } | 379 | } |
| 367 | return true; | 380 | return true; |
| @@ -381,27 +394,24 @@ bool ConvolutionBackwardChecker::CheckDtypeValidForBpFilter8bit(const DataType& | |||
| 381 | } | 394 | } |
| 382 | 395 | ||
| 383 | if (outputTensor_.gradBias != nullptr) { | 396 | if (outputTensor_.gradBias != nullptr) { |
| 384 | - OP_CHECK(!is8bitFlag || all8bitFlag, | 397 | + OP_CHECK(!is8bitFlag || all8bitFlag, |
| 385 | - OP_LOGE(ACLNN_ERR_PARAM_INVALID, "When outputMask[1] = true, any input or gradBias data types is %s, " | 398 | + OP_LOGE_FOR_INVALID_DTYPES_WITH_REASON(ACLNN_CONVOLUTION_BACKWARD_NAME, |
| 386 | - "all input and gradBias data types must be %s, and gradWeight data type must be %s, " | 399 | + "gradOutput, input, weight, gradWeight, gradBias", |
| 387 | - "currently gradOutput is %s, input is %s, weight is %s, gradWeight is %s, gradBias is %s", | 400 | + FormatString("%s,%s,%s,%s,%s", inputTensor_.gradOutput->GetDataType(), |
| 388 | - op::ToString(dType).GetString(), op::ToString(dType).GetString(), op::ToString(DataType::DT_FLOAT).GetString(), | 401 | + inputTensor_.input->GetDataType(), inputTensor_.weight->GetDataType(), |
| 389 | - op::ToString(inputTensor_.gradOutput->GetDataType()).GetString(), | 402 | + outputTensor_.gradWeight->GetDataType(), outputTensor_.gradBias->GetDataType() |
| 390 | - op::ToString(inputTensor_.input->GetDataType()).GetString(), | 403 | + ), FormatString("the dtypes of [gradOutput, input, weight, gradWeight, gradBias] must be the %s," |
| 391 | - op::ToString(inputTensor_.weight->GetDataType()).GetString(), | 404 | + "when outputMask[1] = true, any input or gradBias data types is is %s", |
| 392 | - op::ToString(outputTensor_.gradWeight->GetDataType()).GetString(), | 405 | + op::ToString(dType).GetString(), op::ToString(dType).GetString())), return false); |
| 393 | - op::ToString(outputTensor_.gradBias->GetDataType()).GetString()), | ||
| 394 | - return false); | ||
| 395 | } else { | 406 | } else { |
| 396 | - OP_CHECK(!is8bitFlag || all8bitFlag, | 407 | + OP_CHECK(!is8bitFlag || all8bitFlag, |
| 397 | - OP_LOGE(ACLNN_ERR_PARAM_INVALID, "When outputMask[1] = true, any input data types is %s, " | 408 | + OP_LOGE_FOR_INVALID_DTYPES_WITH_REASON(ACLNN_CONVOLUTION_BACKWARD_NAME, |
| 398 | - "all input data types must be %s, and gradWeight data type must be %s, " | 409 | + "gradOutput, input, weight, gradWeight", |
| 399 | - "currently gradOutput is %s, input is %s, weight is %s, gradWeight is %s", | 410 | + FormatString("%s,%s,%s,%s", inputTensor_.gradOutput->GetDataType(), |
| 400 | - op::ToString(dType).GetString(), op::ToString(dType).GetString(), op::ToString(DataType::DT_FLOAT).GetString(), | 411 | + inputTensor_.input->GetDataType(), inputTensor_.weight->GetDataType(), |
| 401 | - op::ToString(inputTensor_.gradOutput->GetDataType()).GetString(), | 412 | + outputTensor_.gradWeight->GetDataType() |
| 402 | - op::ToString(inputTensor_.input->GetDataType()).GetString(), | 413 | + ), FormatString("the dtypes of [gradOutput, input, weight, gradWeight] must be the %s," |
| 403 | - op::ToString(inputTensor_.weight->GetDataType()).GetString(), | 414 | + "when one of them dtype is %s", op::ToString(dType).GetString(), op::ToString(dType).GetString())), |
| 404 | - op::ToString(outputTensor_.gradWeight->GetDataType()).GetString()), | ||
| 405 | return false); | 415 | return false); |
| 406 | } | 416 | } |
| 407 | 417 | ||
| @@ -415,56 +425,69 @@ bool ConvolutionBackwardChecker::CheckDtypeValidForBpFilter8bit(const DataType& | |||
| 415 | } | 425 | } |
| 416 | 426 | ||
| 417 | bool isFp8Flag = isGradOutputFp8 || isInputFp8 || isWeightFp8 || isGradWeightFp8 || isGradBiasFp8; | 427 | bool isFp8Flag = isGradOutputFp8 || isInputFp8 || isWeightFp8 || isGradWeightFp8 || isGradBiasFp8; |
| 418 | - OP_CHECK(!isFp8Flag, | 428 | + OP_CHECK(!isFp8Flag, OP_LOGE_FOR_INVALID_DTYPES_WITH_REASON(ACLNN_CONVOLUTION_BACKWARD_NAME, |
| 419 | - OP_LOGE(ACLNN_ERR_PARAM_INVALID, "When outputMask[1] = true, not support dataType of all input and output being DT_FLOAT8_E4M3FN now"), return false); | 429 | + "gradOutput, input, weight, gradWeight, gradBias", |
| 430 | + FormatString("%s,%s,%s,%s,%s", inputTensor_.gradOutput->GetDataType(), | ||
| 431 | + inputTensor_.input->GetDataType(), inputTensor_.weight->GetDataType(), | ||
| 432 | + outputTensor_.gradWeight->GetDataType(), outputTensor_.gradBias->GetDataType()), | ||
| 433 | + "the dtypes of [gradOutput, input, weight, gradWeight, gradBias] must not be DT_FLOAT8_E4M3FN"), | ||
| 434 | + return false); | ||
| 420 | return true; | 435 | return true; |
| 421 | } | 436 | } |
| 422 | 437 | ||
| 423 | bool ConvolutionBackwardChecker::CheckConvParams(size_t inputDim) { | 438 | bool ConvolutionBackwardChecker::CheckConvParams(size_t inputDim) { |
| 424 | // stride >= 1 | 439 | // stride >= 1 |
| 425 | OP_CHECK(CheckParamsValue(params_.stride, false), | 440 | OP_CHECK(CheckParamsValue(params_.stride, false), |
| 426 | - OP_LOGE(ACLNN_ERR_PARAM_INVALID, "The value of stride[%s] must be greater than or equal to 1.", | 441 | + OP_LOGE_FOR_INVALID_VALUE_WITH_REASON(ACLNN_CONVOLUTION_BACKWARD_NAME, "stride", |
| 427 | - AclarrayToString(params_.stride).c_str()), | 442 | + AclarrayToString(params_.stride).c_str(), |
| 428 | - return false); | 443 | + "the value of stride must be greater than or equal to 1" |
| 444 | + ), return false); | ||
| 429 | 445 | ||
| 430 | // padding >= 0 | 446 | // padding >= 0 |
| 431 | OP_CHECK(CheckParamsValue(params_.padding, true), | 447 | OP_CHECK(CheckParamsValue(params_.padding, true), |
| 432 | - OP_LOGE(ACLNN_ERR_PARAM_INVALID, "The value of padding[%s] must be greater than or equal to 0.", | 448 | + OP_LOGE_FOR_INVALID_VALUE_WITH_REASON(ACLNN_CONVOLUTION_BACKWARD_NAME, "padding", |
| 433 | - AclarrayToString(params_.padding).c_str()), | 449 | + AclarrayToString(params_.padding).c_str(), |
| 434 | - return false); | 450 | + "the value of padding must be greater than or equal to 0" |
| 451 | + ), return false); | ||
| 435 | 452 | ||
| 436 | // dilation >= 1 | 453 | // dilation >= 1 |
| 437 | OP_CHECK(CheckParamsValue(params_.dilation, false), | 454 | OP_CHECK(CheckParamsValue(params_.dilation, false), |
| 438 | - OP_LOGE(ACLNN_ERR_PARAM_INVALID, "The value of dilation[%s] must be greater than or equal to 1.", | 455 | + OP_LOGE_FOR_INVALID_VALUE_WITH_REASON(ACLNN_CONVOLUTION_BACKWARD_NAME, "dilation", |
| 439 | - AclarrayToString(params_.dilation).c_str()), | 456 | + AclarrayToString(params_.dilation).c_str(), |
| 440 | - return false); | 457 | + "the value of dilation must be greater than or equal to 1" |
| 458 | + ), return false); | ||
| 441 | // outputPadding >= 0 | 459 | // outputPadding >= 0 |
| 442 | if (params_.transposed) { | 460 | if (params_.transposed) { |
| 443 | OP_CHECK(CheckParamsValue(params_.outputPadding, true), | 461 | OP_CHECK(CheckParamsValue(params_.outputPadding, true), |
| 444 | - OP_LOGE(ACLNN_ERR_PARAM_INVALID, "The value of outputPadding[%s] must be greater than or equal to 0 if transposed", | 462 | + OP_LOGE_FOR_INVALID_VALUE_WITH_REASON(ACLNN_CONVOLUTION_BACKWARD_NAME, "outputPadding", |
| 445 | - AclarrayToString(params_.outputPadding).c_str()), | 463 | + AclarrayToString(params_.outputPadding).c_str(), |
| 446 | - return false); | 464 | + "when transposed=true, the value of outputPadding must be greater than or equal to 0" |
| 465 | + ), return false); | ||
| 447 | if (inputDim == CONV3DINPUTDIM) { | 466 | if (inputDim == CONV3DINPUTDIM) { |
| 448 | for (uint64_t i = 0; i < params_.outputPadding->Size(); ++i) { | 467 | for (uint64_t i = 0; i < params_.outputPadding->Size(); ++i) { |
| 449 | OP_CHECK((*params_.outputPadding)[i] < (*params_.stride)[i], | 468 | OP_CHECK((*params_.outputPadding)[i] < (*params_.stride)[i], |
| 450 | - OP_LOGE(ACLNN_ERR_PARAM_INVALID, "The value of outputPadding[%s] should be smaller than stride[%s]", | 469 | + OP_LOGE_FOR_INVALID_VALUE_WITH_REASON(ACLNN_CONVOLUTION_BACKWARD_NAME, "outputPadding", |
| 451 | - AclarrayToString(params_.outputPadding).c_str(), AclarrayToString(params_.stride).c_str()), | 470 | + AclarrayToString(params_.outputPadding).c_str(), |
| 452 | - return false); | 471 | + "when transposed=true, the value of outputPadding must be less than or equal to stride" |
| 472 | + ), return false); | ||
| 453 | } | 473 | } |
| 454 | } | 474 | } |
| 455 | } else if (params_.outputPadding != nullptr) { // !transposed, outputPadding value is unneeded | 475 | } else if (params_.outputPadding != nullptr) { // !transposed, outputPadding value is unneeded |
| 456 | for (uint64_t i = 0; i < params_.outputPadding->Size(); ++i) { | 476 | for (uint64_t i = 0; i < params_.outputPadding->Size(); ++i) { |
| 457 | OP_CHECK((*params_.outputPadding)[i] == 0, | 477 | OP_CHECK((*params_.outputPadding)[i] == 0, |
| 458 | - OP_LOGE(ACLNN_ERR_PARAM_INVALID, "The value of outputPadding[%s] must be 0 if not transposed", | 478 | + OP_LOGE_FOR_INVALID_VALUE_WITH_REASON(ACLNN_CONVOLUTION_BACKWARD_NAME, "outputPadding", |
| 459 | - AclarrayToString(params_.outputPadding).c_str()), | 479 | + AclarrayToString(params_.outputPadding).c_str(), |
| 460 | - return false); | 480 | + "when transposed=false, the value of outputPadding must be 0" |
| 481 | + ), return false); | ||
| 461 | } | 482 | } |
| 462 | } | 483 | } |
| 463 | 484 | ||
| 464 | // group >= 1 | 485 | // group >= 1 |
| 465 | OP_CHECK(params_.groups >= 1, | 486 | OP_CHECK(params_.groups >= 1, |
| 466 | - OP_LOGE(ACLNN_ERR_PARAM_INVALID, "The group[%d] must be greater than or equal to 1.", params_.groups), | 487 | + OP_LOGE_FOR_INVALID_VALUE_WITH_REASON(ACLNN_CONVOLUTION_BACKWARD_NAME, "group", |
| 467 | - return false); | 488 | + std::to_string(params_.groups).c_str(), |
| 489 | + "the value of groups must be greater than or equal to 1" | ||
| 490 | + ), return false); | ||
| 468 | return true; | 491 | return true; |
| 469 | } | 492 | } |
| 470 | 493 | ||
| @@ -490,13 +513,24 @@ bool ConvolutionBackwardChecker::CheckConvShape() { | |||
| 490 | auto weightDim = inputTensor_.weight->GetViewShape().GetDimNum(); | 513 | auto weightDim = inputTensor_.weight->GetViewShape().GetDimNum(); |
| 491 | 514 | ||
| 492 | OP_CHECK(gradOutputDim == inputDim, | 515 | OP_CHECK(gradOutputDim == inputDim, |
| 493 | - OP_LOGE(ACLNN_ERR_PARAM_INVALID, "The dim of gradOutput and input should be equal."), return false); | 516 | + OP_LOGE_FOR_INVALID_SHAPEDIMS_WITH_REASON(ACLNN_CONVOLUTION_BACKWARD_NAME, "gradOutput, input", |
| 517 | + (std::to_string(gradOutputDim) + "," + std::to_string(inputDim)).c_str(), | ||
| 518 | + "the shape dim of [gradOutput, input] must be the same" | ||
| 519 | + ), | ||
| 520 | + return false); | ||
| 494 | 521 | ||
| 495 | - OP_CHECK(inputDim == weightDim, OP_LOGE(ACLNN_ERR_PARAM_INVALID, "The dim of input and weight should be equal."), | 522 | + OP_CHECK(inputDim == weightDim, |
| 523 | + OP_LOGE_FOR_INVALID_SHAPEDIMS_WITH_REASON(ACLNN_CONVOLUTION_BACKWARD_NAME, "input, weight", | ||
| 524 | + (std::to_string(inputDim) + "," + std::to_string(weightDim)).c_str(), | ||
| 525 | + "the shape dim of [input, weight] must be the same" | ||
| 526 | + ), | ||
| 496 | return false); | 527 | return false); |
| 497 | // 检查gradOutput和weight是否为空tensor | 528 | // 检查gradOutput和weight是否为空tensor |
| 498 | OP_CHECK(inputTensor_.gradOutput->Size() != 0 && inputTensor_.weight->Size() != 0, | 529 | OP_CHECK(inputTensor_.gradOutput->Size() != 0 && inputTensor_.weight->Size() != 0, |
| 499 | - OP_LOGE(ACLNN_ERR_PARAM_INVALID, "The gradOutput and weight cannot be empty tensor."), | 530 | + OP_LOGE_FOR_INVALID_SHAPESIZE_WITH_REASON( |
| 531 | + ACLNN_CONVOLUTION_BACKWARD_NAME, "gradOutput,weight", | ||
| 532 | + FormatString("%ld,%ld", inputTensor_.gradOutput->Size(), inputTensor_.weight->Size()), | ||
| 533 | + "[gradOutput,weight] do not support empty tensors"), | ||
| 500 | return false); | 534 | return false); |
| 501 | if (outputTensor_.gradInput != nullptr) { | 535 | if (outputTensor_.gradInput != nullptr) { |
| 502 | OP_CHECK_SHAPE_NOT_EQUAL(inputTensor_.input, outputTensor_.gradInput, return false); | 536 | OP_CHECK_SHAPE_NOT_EQUAL(inputTensor_.input, outputTensor_.gradInput, return false); |
| @@ -512,22 +546,29 @@ bool ConvolutionBackwardChecker::CheckConvShape() { | |||
| 512 | int64_t cOut = inputTensor_.gradOutput->GetViewShape().GetDim(channelOutIdx); | 546 | int64_t cOut = inputTensor_.gradOutput->GetViewShape().GetDim(channelOutIdx); |
| 513 | if (outputTensor_.gradBias != nullptr) { | 547 | if (outputTensor_.gradBias != nullptr) { |
| 514 | OP_CHECK(outputTensor_.gradBias->GetViewShape().GetDimNum() == 1, | 548 | OP_CHECK(outputTensor_.gradBias->GetViewShape().GetDimNum() == 1, |
| 515 | - OP_LOGE(ACLNN_ERR_PARAM_INVALID, "The dimension of gradBias only supports 1."), return false); | 549 | + OP_LOGE_FOR_INVALID_SHAPEDIM(ACLNN_CONVOLUTION_BACKWARD_NAME, "gradBias", |
| 550 | + std::to_string(outputTensor_.gradBias->GetViewShape().GetDimNum()).c_str(), "1"), | ||
| 551 | + return false); | ||
| 516 | OP_CHECK(outputTensor_.gradBias->GetViewShape().GetDim(0) == cOut, | 552 | OP_CHECK(outputTensor_.gradBias->GetViewShape().GetDim(0) == cOut, |
| 517 | - OP_LOGE(ACLNN_ERR_PARAM_INVALID, "The gradBias shape should be equal [%ld].", cOut), return false); | 553 | + OP_LOGE_FOR_INVALID_SHAPE_WITH_REASON(ACLNN_CONVOLUTION_BACKWARD_NAME, "gradBias", |
| 554 | + FormatString("[%ld]", outputTensor_.gradBias->GetViewShape().GetDim(0)), | ||
| 555 | + FormatString("The gradBias shape should be equal [%ld]", cOut)), | ||
| 556 | + return false); | ||
| 518 | } | 557 | } |
| 519 | 558 | ||
| 520 | int64_t paramsDim = inputDim - 2; // 参数维度应该等于输入tensor维度-2 | 559 | int64_t paramsDim = inputDim - 2; // 参数维度应该等于输入tensor维度-2 |
| 521 | int64_t strideDim = params_.stride->Size(); | 560 | int64_t strideDim = params_.stride->Size(); |
| 522 | OP_CHECK(strideDim == paramsDim, | 561 | OP_CHECK(strideDim == paramsDim, |
| 523 | - OP_LOGE(ACLNN_ERR_PARAM_INVALID, "When the input dimension is %ld, the dimension of stride should be %ld.", | 562 | + OP_LOGE_FOR_INVALID_SHAPEDIMS_WITH_REASON(ACLNN_CONVOLUTION_BACKWARD_NAME, "stride, input", |
| 524 | - inputDim, paramsDim), | 563 | + FormatString("%ld, %ld", strideDim, inputDim), |
| 564 | + "the shape dim of [stride] must be 2 less than the shape dim of input"), | ||
| 525 | return false); | 565 | return false); |
| 526 | 566 | ||
| 527 | int64_t dilationDim = params_.dilation->Size(); | 567 | int64_t dilationDim = params_.dilation->Size(); |
| 528 | OP_CHECK(dilationDim == paramsDim, | 568 | OP_CHECK(dilationDim == paramsDim, |
| 529 | - OP_LOGE(ACLNN_ERR_PARAM_INVALID, | 569 | + OP_LOGE_FOR_INVALID_SHAPEDIMS_WITH_REASON(ACLNN_CONVOLUTION_BACKWARD_NAME, "dilation, input", |
| 530 | - "When the input dimension is %ld, the dimension of dilation should be %ld.", inputDim, paramsDim), | 570 | + FormatString("%ld, %ld", dilationDim, inputDim), |
| 571 | + "the shape dim of [dilation] must be 2 less the shape dim of input"), | ||
| 531 | return false); | 572 | return false); |
| 532 | 573 | ||
| 533 | int64_t paddingDim = params_.padding->Size(); | 574 | int64_t paddingDim = params_.padding->Size(); |
| @@ -535,28 +576,33 @@ bool ConvolutionBackwardChecker::CheckConvShape() { | |||
| 535 | if (inputDim == CONV2DINPUTDIM) { | 576 | if (inputDim == CONV2DINPUTDIM) { |
| 536 | // padding类支持4维输入 | 577 | // padding类支持4维输入 |
| 537 | OP_CHECK(paddingDim == paramsDim || paddingDim == CONV2DINPUTDIM, | 578 | OP_CHECK(paddingDim == paramsDim || paddingDim == CONV2DINPUTDIM, |
| 538 | - OP_LOGE(ACLNN_ERR_PARAM_INVALID, | 579 | + OP_LOGE_FOR_INVALID_SHAPEDIMS_WITH_REASON(ACLNN_CONVOLUTION_BACKWARD_NAME, "padding, input", |
| 539 | - "When the input dimension is %ld, the dimension of padding should be %ld or %d.", inputDim, | 580 | + FormatString("%ld,%ld", paddingDim, inputDim), |
| 540 | - paramsDim, CONV2DINPUTDIM), | 581 | + FormatString("the shape dim of [dilation] must be %ld or %ld, when dim of input is %ld", |
| 582 | + paramsDim, CONV2DINPUTDIM, inputDim)), | ||
| 541 | return false); | 583 | return false); |
| 542 | 584 | ||
| 543 | OP_CHECK(outputPaddingDim == paramsDim || outputPaddingDim == CONV2DINPUTDIM, | 585 | OP_CHECK(outputPaddingDim == paramsDim || outputPaddingDim == CONV2DINPUTDIM, |
| 544 | - OP_LOGE(ACLNN_ERR_PARAM_INVALID, | 586 | + OP_LOGE_FOR_INVALID_SHAPEDIMS_WITH_REASON(ACLNN_CONVOLUTION_BACKWARD_NAME, "outputPadding, input", |
| 545 | - "When the input dimension is %ld, the dimension of outputPadding should be %ld or %d.", | 587 | + FormatString("%ld,%ld", outputPaddingDim, inputDim), |
| 546 | - inputDim, paramsDim, CONV2DINPUTDIM), | 588 | + FormatString("the shape dim of [outputPadding] must be %ld or %ld, when dim of input is %ld", |
| 589 | + paramsDim, CONV2DINPUTDIM, inputDim)), | ||
| 547 | return false); | 590 | return false); |
| 548 | } else { | 591 | } else { |
| 549 | OP_CHECK( | 592 | OP_CHECK( |
| 550 | paddingDim == paramsDim, | 593 | paddingDim == paramsDim, |
| 551 | - OP_LOGE(ACLNN_ERR_PARAM_INVALID, "When the input dimension is %ld, the dimension of padding should be %ld.", | 594 | + OP_LOGE_FOR_INVALID_SHAPEDIMS_WITH_REASON(ACLNN_CONVOLUTION_BACKWARD_NAME, "padding, input", |
| 552 | - inputDim, paramsDim), | 595 | + FormatString("%ld,%ld", paddingDim, inputDim), |
| 596 | + FormatString("the shape dim of [paddingDim] must be %ld, when dim of input is %ld", | ||
| 597 | + paramsDim, inputDim)), | ||
| 553 | return false); | 598 | return false); |
| 554 | 599 | ||
| 555 | OP_CHECK(outputPaddingDim == paramsDim, | 600 | OP_CHECK(outputPaddingDim == paramsDim, |
| 556 | - OP_LOGE(ACLNN_ERR_PARAM_INVALID, | 601 | + OP_LOGE_FOR_INVALID_SHAPEDIMS_WITH_REASON(ACLNN_CONVOLUTION_BACKWARD_NAME, "outputPadding, input", |
| 557 | - "When the input dimension is %ld, the dimension of outputPadding should be %ld.", inputDim, | 602 | + FormatString("%ld,%ld", outputPaddingDim, inputDim), |
| 558 | - paramsDim), | 603 | + FormatString("the shape dim of [outputPadding] must be %ld, when dim of input is %ld", |
| 559 | - return false); | 604 | + paramsDim, inputDim)), |
| 605 | + return false); | ||
| 560 | } | 606 | } |
| 561 | 607 | ||
| 562 | return true; | 608 | return true; |
| @@ -581,35 +627,39 @@ bool ConvolutionBackwardChecker::CheckConvChannelAndGroup() { | |||
| 581 | GetChannleIndex(weightShape, weightFormat, weightCinIdx); | 627 | GetChannleIndex(weightShape, weightFormat, weightCinIdx); |
| 582 | } | 628 | } |
| 583 | OP_CHECK(gradOutShape.GetDim(gradOutputChannelIdx) == weightShape.GetDim(weightCoutIdx), // 0: NCHW, the order of N(out_channel) | 629 | OP_CHECK(gradOutShape.GetDim(gradOutputChannelIdx) == weightShape.GetDim(weightCoutIdx), // 0: NCHW, the order of N(out_channel) |
| 584 | - OP_LOGE(ACLNN_ERR_PARAM_INVALID, "gradOutput_channel(%ld) != weight_N_dim(%ld)", | 630 | + OP_LOGE_FOR_INVALID_SHAPEDIMS_WITH_REASON(ACLNN_CONVOLUTION_BACKWARD_NAME, FormatString("gradOutShape[%ld], weight[%ld]", |
| 585 | - gradOutShape.GetDim(gradOutputChannelIdx), weightShape.GetDim(weightCoutIdx)), | 631 | + gradOutputChannelIdx, weightCoutIdx), FormatString("%ld, %ld", gradOutShape.GetDim(gradOutputChannelIdx), |
| 586 | - return false); | 632 | + weightShape.GetDim(weightCoutIdx)), "the shape dim of [gradOutShape[1], weight[0]] must be the same."), return false); |
| 587 | 633 | ||
| 588 | bool channelCheck = weightShape.GetDim(weightCinIdx) == 0 || | 634 | bool channelCheck = weightShape.GetDim(weightCinIdx) == 0 || |
| 589 | - inputShape.GetDim(inputChannelIdx) % weightShape.GetDim(weightCinIdx) != 0; | 635 | + inputShape.GetDim(inputChannelIdx) % weightShape.GetDim(weightCinIdx) != 0; |
| 590 | - OP_CHECK(!channelCheck, | 636 | + OP_CHECK(!channelCheck, OP_LOGE_FOR_INVALID_SHAPEDIMS_WITH_REASON(ACLNN_CONVOLUTION_BACKWARD_NAME, |
| 591 | - OP_LOGE(ACLNN_ERR_PARAM_INVALID, "input_channel(%ld) %% weight_channel(%ld) != 0", | 637 | + FormatString("inputShape[%ld], weight[%ld]", inputChannelIdx, weightCinIdx), FormatString("%ld,%ld", |
| 592 | - inputShape.GetDim(inputChannelIdx), weightShape.GetDim(weightCinIdx)), | 638 | + inputShape.GetDim(inputChannelIdx), weightShape.GetDim(weightCinIdx)), FormatString("the shape dim of inputShape[%ld] " |
| 593 | - return false); | 639 | + "must be divisable by the shape dim of weight[%ld]", inputChannelIdx, weightCinIdx)), return false); |
| 594 | 640 | ||
| 595 | int32_t groups = inputShape.GetDim(inputChannelIdx) / weightShape.GetDim(weightCinIdx); | 641 | int32_t groups = inputShape.GetDim(inputChannelIdx) / weightShape.GetDim(weightCinIdx); |
| 596 | bool groupCheck = groups == params_.groups; | 642 | bool groupCheck = groups == params_.groups; |
| 597 | - OP_CHECK(groupCheck, | 643 | + OP_CHECK(groupCheck, OP_LOGE_FOR_INVALID_SHAPEDIMS_WITH_REASON(ACLNN_CONVOLUTION_BACKWARD_NAME, |
| 598 | - OP_LOGE(ACLNN_ERR_PARAM_INVALID, "input_channel(%ld) / weight_channel(%ld) != groups(%ld)", | 644 | + FormatString("inputShape[%ld], weight[%ld]", inputChannelIdx, weightCinIdx), |
| 599 | - inputShape.GetDim(inputChannelIdx), weightShape.GetDim(weightCinIdx), params_.groups), | 645 | + FormatString("%ld,%ld", inputShape.GetDim(inputChannelIdx), weightShape.GetDim(weightCinIdx)), |
| 600 | - return false); | 646 | + FormatString("the shape dim of inputShape[%ld] must equal to (the shape dim of weight[%ld] times the value of groups).", |
| 647 | + inputChannelIdx, weightCinIdx)), return false); | ||
| 601 | 648 | ||
| 602 | - if (inputShape.GetDim(inputChannelIdx) == params_.groups && (!Ops::NN::AclnnUtil::IsRegbase())){ | 649 | + if (inputShape.GetDim(inputChannelIdx) == params_.groups && (!Ops::NN::AclnnUtil::IsRegbase())) { |
| 603 | auto outChannel = gradOutShape.GetDim(inputChannelIdx); | 650 | auto outChannel = gradOutShape.GetDim(inputChannelIdx); |
| 604 | - OP_CHECK(outChannel >= params_.groups, | 651 | + OP_CHECK(outChannel >= params_.groups, OP_LOGE_FOR_INVALID_SHAPEDIMS_WITH_REASON(ACLNN_CONVOLUTION_BACKWARD_NAME, |
| 605 | - OP_LOGE(ACLNN_ERR_PARAM_INVALID, "when input_channel(%ld) == groups(%ld), output_channel(%ld) need bigger groups", | 652 | + FormatString("gradOutShape[%ld], inputShape[%ld]", inputChannelIdx, inputChannelIdx), |
| 606 | - inputShape.GetDim(inputChannelIdx), params_.groups, outChannel), | 653 | + FormatString("%ld,%ld", gradOutShape.GetDim(inputChannelIdx), inputShape.GetDim(inputChannelIdx)), |
| 607 | - return false); | 654 | + FormatString("the shape dim of gradOutShape[%ld] must be greater than or equal to the value of groups," |
| 655 | + "when the shape dim of inputShape[%ld] == the value of groups", inputChannelIdx, inputChannelIdx)), return false); | ||
| 608 | 656 | ||
| 609 | OP_CHECK(gradOutShape.GetDim(inputChannelIdx) % params_.groups == 0, | 657 | OP_CHECK(gradOutShape.GetDim(inputChannelIdx) % params_.groups == 0, |
| 610 | - OP_LOGE(ACLNN_ERR_PARAM_INVALID, "when input_channel(%ld) == groups(%ld), output_channel(%ld) need k times input_channel", | 658 | + OP_LOGE_FOR_INVALID_SHAPEDIMS_WITH_REASON(ACLNN_CONVOLUTION_BACKWARD_NAME, |
| 611 | - inputShape.GetDim(inputChannelIdx), params_.groups, outChannel), | 659 | + FormatString("gradOutShape[%ld], inputShape[%ld]", inputChannelIdx, inputChannelIdx), |
| 612 | - return false); | 660 | + FormatString("%ld,%ld", gradOutShape.GetDim(inputChannelIdx), inputShape.GetDim(inputChannelIdx)), |
| 661 | + FormatString("the shape dim of gradOutShape[%ld] must be divisible by the value of groups," | ||
| 662 | + "when the shape dim of inputShape[%ld] equals to the value of groups", inputChannelIdx, inputChannelIdx)),return false); | ||
| 613 | } | 663 | } |
| 614 | 664 | ||
| 615 | return true; | 665 | return true; |
| @@ -656,10 +706,13 @@ bool ConvolutionBackwardChecker::CheckConvShapePlus() { | |||
| 656 | expectCheck = (expectValue.doExpect == gradOutputDVal) && (expectValue.hoExpect == gradOutputHVal) && | 706 | expectCheck = (expectValue.doExpect == gradOutputDVal) && (expectValue.hoExpect == gradOutputHVal) && |
| 657 | (expectValue.woExpect == gradOutputWVal); | 707 | (expectValue.woExpect == gradOutputWVal); |
| 658 | } | 708 | } |
| 659 | - OP_CHECK(expectCheck, OP_LOGE(ACLNN_ERR_PARAM_INVALID, | 709 | + |
| 660 | - "gradOutput's shape%s is not equal to inferred shape[%ld,%ld,%ld,%ld,%ld]", | 710 | + OP_CHECK(expectCheck, |
| 661 | - op::ToString(gradOutShape).GetString(), gradOutShape.GetDim(0), gradOutputCout, | 711 | + OP_LOGE_FOR_INVALID_SHAPE_WITH_REASON(ACLNN_CONVOLUTION_BACKWARD_NAME, "gradOutput", op::ToString(gradOutShape).GetString(), |
| 662 | - expectValue.doExpect, expectValue.hoExpect, expectValue.woExpect), return false); | 712 | + FormatString("shape of gradOutput should equal to [%ld, %ld,%ld,%ld,%ld]", |
| 713 | + gradOutShape.GetDim(0), gradOutputCout, expectValue.doExpect, expectValue.hoExpect, expectValue.woExpect | ||
| 714 | + )), | ||
| 715 | + return false); | ||
| 663 | } | 716 | } |
| 664 | return true; | 717 | return true; |
| 665 | } | 718 | } |
| @@ -676,7 +729,9 @@ inline bool ConvolutionBackwardChecker::CheckNotNull() { | |||
| 676 | 729 | ||
| 677 | int64_t outputMaskDim = params_.outputMask->Size(); | 730 | int64_t outputMaskDim = params_.outputMask->Size(); |
| 678 | // outputMask的维度必须为3 | 731 | // outputMask的维度必须为3 |
| 679 | - OP_CHECK(outputMaskDim == 3, OP_LOGE(ACLNN_ERR_PARAM_INVALID, "The dim of outputMask must be equal 3."), | 732 | + OP_CHECK(outputMaskDim == 3, |
| 733 | + OP_LOGE_FOR_INVALID_SHAPEDIM(ACLNN_CONVOLUTION_BACKWARD_NAME, "outputMask", | ||
| 734 | + std::to_string(outputMaskDim).c_str(), "3"), | ||
| 680 | return false); | 735 | return false); |
| 681 | if ((*params_.outputMask)[0]) { | 736 | if ((*params_.outputMask)[0]) { |
| 682 | OP_CHECK_NULL(outputTensor_.gradInput, return false); | 737 | OP_CHECK_NULL(outputTensor_.gradInput, return false); |
| @@ -746,8 +801,9 @@ aclnnStatus ConvolutionBackwardChecker::CheckParams() { | |||
| 746 | if (!params_.transposed && outputTensor_.gradBias != nullptr) { | 801 | if (!params_.transposed && outputTensor_.gradBias != nullptr) { |
| 747 | if (curArch == NpuArch::DAV_2201 || Ops::NN::AclnnUtil::IsRegbase(curArch)) { | 802 | if (curArch == NpuArch::DAV_2201 || Ops::NN::AclnnUtil::IsRegbase(curArch)) { |
| 748 | OP_CHECK(outputTensor_.gradBias->GetStorageFormat() == op::Format::FORMAT_ND, | 803 | OP_CHECK(outputTensor_.gradBias->GetStorageFormat() == op::Format::FORMAT_ND, |
| 749 | - OP_LOGE(ACLNN_ERR_INNER_NULLPTR, "gradBias format only supports ND, but get [%s].", | 804 | + OP_LOGE_FOR_INVALID_FORMAT(ACLNN_CONVOLUTION_BACKWARD_NAME, "gradBias", |
| 750 | - op::ToString(outputTensor_.gradBias->GetStorageFormat()).GetString()), return ACLNN_ERR_PARAM_INVALID); | 805 | + op::ToString(outputTensor_.gradBias->GetStorageFormat()).GetString(),"ND"), |
| 806 | + return ACLNN_ERR_PARAM_INVALID); | ||
| 751 | } | 807 | } |
| 752 | } | 808 | } |
| 753 | 809 | ||
| @@ -767,9 +823,11 @@ bool ConvolutionBackwardChecker::CheckParamsDim() { | |||
| 767 | auto inputDim = inputTensor_.input->GetViewShape().GetDimNum(); | 823 | auto inputDim = inputTensor_.input->GetViewShape().GetDimNum(); |
| 768 | uint64_t paramsDim = inputDim - 2; // 参数维度应该等于输入tensor维度-2 | 824 | uint64_t paramsDim = inputDim - 2; // 参数维度应该等于输入tensor维度-2 |
| 769 | auto validDim = [inputDim, paramsDim](bool condition, const char* paramName) -> bool { | 825 | auto validDim = [inputDim, paramsDim](bool condition, const char* paramName) -> bool { |
| 826 | + std::string paramNameStr = paramName; | ||
| 770 | OP_CHECK(condition, | 827 | OP_CHECK(condition, |
| 771 | - OP_LOGE(ACLNN_ERR_PARAM_INVALID, "When the input dimension is %ld, the dimension of %s should be %ld.", | 828 | + OP_LOGE_FOR_INVALID_SHAPEDIMS_WITH_REASON(ACLNN_CONVOLUTION_BACKWARD_NAME, FormatString("%s,input", paramNameStr), |
| 772 | - inputDim, paramName, paramsDim), | 829 | + FormatString("%ld, %ld", paramsDim, inputDim), FormatString("the shape dim of %s must be %ld," |
| 830 | + ". when the input dim of input is %ld", paramNameStr, paramsDim, inputDim)), | ||
| 773 | return false); | 831 | return false); |
| 774 | return true; | 832 | return true; |
| 775 | }; | 833 | }; |
| @@ -791,8 +849,9 @@ bool ConvolutionBackwardChecker::CheckParamsGroup() { | |||
| 791 | auto weightCin = weightShape.GetDim(1); | 849 | auto weightCin = weightShape.GetDim(1); |
| 792 | int64_t weightCout = weightShape.GetDim(0); | 850 | int64_t weightCout = weightShape.GetDim(0); |
| 793 | OP_CHECK((params_.groups != 0 && weightCout % params_.groups == 0), | 851 | OP_CHECK((params_.groups != 0 && weightCout % params_.groups == 0), |
| 794 | - OP_LOGE(ACLNN_ERR_PARAM_INVALID, "output_channel(%ld) %% groups(%ld) != 0", | 852 | + OP_LOGE_FOR_INVALID_SHAPEDIM_WITH_REASON(ACLNN_CONVOLUTION_BACKWARD_NAME, "weight[0]", |
| 795 | - weightCout, params_.groups), | 853 | + FormatString("%ld", weightCout), |
| 854 | + "the dim of weight[0] should be divisible by groups when the value of groups is not 0"), | ||
| 796 | return false); | 855 | return false); |
| 797 | 856 | ||
| 798 | if (params_.transposed && gradOutShape[0] == 0) { | 857 | if (params_.transposed && gradOutShape[0] == 0) { |
| @@ -802,9 +861,9 @@ bool ConvolutionBackwardChecker::CheckParamsGroup() { | |||
| 802 | if (inputChannel != 0 || weightCin != 0) { | 861 | if (inputChannel != 0 || weightCin != 0) { |
| 803 | bool channelCheck = (weightCin == 0 || inputChannel % weightCin != 0 || inputChannel / weightCin != params_.groups); | 862 | bool channelCheck = (weightCin == 0 || inputChannel % weightCin != 0 || inputChannel / weightCin != params_.groups); |
| 804 | OP_CHECK(!channelCheck, | 863 | OP_CHECK(!channelCheck, |
| 805 | - OP_LOGE(ACLNN_ERR_PARAM_INVALID, "%s(%ld) need groups(%ld) times weight_channel(%ld)", | 864 | + OP_LOGE_FOR_INVALID_SHAPEDIMS_WITH_REASON(ACLNN_CONVOLUTION_BACKWARD_NAME, "input[1], weight[1]", |
| 806 | - params_.transposed ? "gradOutput_channel": "inputChannel", | 865 | + FormatString("%ld, %ld", inputChannel, weightCin), |
| 807 | - inputChannel, params_.groups, weightCin), | 866 | + "the dim of input[1] must equals to (the dim of weight[1] times the value of groups)"), |
| 808 | return false); | 867 | return false); |
| 809 | } | 868 | } |
| 810 | 869 | ||
| @@ -821,9 +880,12 @@ bool ConvolutionBackwardChecker::CheckShape() { | |||
| 821 | int64_t filterDimDilation = (weightShape[i] - 1) * (*params_.dilation)[index] + 1; | 880 | int64_t filterDimDilation = (weightShape[i] - 1) * (*params_.dilation)[index] + 1; |
| 822 | int64_t dimInput = inputShape.GetDim(i) + (*params_.padding)[index] * 2 - filterDimDilation; // 2: pad two dim | 881 | int64_t dimInput = inputShape.GetDim(i) + (*params_.padding)[index] * 2 - filterDimDilation; // 2: pad two dim |
| 823 | OP_CHECK(dimInput >= 0, | 882 | OP_CHECK(dimInput >= 0, |
| 824 | - OP_LOGE(ACLNN_ERR_PARAM_INVALID, | 883 | + OP_LOGE_FOR_INVALID_SHAPEDIMS_WITH_REASON(ACLNN_CONVOLUTION_BACKWARD_NAME, FormatString("input[%ld]",i), |
| 825 | - "At dimension %ld, (in_dim(%ld) + pad_dim(%ld) * 2) should >= ((weight_shape(%ld) - 1) * dilation(%ld) + 1)", | 884 | + (std::to_string(inputShape.GetDim(i))).c_str(), |
| 826 | - i, inputShape.GetDim(i), (*params_.padding)[index], weightShape[i], (*params_.dilation)[index]), | 885 | + FormatString("(in_dim + pad_dim * 2) should >= ((weight_shape - 1) * dilation + 1) when at dimension %ld," |
| 886 | + "current in_dim=%ld, pad_dim=%ld, weight_shape=%ld, dilation=%ld" | ||
| 887 | + , i, inputShape.GetDim(i), (*params_.padding)[index], weightShape[i], (*params_.dilation)[index]) | ||
| 888 | + ), | ||
| 827 | return false); | 889 | return false); |
| 828 | } | 890 | } |
| 829 | return true; | 891 | return true; |
| @@ -833,10 +895,12 @@ bool ConvolutionBackwardChecker::CheckShapeTransposed() { | |||
| 833 | int64_t inputC = inputTensor_.input->GetViewShape().GetDim(1); | 895 | int64_t inputC = inputTensor_.input->GetViewShape().GetDim(1); |
| 834 | int64_t weightCo = inputTensor_.weight->GetViewShape().GetDim(0); | 896 | int64_t weightCo = inputTensor_.weight->GetViewShape().GetDim(0); |
| 835 | OP_CHECK(weightCo > 0, | 897 | OP_CHECK(weightCo > 0, |
| 836 | - OP_LOGE(ACLNN_ERR_PARAM_INVALID, "Weight Cout should be greater than 0."), | 898 | + OP_LOGE_FOR_INVALID_SHAPEDIM(ACLNN_CONVOLUTION_BACKWARD_NAME, "weightCo", std::to_string(weightCo).c_str() |
| 899 | + , "0"), | ||
| 837 | return false); | 900 | return false); |
| 838 | OP_CHECK(weightCo == inputC, | 901 | OP_CHECK(weightCo == inputC, |
| 839 | - OP_LOGE(ACLNN_ERR_PARAM_INVALID, "weight Cout should be %ld, but get %ld", inputC, weightCo), | 902 | + OP_LOGE_FOR_INVALID_SHAPEDIMS_WITH_REASON(ACLNN_CONVOLUTION_BACKWARD_NAME, "inputC, weightCo", |
| 903 | + (std::to_string(inputC) + "," + std::to_string(weightCo)).c_str() , "inputC"), | ||
| 840 | return false); | 904 | return false); |
| 841 | return true; | 905 | return true; |
| 842 | } | 906 | } |
| @@ -857,22 +921,26 @@ bool ConvolutionBackwardChecker::CheckEmptyTensor() { | |||
| 857 | // 空tensor场景且需要计算gradBias, biasSizes不能为nullptr | 921 | // 空tensor场景且需要计算gradBias, biasSizes不能为nullptr |
| 858 | if ((*params_.outputMask)[2]) { | 922 | if ((*params_.outputMask)[2]) { |
| 859 | OP_CHECK(params_.biasSizes != nullptr, | 923 | OP_CHECK(params_.biasSizes != nullptr, |
| 860 | - OP_LOGE(ACLNN_ERR_PARAM_INVALID, "The biasSizes cannot be nullptr with empty tensor calculation."), | 924 | + OP_LOGE_WITH_INVALID_ATTR(ACLNN_CONVOLUTION_BACKWARD_NAME, "biasSizes", "nullptr", "not nullptr"), |
| 861 | return false); | 925 | return false); |
| 862 | OP_CHECK(params_.biasSizes->Size() == 1, | 926 | OP_CHECK(params_.biasSizes->Size() == 1, |
| 863 | - OP_LOGE(ACLNN_ERR_PARAM_INVALID, "The biasSizes size must be 1, actually is %ld.", | 927 | + OP_LOGE_WITH_INVALID_ATTR_SIZE(ACLNN_CONVOLUTION_BACKWARD_NAME, "biasSizes", |
| 864 | - params_.biasSizes->Size()), | 928 | + std::to_string(params_.biasSizes->Size()).c_str() , "1"), |
| 865 | return false); | 929 | return false); |
| 866 | int64_t channelOutDim = 1; // NCHW | 930 | int64_t channelOutDim = 1; // NCHW |
| 867 | int64_t Cout = inputTensor_.gradOutput->GetViewShape().GetDim(channelOutDim); | 931 | int64_t Cout = inputTensor_.gradOutput->GetViewShape().GetDim(channelOutDim); |
| 868 | if (!params_.transposed) { | 932 | if (!params_.transposed) { |
| 869 | OP_CHECK((*params_.biasSizes)[0] == Cout, | 933 | OP_CHECK((*params_.biasSizes)[0] == Cout, |
| 870 | - OP_LOGE(ACLNN_ERR_PARAM_INVALID, "The biasSizes should be equal %ld.", Cout), return false); | 934 | + OP_LOGE_WITH_INVALID_ATTR(ACLNN_CONVOLUTION_BACKWARD_NAME, "biasSizes", |
| 935 | + std::to_string((*params_.biasSizes)[0]).c_str(), std::to_string(Cout).c_str()), | ||
| 936 | + return false); | ||
| 871 | } else { | 937 | } else { |
| 872 | // transposed=true: bias = weight[Cin] * group | 938 | // transposed=true: bias = weight[Cin] * group |
| 873 | auto size = inputTensor_.weight->GetViewShape().GetDim(1) * params_.groups; | 939 | auto size = inputTensor_.weight->GetViewShape().GetDim(1) * params_.groups; |
| 874 | OP_CHECK((*params_.biasSizes)[0] == size, | 940 | OP_CHECK((*params_.biasSizes)[0] == size, |
| 875 | - OP_LOGE(ACLNN_ERR_PARAM_INVALID, "When transposed=true, the biasSizes should be equal %ld.", size), return false); | 941 | + OP_LOGE_WITH_INVALID_ATTR(ACLNN_CONVOLUTION_BACKWARD_NAME, "biasSizes", |
| 942 | + std::to_string((*params_.biasSizes)[0]).c_str(), std::to_string(size).c_str()), | ||
| 943 | + return false); | ||
| 876 | } | 944 | } |
| 877 | } | 945 | } |
| 878 | 946 | ||
| @@ -881,14 +949,14 @@ bool ConvolutionBackwardChecker::CheckEmptyTensor() { | |||
| 881 | auto inputShape = inputTensor_.input->GetViewShape(); | 949 | auto inputShape = inputTensor_.input->GetViewShape(); |
| 882 | // 确保input的shape大于2 | 950 | // 确保input的shape大于2 |
| 883 | OP_CHECK(inputShape.GetDimNum() > 2, | 951 | OP_CHECK(inputShape.GetDimNum() > 2, |
| 884 | - OP_LOGE(ACLNN_ERR_PARAM_INVALID, "The input shape must be greater than 2, but now is %ld", | 952 | + OP_LOGE_FOR_INVALID_SHAPEDIM_WITH_REASON(ACLNN_CONVOLUTION_BACKWARD_NAME, "inputShape", |
| 885 | - inputShape.GetDimNum()), | 953 | + std::to_string(inputShape.GetDimNum()).c_str(), "Dim of inputshape must be greater than 2"), |
| 886 | return false); | 954 | return false); |
| 887 | 955 | ||
| 888 | OP_CHECK(inputShape[0] == 0 || inputShape[1] == 0, | 956 | OP_CHECK(inputShape[0] == 0 || inputShape[1] == 0, |
| 889 | - OP_LOGE(ACLNN_ERR_PARAM_INVALID, | 957 | + OP_LOGE_FOR_INVALID_SHAPE_WITH_REASON(ACLNN_CONVOLUTION_BACKWARD_NAME, "inputShape[0],inputShape[1]", |
| 890 | - "When the input tensors contain an empty tensor, aclnnConvolutionBackward only supports zero batch or zero channel with input, but got input shape is %s", | 958 | + (std::to_string(inputShape[0]) + "," + std::to_string(inputShape[1]).c_str()), |
| 891 | - op::ToString(inputShape).GetString()), | 959 | + "inputShape[0] or inputShape[1] should be 0"), |
| 892 | return false); | 960 | return false); |
| 893 | } | 961 | } |
| 894 | auto curArch = GetCurrentPlatformInfo().GetCurNpuArch(); | 962 | auto curArch = GetCurrentPlatformInfo().GetCurNpuArch(); |
| @@ -22,6 +22,7 @@ | |||
| 22 | 22 | ||
| 23 | 23 | ||
| 24 | 24 | ||
| 25 | + | ||
| 25 | 26 | ||
| 26 | using namespace op; | 27 | using namespace op; |
| 27 | 28 | ||
| @@ -65,6 +66,7 @@ constexpr int64_t BATCH_TRANSPOSE_LIMIT = 2; | |||
| 65 | constexpr int64_t C_IN_TRANSPOSE_LIMIT_MIN = 16; | 66 | constexpr int64_t C_IN_TRANSPOSE_LIMIT_MIN = 16; |
| 66 | constexpr int64_t C_IN_TRANSPOSE_LIMIT_MAX = 256; | 67 | constexpr int64_t C_IN_TRANSPOSE_LIMIT_MAX = 256; |
| 67 | constexpr float MAX_CIN_MULTIPLIER = 1.5f; | 68 | constexpr float MAX_CIN_MULTIPLIER = 1.5f; |
| 69 | +static constexpr const char* ACLNN_CONV_TBC_BACKWARD_NAME = "aclnnConvTbcBackward"; | ||
| 68 | 70 | ||
| 69 | static void AddAclIntArrayToCaseInfo(const aclIntArray &seg, vector<int64_t> &caseInfo) | 71 | static void AddAclIntArrayToCaseInfo(const aclIntArray &seg, vector<int64_t> &caseInfo) |
| 70 | { | 72 | { |
| @@ -424,7 +426,7 @@ static aclnnStatus Conv2DBackpropInputWithFlag(const aclTensor *input, const acl | |||
| 424 | auto ret = INFER_SHAPE(Conv2DBackpropInput, OP_INPUT(inputSize, weight, outBackprop), OP_OUTPUT(output), | 426 | auto ret = INFER_SHAPE(Conv2DBackpropInput, OP_INPUT(inputSize, weight, outBackprop), OP_OUTPUT(output), |
| 425 | OP_ATTR(stride4, pad4, dilation4, groups, dataFormat, paddingString, useHf32Flag)); | 427 | OP_ATTR(stride4, pad4, dilation4, groups, dataFormat, paddingString, useHf32Flag)); |
| 426 | if (ret != ACLNN_SUCCESS) { | 428 | if (ret != ACLNN_SUCCESS) { |
| 427 | - OP_LOGE(ACLNN_ERR_PARAM_INVALID, "Conv2DBackpropInput InferShape failed."); | 429 | + OP_LOGE(ACLNN_ERR_INNER_INFERSHAPE_ERROR, "Conv2DBackpropInput InferShape failed."); |
| 428 | return ACLNN_ERR_INNER_INFERSHAPE_ERROR; | 430 | return ACLNN_ERR_INNER_INFERSHAPE_ERROR; |
| 429 | } | 431 | } |
| 430 | // useHf32Flag的值为0x40 : 表示HF32 | 432 | // useHf32Flag的值为0x40 : 表示HF32 |
| @@ -534,7 +536,7 @@ static aclnnStatus Conv2DBackpropFilterWithFlag(const aclTensor *input, const ac | |||
| 534 | INFER_SHAPE(Conv2DBackpropFilter, OP_INPUT(input, weightSize, outBackprop), OP_OUTPUT(output), | 536 | INFER_SHAPE(Conv2DBackpropFilter, OP_INPUT(input, weightSize, outBackprop), OP_OUTPUT(output), |
| 535 | OP_ATTR(stride4, pad4, dilation4, groups, dataFormat, paddingString, fromDepthwise, useHf32Flag)); | 537 | OP_ATTR(stride4, pad4, dilation4, groups, dataFormat, paddingString, fromDepthwise, useHf32Flag)); |
| 536 | if (ret != ACLNN_SUCCESS) { | 538 | if (ret != ACLNN_SUCCESS) { |
| 537 | - OP_LOGE(ACLNN_ERR_PARAM_INVALID, "Conv2DBackpropFilter InferShape failed."); | 539 | + OP_LOGE(ACLNN_ERR_INNER_INFERSHAPE_ERROR, "Conv2DBackpropFilter InferShape failed."); |
| 538 | return ACLNN_ERR_INNER_INFERSHAPE_ERROR; | 540 | return ACLNN_ERR_INNER_INFERSHAPE_ERROR; |
| 539 | } | 541 | } |
| 540 | // useHf32Flag的值为0x40 : 表示HF32 | 542 | // useHf32Flag的值为0x40 : 表示HF32 |
| @@ -643,8 +645,9 @@ static void GetConv3DBackpropAdapterParam(const aclTensor *input, const aclIntAr | |||
| 643 | params->adaptPad = executor->AllocIntArray(newPad.data(), 6); // conv3D Pad dim = 6; | 645 | params->adaptPad = executor->AllocIntArray(newPad.data(), 6); // conv3D Pad dim = 6; |
| 644 | OP_CHECK(params->adaptPad != nullptr, OP_LOGD("newPad alloc failed."), return); | 646 | OP_CHECK(params->adaptPad != nullptr, OP_LOGD("newPad alloc failed."), return); |
| 645 | } else { | 647 | } else { |
| 646 | - OP_LOGE(ACLNN_ERR_PARAM_INVALID, "GetConv3DBackpropAdapterParam not support: %s with input dim:%ld", | 648 | + OP_LOGE_FOR_INVALID_SHAPEDIM(ACLNN_CONV_TBC_BACKWARD_NAME, "stride", |
| 647 | - op::ToString(socVersion).GetString(), stride->Size()); | 649 | + std::to_string(stride->Size()).c_str(), std::to_string(DIM_3).c_str() |
| 650 | + ); | ||
| 648 | } | 651 | } |
| 649 | } | 652 | } |
| 650 | 653 | ||
| @@ -839,7 +842,7 @@ static aclnnStatus Conv3DBackpropFilterWithFlag(const aclTensor *input, const ac | |||
| 839 | INFER_SHAPE(Conv3DBackpropFilter, OP_INPUT(input, weightSize, outBackprop), OP_OUTPUT(output), | 842 | INFER_SHAPE(Conv3DBackpropFilter, OP_INPUT(input, weightSize, outBackprop), OP_OUTPUT(output), |
| 840 | OP_ATTR(stride5, pad6, dilation5, groups, dataFormat, paddingString, useHf32)); | 843 | OP_ATTR(stride5, pad6, dilation5, groups, dataFormat, paddingString, useHf32)); |
| 841 | if (ret != ACLNN_SUCCESS) { | 844 | if (ret != ACLNN_SUCCESS) { |
| 842 | - OP_LOGE(ACLNN_ERR_PARAM_INVALID, "Conv3DBackpropFilter InferShape failed."); | 845 | + OP_LOGE(ACLNN_ERR_INNER_INFERSHAPE_ERROR, "Conv3DBackpropFilter InferShape failed."); |
| 843 | output = nullptr; | 846 | output = nullptr; |
| 844 | return ACLNN_ERR_INNER_INFERSHAPE_ERROR; | 847 | return ACLNN_ERR_INNER_INFERSHAPE_ERROR; |
| 845 | } | 848 | } |
| @@ -910,7 +913,7 @@ const aclTensor *Conv3DBackpropFilterFp162Fp32(const aclTensor *input, const acl | |||
| 910 | OP_CHECK( | 913 | OP_CHECK( |
| 911 | Conv3DBackpropFilterWithFlag(input, weight, outBackprop, stride, padding, | 914 | Conv3DBackpropFilterWithFlag(input, weight, outBackprop, stride, padding, |
| 912 | dilation, groups, useHf32, output, executor) == ACLNN_SUCCESS, | 915 | dilation, groups, useHf32, output, executor) == ACLNN_SUCCESS, |
| 913 | - OP_LOGE(ACLNN_ERR_PARAM_INVALID, "Conv3DBackpropFilterFp162Fp32 fail due to Conv3DBackpropFilterWithFlag error."), | 916 | + OP_LOGE(ACLNN_ERR_INNER_NULLPTR, "Conv3DBackpropFilterFp162Fp32 fail due to Conv3DBackpropFilterWithFlag error."), |
| 914 | return nullptr | 917 | return nullptr |
| 915 | ); | 918 | ); |
| 916 | return output; | 919 | return output; |
| @@ -927,7 +930,7 @@ const aclTensor *Conv3DBackpropFilterFp322Fp32(const aclTensor *input, const acl | |||
| 927 | OP_CHECK( | 930 | OP_CHECK( |
| 928 | Conv3DBackpropFilterWithFlag(input, weight, outBackprop, stride, padding, | 931 | Conv3DBackpropFilterWithFlag(input, weight, outBackprop, stride, padding, |
| 929 | dilation, groups, useHf32, output, executor) == ACLNN_SUCCESS, | 932 | dilation, groups, useHf32, output, executor) == ACLNN_SUCCESS, |
| 930 | - OP_LOGE(ACLNN_ERR_PARAM_INVALID, "Conv3DBackpropFilterWithFlag failed."), | 933 | + OP_LOGE(ACLNN_ERR_INNER_NULLPTR, "Conv3DBackpropFilterWithFlag failed."), |
| 931 | return nullptr | 934 | return nullptr |
| 932 | ); | 935 | ); |
| 933 | return output; | 936 | return output; |
| @@ -944,7 +947,7 @@ const aclTensor *Conv3DBackpropFilterHf32(const aclTensor *input, const aclTenso | |||
| 944 | OP_CHECK( | 947 | OP_CHECK( |
| 945 | Conv3DBackpropFilterWithFlag(input, weight, outBackprop, stride, padding, | 948 | Conv3DBackpropFilterWithFlag(input, weight, outBackprop, stride, padding, |
| 946 | dilation, groups, useHf32, output, executor) == ACLNN_SUCCESS, | 949 | dilation, groups, useHf32, output, executor) == ACLNN_SUCCESS, |
| 947 | - OP_LOGE(ACLNN_ERR_PARAM_INVALID, "Conv3DBackpropFilterHf32 fail due to Conv3DBackpropFilterWithFlag error."), | 950 | + OP_LOGE(ACLNN_ERR_INNER_NULLPTR, "Conv3DBackpropFilterHf32 fail due to Conv3DBackpropFilterWithFlag error."), |
| 948 | return nullptr | 951 | return nullptr |
| 949 | ); | 952 | ); |
| 950 | return output; | 953 | return output; |
| @@ -961,7 +964,7 @@ const aclTensor *Conv3DBackpropFilterBf162Fp32(const aclTensor *input, const acl | |||
| 961 | OP_CHECK( | 964 | OP_CHECK( |
| 962 | Conv3DBackpropFilterWithFlag(input, weight, outBackprop, stride, padding, | 965 | Conv3DBackpropFilterWithFlag(input, weight, outBackprop, stride, padding, |
| 963 | dilation, groups, useHf32, output, executor) == ACLNN_SUCCESS, | 966 | dilation, groups, useHf32, output, executor) == ACLNN_SUCCESS, |
| 964 | - OP_LOGE(ACLNN_ERR_PARAM_INVALID, "Conv3DBackpropFilterBf162Fp32 fail due to Conv3DBackpropFilterWithFlag error."), | 967 | + OP_LOGE(ACLNN_ERR_INNER_NULLPTR, "Conv3DBackpropFilterBf162Fp32 fail due to Conv3DBackpropFilterWithFlag error."), |
| 965 | return nullptr | 968 | return nullptr |
| 966 | ); | 969 | ); |
| 967 | return output; | 970 | return output; |
| @@ -981,7 +984,7 @@ const aclTensor *Conv3DBackpropFilter(ConvolutionBackwardInputTensor &inputTenso | |||
| 981 | Conv3DBackpropFilterWithFlag(inputTensor.input, inputTensor.weight, inputTensor.gradOutput, | 984 | Conv3DBackpropFilterWithFlag(inputTensor.input, inputTensor.weight, inputTensor.gradOutput, |
| 982 | params.stride, params.padding, params.dilation, params.groups, | 985 | params.stride, params.padding, params.dilation, params.groups, |
| 983 | useHf32, output, executor) == ACLNN_SUCCESS, | 986 | useHf32, output, executor) == ACLNN_SUCCESS, |
| 984 | - OP_LOGE(ACLNN_ERR_PARAM_INVALID, "Conv3DBackpropFilterBf162Fp32 fail due to Conv3DBackpropFilterWithFlag error."), | 987 | + OP_LOGE(ACLNN_ERR_INNER_NULLPTR, "Conv3DBackpropFilterBf162Fp32 fail due to Conv3DBackpropFilterWithFlag error."), |
| 985 | return nullptr | 988 | return nullptr |
| 986 | ); | 989 | ); |
| 987 | return output; | 990 | return output; |
| @@ -1198,7 +1201,7 @@ static aclnnStatus Conv3DBackpropInputWithFlag(const aclTensor *input, const acl | |||
| 1198 | INFER_SHAPE(Conv3DBackpropInput, OP_INPUT(inputSize, weight, outBackprop), OP_OUTPUT(output), | 1201 | INFER_SHAPE(Conv3DBackpropInput, OP_INPUT(inputSize, weight, outBackprop), OP_OUTPUT(output), |
| 1199 | OP_ATTR(stride5, pad6, dilation5, groups, dataFormat, paddingString, useHf32Flag)); | 1202 | OP_ATTR(stride5, pad6, dilation5, groups, dataFormat, paddingString, useHf32Flag)); |
| 1200 | if (ret != ACLNN_SUCCESS) { | 1203 | if (ret != ACLNN_SUCCESS) { |
| 1201 | - OP_LOGE(ACLNN_ERR_PARAM_INVALID, "Conv3DBackpropInput InferShape failed."); | 1204 | + OP_LOGE(ACLNN_ERR_INNER_INFERSHAPE_ERROR, "Conv3DBackpropInput InferShape failed."); |
| 1202 | output = nullptr; | 1205 | output = nullptr; |
| 1203 | return ACLNN_ERR_INNER_INFERSHAPE_ERROR; | 1206 | return ACLNN_ERR_INNER_INFERSHAPE_ERROR; |
| 1204 | } | 1207 | } |
| @@ -1208,7 +1211,7 @@ static aclnnStatus Conv3DBackpropInputWithFlag(const aclTensor *input, const acl | |||
| 1208 | if (Ops::NN::AclnnUtil::IsRegbase() && CheckN2HEnable(weight, output, stride5, dilation5, pad6, groups)) { | 1211 | if (Ops::NN::AclnnUtil::IsRegbase() && CheckN2HEnable(weight, output, stride5, dilation5, pad6, groups)) { |
| 1209 | ret = N2HOptimize(weight, outBackprop, output, stride5, executor); | 1212 | ret = N2HOptimize(weight, outBackprop, output, stride5, executor); |
| 1210 | if (ret != ACLNN_SUCCESS) { | 1213 | if (ret != ACLNN_SUCCESS) { |
| 1211 | - OP_LOGE(ACLNN_ERR_PARAM_INVALID, "Conv3DBackpropInput N2HOptimize failed."); | 1214 | + OP_LOGE(ACLNN_ERR_INNER_NULLPTR, "Conv3DBackpropInput N2HOptimize failed."); |
| 1212 | output = nullptr; | 1215 | output = nullptr; |
| 1213 | return ACLNN_ERR_INNER_NULLPTR; | 1216 | return ACLNN_ERR_INNER_NULLPTR; |
| 1214 | } | 1217 | } |
| @@ -1258,7 +1261,7 @@ const aclTensor *Conv3DBackpropInputFp162Fp16(const aclTensor *input, const aclT | |||
| 1258 | OP_CHECK( | 1261 | OP_CHECK( |
| 1259 | Conv3DBackpropInputWithFlag(input, weight, outBackprop, stride, padding, dilation, groups, | 1262 | Conv3DBackpropInputWithFlag(input, weight, outBackprop, stride, padding, dilation, groups, |
| 1260 | useHf32Flag, output, executor) == ACLNN_SUCCESS, | 1263 | useHf32Flag, output, executor) == ACLNN_SUCCESS, |
| 1261 | - OP_LOGE(ACLNN_ERR_PARAM_INVALID, "Conv3DBackpropInputFp162Fp16 fail due to Conv3DBackpropInputWithFlag error."), | 1264 | + OP_LOGE(ACLNN_ERR_INNER_NULLPTR, "Conv3DBackpropInputFp162Fp16 fail due to Conv3DBackpropInputWithFlag error."), |
| 1262 | return nullptr | 1265 | return nullptr |
| 1263 | ); | 1266 | ); |
| 1264 | return output; | 1267 | return output; |
| @@ -1275,7 +1278,7 @@ const aclTensor *Conv3DBackpropInputFp322Fp32(const aclTensor *input, const aclT | |||
| 1275 | OP_CHECK( | 1278 | OP_CHECK( |
| 1276 | Conv3DBackpropInputWithFlag(input, weight, outBackprop, stride, padding, dilation, groups, | 1279 | Conv3DBackpropInputWithFlag(input, weight, outBackprop, stride, padding, dilation, groups, |
| 1277 | useHf32Flag, output, executor) == ACLNN_SUCCESS, | 1280 | useHf32Flag, output, executor) == ACLNN_SUCCESS, |
| 1278 | - OP_LOGE(ACLNN_ERR_PARAM_INVALID, "Conv3DBackpropInputFp322Fp32 due to Conv3DBackpropInputWithFlag error."), | 1281 | + OP_LOGE(ACLNN_ERR_INNER_NULLPTR, "Conv3DBackpropInputFp322Fp32 due to Conv3DBackpropInputWithFlag error."), |
| 1279 | return nullptr | 1282 | return nullptr |
| 1280 | ); | 1283 | ); |
| 1281 | return output; | 1284 | return output; |
| @@ -1291,7 +1294,7 @@ const aclTensor *Conv3DBackpropInputHf32(const aclTensor *input, const aclTensor | |||
| 1291 | OP_CHECK( | 1294 | OP_CHECK( |
| 1292 | Conv3DBackpropInputWithFlag(input, weight, outBackprop, stride, padding, dilation, groups, | 1295 | Conv3DBackpropInputWithFlag(input, weight, outBackprop, stride, padding, dilation, groups, |
| 1293 | useHf32Flag, output, executor) == ACLNN_SUCCESS, | 1296 | useHf32Flag, output, executor) == ACLNN_SUCCESS, |
| 1294 | - OP_LOGE(ACLNN_ERR_PARAM_INVALID, "Conv3DBackpropInputHf32 fail due to Conv3DBackpropInputWithFlag error."), | 1297 | + OP_LOGE(ACLNN_ERR_INNER_NULLPTR, "Conv3DBackpropInputHf32 fail due to Conv3DBackpropInputWithFlag error."), |
| 1295 | return nullptr | 1298 | return nullptr |
| 1296 | ); | 1299 | ); |
| 1297 | return output; | 1300 | return output; |
| @@ -1308,7 +1311,7 @@ const aclTensor *Conv3DBackpropInputBf162Bf16(const aclTensor *input, const aclT | |||
| 1308 | OP_CHECK( | 1311 | OP_CHECK( |
| 1309 | Conv3DBackpropInputWithFlag(input, weight, outBackprop, stride, padding, dilation, groups, | 1312 | Conv3DBackpropInputWithFlag(input, weight, outBackprop, stride, padding, dilation, groups, |
| 1310 | useHf32Flag, output, executor) == ACLNN_SUCCESS, | 1313 | useHf32Flag, output, executor) == ACLNN_SUCCESS, |
| 1311 | - OP_LOGE(ACLNN_ERR_PARAM_INVALID, "Conv3DBackpropInputBf162Bf16 fail due to Conv3DBackpropInputWithFlag error."), | 1314 | + OP_LOGE(ACLNN_ERR_INNER_NULLPTR, "Conv3DBackpropInputBf162Bf16 fail due to Conv3DBackpropInputWithFlag error."), |
| 1312 | return nullptr | 1315 | return nullptr |
| 1313 | ); | 1316 | ); |
| 1314 | return output; | 1317 | return output; |
| @@ -1327,7 +1330,7 @@ const aclTensor *Conv3DBackpropInput(ConvolutionBackwardInputTensor &inputTensor | |||
| 1327 | Conv3DBackpropInputWithFlag(inputTensor.input, inputTensor.weight, inputTensor.gradOutput, | 1330 | Conv3DBackpropInputWithFlag(inputTensor.input, inputTensor.weight, inputTensor.gradOutput, |
| 1328 | params.stride, params.padding, params.dilation, params.groups, | 1331 | params.stride, params.padding, params.dilation, params.groups, |
| 1329 | useHf32, output, executor) == ACLNN_SUCCESS, | 1332 | useHf32, output, executor) == ACLNN_SUCCESS, |
| 1330 | - OP_LOGE(ACLNN_ERR_PARAM_INVALID, "Conv3DBackpropInput fail due to Conv3DBackpropInputWithFlag error."), | 1333 | + OP_LOGE(ACLNN_ERR_INNER_NULLPTR, "Conv3DBackpropInput fail due to Conv3DBackpropInputWithFlag error."), |
| 1331 | return nullptr | 1334 | return nullptr |
| 1332 | ); | 1335 | ); |
| 1333 | return output; | 1336 | return output; |
| @@ -9,12 +9,15 @@ | |||
| 9 | */ | 9 | */ |
| 10 | 10 | ||
| 11 | 11 | ||
| 12 | + | ||
| 13 | + | ||
| 12 | 14 | ||
| 13 | using namespace op; | 15 | using namespace op; |
| 14 | 16 | ||
| 15 | namespace Ops { | 17 | namespace Ops { |
| 16 | namespace NN { | 18 | namespace NN { |
| 17 | namespace Conv { | 19 | namespace Conv { |
| 20 | +static constexpr const char* ACLNN_CONV_TBC_BACKWARD_NAME = "aclnnConvTbcBackwardGetWorkspaceSize"; | ||
| 18 | 21 | ||
| 19 | inline bool ConvTbcBackwardChecker::CheckTbcNotNull() { | 22 | inline bool ConvTbcBackwardChecker::CheckTbcNotNull() { |
| 20 | OP_CHECK_NULL(inputTensor_.self, return false); | 23 | OP_CHECK_NULL(inputTensor_.self, return false); |
| @@ -49,16 +52,16 @@ bool ConvTbcBackwardChecker::CheckDtypeValidBf16Allowed(const aclTensor *inputTe | |||
| 49 | bool ConvTbcBackwardChecker::CheckTbcFormat(const aclTensor *inputTensor, const string &tensorName) const { | 52 | bool ConvTbcBackwardChecker::CheckTbcFormat(const aclTensor *inputTensor, const string &tensorName) const { |
| 50 | OP_CHECK(inputTensor->GetStorageFormat() == op::Format::FORMAT_ND || | 53 | OP_CHECK(inputTensor->GetStorageFormat() == op::Format::FORMAT_ND || |
| 51 | inputTensor->GetStorageFormat() == op::Format::FORMAT_NCL, | 54 | inputTensor->GetStorageFormat() == op::Format::FORMAT_NCL, |
| 52 | - OP_LOGE(ACLNN_ERR_PARAM_INVALID, "%s format only supports ND or NCL, but got %s.", tensorName.c_str(), | 55 | + OP_LOGE_FOR_INVALID_FORMAT(ACLNN_CONV_TBC_BACKWARD_NAME, tensorName.c_str(), |
| 53 | - op::ToString(inputTensor->GetStorageFormat()).GetString()), | 56 | + op::ToString(inputTensor->GetStorageFormat()).GetString(),"ND or NCL"), |
| 54 | return false); | 57 | return false); |
| 55 | return true; | 58 | return true; |
| 56 | } | 59 | } |
| 57 | 60 | ||
| 58 | bool ConvTbcBackwardChecker::CheckTbcBiasFormat(const aclTensor *inputTensor, const string &tensorName) const { | 61 | bool ConvTbcBackwardChecker::CheckTbcBiasFormat(const aclTensor *inputTensor, const string &tensorName) const { |
| 59 | OP_CHECK(inputTensor->GetStorageFormat() == op::Format::FORMAT_ND, | 62 | OP_CHECK(inputTensor->GetStorageFormat() == op::Format::FORMAT_ND, |
| 60 | - OP_LOGE(ACLNN_ERR_PARAM_INVALID, "%s format only supports ND, but got %s.", tensorName.c_str(), | 63 | + OP_LOGE_FOR_INVALID_FORMAT(ACLNN_CONV_TBC_BACKWARD_NAME, tensorName.c_str(), |
| 61 | - op::ToString(inputTensor->GetStorageFormat()).GetString()), | 64 | + op::ToString(inputTensor->GetStorageFormat()).GetString(),"ND"), |
| 62 | return false); | 65 | return false); |
| 63 | return true; | 66 | return true; |
| 64 | } | 67 | } |
| @@ -66,10 +69,8 @@ bool ConvTbcBackwardChecker::CheckTbcBiasFormat(const aclTensor *inputTensor, co | |||
| 66 | bool ConvTbcBackwardChecker::CheckTbcShape() { | 69 | bool ConvTbcBackwardChecker::CheckTbcShape() { |
| 67 | auto validDim = [](const aclTensor *tensor, int64_t dims, const char* paramName) -> bool { | 70 | auto validDim = [](const aclTensor *tensor, int64_t dims, const char* paramName) -> bool { |
| 68 | int64_t curDims = tensor->GetViewShape().GetDimNum(); | 71 | int64_t curDims = tensor->GetViewShape().GetDimNum(); |
| 69 | - OP_CHECK(curDims == dims, | 72 | + OP_CHECK(curDims == dims, OP_LOGE_FOR_INVALID_SHAPEDIM(ACLNN_CONV_TBC_BACKWARD_NAME, paramName, |
| 70 | - OP_LOGE(ACLNN_ERR_PARAM_INVALID, "the dimension of %s should be %ld, but get %ld.", | 73 | + std::to_string(curDims).c_str(), std::to_string(dims).c_str()), return false); |
| 71 | - paramName, dims, curDims), | ||
| 72 | - return false); | ||
| 73 | return true; | 74 | return true; |
| 74 | }; | 75 | }; |
| 75 | constexpr int64_t tbcDims = 3; | 76 | constexpr int64_t tbcDims = 3; |
| @@ -84,33 +85,34 @@ bool ConvTbcBackwardChecker::CheckTbcShape() { | |||
| 84 | 85 | ||
| 85 | // input(TBC1) weigth(LC1C0) bias(C0): | 86 | // input(TBC1) weigth(LC1C0) bias(C0): |
| 86 | OP_CHECK(inputTensor_.input->GetViewShape().GetDim(2) == inputTensor_.weight->GetViewShape().GetDim(1), | 87 | OP_CHECK(inputTensor_.input->GetViewShape().GetDim(2) == inputTensor_.weight->GetViewShape().GetDim(1), |
| 87 | - OP_LOGE(ACLNN_ERR_PARAM_INVALID, "Input dim 2 (Input Channels) is not == dim 1 in the weight tensor."), | 88 | + OP_LOGE_FOR_INVALID_SHAPEDIMS_WITH_REASON(ACLNN_CONV_TBC_BACKWARD_NAME, "Input[2] , weight[1]", |
| 88 | - return false); | 89 | + (std::to_string(inputTensor_.input->GetViewShape().GetDim(2)) + "," |
| 90 | + + std::to_string(inputTensor_.weight->GetViewShape().GetDim(2))).c_str(), | ||
| 91 | + "the dim of Input[2] and the dim of weight[1] must be the same"), return false); | ||
| 89 | OP_CHECK(inputTensor_.bias->GetViewShape().GetDim(0) == inputTensor_.weight->GetViewShape().GetDim(2), | 92 | OP_CHECK(inputTensor_.bias->GetViewShape().GetDim(0) == inputTensor_.weight->GetViewShape().GetDim(2), |
| 90 | - OP_LOGE(ACLNN_ERR_PARAM_INVALID, "Bias should be [%ld], but get [%ld]", | 93 | + OP_LOGE_FOR_INVALID_SHAPEDIMS_WITH_REASON(ACLNN_CONV_TBC_BACKWARD_NAME, "bias, weight", |
| 91 | - inputTensor_.weight->GetViewShape().GetDim(2), inputTensor_.bias->GetViewShape().GetDim(0)), | 94 | + (std::to_string(inputTensor_.bias->GetViewShape().GetDim(0)) + "," |
| 92 | - return false); | 95 | + + std::to_string(inputTensor_.weight->GetViewShape().GetDim(2))).c_str(), |
| 96 | + "Dim of bias and weight[2] must be the same"), return false); | ||
| 93 | // pad >= 0 | 97 | // pad >= 0 |
| 94 | OP_CHECK(params_.pad >= 0, | 98 | OP_CHECK(params_.pad >= 0, |
| 95 | - OP_LOGE(ACLNN_ERR_PARAM_INVALID, "The pad must be greater than or equal to 0, but get %ld.", params_.pad), | 99 | + OP_LOGE_FOR_INVALID_VALUE_WITH_REASON(ACLNN_CONV_TBC_BACKWARD_NAME, "pad", |
| 96 | - return false); | 100 | + std::to_string(params_.pad).c_str(), "the value of pad must be greater or equal to 0"),return false); |
| 97 | // self 与input, weight shape 必须满足约束 | 101 | // self 与input, weight shape 必须满足约束 |
| 98 | // 约束1:self shape必须与conv_tbc计算出的output match: self(T+2*pad+1-L,B,C0) | 102 | // 约束1:self shape必须与conv_tbc计算出的output match: self(T+2*pad+1-L,B,C0) |
| 99 | auto t = inputTensor_.input->GetViewShape().GetDim(0) + 2 * params_.pad + 1 - inputTensor_.weight->GetViewShape().GetDim(0); | 103 | auto t = inputTensor_.input->GetViewShape().GetDim(0) + 2 * params_.pad + 1 - inputTensor_.weight->GetViewShape().GetDim(0); |
| 100 | auto b = inputTensor_.input->GetViewShape().GetDim(1); | 104 | auto b = inputTensor_.input->GetViewShape().GetDim(1); |
| 101 | auto c0 = inputTensor_.weight->GetViewShape().GetDim(2); | 105 | auto c0 = inputTensor_.weight->GetViewShape().GetDim(2); |
| 102 | - OP_CHECK(t >= 0, | 106 | + OP_CHECK(t >= 0, OP_LOGE_FOR_INVALID_SHAPEDIMS_WITH_REASON(ACLNN_CONV_TBC_BACKWARD_NAME, "input[0], weight[0]", |
| 103 | - OP_LOGE(ACLNN_ERR_PARAM_INVALID, | 107 | + (std::to_string(inputTensor_.input->GetViewShape().GetDim(0)) + "," |
| 104 | - "Try to create tensor with negative dimension %ld:[%ld, %ld, %ld]", | 108 | + + std::to_string(inputTensor_.weight->GetViewShape().GetDim(0))).c_str(), |
| 105 | - t, t, b, c0), | 109 | + "(dim of input[0]) + 2*pad + 1 - (dim of weight[0]) should be greater than or equal to 0"),return false); |
| 106 | - return false); | ||
| 107 | OP_CHECK(inputTensor_.self->GetViewShape().GetDim(0) == t && inputTensor_.self->GetViewShape().GetDim(1) == b && | 110 | OP_CHECK(inputTensor_.self->GetViewShape().GetDim(0) == t && inputTensor_.self->GetViewShape().GetDim(1) == b && |
| 108 | inputTensor_.self->GetViewShape().GetDim(2) == c0, | 111 | inputTensor_.self->GetViewShape().GetDim(2) == c0, |
| 109 | - OP_LOGE(ACLNN_ERR_PARAM_INVALID, | 112 | + OP_LOGE_FOR_INVALID_SHAPE_WITH_REASON(ACLNN_CONV_TBC_BACKWARD_NAME, "self", |
| 110 | - "Mismatch in shape: grad_output has a shape of %s but output has a shape of [%ld, %ld, %ld]," | 113 | + op::ToString(inputTensor_.self->GetViewShape()).GetString(), |
| 111 | - "which output shape is deduced from the input and the weight", | 114 | + ("the shape of self should be [" + std::to_string(t) + "," + std::to_string(b) + "," |
| 112 | - op::ToString(inputTensor_.self->GetViewShape()).GetString(), t, b, c0), | 115 | + + std::to_string(c0) + "]").c_str()),return false); |
| 113 | - return false); | ||
| 114 | 116 | ||
| 115 | // input和gradInput的shape必须一致 | 117 | // input和gradInput的shape必须一致 |
| 116 | OP_CHECK_SHAPE_NOT_EQUAL(inputTensor_.input, outputTensor_.gradInput, return false); | 118 | OP_CHECK_SHAPE_NOT_EQUAL(inputTensor_.input, outputTensor_.gradInput, return false); |
| @@ -155,8 +157,12 @@ aclnnStatus ConvTbcBackwardChecker::CheckTbcParams() { | |||
| 155 | CHECK_RET(CheckTbcBiasFormat(outputTensor_.gradBias, "gradBias"), ACLNN_ERR_PARAM_INVALID); | 157 | CHECK_RET(CheckTbcBiasFormat(outputTensor_.gradBias, "gradBias"), ACLNN_ERR_PARAM_INVALID); |
| 156 | 158 | ||
| 157 | // 4. 检查self不能为空 | 159 | // 4. 检查self不能为空 |
| 158 | - OP_CHECK(inputTensor_.self->Size() != 0, OP_LOGE(ACLNN_ERR_PARAM_INVALID, "The self can not be empty tensor."), | 160 | + OP_CHECK(inputTensor_.self->Size() != 0, |
| 159 | - return ACLNN_ERR_PARAM_INVALID); | 161 | + OP_LOGE_FOR_INVALID_SHAPESIZE(ACLNN_CONV_TBC_BACKWARD_NAME, |
| 162 | + "self",std::to_string(inputTensor_.self->Size()).c_str(), | ||
| 163 | + "greater than 0" | ||
| 164 | + ), | ||
| 165 | + return ACLNN_ERR_PARAM_INVALID); | ||
| 160 | 166 | ||
| 161 | // 5. 检查输入aclTensor的shape是否符合约束 | 167 | // 5. 检查输入aclTensor的shape是否符合约束 |
| 162 | CHECK_RET(CheckTbcShape(), ACLNN_ERR_PARAM_INVALID); | 168 | CHECK_RET(CheckTbcShape(), ACLNN_ERR_PARAM_INVALID); |
| @@ -168,26 +174,26 @@ aclnnStatus ConvTbcBackwardChecker::CheckTbcParams() { | |||
| 168 | // 检查输入输出是否类型一致 | 174 | // 检查输入输出是否类型一致 |
| 169 | OP_CHECK( | 175 | OP_CHECK( |
| 170 | outputTensor_.gradInput->GetDataType() == inputTensor_.input->GetDataType(), | 176 | outputTensor_.gradInput->GetDataType() == inputTensor_.input->GetDataType(), |
| 171 | - OP_LOGE( | 177 | + OP_LOGE_FOR_INVALID_DTYPES_WITH_REASON(ACLNN_CONV_TBC_BACKWARD_NAME, "gradInput, input", |
| 172 | - ACLNN_ERR_INNER_NULLPTR, "gradInput data type[%s] should be equal to input data type[%s]", | 178 | + FormatString("%s,%s",op::ToString(outputTensor_.gradInput->GetDataType()).GetString(), |
| 173 | - op::ToString(outputTensor_.gradInput->GetDataType()).GetString(), | 179 | + op::ToString(inputTensor_.input->GetDataType()).GetString()), |
| 174 | - op::ToString(inputTensor_.input->GetDataType()).GetString()), | 180 | + "the dtypes of [gradInput, input] must be the same"), |
| 175 | return ACLNN_ERR_PARAM_INVALID); | 181 | return ACLNN_ERR_PARAM_INVALID); |
| 176 | 182 | ||
| 177 | OP_CHECK( | 183 | OP_CHECK( |
| 178 | outputTensor_.gradWeight->GetDataType() == inputTensor_.weight->GetDataType(), | 184 | outputTensor_.gradWeight->GetDataType() == inputTensor_.weight->GetDataType(), |
| 179 | - OP_LOGE( | 185 | + OP_LOGE_FOR_INVALID_DTYPES_WITH_REASON(ACLNN_CONV_TBC_BACKWARD_NAME, "gradWeight, weight", |
| 180 | - ACLNN_ERR_INNER_NULLPTR, "gradWeight data type[%s] should be equal to weight data type[%s]", | 186 | + FormatString("%s,%s",op::ToString(outputTensor_.gradWeight->GetDataType()).GetString(), |
| 181 | - op::ToString(outputTensor_.gradWeight->GetDataType()).GetString(), | 187 | + op::ToString(inputTensor_.weight->GetDataType()).GetString()), |
| 182 | - op::ToString(inputTensor_.weight->GetDataType()).GetString()), | 188 | + "the dtypes of [gradWeight, weight] must be the same"), |
| 183 | return ACLNN_ERR_PARAM_INVALID); | 189 | return ACLNN_ERR_PARAM_INVALID); |
| 184 | 190 | ||
| 185 | OP_CHECK( | 191 | OP_CHECK( |
| 186 | outputTensor_.gradBias->GetDataType() == inputTensor_.bias->GetDataType(), | 192 | outputTensor_.gradBias->GetDataType() == inputTensor_.bias->GetDataType(), |
| 187 | - OP_LOGE( | 193 | + OP_LOGE_FOR_INVALID_DTYPES_WITH_REASON(ACLNN_CONV_TBC_BACKWARD_NAME, "gradBias, bias", |
| 188 | - ACLNN_ERR_INNER_NULLPTR, "gradBias data type[%s] should be equal to bias data type[%s]", | 194 | + FormatString("%s,%s", op::ToString(outputTensor_.gradBias->GetDataType()).GetString(), |
| 189 | - op::ToString(outputTensor_.gradBias->GetDataType()).GetString(), | 195 | + op::ToString(inputTensor_.bias->GetDataType()).GetString()), |
| 190 | - op::ToString(inputTensor_.bias->GetDataType()).GetString()), | 196 | + "the dtypes of [gradBias, bias] must be the same"), |
| 191 | return ACLNN_ERR_PARAM_INVALID); | 197 | return ACLNN_ERR_PARAM_INVALID); |
| 192 | } | 198 | } |
| 193 | return ACLNN_SUCCESS; | 199 | return ACLNN_SUCCESS; |
| @@ -9,6 +9,8 @@ | |||
| 9 | */ | 9 | */ |
| 10 | 10 | ||
| 11 | 11 | ||
| 12 | + | ||
| 13 | + | ||
| 12 | 14 | ||
| 13 | namespace Ops { | 15 | namespace Ops { |
| 14 | namespace NN { | 16 | namespace NN { |
| @@ -27,6 +29,7 @@ static size_t PADDING_ARRAY_DIM_SIZE = 4; | |||
| 27 | static size_t DILATION_ARRAY_DIM_SIZE = 4; | 29 | static size_t DILATION_ARRAY_DIM_SIZE = 4; |
| 28 | static size_t DIM_FOUR = 4; | 30 | static size_t DIM_FOUR = 4; |
| 29 | static size_t DIM_ONE = 1; | 31 | static size_t DIM_ONE = 1; |
| 32 | +static constexpr const char* ACLNN_DEFORMABLE_NAME = "aclnnDeformableConv2dBackwardGetWorkspaceSize"; | ||
| 30 | 33 | ||
| 31 | static const std::initializer_list<op::DataType> DTYPE_SUPPORT_LIST = {op::DataType::DT_FLOAT, op::DataType::DT_FLOAT16, | 34 | static const std::initializer_list<op::DataType> DTYPE_SUPPORT_LIST = {op::DataType::DT_FLOAT, op::DataType::DT_FLOAT16, |
| 32 | op::DataType::DT_BF16}; | 35 | op::DataType::DT_BF16}; |
| @@ -75,34 +78,53 @@ bool DeformableConv2dBackwardChecker::CheckDtypeValid() | |||
| 75 | bool DeformableConv2dBackwardChecker::CheckFormat() | 78 | bool DeformableConv2dBackwardChecker::CheckFormat() |
| 76 | { | 79 | { |
| 77 | OP_CHECK(inputTensor_.gradOutput->GetStorageFormat() == Format::FORMAT_NCHW, | 80 | OP_CHECK(inputTensor_.gradOutput->GetStorageFormat() == Format::FORMAT_NCHW, |
| 78 | - OP_LOGE(ACLNN_ERR_PARAM_INVALID, "gradOutput Format only supports NCHW, but got [%s].", | 81 | + OP_LOGE_FOR_INVALID_FORMAT(ACLNN_DEFORMABLE_NAME, "gradOutput", |
| 79 | - op::ToString(inputTensor_.gradOutput->GetStorageFormat()).GetString()), return false); | 82 | + op::ToString(inputTensor_.gradOutput->GetStorageFormat()).GetString(),"NCHW"), return false); |
| 83 | + | ||
| 80 | OP_CHECK(inputTensor_.input->GetStorageFormat() == Format::FORMAT_NCHW, | 84 | OP_CHECK(inputTensor_.input->GetStorageFormat() == Format::FORMAT_NCHW, |
| 81 | - OP_LOGE(ACLNN_ERR_PARAM_INVALID, "input Format only supports NCHW, but got [%s].", | 85 | + OP_LOGE_FOR_INVALID_FORMAT(ACLNN_DEFORMABLE_NAME, "input", |
| 82 | - op::ToString(inputTensor_.input->GetStorageFormat()).GetString()), return false); | 86 | + op::ToString(inputTensor_.input->GetStorageFormat()).GetString(),"NCHW"), return false); |
| 83 | - | 87 | + |
| 84 | OP_CHECK(inputTensor_.weight->GetStorageFormat() == inputTensor_.input->GetStorageFormat(), | 88 | OP_CHECK(inputTensor_.weight->GetStorageFormat() == inputTensor_.input->GetStorageFormat(), |
| 85 | - OP_LOGE(ACLNN_ERR_PARAM_INVALID, "Format of weight and input should be equal."), return false); | 89 | + OP_LOGE_FOR_INVALID_FORMATS_WITH_REASON(ACLNN_DEFORMABLE_NAME, "weight, input", |
| 86 | - | 90 | + FormatString("%s,%s", op::ToString(inputTensor_.weight->GetStorageFormat()).GetString(), |
| 91 | + op::ToString(inputTensor_.input->GetStorageFormat()).GetString()), | ||
| 92 | + "The formats of weight and input must be the same"), return false); | ||
| 93 | + | ||
| 87 | OP_CHECK(inputTensor_.offsetOut->GetStorageFormat() == inputTensor_.input->GetStorageFormat(), | 94 | OP_CHECK(inputTensor_.offsetOut->GetStorageFormat() == inputTensor_.input->GetStorageFormat(), |
| 88 | - OP_LOGE(ACLNN_ERR_PARAM_INVALID, "Format of offsetOut and input should be equal."), return false); | 95 | + OP_LOGE_FOR_INVALID_FORMATS_WITH_REASON(ACLNN_DEFORMABLE_NAME, "offsetOut, input", |
| 96 | + FormatString("%s,%s", op::ToString(inputTensor_.offsetOut->GetStorageFormat()).GetString(), | ||
| 97 | + op::ToString(inputTensor_.input->GetStorageFormat()).GetString()), | ||
| 98 | + "The formats of offsetOut and input must be the same"), return false); | ||
| 89 | 99 | ||
| 90 | OP_CHECK(inputTensor_.offset->GetStorageFormat() == inputTensor_.input->GetStorageFormat(), | 100 | OP_CHECK(inputTensor_.offset->GetStorageFormat() == inputTensor_.input->GetStorageFormat(), |
| 91 | - OP_LOGE(ACLNN_ERR_PARAM_INVALID, "Format of offset and input should be equal."), return false); | 101 | + OP_LOGE_FOR_INVALID_FORMATS_WITH_REASON(ACLNN_DEFORMABLE_NAME, "offset, input", |
| 102 | + FormatString("%s,%s", op::ToString(inputTensor_.offset->GetStorageFormat()).GetString(), | ||
| 103 | + op::ToString(inputTensor_.input->GetStorageFormat()).GetString()), | ||
| 104 | + "The formats of offset and input must be the same"), return false); | ||
| 92 | 105 | ||
| 93 | OP_CHECK(outputTensor_.gradInput->GetStorageFormat() == inputTensor_.input->GetStorageFormat(), | 106 | OP_CHECK(outputTensor_.gradInput->GetStorageFormat() == inputTensor_.input->GetStorageFormat(), |
| 94 | - OP_LOGE(ACLNN_ERR_PARAM_INVALID, "Format of gradInput and input should be equal."), return false); | 107 | + OP_LOGE_FOR_INVALID_FORMATS_WITH_REASON(ACLNN_DEFORMABLE_NAME, "gradInput, input", |
| 108 | + FormatString("%s,%s", op::ToString(outputTensor_.gradInput->GetStorageFormat()).GetString(), | ||
| 109 | + op::ToString(inputTensor_.input->GetStorageFormat()).GetString()), | ||
| 110 | + "The formats of gradInput and input must be the same"), return false); | ||
| 95 | 111 | ||
| 96 | OP_CHECK(outputTensor_.gradWeight->GetStorageFormat() == inputTensor_.weight->GetStorageFormat(), | 112 | OP_CHECK(outputTensor_.gradWeight->GetStorageFormat() == inputTensor_.weight->GetStorageFormat(), |
| 97 | - OP_LOGE(ACLNN_ERR_PARAM_INVALID, "Format of gradWeight and weight should be equal."), return false); | 113 | + OP_LOGE_FOR_INVALID_FORMATS_WITH_REASON(ACLNN_DEFORMABLE_NAME, "gradWeight, weight", |
| 114 | + FormatString("%s,%s", op::ToString(outputTensor_.gradWeight->GetStorageFormat()).GetString(), | ||
| 115 | + op::ToString(inputTensor_.weight->GetStorageFormat()).GetString()), | ||
| 116 | + "The formats of gradWeight and weight must be the same"), return false); | ||
| 98 | 117 | ||
| 99 | OP_CHECK(outputTensor_.gradOffset->GetStorageFormat() == inputTensor_.offsetOut->GetStorageFormat(), | 118 | OP_CHECK(outputTensor_.gradOffset->GetStorageFormat() == inputTensor_.offsetOut->GetStorageFormat(), |
| 100 | - OP_LOGE(ACLNN_ERR_PARAM_INVALID, "Format of gradOffset and offsetOut should be equal."), return false); | 119 | + OP_LOGE_FOR_INVALID_FORMATS_WITH_REASON(ACLNN_DEFORMABLE_NAME, "gradOffset, offsetOut", |
| 120 | + FormatString("%s,%s", op::ToString(outputTensor_.gradOffset->GetStorageFormat()).GetString(), | ||
| 121 | + op::ToString(inputTensor_.offsetOut->GetStorageFormat()).GetString()), | ||
| 122 | + "The formats of gradOffset and offsetOut must be the same"), return false); | ||
| 101 | 123 | ||
| 102 | if (outputTensor_.gradBias != nullptr) { | 124 | if (outputTensor_.gradBias != nullptr) { |
| 103 | OP_CHECK(outputTensor_.gradBias->GetStorageFormat() == Format::FORMAT_ND, | 125 | OP_CHECK(outputTensor_.gradBias->GetStorageFormat() == Format::FORMAT_ND, |
| 104 | - OP_LOGE(ACLNN_ERR_PARAM_INVALID, "gradBias Format only supports ND, but got [%s].", | 126 | + OP_LOGE_FOR_INVALID_FORMAT(ACLNN_DEFORMABLE_NAME, "gradBias", |
| 105 | - op::ToString(outputTensor_.gradBias->GetStorageFormat()).GetString()), return false); | 127 | + op::ToString(outputTensor_.gradBias->GetStorageFormat()).GetString(), "ND"), return false); |
| 106 | } | 128 | } |
| 107 | 129 | ||
| 108 | return true; | 130 | return true; |
| @@ -110,41 +132,55 @@ bool DeformableConv2dBackwardChecker::CheckFormat() | |||
| 110 | 132 | ||
| 111 | bool DeformableConv2dBackwardChecker::CheckAttrs() | 133 | bool DeformableConv2dBackwardChecker::CheckAttrs() |
| 112 | { | 134 | { |
| 113 | - OP_CHECK(params_.kernelSize->Size() == KERNEL_ARRAY_DIM_SIZE, | 135 | + OP_CHECK(params_.kernelSize->Size() == KERNEL_ARRAY_DIM_SIZE, |
| 114 | - OP_LOGE(ACLNN_ERR_PARAM_INVALID, "kernelSize length should be 2, but got %ld.", params_.kernelSize->Size()), return false); | 136 | + OP_LOGE_FOR_INVALID_SHAPESIZE(ACLNN_DEFORMABLE_NAME, "kernelSize", std::to_string(params_.kernelSize->Size()).c_str() |
| 137 | + , std::to_string(KERNEL_ARRAY_DIM_SIZE).c_str()), return false); | ||
| 115 | OP_CHECK(params_.stride->Size() == STRIDE_ARRAY_DIM_SIZE, | 138 | OP_CHECK(params_.stride->Size() == STRIDE_ARRAY_DIM_SIZE, |
| 116 | - OP_LOGE(ACLNN_ERR_PARAM_INVALID, "stride length should be 4, but got %ld.", params_.stride->Size()), return false); | 139 | + OP_LOGE_WITH_INVALID_ATTR_SIZE(ACLNN_DEFORMABLE_NAME, "stride", std::to_string(params_.stride->Size()).c_str(), |
| 140 | + std::to_string(STRIDE_ARRAY_DIM_SIZE).c_str()), return false); | ||
| 117 | OP_CHECK(params_.padding->Size() == PADDING_ARRAY_DIM_SIZE, | 141 | OP_CHECK(params_.padding->Size() == PADDING_ARRAY_DIM_SIZE, |
| 118 | - OP_LOGE(ACLNN_ERR_PARAM_INVALID, "padding length should be 4, but got %ld.", params_.padding->Size()), return false); | 142 | + OP_LOGE_WITH_INVALID_ATTR_SIZE(ACLNN_DEFORMABLE_NAME, "padding", |
| 143 | + std::to_string(params_.padding->Size()).c_str(), std::to_string(PADDING_ARRAY_DIM_SIZE).c_str()), return false); | ||
| 119 | OP_CHECK(params_.dilation->Size() == DILATION_ARRAY_DIM_SIZE, | 144 | OP_CHECK(params_.dilation->Size() == DILATION_ARRAY_DIM_SIZE, |
| 120 | - OP_LOGE(ACLNN_ERR_PARAM_INVALID, "dilation length should be 4, but got %ld.", params_.dilation->Size()), return false); | 145 | + OP_LOGE_WITH_INVALID_ATTR_SIZE(ACLNN_DEFORMABLE_NAME, "dilation", |
| 146 | + std::to_string(params_.dilation->Size()).c_str(), std::to_string(DILATION_ARRAY_DIM_SIZE).c_str()), return false); | ||
| 121 | 147 | ||
| 122 | int64_t kH = (*params_.kernelSize)[INDEX_ZERO]; | 148 | int64_t kH = (*params_.kernelSize)[INDEX_ZERO]; |
| 123 | int64_t kW = (*params_.kernelSize)[INDEX_ONE]; | 149 | int64_t kW = (*params_.kernelSize)[INDEX_ONE]; |
| 124 | OP_CHECK(kH > 0 && kW > 0, | 150 | OP_CHECK(kH > 0 && kW > 0, |
| 125 | - OP_LOGE(ACLNN_ERR_PARAM_INVALID, "kernelSize should be greater than 0, but got KH = %ld, KW = %ld.", kH, kW), return false); | 151 | + OP_LOGE_FOR_INVALID_SHAPES_WITH_REASON(ACLNN_DEFORMABLE_NAME, "kH,kW", |
| 152 | + (std::to_string(kH) + "," + std::to_string(kW)).c_str(), "all axis of [kH, kW] must be greater than 0"), return false); | ||
| 126 | OP_CHECK(kH * kW <= MAX_KERNEL_SIZE, | 153 | OP_CHECK(kH * kW <= MAX_KERNEL_SIZE, |
| 127 | - OP_LOGE(ACLNN_ERR_PARAM_INVALID, "kH[%ld] * kW[%ld] should not exceed 2048.", kH, kW), return false); | 154 | + OP_LOGE_FOR_INVALID_SHAPES_WITH_REASON(ACLNN_DEFORMABLE_NAME, "kH,kW", |
| 155 | + (std::to_string(kH) + "," + std::to_string(kW)).c_str(), "all axis of [kH, kW] must be less than 2048"), return false); | ||
| 128 | // stride >= 1 | 156 | // stride >= 1 |
| 129 | OP_CHECK((*params_.stride)[INDEX_ZERO] == 1 && (*params_.stride)[INDEX_ONE] == 1 && CheckParamsValue(params_.stride, false), | 157 | OP_CHECK((*params_.stride)[INDEX_ZERO] == 1 && (*params_.stride)[INDEX_ONE] == 1 && CheckParamsValue(params_.stride, false), |
| 130 | - OP_LOGE(ACLNN_ERR_PARAM_INVALID, | 158 | + OP_LOGE_FOR_INVALID_VALUES_WITH_REASON(ACLNN_DEFORMABLE_NAME, |
| 131 | - "stride[0]、stride[1] should be 1, stride[2]、stride[3] should be greater than or equal to 1, but got stride[%s].", | 159 | + "stride[0],stride[1],stride[2],stride[3]", AclarrayToString(params_.stride).c_str(), |
| 132 | - AclarrayToString(params_.stride).c_str()), return false); | 160 | + "stride[0]、stride[1] must be 1, stride[2]、stride[3] must be greater than or equal to 1" |
| 161 | + ), return false); | ||
| 133 | // padding >= 0 | 162 | // padding >= 0 |
| 134 | OP_CHECK(CheckParamsValue(params_.padding, true), | 163 | OP_CHECK(CheckParamsValue(params_.padding, true), |
| 135 | - OP_LOGE(ACLNN_ERR_PARAM_INVALID, "padding should be greater than or equal to 0, but got padding[%s].", | 164 | + OP_LOGE_FOR_INVALID_VALUE_WITH_REASON(ACLNN_DEFORMABLE_NAME, "padding", |
| 136 | - AclarrayToString(params_.padding).c_str()), return false); | 165 | + AclarrayToString(params_.padding).c_str(), "the value of padding must be greater than or equal to 0"), return false); |
| 137 | // dilation >= 1 | 166 | // dilation >= 1 |
| 138 | OP_CHECK((*params_.dilation)[INDEX_ZERO] == 1 && (*params_.dilation)[INDEX_ONE] == 1 && CheckParamsValue(params_.dilation, false), | 167 | OP_CHECK((*params_.dilation)[INDEX_ZERO] == 1 && (*params_.dilation)[INDEX_ONE] == 1 && CheckParamsValue(params_.dilation, false), |
| 139 | - OP_LOGE(ACLNN_ERR_PARAM_INVALID, | 168 | + OP_LOGE_FOR_INVALID_VALUES_WITH_REASON(ACLNN_DEFORMABLE_NAME, |
| 140 | - "dilation[0]、dilation[1] should be 1, dilation[2]、dilation[3] should be greater than or equal to 1, but got dilation[%s].", | 169 | + "dilation", AclarrayToString(params_.dilation).c_str(), |
| 141 | - AclarrayToString(params_.dilation).c_str()), return false); | 170 | + "dilation[0]、dilation[1] must be 1, dilation[2]、dilation[3] must be greater than or equal to 1" |
| 171 | + ), return false); | ||
| 142 | OP_CHECK(params_.groups > 0, | 172 | OP_CHECK(params_.groups > 0, |
| 143 | - OP_LOGE(ACLNN_ERR_PARAM_INVALID, "groups should be greater than 0, but got %ld.", params_.groups), return false); | 173 | + OP_LOGE_FOR_INVALID_VALUE_WITH_REASON(ACLNN_DEFORMABLE_NAME, "groups", |
| 174 | + std::to_string(params_.groups).c_str(), "the value of groups must be greater than 0" | ||
| 175 | + ), return false); | ||
| 144 | OP_CHECK(params_.deformableGroups > 0, | 176 | OP_CHECK(params_.deformableGroups > 0, |
| 145 | - OP_LOGE(ACLNN_ERR_PARAM_INVALID, "deformableGroups should be greater than 0, but got %ld.", params_.deformableGroups), return false); | 177 | + OP_LOGE_FOR_INVALID_VALUE_WITH_REASON(ACLNN_DEFORMABLE_NAME, "deformableGroups", |
| 178 | + std::to_string(params_.deformableGroups).c_str(), "the value of deformableGroups must be greater than 0" | ||
| 179 | + ), return false); | ||
| 146 | OP_CHECK(params_.modulated == true, | 180 | OP_CHECK(params_.modulated == true, |
| 147 | - OP_LOGE(ACLNN_ERR_PARAM_INVALID, "modulated should be true, but got false."), return false); | 181 | + OP_LOGE_FOR_INVALID_VALUE_WITH_REASON(ACLNN_DEFORMABLE_NAME, "modulated", |
| 182 | + std::to_string(params_.modulated).c_str(), "the value of modulated must be true" | ||
| 183 | + ), return false); | ||
| 148 | return true; | 184 | return true; |
| 149 | } | 185 | } |
| 150 | 186 | ||
| @@ -175,11 +211,15 @@ bool DeformableConv2dBackwardChecker::CheckShape() | |||
| 175 | int64_t inSize = inH * inW; | 211 | int64_t inSize = inH * inW; |
| 176 | int64_t outC = inputTensor_.weight->GetViewShape()[INDEX_ZERO]; | 212 | int64_t outC = inputTensor_.weight->GetViewShape()[INDEX_ZERO]; |
| 177 | OP_CHECK(inC % params_.deformableGroups == 0, | 213 | OP_CHECK(inC % params_.deformableGroups == 0, |
| 178 | - OP_LOGE(ACLNN_ERR_PARAM_INVALID, "inC[%ld] needs to be divisible by deformable_groups[%ld].", inC, params_.deformableGroups), return false); | 214 | + OP_LOGE_FOR_INVALID_SHAPE_WITH_REASON(ACLNN_DEFORMABLE_NAME, "inC", std::to_string(inC).c_str(), |
| 215 | + "inC must be exactly divisible by deformableGroups"), return false); | ||
| 179 | OP_CHECK(inC % params_.groups == 0 && outC % params_.groups == 0, | 216 | OP_CHECK(inC % params_.groups == 0 && outC % params_.groups == 0, |
| 180 | - OP_LOGE(ACLNN_ERR_PARAM_INVALID, "Both inC[%ld] and outC[%ld] needs to be divisible by groups[%ld].", inC, outC, params_.groups), return false); | 217 | + OP_LOGE_FOR_INVALID_SHAPES_WITH_REASON(ACLNN_DEFORMABLE_NAME, "inC,outC", |
| 181 | - OP_CHECK(inSize <= INT_MAX_VALUE, | 218 | + (std::to_string(inC) + "," + std::to_string(outC)).c_str(), |
| 182 | - OP_LOGE(ACLNN_ERR_PARAM_INVALID, "inH[%ld] multiplied by inW[%ld] should not exceed 2147483647.", inH, inW), return false); | 219 | + "all axis of [inC, outC] must be divisible by groups"), return false); |
| 220 | + OP_CHECK(inSize <= INT_MAX_VALUE, OP_LOGE_FOR_INVALID_SHAPES_WITH_REASON(ACLNN_DEFORMABLE_NAME, "inH,inW", | ||
| 221 | + (std::to_string(inC) + "," + std::to_string(outC)).c_str(), | ||
| 222 | + "inH * inW must be not greater than 2147483647"), return false); | ||
| 183 | 223 | ||
| 184 | int64_t kH = (*params_.kernelSize)[INDEX_ZERO]; | 224 | int64_t kH = (*params_.kernelSize)[INDEX_ZERO]; |
| 185 | int64_t kW = (*params_.kernelSize)[INDEX_ONE]; | 225 | int64_t kW = (*params_.kernelSize)[INDEX_ONE]; |
| @@ -210,15 +250,18 @@ bool DeformableConv2dBackwardChecker::CheckShape() | |||
| 210 | 250 | ||
| 211 | int64_t matmulK = kH * kW * inC / params_.groups; | 251 | int64_t matmulK = kH * kW * inC / params_.groups; |
| 212 | OP_CHECK(matmulK <= MAX_MATMUL_K, | 252 | OP_CHECK(matmulK <= MAX_MATMUL_K, |
| 213 | - OP_LOGE(ACLNN_ERR_PARAM_INVALID,"kH[%ld] multiplied by kW[%ld] multiplied by inC[%ld] divided by groups[%ld] should not exceed 65535.", | 253 | + OP_LOGE_FOR_INVALID_SHAPES_WITH_REASON(ACLNN_DEFORMABLE_NAME, "(kH * kW * inC) / params_.groups", |
| 214 | - kH, kW, inC, params_.groups),return false); | 254 | + (std::to_string(matmulK)).c_str(), |
| 255 | + "kH * kW * inC / params_.groups should not greater than 65535"), return false); | ||
| 215 | return true; | 256 | return true; |
| 216 | } | 257 | } |
| 217 | 258 | ||
| 218 | aclnnStatus DeformableConv2dBackwardChecker::CheckParams() | 259 | aclnnStatus DeformableConv2dBackwardChecker::CheckParams() |
| 219 | { | 260 | { |
| 220 | OP_CHECK(npuArch_ == NpuArch::DAV_3510, | 261 | OP_CHECK(npuArch_ == NpuArch::DAV_3510, |
| 221 | - OP_LOGE(ACLNN_ERR_PARAM_INVALID, "current soc version not support."), return false); | 262 | + OP_LOGE_FOR_INVALID_VALUE_WITH_REASON(ACLNN_DEFORMABLE_NAME, "npuarch", |
| 263 | + std::to_string(static_cast<uint32_t>(npuArch_)).c_str(), "npuarch must not be 3510"), | ||
| 264 | + return false); | ||
| 222 | 265 | ||
| 223 | CHECK_COND(CheckNotNull(), ACLNN_ERR_PARAM_NULLPTR, "CheckNotNull failed!"); | 266 | CHECK_COND(CheckNotNull(), ACLNN_ERR_PARAM_NULLPTR, "CheckNotNull failed!"); |
| 224 | CHECK_COND(CheckDtypeValid(), ACLNN_ERR_PARAM_INVALID, "CheckDtypeValid failed!"); | 267 | CHECK_COND(CheckDtypeValid(), ACLNN_ERR_PARAM_INVALID, "CheckDtypeValid failed!"); |
| @@ -215,6 +215,36 @@ TEST_F(convolution_backward_test, test_Conv1DBackward_Fp16) { | |||
| 215 | aclnnStatus aclRet = ut.TestGetWorkspaceSize(&workspace_size); | 215 | aclnnStatus aclRet = ut.TestGetWorkspaceSize(&workspace_size); |
| 216 | EXPECT_EQ(aclRet, ACLNN_SUCCESS); | 216 | EXPECT_EQ(aclRet, ACLNN_SUCCESS); |
| 217 | } | 217 | } |
| 218 | + | ||
| 219 | +TEST_F(convolution_backward_test, test_Conv1DBackward_invalid_format_error) { | ||
| 220 | + auto input_tensor_desc = TensorDesc({16, 16, 16}, ACL_FLOAT16, ACL_FORMAT_NCHW); | ||
| 221 | + auto weight_tensor_desc = TensorDesc({8, 16, 3}, ACL_FLOAT16, ACL_FORMAT_NCL); | ||
| 222 | + auto grad_output_tensor_desc = TensorDesc({16, 8, 16}, ACL_FLOAT16, ACL_FORMAT_NCL); | ||
| 223 | + | ||
| 224 | + auto bias_sizes_desc = IntArrayDesc(vector<int64_t>{1}); | ||
| 225 | + auto stride_desc = IntArrayDesc(vector<int64_t>{1}); | ||
| 226 | + auto padding_desc = IntArrayDesc(vector<int64_t>{1}); | ||
| 227 | + auto dilation_desc = IntArrayDesc(vector<int64_t>{1}); | ||
| 228 | + bool transposed = false; | ||
| 229 | + auto output_padding_desc = IntArrayDesc(vector<int64_t>{0}); | ||
| 230 | + int groups = 1; | ||
| 231 | + auto output_mask = BoolArrayDesc(vector<bool>{true, true, true}); | ||
| 232 | + auto gradInput = TensorDesc({16, 16, 16}, ACL_FLOAT16, ACL_FORMAT_NCL); | ||
| 233 | + auto gradWeight = TensorDesc({8, 16, 3}, ACL_FLOAT16, ACL_FORMAT_NCL); | ||
| 234 | + auto gradBias = TensorDesc({8}, ACL_FLOAT16, ACL_FORMAT_ND); | ||
| 235 | + | ||
| 236 | + int8_t cubeMathType = 0; | ||
| 237 | + | ||
| 238 | + auto ut = | ||
| 239 | + OP_API_UT(aclnnConvolutionBackward, | ||
| 240 | + INPUT(grad_output_tensor_desc, input_tensor_desc, weight_tensor_desc, bias_sizes_desc, stride_desc, | ||
| 241 | + padding_desc, dilation_desc, transposed, output_padding_desc, groups, output_mask, cubeMathType), | ||
| 242 | + OUTPUT(gradInput, gradWeight, gradBias)); | ||
| 243 | + | ||
| 244 | + uint64_t workspace_size = 0; | ||
| 245 | + aclnnStatus aclRet = ut.TestGetWorkspaceSize(&workspace_size); | ||
| 246 | + EXPECT_EQ(aclRet, ACLNN_ERR_PARAM_INVALID); | ||
| 247 | +} | ||
| 218 | // test empty | 248 | // test empty |
| 219 | TEST_F(convolution_backward_test, test_ConvBackward_empty_error) { | 249 | TEST_F(convolution_backward_test, test_ConvBackward_empty_error) { |
| 220 | auto input_tensor_desc = TensorDesc({16, 16, 0, 16}, ACL_FLOAT16, ACL_FORMAT_NCHW); | 250 | auto input_tensor_desc = TensorDesc({16, 16, 0, 16}, ACL_FLOAT16, ACL_FORMAT_NCHW); |
| @@ -1965,4 +1995,231 @@ TEST_F(convolution_backward_test, ascend910B2_test_Conv3DBackward_DH_Swap) { | |||
| 1965 | aclnnStatus aclRet = ut.TestGetWorkspaceSize(&workspace_size); | 1995 | aclnnStatus aclRet = ut.TestGetWorkspaceSize(&workspace_size); |
| 1966 | EXPECT_EQ(aclRet, ACLNN_SUCCESS); | 1996 | EXPECT_EQ(aclRet, ACLNN_SUCCESS); |
| 1967 | } | 1997 | } |
| 1998 | + | ||
| 1999 | +TEST_F(convolution_backward_test, ascend910B2_test_groups_zero_error) { | ||
| 2000 | + auto input_tensor_desc = TensorDesc({1, 16, 10, 10}, ACL_FLOAT16, ACL_FORMAT_NCHW); | ||
| 2001 | + auto weight_tensor_desc = TensorDesc({16, 16, 3, 3}, ACL_FLOAT16, ACL_FORMAT_NCHW); | ||
| 2002 | + auto grad_output_tensor_desc = TensorDesc({1, 16, 10, 10}, ACL_FLOAT16, ACL_FORMAT_NCHW); | ||
| 2003 | + | ||
| 2004 | + auto bias_sizes_desc = IntArrayDesc(vector<int64_t>{16}); | ||
| 2005 | + auto stride_desc = IntArrayDesc(vector<int64_t>{1, 1}); | ||
| 2006 | + auto padding_desc = IntArrayDesc(vector<int64_t>{1, 1}); | ||
| 2007 | + auto dilation_desc = IntArrayDesc(vector<int64_t>{1, 1}); | ||
| 2008 | + bool transposed = false; | ||
| 2009 | + auto output_padding_desc = IntArrayDesc(vector<int64_t>{0, 0}); | ||
| 2010 | + int groups = 0; | ||
| 2011 | + auto output_mask = BoolArrayDesc(vector<bool>{true, true, true}); | ||
| 2012 | + auto gradInput = TensorDesc({1, 16, 10, 10}, ACL_FLOAT16, ACL_FORMAT_NCHW); | ||
| 2013 | + auto gradWeight = TensorDesc({16, 16, 3, 3}, ACL_FLOAT16, ACL_FORMAT_NCHW); | ||
| 2014 | + auto gradBias = TensorDesc({16}, ACL_FLOAT16, ACL_FORMAT_ND); | ||
| 2015 | + | ||
| 2016 | + int8_t cubeMathType = 0; | ||
| 2017 | + | ||
| 2018 | + auto ut = | ||
| 2019 | + OP_API_UT(aclnnConvolutionBackward, | ||
| 2020 | + INPUT(grad_output_tensor_desc, input_tensor_desc, weight_tensor_desc, bias_sizes_desc, stride_desc, | ||
| 2021 | + padding_desc, dilation_desc, transposed, output_padding_desc, groups, output_mask, cubeMathType), | ||
| 2022 | + OUTPUT(gradInput, gradWeight, gradBias)); | ||
| 2023 | + | ||
| 2024 | + uint64_t workspace_size = 0; | ||
| 2025 | + aclnnStatus aclRet = ut.TestGetWorkspaceSize(&workspace_size); | ||
| 2026 | + EXPECT_EQ(aclRet, ACLNN_ERR_PARAM_INVALID); | ||
| 2027 | +} | ||
| 2028 | + | ||
| 2029 | +TEST_F(convolution_backward_test, ascend910B2_test_weightCout_not_divisible_by_groups_error) { | ||
| 2030 | + auto input_tensor_desc = TensorDesc({1, 16, 10, 10}, ACL_FLOAT16, ACL_FORMAT_NCHW); | ||
| 2031 | + auto weight_tensor_desc = TensorDesc({17, 16, 3, 3}, ACL_FLOAT16, ACL_FORMAT_NCHW); | ||
| 2032 | + auto grad_output_tensor_desc = TensorDesc({1, 17, 10, 10}, ACL_FLOAT16, ACL_FORMAT_NCHW); | ||
| 2033 | + | ||
| 2034 | + auto bias_sizes_desc = IntArrayDesc(vector<int64_t>{17}); | ||
| 2035 | + auto stride_desc = IntArrayDesc(vector<int64_t>{1, 1}); | ||
| 2036 | + auto padding_desc = IntArrayDesc(vector<int64_t>{1, 1}); | ||
| 2037 | + auto dilation_desc = IntArrayDesc(vector<int64_t>{1, 1}); | ||
| 2038 | + bool transposed = false; | ||
| 2039 | + auto output_padding_desc = IntArrayDesc(vector<int64_t>{0, 0}); | ||
| 2040 | + int groups = 2; | ||
| 2041 | + auto output_mask = BoolArrayDesc(vector<bool>{true, true, true}); | ||
| 2042 | + auto gradInput = TensorDesc({1, 16, 10, 10}, ACL_FLOAT16, ACL_FORMAT_NCHW); | ||
| 2043 | + auto gradWeight = TensorDesc({17, 16, 3, 3}, ACL_FLOAT16, ACL_FORMAT_NCHW); | ||
| 2044 | + auto gradBias = TensorDesc({17}, ACL_FLOAT16, ACL_FORMAT_ND); | ||
| 2045 | + | ||
| 2046 | + int8_t cubeMathType = 0; | ||
| 2047 | + | ||
| 2048 | + auto ut = | ||
| 2049 | + OP_API_UT(aclnnConvolutionBackward, | ||
| 2050 | + INPUT(grad_output_tensor_desc, input_tensor_desc, weight_tensor_desc, bias_sizes_desc, stride_desc, | ||
| 2051 | + padding_desc, dilation_desc, transposed, output_padding_desc, groups, output_mask, cubeMathType), | ||
| 2052 | + OUTPUT(gradInput, gradWeight, gradBias)); | ||
| 2053 | + | ||
| 2054 | + uint64_t workspace_size = 0; | ||
| 2055 | + aclnnStatus aclRet = ut.TestGetWorkspaceSize(&workspace_size); | ||
| 2056 | + EXPECT_EQ(aclRet, ACLNN_ERR_PARAM_INVALID); | ||
| 2057 | +} | ||
| 2058 | + | ||
| 2059 | +TEST_F(convolution_backward_test, ascend910B2_test_input_dim_less_than_3_error) { | ||
| 2060 | + auto input_tensor_desc = TensorDesc({0, 0}, ACL_FLOAT16, ACL_FORMAT_NCHW); | ||
| 2061 | + auto weight_tensor_desc = TensorDesc({16, 16, 3, 3}, ACL_FLOAT16, ACL_FORMAT_NCHW); | ||
| 2062 | + auto grad_output_tensor_desc = TensorDesc({1, 16, 10, 10}, ACL_FLOAT16, ACL_FORMAT_NCHW); | ||
| 2063 | + | ||
| 2064 | + auto bias_sizes_desc = IntArrayDesc(vector<int64_t>{16}); | ||
| 2065 | + auto stride_desc = IntArrayDesc(vector<int64_t>{1, 1}); | ||
| 2066 | + auto padding_desc = IntArrayDesc(vector<int64_t>{1, 1}); | ||
| 2067 | + auto dilation_desc = IntArrayDesc(vector<int64_t>{1, 1}); | ||
| 2068 | + bool transposed = false; | ||
| 2069 | + auto output_padding_desc = IntArrayDesc(vector<int64_t>{0, 0}); | ||
| 2070 | + int groups = 1; | ||
| 2071 | + auto output_mask = BoolArrayDesc(vector<bool>{true, true, true}); | ||
| 2072 | + auto gradInput = TensorDesc({0, 0}, ACL_FLOAT16, ACL_FORMAT_NCHW); | ||
| 2073 | + auto gradWeight = TensorDesc({16, 16, 3, 3}, ACL_FLOAT16, ACL_FORMAT_NCHW); | ||
| 2074 | + auto gradBias = TensorDesc({16}, ACL_FLOAT16, ACL_FORMAT_ND); | ||
| 2075 | + | ||
| 2076 | + int8_t cubeMathType = 0; | ||
| 2077 | + | ||
| 2078 | + auto ut = | ||
| 2079 | + OP_API_UT(aclnnConvolutionBackward, | ||
| 2080 | + INPUT(grad_output_tensor_desc, input_tensor_desc, weight_tensor_desc, bias_sizes_desc, stride_desc, | ||
| 2081 | + padding_desc, dilation_desc, transposed, output_padding_desc, groups, output_mask, cubeMathType), | ||
| 2082 | + OUTPUT(gradInput, gradWeight, gradBias)); | ||
| 2083 | + | ||
| 2084 | + uint64_t workspace_size = 0; | ||
| 2085 | + aclnnStatus aclRet = ut.TestGetWorkspaceSize(&workspace_size); | ||
| 2086 | + EXPECT_EQ(aclRet, ACLNN_ERR_PARAM_INVALID); | ||
| 2087 | +} | ||
| 2088 | + | ||
| 2089 | +TEST_F(convolution_backward_test, ascend910B2_test_gradOutput_input_dim_not_equal_error) { | ||
| 2090 | + auto input_tensor_desc = TensorDesc({1, 16, 10}, ACL_FLOAT16, ACL_FORMAT_NCL); | ||
| 2091 | + auto weight_tensor_desc = TensorDesc({16, 16, 3}, ACL_FLOAT16, ACL_FORMAT_NCL); | ||
| 2092 | + auto grad_output_tensor_desc = TensorDesc({1, 16, 10, 10}, ACL_FLOAT16, ACL_FORMAT_NCHW); | ||
| 2093 | + | ||
| 2094 | + auto bias_sizes_desc = IntArrayDesc(vector<int64_t>{16}); | ||
| 2095 | + auto stride_desc = IntArrayDesc(vector<int64_t>{1}); | ||
| 2096 | + auto padding_desc = IntArrayDesc(vector<int64_t>{1}); | ||
| 2097 | + auto dilation_desc = IntArrayDesc(vector<int64_t>{1}); | ||
| 2098 | + bool transposed = false; | ||
| 2099 | + auto output_padding_desc = IntArrayDesc(vector<int64_t>{0}); | ||
| 2100 | + int groups = 1; | ||
| 2101 | + auto output_mask = BoolArrayDesc(vector<bool>{true, true, true}); | ||
| 2102 | + auto gradInput = TensorDesc({1, 16, 10}, ACL_FLOAT16, ACL_FORMAT_NCL); | ||
| 2103 | + auto gradWeight = TensorDesc({16, 16, 3}, ACL_FLOAT16, ACL_FORMAT_NCL); | ||
| 2104 | + auto gradBias = TensorDesc({16}, ACL_FLOAT16, ACL_FORMAT_ND); | ||
| 2105 | + | ||
| 2106 | + int8_t cubeMathType = 0; | ||
| 2107 | + | ||
| 2108 | + auto ut = | ||
| 2109 | + OP_API_UT(aclnnConvolutionBackward, | ||
| 2110 | + INPUT(grad_output_tensor_desc, input_tensor_desc, weight_tensor_desc, bias_sizes_desc, stride_desc, | ||
| 2111 | + padding_desc, dilation_desc, transposed, output_padding_desc, groups, output_mask, cubeMathType), | ||
| 2112 | + OUTPUT(gradInput, gradWeight, gradBias)); | ||
| 2113 | + | ||
| 2114 | + uint64_t workspace_size = 0; | ||
| 2115 | + aclnnStatus aclRet = ut.TestGetWorkspaceSize(&workspace_size); | ||
| 2116 | + EXPECT_EQ(aclRet, ACLNN_ERR_PARAM_INVALID); | ||
| 2117 | +} | ||
| 2118 | + | ||
| 2119 | +TEST_F(convolution_backward_test, ascend910B2_test_empty_tensor_biasSizes_nullptr_error) { | ||
| 2120 | + auto input_tensor_desc = TensorDesc({0, 16, 10, 10}, ACL_FLOAT16, ACL_FORMAT_NCHW); | ||
| 2121 | + auto weight_tensor_desc = TensorDesc({16, 16, 3, 3}, ACL_FLOAT16, ACL_FORMAT_NCHW); | ||
| 2122 | + auto grad_output_tensor_desc = TensorDesc({0, 16, 10, 10}, ACL_FLOAT16, ACL_FORMAT_NCHW); | ||
| 2123 | + | ||
| 2124 | + auto stride_desc = IntArrayDesc(vector<int64_t>{1, 1}); | ||
| 2125 | + auto padding_desc = IntArrayDesc(vector<int64_t>{1, 1}); | ||
| 2126 | + auto dilation_desc = IntArrayDesc(vector<int64_t>{1, 1}); | ||
| 2127 | + bool transposed = false; | ||
| 2128 | + auto output_padding_desc = IntArrayDesc(vector<int64_t>{0, 0}); | ||
| 2129 | + int groups = 1; | ||
| 2130 | + auto output_mask = BoolArrayDesc(vector<bool>{true, true, true}); | ||
| 2131 | + auto gradInput = TensorDesc({0, 16, 10, 10}, ACL_FLOAT16, ACL_FORMAT_NCHW); | ||
| 2132 | + auto gradWeight = TensorDesc({16, 16, 3, 3}, ACL_FLOAT16, ACL_FORMAT_NCHW); | ||
| 2133 | + auto gradBias = TensorDesc({16}, ACL_FLOAT16, ACL_FORMAT_ND); | ||
| 2134 | + | ||
| 2135 | + int8_t cubeMathType = 0; | ||
| 2136 | + | ||
| 2137 | + uint64_t workspace_size = 0; | ||
| 2138 | + aclOpExecutor* executor = nullptr; | ||
| 2139 | + | ||
| 2140 | + aclnnStatus aclRet = aclnnConvolutionBackwardGetWorkspaceSize( | ||
| 2141 | + grad_output_tensor_desc.ToAclTypeRawPtr(), | ||
| 2142 | + input_tensor_desc.ToAclTypeRawPtr(), | ||
| 2143 | + weight_tensor_desc.ToAclTypeRawPtr(), | ||
| 2144 | + nullptr, | ||
| 2145 | + stride_desc.ToAclTypeRawPtr(), | ||
| 2146 | + padding_desc.ToAclTypeRawPtr(), | ||
| 2147 | + dilation_desc.ToAclTypeRawPtr(), | ||
| 2148 | + transposed, | ||
| 2149 | + output_padding_desc.ToAclTypeRawPtr(), | ||
| 2150 | + groups, | ||
| 2151 | + output_mask.ToAclTypeRawPtr(), | ||
| 2152 | + cubeMathType, | ||
| 2153 | + gradInput.ToAclTypeRawPtr(), | ||
| 2154 | + gradWeight.ToAclTypeRawPtr(), | ||
| 2155 | + gradBias.ToAclTypeRawPtr(), | ||
| 2156 | + &workspace_size, | ||
| 2157 | + &executor); | ||
| 2158 | + | ||
| 2159 | + if (executor != nullptr) { | ||
| 2160 | + delete executor; | ||
| 2161 | + } | ||
| 2162 | + | ||
| 2163 | + EXPECT_EQ(aclRet, ACLNN_ERR_PARAM_INVALID); | ||
| 2164 | +} | ||
| 2165 | + | ||
| 2166 | +TEST_F(convolution_backward_test, ascend910B2_test_gradOutput_empty_tensor_error) { | ||
| 2167 | + auto input_tensor_desc = TensorDesc({1, 16, 10, 10}, ACL_FLOAT16, ACL_FORMAT_NCHW); | ||
| 2168 | + auto weight_tensor_desc = TensorDesc({16, 16, 3, 3}, ACL_FLOAT16, ACL_FORMAT_NCHW); | ||
| 2169 | + auto grad_output_tensor_desc = TensorDesc({0, 16, 8, 8}, ACL_FLOAT16, ACL_FORMAT_NCHW); | ||
| 2170 | + | ||
| 2171 | + auto bias_sizes_desc = IntArrayDesc(vector<int64_t>{16}); | ||
| 2172 | + auto stride_desc = IntArrayDesc(vector<int64_t>{1, 1}); | ||
| 2173 | + auto padding_desc = IntArrayDesc(vector<int64_t>{1, 1}); | ||
| 2174 | + auto dilation_desc = IntArrayDesc(vector<int64_t>{1, 1}); | ||
| 2175 | + bool transposed = false; | ||
| 2176 | + auto output_padding_desc = IntArrayDesc(vector<int64_t>{0, 0}); | ||
| 2177 | + int groups = 1; | ||
| 2178 | + auto output_mask = BoolArrayDesc(vector<bool>{true, true, true}); | ||
| 2179 | + auto gradInput = TensorDesc({1, 16, 10, 10}, ACL_FLOAT16, ACL_FORMAT_NCHW); | ||
| 2180 | + auto gradWeight = TensorDesc({16, 16, 3, 3}, ACL_FLOAT16, ACL_FORMAT_NCHW); | ||
| 2181 | + auto gradBias = TensorDesc({16}, ACL_FLOAT16, ACL_FORMAT_ND); | ||
| 2182 | + | ||
| 2183 | + int8_t cubeMathType = 0; | ||
| 2184 | + | ||
| 2185 | + auto ut = | ||
| 2186 | + OP_API_UT(aclnnConvolutionBackward, | ||
| 2187 | + INPUT(grad_output_tensor_desc, input_tensor_desc, weight_tensor_desc, bias_sizes_desc, stride_desc, | ||
| 2188 | + padding_desc, dilation_desc, transposed, output_padding_desc, groups, output_mask, cubeMathType), | ||
| 2189 | + OUTPUT(gradInput, gradWeight, gradBias)); | ||
| 2190 | + | ||
| 2191 | + uint64_t workspace_size = 0; | ||
| 2192 | + aclnnStatus aclRet = ut.TestGetWorkspaceSize(&workspace_size); | ||
| 2193 | + EXPECT_EQ(aclRet, ACLNN_ERR_PARAM_INVALID); | ||
| 2194 | +} | ||
| 2195 | + | ||
| 2196 | +TEST_F(convolution_backward_test, ascend910B2_test_weight_empty_tensor_error) { | ||
| 2197 | + auto input_tensor_desc = TensorDesc({1, 16, 10, 10}, ACL_FLOAT16, ACL_FORMAT_NCHW); | ||
| 2198 | + auto weight_tensor_desc = TensorDesc({0, 16, 3, 3}, ACL_FLOAT16, ACL_FORMAT_NCHW); | ||
| 2199 | + auto grad_output_tensor_desc = TensorDesc({1, 16, 8, 8}, ACL_FLOAT16, ACL_FORMAT_NCHW); | ||
| 2200 | + | ||
| 2201 | + auto bias_sizes_desc = IntArrayDesc(vector<int64_t>{16}); | ||
| 2202 | + auto stride_desc = IntArrayDesc(vector<int64_t>{1, 1}); | ||
| 2203 | + auto padding_desc = IntArrayDesc(vector<int64_t>{1, 1}); | ||
| 2204 | + auto dilation_desc = IntArrayDesc(vector<int64_t>{1, 1}); | ||
| 2205 | + bool transposed = false; | ||
| 2206 | + auto output_padding_desc = IntArrayDesc(vector<int64_t>{0, 0}); | ||
| 2207 | + int groups = 1; | ||
| 2208 | + auto output_mask = BoolArrayDesc(vector<bool>{true, true, true}); | ||
| 2209 | + auto gradInput = TensorDesc({1, 16, 10, 10}, ACL_FLOAT16, ACL_FORMAT_NCHW); | ||
| 2210 | + auto gradWeight = TensorDesc({0, 16, 3, 3}, ACL_FLOAT16, ACL_FORMAT_NCHW); | ||
| 2211 | + auto gradBias = TensorDesc({16}, ACL_FLOAT16, ACL_FORMAT_ND); | ||
| 2212 | + | ||
| 2213 | + int8_t cubeMathType = 0; | ||
| 2214 | + | ||
| 2215 | + auto ut = | ||
| 2216 | + OP_API_UT(aclnnConvolutionBackward, | ||
| 2217 | + INPUT(grad_output_tensor_desc, input_tensor_desc, weight_tensor_desc, bias_sizes_desc, stride_desc, | ||
| 2218 | + padding_desc, dilation_desc, transposed, output_padding_desc, groups, output_mask, cubeMathType), | ||
| 2219 | + OUTPUT(gradInput, gradWeight, gradBias)); | ||
| 2220 | + | ||
| 2221 | + uint64_t workspace_size = 0; | ||
| 2222 | + aclnnStatus aclRet = ut.TestGetWorkspaceSize(&workspace_size); | ||
| 2223 | + EXPECT_EQ(aclRet, ACLNN_ERR_PARAM_INVALID); | ||
| 2224 | +} | ||
| 1968 | } | 2225 | } |
| @@ -544,4 +544,23 @@ TEST_F(convolution_tbc_backward_test, ascend950_8bit_test_case) | |||
| 544 | aclnnStatus aclRet = ut.TestGetWorkspaceSize(&workspaceSize); | 544 | aclnnStatus aclRet = ut.TestGetWorkspaceSize(&workspaceSize); |
| 545 | EXPECT_EQ(aclRet, ACLNN_ERR_PARAM_INVALID); | 545 | EXPECT_EQ(aclRet, ACLNN_ERR_PARAM_INVALID); |
| 546 | } | 546 | } |
| 547 | + | ||
| 548 | +TEST_F(convolution_tbc_backward_test, ascend950_test_self_size_zero_error) { | ||
| 549 | + auto input_tensor_desc = TensorDesc({5, 1, 2}, ACL_FLOAT16, ACL_FORMAT_NCL); | ||
| 550 | + auto weight_tensor_desc = TensorDesc({1, 2, 2}, ACL_FLOAT16, ACL_FORMAT_NCL); | ||
| 551 | + auto self_desc = TensorDesc({0, 1, 2}, ACL_FLOAT16, ACL_FORMAT_NCL); | ||
| 552 | + auto bias_desc = TensorDesc({2}, ACL_FLOAT16, ACL_FORMAT_ND); | ||
| 553 | + int64_t pad = 0; | ||
| 554 | + int8_t cubeMathType = 1; | ||
| 555 | + auto gradInput = TensorDesc({0, 1, 2}, ACL_FLOAT16, ACL_FORMAT_NCL); | ||
| 556 | + auto gradWeight = TensorDesc({1, 2, 2}, ACL_FLOAT16, ACL_FORMAT_NCL); | ||
| 557 | + auto gradBias = TensorDesc({2}, ACL_FLOAT16, ACL_FORMAT_ND); | ||
| 558 | + | ||
| 559 | + auto ut = OP_API_UT(aclnnConvTbcBackward, INPUT(self_desc, input_tensor_desc, weight_tensor_desc, | ||
| 560 | + bias_desc, pad, cubeMathType), | ||
| 561 | + OUTPUT(gradInput, gradWeight, gradBias)); | ||
| 562 | + uint64_t workspaceSize = 0; | ||
| 563 | + aclnnStatus aclRet = ut.TestGetWorkspaceSize(&workspaceSize); | ||
| 564 | + EXPECT_EQ(aclRet, ACLNN_ERR_PARAM_INVALID); | ||
| 565 | +} | ||
| 547 | } | 566 | } |
| @@ -678,4 +678,46 @@ TEST_F(deformable_conv2d_backward_test, test_DeformableConv2dBackward_invalid_we | |||
| 678 | aclnnStatus aclRet = ut.TestGetWorkspaceSize(&workspace_size); | 678 | aclnnStatus aclRet = ut.TestGetWorkspaceSize(&workspace_size); |
| 679 | EXPECT_EQ(aclRet, ACLNN_ERR_PARAM_INVALID); | 679 | EXPECT_EQ(aclRet, ACLNN_ERR_PARAM_INVALID); |
| 680 | } | 680 | } |
| 681 | + | ||
| 682 | +TEST_F(deformable_conv2d_backward_test, test_DeformableConv2dBackward_weight_input_format_mismatch) | ||
| 683 | +{ | ||
| 684 | + op::SocVersionManager versionManager(op::SocVersion::ASCEND950); | ||
| 685 | + int64_t N = 1, inC = 64, inH = 128, inW = 128; | ||
| 686 | + int64_t outC = 64, K_H = 3, K_W = 3; | ||
| 687 | + int64_t groups = 1, deformableGroups = 1; | ||
| 688 | + bool modulated = true; | ||
| 689 | + auto stride_desc = IntArrayDesc(vector<int64_t>{1, 1, 1, 1}); | ||
| 690 | + auto padding_desc = IntArrayDesc(vector<int64_t>{1, 1, 1, 1}); | ||
| 691 | + auto dilation_desc = IntArrayDesc(vector<int64_t>{1, 1, 1, 1}); | ||
| 692 | + | ||
| 693 | + int64_t outH = CalculateOutputSize(inH, padding_desc.Get()[0], padding_desc.Get()[1], K_H, dilation_desc.Get()[2], stride_desc.Get()[2]); | ||
| 694 | + int64_t outW = CalculateOutputSize(inW, padding_desc.Get()[2], padding_desc.Get()[3], K_W, dilation_desc.Get()[3], stride_desc.Get()[3]); | ||
| 695 | + int64_t offsetOutC = CalculateOffsetOutChannels(outH, outW, K_H, K_W); | ||
| 696 | + int64_t offsetOutW = CalculateOffsetOutWidth(outW, K_W); | ||
| 697 | + int64_t offsetC = CalculateOffsetChannels(modulated, deformableGroups, K_H, K_W); | ||
| 698 | + | ||
| 699 | + auto input_tensor_desc = TensorDesc({N, inC, inH, inW}, ACL_FLOAT16, ACL_FORMAT_NCHW); | ||
| 700 | + auto grad_output_tensor_desc = TensorDesc({N, outC, outH, outW}, ACL_FLOAT16, ACL_FORMAT_NCHW); | ||
| 701 | + auto offset_out_tensor_desc = TensorDesc({N, inC, offsetOutC, offsetOutW}, ACL_FLOAT16, ACL_FORMAT_NCHW); | ||
| 702 | + auto weight_tensor_desc = TensorDesc({outC, inC / groups, K_H, K_W}, ACL_FLOAT16, ACL_FORMAT_ND); | ||
| 703 | + auto offset_tensor_desc = TensorDesc({N, offsetC, outH, outW}, ACL_FLOAT16, ACL_FORMAT_NCHW); | ||
| 704 | + | ||
| 705 | + auto gradInput = TensorDesc({N, inC, inH, inW}, ACL_FLOAT16, ACL_FORMAT_NCHW); | ||
| 706 | + auto gradWeight = TensorDesc({outC, inC / groups, K_H, K_W}, ACL_FLOAT16, ACL_FORMAT_NCHW); | ||
| 707 | + auto gradBias = TensorDesc({outC}, ACL_FLOAT16, ACL_FORMAT_ND); | ||
| 708 | + auto gradOffset = TensorDesc({N, offsetC, outH, outW}, ACL_FLOAT16, ACL_FORMAT_NCHW); | ||
| 709 | + | ||
| 710 | + auto kernel_size_desc = IntArrayDesc(vector<int64_t>{K_H, K_W}); | ||
| 711 | + | ||
| 712 | + auto ut = OP_API_UT( | ||
| 713 | + aclnnDeformableConv2dBackward, | ||
| 714 | + INPUT( | ||
| 715 | + input_tensor_desc, grad_output_tensor_desc, offset_out_tensor_desc, weight_tensor_desc, offset_tensor_desc, | ||
| 716 | + kernel_size_desc, stride_desc, padding_desc, dilation_desc, groups, deformableGroups, modulated), | ||
| 717 | + OUTPUT(gradInput, gradWeight, gradOffset, gradBias)); | ||
| 718 | + | ||
| 719 | + uint64_t workspace_size = 0; | ||
| 720 | + aclnnStatus aclRet = ut.TestGetWorkspaceSize(&workspace_size); | ||
| 721 | + EXPECT_EQ(aclRet, ACLNN_ERR_PARAM_INVALID); | ||
| 722 | +} | ||
| 681 | } // namespace | 723 | } // namespace |
描述格式改一下,错位了