| @@ -367,7 +367,99 @@ inline static bool isDivsMixDtypeSupport(const aclTensor* self, const aclScalar* |
| (self->GetDataType() == DataType::DT_FLOAT && other->GetDataType() == DataType::DT_FLOAT16) || | (self->GetDataType() == DataType::DT_FLOAT && other->GetDataType() == DataType::DT_FLOAT16) || |
| (self->GetDataType() == DataType::DT_BF16 && other->GetDataType() == DataType::DT_FLOAT) || | (self->GetDataType() == DataType::DT_BF16 && other->GetDataType() == DataType::DT_FLOAT) || |
| (self->GetDataType() == DataType::DT_FLOAT && other->GetDataType() == DataType::DT_BF16) || | (self->GetDataType() == DataType::DT_FLOAT && other->GetDataType() == DataType::DT_BF16) || |
| - (self->GetDataType() == DataType::DT_BF16 && other->GetDataType() == DataType::DT_DOUBLE); | + (self->GetDataType() == DataType::DT_BF16 && other->GetDataType() == DataType::DT_DOUBLE) || |
| + (self->GetDataType() == DataType::DT_FLOAT16 && other->GetDataType() == DataType::DT_BF16) || |
| + (self->GetDataType() == DataType::DT_BF16 && other->GetDataType() == DataType::DT_FLOAT16); |
| +} |
| + |
| +inline static bool checkMixDtypeConditions(DataType selfDtype, DataType otherDtype){ |
| + return (selfDtype == DataType::DT_FLOAT16 && otherDtype == DataType::DT_FLOAT) || |
| + (selfDtype == DataType::DT_FLOAT16 && otherDtype == DataType::DT_BF16) || |
| + (selfDtype == DataType::DT_BF16 && otherDtype == DataType::DT_FLOAT) || |
| + (selfDtype == DataType::DT_BF16 && otherDtype == DataType::DT_FLOAT16) || |
| + (selfDtype == DataType::DT_FLOAT && otherDtype == DataType::DT_FLOAT16) || |
| + (selfDtype == DataType::DT_FLOAT && otherDtype == DataType::DT_BF16); |
| +} |
| + |
| +inline static bool isMixDtypeScalarSupport(const aclTensor* self, const aclScalar* other) |
| +{ |
| + auto socVersion = GetCurrentPlatformInfo().GetSocVersion(); |
| + if (socVersion != SocVersion::ASCEND910B && socVersion != SocVersion::ASCEND910_93) { |
| + return false; |
| + } |
| + return checkMixDtypeConditions(self->GetDataType(), other->GetDataType()); |
| +} |
| + |
| +inline static bool isMixDtypeTensorSupport(const aclTensor* self, const aclTensor* other) |
| +{ |
| + auto socVersion = GetCurrentPlatformInfo().GetSocVersion(); |
| + if (socVersion != SocVersion::ASCEND910B && socVersion != SocVersion::ASCEND910_93) { |
| + return false; |
| + } |
| + return checkMixDtypeConditions(self->GetDataType(), other->GetDataType()); |
| +} |
| + |
| +static aclnnStatus HandleMixDataTypeDiv( |
| + const aclTensor* self, const aclTensor* other, aclOpExecutor* executor, const aclTensor** divOpOut |
| +) { |
| + |
| + auto selfContiguous = l0op::Contiguous(self, executor); |
| + CHECK_RET(selfContiguous != nullptr, ACLNN_ERR_INNER_NULLPTR); |
| + |
| + |
| + auto otherContiguous = l0op::Contiguous(other, executor); |
| + CHECK_RET(otherContiguous != nullptr, ACLNN_ERR_INNER_NULLPTR); |
| + |
| + *divOpOut = l0op::RealDiv(selfContiguous, otherContiguous, false, executor); |
| + CHECK_RET(*divOpOut != nullptr, ACLNN_ERR_INNER_NULLPTR); |
| + |
| + return ACLNN_SUCCESS; |
| +} |
| + |
| +static aclnnStatus HandleNotMixDataTypeDiv( |
| + const aclTensor* self, const aclTensor* other, aclOpExecutor* executor, const aclTensor** divOpOut |
| +) { |
| + |
| + auto npuArch = op::GetCurrentPlatformInfo().GetCurNpuArch(); |
| + auto promoteType = (!IsRegBase(npuArch)) ? |
| + CompatibleInferDivDtype(self->GetDataType(), other->GetDataType()) : |
| + InferDivModeDtype(self->GetDataType(), other->GetDataType(), MODE_REAL_DIV); |
| + |
| + |
| + const aclTensor* selfProcessed = nullptr; |
| + if (self->GetDataType() == promoteType && l0op::IsRealDivSupportNonContiguous(self)) { |
| + selfProcessed = executor->CreateView( |
| + self, self->GetViewShape(), self->GetStorageShape(), self->GetViewStrides(), self->GetViewOffset()); |
| + } else { |
| + |
| + auto selfContiguous = l0op::Contiguous(self, executor); |
| + CHECK_RET(selfContiguous != nullptr, ACLNN_ERR_INNER_NULLPTR); |
| + |
| + |
| + selfProcessed = l0op::Cast(selfContiguous, promoteType, executor); |
| + } |
| + CHECK_RET(selfProcessed != nullptr, ACLNN_ERR_INNER_NULLPTR); |
| + |
| + |
| + const aclTensor* otherProcessed = nullptr; |
| + if (other->GetDataType() == promoteType && l0op::IsRealDivSupportNonContiguous(self)) { |
| + otherProcessed = executor->CreateView( |
| + other, other->GetViewShape(), other->GetStorageShape(), other->GetViewStrides(), other->GetViewOffset()); |
| + } else { |
| + |
| + auto otherContiguous = l0op::Contiguous(other, executor); |
| + CHECK_RET(otherContiguous != nullptr, ACLNN_ERR_INNER_NULLPTR); |
| + |
| + |
| + otherProcessed = l0op::Cast(otherContiguous, promoteType, executor); |
| + } |
| + CHECK_RET(otherProcessed != nullptr, ACLNN_ERR_INNER_NULLPTR); |
| + |
| + |
| + *divOpOut = l0op::RealDiv(selfProcessed, otherProcessed, MODE_REAL_DIV, executor); |
| + CHECK_RET(*divOpOut != nullptr, ACLNN_ERR_INNER_NULLPTR); |
| + |
| + return ACLNN_SUCCESS; |
| } | } |
| | |
| aclnnStatus aclnnDivGetWorkspaceSize( | aclnnStatus aclnnDivGetWorkspaceSize( |
| @@ -390,45 +482,15 @@ aclnnStatus aclnnDivGetWorkspaceSize( |
| return ACLNN_SUCCESS; | return ACLNN_SUCCESS; |
| } | } |
| | |
| - // RealDiv算子需要对self和other两个输入做隐式数据类型转换,根据具体算子语义按需调用 | + bool isMixDataType = isMixDtypeTensorSupport(self, other); |
| - auto npuArch = op::GetCurrentPlatformInfo().GetCurNpuArch(); | + const aclTensor* divOpOut = nullptr; |
| - auto promoteType = (!IsRegBase(npuArch)) ? | + if (isMixDataType) { |
| - CompatibleInferDivDtype(self->GetDataType(), other->GetDataType()) : | + auto mixResult = HandleMixDataTypeDiv(self, other, uniqueExecutor.get(), &divOpOut); |
| - InferDivModeDtype(self->GetDataType(), other->GetDataType(), MODE_REAL_DIV); | + CHECK_RET(mixResult == ACLNN_SUCCESS, mixResult); |
| - | |
| - | |
| - const aclTensor* selfProcessed = nullptr; | |
| - if (self->GetDataType() == promoteType && l0op::IsRealDivSupportNonContiguous(self)) { | |
| - selfProcessed = uniqueExecutor.get()->CreateView( | |
| - self, self->GetViewShape(), self->GetStorageShape(), self->GetViewStrides(), self->GetViewOffset()); | |
| } else { | } else { |
| - // 固定写法,将输入self转换成连续的tensor | + auto notMixResult = HandleNotMixDataTypeDiv(self, other, uniqueExecutor.get(), &divOpOut); |
| - auto selfContiguous = l0op::Contiguous(self, uniqueExecutor.get()); | + CHECK_RET(notMixResult == ACLNN_SUCCESS, notMixResult); |
| - CHECK_RET(selfContiguous != nullptr, ACLNN_ERR_INNER_NULLPTR); | |
| - | |
| - | |
| - selfProcessed = l0op::Cast(selfContiguous, promoteType, uniqueExecutor.get()); | |
| } | } |
| - CHECK_RET(selfProcessed != nullptr, ACLNN_ERR_INNER_NULLPTR); | |
| - | |
| - | |
| - const aclTensor* otherProcessed = nullptr; | |
| - if (other->GetDataType() == promoteType && l0op::IsRealDivSupportNonContiguous(self)) { | |
| - otherProcessed = uniqueExecutor.get()->CreateView( | |
| - other, other->GetViewShape(), other->GetStorageShape(), other->GetViewStrides(), other->GetViewOffset()); | |
| - } else { | |
| - | |
| - auto otherContiguous = l0op::Contiguous(other, uniqueExecutor.get()); | |
| - CHECK_RET(otherContiguous != nullptr, ACLNN_ERR_INNER_NULLPTR); | |
| - | |
| - | |
| - otherProcessed = l0op::Cast(otherContiguous, promoteType, uniqueExecutor.get()); | |
| - } | |
| - CHECK_RET(otherProcessed != nullptr, ACLNN_ERR_INNER_NULLPTR); | |
| - | |
| - | |
| - auto divOpOut = l0op::RealDiv(selfProcessed, otherProcessed, MODE_REAL_DIV, uniqueExecutor.get()); | |
| - CHECK_RET(divOpOut != nullptr, ACLNN_ERR_INNER_NULLPTR); | |
| | |
| | |
| auto castOut = l0op::Cast(divOpOut, out->GetDataType(), uniqueExecutor.get()); | auto castOut = l0op::Cast(divOpOut, out->GetDataType(), uniqueExecutor.get()); |
| @@ -568,7 +630,7 @@ aclnnStatus aclnnDivsGetWorkspaceSize( |
| self->GetViewStrides(), self->GetViewOffset()) : | self->GetViewStrides(), self->GetViewOffset()) : |
| l0op::Contiguous(self, uniqueExecutor.get()); | l0op::Contiguous(self, uniqueExecutor.get()); |
| CHECK_RET(selfProcessed != nullptr, ACLNN_ERR_INNER_NULLPTR); | CHECK_RET(selfProcessed != nullptr, ACLNN_ERR_INNER_NULLPTR); |
| - divOpOut = l0op::RealDiv(selfProcessed, otherConvert, MODE_REAL_DIV, uniqueExecutor.get()); | + divOpOut = l0op::RealDiv(selfProcessed, otherConvert, true, uniqueExecutor.get()); |
| CHECK_RET(divOpOut != nullptr, ACLNN_ERR_INNER_NULLPTR); | CHECK_RET(divOpOut != nullptr, ACLNN_ERR_INNER_NULLPTR); |
| } else { | } else { |
| auto promoteType = (!IsRegBase(npuArch)) ? | auto promoteType = (!IsRegBase(npuArch)) ? |
| @@ -655,47 +717,64 @@ aclnnStatus aclnnDivModGetWorkspaceSize( |
| | |
| auto selfCasted = selfContiguous; | auto selfCasted = selfContiguous; |
| auto otherCasted = otherContiguous; | auto otherCasted = otherContiguous; |
| - op::DataType promoteType; | + |
| - bool needToInt32 = false; | + bool isMixDataType = isMixDtypeTensorSupport(self, other); |
| - op::DataType oriType = out->GetDataType(); | |
| - auto npuArch = op::GetCurrentPlatformInfo().GetCurNpuArch(); | |
| - if (!IsRegBase(npuArch)) { | |
| - auto promoteRet = CompatibleInferDivModeDtype(self->GetDataType(), other->GetDataType(), mode, promoteType); | |
| - CHECK_RET(promoteRet == ACLNN_SUCCESS, promoteRet); | |
| - } else { | |
| - promoteType = InferDivModeDtype(self->GetDataType(), other->GetDataType(), mode); | |
| - | |
| - bool needToFloat = (promoteType == op::DataType::DT_BOOL && mode == MODE_FLOOR_DIV); | |
| - promoteType = needToFloat ? op::DataType::DT_FLOAT : promoteType; | |
| - | |
| - needToInt32 = (promoteType == op::DataType::DT_INT16 && mode == MODE_FLOOR_DIV) || | |
| - ((promoteType == op::DataType::DT_INT8 || promoteType == op::DataType::DT_UINT8 || | |
| - promoteType == op::DataType::DT_INT16) && | |
| - mode == MODE_TRUNC_DIV); | |
| - oriType = promoteType; | |
| - promoteType = needToInt32 ? op::DataType::DT_INT32 : promoteType; | |
| - } | |
| - selfCasted = l0op::Cast(selfContiguous, promoteType, uniqueExecutor.get()); | |
| - CHECK_RET(selfCasted != nullptr, ACLNN_ERR_INNER_NULLPTR); | |
| - otherCasted = l0op::Cast(otherContiguous, promoteType, uniqueExecutor.get()); | |
| - CHECK_RET(otherCasted != nullptr, ACLNN_ERR_INNER_NULLPTR); | |
| const aclTensor* divOpOut = nullptr; | const aclTensor* divOpOut = nullptr; |
| - // 根据mode分三种场景调用算子计算 | + if (isMixDataType) { |
| - if (mode == MODE_FLOOR_DIV) { | + if (mode == MODE_FLOOR_DIV) { |
| - divOpOut = l0op::FloorDiv(selfCasted, otherCasted, uniqueExecutor.get()); | + divOpOut = l0op::FloorDiv(selfCasted, otherCasted, false, uniqueExecutor.get()); |
| - } else { | + } else { |
| - divOpOut = l0op::RealDiv(selfCasted, otherCasted, mode, uniqueExecutor.get()); | + divOpOut = l0op::RealDiv(selfCasted, otherCasted, false, uniqueExecutor.get()); |
| + CHECK_RET(divOpOut != nullptr, ACLNN_ERR_INNER_NULLPTR); |
| + if (mode == MODE_TRUNC_DIV && divOpOut->GetDataType() != op::DataType::DT_INT64 && |
| + divOpOut->GetDataType() != op::DataType::DT_INT16) { |
| + divOpOut = l0op::Trunc(divOpOut, uniqueExecutor.get()); |
| + } |
| + } |
| CHECK_RET(divOpOut != nullptr, ACLNN_ERR_INNER_NULLPTR); | CHECK_RET(divOpOut != nullptr, ACLNN_ERR_INNER_NULLPTR); |
| - if (mode == MODE_TRUNC_DIV && divOpOut->GetDataType() != op::DataType::DT_INT64 && | + } else { |
| - divOpOut->GetDataType() != op::DataType::DT_INT16) { | + op::DataType promoteType; |
| - divOpOut = l0op::Trunc(divOpOut, uniqueExecutor.get()); | + bool needToInt32 = false; |
| + op::DataType oriType = out->GetDataType(); |
| + auto npuArch = op::GetCurrentPlatformInfo().GetCurNpuArch(); |
| + if (!IsRegBase(npuArch)) { |
| + auto promoteRet = CompatibleInferDivModeDtype(self->GetDataType(), other->GetDataType(), mode, promoteType); |
| + CHECK_RET(promoteRet == ACLNN_SUCCESS, promoteRet); |
| + } else { |
| + promoteType = InferDivModeDtype(self->GetDataType(), other->GetDataType(), mode); |
| + |
| + bool needToFloat = (promoteType == op::DataType::DT_BOOL && mode == MODE_FLOOR_DIV); |
| + promoteType = needToFloat ? op::DataType::DT_FLOAT : promoteType; |
| + |
| + needToInt32 = (promoteType == op::DataType::DT_INT16 && mode == MODE_FLOOR_DIV) || |
| + ((promoteType == op::DataType::DT_INT8 || promoteType == op::DataType::DT_UINT8 || |
| + promoteType == op::DataType::DT_INT16) && |
| + mode == MODE_TRUNC_DIV); |
| + oriType = promoteType; |
| + promoteType = needToInt32 ? op::DataType::DT_INT32 : promoteType; |
| + } |
| + selfCasted = l0op::Cast(selfContiguous, promoteType, uniqueExecutor.get()); |
| + CHECK_RET(selfCasted != nullptr, ACLNN_ERR_INNER_NULLPTR); |
| + otherCasted = l0op::Cast(otherContiguous, promoteType, uniqueExecutor.get()); |
| + CHECK_RET(otherCasted != nullptr, ACLNN_ERR_INNER_NULLPTR); |
| + |
| + if (mode == MODE_FLOOR_DIV) { |
| + divOpOut = l0op::FloorDiv(selfCasted, otherCasted, uniqueExecutor.get()); |
| + } else { |
| + divOpOut = l0op::RealDiv(selfCasted, otherCasted, mode, uniqueExecutor.get()); |
| + CHECK_RET(divOpOut != nullptr, ACLNN_ERR_INNER_NULLPTR); |
| + if (mode == MODE_TRUNC_DIV && divOpOut->GetDataType() != op::DataType::DT_INT64 && |
| + divOpOut->GetDataType() != op::DataType::DT_INT16) { |
| + divOpOut = l0op::Trunc(divOpOut, uniqueExecutor.get()); |
| + } |
| + } |
| + CHECK_RET(divOpOut != nullptr, ACLNN_ERR_INNER_NULLPTR); |
| + if (needToInt32) { |
| + divOpOut = l0op::Cast(divOpOut, oriType, uniqueExecutor.get()); |
| + CHECK_RET(divOpOut != nullptr, ACLNN_ERR_INNER_NULLPTR); |
| } | } |
| } | } |
| - CHECK_RET(divOpOut != nullptr, ACLNN_ERR_INNER_NULLPTR); | + |
| - if (needToInt32) { | |
| - divOpOut = l0op::Cast(divOpOut, oriType, uniqueExecutor.get()); | |
| - CHECK_RET(divOpOut != nullptr, ACLNN_ERR_INNER_NULLPTR); | |
| - } | |
| auto castOut = l0op::Cast(divOpOut, out->GetDataType(), uniqueExecutor.get()); | auto castOut = l0op::Cast(divOpOut, out->GetDataType(), uniqueExecutor.get()); |
| CHECK_RET(castOut != nullptr, ACLNN_ERR_INNER_NULLPTR); | CHECK_RET(castOut != nullptr, ACLNN_ERR_INNER_NULLPTR); |
| | |
| @@ -737,47 +816,65 @@ aclnnStatus aclnnDivModsGetWorkspaceSize( |
| CHECK_RET(selfContiguous != nullptr, ACLNN_ERR_INNER_NULLPTR); | CHECK_RET(selfContiguous != nullptr, ACLNN_ERR_INNER_NULLPTR); |
| | |
| auto selfCasted = selfContiguous; | auto selfCasted = selfContiguous; |
| - op::DataType promoteType; | + bool isMixDataType = isMixDtypeScalarSupport(self, other); |
| - bool needToInt32 = false; | |
| - op::DataType oriType = out->GetDataType(); | |
| - auto npuArch = op::GetCurrentPlatformInfo().GetCurNpuArch(); | |
| - if (!IsRegBase(npuArch)) { | |
| - auto promoteRet = CompatibleInferDivsModeDtype(self->GetDataType(), other->GetDataType(), mode, promoteType); | |
| - CHECK_RET(promoteRet == ACLNN_SUCCESS, promoteRet); | |
| - } else { | |
| - promoteType = InferDivsModeDtype(self->GetDataType(), other->GetDataType(), mode); | |
| - | |
| - bool needToFloat = (promoteType == op::DataType::DT_BOOL && mode == MODE_FLOOR_DIV); | |
| - promoteType = needToFloat ? op::DataType::DT_FLOAT : promoteType; | |
| - | |
| - needToInt32 = (promoteType == op::DataType::DT_INT16 && mode == MODE_FLOOR_DIV) || | |
| - ((promoteType == op::DataType::DT_INT8 || promoteType == op::DataType::DT_UINT8 || | |
| - promoteType == op::DataType::DT_INT16) && | |
| - mode == MODE_TRUNC_DIV); | |
| - oriType = promoteType; | |
| - promoteType = needToInt32 ? op::DataType::DT_INT32 : promoteType; | |
| - } | |
| - selfCasted = l0op::Cast(selfContiguous, promoteType, uniqueExecutor.get()); | |
| - CHECK_RET(selfCasted != nullptr, ACLNN_ERR_INNER_NULLPTR); | |
| - auto otherCasted = uniqueExecutor.get()->ConvertToTensor(other, promoteType); | |
| - CHECK_RET(otherCasted != nullptr, ACLNN_ERR_INNER_NULLPTR); | |
| const aclTensor* divOpOut = nullptr; | const aclTensor* divOpOut = nullptr; |
| - // 根据mode分三种场景调用算子计算 | + if (isMixDataType) { |
| - if (mode == MODE_FLOOR_DIV) { | + auto otherConvert = uniqueExecutor.get()->ConvertToTensor(other, other->GetDataType()); |
| - divOpOut = l0op::FloorDiv(selfCasted, otherCasted, uniqueExecutor.get()); | + CHECK_RET(otherConvert != nullptr, ACLNN_ERR_INNER_NULLPTR); |
| - } else { | + if (mode == MODE_FLOOR_DIV) { |
| - divOpOut = l0op::RealDiv(selfCasted, otherCasted, mode, uniqueExecutor.get()); | + divOpOut = l0op::FloorDiv(selfCasted, otherConvert, true, uniqueExecutor.get()); |
| + } else { |
| + divOpOut = l0op::RealDiv(selfCasted, otherConvert, true, uniqueExecutor.get()); |
| + CHECK_RET(divOpOut != nullptr, ACLNN_ERR_INNER_NULLPTR); |
| + if (mode == MODE_TRUNC_DIV && divOpOut->GetDataType() != op::DataType::DT_INT64 && |
| + divOpOut->GetDataType() != op::DataType::DT_INT16) { |
| + divOpOut = l0op::Trunc(divOpOut, uniqueExecutor.get()); |
| + } |
| + } |
| CHECK_RET(divOpOut != nullptr, ACLNN_ERR_INNER_NULLPTR); | CHECK_RET(divOpOut != nullptr, ACLNN_ERR_INNER_NULLPTR); |
| - if (mode == MODE_TRUNC_DIV && divOpOut->GetDataType() != op::DataType::DT_INT64 && | + } else { |
| - divOpOut->GetDataType() != op::DataType::DT_INT16) { | + op::DataType promoteType; |
| - divOpOut = l0op::Trunc(divOpOut, uniqueExecutor.get()); | + bool needToInt32 = false; |
| + op::DataType oriType = out->GetDataType(); |
| + auto npuArch = op::GetCurrentPlatformInfo().GetCurNpuArch(); |
| + if (!IsRegBase(npuArch)) { |
| + auto promoteRet = CompatibleInferDivsModeDtype(self->GetDataType(), other->GetDataType(), mode, promoteType); |
| + CHECK_RET(promoteRet == ACLNN_SUCCESS, promoteRet); |
| + } else { |
| + promoteType = InferDivsModeDtype(self->GetDataType(), other->GetDataType(), mode); |
| + |
| + bool needToFloat = (promoteType == op::DataType::DT_BOOL && mode == MODE_FLOOR_DIV); |
| + promoteType = needToFloat ? op::DataType::DT_FLOAT : promoteType; |
| + |
| + needToInt32 = (promoteType == op::DataType::DT_INT16 && mode == MODE_FLOOR_DIV) || |
| + ((promoteType == op::DataType::DT_INT8 || promoteType == op::DataType::DT_UINT8 || |
| + promoteType == op::DataType::DT_INT16) && |
| + mode == MODE_TRUNC_DIV); |
| + oriType = promoteType; |
| + promoteType = needToInt32 ? op::DataType::DT_INT32 : promoteType; |
| + } |
| + selfCasted = l0op::Cast(selfContiguous, promoteType, uniqueExecutor.get()); |
| + CHECK_RET(selfCasted != nullptr, ACLNN_ERR_INNER_NULLPTR); |
| + auto otherCasted = uniqueExecutor.get()->ConvertToTensor(other, promoteType); |
| + CHECK_RET(otherCasted != nullptr, ACLNN_ERR_INNER_NULLPTR); |
| + |
| + if (mode == MODE_FLOOR_DIV) { |
| + divOpOut = l0op::FloorDiv(selfCasted, otherCasted, uniqueExecutor.get()); |
| + } else { |
| + divOpOut = l0op::RealDiv(selfCasted, otherCasted, mode, uniqueExecutor.get()); |
| + CHECK_RET(divOpOut != nullptr, ACLNN_ERR_INNER_NULLPTR); |
| + if (mode == MODE_TRUNC_DIV && divOpOut->GetDataType() != op::DataType::DT_INT64 && |
| + divOpOut->GetDataType() != op::DataType::DT_INT16) { |
| + divOpOut = l0op::Trunc(divOpOut, uniqueExecutor.get()); |
| + } |
| + } |
| + CHECK_RET(divOpOut != nullptr, ACLNN_ERR_INNER_NULLPTR); |
| + if (needToInt32) { |
| + divOpOut = l0op::Cast(divOpOut, oriType, uniqueExecutor.get()); |
| + CHECK_RET(divOpOut != nullptr, ACLNN_ERR_INNER_NULLPTR); |
| } | } |
| } | } |
| - CHECK_RET(divOpOut != nullptr, ACLNN_ERR_INNER_NULLPTR); | + |
| - if (needToInt32) { | |
| - divOpOut = l0op::Cast(divOpOut, oriType, uniqueExecutor.get()); | |
| - CHECK_RET(divOpOut != nullptr, ACLNN_ERR_INNER_NULLPTR); | |
| - } | |
| auto castOut = l0op::Cast(divOpOut, out->GetDataType(), uniqueExecutor.get()); | auto castOut = l0op::Cast(divOpOut, out->GetDataType(), uniqueExecutor.get()); |
| CHECK_RET(castOut != nullptr, ACLNN_ERR_INNER_NULLPTR); | CHECK_RET(castOut != nullptr, ACLNN_ERR_INNER_NULLPTR); |
| | |
| |
代码结构与可维护性: checkMixDtypeConditions函数(第375-382行)与isDivsMixDtypeSupport函数(第360-373行)存在功能重叠但逻辑不完全一致。isDivsMixDtypeSupport检查了更多数据类型组合(包括DT_BF16和DT_DOUBLE),而checkMixDtypeConditions只检查了部分组合。这可能导致不一致的判断结果。
问题类型: 代码结构与可维护性 文件路径:
math/div/op_api/aclnn_div.cpp行号: 375 问题代码:inline static bool checkMixDtypeConditions(DataType selfDtype, DataType otherDtype){ return (selfDtype == DataType::DT_FLOAT16 && otherDtype == DataType::DT_FLOAT) || (selfDtype == DataType::DT_FLOAT16 && otherDtype == DataType::DT_BF16) || (selfDtype == DataType::DT_BF16 && otherDtype == DataType::DT_FLOAT) || (selfDtype == DataType::DT_BF16 && otherDtype == DataType::DT_FLOAT16) || (selfDtype == DataType::DT_FLOAT && otherDtype == DataType::DT_FLOAT16) || (selfDtype == DataType::DT_FLOAT && otherDtype == DataType::DT_BF16); }修改建议:
此评论由代码审查工具自动生成