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