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 : #ifndef HCCLV2_LOCAL_RMA_BUFFER_H
12 : #define HCCLV2_LOCAL_RMA_BUFFER_H
13 :
14 : #include <string>
15 : #include <memory>
16 : #include <vector>
17 :
18 : #include "buffer.h"
19 : #include "rma_type.h"
20 :
21 : #include "serializable.h"
22 : #include "rma_buffer_lite.h"
23 :
24 : namespace Hccl {
25 :
26 : class LocalRmaBuffer {
27 : public:
28 939 : LocalRmaBuffer(std::shared_ptr<Buffer> buf, RmaType type) : buf(buf), rmaType(type)
29 : {
30 939 : }
31 :
32 22 : LocalRmaBuffer(std::shared_ptr<Buffer> buf, RmaType type, bool isAlias) : buf(buf), rmaType(type), isAlias_(isAlias)
33 : {
34 22 : }
35 :
36 959 : virtual ~LocalRmaBuffer() = default;
37 :
38 : virtual std::string Describe() const = 0;
39 :
40 364 : Buffer *GetBuf() const
41 : {
42 364 : return buf.get();
43 : }
44 :
45 2 : RmaType GetRmaType() const // used for grant check
46 : {
47 2 : return rmaType;
48 : }
49 :
50 50 : bool IsAlias() const
51 : {
52 50 : return isAlias_;
53 : }
54 :
55 8 : u64 GetMemHandle() const
56 : {
57 8 : return memHandle;
58 : }
59 :
60 161 : size_t GetSize() const
61 : {
62 161 : return buf->GetSize();
63 : }
64 :
65 163 : uintptr_t GetAddr() const
66 : {
67 163 : return buf->GetAddr();
68 : }
69 :
70 0 : virtual std::unique_ptr<Serializable> GetExchangeDto()
71 : {
72 0 : HCCL_ERROR("this is base class, not support.");
73 0 : return nullptr;
74 : }
75 :
76 : protected:
77 : std::shared_ptr<Buffer> buf;
78 : RmaType rmaType;
79 : u64 memHandle{0};
80 : bool isAlias_{false}; // 区分该RmaBuffer对象是否为某一注册Buffer的子集
81 : };
82 :
83 : } // namespace Hccl
84 : #endif
|