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 : #include <vector>
12 : #include <string>
13 : #include <sstream>
14 : #include <ios>
15 : #include <iostream>
16 : #include "ccu_ins.h"
17 : #include "ccu_ctx_signature.h"
18 : #include "ccu_context_utils.h"
19 :
20 : namespace Hccl {
21 :
22 : constexpr int COMM_LEVEL_SIZE_1 = 1;
23 : constexpr int COMM_LEVEL_SIZE_2 = 2;
24 :
25 2 : uint64_t CalcLGMaxTransSize()
26 : {
27 2 : return LOC_CPY_LOOP_NUM * 4096 * 8192; // 单片MS搬4096B,每个loop循环最多8192次
28 : }
29 :
30 7 : HcclResult GenerateCcuCtxSignature(CcuCtxSignature &sig, CcuInstType instType, const CollAlgOperator &op,
31 : const std::vector<std::vector<RankId>> &tempVTopo)
32 : {
33 7 : sig.Append<int>(int(instType));
34 14 : if (op.opType == OpType::REDUCESCATTER || op.opType == OpType::ALLREDUCE || op.opType == OpType::REDUCE
35 14 : || op.opType == OpType::REDUCESCATTERV) {
36 0 : sig.Append<int>(int(op.reduceOp));
37 0 : sig.Append<int>(int(op.dataType));
38 0 : sig.Append<int>(int(op.outputDataType));
39 : }
40 14 : if (op.opType == OpType::REDUCE || op.opType == OpType::BROADCAST || op.opType == OpType::GATHER
41 14 : || op.opType == OpType::SCATTER) {
42 : // 带有root属性的算子需要考虑自己与root的关系,暂定直接用root号做区分
43 0 : sig.Append<char>('R');
44 0 : sig.Append<int>(int(op.root));
45 : // sig.Append<std::string>("_");
46 : }
47 7 : if (tempVTopo.size() == COMM_LEVEL_SIZE_1) {
48 0 : sig.Append<uint32_t>(tempVTopo[0].size());
49 0 : sig.Append<char>('P');
50 7 : } else if (tempVTopo.size() == COMM_LEVEL_SIZE_2) {
51 7 : sig.Append<uint32_t>(tempVTopo[0].size());
52 7 : sig.Append<char>('X');
53 7 : sig.Append<uint32_t>(tempVTopo[1].size());
54 7 : sig.Append<char>('P');
55 : } else {
56 0 : THROW<InvalidParamsException>(
57 0 : StringFormat("GenerateCcuCtxSignature failed: unexpected tempVTopoSize[%zu]", tempVTopo.size()));
58 : }
59 7 : return HcclResult::HCCL_SUCCESS;
60 : }
61 : }
|