/** * Copyright (c) Huawei Technologies Co., Ltd. 2023. All rights reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ /* ! * \file kernel_common.h * \brief */ #ifndef ASCENDC_KERNEL_COMMON_H #define ASCENDC_KERNEL_COMMON_H #include "kernel_reg.h" #include "kernel_process_lock.h" namespace AscendC { class TPipe; class KfcCommClient; __aicore__ inline constexpr int16_t GetDataBlockSizeInBytes() { return ONE_BLK_SIZE; } } // namespace AscendC #if __CCE_AICORE__ == 220 #ifdef __DAV_C220_CUBE__ __BLOCK_LOCAL__ __inline__ AscendC::TPipe* g_cubeTPipePtr; #elif defined(__DAV_C220_VEC__) __BLOCK_LOCAL__ __inline__ AscendC::TPipe* g_vecTPipePtr; #else __BLOCK_LOCAL__ __inline__ AscendC::TPipe* g_tPipePtr; #endif #else __BLOCK_LOCAL__ __inline__ AscendC::TPipe* g_tPipePtr; #endif __BLOCK_LOCAL__ __inline__ __gm__ uint8_t* g_sysWorkspaceReserved; __BLOCK_LOCAL__ __inline__ __gm__ uint8_t* g_dumpWorkspaceReserved; #if defined(UT_TEST) || defined(ST_TEST) __aicore__ AscendC::TPipe* GetTPipePtr(); #else __aicore__ inline AscendC::TPipe* GetTPipePtr() { #if __CCE_AICORE__ == 220 #ifdef __DAV_C220_CUBE__ return g_cubeTPipePtr; #elif defined(__DAV_C220_VEC__) return g_vecTPipePtr; #else return g_tPipePtr; #endif #else return g_tPipePtr; #endif } #endif namespace AscendC { template __aicore__ static inline void OOMCheckAddrRange(__gm__ T* gmAddr, const uint64_t gmSize) { #if defined(ASCENDC_OOM) && ASCENDC_OOM == 1 uint64_t ioCount = g_oomAddrArange.count; if (ioCount >= g_oomAddrRangeMaxSize) { return; } g_oomAddrArange.addr[ioCount] = reinterpret_cast(gmAddr); g_oomAddrArange.len[ioCount] = gmSize; g_oomAddrArange.count += 1; #endif } __aicore__ static inline void OOMInit() { #if defined(ASCENDC_OOM) && ASCENDC_OOM == 1 g_oomAddrArange.count = 0; #endif } template __aicore__ static inline void SetVectorMask(const uint64_t maskHigh, const uint64_t maskLow) { SetVectorMaskImpl(maskHigh, maskLow); } template __aicore__ static inline void SetVectorMask(int32_t len) { SetVectorMaskImpl(len); } __aicore__ inline void ResetMask() { ResetMaskImpl(); } #if __CCE_AICORE__ >= 220 template __aicore__ inline void DataSyncBarrier() { DataSyncBarrierImpl(); } template __aicore__ inline void HSetFlag(int32_t eventID) { HSetFlagImpl(eventID); } template __aicore__ inline void HWaitFlag(int32_t eventID) { HWaitFlagImpl(eventID); } #endif template __aicore__ inline void SetFlag(int32_t eventID) { SetFlagImpl(eventID); } template __aicore__ inline void WaitFlag(int32_t eventID) { WaitFlagImpl(event, eventID); } template __aicore__ inline void PipeBarrier() { PipeBarrierImpl(); } #if __CCE_AICORE__ == 220 template __aicore__ inline void DataCacheCleanAndInvalid(const GlobalTensor& dstTensor) { DcciGMImpl(const_cast<__gm__ T*>(dstTensor.GetPhyAddr())); } template __aicore__ inline void DataCacheCleanAndInvalid(const LocalTensor& dstTensor) { DcciUBImpl(const_cast<__ubuf__ T*>(dstTensor.GetPhyAddr())); } #endif #if (__CCE_AICORE__ == 220) || (__CCE_AICORE__ == 200) template __aicore__ inline void DataCacheCleanAndInvalid(const GlobalTensor& dstTensor) { DcciGMImpl(const_cast<__gm__ T*>(dstTensor.GetPhyAddr())); } #endif __aicore__ inline void SetMaskCount() { SetMaskCountImpl(); } __aicore__ inline void SetMaskNorm() { SetMaskNormImpl(); } __aicore__ inline void SetLreluMode(bool lreluMode) { SetLreluModeImpl(lreluMode); } __aicore__ inline void SetHF32Mode(bool hf32Mode) { SetHF32ModeImpl(hf32Mode); } __aicore__ inline void SetHF32TransMode(bool hf32TransMode) { SetHF32TransModeImpl(hf32TransMode); } __aicore__ inline void SetMMLayoutTransform(bool mmLayoutMode) { SetMMLayoutTransformImpl(mmLayoutMode); } __aicore__ inline int64_t GetAccVal() { #if __CCE_AICORE__ == 220 if (g_coreType == AIC) { return 0; } #endif return GetAccValImpl(); } } // namespace AscendC [[deprecated("NOTICE: SetDumpWorkSpacePtr has been deprecated and will be removed in the next version. " "Please do not use it!")]] __aicore__ inline __gm__ uint8_t* __gm__ SetDumpWorkSpacePtr(__gm__ uint8_t* workspace) { return g_dumpWorkspaceReserved = workspace; } [[deprecated("NOTICE: GetDumpWorkSpacePtr has been deprecated and will be removed in the next version. " "Please do not use it!")]] __aicore__ inline __gm__ uint8_t* __gm__ GetDumpWorkSpacePtr() { return g_dumpWorkspaceReserved; } #if defined(__CCE_KT_TEST__) __aicore__ __gm__ uint8_t* __gm__ GetSysWorkSpacePtr(); __aicore__ void SetSysWorkSpacePtr(__gm__ uint8_t* workspace); #else __aicore__ inline __gm__ uint8_t* __gm__ GetSysWorkSpacePtr() { return g_sysWorkspaceReserved; } [[deprecated( "NOTICE: SetSysWorkSpacePtr has been deprecated and will be removed in the next version.")]] __aicore__ inline void SetSysWorkSpacePtr(__gm__ uint8_t* workspace) { g_sysWorkspaceReserved = workspace; } #endif #endif