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 OP_BASE_H
12 : #define OP_BASE_H
13 :
14 : #include <vector>
15 : #include <hccl/hccl_comm.h>
16 : #include <hccl/hccl_inner.h>
17 : #include <hccl/hccl_types.h>
18 :
19 : #include "op_base_pub.h"
20 : #include "hccl_comm_pub.h"
21 : // ltm指定config路径
22 : #include "common/src/config.h"
23 : #include "../common/src/topo/topoinfo_detect.h"
24 : #include "op_base_v2.h"
25 :
26 : using HcclOpInfoCtx = struct HcclInfoTag {
27 : HcclCommPtr pComm;
28 : hccl::HcclCommParams params;
29 : hccl::RankTable_t rankTable;
30 : bool cloudFlag = false; // cloudFlag为0即实验室场景,cloudFlag为1则为云场景
31 : bool isUsed;
32 : std::mutex opGroupMapMutex;
33 : std::unordered_map<std::string, std::shared_ptr<hccl::hcclComm>> opGroup2CommMap;
34 : std::map<std::string, std::shared_ptr<hccl::TopoInfoDetect>> hcclCommTopoInfoDetectServer;
35 : std::map<std::string, std::shared_ptr<hccl::TopoInfoDetect>> hcclCommTopoInfoDetectAgent;
36 396 : HcclInfoTag() :isUsed(false) {}
37 :
38 396 : ~HcclInfoTag() {
39 396 : pComm = nullptr;
40 396 : opGroup2CommMap.clear();
41 396 : hcclCommTopoInfoDetectServer.clear();
42 396 : hcclCommTopoInfoDetectAgent.clear();
43 396 : }
44 : };
45 :
46 : constexpr uint32_t MAX_HCOM_NUM = 3U;
47 :
48 : HcclOpInfoCtx &GetHcclExistDeviceOpInfoCtx(void);
49 :
50 : HcclOpInfoCtx &GetHcclOpInfoCtx(void);
51 :
52 : HcclResult InitOtherInfo(hccl::HcclCommParams ¶ms, const char *rankTable);
53 :
54 : HcclResult CallMsprofReportHostApi(hccl::hcclComm* hcclComm, HcclCMDType cmdType, uint64_t beginTime, u64 count,
55 : HcclDataType dataType, const std::string &tag);
56 :
57 : HcclResult ReduceScatterLoop(const std::string &tag, void *inputPtr, void *outputPtr, const u64 &count,
58 : HcclDataType dataType, HcclReduceOp op, hccl::hcclComm *hcclComm, rtStream_t stream);
59 :
60 : HcclResult HcclGetOpBasedMemSize(const HcclCMDType &opType, u64 &size,
61 : const HcomCollOpInfo &opInfo);
62 :
63 : HcclResult ReduceLoop(const std::string &tag, void *inputPtr, void *outputPtr, const u64 count,
64 : HcclDataType dataType, HcclReduceOp op, const u32 root, hccl::hcclComm *hcclComm, rtStream_t stream);
65 :
66 : HcclResult HcclGatherAlltoAllV(HcomGatherAllToAllVParams params, HcclComm comm, aclrtStream stream);
67 :
68 : HcclResult RunGather(u64 *sendCounts, u64 *sdispls, void *sendDevBuf, GatherPara &gatherPara);
69 :
70 : void GatherMemCopyThread(void *baseAddr, u64 offset, std::vector<u64> &addrInfo, OpBaseMemPara memCpyPara);
71 :
72 : HcclResult HcclGetCommAll(uint32_t ndev, int32_t *devices, HcclComm *comms);
73 :
74 : HcclResult GetDeviceComm(uint32_t ndev, const HcclRootInfo &rootHandle, const s32 rank, const s32 logicDeviceId,
75 : HcclComm &comm);
76 :
77 : HcclResult SetOverFlowAddr(hccl::hcclComm *hcclComm);
78 :
79 : HcclResult HcclGetCommHandle(const char *commName, std::shared_ptr<hccl::hcclComm> &comm);
80 :
81 : HcclResult CheckScatterInputPara(HcclComm comm, void *recvBuf);
82 :
83 : HcclResult HcclMc2ComResourceByTiling(HcclComm comm, uint32_t *pVersion, void *mc2Tiling, rtStream_t &aicpuStream);
84 :
85 : HcclResult HcclCreateComResourceByComm(HcclComm comm, u32 streamMode, bool isOpbaseMode,
86 : void** commContext, bool isMC2 = false, void* mc2Tiling = nullptr);
87 :
88 : HcclResult HcclDeviceRefresh(s32 &deviceLogicId);
89 :
90 : HcclResult HcclBatchSendRecvGroup(HcclSendRecvItem* sendRecvInfo, uint32_t itemNum, HcclComm comm, aclrtStream stream);
91 :
92 : HcclResult HcclSetIfProfile(void);
93 :
94 : void HcclResetIfProfile(void);
95 :
96 : void PrintCountsAndDispls(const u32 length, const void *counts, const void *displs, const std::string &tag);
97 :
98 : void CheckCountsAndDispls(const u32 length, const void *counts, const void *displs, const std::string &tag);
99 :
100 : HcclResult GetCaptureInfo(aclrtStream stream, aclmdlRICaptureStatus& captureStatus, uint64_t& modelId, bool& isCapture);
101 :
102 : HcclResult HcclGetInitTilingList(const void *mc2Tiling, const void *p[], uint32_t &cnt);
103 :
104 : HcclResult HcclCommInitCollComm(uint32_t rank, void **commV2, const HcclCommConfig *config, HcclComm *comm);
105 : HcclResult HcclMc2ComOpResCtx(HcclComm comm, uint8_t opType, HcclDataType srcDataType, HcclDataType dstDataType,
106 : HcclReduceOp reduceType, uint64_t count, char *algConfig, uint32_t commEngine, rtStream_t &aicpuStream);
107 :
108 : #ifdef __cplusplus
109 : extern "C" {
110 : #endif // __cplusplus
111 :
112 : HcclResult HcclCommInitClusterInfoMemConfig(const char *rankTableString, uint32_t rank,
113 : HcclCommConfig *config, HcclComm *comm);
114 :
115 : HcclResult HcclCommResumePostCallback(HcclComm comm);
116 : #ifdef __cplusplus
117 : }
118 : #endif // __cplusplus
119 : #endif // OP_BASE_H
|