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 HCCLV2_AICPU_UTILS_H
12 : #define HCCLV2_AICPU_UTILS_H
13 : #include <string>
14 : #include <shared_mutex>
15 : #include "communicator_impl_lite.h"
16 : #include "stream_lite.h"
17 : #include "mc2_data_type.h"
18 : #include "data_type.h"
19 :
20 : /* 检查指针, 若指针为NULL, 则记录日志, 并返回错误 */
21 : #define CHK_PTR_NULL_WITH_MSG(ptr, format, ...) \
22 : do { \
23 : if (UNLIKELY((ptr) == nullptr)) { \
24 : HCCL_ERROR("[%s]errNo[0x%016llx]ptr [%s] is NULL, return HCCL_E_PTR, additional msg: " format, \
25 : __func__, HCCL_ERROR_CODE(HCCL_E_PTR), #ptr, ##__VA_ARGS__); \
26 : return HCCL_E_PTR; \
27 : } \
28 : } while (0)
29 :
30 : #define CHECK_DATA_TYPE(dataType) \
31 : do { \
32 : if ((dataType) == DataType::INVALID) { \
33 : HCCL_ERROR("[%s] dataType is invalid", __func__); \
34 : return HCCL_E_PARA; \
35 : } \
36 : } while (0)
37 :
38 : namespace Hccl {
39 : class AicpuMc2Handler;
40 : constexpr uint32_t MAX_REPORT_CNT = 256U;
41 : constexpr uint32_t GET_TASK_STATUS = 1;
42 : constexpr uint32_t GET_EXCEPTION_INFO = 0;
43 : constexpr uint32_t CCORE_WAIT_TYPE = 0;
44 : constexpr uint32_t CCORE_NOTIFY_TYPE = 1;
45 :
46 : class AicpuUtils {
47 : public:
48 : friend class AicpuMc2Handler;
49 : AicpuUtils();
50 1 : ~AicpuUtils() = default;
51 : static AicpuUtils &GetInstance();
52 :
53 : void CreateSingleInstance(void *args) const;
54 : HcclResult Init() const;
55 :
56 : HcclResult WaitCommFree(CommunicatorImplLite *communicatorImplLite, const char *funcName) const;
57 :
58 : void GetStreamException(StreamLite *curStream, string nullInfo, CommunicatorImplLite *communicatorImplLite, string additionInfo) const;
59 :
60 : HcclResult HcclLaunchCcore(void *opHandle, uint64_t dstAddr, uint32_t turnNum, uint64_t turnNumAddr, bool isLast,
61 : int ccoreType) const;
62 :
63 : void ConvertCollOperatorMem(CollAlgOperator &algOperator, HcclAicpuOpLite &op, const HcclOpData *data,
64 : const uint64_t &size) const;
65 :
66 6 : int GetException(StreamLite *curStream, uint32_t flag, CommunicatorImplLite *communicatorImplLite, string additionInfo = "") const;
67 :
68 : HcclResult GetCommHandle(CommunicatorImplLite *communicatorImplLite, void **opHandle) const;
69 :
70 : HcclResult ConvertCollOperatorMemV(CollAlgOperator &algOperator, HcclAicpuOpLite &op, const HcclOpData *data) const;
71 :
72 : void CalcA2ASendRecvMem(const CollAlgOperator &algOperator, uint64_t &sendSize, uint64_t &recvSize) const;
73 :
74 : HcclResult FillKernelParam(HcclOpData *data) const;
75 :
76 : HcclResult RecoverKernelParam(CommunicatorImplLite *communicatorImplLite, HcclOpData *data);
77 :
78 : HcclResult RestoreOpRes(CommunicatorImplLite *communicatorImplLite);
79 :
80 : HcclResult ExecuteOp(CommunicatorImplLite *communicatorImplLite);
81 :
82 : HcclResult FillCollOperatorMemInfo(CollAlgOperator &algOperator, HcclAicpuOpLite &op, const HcclOpData *data) const;
83 :
84 : private:
85 : map<uint32_t, HcclKernelParamLite*> kernelParamMap_;
86 : HcclKernelParamLite* kernelParam_{nullptr};
87 : uint32_t rankSize_{0};
88 : uint32_t myRank_{0};
89 : mutable std::shared_timed_mutex handlerMutex_{};
90 : };
91 : } // namespace Hccl
92 :
93 : #endif // HCCLV2_AICPU_UTILS_H
|