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