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 COLL_SERVICE_DEVICE_MODE_H
12 : #define COLL_SERVICE_DEVICE_MODE_H
13 :
14 : #include <memory>
15 : #include "coll_service_base.h"
16 : #include "communicator_impl.h"
17 : #include "ins_queue.h"
18 : #include "ccu_communicator.h"
19 : #include "ccu_ins_preprocessor.h"
20 : #include "aicpu_ins_preprocessor.h"
21 : #include "mc2_compont.h"
22 : #include "aicpu_stream_manager.h"
23 : #include "aiv_mc2_compont.h"
24 : #include "aiv_ins_preprocessor.h"
25 : #include "aiv_ins.h"
26 : #include "hccl_aiv_utils.h"
27 :
28 : namespace Hccl {
29 :
30 : class CollServiceDeviceMode : public CollServiceBase {
31 : public:
32 237 : explicit CollServiceDeviceMode(CommunicatorImpl *comm)
33 237 : : CollServiceBase(comm), ccuInsPreprocessor(comm), aivInsPreprocessor(comm), aicpuInsPreprocessor(comm),
34 474 : mc2Compont(comm), aivMc2Compont(comm)
35 : {
36 237 : }
37 :
38 : void Init() override;
39 : // 单算子
40 : void LoadWithOpBasedMode(CollOperator &op, std::unique_ptr<Stream> stream) override;
41 : // 图模式
42 : void LoadWithOffloadMode(CollOperator &op, std::unique_ptr<Stream> stream) override;
43 :
44 : // MC2 CCU用
45 : void AllocCommResource(void *mc2Tiling, void **commContext, const AcceleratorState& tilingAccelerator) override;
46 : void GetCcuTaskInfo(void *tilingData, void *ccuTaskGroup) override;
47 : u32 GetCcuMc2ServerNum() override;
48 : CcuInsPreprocessor *GetCcuInsPreprocessor();
49 : AivInsPreprocessor *GetAivInsPreprocessor();
50 : std::vector<LinkData> GetUniqueLinks(std::shared_ptr<InsQueue> &insQueue) const;
51 : // Aicpu用
52 : AicpuInsPreprocessor *GetAicpuInsPreprocessor();
53 : bool IsAicpuResExisted(std::string algName);
54 : DevBuffer *GetAicpuResBuffer(std::string algName);
55 :
56 : // 快照保存和恢复场景使用
57 : void RecoverTransport(vector<LinkData> &links, vector<std::pair<LinkGroup, u32>> linkGroupPair) override;
58 : void RecoverAicpuTransport(vector<LinkData> &links) const;
59 : void RecoverCcuTransport(vector<LinkData> &links, vector<std::pair<LinkGroup, u32>> linkGroupPair);
60 : HcclResult GetSnapShotDynamicBuf(CollOperator &op,BinaryStream &buf) override;
61 : bool IsAllTransportRecoveredReady(const std::string &opTag) override;
62 :
63 2 : const Mc2Compont& GetMc2Compont() const { return mc2Compont; }
64 : const AivMc2Compont& GetAivMc2Compont() const { return aivMc2Compont; }
65 : // N秒快恢场景使用
66 : void Resume() override;
67 :
68 : HcclResult GetAlgExecParam(bool clearEnable, u32 numBlocks, void *&commContext, u64 &len) override;
69 : private:
70 : CcuInsPreprocessor ccuInsPreprocessor;
71 : AivInsPreprocessor aivInsPreprocessor;
72 : AicpuInsPreprocessor aicpuInsPreprocessor;
73 : AicpuStreamManager aicpuStreamManager;
74 :
75 : Mc2Compont mc2Compont;
76 : AivMc2Compont aivMc2Compont;
77 : std::unordered_set<u32> captureModelIds;
78 :
79 : std::shared_ptr<InsQueue> Orchestrate(const CollAlgOperator &op) const;
80 :
81 : // aicpu展开模式单算子快照恢复使用
82 : void RecoverInterRankNotifies(const vector<LinkData> &links) const;
83 :
84 : // AIV场景Acl Graph专用
85 : HcclResult HandleAclGraphFirstOpAivBuff(rtStream_t mainStream);
86 : // 生成AivOpArgs,AIV superKernel
87 : HcclResult GenerateAivOpArgs(const AivInstruction &aivInstruction, AivOpArgs& aivOpArgs) const;
88 : void GeneratorAivSuperKernelArgs(const AivOpArgs &aivOpArgs, bool clearEnable, u32 numBlocks,
89 : AivSuperKernelArgs &superArgs) const;
90 : };
91 :
92 : } // namespace Hccl
93 :
94 : #endif // COLL_SERVICE_DEVICE_MODE_H
|