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