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