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