Merged
fix(operation): Restrict LogicalNot integer dtypes to A5 #5885
bynshardAdd on Sep 3
fix(operation): Restrict LogicalNot integer dtypes to A5 #5885
Merged
Merged frombynshard/pyptofix-LogicalNotintocann/pyptomaster
Total: 4 files changed+23-9
| @@ -39,15 +39,17 @@ logical_not(input: Tensor) -> Tensor | |||
| 39 | - Ascend 950PR/Ascend 950DT:DT_FP32,DT_FP16,DT_BF16,DT_BOOL,DT_INT8,DT_UINT8,DT_INT16,DT_UINT16,DT_INT32,DT_UINT32,DT_INT64。 | 39 | - Ascend 950PR/Ascend 950DT:DT_FP32,DT_FP16,DT_BF16,DT_BOOL,DT_INT8,DT_UINT8,DT_INT16,DT_UINT16,DT_INT32,DT_UINT32,DT_INT64。 |
| 40 | <!-- end id4 --> | 40 | <!-- end id4 --> |
| 41 | <!-- npu="A3" id5 --> | 41 | <!-- npu="A3" id5 --> |
| 42 | - - Atlas A3 训练系列产品/Atlas A3 推理系列产品:DT_FP32,DT_FP16,DT_BF16,DT_BOOL,DT_INT8,DT_UINT8,DT_INT16,DT_UINT16,DT_INT32,DT_UINT32。 | 42 | + - Atlas A3 训练系列产品/Atlas A3 推理系列产品:DT_FP32,DT_FP16,DT_BF16,DT_BOOL,DT_INT8,DT_UINT8。 |
| 43 | <!-- end id5 --> | 43 | <!-- end id5 --> |
| 44 | <!-- npu="910b" id6 --> | 44 | <!-- npu="910b" id6 --> |
| 45 | - - Atlas A2 训练系列产品/Atlas A2 推理系列产品:DT_FP32,DT_FP16,DT_BF16,DT_BOOL,DT_INT8,DT_UINT8,DT_INT16,DT_UINT16,DT_INT32,DT_UINT32。 | 45 | + - Atlas A2 训练系列产品/Atlas A2 推理系列产品:DT_FP32,DT_FP16,DT_BF16,DT_BOOL,DT_INT8,DT_UINT8。 |
| 46 | <!-- end id6 --> | 46 | <!-- end id6 --> |
| 47 | 2. TileShape与input维度保持一致; | 47 | 2. TileShape与input维度保持一致; |
| 48 | -3. 由于存在临时内存使用,当输入数据类型为DT_FP32,TileShape大小有额外约束,假设TileShape为[a,b,c,d],那么a*b*c*d*sizeof(input) + a*b*c*d*sizeof(BOOL) + 20.25KB<UB。其他输入数据类型应该满足,a*b*c*d*sizeof(input) + a*b*c*d*sizeof(BOOL) + 12.54KB<UB | 48 | +3. 由于存在临时内存使用,假设TileShape为$[a,b,c,d]$,记$N=a \cdot b \cdot c \cdot d$。当输入数据类型为DT_FP32时,TileShape大小应满足$N \cdot \text{sizeof}(input) + N \cdot \text{sizeof}(BOOL) + 20.25\text{KB} < \text{UB}$;其他基础支持类型应满足$N \cdot \text{sizeof}(input) + N \cdot \text{sizeof}(BOOL) + 12.54\text{KB} < \text{UB}$。 |
| 49 | -4. 当输入数据类型为DT_INT16、DT_UINT16、DT_INT32、DT_UINT32、DT_INT64(DT_INT64仅Ascend 950PR/Ascend 950DT支持)时,走整数计算路径,临时内存占用与输入数据类型相关:DT_INT16/DT_UINT16需4KB,DT_INT32/DT_UINT32需8KB,DT_INT64需16KB。TileShape大小约束为:a*b*c*d*sizeof(input) + a*b*c*d*sizeof(BOOL) + sizeof(input)*2KB<UB。 | 49 | + <!-- npu="950" id7 --> |
| 50 | -5. Tensor类型输入不支持`TileOpFormat.TILEOP_NZ`格式。 | 50 | + - Ascend 950PR/Ascend 950DT:输入数据类型为DT_INT16、DT_UINT16、DT_INT32、DT_UINT32或DT_INT64时,采用整数计算实现。其中,DT_INT16/DT_UINT16需要4KB临时内存,DT_INT32/DT_UINT32需要8KB临时内存,DT_INT64需要16KB临时内存。上述类型的TileShape大小应满足$N \cdot \text{sizeof}(input) + N \cdot \text{sizeof}(BOOL) + 2048 \cdot \text{sizeof}(input) < \text{UB}$。 |
| 51 | + <!-- end id7 --> | ||
abcdsizeof(input) + abcdsizeof(BOOL) + 20.25KB<UB 预览有问题,建议使用上引号包裹。 走整数计算路径==口语化表达,建议修改 ![]() ![]() | |||
| 52 | +4. Tensor类型输入不支持`TileOpFormat.TILEOP_NZ`格式。 | ||
| 51 | 53 | ||
| 52 | ## 调用示例 | 54 | ## 调用示例 |
| 53 | 55 | ||
| @@ -102,10 +102,10 @@ Tensor LogicalNot(const Tensor& self) | |||
| 102 | DECLARE_TRACER(); | 102 | DECLARE_TRACER(); |
| 103 | CheckTensorFormat(self.GetStorage(), {TileOpFormat::TILEOP_NZ}, "LogicalNot"); | 103 | CheckTensorFormat(self.GetStorage(), {TileOpFormat::TILEOP_NZ}, "LogicalNot"); |
| 104 | 104 | ||
| 105 | - static const std::unordered_set<DataType> LOGICALNOT_A2A3_TYPES = { | 105 | + static const std::unordered_set<DataType> LOGICALNOT_A2A3_TYPES = {DT_FP32, DT_FP16, DT_UINT8, |
| 106 | - DT_FP32, DT_FP16, DT_UINT8, DT_INT8, DT_BOOL, DT_BF16, DT_INT16, DT_INT32, DT_UINT16, DT_UINT32}; | 106 | + DT_INT8, DT_BOOL, DT_BF16}; |
| 107 | static const std::unordered_set<DataType> LOGICALNOT_A5_TYPES = { | 107 | static const std::unordered_set<DataType> LOGICALNOT_A5_TYPES = { |
| 108 | - DT_FP32, DT_FP16, DT_UINT8, DT_INT8, DT_BOOL, DT_BF16, DT_INT16, DT_INT32, DT_UINT16, DT_UINT32, DT_INT64}; | 108 | + DT_FP32, DT_FP16, DT_UINT8, DT_INT8, DT_BOOL, DT_BF16, DT_INT16, DT_UINT16, DT_INT32, DT_UINT32, DT_INT64}; |
| 109 | const auto& supportedTypes = GetSupportedDataTypesByArch(LOGICALNOT_A2A3_TYPES, LOGICALNOT_A5_TYPES); | 109 | const auto& supportedTypes = GetSupportedDataTypesByArch(LOGICALNOT_A2A3_TYPES, LOGICALNOT_A5_TYPES); |
| 110 | CheckTensorDataType(self.GetStorage(), supportedTypes, "LOGICALNOT"); | 110 | CheckTensorDataType(self.GetStorage(), supportedTypes, "LOGICALNOT"); |
| 111 | CheckTensorDimRange(self.GetStorage(), 1, NUM_VALUE_4, "LOGICALNOT"); | 111 | CheckTensorDimRange(self.GetStorage(), 1, NUM_VALUE_4, "LOGICALNOT"); |
| @@ -60,7 +60,7 @@ __tf__ PTO_INTERNAL void TCOLMAX_HIGH_PERF(TileDataOut& dstTile, TileDataIn& src | |||
| 60 | vlds(max_3a, src0_ub, DIM_4TH * F32_ELEMENTS_PER_VECTOR, NORM); | 60 | vlds(max_3a, src0_ub, DIM_4TH * F32_ELEMENTS_PER_VECTOR, NORM); |
| 61 | 61 | ||
| 62 | pto::RegTensor<float> v_row; | 62 | pto::RegTensor<float> v_row; |
| 63 | - for (uint16_t row = ROWS_PER_ITER; row < uint16_t(TileDataIn::Rows); row += ROWS_PER_ITER) { | 63 | + for (uint16_t row = 4; row < uint16_t(TileDataIn::Rows); row += 4) { |
| 64 | vlds(v_row, p0, ITER_STRIDE, NORM, POST_UPDATE); | 64 | vlds(v_row, p0, ITER_STRIDE, NORM, POST_UPDATE); |
| 65 | vmax(max_0a, max_0a, v_row, preg_108, MODE_ZEROING); | 65 | vmax(max_0a, max_0a, v_row, preg_108, MODE_ZEROING); |
| 66 | vlds(v_row, p1, ITER_STRIDE, NORM, POST_UPDATE); | 66 | vlds(v_row, p1, ITER_STRIDE, NORM, POST_UPDATE); |
| @@ -86,10 +86,22 @@ TEST_F(OperationOpsTest, Range_UnsupportedOutputDataType) | |||
| 86 | 86 | ||
| 87 | TEST_F(OperationOpsTest, LogicalNot_UnsupportedDataType) | 87 | TEST_F(OperationOpsTest, LogicalNot_UnsupportedDataType) |
| 88 | { | 88 | { |
| 89 | + Platform::Instance().GetSoc().SetNPUArch(NPUArch::DAV_2201); | ||
| 89 | std::vector<int64_t> shape = {10, 10}; | 90 | std::vector<int64_t> shape = {10, 10}; |
| 90 | Tensor input(DT_INT32, shape); | 91 | Tensor input(DT_INT32, shape); |
| 91 | 92 | ||
| 92 | EXPECT_THROW(LogicalNot(input), std::exception); | 93 | EXPECT_THROW(LogicalNot(input), std::exception); |
| 94 | + Platform::Instance().GetSoc().SetNPUArch(NPUArch::DAV_UNKNOWN); | ||
| 95 | +} | ||
| 96 | + | ||
| 97 | +TEST_F(OperationOpsTest, LogicalNot_A5SupportedDataType) | ||
| 98 | +{ | ||
| 99 | + Platform::Instance().GetSoc().SetNPUArch(NPUArch::DAV_3510); | ||
| 100 | + TileShape::Current().SetVecTile(10, 10); | ||
| 101 | + Tensor input(DT_UINT32, {10, 10}); | ||
| 102 | + | ||
| 103 | + FUNCTION("LogicalNotA5SupportedDataType", {input}) { EXPECT_NO_THROW((void)LogicalNot(input)); } | ||
| 104 | + Platform::Instance().GetSoc().SetNPUArch(NPUArch::DAV_UNKNOWN); | ||
| 93 | } | 105 | } |
| 94 | 106 | ||
| 95 | TEST_F(OperationOpsTest, QuantMX_DefaultRoundDownFp8Output) | 107 | TEST_F(OperationOpsTest, QuantMX_DefaultRoundDownFp8Output) |


删除A5架构的描述,统一写到Ascend 950PR/Ascend 950DT中就可以了