Line data Source code
1 : /**
2 : * Copyright (c) 2026 Huawei Technologies Co., Ltd.
3 : * This program is free software, you can redistribute it and/or modify it under the terms and conditions of
4 : * CANN Open Software License Agreement Version 2.0 (the "License").
5 : * Please refer to the License for details. You may not use this file except in compliance with the License.
6 : * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED,
7 : * INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.
8 : * See LICENSE in the root of the software repository for the full text of the License.
9 : */
10 :
11 : #ifndef __KFC_DUMP_SERVER_H__
12 : #define __KFC_DUMP_SERVER_H__
13 :
14 : #include "kfc_dump_param.h"
15 :
16 : namespace KfcDumpStat {
17 : class KfcDumpServer {
18 : public:
19 : __aicore__ inline KfcDumpServer() = default;
20 :
21 : __aicore__ inline ~KfcDumpServer() = default;
22 :
23 8 : __aicore__ inline void Init(uint64_t workspaceAddr)
24 : {
25 8 : msgBody_ = (__gm__ KfcDumpMsgBody*)workspaceAddr;
26 8 : msgRcvArea_ = msgBody_->msgRcvArea;
27 8 : msgSndArea_ = msgBody_->msgSndArea;
28 8 : rcvMsgPos_ = 0;
29 8 : sndMsgPos_ = 0;
30 8 : }
31 :
32 12 : __aicore__ inline __gm__ KfcDumpStatMsg* GetSndMsg()
33 : {
34 12 : GlobalTensor<uint32_t> sndMsgGm;
35 12 : __gm__ KfcDumpStatMsg* msg = &(msgBody_->msgSndArea[sndMsgPos_]);
36 12 : sndMsgGm.SetGlobalBuffer((__gm__ uint32_t*)msg);
37 : #if KFC_DUMP_ARCH_DAVID
38 12 : DataCacheCleanAndInvalid<uint32_t, CacheLine::SINGLE_CACHE_LINE, DcciDst::CACHELINE_OUT>(sndMsgGm);
39 : #else
40 : DataCacheCleanAndInvalid<uint32_t, CacheLine::SINGLE_CACHE_LINE>(sndMsgGm);
41 : #endif
42 12 : return msg;
43 : }
44 :
45 12 : __aicore__ inline __gm__ KfcDumpStatMsg* GetRcvMsg()
46 : {
47 12 : GlobalTensor<uint32_t> rcvMsgGm;
48 12 : __gm__ KfcDumpStatMsg* msg = &(msgBody_->msgRcvArea[rcvMsgPos_]);
49 12 : rcvMsgGm.SetGlobalBuffer((__gm__ uint32_t*)msg);
50 : #if KFC_DUMP_ARCH_DAVID
51 12 : DataCacheCleanAndInvalid<uint32_t, CacheLine::SINGLE_CACHE_LINE, DcciDst::CACHELINE_OUT>(rcvMsgGm);
52 : #else
53 : DataCacheCleanAndInvalid<uint32_t, CacheLine::SINGLE_CACHE_LINE>(rcvMsgGm);
54 : #endif
55 12 : return msg;
56 : }
57 :
58 22 : __aicore__ inline void IncreaseRcv() { rcvMsgPos_ = (rcvMsgPos_ + 1) % DUMP_MSG_CNT; }
59 :
60 23 : __aicore__ inline void IncreaseSnd() { sndMsgPos_ = (sndMsgPos_ + 1) % DUMP_MSG_CNT; }
61 :
62 3 : __aicore__ inline uint32_t GetSendPos() { return sndMsgPos_; }
63 :
64 2 : __aicore__ inline uint32_t GetRcvPos() { return rcvMsgPos_; }
65 :
66 1 : __aicore__ inline uint64_t GetMsgBody() { return reinterpret_cast<uint64_t>(msgBody_); }
67 :
68 : private:
69 : __gm__ KfcDumpMsgBody* msgBody_ = nullptr;
70 : __gm__ KfcDumpStatMsg* msgSndArea_ = nullptr;
71 : __gm__ KfcDumpStatMsg* msgRcvArea_ = nullptr;
72 :
73 : // 记录每个消息队列的位置
74 : uint32_t rcvMsgPos_ = 0;
75 : uint32_t sndMsgPos_ = 0;
76 : };
77 :
78 : } // namespace KfcDumpStat
79 :
80 : #endif // __KFC_DUMP_SERVER_H__
|