已合并
fix(pow/sub): A2/A3补充out dtype白名单校验(#3964) #6800
baijinxiang_hw创建于 10 天前
fix(pow/sub): A2/A3补充out dtype白名单校验(#3964) #6800
已合并
共 7 个文件变更+172-2
| @@ -49,6 +49,13 @@ static const std::initializer_list<op::DataType> DTYPE_SUPPORT_LIST = { | |||
| 49 | op::DataType::DT_INT8, op::DataType::DT_UINT8, op::DataType::DT_DOUBLE, op::DataType::DT_BOOL, | 49 | op::DataType::DT_INT8, op::DataType::DT_UINT8, op::DataType::DT_DOUBLE, op::DataType::DT_BOOL, |
| 50 | op::DataType::DT_INT16, op::DataType::DT_COMPLEX64, op::DataType::DT_COMPLEX128, op::DataType::DT_BF16}; | 50 | op::DataType::DT_INT16, op::DataType::DT_COMPLEX64, op::DataType::DT_COMPLEX128, op::DataType::DT_BF16}; |
| 51 | 51 | ||
| 52 | +// out的数据类型支持列表(比输入列表多UINT16/UINT32/UINT64,与API资料一致) | ||
| 53 | +static const std::initializer_list<op::DataType> OUT_DTYPE_SUPPORT_LIST = { | ||
| 54 | + op::DataType::DT_FLOAT, op::DataType::DT_INT32, op::DataType::DT_INT64, op::DataType::DT_FLOAT16, | ||
| 55 | + op::DataType::DT_INT8, op::DataType::DT_UINT8, op::DataType::DT_DOUBLE, op::DataType::DT_INT16, | ||
| 56 | + op::DataType::DT_COMPLEX64, op::DataType::DT_COMPLEX128, op::DataType::DT_BF16, op::DataType::DT_UINT16, | ||
| 57 | + op::DataType::DT_UINT32, op::DataType::DT_UINT64}; | ||
| 58 | + | ||
| 52 | static const std::initializer_list<op::DataType> SQUARE_NEED_CAST_DTYPE_LIST = { | 59 | static const std::initializer_list<op::DataType> SQUARE_NEED_CAST_DTYPE_LIST = { |
| 53 | op::DataType::DT_INT8, op::DataType::DT_UINT8, op::DataType::DT_BOOL, op::DataType::DT_INT16}; | 60 | op::DataType::DT_INT8, op::DataType::DT_UINT8, op::DataType::DT_BOOL, op::DataType::DT_INT16}; |
| 54 | 61 | ||
| @@ -184,6 +191,11 @@ static bool CheckDtypeValid(const op::DataType selfDtype, const op::DataType exp | |||
| 184 | op::ToString(selfDtype).GetString(), op::ToString(expDtype).GetString()); | 191 | op::ToString(selfDtype).GetString(), op::ToString(expDtype).GetString()); |
| 185 | return false; | 192 | return false; |
| 186 | } | 193 | } |
| 194 | + if (GetCurrentPlatformInfo().GetCurNpuArch() == NpuArch::DAV_2201 && !CheckType(outDtype, OUT_DTYPE_SUPPORT_LIST)) { | ||
| 195 | + OP_LOGE(ACLNN_ERR_PARAM_INVALID, "out dtype %s should be in out dtype support list %s.", | ||
| 196 | + op::ToString(outDtype).GetString(), op::ToString(OUT_DTYPE_SUPPORT_LIST).GetString()); | ||
| 197 | + return false; | ||
| 198 | + } | ||
| 187 | OP_CHECK_RESULT_DTYPE_CAST_FAILED(promoteType, outDtype, return false); | 199 | OP_CHECK_RESULT_DTYPE_CAST_FAILED(promoteType, outDtype, return false); |
| 188 | return true; | 200 | return true; |
| 189 | } | 201 | } |
| @@ -54,6 +54,13 @@ static const std::initializer_list<op::DataType> DTYPE_SUPPORT_LIST = { | |||
| 54 | op::DataType::DT_INT8, op::DataType::DT_UINT8, op::DataType::DT_DOUBLE, op::DataType::DT_BOOL, | 54 | op::DataType::DT_INT8, op::DataType::DT_UINT8, op::DataType::DT_DOUBLE, op::DataType::DT_BOOL, |
| 55 | op::DataType::DT_COMPLEX64, op::DataType::DT_COMPLEX128, op::DataType::DT_INT16, op::DataType::DT_BF16}; | 55 | op::DataType::DT_COMPLEX64, op::DataType::DT_COMPLEX128, op::DataType::DT_INT16, op::DataType::DT_BF16}; |
| 56 | 56 | ||
| 57 | +// out的数据类型支持列表(比输入列表多UINT16/UINT32/UINT64,与API资料一致) | ||
| 58 | +static const std::initializer_list<op::DataType> OUT_DTYPE_SUPPORT_LIST = { | ||
| 59 | + op::DataType::DT_FLOAT, op::DataType::DT_INT32, op::DataType::DT_INT64, op::DataType::DT_FLOAT16, | ||
| 60 | + op::DataType::DT_INT8, op::DataType::DT_UINT8, op::DataType::DT_DOUBLE, op::DataType::DT_INT16, | ||
| 61 | + op::DataType::DT_COMPLEX64, op::DataType::DT_COMPLEX128, op::DataType::DT_BF16, op::DataType::DT_UINT16, | ||
| 62 | + op::DataType::DT_UINT32, op::DataType::DT_UINT64}; | ||
| 63 | + | ||
| 57 | static bool CheckNotNull(const aclTensor* self, const aclTensor* exponent, const aclTensor* out) | 64 | static bool CheckNotNull(const aclTensor* self, const aclTensor* exponent, const aclTensor* out) |
| 58 | { | 65 | { |
| 59 | OP_CHECK_NULL(self, return false); | 66 | OP_CHECK_NULL(self, return false); |
| @@ -132,6 +139,12 @@ static aclnnStatus CheckParams(const aclTensor* self, const aclTensor* exponent, | |||
| 132 | 139 | ||
| 133 | // 2. 检查输入的数据类型是否在API支持的数据类型范围之内,需要根据api定义校验 | 140 | // 2. 检查输入的数据类型是否在API支持的数据类型范围之内,需要根据api定义校验 |
| 134 | CHECK_RET(CheckDtypeValid(self, exponent), ACLNN_ERR_PARAM_INVALID); | 141 | CHECK_RET(CheckDtypeValid(self, exponent), ACLNN_ERR_PARAM_INVALID); |
| 142 | + if (GetCurrentPlatformInfo().GetCurNpuArch() == NpuArch::DAV_2201 && | ||
| 143 | + !CheckType(out->GetDataType(), OUT_DTYPE_SUPPORT_LIST)) { | ||
| 144 | + OP_LOGE(ACLNN_ERR_PARAM_INVALID, "out dtype %s should be in out dtype support list %s.", | ||
| 145 | + op::ToString(out->GetDataType()).GetString(), op::ToString(OUT_DTYPE_SUPPORT_LIST).GetString()); | ||
| 146 | + return ACLNN_ERR_PARAM_INVALID; | ||
| 147 | + } | ||
| 135 | 148 | ||
| 136 | // 3. 检查self和exponent能否做数据类型推导以及推导的数据类型能否转换为输出数据类型 | 149 | // 3. 检查self和exponent能否做数据类型推导以及推导的数据类型能否转换为输出数据类型 |
| 137 | CHECK_RET(CheckPromoteType(self, exponent, out), ACLNN_ERR_PARAM_INVALID); | 150 | CHECK_RET(CheckPromoteType(self, exponent, out), ACLNN_ERR_PARAM_INVALID); |
| @@ -16,6 +16,7 @@ | |||
| 16 | #include "op_api_ut_common/op_api_ut.h" | 16 | #include "op_api_ut_common/op_api_ut.h" |
| 17 | #include "op_api_ut_common/scalar_desc.h" | 17 | #include "op_api_ut_common/scalar_desc.h" |
| 18 | #include "op_api_ut_common/tensor_desc.h" | 18 | #include "op_api_ut_common/tensor_desc.h" |
| 19 | +#include "opdev/platform.h" | ||
| 19 | 20 | ||
| 20 | using namespace std; | 21 | using namespace std; |
| 21 | 22 | ||
| @@ -445,3 +446,49 @@ TEST_F(l2_pow_scalar_tensor_test, Ascend950PR_89_aclnnPowScalarTensor_scalar_flo | |||
| 445 | EXPECT_EQ(aclRet, ACL_SUCCESS); | 446 | EXPECT_EQ(aclRet, ACL_SUCCESS); |
| 446 | } | 447 | } |
| 447 | */ | 448 | */ |
| 449 | + | ||
| 450 | +TEST_F(l2_pow_scalar_tensor_test, aclnnPowScalarTensor_out_dtype_not_in_support_list) | ||
| 451 | +{ | ||
| 452 | + auto expTensorDesc = TensorDesc({4, 8}, ACL_FLOAT, ACL_FORMAT_ND).ValueRange(0, 2); | ||
| 453 | + auto selfScalarDesc = ScalarDesc(2); | ||
| 454 | + // INT4不在out支持列表中,校验报错 | ||
| 455 | + { | ||
| 456 | + auto outTensorDesc = TensorDesc({4, 8}, ACL_INT4, ACL_FORMAT_ND); | ||
| 457 | + auto ut = OP_API_UT(aclnnPowScalarTensor, INPUT(selfScalarDesc, expTensorDesc), OUTPUT(outTensorDesc)); | ||
| 458 | + uint64_t workspaceSize = 0; | ||
| 459 | + EXPECT_EQ(ut.TestGetWorkspaceSize(&workspaceSize), ACLNN_ERR_PARAM_INVALID); | ||
| 460 | + } | ||
| 461 | + // BOOL不在out支持列表中,校验报错 | ||
| 462 | + { | ||
| 463 | + auto outTensorDesc = TensorDesc({4, 8}, ACL_BOOL, ACL_FORMAT_ND); | ||
| 464 | + auto ut = OP_API_UT(aclnnPowScalarTensor, INPUT(selfScalarDesc, expTensorDesc), OUTPUT(outTensorDesc)); | ||
| 465 | + uint64_t workspaceSize = 0; | ||
| 466 | + EXPECT_EQ(ut.TestGetWorkspaceSize(&workspaceSize), ACLNN_ERR_PARAM_INVALID); | ||
| 467 | + } | ||
| 468 | + // 列表内dtype(UINT16)但推导类型不可转换,仍返回161002 | ||
| 469 | + { | ||
| 470 | + auto outTensorDesc = TensorDesc({4, 8}, ACL_UINT16, ACL_FORMAT_ND); | ||
| 471 | + auto ut = OP_API_UT(aclnnPowScalarTensor, INPUT(selfScalarDesc, expTensorDesc), OUTPUT(outTensorDesc)); | ||
| 472 | + uint64_t workspaceSize = 0; | ||
| 473 | + EXPECT_EQ(ut.TestGetWorkspaceSize(&workspaceSize), ACLNN_ERR_PARAM_INVALID); | ||
| 474 | + } | ||
| 475 | + // 合法out dtype | ||
| 476 | + { | ||
| 477 | + auto outTensorDesc = TensorDesc({4, 8}, ACL_FLOAT, ACL_FORMAT_ND).Precision(0.0001, 0.0001); | ||
| 478 | + auto ut = OP_API_UT(aclnnPowScalarTensor, INPUT(selfScalarDesc, expTensorDesc), OUTPUT(outTensorDesc)); | ||
| 479 | + uint64_t workspaceSize = 0; | ||
| 480 | + EXPECT_EQ(ut.TestGetWorkspaceSize(&workspaceSize), ACL_SUCCESS); | ||
| 481 | + } | ||
| 482 | +} | ||
| 483 | + | ||
| 484 | +TEST_F(l2_pow_scalar_tensor_test, Ascend950_out_dtype_check_not_applied) | ||
| 485 | +{ | ||
| 486 | + op::SetPlatformSocVersion(op::SocVersion::ASCEND950); | ||
| 487 | + auto expTensorDesc = TensorDesc({4, 8}, ACL_FLOAT, ACL_FORMAT_ND).ValueRange(0, 2); | ||
| 488 | + auto selfScalarDesc = ScalarDesc(2); | ||
| 489 | + auto outTensorDesc = TensorDesc({4, 8}, ACL_INT4, ACL_FORMAT_ND); | ||
| 490 | + auto ut = OP_API_UT(aclnnPowScalarTensor, INPUT(selfScalarDesc, expTensorDesc), OUTPUT(outTensorDesc)); | ||
| 491 | + uint64_t workspaceSize = 0; | ||
| 492 | + EXPECT_NE(ut.TestGetWorkspaceSize(&workspaceSize), ACLNN_ERR_PARAM_INVALID); | ||
| 493 | + op::SetPlatformSocVersion(op::SocVersion::ASCEND910B); | ||
| 494 | +} | ||
| @@ -252,7 +252,7 @@ TEST_F(l2_pow_tensor_scalar_test, aclnnPowTensorScalar_1_1_16_129_in64_hwcn_1_1_ | |||
| 252 | 252 | ||
| 253 | TEST_F(l2_pow_tensor_scalar_test, Ascend950_aclnnPowTensorScalar_square_complex64) | 253 | TEST_F(l2_pow_tensor_scalar_test, Ascend950_aclnnPowTensorScalar_square_complex64) |
| 254 | { | 254 | { |
| 255 | - op::SetPlatformNpuArch(NpuArch::DAV_3510); | 255 | + op::SetPlatformSocVersion(op::SocVersion::ASCEND950); |
| 256 | 256 | ||
| 257 | const vector<int64_t>& selfShape = {1, 1, 16, 129}; | 257 | const vector<int64_t>& selfShape = {1, 1, 16, 129}; |
| 258 | aclDataType selfDtype = ACL_COMPLEX64; | 258 | aclDataType selfDtype = ACL_COMPLEX64; |
| @@ -269,7 +269,7 @@ TEST_F(l2_pow_tensor_scalar_test, Ascend950_aclnnPowTensorScalar_square_complex6 | |||
| 269 | auto ut = OP_API_UT(aclnnPowTensorScalar, INPUT(selfTensorDesc, expScalarDesc), OUTPUT(outTensorDesc)); | 269 | auto ut = OP_API_UT(aclnnPowTensorScalar, INPUT(selfTensorDesc, expScalarDesc), OUTPUT(outTensorDesc)); |
| 270 | uint64_t workspaceSize = 0; | 270 | uint64_t workspaceSize = 0; |
| 271 | aclnnStatus aclRet = ut.TestGetWorkspaceSize(&workspaceSize); | 271 | aclnnStatus aclRet = ut.TestGetWorkspaceSize(&workspaceSize); |
| 272 | - op::SetPlatformNpuArch(NpuArch::DAV_2201); | 272 | + op::SetPlatformSocVersion(op::SocVersion::ASCEND910B); |
| 273 | EXPECT_EQ(aclRet, ACL_SUCCESS); | 273 | EXPECT_EQ(aclRet, ACL_SUCCESS); |
| 274 | } | 274 | } |
| 275 | 275 | ||
| @@ -295,6 +295,18 @@ TEST_F(l2_pow_tensor_scalar_test, Ascend950_aclnnPowTensorScalar_square_complex1 | |||
| 295 | op::SetPlatformNpuArch(NpuArch::DAV_2201); | 295 | op::SetPlatformNpuArch(NpuArch::DAV_2201); |
| 296 | EXPECT_EQ(aclRet, ACL_SUCCESS); | 296 | EXPECT_EQ(aclRet, ACL_SUCCESS); |
| 297 | } | 297 | } |
| 298 | + | ||
| 299 | +TEST_F(l2_pow_tensor_scalar_test, Ascend950_out_dtype_check_not_applied) | ||
| 300 | +{ | ||
| 301 | + op::SetPlatformNpuArch(NpuArch::DAV_3510); | ||
| 302 | + auto selfTensorDesc = TensorDesc({4, 8}, ACL_FLOAT, ACL_FORMAT_ND); | ||
| 303 | + auto expScalarDesc = ScalarDesc(2); | ||
| 304 | + auto outTensorDesc = TensorDesc({4, 8}, ACL_INT4, ACL_FORMAT_ND); | ||
| 305 | + auto ut = OP_API_UT(aclnnPowTensorScalar, INPUT(selfTensorDesc, expScalarDesc), OUTPUT(outTensorDesc)); | ||
| 306 | + uint64_t workspaceSize = 0; | ||
| 307 | + EXPECT_NE(ut.TestGetWorkspaceSize(&workspaceSize), ACLNN_ERR_PARAM_INVALID); | ||
| 308 | + op::SetPlatformNpuArch(NpuArch::DAV_2201); | ||
| 309 | +} | ||
| 298 | /* | 310 | /* |
| 299 | TEST_F(l2_pow_tensor_scalar_test, aclnnPowTensorScalar_1_1_16_129_complex64_hwcn_1_1_16_129_complex64_hwcn) { | 311 | TEST_F(l2_pow_tensor_scalar_test, aclnnPowTensorScalar_1_1_16_129_complex64_hwcn_1_1_16_129_complex64_hwcn) { |
| 300 | // input | 312 | // input |
| @@ -16,6 +16,7 @@ | |||
| 16 | #include "op_api_ut_common/op_api_ut.h" | 16 | #include "op_api_ut_common/op_api_ut.h" |
| 17 | #include "op_api_ut_common/scalar_desc.h" | 17 | #include "op_api_ut_common/scalar_desc.h" |
| 18 | #include "op_api_ut_common/tensor_desc.h" | 18 | #include "op_api_ut_common/tensor_desc.h" |
| 19 | +#include "opdev/platform.h" | ||
| 19 | 20 | ||
| 20 | using namespace std; | 21 | using namespace std; |
| 21 | 22 | ||
| @@ -630,3 +631,15 @@ TEST_F(l2_pow_tensor_tensor_test, aclnnPowTensorTensor_2_7_bool_nd_2_7_bool_nd) | |||
| 630 | aclnnStatus aclRet = ut.TestGetWorkspaceSize(&workspaceSize); | 631 | aclnnStatus aclRet = ut.TestGetWorkspaceSize(&workspaceSize); |
| 631 | EXPECT_EQ(aclRet, ACLNN_ERR_PARAM_INVALID); | 632 | EXPECT_EQ(aclRet, ACLNN_ERR_PARAM_INVALID); |
| 632 | } | 633 | } |
| 634 | + | ||
| 635 | +TEST_F(l2_pow_tensor_tensor_test, Ascend950_out_dtype_check_not_applied) | ||
| 636 | +{ | ||
| 637 | + op::SetPlatformSocVersion(op::SocVersion::ASCEND950); | ||
| 638 | + auto selfTensorDesc = TensorDesc({4, 8}, ACL_FLOAT, ACL_FORMAT_ND); | ||
| 639 | + auto otherTensorDesc = TensorDesc({4, 8}, ACL_FLOAT, ACL_FORMAT_ND); | ||
| 640 | + auto outTensorDesc = TensorDesc({4, 8}, ACL_INT4, ACL_FORMAT_ND); | ||
| 641 | + auto ut = OP_API_UT(aclnnPowTensorTensor, INPUT(selfTensorDesc, otherTensorDesc), OUTPUT(outTensorDesc)); | ||
| 642 | + uint64_t workspaceSize = 0; | ||
| 643 | + EXPECT_NE(ut.TestGetWorkspaceSize(&workspaceSize), ACLNN_ERR_PARAM_INVALID); | ||
| 644 | + op::SetPlatformSocVersion(op::SocVersion::ASCEND910B); | ||
| 645 | +} | ||
| @@ -247,6 +247,9 @@ static aclnnStatus CheckParams(const aclTensor* self, const aclTensor* other, co | |||
| 247 | const std::initializer_list<op::DataType> dtypeSupportList = GetDtypeSupportListBySocVersion(); | 247 | const std::initializer_list<op::DataType> dtypeSupportList = GetDtypeSupportListBySocVersion(); |
| 248 | OP_CHECK_DTYPE_NOT_SUPPORT(self, dtypeSupportList, return ACLNN_ERR_PARAM_INVALID); | 248 | OP_CHECK_DTYPE_NOT_SUPPORT(self, dtypeSupportList, return ACLNN_ERR_PARAM_INVALID); |
| 249 | OP_CHECK_DTYPE_NOT_SUPPORT(other, dtypeSupportList, return ACLNN_ERR_PARAM_INVALID); | 249 | OP_CHECK_DTYPE_NOT_SUPPORT(other, dtypeSupportList, return ACLNN_ERR_PARAM_INVALID); |
| 250 | + if (GetCurrentPlatformInfo().GetCurNpuArch() == NpuArch::DAV_2201) { | ||
| 251 | + OP_CHECK_DTYPE_NOT_SUPPORT(out, dtypeSupportList, return ACLNN_ERR_PARAM_INVALID); | ||
| 252 | + } | ||
| 250 | 253 | ||
| 251 | // 3. 检查self和other能否做数据类型推导以及推导的数据类型能否转换为输出数据类型 | 254 | // 3. 检查self和other能否做数据类型推导以及推导的数据类型能否转换为输出数据类型 |
| 252 | op::DataType promoteType = op::PromoteType(self->GetDataType(), other->GetDataType()); | 255 | op::DataType promoteType = op::PromoteType(self->GetDataType(), other->GetDataType()); |
| @@ -432,6 +435,9 @@ static aclnnStatus CheckParamsScalar(const aclTensor* self, const aclScalar* oth | |||
| 432 | // 2. 检查输入的数据类型是否在API支持的数据类型范围之内,需要根据api定义校验 | 435 | // 2. 检查输入的数据类型是否在API支持的数据类型范围之内,需要根据api定义校验 |
| 433 | const std::initializer_list<op::DataType> dtypeSupportList = GetDtypeSupportListBySocVersion(); | 436 | const std::initializer_list<op::DataType> dtypeSupportList = GetDtypeSupportListBySocVersion(); |
| 434 | OP_CHECK_DTYPE_NOT_SUPPORT(self, dtypeSupportList, return ACLNN_ERR_PARAM_INVALID); | 437 | OP_CHECK_DTYPE_NOT_SUPPORT(self, dtypeSupportList, return ACLNN_ERR_PARAM_INVALID); |
| 438 | + if (GetCurrentPlatformInfo().GetCurNpuArch() == NpuArch::DAV_2201) { | ||
| 439 | + OP_CHECK_DTYPE_NOT_SUPPORT(out, dtypeSupportList, return ACLNN_ERR_PARAM_INVALID); | ||
| 440 | + } | ||
| 435 | 441 | ||
| 436 | // 3. 检查self和other能否做数据类型推导以及推导的数据类型能否转换为输出数据类型 | 442 | // 3. 检查self和other能否做数据类型推导以及推导的数据类型能否转换为输出数据类型 |
| 437 | auto promoteType = PromoteTypeScalar(self, other, alpha, out); | 443 | auto promoteType = PromoteTypeScalar(self, other, alpha, out); |
| @@ -15,6 +15,7 @@ | |||
| 15 | #include "op_api_ut_common/tensor_desc.h" | 15 | #include "op_api_ut_common/tensor_desc.h" |
| 16 | #include "op_api_ut_common/scalar_desc.h" | 16 | #include "op_api_ut_common/scalar_desc.h" |
| 17 | #include "op_api_ut_common/op_api_ut.h" | 17 | #include "op_api_ut_common/op_api_ut.h" |
| 18 | +#include "opdev/platform.h" | ||
| 18 | 19 | ||
| 19 | class l2_sub_test : public testing::Test { | 20 | class l2_sub_test : public testing::Test { |
| 20 | protected: | 21 | protected: |
| @@ -529,3 +530,69 @@ TEST_F(l2_sub_test, Ascend950PR_89_case_005) | |||
| 529 | // SAMPLE: precision simulate | 530 | // SAMPLE: precision simulate |
| 530 | // ut.TestPrecision(); | 531 | // ut.TestPrecision(); |
| 531 | } | 532 | } |
| 533 | + | ||
| 534 | +TEST_F(l2_sub_test, abnormal_out_dtype_not_in_support_list) | ||
| 535 | +{ | ||
| 536 | + // INT4不在out支持列表中,校验报错 | ||
| 537 | + { | ||
| 538 | + auto selfDesc = TensorDesc({10, 5}, ACL_FLOAT, ACL_FORMAT_ND); | ||
| 539 | + auto otherDesc = ScalarDesc(1.0f); | ||
| 540 | + auto scalarDesc = ScalarDesc(1.0f); | ||
| 541 | + auto outDesc = TensorDesc({10, 5}, ACL_INT4, ACL_FORMAT_ND); | ||
| 542 | + auto ut = OP_API_UT(aclnnSubs, INPUT(selfDesc, otherDesc, scalarDesc), OUTPUT(outDesc)); | ||
| 543 | + uint64_t workspaceSize = 0; | ||
| 544 | + EXPECT_EQ(ut.TestGetWorkspaceSize(&workspaceSize), ACLNN_ERR_PARAM_INVALID); | ||
| 545 | + } | ||
| 546 | + // 合法out dtype不受影响 | ||
| 547 | + { | ||
| 548 | + auto selfDesc = TensorDesc({10, 5}, ACL_FLOAT, ACL_FORMAT_ND); | ||
| 549 | + auto otherDesc = ScalarDesc(1.0f); | ||
| 550 | + auto scalarDesc = ScalarDesc(1.0f); | ||
| 551 | + auto outDesc = TensorDesc({10, 5}, ACL_FLOAT, ACL_FORMAT_ND); | ||
| 552 | + auto ut = OP_API_UT(aclnnSubs, INPUT(selfDesc, otherDesc, scalarDesc), OUTPUT(outDesc)); | ||
| 553 | + uint64_t workspaceSize = 0; | ||
| 554 | + EXPECT_EQ(ut.TestGetWorkspaceSize(&workspaceSize), ACL_SUCCESS); | ||
| 555 | + } | ||
| 556 | + // inplace场景out与self同dtype,不受新增校验影响 | ||
| 557 | + { | ||
| 558 | + auto selfDesc = TensorDesc({10, 5}, ACL_FLOAT, ACL_FORMAT_ND); | ||
| 559 | + auto otherDesc = ScalarDesc(1.0f); | ||
| 560 | + auto scalarDesc = ScalarDesc(1.0f); | ||
| 561 | + auto ut = OP_API_UT(aclnnInplaceSubs, INPUT(selfDesc, otherDesc, scalarDesc), OUTPUT()); | ||
| 562 | + uint64_t workspaceSize = 0; | ||
| 563 | + EXPECT_EQ(ut.TestGetWorkspaceSize(&workspaceSize), ACL_SUCCESS); | ||
| 564 | + } | ||
| 565 | + // tensor-tensor入口aclnnSub:INT4不在out支持列表中,校验报错 | ||
| 566 | + { | ||
| 567 | + auto selfDesc = TensorDesc({10, 5}, ACL_FLOAT, ACL_FORMAT_ND); | ||
| 568 | + auto otherDesc = TensorDesc({10, 5}, ACL_FLOAT, ACL_FORMAT_ND); | ||
| 569 | + auto scalarDesc = ScalarDesc(1.0f); | ||
| 570 | + auto outDesc = TensorDesc({10, 5}, ACL_INT4, ACL_FORMAT_ND); | ||
| 571 | + auto ut = OP_API_UT(aclnnSub, INPUT(selfDesc, otherDesc, scalarDesc), OUTPUT(outDesc)); | ||
| 572 | + uint64_t workspaceSize = 0; | ||
| 573 | + EXPECT_EQ(ut.TestGetWorkspaceSize(&workspaceSize), ACLNN_ERR_PARAM_INVALID); | ||
| 574 | + } | ||
| 575 | + // tensor-tensor入口aclnnSub:合法out dtype不受影响 | ||
| 576 | + { | ||
| 577 | + auto selfDesc = TensorDesc({10, 5}, ACL_FLOAT, ACL_FORMAT_ND); | ||
| 578 | + auto otherDesc = TensorDesc({10, 5}, ACL_FLOAT, ACL_FORMAT_ND); | ||
| 579 | + auto scalarDesc = ScalarDesc(1.0f); | ||
| 580 | + auto outDesc = TensorDesc({10, 5}, ACL_FLOAT, ACL_FORMAT_ND); | ||
| 581 | + auto ut = OP_API_UT(aclnnSub, INPUT(selfDesc, otherDesc, scalarDesc), OUTPUT(outDesc)); | ||
| 582 | + uint64_t workspaceSize = 0; | ||
| 583 | + EXPECT_EQ(ut.TestGetWorkspaceSize(&workspaceSize), ACL_SUCCESS); | ||
| 584 | + } | ||
| 585 | +} | ||
| 586 | + | ||
| 587 | +TEST_F(l2_sub_test, Ascend950_out_dtype_check_not_applied) | ||
| 588 | +{ | ||
| 589 | + op::SetPlatformSocVersion(op::SocVersion::ASCEND950); | ||
| 590 | + auto selfDesc = TensorDesc({10, 5}, ACL_FLOAT, ACL_FORMAT_ND); | ||
| 591 | + auto otherDesc = ScalarDesc(1.0f); | ||
| 592 | + auto scalarDesc = ScalarDesc(1.0f); | ||
| 593 | + auto outDesc = TensorDesc({10, 5}, ACL_INT4, ACL_FORMAT_ND); | ||
| 594 | + auto ut = OP_API_UT(aclnnSubs, INPUT(selfDesc, otherDesc, scalarDesc), OUTPUT(outDesc)); | ||
| 595 | + uint64_t workspaceSize = 0; | ||
| 596 | + EXPECT_NE(ut.TestGetWorkspaceSize(&workspaceSize), ACLNN_ERR_PARAM_INVALID); | ||
| 597 | + op::SetPlatformSocVersion(op::SocVersion::ASCEND910B); | ||
| 598 | +} | ||