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_legacy.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, const LocalUbRmaBuffer& parent);
33 :
34 : LocalUbRmaBuffer(std::shared_ptr<Buffer> buf, void* netDevice, bool flag);
35 :
36 : LocalUbRmaBuffer(std::shared_ptr<Buffer> buf);
37 :
38 : ~LocalUbRmaBuffer() override;
39 :
40 : LocalUbRmaBuffer(const LocalUbRmaBuffer& that) = delete;
41 :
42 : LocalUbRmaBuffer& operator=(const LocalUbRmaBuffer& that) = delete;
43 :
44 : string Describe() const override;
45 :
46 : std::unique_ptr<Serializable> GetExchangeDto() override;
47 :
48 : u32 GetTokenId() const;
49 : u32 GetTokenValue() const;
50 : TokenIdHandle GetTokenIdHandle() const;
51 40 : std::pair<uintptr_t, u64> GetBufferInfo() { return make_pair(buf->GetAddr(), buf->GetSize()); }
52 4 : u64 GetTargetSeg() const { return reqReg.targetSegVa; }
53 :
54 16 : void* GetMemRegOutParam() { return static_cast<void*>(&reqReg); }
55 :
56 : const void* GetMemRegOutParam() const { return static_cast<const void*>(&reqReg); }
57 :
58 8 : static bool IsSameMemRegOutParam(const void* lhs, const void* rhs)
59 : {
60 8 : if (lhs == nullptr || rhs == nullptr) {
61 0 : return false;
62 : }
63 8 : const auto* left = static_cast<const HrtRaUbLocalMemRegOutParam*>(lhs);
64 8 : const auto* right = static_cast<const HrtRaUbLocalMemRegOutParam*>(rhs);
65 8 : if (left->keySize > HRT_UB_MEM_KEY_MAX_LEN) {
66 0 : return false;
67 : }
68 8 : return left->handle == right->handle && left->keySize == right->keySize
69 16 : && left->targetSegVa == right->targetSegVa && memcmp(left->key, right->key, left->keySize) == 0;
70 : }
71 :
72 : std::vector<char> Desc;
73 :
74 : private:
75 : RdmaHandle rdmaHandle{nullptr};
76 : HcclNetDevice* netDev{nullptr};
77 : u8 key[HRT_UB_MEM_KEY_MAX_LEN]{0};
78 : u32 tokenValue{0};
79 : u32 tokenId{0};
80 : TokenIdHandle tokenIdHandle{0};
81 :
82 : HrtRaUbLocalMemRegOutParam reqReg{};
83 :
84 : BufferKey<uintptr_t, u64> bufKey_{0, 0};
85 : };
86 : u32 GetUbToken(); // 生成伪随机数
87 : } // namespace Hccl
88 : #endif // HCCLV2_LOCAL_UB_RMA_BUFFER_H
|