Line data Source code
1 : /*
2 : * Copyright (c) Huawei Technologies Co., Ltd. 2024-2024. All rights reserved.
3 : * Description: ccu representation implementation file
4 : * Author: sunzhepeng
5 : * Create: 2024-06-17
6 : */
7 :
8 : #include "ccu_interface_assist_v1.h"
9 : #include "ccu_kernel.h"
10 :
11 : #include "exception_util.h"
12 : #include "ccu_api_exception.h"
13 :
14 : namespace hcomm {
15 : namespace CcuRep {
16 :
17 526 : void AppendToContext(CcuRepContext* context, std::shared_ptr<CcuRep::CcuRepBase> rep)
18 : {
19 526 : if (context == nullptr) {
20 2 : Hccl::THROW<Hccl::CcuApiException>("context is nullptr, AppendToContext assist[%d]", rep->Type());
21 : }
22 : else {
23 524 : return context->Append(rep);
24 : }
25 : }
26 :
27 5 : std::shared_ptr<CcuRep::CcuRepBlock> CurrentBlock(CcuRepContext* context)
28 : {
29 5 : if (context == nullptr) {
30 1 : Hccl::THROW<Hccl::CcuApiException>("context is nullptr, currentBlock");
31 : }
32 4 : return context->CurrentBlock();
33 : }
34 :
35 3 : void SetCurrentBlock(CcuRepContext* context, std::shared_ptr<CcuRep::CcuRepBlock> repBlock)
36 : {
37 3 : if (context == nullptr) {
38 1 : Hccl::THROW<Hccl::CcuApiException>("context is nullptr, set currentBlock");
39 : }
40 2 : context->SetCurrentBlock(repBlock);
41 2 : }
42 :
43 51 : Variable CreateVariable(CcuRepContext* context)
44 : {
45 51 : if (context == nullptr) {
46 1 : Hccl::THROW<Hccl::CcuApiException>("context is nullptr, CreateVar");
47 : }
48 50 : auto ctx = dynamic_cast<CcuKernel *>(context);
49 50 : if (ctx == nullptr) {
50 0 : Hccl::THROW<Hccl::CcuApiException>("Invalid context");
51 : }
52 50 : return ctx->CreateVariable();
53 : }
54 :
55 : }; // namespace CcuRep
56 : }; // namespace hcomm
|