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 NOTIFY_MANAGER_H
12 : #define NOTIFY_MANAGER_H
13 :
14 : #include "local_notify.h"
15 : #include "hccl_common.h"
16 : #include "hccl/hccl_res.h"
17 : #include "hccl_independent_common.h"
18 : #include "manager_common.h"
19 :
20 : namespace hccl {
21 :
22 : class NotifyManager {
23 : struct NotifyInfo {
24 : CommEngine commEngine;
25 : ::NotifyType notifyType;
26 : bool isAicpu;
27 : NotifyHandle notifyHandle;
28 : };
29 : public:
30 :
31 : #ifndef CCL_KERNEL_AICPU
32 : NotifyManager(std::string commId, aclrtBinHandle binHandle, const ManagerCallbacks& callbacks);
33 332 : ~NotifyManager() = default;
34 : #endif
35 :
36 : static HcclResult ParseBinNotifys(const std::string& uniqueIdStr,
37 : std::vector<std::unique_ptr<LocalNotify>> &newNotifys);
38 : #ifndef CCL_KERNEL_AICPU
39 : static std::string GetBinNotifys(std::vector<std::unique_ptr<LocalNotify>> &newNotifys,
40 : const NotifyLoadType notifyType);
41 :
42 : HcclResult HcclAllocNotify(CommEngine commEngine, ::NotifyType notifyType, uint32_t notifyNum,
43 : NotifyHandle **notifyHandleList);
44 : HcclResult HcommFreeNotify(uint32_t notifyNum, NotifyHandle *notifyHandleList);
45 :
46 : inline LocalNotify* GetNotify(u32 index) const {
47 : if (index > notifyNum_) {
48 : HCCL_ERROR("[NotifyManager][GetNotify]notifyNum[%u], notifyIdx[%u] out of range, maxIndex[%u]", \
49 : notifyNum_, index, (notifyNum_ == 0 ? 0 : notifyNum_ - 1));
50 : return nullptr;
51 : }
52 : return notifys_[index].get();
53 : }
54 :
55 : inline u32 GetNotifyNum()
56 : {
57 : return notifyNum_;
58 : }
59 : #endif
60 : private:
61 : static HcclResult InitNotifys(std::istringstream &iss, size_t notifyNum,
62 : std::vector<std::unique_ptr<LocalNotify>> &newNotifys);
63 : #ifndef CCL_KERNEL_AICPU
64 : HcclResult NotifyTypeToNotifyLoadType(::NotifyType notifyType, NotifyLoadType ¬ifyLoadType);
65 : std::string commId_;
66 : aclrtBinHandle binHandle_;
67 : std::mutex notifyMutex_;
68 : bool isDeviceSide_ = false;
69 : u32 notifyNum_ = 0;
70 : std::vector<std::unique_ptr<LocalNotify>> notifys_;
71 : std::vector<std::unique_ptr<NotifyHandle[]>> handleBlocks_; // 托管所有 handle 数组
72 : std::unordered_map<LocalNotify*, NotifyInfo> notifysInfo_;
73 : ManagerCallbacks callbacks_;
74 : #endif
75 : };
76 : }
77 :
78 : #endif
|