已合并
修复tensor_equal某些场景下判断失效问题 #3910
m0_46386992创建于 7月8日
修复tensor_equal某些场景下判断失效问题 #3910
已合并
m0_46386992创建于 7月8日
2 个文件变更+37-25
Mmath/tensor_equal/op_graph/tensor_equal_proto.h+6-4
@@ -30,18 +30,20 @@ namespace ge {
30* @li input_y: A ND tensor of the same dtype as "input_x". \n30* @li input_y: A ND tensor of the same dtype as "input_x". \n
31 31 
32* @par Outputs:32* @par Outputs:
33-* output_z: A ND tensor. Bool type, compare result of the two inputs. True if element in input_x is equal to input_y, False otherwise. \n33+* output_z: A ND tensor. Bool type, compare result of the two inputs. True if element in input_x is equal to input_y,
34+False otherwise. \n
34 35 
35* @par Third-party framework compatibility36* @par Third-party framework compatibility
36* Compatible with the PyTorch equal operator. \n37* Compatible with the PyTorch equal operator. \n
37*/38*/
38REG_OP(TensorEqual)39REG_OP(TensorEqual)
39- .INPUT(input_x, TensorType({DT_FLOAT16, DT_FLOAT, DT_DOUBLE, DT_INT64, DT_INT32, DT_INT8, DT_UINT8, DT_BOOL, DT_BF16, DT_IN16, DT_UINT16, DT_UINT32, DT_UINT64}))40+ .INPUT(input_x, TensorType({DT_FLOAT16, DT_FLOAT, DT_DOUBLE, DT_INT64, DT_INT32, DT_INT8, DT_UINT8, DT_BOOL,
40- .INPUT(input_y, TensorType({DT_FLOAT16, DT_FLOAT, DT_DOUBLE, DT_INT64, DT_INT32, DT_INT8, DT_UINT8, DT_BOOL, DT_BF16, DT_IN16, DT_UINT16, DT_UINT32, DT_UINT64}))41+ DT_BF16, DT_INT16, DT_UINT16, DT_UINT32, DT_UINT64}))
42+ .INPUT(input_y, TensorType({DT_FLOAT16, DT_FLOAT, DT_DOUBLE, DT_INT64, DT_INT32, DT_INT8, DT_UINT8, DT_BOOL,
43+ DT_BF16, DT_INT16, DT_UINT16, DT_UINT32, DT_UINT64}))
41 .OUTPUT(output_z, TensorType({DT_BOOL}))44 .OUTPUT(output_z, TensorType({DT_BOOL}))
42 .OP_END_FACTORY_REG(TensorEqual)45 .OP_END_FACTORY_REG(TensorEqual)
43 46 
44} // namespace ge47} // namespace ge
45 48 
46#endif // OPS_OP_PROTO_INC_TENSOR_EQUAL_H_49#endif // OPS_OP_PROTO_INC_TENSOR_EQUAL_H_
47- 
Mmath/tensor_equal/op_kernel/arch35/tensor_equal.h+31-21
@@ -31,15 +31,18 @@ constexpr uint8_t DIFF_SHAPE_OUTPUT = 0;
31 31 
32template <typename T>32template <typename T>
33class TensorEqualKernel {33class TensorEqualKernel {
34-using InputType = std::conditional_t<std::is_integral_v<T>, uint8_t, T>;34+ using InputType = std::conditional_t<std::is_integral_v<T>, uint8_t, T>;
35+ 
35public:36public:
36- __aicore__ inline TensorEqualKernel(const TensorEqualTilingData& tilingData, TPipe& pipe) :37+ __aicore__ inline TensorEqualKernel(const TensorEqualTilingData& tilingData, TPipe& pipe)
37- tilingData_(tilingData), pipe_(pipe) {};38+ : tilingData_(tilingData), pipe_(pipe){};
38 __aicore__ inline void Init(GM_ADDR input_x, GM_ADDR input_y, GM_ADDR output_z, GM_ADDR workspace);39 __aicore__ inline void Init(GM_ADDR input_x, GM_ADDR input_y, GM_ADDR output_z, GM_ADDR workspace);
39 __aicore__ inline void Process();40 __aicore__ inline void Process();
41+ 
40private:42private:
41 __aicore__ inline void CopyIn(int64_t offset, int64_t dataLen);43 __aicore__ inline void CopyIn(int64_t offset, int64_t dataLen);
42 __aicore__ inline void Compute(int64_t dataLen);44 __aicore__ inline void Compute(int64_t dataLen);
45+ 
43private:46private:
44 TQue<QuePosition::VECIN, DOUBLE_BUFFER> inputXQueue_;47 TQue<QuePosition::VECIN, DOUBLE_BUFFER> inputXQueue_;
45 TQue<QuePosition::VECIN, DOUBLE_BUFFER> inputYQueue_;48 TQue<QuePosition::VECIN, DOUBLE_BUFFER> inputYQueue_;
@@ -72,9 +75,9 @@ __aicore__ inline void TensorEqualKernel<T>::Init(GM_ADDR input_x, GM_ADDR input
72 ((tilingData_.perCoreLoopTimes - 1) * tilingData_.ubFactor + tilingData_.perCoreTailFactor);75 ((tilingData_.perCoreLoopTimes - 1) * tilingData_.ubFactor + tilingData_.perCoreTailFactor);
73 bufferSize_ = tilingData_.ubFactor * sizeof(T);76 bufferSize_ = tilingData_.ubFactor * sizeof(T);
74 77 
75- inputXGm_.SetGlobalBuffer((__gm__ InputType *)(input_x) + blockOffset_);78+ inputXGm_.SetGlobalBuffer((__gm__ InputType*)(input_x) + blockOffset_);
76- inputYGm_.SetGlobalBuffer((__gm__ InputType *)(input_y) + blockOffset_);79+ inputYGm_.SetGlobalBuffer((__gm__ InputType*)(input_y) + blockOffset_);
77- outputZGm_.SetGlobalBuffer((__gm__ uint8_t *)(output_z));80+ outputZGm_.SetGlobalBuffer((__gm__ uint8_t*)(output_z));
78 81 
79 if (blockIdx_ == 0) {82 if (blockIdx_ == 0) {
80 uint32_t initOutput = 1;83 uint32_t initOutput = 1;
@@ -95,14 +98,15 @@ __aicore__ inline void TensorEqualKernel<T>::Init(GM_ADDR input_x, GM_ADDR input
95template <typename T>98template <typename T>
96__aicore__ inline void TensorEqualKernel<T>::CopyIn(int64_t offset, int64_t dataLen)99__aicore__ inline void TensorEqualKernel<T>::CopyIn(int64_t offset, int64_t dataLen)
97{100{
98- DataCopyExtParams inParams = { 1, static_cast<uint32_t>(dataLen * sizeof(T)), 0, 0, 0 };101+ DataCopyExtParams inParams = {1, static_cast<uint32_t>(dataLen * sizeof(T)), 0, 0, 0};
99- DataCopyPadExtParams<InputType> padParams = { false, 0, 0, 0};102+ DataCopyPadExtParams<InputType> padParams = {false, 0, 0, 0};
100 103 
101 LocalTensor<InputType> xLocal = inputXQueue_.AllocTensor<InputType>();104 LocalTensor<InputType> xLocal = inputXQueue_.AllocTensor<InputType>();
102 LocalTensor<InputType> yLocal = inputYQueue_.AllocTensor<InputType>();105 LocalTensor<InputType> yLocal = inputYQueue_.AllocTensor<InputType>();
103 106 
104- DataCopyPad(xLocal, inputXGm_[offset], inParams, padParams);107+ int64_t gmOffset = offset * (sizeof(T) / sizeof(InputType));
105- DataCopyPad(yLocal, inputYGm_[offset], inParams, padParams);108+ DataCopyPad(xLocal, inputXGm_[gmOffset], inParams, padParams);
109+ DataCopyPad(yLocal, inputYGm_[gmOffset], inParams, padParams);
106 110 
107 inputXQueue_.EnQue(xLocal);111 inputXQueue_.EnQue(xLocal);
108 inputYQueue_.EnQue(yLocal);112 inputYQueue_.EnQue(yLocal);
@@ -113,13 +117,13 @@ __aicore__ inline void TensorEqualKernel<T>::Compute(int64_t dataLen)
113{117{
114 LocalTensor<InputType> xLocal = inputXQueue_.DeQue<InputType>();118 LocalTensor<InputType> xLocal = inputXQueue_.DeQue<InputType>();
115 LocalTensor<InputType> yLocal = inputYQueue_.DeQue<InputType>();119 LocalTensor<InputType> yLocal = inputYQueue_.DeQue<InputType>();
116- __ubuf__ InputType *inputXAddr = (__ubuf__ InputType *)xLocal.GetPhyAddr();120+ __ubuf__ InputType* inputXAddr = (__ubuf__ InputType*)xLocal.GetPhyAddr();
117- __ubuf__ InputType *inputYAddr = (__ubuf__ InputType *)yLocal.GetPhyAddr();121+ __ubuf__ InputType* inputYAddr = (__ubuf__ InputType*)yLocal.GetPhyAddr();
118 uint16_t strideVReg = Ops::Base::GetVRegSize();122 uint16_t strideVReg = Ops::Base::GetVRegSize();
119 uint32_t dataLenVf = dataLen * sizeof(T);123 uint32_t dataLenVf = dataLen * sizeof(T);
120 uint16_t repeatTimes = (dataLenVf + strideVReg - 1) / strideVReg;124 uint16_t repeatTimes = (dataLenVf + strideVReg - 1) / strideVReg;
121 LocalTensor<uint32_t> resultLocal = resultBuf_.Get<uint32_t>();125 LocalTensor<uint32_t> resultLocal = resultBuf_.Get<uint32_t>();
122- __ubuf__ uint32_t *resultAddr = (__ubuf__ uint32_t *)resultLocal.GetPhyAddr();126+ __ubuf__ uint32_t* resultAddr = (__ubuf__ uint32_t*)resultLocal.GetPhyAddr();
123 127 
124 __VEC_SCOPE__128 __VEC_SCOPE__
125 {129 {
@@ -128,8 +132,10 @@ __aicore__ inline void TensorEqualKernel<T>::Compute(int64_t dataLen)
128 AscendC::MicroAPI::RegTensor<uint32_t> tmpU32Reg;132 AscendC::MicroAPI::RegTensor<uint32_t> tmpU32Reg;
129 AscendC::MicroAPI::AddrReg offSetReg;133 AscendC::MicroAPI::AddrReg offSetReg;
130 AscendC::MicroAPI::MaskReg bakMaskRegHigh, bakMaskRegLow, maskReg, cmpMaskReg;134 AscendC::MicroAPI::MaskReg bakMaskRegHigh, bakMaskRegLow, maskReg, cmpMaskReg;
131- AscendC::MicroAPI::MaskReg allMaskReg = AscendC::MicroAPI::CreateMask<uint8_t, AscendC::MicroAPI::MaskPattern::ALL>();135+ AscendC::MicroAPI::MaskReg
132- AscendC::MicroAPI::MaskReg bakMaskReg = AscendC::MicroAPI::CreateMask<uint8_t, AscendC::MicroAPI::MaskPattern::ALLF>();136+ allMaskReg = AscendC::MicroAPI::CreateMask<uint8_t, AscendC::MicroAPI::MaskPattern::ALL>();
137+ AscendC::MicroAPI::MaskReg
138+ bakMaskReg = AscendC::MicroAPI::CreateMask<uint8_t, AscendC::MicroAPI::MaskPattern::ALLF>();
133 for (uint16_t i = 0; i < repeatTimes; i++) {139 for (uint16_t i = 0; i < repeatTimes; i++) {
134 offSetReg = AscendC::MicroAPI::CreateAddrReg<uint8_t>(i, strideVReg);140 offSetReg = AscendC::MicroAPI::CreateAddrReg<uint8_t>(i, strideVReg);
135 AscendC::MicroAPI::DataCopy(xReg, inputXAddr, offSetReg);141 AscendC::MicroAPI::DataCopy(xReg, inputXAddr, offSetReg);
@@ -165,14 +171,17 @@ __aicore__ inline void TensorEqualKernel<T>::Compute(int64_t dataLen)
165template <typename T>171template <typename T>
166__aicore__ inline void TensorEqualKernel<T>::Process()172__aicore__ inline void TensorEqualKernel<T>::Process()
167{173{
168- if (blockIdx_ >= tilingData_.usedCoreNum || tilingData_.tilingKey == DIFF_SHAPE_TILINGKEY || tilingData_.tilingKey == EMPTY_SHAPE_TILINGKEY) {174+ if (blockIdx_ >= tilingData_.usedCoreNum || tilingData_.tilingKey == DIFF_SHAPE_TILINGKEY ||
175+ tilingData_.tilingKey == EMPTY_SHAPE_TILINGKEY) {
169 return;176 return;
170 }177 }
171 LocalTensor<uint32_t> saveLocal = saveBuf_.Get<uint32_t>();178 LocalTensor<uint32_t> saveLocal = saveBuf_.Get<uint32_t>();
172 AscendC::Duplicate<uint32_t>(saveLocal, 0, 1);179 AscendC::Duplicate<uint32_t>(saveLocal, 0, 1);
173 180 
174- int64_t loopSize_ = blockIdx_ == tilingData_.usedCoreNum - 1 ? tilingData_.tailCoreLoopTimes : tilingData_.perCoreLoopTimes;181+ int64_t loopSize_ = blockIdx_ == tilingData_.usedCoreNum - 1 ? tilingData_.tailCoreLoopTimes :
175- int64_t tailFactor_ = blockIdx_ == tilingData_.usedCoreNum - 1 ? tilingData_.tailCoreTailFactor : tilingData_.perCoreTailFactor;182+ tilingData_.perCoreLoopTimes;
183+ int64_t tailFactor_ = blockIdx_ == tilingData_.usedCoreNum - 1 ? tilingData_.tailCoreTailFactor :
184+ tilingData_.perCoreTailFactor;
176 185 
177 int64_t offset = 0;186 int64_t offset = 0;
178 187 
@@ -196,10 +205,11 @@ __aicore__ inline void TensorEqualKernel<T>::Process()
196 205 
197 if (saveLocal(0) != 0 && outputZGm_.GetValue(0) == NORMAL_OUTPUT) {206 if (saveLocal(0) != 0 && outputZGm_.GetValue(0) == NORMAL_OUTPUT) {
198 outputZGm_.SetValue(0, 0);207 outputZGm_.SetValue(0, 0);
199- AscendC::DataCacheCleanAndInvalid<uint8_t, AscendC::CacheLine::SINGLE_CACHE_LINE, AscendC::DcciDst::CACHELINE_ALL>(outputZGm_);208+ AscendC::DataCacheCleanAndInvalid<uint8_t, AscendC::CacheLine::SINGLE_CACHE_LINE,
209+ AscendC::DcciDst::CACHELINE_ALL>(outputZGm_);
200 return;210 return;
201 }211 }
202}212}
203-} // namespace TensorEqual213+} // namespace TensorEqual
204 214 
205-#endif // TENSOR_EQUAL_H_215+#endif // TENSOR_EQUAL_H_