已合并
修复FlatQuant内存检测问题+精度问题 #3937
陈海杰创建于 4月17日
修复FlatQuant内存检测问题+精度问题 #3937
已合并
陈海杰创建于 4月17日
共 4 个文件变更+11-11
@@ -33,7 +33,6 @@ public:
33 p1GM.SetGlobalBuffer((__gm__ T *)p1mtx_);33 p1GM.SetGlobalBuffer((__gm__ T *)p1mtx_);
34 p2GM.SetGlobalBuffer((__gm__ T *)p2mtx_);34 p2GM.SetGlobalBuffer((__gm__ T *)p2mtx_);
35 outnzGM.SetGlobalBuffer((__gm__ T *)workspace_);35 outnzGM.SetGlobalBuffer((__gm__ T *)workspace_);
36- doubleP1GM.SetGlobalBuffer((__gm__ T *)(workspace_ + (shape.K + shape.K % 2) * shape.Mceil * shape.N * sizeof(T)));
37 36 
38 SetFixpipeNz2ndFlag(1, 1, shape.Nceil);37 SetFixpipeNz2ndFlag(1, 1, shape.Nceil);
39 pipe.InitBuffer(l1Buf, L1_SIZE);38 pipe.InitBuffer(l1Buf, L1_SIZE);
@@ -101,7 +100,7 @@ public:
101 100 
102 for (int64_t startK = shape.K1; startK < shape.K2; startK += shape.perK) {101 for (int64_t startK = shape.K1; startK < shape.K2; startK += shape.perK) {
103 int64_t endK = (startK + shape.perK > shape.K2) ? shape.K2 : (startK + shape.perK);102 int64_t endK = (startK + shape.perK > shape.K2) ? shape.K2 : (startK + shape.perK);
104- bool isLast = startK + shape.perK > shape.K2;103+ bool isLast = (endK == shape.K);
105 if constexpr (MM_MODE == MM_SPLIT_MODE) {104 if constexpr (MM_MODE == MM_SPLIT_MODE) {
106 for (int64_t k = startK; k < endK; ++k) {105 for (int64_t k = startK; k < endK; ++k) {
107 ProcessSplitK(k, isLast);106 ProcessSplitK(k, isLast);
@@ -133,11 +132,11 @@ public:
133 l1empty.wait();132 l1empty.wait();
134 CopyXToL1(GetXTensor(nextK), xGM[nextK * shape.M * shape.N], nextK > invalidK, shape);133 CopyXToL1(GetXTensor(nextK), xGM[nextK * shape.M * shape.N], nextK > invalidK, shape);
135 l1ready.set();134 l1ready.set();
136- } else if (nextK < shape.K2 && !isLast) {135+ } else if (nextK < shape.K2 && nextK != shape.K - 1) {
137 l1empty.wait();136 l1empty.wait();
138 CopyXToL1(GetXTensor(nextK), xGM[nextK * shape.M * shape.N], nextK > invalidK, shape);137 CopyXToL1(GetXTensor(nextK), xGM[nextK * shape.M * shape.N], nextK > invalidK, shape);
139 l1ready.set();138 l1ready.set();
140- } else if (nextK < shape.K2 && isLast) {139+ } else if (nextK < shape.K2 && nextK == shape.K - 1) {
141 int64_t oriM = shape.M;140 int64_t oriM = shape.M;
142 shape.M = tailK;141 shape.M = tailK;
143 l1empty.wait();142 l1empty.wait();
@@ -233,7 +232,6 @@ private:
233 GlobalTensor<T> p1GM;232 GlobalTensor<T> p1GM;
234 GlobalTensor<T> p2GM;233 GlobalTensor<T> p2GM;
235 GlobalTensor<T> outnzGM;234 GlobalTensor<T> outnzGM;
236- GlobalTensor<T> doubleP1GM;
237 235 
238 TBuf<TPosition::A1> l1Buf;236 TBuf<TPosition::A1> l1Buf;
239 TBuf<TPosition::A2> l0aBuf;237 TBuf<TPosition::A2> l0aBuf;
@@ -274,7 +274,9 @@ public:
274 274 
275 CalReduceMax(absTensor, rowNumCeil * shape.Nceil, eventIdVToS);275 CalReduceMax(absTensor, rowNumCeil * shape.Nceil, eventIdVToS);
276 float tmpMax = static_cast<float>(absTensor.GetValue(0));276 float tmpMax = static_cast<float>(absTensor.GetValue(0));
277- maxValue = AscendC::Std::max(tmpMax, maxValue);277+ if (tmpMax != tmpMax || tmpMax > maxValue) {
278+ maxValue = tmpMax;
279+ }
278 p ++;280 p ++;
279 }281 }
280 }282 }
@@ -109,11 +109,11 @@ public:
109 int64_t subBlockIdx = GetSubBlockIdx();109 int64_t subBlockIdx = GetSubBlockIdx();
110 for (int64_t startK = shape.K1; startK < shape.K2; startK += shape.perK) {110 for (int64_t startK = shape.K1; startK < shape.K2; startK += shape.perK) {
111 int64_t endK = startK + shape.perK > shape.K2 ? shape.K2 : startK + shape.perK;111 int64_t endK = startK + shape.perK > shape.K2 ? shape.K2 : startK + shape.perK;
112- bool isLast = startK + shape.perK > shape.K2;112+ bool isLast = shape.K - (endK - 1) * perM < perM;
113 for (int64_t k = startK; k < endK; k ++) {113 for (int64_t k = startK; k < endK; k ++) {
114 // 量化分给两个vec核,0核做偶数,1核做奇数114 // 量化分给两个vec核,0核做偶数,1核做奇数
115 if ((k & 1) == subBlockIdx) {115 if ((k & 1) == subBlockIdx) {
116- if (isLast && k == endK - 1) {116+ if (isLast && shape.K - k * perM < perM) {
117 MultiQuantTail(k, scaleK, isLast);117 MultiQuantTail(k, scaleK, isLast);
118 } else {118 } else {
119 MultiQuant(k, scaleK, isLast);119 MultiQuant(k, scaleK, isLast);
@@ -220,14 +220,14 @@ __aicore__ inline void DataCopyInContiguous(LocalTensor<T> dstTensor, GlobalTens
220 220 
221__aicore__ inline void CalReduceMaxOne(LocalTensor<half> srcTensor, int32_t rowNum, int32_t colAlign, int32_t colSize)221__aicore__ inline void CalReduceMaxOne(LocalTensor<half> srcTensor, int32_t rowNum, int32_t colAlign, int32_t colSize)
222{222{
223- int32_t repeatTimes = colSize >> LOG2_128; // 除128223+ int32_t repeatTimes = (colSize - 1) >> LOG2_128; // 除128
224 uint8_t repeatStride = colAlign >> LOG2_16;224 uint8_t repeatStride = colAlign >> LOG2_16;
225 BinaryRepeatParams repeatParams = {1, 1, 1, repeatStride, repeatStride, repeatStride};225 BinaryRepeatParams repeatParams = {1, 1, 1, repeatStride, repeatStride, repeatStride};
226- for (int64_t i = 0; i < repeatTimes - 1; i++) {226+ for (int64_t i = 1; i < repeatTimes; i++) {
227 Max(srcTensor, srcTensor[i * BASE_SIZE], srcTensor, BASE_SIZE, rowNum, repeatParams);227 Max(srcTensor, srcTensor[i * BASE_SIZE], srcTensor, BASE_SIZE, rowNum, repeatParams);
228 PipeBarrier<PIPE_V>();228 PipeBarrier<PIPE_V>();
229 }229 }
230- Max(srcTensor, srcTensor[repeatTimes * BASE_SIZE], srcTensor, colSize % BASE_SIZE, rowNum, repeatParams);230+ Max(srcTensor, srcTensor[repeatTimes * BASE_SIZE], srcTensor, colSize - repeatTimes * BASE_SIZE, rowNum, repeatParams);
231 PipeBarrier<PIPE_V>();231 PipeBarrier<PIPE_V>();
232 WholeReduceMax(srcTensor, srcTensor, colSize < BASE_SIZE ? colSize : BASE_SIZE, rowNum, 1, 1, repeatStride, ReduceOrder::ORDER_ONLY_VALUE);232 WholeReduceMax(srcTensor, srcTensor, colSize < BASE_SIZE ? colSize : BASE_SIZE, rowNum, 1, 1, repeatStride, ReduceOrder::ORDER_ONLY_VALUE);
233 PipeBarrier<PIPE_V>();233 PipeBarrier<PIPE_V>();