Merged
降低dav_9201基础API代码重复率 #7442
tongjinjianAdd on 13 days ago
降低dav_9201基础API代码重复率 #7442
Merged
tongjinjianAdd on 13 days ago
Total: 3 files changed+74-136
@@ -28,6 +28,23 @@
28#include <utility>28#include <utility>
29#include "../../utils/base/compat_utils.h"29#include "../../utils/base/compat_utils.h"
30 30 
31+#define ASCENDC_COPY_LOOP_PARAM_CHK_() \
32+ ASCENDC_ASSERT((loopParams.loop1Size < (1ul << 21)), { \
33+ KERNEL_LOG(KERNEL_ERROR, "loopParams.loop1Size is too big and needs to be less than 2^21"); \
34+ }); \
35+ ASCENDC_ASSERT((loopParams.loop1DstStride < (1ul << 21)), { \
36+ KERNEL_LOG(KERNEL_ERROR, "loopParams.loop1DstStride is too big and needs to be less than 2^21"); \
37+ }); \
38+ ASCENDC_ASSERT((loopParams.loop2DstStride < (1ul << 21)), { \
39+ KERNEL_LOG(KERNEL_ERROR, "loopParams.loop2DstStride is too big and needs to be less than 2^21"); \
40+ }); \
41+ ASCENDC_ASSERT((loopParams.loop1SrcStride < (1ul << 40)), { \
42+ KERNEL_LOG(KERNEL_ERROR, "loopParams.loop1SrcStride is too big and needs to be less than 2^40"); \
43+ }); \
44+ ASCENDC_ASSERT((loopParams.loop2SrcStride < (1ul << 40)), { \
45+ KERNEL_LOG(KERNEL_ERROR, "loopParams.loop2SrcStride is too big and needs to be less than 2^40"); \
46+ })
47+ 
31namespace AscendC {48namespace AscendC {
32 49 
33// all input params: C220 version, not C310 version, thus need conversion by *3250// all input params: C220 version, not C310 version, thus need conversion by *32
@@ -677,21 +694,7 @@ __aicore__ inline void SetLoopModeOutParaImpl(const LoopModeParams& loopParams)
677 ASCENDC_ASSERT((loopParams.loop2Size < (1ul << 21)), {694 ASCENDC_ASSERT((loopParams.loop2Size < (1ul << 21)), {
678 KERNEL_LOG(KERNEL_ERROR, "loopParams.loop2Size is too big and needs to be less than 2^21");695 KERNEL_LOG(KERNEL_ERROR, "loopParams.loop2Size is too big and needs to be less than 2^21");
679 });696 });
680- ASCENDC_ASSERT((loopParams.loop1Size < (1ul << 21)), {697+ ASCENDC_COPY_LOOP_PARAM_CHK_();
681- KERNEL_LOG(KERNEL_ERROR, "loopParams.loop1Size is too big and needs to be less than 2^21");
682- });
683- ASCENDC_ASSERT((loopParams.loop1DstStride < (1ul << 21)), {
684- KERNEL_LOG(KERNEL_ERROR, "loopParams.loop1DstStride is too big and needs to be less than 2^21");
685- });
686- ASCENDC_ASSERT((loopParams.loop2DstStride < (1ul << 21)), {
687- KERNEL_LOG(KERNEL_ERROR, "loopParams.loop2DstStride is too big and needs to be less than 2^21");
688- });
689- ASCENDC_ASSERT((loopParams.loop1SrcStride < (1ul << 40)), {
690- KERNEL_LOG(KERNEL_ERROR, "loopParams.loop1SrcStride is too big and needs to be less than 2^40");
691- });
692- ASCENDC_ASSERT((loopParams.loop2SrcStride < (1ul << 40)), {
693- KERNEL_LOG(KERNEL_ERROR, "loopParams.loop2SrcStride is too big and needs to be less than 2^40");
694- });
695 uint64_t loopSizePara = static_cast<uint64_t>(loopParams.loop2Size) << 21; // LOOP_SIZE_OUTTOUB[42:21]698 uint64_t loopSizePara = static_cast<uint64_t>(loopParams.loop2Size) << 21; // LOOP_SIZE_OUTTOUB[42:21]
696 loopSizePara |= static_cast<uint64_t>(loopParams.loop1Size); // LOOP_SIZE_OUTTOUB[20:0]699 loopSizePara |= static_cast<uint64_t>(loopParams.loop1Size); // LOOP_SIZE_OUTTOUB[20:0]
697 700 
@@ -760,21 +763,7 @@ __aicore__ inline void SetLoopModeOutToL1ParaImpl(const LoopModeParams& loopPara
760 ASCENDC_ASSERT((loopParams.loop2Size < (1ul << 22)), {763 ASCENDC_ASSERT((loopParams.loop2Size < (1ul << 22)), {
761 KERNEL_LOG(KERNEL_ERROR, "loopParams.loop2Size is too big and needs to be less than 2^22");764 KERNEL_LOG(KERNEL_ERROR, "loopParams.loop2Size is too big and needs to be less than 2^22");
762 });765 });
763- ASCENDC_ASSERT((loopParams.loop1Size < (1ul << 21)), {766+ ASCENDC_COPY_LOOP_PARAM_CHK_();
764- KERNEL_LOG(KERNEL_ERROR, "loopParams.loop1Size is too big and needs to be less than 2^21");
765- });
766- ASCENDC_ASSERT((loopParams.loop1DstStride < (1ul << 21)), {
767- KERNEL_LOG(KERNEL_ERROR, "loopParams.loop1DstStride is too big and needs to be less than 2^21");
768- });
769- ASCENDC_ASSERT((loopParams.loop2DstStride < (1ul << 21)), {
770- KERNEL_LOG(KERNEL_ERROR, "loopParams.loop2DstStride is too big and needs to be less than 2^21");
771- });
772- ASCENDC_ASSERT((loopParams.loop1SrcStride < (1ul << 40)), {
773- KERNEL_LOG(KERNEL_ERROR, "loopParams.loop1SrcStride is too big and needs to be less than 2^40");
774- });
775- ASCENDC_ASSERT((loopParams.loop2SrcStride < (1ul << 40)), {
776- KERNEL_LOG(KERNEL_ERROR, "loopParams.loop2SrcStride is too big and needs to be less than 2^40");
777- });
778 uint64_t loopSizePara = static_cast<uint64_t>(loopParams.loop2Size) << 21;767 uint64_t loopSizePara = static_cast<uint64_t>(loopParams.loop2Size) << 21;
779 loopSizePara |= static_cast<uint64_t>(loopParams.loop1Size);768 loopSizePara |= static_cast<uint64_t>(loopParams.loop1Size);
780 769 
@@ -1169,16 +1158,7 @@ __aicore__ inline void VecCopyLevel0Template(
1169 __ubuf__ T* dst, __ubuf__ T* src, const uint64_t maskArray[], const uint64_t maskCount, const uint8_t repeatTime,1158 __ubuf__ T* dst, __ubuf__ T* src, const uint64_t maskArray[], const uint64_t maskCount, const uint8_t repeatTime,
1170 const CopyRepeatParams& repeatParams)1159 const CopyRepeatParams& repeatParams)
1171{1160{
1172- BasicAPIMaskStruct maskArrayStruct;1161+ BasicAPIMaskStruct maskArrayStruct = GetVecMaskArrayStruct<isMaskBitMode>(maskArray, maskCount);
1173- if constexpr (isMaskBitMode) {
1174- ASCENDC_ASSERT(
1175- maskCount == 0, { KERNEL_LOG(KERNEL_ERROR, "maskCount must be 0 when isMaskBitMode is true."); });
1176- maskArrayStruct = *(reinterpret_cast<const BasicAPIMaskStruct*>(maskArray));
1177- } else {
1178- ASCENDC_ASSERT(maskArray == nullptr, {
1179- KERNEL_LOG(KERNEL_ERROR, "maskArray must be nullptr when isMaskBitMode is false.");
1180- });
1181- }
1182 __ubuf__ uint64_t* maskBuf = nullptr;1162 __ubuf__ uint64_t* maskBuf = nullptr;
1183 1163 
1184 if (Internal::IsCounterMode()) {1164 if (Internal::IsCounterMode()) {
@@ -1915,3 +1895,5 @@ __aicore__ inline void DataCopyWithNDDMAB64Impl(
1915#undef __ASCENDC_INCLUDE_INTERNAL_HEADERS__1895#undef __ASCENDC_INCLUDE_INTERNAL_HEADERS__
1916#undef __UNDEF_ASCENDC_INCLUDE_INTERNAL_HEADERS_KERNEL_OPERATOR_DATA_COPY_IMPL_H__1896#undef __UNDEF_ASCENDC_INCLUDE_INTERNAL_HEADERS_KERNEL_OPERATOR_DATA_COPY_IMPL_H__
1917#endif1897#endif
1898+ 
1899+#undef ASCENDC_COPY_LOOP_PARAM_CHK_
@@ -25,6 +25,24 @@
25#include "../../../include/basic_api/kernel_operator_block_sync_intf.h"25#include "../../../include/basic_api/kernel_operator_block_sync_intf.h"
26#include "../kernel_process_lock.h"26#include "../kernel_process_lock.h"
27 27 
28+#define ASCENDC_FIXPIPE_SET_L0C_PARA_() \
29+ SetLoop3Para<config>(intriParams); \
30+ /* nz2dn mode need set CHANNEL_PARA extra */ \
31+ /* Loop0 dst(src) stride in unit of CO_SIZE */ \
32+ if constexpr (config.format == CO2Layout::COLUMN_MAJOR) { \
33+ /* CHANNEL_PARA[63:48] */ \
34+ uint64_t channelPara = static_cast<uint64_t>(intriParams.params.srcNzC0Stride) << 48; \
35+ set_channel_para(channelPara); \
36+ } \
37+ /* make code for scalar quant mode: */ \
38+ /* 1. copy deq scalar u64 immediate */ \
39+ /* 2. code gen: move data from l0c to l1/ub/gm */ \
40+ if (IsScalarQuantMode(intriParams.quantPre)) { \
41+ /* deq factor: bits[31:13] is deq value of fp32 */ \
42+ set_quant_pre(intriParams.deqScalar); \
43+ } \
44+ PipeBarrier<PIPE_FIX>()
45+ 
28namespace AscendC {46namespace AscendC {
29__aicore__ inline void SetFixPipeClipReluImpl(uint64_t config)47__aicore__ inline void SetFixPipeClipReluImpl(uint64_t config)
30{48{
@@ -598,24 +616,7 @@ __aicore__ inline void FixpipeL0C2L1Impl(
598 if ASCEND_IS_AIC {616 if ASCEND_IS_AIC {
599 CheckFixpipeL0C2L1Param<DstT, SrcT, config>(dst, src, intriParams);617 CheckFixpipeL0C2L1Param<DstT, SrcT, config>(dst, src, intriParams);
600 // nz2nd/nz2dn need set LOOP3_PARA618 // nz2nd/nz2dn need set LOOP3_PARA
601- SetLoop3Para<config>(intriParams);619+ ASCENDC_FIXPIPE_SET_L0C_PARA_();
602- 
603- // nz2dn mode need set CHANNEL_PARA extra
604- if constexpr (config.format == CO2Layout::COLUMN_MAJOR) {
605- // Loop0_dst_stride in uint of CO_SIZE
606- uint64_t channelPara = static_cast<uint64_t>(intriParams.params.srcNzC0Stride) << 48; // CHANNEL_PARA[63:48]
607- set_channel_para(channelPara);
608- }
609- /*
610- make code for scalar quant mode:
611- 1. copy deq scalar u64 immediate
612- 2. code gen: move data from l0c to l1
613- */
614- if (IsScalarQuantMode(intriParams.quantPre)) {
615- // deq factor of uint64 bits describe: bits[31:13] is deq value of fp32,
616- set_quant_pre(intriParams.deqScalar);
617- }
618- PipeBarrier<PIPE_FIX>();
619 FixpipeTiling fixpipeTiling;620 FixpipeTiling fixpipeTiling;
620 // LOC -> L1621 // LOC -> L1
621 FixpipeL0cToL1<DstT, SrcT, config>(dst, src, intriParams, fixpipeTiling, intriParams.nSize);622 FixpipeL0cToL1<DstT, SrcT, config>(dst, src, intriParams, fixpipeTiling, intriParams.nSize);
@@ -668,23 +669,7 @@ __aicore__ inline void FixpipeL0C2UBImpl(
668 if ASCEND_IS_AIC {669 if ASCEND_IS_AIC {
669 CheckFixpipeL0C2UBParam<DstT, SrcT, config>(dst, src, intriParams);670 CheckFixpipeL0C2UBParam<DstT, SrcT, config>(dst, src, intriParams);
670 // nz2nd/nz2dn need set LOOP3_PARA671 // nz2nd/nz2dn need set LOOP3_PARA
671- SetLoop3Para<config>(intriParams);672+ ASCENDC_FIXPIPE_SET_L0C_PARA_();
672- // nz2dn mode need set CHANNEL_PARA extra
673- if constexpr (config.format == CO2Layout::COLUMN_MAJOR) {
674- // Loop0_src_stride in uint of CO_SIZE
675- uint64_t channelPara = static_cast<uint64_t>(intriParams.params.srcNzC0Stride) << 48; // CHANNEL_PARA[63:48]
676- set_channel_para(channelPara);
677- }
678- /*
679- make code for scalar quant mode:
680- 1. copy deq scalar u64 immediate
681- 2. code gen: move data from l0c to ub
682- */
683- if (IsScalarQuantMode(intriParams.quantPre)) {
684- // deq factor of uint64 bits describe: bits[31:13] is deq value of fp32
685- set_quant_pre(intriParams.deqScalar); // float32->uint64_t
686- }
687- PipeBarrier<PIPE_FIX>();
688 // LOC->UB673 // LOC->UB
689 FixpipeTiling fixpipeTiling;674 FixpipeTiling fixpipeTiling;
690 FixpipeL0cToUB<DstT, SrcT, config>(dst, src, intriParams, fixpipeTiling, intriParams.nSize);675 FixpipeL0cToUB<DstT, SrcT, config>(dst, src, intriParams, fixpipeTiling, intriParams.nSize);
@@ -737,21 +722,7 @@ __aicore__ inline void FixpipeL0C2GMImpl(
737 if ASCEND_IS_AIC {722 if ASCEND_IS_AIC {
738 CheckFixpipeL0C2GMParam<DstT, SrcT, config>(dst, src, intriParams);723 CheckFixpipeL0C2GMParam<DstT, SrcT, config>(dst, src, intriParams);
739 // nz2nd/nz2dn need set LOOP3_PARA724 // nz2nd/nz2dn need set LOOP3_PARA
740- SetLoop3Para<config>(intriParams);725+ ASCENDC_FIXPIPE_SET_L0C_PARA_();
741- // nz2dn mode need set CHANNEL_PARA extra
742- if constexpr (config.format == CO2Layout::COLUMN_MAJOR) {
743- uint64_t channelPara = static_cast<uint64_t>(intriParams.params.srcNzC0Stride) << 48; // CHANNEL_PARA[63:48]
744- set_channel_para(channelPara);
745- }
746- /*
747- make code for scalar quant mode:
748- 1. copy deq scalar u64 immediate
749- 2. code gen: move data from l0c to gm
750- */
751- if (IsScalarQuantMode(intriParams.quantPre)) {
752- set_quant_pre(intriParams.deqScalar);
753- }
754- PipeBarrier<PIPE_FIX>();
755 // LOC -> GM726 // LOC -> GM
756 FixpipeTiling fixpipeTiling;727 FixpipeTiling fixpipeTiling;
757 FixpipeL0cToOut<DstT, SrcT, config>(dst, src, intriParams, fixpipeTiling, intriParams.nSize, cacheMode);728 FixpipeL0cToOut<DstT, SrcT, config>(dst, src, intriParams, fixpipeTiling, intriParams.nSize, cacheMode);
@@ -876,3 +847,5 @@ __aicore__ inline void FixpipeL0C2GMImpl(
876#undef __ASCENDC_INCLUDE_INTERNAL_HEADERS__847#undef __ASCENDC_INCLUDE_INTERNAL_HEADERS__
877#undef __UNDEF_ASCENDC_INCLUDE_INTERNAL_HEADERS_KERNEL_OPERATOR_FIXPIPE_IMPL_H__848#undef __UNDEF_ASCENDC_INCLUDE_INTERNAL_HEADERS_KERNEL_OPERATOR_FIXPIPE_IMPL_H__
878#endif849#endif
850+ 
851+#undef ASCENDC_FIXPIPE_SET_L0C_PARA_
@@ -58,6 +58,31 @@
58#include "stub_fun.h"58#include "stub_fun.h"
59#endif59#endif
60 60 
61+#define ASCENDC_TPIPE_TBUF_STATE_INIT_() \
62+ ptr->state = TBufState::FREE; \
63+ ptr->freeBufEvt = T::freeBufEvt; \
64+ if ASCEND_IS_AIV { \
65+ ptr->bufId = AllocMutexID(); \
66+ if constexpr (useAltBufId) { \
67+ ptr->bufIdAlt = AllocMutexID(); \
68+ } else { \
69+ ptr->bufIdAlt = INVALID_TBUFID; \
70+ } \
71+ } else { \
72+ /* c310 aic quedepth=0 will setflag */ \
73+ if constexpr (T::queDepth == 0) { \
74+ ptr->enQueEvtID = AllocEventID<T::enQueEvt>(); \
75+ ptr->freeBufEvtID = AllocEventID<T::freeBufEvt>(); \
76+ SetFlag<T::freeBufEvt>(ptr->freeBufEvtID); \
77+ } else if constexpr (T::config.enableStaticEvtId) { \
78+ ptr->bufId = AllocMutexID(); \
79+ ptr->bufIdAlt = INVALID_TBUFID; \
80+ } else { \
81+ ptr->enQueEvtID = INVALID_TEVENTID; \
82+ ptr->freeBufEvtID = INVALID_TEVENTID; \
83+ } \
84+ }
85+ 
61namespace AscendC {86namespace AscendC {
62namespace Std {87namespace Std {
63template <typename... Tps>88template <typename... Tps>
@@ -165,29 +190,7 @@ __aicore__ inline void TPipe::AllocAddrs(TBufType* ptr, const First& addr, const
165 Std::is_tuple_v<First> && Std::tuple_size_v<First> == 2,190 Std::is_tuple_v<First> && Std::tuple_size_v<First> == 2,
166 "input Addrs must be Std::tuple type and tuple_size must be 2");191 "input Addrs must be Std::tuple type and tuple_size must be 2");
167 constexpr bool useAltBufId = T::config.consumerSize > 1;192 constexpr bool useAltBufId = T::config.consumerSize > 1;
168- ptr->state = TBufState::FREE;193+ ASCENDC_TPIPE_TBUF_STATE_INIT_()
169- ptr->freeBufEvt = T::freeBufEvt;
170- if ASCEND_IS_AIV {
171- ptr->bufId = AllocMutexID();
172- if constexpr (useAltBufId) {
173- ptr->bufIdAlt = AllocMutexID();
174- } else {
175- ptr->bufIdAlt = INVALID_TBUFID;
176- }
177- } else {
178- // c310 aic quedepth=0 will setflag
179- if constexpr (T::queDepth == 0) {
180- ptr->enQueEvtID = AllocEventID<T::enQueEvt>();
181- ptr->freeBufEvtID = AllocEventID<T::freeBufEvt>();
182- SetFlag<T::freeBufEvt>(ptr->freeBufEvtID);
183- } else if constexpr (T::config.enableStaticEvtId) {
184- ptr->bufId = AllocMutexID();
185- ptr->bufIdAlt = INVALID_TBUFID;
186- } else {
187- ptr->enQueEvtID = INVALID_TEVENTID;
188- ptr->freeBufEvtID = INVALID_TEVENTID;
189- }
190- }
191 // process specifically for better static_assert message194 // process specifically for better static_assert message
192 if constexpr ((Std::tuple_size_v<First>) > 1) {195 if constexpr ((Std::tuple_size_v<First>) > 1) {
193 ptr->address = Std::get<0>(addr);196 ptr->address = Std::get<0>(addr);
@@ -283,29 +286,7 @@ __aicore__ inline bool TPipe::InitBuffer(T& que, uint8_t num, uint32_t len)
283 AscendCBufInit(static_cast<uint8_t>(pos_), 0, num, reinterpret_cast<uint64_t>(curPoolAddr + absAddr), len);286 AscendCBufInit(static_cast<uint8_t>(pos_), 0, num, reinterpret_cast<uint64_t>(curPoolAddr + absAddr), len);
284#endif287#endif
285 for (int32_t i = 0; i < num; i++, ptr++) {288 for (int32_t i = 0; i < num; i++, ptr++) {
286- ptr->state = TBufState::FREE;289+ ASCENDC_TPIPE_TBUF_STATE_INIT_()
287- ptr->freeBufEvt = T::freeBufEvt;
288- if ASCEND_IS_AIV {
289- ptr->bufId = AllocMutexID();
290- if constexpr (useAltBufId) {
291- ptr->bufIdAlt = AllocMutexID();
292- } else {
293- ptr->bufIdAlt = INVALID_TBUFID;
294- }
295- } else {
296- // c310 aic quedepth=0 will setflag
297- if constexpr (T::queDepth == 0) {
298- ptr->enQueEvtID = AllocEventID<T::enQueEvt>();
299- ptr->freeBufEvtID = AllocEventID<T::freeBufEvt>();
300- SetFlag<T::freeBufEvt>(ptr->freeBufEvtID);
301- } else if constexpr (T::config.enableStaticEvtId) {
302- ptr->bufId = AllocMutexID();
303- ptr->bufIdAlt = INVALID_TBUFID;
304- } else {
305- ptr->enQueEvtID = INVALID_TEVENTID;
306- ptr->freeBufEvtID = INVALID_TEVENTID;
307- }
308- }
309 ptr->address = curPoolAddr;290 ptr->address = curPoolAddr;
310 ptr->dataLen = len;291 ptr->dataLen = len;
311 ptr->usertag = -1;292 ptr->usertag = -1;
@@ -1024,3 +1005,5 @@ __aicore__ inline bool TPipe::TscmInitBuffer(T& que, uint8_t num, uint32_t len)
1024#undef __ASCENDC_INCLUDE_INTERNAL_HEADERS__1005#undef __ASCENDC_INCLUDE_INTERNAL_HEADERS__
1025#undef __UNDEF_ASCENDC_INCLUDE_INTERNAL_HEADERS_KERNEL_TPIPE_IMPL_C310_H__1006#undef __UNDEF_ASCENDC_INCLUDE_INTERNAL_HEADERS_KERNEL_TPIPE_IMPL_C310_H__
1026#endif1007#endif
1008+ 
1009+#undef ASCENDC_TPIPE_TBUF_STATE_INIT_