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 <sstream>
12 :
13 : #include "op_unfold_key.h"
14 :
15 : #include "log.h"
16 :
17 : namespace hccl {
18 471 : OpUnfoldKey::OpUnfoldKey()
19 471 : : opType(HcclCMDType::HCCL_CMD_INVALID),
20 471 : dataType(HcclDataType::HCCL_DATA_TYPE_RESERVED),
21 471 : reduceType(HcclReduceOp::HCCL_REDUCE_RESERVED),
22 471 : isZeroCopy(false),
23 471 : isSymmetricMemory(false),
24 471 : inputSize(0),
25 471 : isInplacePreSync(false),
26 471 : workflowMode(HcclWorkflowMode::HCCL_WORKFLOW_MODE_RESERVED),
27 471 : isCapture(false),
28 471 : root(0)
29 471 : {}
30 :
31 1 : OpUnfoldKey::OpUnfoldKey(const OpUnfoldKey& other)
32 1 : : opType(other.opType),
33 1 : dataType(other.dataType),
34 1 : reduceType(other.reduceType),
35 1 : isZeroCopy(other.isZeroCopy),
36 1 : isSymmetricMemory(other.isSymmetricMemory),
37 1 : inputSize(other.inputSize),
38 1 : isInplacePreSync(other.isInplacePreSync),
39 1 : workflowMode(other.workflowMode),
40 1 : isCapture(other.isCapture),
41 1 : root(other.root)
42 : {
43 1 : CHK_PRT_CONT(opType == HcclCMDType::HCCL_CMD_INVALID, HCCL_ERROR("[OpUnfoldKey][OpUnfoldKey] opType is invalid"));
44 1 : if (opType != HcclCMDType::HCCL_CMD_ALLTOALLV
45 1 : && opType != HcclCMDType::HCCL_CMD_ALLTOALLVC) { // 非V类算子, dataType一定不是RESERVED; 如果是alltoallv类算子
46 : // (alltoallv/alltoallvc), dataType一定是RESERVED
47 1 : CHK_PRT_CONT(
48 : dataType == HcclDataType::HCCL_DATA_TYPE_RESERVED,
49 : HCCL_ERROR("[OpUnfoldKey][OpUnfoldKey] dataType is reserved"));
50 : }
51 1 : CHK_PRT_CONT(
52 : workflowMode == HcclWorkflowMode::HCCL_WORKFLOW_MODE_RESERVED,
53 : HCCL_ERROR("[[OpUnfoldKey][OpUnfoldKey]] workflowMode is reserved"));
54 :
55 : // 注意: 当算子不涉及reduce操作时, reduceType为HcclReduceOp::HCCL_REDUCE_RESERVED
56 1 : }
57 :
58 19 : HcclResult OpUnfoldKey::Init(
59 : const HcclCMDType curOpType, const HcclDataType curDataType, const HcclReduceOp curReduceType,
60 : const bool curIsZeroCopy, const bool curIsSymmetricMemory, const uint64_t curInputSize,
61 : const bool curIsInplacePreSync, const HcclWorkflowMode curWorkflowMode, const bool curIsCapture,
62 : const uint32_t curRoot)
63 : {
64 19 : CHK_PRT_RET(
65 : curOpType == HcclCMDType::HCCL_CMD_INVALID, HCCL_ERROR("[OpUnfoldKey][OpUnfoldKey] opType is invalid"),
66 : HCCL_E_INTERNAL);
67 19 : if (curOpType != HcclCMDType::HCCL_CMD_ALLTOALLV
68 19 : && curOpType
69 : != HcclCMDType::HCCL_CMD_ALLTOALLVC) { // 非V类算子, dataType一定不是RESERVED; 如果是alltoallv类算子
70 : // (alltoallv/alltoallvc), dataType一定是RESERVED
71 19 : CHK_PRT_RET(
72 : curDataType == HcclDataType::HCCL_DATA_TYPE_RESERVED,
73 : HCCL_ERROR("[OpUnfoldKey][OpUnfoldKey] dataType is reserved"), HCCL_E_INTERNAL);
74 : }
75 19 : CHK_PRT_RET(
76 : curWorkflowMode == HcclWorkflowMode::HCCL_WORKFLOW_MODE_RESERVED,
77 : HCCL_ERROR("[[OpUnfoldKey][Init]] workflowMode is reserved"), HCCL_E_INTERNAL);
78 :
79 : // 注意: 当算子不涉及reduce操作时, reduceType为HcclReduceOp::HCCL_REDUCE_RESERVED
80 :
81 19 : opType = curOpType;
82 19 : dataType = curDataType;
83 19 : reduceType = curReduceType;
84 19 : isZeroCopy = curIsZeroCopy;
85 19 : isSymmetricMemory = curIsSymmetricMemory;
86 19 : inputSize = curInputSize;
87 19 : isInplacePreSync = curIsInplacePreSync;
88 19 : workflowMode = curWorkflowMode;
89 19 : isCapture = curIsCapture;
90 : // 注意: curRoot 默认值为 0, 对非root类算子无影响; 对 scatter/broadcast/reduce 会区分不同 root
91 19 : root = curRoot;
92 :
93 19 : return HCCL_SUCCESS;
94 : }
95 :
96 5 : std::string OpUnfoldKey::GetKeyString() const
97 : {
98 5 : std::ostringstream oss;
99 5 : oss << "opType" << static_cast<uint32_t>(opType) << "-dataType" << static_cast<uint32_t>(dataType) << "-reduceType"
100 5 : << static_cast<uint32_t>(reduceType) << "-isZeroCopy" << isZeroCopy << "-isSymmetricMemory" << isSymmetricMemory
101 5 : << "-inputSize" << inputSize << "-isInplacePreSync" << isInplacePreSync << "-workflowMode"
102 5 : << static_cast<uint32_t>(workflowMode) << "-isCapture" << isCapture << "-root" << root;
103 10 : return oss.str();
104 5 : }
105 :
106 4 : bool OpUnfoldKey::operator==(const OpUnfoldKey& other) const
107 : {
108 4 : return opType == other.opType && dataType == other.dataType && reduceType == other.reduceType
109 4 : && isZeroCopy == other.isZeroCopy && isSymmetricMemory == other.isSymmetricMemory
110 4 : && inputSize == other.inputSize && isInplacePreSync == other.isInplacePreSync
111 8 : && workflowMode == other.workflowMode && isCapture == other.isCapture && root == other.root;
112 : }
113 :
114 1 : const OpUnfoldKey& OpUnfoldKey::operator=(const OpUnfoldKey& other)
115 : {
116 1 : if (this != &other) {
117 1 : this->opType = other.opType;
118 1 : this->dataType = other.dataType;
119 1 : this->reduceType = other.reduceType;
120 1 : this->isZeroCopy = other.isZeroCopy;
121 1 : this->isSymmetricMemory = other.isSymmetricMemory;
122 1 : this->inputSize = other.inputSize;
123 1 : this->isInplacePreSync = other.isInplacePreSync;
124 1 : this->workflowMode = other.workflowMode;
125 1 : this->isCapture = other.isCapture;
126 1 : this->root = other.root;
127 : }
128 1 : return *this;
129 : }
130 :
131 : }; // namespace hccl
|