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 :
13 : #include "string_util.h"
14 :
15 : namespace Hccl {
16 : namespace CcuRep {
17 :
18 6 : CcuRepPostSharedVar::CcuRepPostSharedVar(const Variable &srcVar, const Variable &dstVar, const MaskSignal &sem,
19 6 : uint16_t mask)
20 6 : : srcVar(srcVar), dstVar(dstVar), sem(sem), mask(mask)
21 : {
22 6 : type = CcuRepType::POST_SHARED_VAR;
23 6 : instrCount = 2; // 指令数为2个
24 6 : }
25 :
26 5 : bool CcuRepPostSharedVar::Translate(CcuInstr *&instr, uint16_t &instrId, const TransDep &dep)
27 : {
28 5 : this->instrId = instrId;
29 5 : translated = true;
30 :
31 5 : if (sem.DieId() != dep.dieId) {
32 1 : SyncXnInstr(instr++, dstVar.Id(), srcVar.Id(), dep.reserveChannalId[1], sem.Id(), mask, 0, 0, 0, 0, 1);
33 1 : LoadImdToXnInstr(instr++, dep.reserveXnId, 0);
34 : } else {
35 4 : LoadXXInstr(instr++, dstVar.Id(), srcVar.Id(), dep.reserveXnId);
36 4 : SetCKEInstr(instr++, sem.Id(), mask, 0, 0, 1);
37 : }
38 5 : CHK_PRT_THROW((instrId > UINT16_MAX - instrCount),
39 : HCCL_ERROR("[CcuRepPostSharedVar::Translate]uint16 integer overflow occurs, instrId = [%hu], instrCount = [%hu]", instrId, instrCount),
40 : InternalException, "integer overflow");
41 5 : instrId += instrCount;
42 :
43 5 : return translated;
44 : }
45 :
46 7 : std::string CcuRepPostSharedVar::Describe()
47 : {
48 7 : return StringFormat("Post Shared Variable[%u], from Variable[%u]", dstVar.Id(), srcVar.Id());
49 : }
50 :
51 : }; // namespace CcuRep
52 : }; // namespace Hccl
|