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 HCCL_COMM_KFC_AICPU_SERVER_H
12 : #define HCCL_COMM_KFC_AICPU_SERVER_H
13 :
14 : #include <unordered_set>
15 : #include <unordered_map>
16 : #include "hccl_msg.h"
17 : #include <hccl/hccl_types.h>
18 : #include "aicpu_hccl_common.h"
19 : #include "common/aicpu_kfc_def.h"
20 :
21 : class CommKfcAicpuServer {
22 : public:
23 16 : CommKfcAicpuServer(u32 groupIdx) : groupIdx_(groupIdx) {}
24 36 : ~CommKfcAicpuServer() = default;
25 34980984 : HcclApi::HcclMsgArea* GetMsgAreaAddr() const { return msgArea_; }
26 5 : u32 GetRankNum() const { return rankNum_; }
27 : HcclResult AddOpContext(const HcclApi::CommKfcContext* ctx);
28 : HcclResult Orchestrate(const HcclApi::HcclMsg& msg, HcclApi::HcclMsgExt& extMsg, u32 msgPos);
29 : HcclResult Finalize(u32 msgPos);
30 : HcclResult IsAllTaskFinished(u32 msgPos, bool& isFinish);
31 : HcclResult InterGroupSync(const CommKfcAicpuServer& otherServer, HcclHandle handle);
32 : HcclResult CheckTimeOut(u32 msgPos);
33 : HcclResult ErrorDfxProcess(HcclResult errorCode);
34 :
35 : private:
36 : #ifdef CCL_LLT
37 : static constexpr u64 KFC_NSEC_PER_SEC = 1000000UL;
38 : #else
39 : static constexpr u64 KFC_NSEC_PER_SEC = 1000000000UL;
40 : #endif
41 : HcclResult GetServerInfoForSync(HcclHandle handle, u32& msgPos, u32& repeat) const;
42 39 : void KeepAlive() { lastMsgTimestamp_ = GetCurCpuTimestamp(); }
43 36107837 : bool IsTimeout() const { return GetCurCpuTimestamp() - lastMsgTimestamp_ >= timeout_ * KFC_NSEC_PER_SEC; }
44 12 : void SetMsgPosByHandle(HcclHandle handle, u32 msgPos) { handleIdToMsgPos_[handle] = msgPos; }
45 12 : void SetRepeatByHandle(HcclHandle handle, u32 repeat) { handleIdToRepeat_[handle] = repeat; }
46 :
47 : private:
48 : std::unordered_map<uintptr_t, void*> ctxToOpHandle_{};
49 : std::unordered_map<HcclHandle, u32> handleIdToMsgPos_{};
50 : std::unordered_map<HcclHandle, u32> handleIdToRepeat_{};
51 : HcclApi::HcclMsgArea* msgArea_{nullptr};
52 : u64 lastMsgTimestamp_{0UL};
53 : u64 timeout_{30UL};
54 : u64 turnNumsAddr_{0UL};
55 : u32 groupIdx_;
56 : u32 rankNum_{0U};
57 : };
58 :
59 : #endif // HCCL_COMM_KFC_AICPU_SERVER_H
|