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 : #ifndef TYPICAL_PARAM_CHECK_H
12 : #define TYPICAL_PARAM_CHECK_H
13 : #include "interface_hccl.h"
14 : namespace hccl {
15 :
16 0 : inline HcclResult CheckDataType(const HcclDataType dataType)
17 : {
18 0 : if ((dataType >= HCCL_DATA_TYPE_RESERVED) || (dataType < HCCL_DATA_TYPE_INT8)) {
19 0 : HCCL_ERROR(
20 : "[Check][DataType]errNo[0x%016llx] data type[%s] not supported", HCOM_ERROR_CODE(HCCL_E_NOT_SUPPORT),
21 : GetDataTypeEnumStr(dataType).c_str());
22 0 : return HCCL_E_NOT_SUPPORT;
23 : }
24 0 : return HCCL_SUCCESS;
25 : }
26 :
27 0 : inline HcclResult CheckCount(const u64 count)
28 : {
29 0 : if (count > SYS_MAX_COUNT) {
30 0 : HCCL_ERROR(
31 : "[Check][Count]errNo[0x%016llx] count[%llu] is invalid(bigger than MAX count[%llu])",
32 : HCOM_ERROR_CODE(HCCL_E_PARA), count, SYS_MAX_COUNT);
33 0 : return HCCL_E_PARA;
34 : }
35 0 : return HCCL_SUCCESS;
36 : }
37 :
38 0 : inline HcclResult CheckSendRecvInfo(AscendSendRecvInfo* sendRecvInfo)
39 : {
40 0 : CHK_PTR_NULL(sendRecvInfo);
41 0 : CHK_PTR_NULL(sendRecvInfo->localQPinfo);
42 :
43 0 : CHK_PTR_NULL(sendRecvInfo->localWindowMem);
44 0 : CHK_PTR_NULL(sendRecvInfo->remoteWindowMem);
45 :
46 0 : CHK_PTR_NULL(sendRecvInfo->localSyncMemPrepare);
47 0 : CHK_PTR_NULL(sendRecvInfo->localSyncMemDone);
48 0 : CHK_PTR_NULL(sendRecvInfo->localSyncMemAck);
49 :
50 0 : CHK_PTR_NULL(sendRecvInfo->remoteSyncMemPrepare);
51 0 : CHK_PTR_NULL(sendRecvInfo->remoteSyncMemDone);
52 0 : CHK_PTR_NULL(sendRecvInfo->remoteSyncMemAck);
53 :
54 0 : CHK_PTR_NULL(reinterpret_cast<void*>(sendRecvInfo->localWindowMem->addr));
55 0 : CHK_PTR_NULL(reinterpret_cast<void*>(sendRecvInfo->remoteWindowMem->addr));
56 :
57 0 : CHK_PTR_NULL(reinterpret_cast<void*>(sendRecvInfo->localSyncMemPrepare->addr));
58 0 : CHK_PTR_NULL(reinterpret_cast<void*>(sendRecvInfo->localSyncMemDone->addr));
59 0 : CHK_PTR_NULL(reinterpret_cast<void*>(sendRecvInfo->localSyncMemAck->addr));
60 :
61 0 : CHK_PTR_NULL(reinterpret_cast<void*>(sendRecvInfo->remoteSyncMemPrepare->addr));
62 0 : CHK_PTR_NULL(reinterpret_cast<void*>(sendRecvInfo->remoteSyncMemDone->addr));
63 0 : CHK_PTR_NULL(reinterpret_cast<void*>(sendRecvInfo->remoteSyncMemAck->addr));
64 0 : return HCCL_SUCCESS;
65 : }
66 :
67 19 : inline HcclResult CheckSendRecvLinkInfo(AscendSendRecvLinkInfo* sendRecvInfo)
68 : {
69 19 : CHK_PTR_NULL(sendRecvInfo);
70 19 : CHK_PTR_NULL(sendRecvInfo->localQPinfo);
71 :
72 19 : CHK_PTR_NULL(sendRecvInfo->localSyncMemPrepare);
73 19 : CHK_PTR_NULL(sendRecvInfo->localSyncMemDone);
74 19 : CHK_PTR_NULL(sendRecvInfo->localSyncMemAck);
75 :
76 19 : CHK_PTR_NULL(sendRecvInfo->remoteSyncMemPrepare);
77 19 : CHK_PTR_NULL(sendRecvInfo->remoteSyncMemDone);
78 19 : CHK_PTR_NULL(sendRecvInfo->remoteSyncMemAck);
79 19 : return HCCL_SUCCESS;
80 : }
81 :
82 11 : inline HcclResult CheckSendLinkInfo(AscendSendLinkInfo* sendInfo)
83 : {
84 11 : CHK_PTR_NULL(sendInfo);
85 11 : CHK_PTR_NULL(sendInfo->localQPinfo);
86 11 : CHK_PTR_NULL(sendInfo->localSyncMemAck);
87 11 : CHK_PTR_NULL(sendInfo->remoteNotifyValueMem);
88 : // 校验sendInfo->remoteNotifyValueMem长度
89 11 : const uint32_t NOTIFY_MEM_LEN = 4;
90 11 : CHK_PRT_RET(
91 : sendInfo->remoteNotifyValueMem->size != NOTIFY_MEM_LEN,
92 : HCCL_ERROR(
93 : "[CheckSendLinkInfo] remoteNotifyValueMem len expect:[%u], actual:[%llu].", NOTIFY_MEM_LEN,
94 : sendInfo->remoteNotifyValueMem->size),
95 : HCCL_E_PARA);
96 10 : return HCCL_SUCCESS;
97 : }
98 :
99 0 : inline HcclResult CheckParam(void* buf, uint64_t count, HcclDataType dataType, aclrtStream stream)
100 : {
101 0 : CHK_PTR_NULL(buf);
102 0 : CHK_RET(CheckCount(count));
103 0 : CHK_RET(CheckDataType(dataType));
104 0 : CHK_PTR_NULL(stream);
105 0 : return HCCL_SUCCESS;
106 : }
107 : } // namespace hccl
108 : // namespace hccl
109 : #endif
|