已合并
fix: 修复 div/mod 类算子多项代码缺陷 #2111
zhang-song-rui创建于 4月7日
fix: 修复 div/mod 类算子多项代码缺陷 #2111
已合并
共 9 个文件变更+92-11
| @@ -144,13 +144,12 @@ ge::graphStatus AddcdivTiling::GetPlatformInfo() | |||
| 144 | 144 | ||
| 145 | ge::graphStatus TilingForAddcdiv(gert::TilingContext* context) | 145 | ge::graphStatus TilingForAddcdiv(gert::TilingContext* context) |
| 146 | { | 146 | { |
| 147 | - auto nodeName = context->GetNodeName(); | 147 | + OP_LOGD("AddcdivTiling", "Enter TilingForAddcdiv"); |
| 148 | - OP_LOGD(nodeName, "Enter TilingForAddcdiv"); | ||
| 149 | if (context == nullptr) { | 148 | if (context == nullptr) { |
| 150 | - OP_LOGE(nodeName, "Tiling context is nullptr"); | 149 | + OP_LOGE("AddcdivTiling", "Tiling context is nullptr"); |
| 151 | return ge::GRAPH_FAILED; | 150 | return ge::GRAPH_FAILED; |
| 152 | } | 151 | } |
| 153 | - | 152 | + auto nodeName = context->GetNodeName(); |
| 154 | auto compileInfo = reinterpret_cast<const AddcdivCompileInfo*>(context->GetCompileInfo()); | 153 | auto compileInfo = reinterpret_cast<const AddcdivCompileInfo*>(context->GetCompileInfo()); |
| 155 | OP_CHECK_NULL_WITH_CONTEXT(context, compileInfo); | 154 | OP_CHECK_NULL_WITH_CONTEXT(context, compileInfo); |
| 156 | OP_LOGD(nodeName, "Enter ascendc AddcdivTiling"); | 155 | OP_LOGD(nodeName, "Enter ascendc AddcdivTiling"); |
| @@ -458,7 +458,7 @@ static aclnnStatus HandleNotMixDataTypeDiv( | |||
| 458 | 458 | ||
| 459 | // 处理other输入 | 459 | // 处理other输入 |
| 460 | const aclTensor* otherProcessed = nullptr; | 460 | const aclTensor* otherProcessed = nullptr; |
| 461 | - if (other->GetDataType() == promoteType && l0op::IsRealDivSupportNonContiguous(self)) { | 461 | + if (other->GetDataType() == promoteType && l0op::IsRealDivSupportNonContiguous(other)) { |
| 462 | otherProcessed = executor->CreateView( | 462 | otherProcessed = executor->CreateView( |
| 463 | other, other->GetViewShape(), other->GetStorageShape(), other->GetViewStrides(), other->GetViewOffset()); | 463 | other, other->GetViewShape(), other->GetStorageShape(), other->GetViewStrides(), other->GetViewOffset()); |
| 464 | } else { | 464 | } else { |
| @@ -97,10 +97,8 @@ const aclTensor* Div(const aclTensor* self, const aclTensor* other, aclOpExecuto | |||
| 97 | auto divOut = executor->AllocTensor(broadcastShape, self->GetDataType()); | 97 | auto divOut = executor->AllocTensor(broadcastShape, self->GetDataType()); |
| 98 | if (IsAiCoreSupport(self)) { | 98 | if (IsAiCoreSupport(self)) { |
| 99 | return DivAiCore(self, other, divOut, executor); | 99 | return DivAiCore(self, other, divOut, executor); |
| 100 | - } else { | ||
| 101 | - return DivAiCpu(self, other, divOut, executor); | ||
| 102 | } | 100 | } |
| 103 | - return divOut; | 101 | + return DivAiCpu(self, other, divOut, executor); |
Z 已过期 一个函数必须要有return ![]() ![]() | |||
| 104 | } | 102 | } |
| 105 | 103 | ||
| 106 | } // namespace l0op | 104 | } // namespace l0op |
| @@ -191,6 +191,30 @@ TEST_F(l2_div_test, case_NonContiguous) | |||
| 191 | EXPECT_EQ(aclRet, ACL_SUCCESS); | 191 | EXPECT_EQ(aclRet, ACL_SUCCESS); |
| 192 | } | 192 | } |
| 193 | 193 | ||
| 194 | +TEST_F(l2_div_test, case_NonContiguous_other_only) | ||
| 195 | +{ | ||
| 196 | + auto self_tensor_desc = TensorDesc({5, 4}, ACL_FLOAT, ACL_FORMAT_ND).ValueRange(-2, 2); | ||
| 197 | + auto other_tensor_desc = TensorDesc({5, 4}, ACL_FLOAT, ACL_FORMAT_ND, {1, 5}, 0, {4, 5}).ValueRange(-2, 2); | ||
| 198 | + auto out_tensor_desc = TensorDesc({5, 4}, ACL_FLOAT, ACL_FORMAT_ND).Precision(0.0001, 0.0001); | ||
| 199 | + | ||
| 200 | + auto ut = OP_API_UT(aclnnDiv, INPUT(self_tensor_desc, other_tensor_desc), OUTPUT(out_tensor_desc)); | ||
| 201 | + uint64_t workspace_size = 0; | ||
| 202 | + aclnnStatus aclRet = ut.TestGetWorkspaceSize(&workspace_size); | ||
| 203 | + EXPECT_EQ(aclRet, ACL_SUCCESS); | ||
| 204 | +} | ||
| 205 | + | ||
| 206 | +TEST_F(l2_div_test, case_NonContiguous_self_only) | ||
| 207 | +{ | ||
| 208 | + auto self_tensor_desc = TensorDesc({5, 4}, ACL_FLOAT, ACL_FORMAT_ND, {1, 5}, 0, {4, 5}).ValueRange(-2, 2); | ||
| 209 | + auto other_tensor_desc = TensorDesc({5, 4}, ACL_FLOAT, ACL_FORMAT_ND).ValueRange(-2, 2); | ||
| 210 | + auto out_tensor_desc = TensorDesc({5, 4}, ACL_FLOAT, ACL_FORMAT_ND).Precision(0.0001, 0.0001); | ||
| 211 | + | ||
| 212 | + auto ut = OP_API_UT(aclnnDiv, INPUT(self_tensor_desc, other_tensor_desc), OUTPUT(out_tensor_desc)); | ||
| 213 | + uint64_t workspace_size = 0; | ||
| 214 | + aclnnStatus aclRet = ut.TestGetWorkspaceSize(&workspace_size); | ||
| 215 | + EXPECT_EQ(aclRet, ACL_SUCCESS); | ||
| 216 | +} | ||
| 217 | + | ||
| 194 | // 测试不支持类型CheckDtypeValid | 218 | // 测试不支持类型CheckDtypeValid |
| 195 | TEST_F(l2_div_test, case_CheckDtypeValid) | 219 | TEST_F(l2_div_test, case_CheckDtypeValid) |
| 196 | { | 220 | { |
| @@ -73,7 +73,8 @@ ge::graphStatus FloorModTiling::DoOpTiling() | |||
| 73 | // 获取fmod额外空间和存活节点 | 73 | // 获取fmod额外空间和存活节点 |
| 74 | uint32_t maxLiveNodeCnt = 0; | 74 | uint32_t maxLiveNodeCnt = 0; |
| 75 | uint32_t extraBuf = 0; | 75 | uint32_t extraBuf = 0; |
| 76 | - AscendC::GetFmodTmpBufferFactorSize(sizeof(input0Dtype), maxLiveNodeCnt, extraBuf); | 76 | + // kernel中所有输入类型均cast到float32后进入高阶API计算,因此临时buffer按float大小计算 |
| 77 | + AscendC::GetFmodTmpBufferFactorSize(sizeof(float), maxLiveNodeCnt, extraBuf); | ||
| 77 | 78 | ||
| 78 | ge::graphStatus ret = ge::GRAPH_SUCCESS; | 79 | ge::graphStatus ret = ge::GRAPH_SUCCESS; |
| 79 | if (input0Dtype == ge::DT_FLOAT16 || input0Dtype == ge::DT_BF16) { | 80 | if (input0Dtype == ge::DT_FLOAT16 || input0Dtype == ge::DT_BF16) { |
| @@ -54,3 +54,39 @@ TEST_F(FloorModTiling, floor_mod_test_0) | |||
| 54 | std::vector<size_t> expectWorkspaces = {16777216}; | 54 | std::vector<size_t> expectWorkspaces = {16777216}; |
| 55 | ExecuteTestCase(tilingContextPara, ge::GRAPH_SUCCESS, expectTilingKey, expectTilingData, expectWorkspaces); | 55 | ExecuteTestCase(tilingContextPara, ge::GRAPH_SUCCESS, expectTilingKey, expectTilingData, expectWorkspaces); |
| 56 | } | 56 | } |
| 57 | + | ||
| 58 | +TEST_F(FloorModTiling, floor_mod_test_float16) | ||
| 59 | +{ | ||
| 60 | + optiling::FloorModCompileInfo compileInfo = {64, 245760}; | ||
| 61 | + gert::TilingContextPara tilingContextPara( | ||
| 62 | + "FloorMod", | ||
| 63 | + { | ||
| 64 | + {{{1, 32, 4, 32}, {1, 32, 4, 32}}, ge::DT_FLOAT16, ge::FORMAT_ND}, | ||
| 65 | + {{{1, 32, 4, 32}, {1, 32, 4, 32}}, ge::DT_FLOAT16, ge::FORMAT_ND}, | ||
| 66 | + }, | ||
| 67 | + { | ||
| 68 | + {{{1, 32, 4, 32}, {1, 32, 4, 32}}, ge::DT_FLOAT16, ge::FORMAT_ND}, | ||
| 69 | + }, | ||
| 70 | + &compileInfo); | ||
| 71 | + TilingInfo tilingInfo; | ||
| 72 | + bool success = ExecuteTiling(tilingContextPara, tilingInfo); | ||
| 73 | + EXPECT_TRUE(success); | ||
| 74 | +} | ||
| 75 | + | ||
| 76 | +TEST_F(FloorModTiling, floor_mod_test_int64) | ||
| 77 | +{ | ||
| 78 | + optiling::FloorModCompileInfo compileInfo = {64, 245760}; | ||
| 79 | + gert::TilingContextPara tilingContextPara( | ||
| 80 | + "FloorMod", | ||
| 81 | + { | ||
| 82 | + {{{1, 64, 2, 64}, {1, 64, 2, 64}}, ge::DT_INT64, ge::FORMAT_ND}, | ||
| 83 | + {{{1, 64, 2, 64}, {1, 64, 2, 64}}, ge::DT_INT64, ge::FORMAT_ND}, | ||
| 84 | + }, | ||
| 85 | + { | ||
| 86 | + {{{1, 64, 2, 64}, {1, 64, 2, 64}}, ge::DT_INT64, ge::FORMAT_ND}, | ||
| 87 | + }, | ||
| 88 | + &compileInfo); | ||
| 89 | + TilingInfo tilingInfo; | ||
| 90 | + bool success = ExecuteTiling(tilingContextPara, tilingInfo); | ||
| 91 | + EXPECT_TRUE(success); | ||
| 92 | +} | ||
| @@ -77,7 +77,8 @@ ge::graphStatus ModTiling::DoOpTiling() | |||
| 77 | // 获取fmod额外空间和存活节点 | 77 | // 获取fmod额外空间和存活节点 |
| 78 | uint32_t maxLiveNodeCnt = 0; | 78 | uint32_t maxLiveNodeCnt = 0; |
| 79 | uint32_t extraBuf = 0; | 79 | uint32_t extraBuf = 0; |
| 80 | - AscendC::GetFmodTmpBufferFactorSize(sizeof(input0Dtype), maxLiveNodeCnt, extraBuf); | 80 | + // kernel中所有输入类型均cast到float32后进入高阶API计算,因此临时buffer按float大小计算 |
| 81 | + AscendC::GetFmodTmpBufferFactorSize(sizeof(float), maxLiveNodeCnt, extraBuf); | ||
| 81 | 82 | ||
| 82 | ge::graphStatus ret = ge::GRAPH_SUCCESS; | 83 | ge::graphStatus ret = ge::GRAPH_SUCCESS; |
| 83 | if (input0Dtype == ge::DT_FLOAT16 || input0Dtype == ge::DT_BF16) { | 84 | if (input0Dtype == ge::DT_FLOAT16 || input0Dtype == ge::DT_BF16) { |
| @@ -260,4 +260,23 @@ TEST_F(ModTilingTest, test_tiling_int64) | |||
| 260 | string expectTilingData = "8192 137438953600 "; | 260 | string expectTilingData = "8192 137438953600 "; |
| 261 | std::vector<size_t> expectWorkspaces = {16777216}; | 261 | std::vector<size_t> expectWorkspaces = {16777216}; |
| 262 | ExecuteTestCase(tilingContextPara, ge::GRAPH_SUCCESS, expectTilingKey, expectTilingData, expectWorkspaces); | 262 | ExecuteTestCase(tilingContextPara, ge::GRAPH_SUCCESS, expectTilingKey, expectTilingData, expectWorkspaces); |
| 263 | +} | ||
| 264 | + | ||
| 265 | +TEST_F(ModTilingTest, test_tiling_bf16) | ||
| 266 | +{ | ||
| 267 | + BroadcastCompileInfo compileInfo{}; | ||
| 268 | + gert::TilingContextPara tilingContextPara( | ||
| 269 | + "Mod", | ||
| 270 | + { | ||
| 271 | + {{{1, 32, 4, 32}, {1, 32, 4, 32}}, ge::DT_BF16, ge::FORMAT_ND}, | ||
| 272 | + {{{1, 32, 4, 32}, {1, 32, 4, 32}}, ge::DT_BF16, ge::FORMAT_ND}, | ||
| 273 | + }, | ||
| 274 | + { | ||
| 275 | + {{{1, 32, 4, 32}, {1, 32, 4, 32}}, ge::DT_BF16, ge::FORMAT_ND}, | ||
| 276 | + }, | ||
| 277 | + &compileInfo); | ||
| 278 | + | ||
| 279 | + TilingInfo tilingInfo; | ||
| 280 | + bool success = ExecuteTiling(tilingContextPara, tilingInfo); | ||
| 281 | + EXPECT_TRUE(success); | ||
| 263 | } | 282 | } |
| @@ -53,9 +53,12 @@ static const aclTensor *PowAiCore(const aclTensor *self, const aclTensor *expone | |||
| 53 | aclTensor *powOut, aclOpExecutor *executor) { | 53 | aclTensor *powOut, aclOpExecutor *executor) { |
| 54 | L0_DFX(PowAiCore, self, exponent, powOut); | 54 | L0_DFX(PowAiCore, self, exponent, powOut); |
| 55 | 55 | ||
| 56 | - ADD_TO_LAUNCHER_LIST_AICORE(Pow, | 56 | + auto ret = ADD_TO_LAUNCHER_LIST_AICORE(Pow, |
| 57 | OP_INPUT(self, exponent), | 57 | OP_INPUT(self, exponent), |
| 58 | OP_OUTPUT(powOut)); | 58 | OP_OUTPUT(powOut)); |
| 59 | + OP_CHECK( | ||
| 60 | + ret == ACL_SUCCESS, OP_LOGE(ACLNN_ERR_INNER_NULLPTR, "PowAiCore ADD_TO_LAUNCHER_LIST_AICORE failed."), | ||
| 61 | + return nullptr); | ||
| 59 | return powOut; | 62 | return powOut; |
| 60 | } | 63 | } |
| 61 | 64 | ||


math/addcdiv/op_host/arch35/addcdiv_tiling_arch35.cppOP_LOGD("AddcdivTiling", "Enter TilingForAddcdiv"); if (context == nullptr) { OP_LOGE("AddcdivTiling", "Tiling context is nullptr"); return ge::GRAPH_FAILED; } auto nodeName = context->GetNodeName();此评论由代码审查工具自动生成