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 : #include "local_notify.h"
11 : #include "local_notify_impl.h"
12 :
13 : namespace hccl {
14 :
15 4503 : LocalNotify::LocalNotify()
16 : {
17 4503 : }
18 :
19 4506 : LocalNotify::~LocalNotify()
20 : {
21 4506 : Destroy();
22 4506 : }
23 :
24 993 : HcclResult LocalNotify::Init(const NotifyLoadType type)
25 : {
26 993 : notifyOwner_ = true; // host侧需要申请新的notify资源
27 993 : pimpl_.reset((new (std::nothrow) LocalNotifyImpl()));
28 994 : CHK_SMART_PTR_NULL(pimpl_);
29 992 : HcclResult ret = pimpl_->Init(type);
30 1000 : if (ret != HCCL_SUCCESS) {
31 4 : pimpl_ = nullptr;
32 4 : HCCL_ERROR("[LocalNotify]Init failed, ret[%d]", ret);
33 4 : return ret;
34 : }
35 :
36 : HcclSignalInfo notifyInfo;
37 996 : CHK_RET(pimpl_->GetNotifyData(notifyInfo));
38 997 : notifyId_ = static_cast<u32>(notifyInfo.resId);
39 :
40 997 : notifyPtr = pimpl_->ptr();
41 995 : return HCCL_SUCCESS;
42 : }
43 :
44 3218 : HcclResult LocalNotify::Init(const HcclSignalInfo &signalInfo, const NotifyLoadType type)
45 : {
46 3218 : notifyOwner_ = false; // aicpu侧不需要申请新的notify资源
47 3218 : pimpl_.reset((new (std::nothrow) LocalNotifyImpl()));
48 3218 : CHK_SMART_PTR_NULL(pimpl_);
49 3218 : HcclResult ret = pimpl_->Init(signalInfo, type);
50 3218 : if (ret != HCCL_SUCCESS) {
51 0 : pimpl_ = nullptr;
52 0 : HCCL_ERROR("[LocalNotify]Init failed, ret[%d]", ret);
53 0 : return ret;
54 : }
55 :
56 : HcclSignalInfo notifyInfo;
57 3218 : CHK_RET(pimpl_->GetNotifyData(notifyInfo));
58 3218 : notifyId_ = static_cast<u32>(notifyInfo.resId);
59 :
60 3218 : notifyPtr = pimpl_->ptr();
61 3218 : return HCCL_SUCCESS;
62 : }
63 :
64 273 : HcclResult LocalNotify::InitNotifyLite(const HcclSignalInfo ¬ifyInfo)
65 : {
66 273 : notifyOwner_ = false; // aicpu侧不需要申请新的notify资源
67 273 : notifyId_ = static_cast<u32>(notifyInfo.resId);
68 273 : HCCL_INFO("[LocalNotify]Init success. notify id [%u]", notifyId_);
69 273 : return HCCL_SUCCESS;
70 : }
71 :
72 0 : HcclResult LocalNotify::Wait(Stream& stream, HcclDispatcher dispatcher, s32 stage, u32 timeOut)
73 : {
74 0 : return pimpl_->Wait(stream, dispatcher, stage, timeOut);
75 : }
76 :
77 1 : HcclResult LocalNotify::Wait(Stream& stream, u32 timeOut)
78 : {
79 1 : return pimpl_->Wait(stream, timeOut);
80 : }
81 :
82 0 : HcclResult LocalNotify::Post(Stream& stream, HcclDispatcher dispatcher, s32 stage)
83 : {
84 0 : return pimpl_->Post(stream, dispatcher, stage);
85 : }
86 :
87 1 : HcclResult LocalNotify::Post(Stream& stream)
88 : {
89 1 : return pimpl_->Post(stream);
90 : }
91 :
92 0 : HcclResult LocalNotify::Wait(Stream& stream, HcclDispatcher dispatcherPtr, const std::shared_ptr<LocalNotify> ¬ify,
93 : s32 stage, u32 timeOut)
94 : {
95 0 : CHK_PTR_NULL(dispatcherPtr);
96 0 : CHK_SMART_PTR_NULL(notify);
97 :
98 0 : return reinterpret_cast<DispatcherPub*>(dispatcherPtr)->SignalWait(
99 0 : notify->ptr(), stream, INVALID_VALUE_RANKID, INVALID_VALUE_RANKID, stage, true, notify->notifyId_, timeOut);
100 : }
101 :
102 0 : HcclResult LocalNotify::Post(Stream& stream, HcclDispatcher dispatcherPtr, const std::shared_ptr<LocalNotify> ¬ify,
103 : s32 stage)
104 : {
105 0 : CHK_PTR_NULL(dispatcherPtr);
106 0 : CHK_SMART_PTR_NULL(notify);
107 :
108 0 : return reinterpret_cast<DispatcherPub*>(dispatcherPtr)->SignalRecord(
109 0 : notify->ptr(), stream, INVALID_VALUE_RANKID, INVALID_U64, stage, true, INVALID_U64, notify->notifyId_);
110 : }
111 :
112 5040 : HcclResult LocalNotify::Destroy()
113 : {
114 5040 : if (notifyOwner_ == true && pimpl_ != nullptr) {
115 998 : pimpl_->Destroy();
116 998 : pimpl_ = nullptr;
117 998 : notifyPtr = nullptr;
118 : }
119 5040 : return HCCL_SUCCESS;
120 : }
121 :
122 63 : HcclResult LocalNotify::SetIpc()
123 : {
124 63 : return pimpl_->SetIpc();
125 : }
126 :
127 :
128 2777 : HcclResult LocalNotify::GetNotifyData(HcclSignalInfo ¬ifyInfo)
129 : {
130 2777 : return pimpl_->GetNotifyData(notifyInfo);
131 : }
132 :
133 0 : HcclResult LocalNotify::SetNotifyData(HcclSignalInfo ¬ifyInfo)
134 : {
135 0 : return pimpl_->SetNotifyData(notifyInfo);
136 : }
137 :
138 0 : HcclResult LocalNotify::GetNotifyOffset(u64 ¬ifyOffset)
139 : {
140 0 : return pimpl_->GetNotifyOffset(notifyOffset);
141 : }
142 : }
|