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 : #include "local_notify_impl.h"
12 : #include "rts_notify.h"
13 : #include "bare_notify.h"
14 : #include "esched_notify.h"
15 :
16 : namespace hccl {
17 : std::atomic<bool> LocalNotifyImpl::tidQueueInit_ = {false};
18 4240 : LocalNotifyImpl::LocalNotifyImpl()
19 : {
20 4240 : }
21 :
22 4240 : LocalNotifyImpl::~LocalNotifyImpl()
23 : {
24 4240 : }
25 :
26 1011 : HcclResult LocalNotifyImpl::Init(const NotifyLoadType type)
27 : {
28 1011 : if (type == NotifyLoadType::DEVICE_NOTIFY) {
29 479 : notify_.reset(new (std::nothrow) RtsNotify(NotifyType::RUNTIME_NOTIFY_MC2));
30 : } else {
31 532 : notify_.reset(new (std::nothrow) RtsNotify(NotifyType::RUNTIME_NOTIFY));
32 : }
33 :
34 1011 : HCCL_DEBUG("[Create][LocalNotify]notify load type[%d].", type);
35 :
36 1015 : CHK_SMART_PTR_NULL(notify_);
37 :
38 1015 : CHK_RET(notify_->Alloc());
39 1011 : return HCCL_SUCCESS;
40 : }
41 :
42 1 : HcclResult LocalNotifyImpl::Init(const s32 localDeviceId,
43 : const s32 remoteDeviceId, const NotifyLoadType type)
44 : {
45 1 : if (type == NotifyLoadType::DEVICE_NOTIFY) {
46 1 : notify_.reset(new (std::nothrow) RtsNotify(NotifyType::RUNTIME_NOTIFY_MC2));
47 : } else {
48 0 : if (localDeviceId != HOST_DEVICE_ID && remoteDeviceId != HOST_DEVICE_ID) {
49 0 : notify_.reset(new (std::nothrow) RtsNotify(NotifyType::RUNTIME_NOTIFY));
50 0 : } else if (localDeviceId != HOST_DEVICE_ID && remoteDeviceId == HOST_DEVICE_ID) {
51 0 : notify_.reset(new (std::nothrow) BareNotify(NotifyType::BARE_NOTIFY));
52 0 : } else if (localDeviceId == HOST_DEVICE_ID && remoteDeviceId != HOST_DEVICE_ID) {
53 0 : if (!tidQueueInit_) {
54 0 : EschedNotify::ThreadIdQueInit();
55 0 : tidQueueInit_ = true;
56 : }
57 0 : notify_.reset(new (std::nothrow) EschedNotify(NotifyType::ESCHED_EVENT));
58 : } else {
59 0 : HCCL_ERROR("[Create][LocalNotify]not support create notify, notify load type[%d], localDeviceId[%d], "
60 : "remoteDeviceId[%d]", type, localDeviceId, remoteDeviceId);
61 : }
62 : }
63 :
64 1 : HCCL_DEBUG("[Create][LocalNotify]notify load type[%d], localDeviceId[%d], remoteDeviceId[%d].",
65 : type, localDeviceId, remoteDeviceId);
66 :
67 1 : CHK_SMART_PTR_NULL(notify_);
68 :
69 1 : CHK_RET(notify_->Alloc());
70 1 : return HCCL_SUCCESS;
71 : }
72 :
73 3224 : HcclResult LocalNotifyImpl::Init(const HcclSignalInfo ¬ifyInfo, const NotifyLoadType type)
74 : {
75 3224 : if (type == NotifyLoadType::DEVICE_NOTIFY) {
76 3221 : notify_.reset(new (std::nothrow) RtsNotify(NotifyType::RUNTIME_NOTIFY_MC2, notifyInfo));
77 : } else {
78 3 : notify_.reset(new (std::nothrow) RtsNotify(NotifyType::RUNTIME_NOTIFY, notifyInfo));
79 : }
80 :
81 3224 : HCCL_DEBUG("[Create][LocalNotify]notify load type[%d].", type);
82 :
83 3224 : CHK_SMART_PTR_NULL(notify_);
84 :
85 : #ifdef CCL_KERNEL
86 3224 : if (type == NotifyLoadType::DEVICE_NOTIFY) {
87 3221 : CHK_RET(static_cast<RtsNotify*>(notify_.get())->InitAndVerifySingleSignal());
88 : }
89 : #endif
90 :
91 3224 : return HCCL_SUCCESS;
92 : }
93 :
94 0 : HcclResult LocalNotifyImpl::Wait(Stream& stream, HcclDispatcher dispatcher, s32 stage, u32 timeOut)
95 : {
96 0 : return notify_->Wait(stream, dispatcher, stage, timeOut);
97 : }
98 :
99 0 : HcclResult LocalNotifyImpl::Post(Stream& stream, HcclDispatcher dispatcher, s32 stage)
100 : {
101 0 : return notify_->Post(stream, dispatcher, stage);
102 : }
103 :
104 1 : HcclResult LocalNotifyImpl::Post(Stream& stream)
105 : {
106 1 : return notify_->Post(stream);
107 : }
108 :
109 0 : HcclResult LocalNotifyImpl::Wait(Stream& stream, HcclDispatcher dispatcher, s32 stage, u32 timeOut,
110 : u32 userRank, u32 remoteUserRank)
111 : {
112 0 : return notify_->Wait(stream, dispatcher, stage, timeOut, userRank, remoteUserRank);
113 : }
114 :
115 1 : HcclResult LocalNotifyImpl::Wait(Stream& stream, u32 timeOut)
116 : {
117 1 : return notify_->Wait(stream, timeOut);
118 : }
119 :
120 0 : HcclResult LocalNotifyImpl::Post(Stream& stream, HcclDispatcher dispatcher, s32 stage,
121 : u32 remoteUserRank)
122 : {
123 0 : return notify_->Post(stream, dispatcher, stage, remoteUserRank);
124 : }
125 :
126 71 : HcclResult LocalNotifyImpl::SetIpc()
127 : {
128 71 : return notify_->SetIpc();
129 : }
130 :
131 0 : HcclResult LocalNotifyImpl::Grant(s64 recvId)
132 : {
133 0 : return notify_->Grant(recvId);
134 : }
135 :
136 1012 : HcclResult LocalNotifyImpl::Destroy()
137 : {
138 1012 : HcclResult ret = HCCL_SUCCESS;
139 1012 : if (notify_) {
140 1012 : ret = notify_->Destroy();
141 : }
142 1012 : notify_ = nullptr;
143 1012 : return ret;
144 : }
145 :
146 1 : HcclResult LocalNotifyImpl::Serialize(std::vector<u8> &byteVector)
147 : {
148 1 : return notify_->Serialize(byteVector);
149 : }
150 :
151 7006 : HcclResult LocalNotifyImpl::GetNotifyData(HcclSignalInfo ¬ifyInfo)
152 : {
153 7006 : return notify_->GetNotifyData(notifyInfo);
154 : }
155 :
156 0 : HcclResult LocalNotifyImpl::SetNotifyData(HcclSignalInfo ¬ifyInfo)
157 : {
158 0 : return notify_->SetNotifyData(notifyInfo);
159 : }
160 :
161 7 : HcclResult LocalNotifyImpl::GetNotifyOffset(u64 ¬ifyOffset)
162 : {
163 7 : return notify_->GetNotifyOffset(notifyOffset);
164 : }
165 :
166 0 : void LocalNotifyImpl::Break()
167 : {
168 0 : return notify_->Break();
169 : }
170 :
171 0 : void LocalNotifyImpl::SetEventIdAndTid(const u32 eventId, const u32 tid)
172 : {
173 0 : EschedNotify::SetEventIdAndTid(eventId, tid);
174 0 : return;
175 : }
176 : }
|