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 35 : CcuRepLoopGroup::CcuRepLoopGroup(const Variable& parallelParam, const Variable& offsetParam) : parallelParam(parallelParam), offsetParam(offsetParam)
20 : {
21 35 : type = CcuRepType::LOOPGROUP;
22 35 : instrCount = 1;
23 35 : }
24 :
25 6 : bool CcuRepLoopGroup::Translate(CcuInstr *&instr, uint16_t &instrId, const TransDep &dep)
26 : {
27 6 : this->instrId = instrId;
28 6 : translated = true;
29 :
30 6 : if (instrId > USHRT_MAX - 3) {
31 0 : HCCL_ERROR("[CcuRepLoopGroup][Translate] instrId[%u] + 3 exceeds the maximum value of unsigned short int.",
32 : instrId);
33 0 : return false;
34 : }
35 : // 这是个非常危险的操作,需要谨慎使用
36 : // 依赖于LoopGroupCall的实现
37 : // LoopGroup所指向的Loop的位置为当前指令Id + 3
38 6 : LoopGroupInstr(instr++, instrId + 3, parallelParam.Id(), offsetParam.Id(), 0);
39 :
40 6 : instrId += instrCount;
41 :
42 6 : return translated;
43 : }
44 :
45 8 : std::string CcuRepLoopGroup::Describe()
46 : {
47 8 : return StringFormat("LoopGroup");
48 : }
49 :
50 34 : std::shared_ptr<CcuRepBase> CcuRepLoopGroup::SetParallelParam(Variable var)
51 : {
52 34 : return std::make_shared<CcuRepAssign>(parallelParam, var);
53 : }
54 :
55 34 : std::shared_ptr<CcuRepBase> CcuRepLoopGroup::SetOffsetParam(Variable var)
56 : {
57 34 : return std::make_shared<CcuRepAssign>(offsetParam, var);
58 : }
59 :
60 1 : uint16_t CcuRepLoopGroup::GetStartLoopInstrId() const
61 : {
62 : // 这是个非常危险的操作,需要谨慎使用
63 : // 依赖于LoopGroupCall的实现
64 : // LoopGroup所指向的Loop的位置为当前指令Id + 3
65 1 : return this->instrId + 3;
66 : }
67 :
68 : }; // namespace CcuRep
69 : }; // namespace Hccl
|