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.h"
12 : #include <climits>
13 :
14 : #include "string_util.h"
15 :
16 : namespace Hccl {
17 : namespace CcuRep {
18 :
19 129 : CcuRepLocWaitSem::CcuRepLocWaitSem(const MaskSignal &sem, uint16_t mask, bool isProfiling) : sem(sem), mask(mask), isProfiling(isProfiling)
20 : {
21 129 : type = CcuRepType::LOC_WAIT_SEM;
22 129 : instrCount = 1;
23 129 : }
24 :
25 32 : uint16_t CcuRepLocWaitSem::GetSemId() const
26 : {
27 32 : return sem.Id();
28 : }
29 :
30 45 : void CcuRepLocWaitSem::SetDependencyInfo(const std::unordered_map<uint32_t, std::vector<std::shared_ptr<CcuRepBase>>>& depInfo) {
31 45 : depInfo_ = depInfo;
32 45 : }
33 :
34 0 : std::vector<std::shared_ptr<CcuRepBase>> CcuRepLocWaitSem::GetDependencyInfo(uint32_t bit) {
35 : // 查找给定 bit 是否存在于 depInfo_ 中
36 0 : auto it = depInfo_.find(bit);
37 : // 如果找到 bit,返回与之关联的 vector
38 0 : if (it != depInfo_.end()) {
39 0 : return it->second;
40 : }
41 : // 如果未找到 bit,返回一个空的 vector
42 0 : return std::vector<std::shared_ptr<CcuRepBase>>();
43 : }
44 :
45 37 : bool CcuRepLocWaitSem::Translate(CcuInstr *&instr, uint16_t &instrId, const TransDep &dep)
46 : {
47 37 : this->instrId = instrId;
48 37 : translated = true;
49 :
50 : // 需要profiling的使用SetCKEInstr, 否则使用ClearCKEInstr
51 37 : if (isProfiling) {
52 15 : SetCKEInstr(instr++, 0, 0, sem.Id(), mask, 1);
53 : } else {
54 22 : ClearCKEInstr(instr++, 0, 0, sem.Id(), mask, 1);
55 : }
56 :
57 37 : if (instrId > USHRT_MAX - instrCount) {
58 2 : THROW<InternalException>(StringFormat("[CcuRepLocWaitSem][Translate] instrId[%u] + instrCount[%u] exceeds the "
59 1 : "maximum value of unsigned short int.", instrId, instrCount));
60 : }
61 36 : CHK_PRT_THROW((instrId > UINT16_MAX - instrCount),
62 : HCCL_ERROR("[CcuRepLocWaitSem::Translate]uint16 integer overflow occurs, instrId = [%hu], instrCount = [%hu]", instrId, instrCount),
63 : InternalException, "integer overflow");
64 36 : instrId += instrCount;
65 :
66 36 : return translated;
67 : }
68 :
69 50 : std::string CcuRepLocWaitSem::Describe()
70 : {
71 50 : return StringFormat("Wait Sem[%u], mask[%04x]", sem.Id(), mask);
72 : }
73 :
74 : }; // namespace CcuRep
75 : }; // namespace Hccl
|