Line data Source code
1 : /**
2 : * Copyright (c) 2026 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 : #include "ccu_rep_loc_wait_event.h"
12 : #include <climits>
13 : #include "ccu_rep_v1.h"
14 : #include "string_util.h"
15 : #include "exception_util.h"
16 : #include "ccu_api_exception.h"
17 : #include "ccu_ins_generator_v1.h"
18 : #include "ccu_kernel.h"
19 : namespace hcomm {
20 : namespace CcuRep {
21 :
22 48 : CcuRepLocWaitEvent::CcuRepLocWaitEvent(
23 48 : CcuInsGeneratorBase* insGenPtr, const CompletedEvent& event, uint32_t mask, bool isProfiling)
24 48 : : insGenPtr(insGenPtr),
25 48 : event_(event),
26 48 : mask_(mask),
27 48 : isProfiling_(isProfiling)
28 : {
29 48 : type = CcuRepType::LOC_WAIT_EVENT;
30 48 : instrCount = insGenPtr->GetInstrCount(type);
31 48 : }
32 :
33 42 : void CcuRepLocWaitEvent::SetDependencyInfo(
34 : const std::unordered_map<uint32_t, std::vector<std::shared_ptr<CcuRepBase>>>& depInfo)
35 : {
36 42 : depInfo_ = depInfo;
37 42 : }
38 :
39 2 : std::vector<std::shared_ptr<CcuRepBase>> CcuRepLocWaitEvent::GetDependencyInfo(uint32_t bit)
40 : {
41 : // 查找给定 bit 是否存在于 depInfo_ 中
42 2 : auto it = depInfo_.find(bit);
43 : // 如果找到 bit,返回与之关联的 vector
44 2 : if (it != depInfo_.end()) {
45 1 : return it->second;
46 : }
47 : // 如果未找到 bit,返回一个空的 vector
48 1 : return std::vector<std::shared_ptr<CcuRepBase>>();
49 : }
50 :
51 39 : bool CcuRepLocWaitEvent::Translate(
52 : CcuKernel* ccuKernel, CcuInstr*& instr, uint16_t& instrId, [[maybe_unused]] const TransDep& dep)
53 : {
54 39 : this->instrId = instrId;
55 39 : translated = true;
56 :
57 39 : CHK_PRT_THROW(
58 : insGenPtr->CcuRepLocWaitEventTranslate(ccuKernel, instr, this) != HcclResult::HCCL_SUCCESS,
59 : HCCL_ERROR("[CcuRepLocWaitEvent][Translate] failed to translate for instrId[%u]", instrId),
60 : Hccl::CcuApiException, "CcuRepLocWaitEvent translate failed");
61 :
62 39 : CHK_PRT_THROW(
63 : (instrId > UINT16_MAX - instrCount),
64 : HCCL_ERROR(
65 : "[CcuRepLocWaitEvent::Translate]uint16 integer overflow occurs, "
66 : "instrId = [%hu], instrCount = [%hu]",
67 : instrId, instrCount),
68 : Hccl::CcuApiException, "integer overflow");
69 39 : instrId += instrCount;
70 39 : return translated;
71 : }
72 :
73 38 : std::string CcuRepLocWaitEvent::Describe()
74 : {
75 38 : return Hccl::StringFormat("CcuRepLocWaitEvent=id[%u], mask[%04x]", event_.Id(), mask_);
76 : }
77 :
78 : }; // namespace CcuRep
79 : }; // namespace hcomm
|