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 50 : CcuRepWaitGroup::CcuRepWaitGroup(const CcuTransportGroup &transportGroup, uint16_t semIndex, uint16_t mask, bool isProfiling)
19 50 : : transportGroup(transportGroup), semIndex(semIndex), mask(mask), isProfiling(isProfiling)
20 : {
21 50 : type = CcuRepType::REM_WAIT_GROUP;
22 50 : instrCount = 1;
23 50 : }
24 :
25 16 : bool CcuRepWaitGroup::Translate(CcuInstr *&instr, uint16_t &instrId, const TransDep &dep)
26 : {
27 16 : this->instrId = instrId;
28 16 : translated = true;
29 :
30 16 : u32 cntCkeId = 0;
31 16 : HcclResult ret = transportGroup.GetCntCkeId(semIndex, cntCkeId);
32 16 : if (ret != HcclResult::HCCL_SUCCESS) {
33 : string msg = StringFormat("[Translate]rt get CntCkeId failed. "
34 0 : "semIndex[%u], cntCkeId[%u] return[%d].", semIndex, cntCkeId, ret);
35 0 : MACRO_THROW(CcuApiException, msg);
36 0 : }
37 : // 需要profiling的使用SetCKEInstr, 否则使用ClearCKEInstr
38 16 : if (isProfiling) {
39 16 : SetCKEInstr(instr++, 0, 0, cntCkeId, mask, 1);
40 : } else {
41 0 : ClearCKEInstr(instr++, 0, 0, cntCkeId, mask, 1);
42 : }
43 16 : CHK_PRT_THROW((instrId > UINT16_MAX - instrCount),
44 : HCCL_ERROR("[CcuRepWaitGroup::Translate]uint16 integer overflow occurs, instrId = [%hu], instrCount = [%hu]", instrId, instrCount),
45 : InternalException, "integer overflow");
46 16 : instrId += instrCount;
47 :
48 16 : return translated;
49 : }
50 :
51 16 : std::string CcuRepWaitGroup::Describe()
52 : {
53 16 : return StringFormat("Wait, Use semIndex[%u] and mask[%04x]", semIndex, mask);
54 : }
55 :
56 : }; // namespace CcuRep
57 : }; // namespace Hccl
|