Line data Source code
1 : /**
2 : * Copyright (c) 2025 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 ESCHED_NOTIFY_H
12 : #define ESCHED_NOTIFY_H
13 :
14 : #include <atomic>
15 : #include "notify_base.h"
16 :
17 : namespace hccl {
18 : // 订阅事件相关的参数
19 : struct CpuSendInfo {
20 : int32_t devId;
21 : uint32_t grpId;
22 : uint32_t threadId;
23 : uint64_t eventBitMap;
24 : };
25 :
26 : class EschedNotify : public NotifyBase {
27 : public:
28 : explicit EschedNotify(NotifyType notifyType);
29 : EschedNotify(NotifyType notifyType, HcclNotifyInfo notifyInfo);
30 : ~EschedNotify() override;
31 :
32 : HcclResult Alloc() override;
33 : HcclResult Open() override;
34 : HcclResult Close() override;
35 :
36 : HcclResult Wait(Stream& stream, HcclDispatcher dispatcher, s32 stage, u32 timeOut) override;
37 : HcclResult Post(Stream& stream, HcclDispatcher dispatcher, s32 stage) override;
38 :
39 : HcclResult
40 : Wait(Stream& stream, HcclDispatcher dispatcher, s32 stage, u32 timeOut, u32 userRank, u32 remoteUserRank) override;
41 : HcclResult Wait(Stream& stream, u32 timeOut) override;
42 : HcclResult Post(Stream& stream, HcclDispatcher dispatcher, s32 stage, u32 remoteUserRank) override;
43 : HcclResult Post(Stream& stream) override;
44 :
45 : HcclResult SetIpc() override;
46 : HcclResult Grant(s64 recvId) override;
47 : HcclResult Destroy() override;
48 : void Break() override;
49 :
50 0 : static void SetEventIdAndTid(const u32& eventId, const u32& tid)
51 : {
52 0 : eventId_ = eventId;
53 0 : initialThreadId_ = tid;
54 0 : return;
55 : }
56 :
57 : static void ThreadIdQueInit();
58 :
59 : private:
60 : HcclResult ThreadIdCreate(uint32_t& threadId);
61 :
62 : static HcclResult InitGroupId();
63 : static HcclResult GetGroupId();
64 :
65 : bool isDestroyed{false};
66 : CpuSendInfo sendinfo_{};
67 : std::atomic<bool> break_ = {false};
68 : std::atomic<bool> isWaiting_ = {false};
69 :
70 : static u32 groupId_;
71 : static u32 eventId_;
72 : static u32 initialThreadId_;
73 : };
74 :
75 : } // namespace hccl
76 :
77 : #endif // ESCHED_NOTIFY_H
|