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 "dev_capability.h"
12 : #include "not_support_exception.h"
13 : #include "string_util.h"
14 : namespace Hccl {
15 : using namespace std;
16 : const u64 RDMA_SEND_MAX_SIZE = 0x80000000; // 节点间RDMA发送数据单个WQE支持的最大数据量
17 : const u64 SDMA_SEND_MAX_SIZE = 0x100000000; // 节点内单个SDMA任务发送数据支持的最大数据量
18 : const map<DataType, bool> CAP_INLINE_REDUCE_DATATYPE_910A = {
19 : {DataType::INT8, false}, {DataType::INT16, false}, {DataType::INT32, false}, {DataType::FP16, false},
20 : {DataType::FP32, true}, {DataType::INT64, false}, {DataType::UINT64, false}, {DataType::UINT8, false},
21 : {DataType::UINT16, false}, {DataType::UINT32, false}, {DataType::FP64, false}, {DataType::BFP16, false},
22 : {DataType::INT128, false},
23 : };
24 : const map<ReduceOp, bool> CAP_INLINE_REDUCE_OP_910A
25 : = {{ReduceOp::SUM, true}, {ReduceOp::PROD, false}, {ReduceOp::MAX, false}, {ReduceOp::MIN, false}};
26 : const u32 CAP_NOTIFY_SIZE_910A = 8;
27 : const u32 CAP_SDMA_INLINE_REDUCE_ALIGN_BYTES_910A = 128;
28 : const map<DataType, bool> CAP_INLINE_REDUCE_DATATYPE_910A3 = {
29 : {DataType::INT8, true}, {DataType::INT16, true}, {DataType::INT32, true}, {DataType::FP16, true},
30 : {DataType::FP32, true}, {DataType::INT64, false}, {DataType::UINT64, false}, {DataType::UINT8, false},
31 : {DataType::UINT16, false}, {DataType::UINT32, false}, {DataType::FP64, false}, {DataType::BFP16, true},
32 : {DataType::INT128, false},
33 : };
34 : const map<ReduceOp, bool> CAP_INLINE_REDUCE_OP_910A3
35 : = {{ReduceOp::SUM, true}, {ReduceOp::PROD, false}, {ReduceOp::MAX, true}, {ReduceOp::MIN, true}};
36 : const u32 CAP_NOTIFY_SIZE_910A3 = 4;
37 : const u32 CAP_SDMA_INLINE_REDUCE_ALIGN_BYTES_910A3 = 32;
38 :
39 : const map<DataType, bool> CAP_INLINE_REDUCE_DATATYPE_V82 = {
40 : {DataType::INT8, true}, {DataType::INT16, true}, {DataType::INT32, true}, {DataType::FP16, true},
41 : {DataType::FP32, true}, {DataType::INT64, false}, {DataType::UINT64, false}, {DataType::UINT8, true},
42 : {DataType::UINT16, true}, {DataType::UINT32, true}, {DataType::FP64, false}, {DataType::BFP16, true},
43 : {DataType::INT128, false}, {DataType::BF16_SAT, true},
44 : };
45 : const map<ReduceOp, bool> CAP_INLINE_REDUCE_OP_V82
46 : = {{ReduceOp::SUM, true},
47 : {ReduceOp::PROD, false},
48 : {ReduceOp::MAX, true},
49 : {ReduceOp::MIN, true},
50 : {ReduceOp::EQUAL, true}};
51 : const u32 CAP_NOTIFY_SIZE_V82 = 8;
52 : const u32 CAP_SDMA_INLINE_REDUCE_ALIGN_BYTES_V82 = 32;
53 :
54 331 : DevCapability& DevCapability::GetInstance()
55 : {
56 331 : static DevCapability devCapability;
57 331 : return devCapability;
58 : }
59 :
60 1 : DevCapability::DevCapability() {}
61 :
62 121 : void DevCapability::Init(DevType givenDevType)
63 : {
64 121 : if (isInit) {
65 119 : return;
66 : }
67 2 : isInit = true;
68 2 : devType = givenDevType;
69 2 : if (devType == DevType::DEV_TYPE_910A) {
70 0 : Load910ACap();
71 2 : } else if (devType == DevType::DEV_TYPE_910A3 || devType == DevType::DEV_TYPE_910A2) {
72 0 : Load910A3Cap();
73 2 : } else if (devType == DevType::DEV_TYPE_950 || devType == DevType::DEV_TYPE_960) {
74 1 : LoadV82Cap();
75 : } else {
76 1 : throw NotSupportException(StringFormat("we don't support %s now.", devType.Describe().c_str()));
77 : }
78 : }
79 :
80 1 : void DevCapability::Reset() { isInit = false; }
81 :
82 2 : void DevCapability::Load910A910A3CommonCap()
83 : {
84 2 : isSupportWriteWithNotify = false;
85 2 : isSupportStarsPollNetCq = false;
86 2 : sdmaSendMaxSize = SDMA_SEND_MAX_SIZE;
87 2 : rdmaSendMaxSize = RDMA_SEND_MAX_SIZE;
88 2 : }
89 :
90 1 : void DevCapability::Load910A3Cap()
91 : {
92 1 : Load910A910A3CommonCap();
93 1 : inlineReduceDataTypeMap = CAP_INLINE_REDUCE_DATATYPE_910A3;
94 1 : inlineReduceOpMap = CAP_INLINE_REDUCE_OP_910A3;
95 1 : sdmaInlineReduceAlignBytes = CAP_SDMA_INLINE_REDUCE_ALIGN_BYTES_910A3;
96 1 : notifySize = CAP_NOTIFY_SIZE_910A3;
97 1 : isSupportDevNetInlineReduce = true;
98 1 : }
99 :
100 1 : void DevCapability::Load910ACap()
101 : {
102 1 : Load910A910A3CommonCap();
103 1 : inlineReduceDataTypeMap = CAP_INLINE_REDUCE_DATATYPE_910A;
104 1 : inlineReduceOpMap = CAP_INLINE_REDUCE_OP_910A;
105 1 : sdmaInlineReduceAlignBytes = CAP_SDMA_INLINE_REDUCE_ALIGN_BYTES_910A;
106 1 : notifySize = CAP_NOTIFY_SIZE_910A;
107 1 : isSupportDevNetInlineReduce = false;
108 1 : }
109 :
110 13 : void DevCapability::LoadV82Cap()
111 : {
112 13 : isSupportWriteWithNotify = true;
113 13 : isSupportStarsPollNetCq = true;
114 13 : sdmaSendMaxSize = SDMA_SEND_MAX_SIZE;
115 13 : rdmaSendMaxSize = RDMA_SEND_MAX_SIZE;
116 :
117 13 : inlineReduceDataTypeMap = CAP_INLINE_REDUCE_DATATYPE_V82;
118 13 : inlineReduceOpMap = CAP_INLINE_REDUCE_OP_V82;
119 13 : sdmaInlineReduceAlignBytes = CAP_SDMA_INLINE_REDUCE_ALIGN_BYTES_V82;
120 13 : notifySize = CAP_NOTIFY_SIZE_V82;
121 13 : isSupportDevNetInlineReduce = true;
122 13 : }
123 :
124 : } // namespace Hccl
|