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