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