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(
31 : CcuCtxSignature& sig, CcuInstType instType, const CollAlgOperator& op,
32 : const std::vector<std::vector<RankId>>& tempVTopo)
33 : {
34 7 : sig.Append<int>(int(instType));
35 14 : if (op.opType == OpType::REDUCESCATTER || op.opType == OpType::ALLREDUCE || op.opType == OpType::REDUCE
36 14 : || op.opType == OpType::REDUCESCATTERV) {
37 0 : sig.Append<int>(int(op.reduceOp));
38 0 : sig.Append<int>(int(op.dataType));
39 0 : sig.Append<int>(int(op.outputDataType));
40 : }
41 14 : if (op.opType == OpType::REDUCE || op.opType == OpType::BROADCAST || op.opType == OpType::GATHER
42 14 : || op.opType == OpType::SCATTER) {
43 : // 带有root属性的算子需要考虑自己与root的关系,暂定直接用root号做区分
44 0 : sig.Append<char>('R');
45 0 : sig.Append<int>(int(op.root));
46 : // sig.Append<std::string>("_");
47 : }
48 7 : if (tempVTopo.size() == COMM_LEVEL_SIZE_1) {
49 0 : sig.Append<uint32_t>(tempVTopo[0].size());
50 0 : sig.Append<char>('P');
51 7 : } else if (tempVTopo.size() == COMM_LEVEL_SIZE_2) {
52 7 : sig.Append<uint32_t>(tempVTopo[0].size());
53 7 : sig.Append<char>('X');
54 7 : sig.Append<uint32_t>(tempVTopo[1].size());
55 7 : sig.Append<char>('P');
56 : } else {
57 0 : THROW<InvalidParamsException>(
58 0 : StringFormat("GenerateCcuCtxSignature failed: unexpected tempVTopoSize[%zu]", tempVTopo.size()));
59 : }
60 7 : return HcclResult::HCCL_SUCCESS;
61 : }
62 : } // namespace Hccl
|