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