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_v1.h"
12 : #include "ccu_kernel.h"
13 :
14 : #include "exception_util.h"
15 : #include "ccu_api_exception.h"
16 :
17 : namespace hcomm {
18 : namespace CcuRep {
19 :
20 700 : void AppendToContext(CcuRepContext* context, std::shared_ptr<CcuRep::CcuRepBase> rep)
21 : {
22 700 : if (context == nullptr) {
23 2 : Hccl::THROW<Hccl::CcuApiException>("context is nullptr, AppendToContext assist[%d]", rep->Type());
24 : } else {
25 698 : return context->Append(rep);
26 : }
27 : }
28 :
29 5 : std::shared_ptr<CcuRep::CcuRepBlock> CurrentBlock(CcuRepContext* context)
30 : {
31 5 : if (context == nullptr) {
32 1 : Hccl::THROW<Hccl::CcuApiException>("context is nullptr, currentBlock");
33 : }
34 4 : return context->CurrentBlock();
35 : }
36 :
37 3 : void SetCurrentBlock(CcuRepContext* context, std::shared_ptr<CcuRep::CcuRepBlock> repBlock)
38 : {
39 3 : if (context == nullptr) {
40 1 : Hccl::THROW<Hccl::CcuApiException>("context is nullptr, set currentBlock");
41 : }
42 2 : context->SetCurrentBlock(repBlock);
43 2 : }
44 :
45 39 : Variable CreateVariable(CcuRepContext* context)
46 : {
47 39 : if (context == nullptr) {
48 1 : Hccl::THROW<Hccl::CcuApiException>("context is nullptr, CreateVar");
49 : }
50 38 : auto ctx = dynamic_cast<CcuKernel*>(context);
51 38 : if (ctx == nullptr) {
52 0 : Hccl::THROW<Hccl::CcuApiException>("Invalid context");
53 : }
54 38 : return ctx->CreateVariable();
55 : }
56 :
57 : }; // namespace CcuRep
58 : }; // namespace hcomm
|