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),
34 237 : ccuInsPreprocessor(comm),
35 237 : aivInsPreprocessor(comm),
36 237 : aicpuInsPreprocessor(comm),
37 237 : mc2Compont(comm),
38 711 : aivMc2Compont(comm)
39 237 : {}
40 :
41 : void Init() override;
42 : // 单算子
43 : void LoadWithOpBasedMode(CollOperator& op, std::unique_ptr<Stream> stream) override;
44 : // 图模式
45 : void LoadWithOffloadMode(CollOperator& op, std::unique_ptr<Stream> stream) override;
46 :
47 : // MC2 CCU用
48 : void AllocCommResource(void* mc2Tiling, void** commContext, const AcceleratorState& tilingAccelerator) override;
49 : void GetCcuTaskInfo(void* tilingData, void* ccuTaskGroup) override;
50 : u32 GetCcuMc2ServerNum() override;
51 : CcuInsPreprocessor* GetCcuInsPreprocessor();
52 : AivInsPreprocessor* GetAivInsPreprocessor();
53 : std::vector<LinkData> GetUniqueLinks(std::shared_ptr<InsQueue>& insQueue) const;
54 : // Aicpu用
55 : AicpuInsPreprocessor* GetAicpuInsPreprocessor();
56 : bool IsAicpuResExisted(std::string algName);
57 : DevBuffer* GetAicpuResBuffer(std::string algName);
58 :
59 : // 快照保存和恢复场景使用
60 : void RecoverTransport(vector<LinkData>& links, vector<std::pair<LinkGroup, u32>> linkGroupPair) override;
61 : void RecoverCcuTransport(vector<LinkData>& links, vector<std::pair<LinkGroup, u32>> linkGroupPair);
62 : HcclResult GetSnapShotDynamicBuf(CollOperator& op, BinaryStream& buf) override;
63 : bool IsAllTransportRecoveredReady(const std::string& opTag) override;
64 :
65 2 : const Mc2Compont& GetMc2Compont() const { return mc2Compont; }
66 : const AivMc2Compont& GetAivMc2Compont() const { return aivMc2Compont; }
67 : // N秒快恢场景使用
68 : void Resume() override;
69 :
70 : HcclResult GetAlgExecParam(bool clearEnable, u32 numBlocks, void*& commContext, u64& len) override;
71 :
72 : private:
73 : CcuInsPreprocessor ccuInsPreprocessor;
74 : AivInsPreprocessor aivInsPreprocessor;
75 : AicpuInsPreprocessor aicpuInsPreprocessor;
76 : AicpuStreamManager aicpuStreamManager;
77 :
78 : Mc2Compont mc2Compont;
79 : AivMc2Compont aivMc2Compont;
80 : std::unordered_set<u32> captureModelIds;
81 :
82 : std::shared_ptr<InsQueue> Orchestrate(const CollAlgOperator& op) 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(
89 : const AivOpArgs& aivOpArgs, bool clearEnable, u32 numBlocks, AivSuperKernelArgs& superArgs) const;
90 : };
91 :
92 : } // namespace Hccl
93 :
94 : #endif // COLL_SERVICE_DEVICE_MODE_H
|