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