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