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_interface_assist.h"
12 : #include "ccu_ctx.h"
13 :
14 : #include "exception_util.h"
15 : #include "ccu_api_exception.h"
16 :
17 : namespace Hccl {
18 : namespace CcuRep {
19 :
20 1434 : void AppendToContext(CcuRepContext* context, std::shared_ptr<CcuRep::CcuRepBase> rep)
21 : {
22 1434 : if (context == nullptr) {
23 0 : THROW<CcuApiException>("context is nullptr");
24 : }
25 : else {
26 1434 : return context->Append(rep);
27 : }
28 : }
29 :
30 37 : std::shared_ptr<CcuRep::CcuRepBlock> CurrentBlock(CcuRepContext* context)
31 : {
32 37 : if (context == nullptr) {
33 0 : THROW<CcuApiException>("context is nullptr");
34 : }
35 37 : return context->CurrentBlock();
36 : }
37 :
38 74 : void SetCurrentBlock(CcuRepContext* context, std::shared_ptr<CcuRep::CcuRepBlock> repBlock)
39 : {
40 74 : if (context == nullptr) {
41 0 : THROW<CcuApiException>("context is nullptr");
42 : }
43 74 : context->SetCurrentBlock(repBlock);
44 74 : }
45 :
46 216 : HcclResult CreateVariable(CcuRepContext* context, Variable &variable)
47 : {
48 648 : HCCL_INFO("[CreateVariable] Input params: context[%p]", context);
49 216 : if (context == nullptr) {
50 0 : HCCL_ERROR("context is nullptr");
51 0 : return HCCL_E_PTR;
52 : }
53 216 : auto ctx = dynamic_cast<CcuContext*>(context);
54 216 : if (ctx == nullptr) {
55 0 : HCCL_ERROR("Invalid context");
56 0 : return HCCL_E_PTR;
57 : }
58 216 : variable = ctx->CreateVariable();
59 216 : return HCCL_SUCCESS;
60 : }
61 :
62 : }; // namespace CcuRep
63 : }; // namespace Hccl
|