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 "remote_notify_impl.h"
12 : #include "rts_notify.h"
13 : #include "bare_notify.h"
14 : #include "esched_notify.h"
15 :
16 : namespace hccl {
17 1127 : RemoteNotifyImpl::RemoteNotifyImpl() {}
18 :
19 1127 : RemoteNotifyImpl::~RemoteNotifyImpl() {}
20 :
21 1 : HcclResult RemoteNotifyImpl::Init(const std::vector<u8>& byteVector)
22 : {
23 1 : HcclNotifyInfo notifyInfo;
24 1 : CHK_RET(NotifyBase::Deserialize(byteVector, notifyInfo));
25 1 : NotifyType notifyType = static_cast<NotifyType>(notifyInfo.type);
26 :
27 1 : HCCL_DEBUG("[RemoteNotifyImpl]notifyType[%u], remote withIpc[%d].", notifyInfo.type, notifyInfo.ipcNotify.withIpc);
28 :
29 1 : switch (notifyType) {
30 1 : case NotifyType::RUNTIME_NOTIFY:
31 : case NotifyType::RUNTIME_NOTIFY_MC2: {
32 1 : notify_.reset(new (std::nothrow) RtsNotify(notifyType, notifyInfo));
33 1 : break;
34 : }
35 :
36 0 : case NotifyType::BARE_NOTIFY: {
37 0 : notify_.reset(new (std::nothrow) BareNotify(notifyType, notifyInfo));
38 0 : break;
39 : }
40 :
41 0 : case NotifyType::ESCHED_EVENT: {
42 0 : notify_.reset(new (std::nothrow) EschedNotify(notifyType, notifyInfo));
43 0 : break;
44 : }
45 :
46 0 : default: {
47 0 : HCCL_ERROR("[Create][RemoteNotify]No specified notify type[%d]!", notifyType);
48 0 : break;
49 : }
50 : }
51 :
52 1 : CHK_SMART_PTR_NULL(notify_);
53 1 : return HCCL_SUCCESS;
54 : }
55 :
56 1126 : HcclResult RemoteNotifyImpl::Init(const HcclSignalInfo& notifyInfo, const NotifyLoadType type)
57 : {
58 1126 : if (type == NotifyLoadType::DEVICE_NOTIFY) {
59 1126 : notify_.reset(new (std::nothrow) RtsNotify(NotifyType::RUNTIME_NOTIFY_MC2, notifyInfo));
60 : } else {
61 0 : notify_.reset(new (std::nothrow) RtsNotify(NotifyType::RUNTIME_NOTIFY, notifyInfo));
62 : }
63 :
64 1126 : HCCL_DEBUG("[Create][LocalNotify]notify load type[%d]. notifyInfo.resId[%u]", type, notifyInfo.resId);
65 :
66 1126 : CHK_SMART_PTR_NULL(notify_);
67 :
68 : #ifdef CCL_KERNEL
69 1126 : CHK_RET(static_cast<RtsNotify*>(notify_.get())->InitAndVerifySingleSignal());
70 : #endif
71 :
72 1126 : return HCCL_SUCCESS;
73 : }
74 :
75 1 : HcclResult RemoteNotifyImpl::Open() { return notify_->Open(); }
76 :
77 4 : HcclResult RemoteNotifyImpl::Close()
78 : {
79 4 : if (notify_) {
80 4 : return notify_->Close();
81 : }
82 0 : notify_ = nullptr;
83 0 : return HCCL_SUCCESS;
84 : }
85 :
86 0 : HcclResult RemoteNotifyImpl::Post(Stream& stream, HcclDispatcher dispatcher, s32 stage)
87 : {
88 0 : return notify_->Post(stream, dispatcher, stage);
89 : }
90 :
91 1131 : HcclResult RemoteNotifyImpl::GetNotifyData(HcclSignalInfo& notifyInfo) { return notify_->GetNotifyData(notifyInfo); }
92 :
93 3 : HcclResult RemoteNotifyImpl::SetNotifyData(HcclSignalInfo& notifyInfo) { return notify_->SetNotifyData(notifyInfo); }
94 :
95 4 : HcclResult RemoteNotifyImpl::GetNotifyOffset(u64& notifyOffset) { return notify_->GetNotifyOffset(notifyOffset); }
96 : } // namespace hccl
|