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 AICPU_TS_THREAD_H
12 : #define AICPU_TS_THREAD_H
13 :
14 : #include <vector>
15 : #include <functional>
16 : #include "thread.h"
17 : #include "aicpu_ts_thread_interface.h"
18 : #include "dfx_circular_queue.h"
19 :
20 : namespace hccl {
21 : class AicpuTsThread : public Thread {
22 : public:
23 : AicpuTsThread(StreamType streamType, uint32_t notifyNum, const NotifyLoadType notifyLoadType);
24 : AicpuTsThread(const std::string& uniqueIdStr);
25 :
26 : ~AicpuTsThread();
27 :
28 : HcclResult Init() override;
29 : HcclResult DeInit() override;
30 : std::string& GetUniqueId() override;
31 : uint32_t GetNotifyNum() const override;
32 : LocalNotify* GetNotify(uint32_t index) const override;
33 : HcclResult GetNotifyByUniqueId(u32& notifyNum, std::string& notifyDesc);
34 : HcclResult SupplementNotify(uint32_t notifyNum) override;
35 : HcclResult SupplementNotify(u32 notifyNum, const std::string& notifyDesc);
36 :
37 : // A3 Stream & A5 Stream
38 48 : inline bool IsDeviceA5() const override
39 : {
40 48 : return devType_ == DevType::DEV_TYPE_950 || devType_ == DevType::DEV_TYPE_960;
41 : }
42 :
43 : Stream* GetStream() const override;
44 :
45 68 : inline void* GetStreamLitePtr() const override { return pImpl_ ? pImpl_->GetStreamLitePtr() : nullptr; }
46 :
47 : void LaunchTask() const override;
48 : void TryLaunchTask() const override;
49 :
50 : // Local Data Plane Functions
51 : HcclResult LocalNotifyWait(uint32_t notifyId) const override;
52 : HcclResult LocalNotifyRecord(uint32_t notifyId) const override;
53 :
54 : HcclResult LocalNotifyRecord(ThreadHandle dstThread, uint32_t dstNotifyIdx) const override;
55 : HcclResult LocalNotifyWait(uint32_t notifyId, uint32_t timeout) const override;
56 :
57 : HcclResult LocalCopy(void* dst, const void* src, uint64_t size) const override;
58 : HcclResult LocalReduce(
59 : void* dst, const void* src, uint64_t size, HcommDataType dataType, HcommReduceOp reduceOp) const override;
60 :
61 : // Non-override functions
62 : HcclResult GetSqHeadAndTail(uint32_t& sqHead, uint32_t& sqTail);
63 : bool GetMaster() const override;
64 : void SetIsMaster(bool isMaster) override;
65 :
66 : HcclResult SetCheckExecStatusCallback(std::function<HcclResult(bool)> callback) override;
67 :
68 : Hccl::TaskInfoCircularQueue* GetTaskInfos() const;
69 : HcclResult GetTaskInfoCount(u32& count) const;
70 : void SetReportStreamTaskCallback(std::function<void(Hccl::TaskInfoCircularQueue*)> callback);
71 : void SetGetLatestDfxOpInfoCallback(std::function<const void*()> callback);
72 :
73 : private:
74 : struct HcclStreamInfo {
75 : s32 streamIds;
76 : uint32_t sqIds;
77 : uint32_t cqIds; // 记录物理cqId
78 : uint32_t logicCqids; // 记录逻辑cqId
79 : };
80 :
81 : struct HcclStreamParam {
82 : HcclStreamInfo streamInfo;
83 : uint64_t sqCqContextAddr = 0; // 记录sqeContext地址
84 : uint64_t sqCqContextSize = 0; // 记录sqeContext大小
85 : };
86 : HcclResult InitStreamLite(HcclStreamInfo& streamParam, uint32_t hostPhyId);
87 : HcclResult InitStream(HcclStreamParam& streamParam);
88 : HcclResult HostInit();
89 : HcclResult DeviceInit();
90 : std::string& UpdateUniqueId();
91 : #ifdef CCL_KERNEL_AICPU
92 : HcclResult BuildComStreamInfo(const HcclStreamInfo& streamInfo, HcclComStreamInfo& comStreamInfo) const;
93 : #endif
94 : template <typename Operation, typename ReportOp>
95 : HcclResult LocalProcess(void* dst, const void* src, uint64_t size, Operation&& op, ReportOp&& reportOp) const;
96 :
97 : // 成员变量(适配 AICPU-TS)
98 : bool isDeviceSide_ = false;
99 : rtStream_t rtStream_ = nullptr;
100 : StreamType streamType_ = StreamType::STREAM_TYPE_RESERVED;
101 : uint32_t notifyNum_ = 0;
102 : NotifyLoadType notifyLoadType_ = NotifyLoadType::HOST_NOTIFY;
103 : uint32_t devId_ = INVALID_UINT;
104 : std::unique_ptr<Stream> stream_ = nullptr;
105 : std::vector<std::unique_ptr<LocalNotify>> notifys_;
106 : std::string uniqueIdStr_;
107 : DeviceMem sqCqeContext_;
108 : DevType devType_ = DevType::DEV_TYPE_COUNT;
109 : std::unique_ptr<Hccl::IAicpuTsThread> pImpl_{nullptr};
110 : bool isMaster_{false};
111 : };
112 :
113 : } // namespace hccl
114 : #endif // AICPU_TS_THREAD_H
|