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 "ccu_interface_assist.h"
13 :
14 : #include "string_util.h"
15 : #include "exception_util.h"
16 : #include "ccu_api_exception.h"
17 : namespace Hccl {
18 : namespace CcuRep {
19 :
20 38 : void LoopGroupCall::Run(const std::vector<LoopCall> &loopVec, const std::vector<Variable> &loopCfg,
21 : const std::vector<Executor> &executors, Variable paraCfgIn, Variable offsetCfgIn) const
22 : {
23 38 : Variable var1, var2;
24 38 : auto ret1 = CreateVariable(context, var1);
25 38 : auto ret2 = CreateVariable(context, var2);
26 38 : if (ret1 != HcclResult::HCCL_SUCCESS || ret2 != HcclResult::HCCL_SUCCESS) {
27 0 : THROW<CcuApiException>("CreateVariable failed. ret1[%d], ret2[%d]", ret1, ret2);
28 : }
29 :
30 38 : if (executors.size() < loopVec.size() || loopCfg.size() < loopVec.size()) {
31 0 : THROW<CcuApiException>("Executors size[%lu] or loopCfg size[%lu] is less than loopVec size", executors.size(), loopCfg.size());
32 : }
33 :
34 38 : auto loopGroup = std::make_shared<CcuRepLoopGroup>(var1, var2);
35 :
36 38 : std::vector<std::shared_ptr<CcuRepLoop>> loops;
37 95 : for (uint32_t index = 0; index < loopVec.size(); index++) {
38 57 : Variable repVar;
39 57 : auto ret3 = CreateVariable(context, repVar);
40 57 : if (ret3 != HcclResult::HCCL_SUCCESS) {
41 0 : THROW<CcuApiException>("CreateVariable failed. ret3[%d]", ret3);
42 : }
43 57 : auto repLoop = std::make_shared<CcuRepLoop>(loopVec[index].GetLabel(), repVar);
44 57 : AppendToContext(context, repLoop->SetLoopParam(executors[index], loopCfg[index]));
45 57 : loops.push_back(repLoop);
46 57 : }
47 :
48 38 : Variable hideLoopVar;
49 38 : auto ret4 = CreateVariable(context, hideLoopVar);
50 38 : if (ret4 != HcclResult::HCCL_SUCCESS) {
51 0 : THROW<CcuApiException>("CreateVariable failed. ret4[%d]", ret4);
52 : }
53 38 : auto hideLoop = std::make_shared<CcuRepJump>("hideLoop", hideLoopVar);
54 38 : auto hideLoopLabel = std::make_shared<CcuRepJumpLabel>("hideLoop");
55 38 : hideLoop->Reference(hideLoopLabel);
56 :
57 38 : AppendToContext(context, loopGroup->SetParallelParam(paraCfgIn));
58 38 : AppendToContext(context, loopGroup->SetOffsetParam(offsetCfgIn));
59 38 : AppendToContext(context, loopGroup);
60 :
61 38 : AppendToContext(context, hideLoop);
62 95 : for (auto loop : loops) {
63 57 : AppendToContext(context, loop);
64 57 : }
65 38 : AppendToContext(context, hideLoopLabel);
66 38 : }
67 :
68 : }; // namespace CcuRep
69 : }; // namespace Hccl
|