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_INS_PREPROCESSOR_H
12 : #define AICPU_INS_PREPROCESSOR_H
13 :
14 : #include <unordered_map>
15 : #include <memory>
16 : #include "aicpu_ins.h"
17 : #include "ins_queue.h"
18 : #include "dev_buffer.h"
19 : #include "communicator_impl.h"
20 : #include "virtual_topo.h"
21 : #include "connections_builder.h"
22 :
23 : namespace Hccl {
24 :
25 : class AicpuInsPreprocessor {
26 : public:
27 : using InsIterator = HierarchicalQueue<Instruction, InsQueue>::Iterator;
28 :
29 244 : explicit AicpuInsPreprocessor(CommunicatorImpl* comm) : comm(comm) {}
30 :
31 : void Preprocess(std::shared_ptr<InsQueue>& insQueue);
32 :
33 : // AlltoallV算子使用
34 : void SetAicpuKernelLaunchParam(HcclKernelLaunchParam& param);
35 : bool IsAicpuResExisted(const std::string& algName);
36 : void SetAicpuResExisted(const std::string& algName);
37 : DevBuffer* GetAicpuResBuffer(const std::string& algName);
38 :
39 : private:
40 : CommunicatorImpl* comm;
41 : std::unordered_map<std::string, std::shared_ptr<DevBuffer>> aicpuResMap; // 集合通信算子资源加载到device侧的内存
42 : std::unordered_map<std::string, bool> aicpuResExistedMap;
43 :
44 : std::set<LinkData> availableLinks;
45 : unordered_map<std::string, unique_ptr<ConnectionsBuilder>> connectionsBuilders;
46 :
47 : // AlltoallV算子使用
48 : std::vector<std::shared_ptr<DevBuffer>> sendCountsMem{};
49 : std::vector<std::shared_ptr<DevBuffer>> recvCountsMem{};
50 : std::vector<std::shared_ptr<DevBuffer>> sdisplsMem{};
51 : std::vector<std::shared_ptr<DevBuffer>> rdisplsMem{};
52 : bool isCountMemInited{false};
53 : u32 resIndex{0};
54 : u32 launchResIndex{0};
55 :
56 : void InsPreprocess(InsIterator& insIter);
57 :
58 : void AllocQueueNotify(std::vector<std::tuple<QId, QId, u32>>& queueNotifyReq) const;
59 : void AllocBcastPostCntNotify(std::vector<std::pair<QId, u32>>& bcastPostCntNotifyReq) const;
60 : void AllocWaitGroupCntNotify(std::vector<std::pair<QId, u32>>& waitGroupCntNotifyReq) const;
61 : void AllocWorkStream(u32 primQueueNum) const;
62 : void AllocInterRankNotifies(const vector<LinkData>& links);
63 : void BatchBuildTransports(const vector<LinkData>& links);
64 :
65 : void PackResAndCopyToDev(const std::string& algName, const CollAlgResReq& collAlgResReq);
66 :
67 : // AlltoallV算子使用
68 : void AllocAlltoallVOpMem();
69 :
70 : std::vector<char> PackOpData(const std::string& opTag, const std::string& algName, const CollAlgResReq& resReq);
71 : };
72 :
73 : } // namespace Hccl
74 :
75 : #endif // AICPU_INS_PREPROCESSOR_H
|