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)
20 35 : : parallelParam(parallelParam),
21 35 : offsetParam(offsetParam)
22 : {
23 35 : type = CcuRepType::LOOPGROUP;
24 35 : instrCount = 1;
25 35 : }
26 :
27 6 : bool CcuRepLoopGroup::Translate(CcuInstr*& instr, uint16_t& instrId, [[maybe_unused]] const TransDep& dep)
28 : {
29 6 : this->instrId = instrId;
30 6 : translated = true;
31 :
32 6 : if (instrId > USHRT_MAX - 3) {
33 0 : HCCL_ERROR(
34 : "[CcuRepLoopGroup][Translate] instrId[%u] + 3 exceeds the maximum value of unsigned short int.",
35 : instrId);
36 0 : return false;
37 : }
38 : // 这是个非常危险的操作,需要谨慎使用
39 : // 依赖于LoopGroupCall的实现
40 : // LoopGroup所指向的Loop的位置为当前指令Id + 3
41 6 : LoopGroupInstr(instr++, instrId + 3, parallelParam.Id(), offsetParam.Id(), 0);
42 :
43 6 : instrId += instrCount;
44 :
45 6 : return translated;
46 : }
47 :
48 8 : std::string CcuRepLoopGroup::Describe() { return StringFormat("LoopGroup"); }
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
|