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_UB_RMA_BUFFER_H
12 : #define HCCLV2_LOCAL_UB_RMA_BUFFER_H
13 :
14 : #include <cstring>
15 :
16 : #include "local_rma_buffer.h"
17 :
18 : #include "enum_factory.h"
19 : #include "orion_adapter_hccp.h"
20 : #include "orion_adapter_rts.h"
21 : #include "net_device.h"
22 :
23 : namespace Hccl {
24 :
25 : MAKE_ENUM(UbBufferStatus, INIT, READY, RELEASED);
26 :
27 : class LocalUbRmaBuffer : public LocalRmaBuffer {
28 : public:
29 : LocalUbRmaBuffer(std::shared_ptr<Buffer> buf, RdmaHandle rdmaHandle);
30 :
31 : // 别名构造函数:共享父buffer的注册资源
32 : LocalUbRmaBuffer(std::shared_ptr<Buffer> buf, RdmaHandle rdmaHandle,
33 : const LocalUbRmaBuffer &parent);
34 :
35 : LocalUbRmaBuffer(std::shared_ptr<Buffer> buf, void* netDevice, bool flag);
36 :
37 : LocalUbRmaBuffer(std::shared_ptr<Buffer> buf);
38 :
39 : ~LocalUbRmaBuffer() override;
40 :
41 : LocalUbRmaBuffer(const LocalUbRmaBuffer &that) = delete;
42 :
43 : LocalUbRmaBuffer &operator=(const LocalUbRmaBuffer &that) = delete;
44 :
45 : string Describe() const override;
46 :
47 : std::unique_ptr<Serializable> GetExchangeDto() override;
48 :
49 : u32 GetTokenId() const;
50 : u32 GetTokenValue() const;
51 : TokenIdHandle GetTokenIdHandle() const;
52 40 : std::pair<uintptr_t, u64> GetBufferInfo() {return make_pair(buf->GetAddr(), buf->GetSize());}
53 4 : u64 GetTargetSeg() const {return reqReg.targetSegVa;}
54 :
55 16 : void *GetMemRegOutParam()
56 : {
57 16 : return static_cast<void *>(&reqReg);
58 : }
59 :
60 : const void *GetMemRegOutParam() const
61 : {
62 : return static_cast<const void *>(&reqReg);
63 : }
64 :
65 8 : static bool IsSameMemRegOutParam(const void *lhs, const void *rhs)
66 : {
67 8 : if (lhs == nullptr || rhs == nullptr) {
68 0 : return false;
69 : }
70 8 : const auto *left = static_cast<const HrtRaUbLocalMemRegOutParam *>(lhs);
71 8 : const auto *right = static_cast<const HrtRaUbLocalMemRegOutParam *>(rhs);
72 8 : if (left->keySize > HRT_UB_MEM_KEY_MAX_LEN) {
73 0 : return false;
74 : }
75 16 : return left->handle == right->handle &&
76 8 : left->keySize == right->keySize &&
77 24 : left->targetSegVa == right->targetSegVa &&
78 16 : memcmp(left->key, right->key, left->keySize) == 0;
79 : }
80 :
81 : std::vector<char> Desc;
82 :
83 : private:
84 : RdmaHandle rdmaHandle{nullptr};
85 : HcclNetDevice *netDev{nullptr};
86 : u8 key[HRT_UB_MEM_KEY_MAX_LEN]{0};
87 : u32 tokenValue{0};
88 : u32 tokenId{0};
89 : TokenIdHandle tokenIdHandle{0};
90 :
91 : HrtRaUbLocalMemRegOutParam reqReg{};
92 :
93 : BufferKey<uintptr_t, u64> bufKey_{0, 0};
94 : };
95 : u32 GetUbToken(); // 生成伪随机数
96 : } // namespace Hccl
97 : #endif // HCCLV2_LOCAL_UB_RMA_BUFFER_H
|