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 = {{ReduceOp::SUM, true},
46 : {ReduceOp::PROD, false},
47 : {ReduceOp::MAX, true},
48 : {ReduceOp::MIN, true},
49 : {ReduceOp::EQUAL, true}};
50 : const u32 CAP_NOTIFY_SIZE_V82 = 8;
51 : const u32 CAP_SDMA_INLINE_REDUCE_ALIGN_BYTES_V82 = 32;
52 :
53 311 : DevCapability &DevCapability::GetInstance()
54 : {
55 311 : static DevCapability devCapability;
56 311 : return devCapability;
57 : }
58 :
59 1 : DevCapability::DevCapability()
60 : {
61 1 : }
62 :
63 114 : void DevCapability::Init(DevType givenDevType)
64 : {
65 114 : if (isInit) {
66 112 : return;
67 : }
68 2 : isInit = true;
69 2 : devType = givenDevType;
70 2 : if (devType == DevType::DEV_TYPE_910A) {
71 0 : Load910ACap();
72 2 : } else if (devType == DevType::DEV_TYPE_910A3 || devType == DevType::DEV_TYPE_910A2) {
73 0 : Load910A3Cap();
74 2 : } else if (devType == DevType::DEV_TYPE_950 || devType == DevType::DEV_TYPE_960) {
75 1 : LoadV82Cap();
76 : } else {
77 1 : throw NotSupportException(StringFormat("we don't support %s now.", devType.Describe().c_str()));
78 : }
79 : }
80 :
81 1 : void DevCapability::Reset()
82 : {
83 1 : isInit = false;
84 1 : }
85 :
86 2 : void DevCapability::Load910A910A3CommonCap()
87 : {
88 2 : isSupportWriteWithNotify = false;
89 2 : isSupportStarsPollNetCq = false;
90 2 : sdmaSendMaxSize = SDMA_SEND_MAX_SIZE;
91 2 : rdmaSendMaxSize = RDMA_SEND_MAX_SIZE;
92 2 : }
93 :
94 1 : void DevCapability::Load910A3Cap()
95 : {
96 1 : Load910A910A3CommonCap();
97 1 : inlineReduceDataTypeMap = CAP_INLINE_REDUCE_DATATYPE_910A3;
98 1 : inlineReduceOpMap = CAP_INLINE_REDUCE_OP_910A3;
99 1 : sdmaInlineReduceAlignBytes = CAP_SDMA_INLINE_REDUCE_ALIGN_BYTES_910A3;
100 1 : notifySize = CAP_NOTIFY_SIZE_910A3;
101 1 : isSupportDevNetInlineReduce = true;
102 1 : }
103 :
104 1 : void DevCapability::Load910ACap()
105 : {
106 1 : Load910A910A3CommonCap();
107 1 : inlineReduceDataTypeMap = CAP_INLINE_REDUCE_DATATYPE_910A;
108 1 : inlineReduceOpMap = CAP_INLINE_REDUCE_OP_910A;
109 1 : sdmaInlineReduceAlignBytes = CAP_SDMA_INLINE_REDUCE_ALIGN_BYTES_910A;
110 1 : notifySize = CAP_NOTIFY_SIZE_910A;
111 1 : isSupportDevNetInlineReduce = false;
112 1 : }
113 :
114 13 : void DevCapability::LoadV82Cap()
115 : {
116 13 : isSupportWriteWithNotify = true;
117 13 : isSupportStarsPollNetCq = true;
118 13 : sdmaSendMaxSize = SDMA_SEND_MAX_SIZE;
119 13 : rdmaSendMaxSize = RDMA_SEND_MAX_SIZE;
120 :
121 13 : inlineReduceDataTypeMap = CAP_INLINE_REDUCE_DATATYPE_V82;
122 13 : inlineReduceOpMap = CAP_INLINE_REDUCE_OP_V82;
123 13 : sdmaInlineReduceAlignBytes = CAP_SDMA_INLINE_REDUCE_ALIGN_BYTES_V82;
124 13 : notifySize = CAP_NOTIFY_SIZE_V82;
125 13 : isSupportDevNetInlineReduce = true;
126 13 : }
127 :
128 : } // namespace Hccl
|