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 : #include "local_cnt_notify.h"
12 :
13 : #include "exchange_ub_buffer_dto.h"
14 : #include "rdma_handle_manager.h"
15 : #include "local_ub_rma_buffer.h"
16 :
17 : namespace Hccl {
18 :
19 49 : LocalCntNotify::LocalCntNotify(RdmaHandle rdmaHandle, RtsCntNotify* notify) : rdmaHandle(rdmaHandle), notify(notify),
20 49 : tokenValue(GetUbToken()), addr(notify->GetAddr()), size(notify->GetSize())
21 : {
22 49 : auto tokenIdInfoPair = RdmaHandleManager::GetInstance().GetTokenIdInfo(rdmaHandle);
23 49 : TokenIdHandle tokenIdHandle = tokenIdInfoPair.first;
24 49 : tokenId = tokenIdInfoPair.second;
25 147 : HCCL_INFO("[LocalCntNotify] tokenIdHandle=0x[%llx].", tokenIdHandle);
26 49 : std::pair<u64, u64> alignBuf = BufAlign(addr, size);
27 49 : HrtRaUbLocMemRegParam memRegInput(alignBuf.first, alignBuf.second, tokenValue, tokenIdHandle);
28 49 : reqReg = HrtRaUbLocalMemReg(rdmaHandle, memRegInput);
29 49 : keySize = reqReg.keySize;
30 49 : memHandle = reqReg.handle;
31 49 : (void)memcpy_s(key, HRT_UB_MEM_KEY_MAX_LEN, reqReg.key, HRT_UB_MEM_KEY_MAX_LEN);
32 49 : }
33 :
34 2 : std::unique_ptr<Serializable> LocalCntNotify::GetExchangeDto()
35 : {
36 : std::unique_ptr<ExchangeUbBufferDto> dto
37 2 : = make_unique<ExchangeUbBufferDto>(addr, size, tokenValue, tokenId, keySize, notify->GetId());
38 2 : (void)memcpy_s(dto->key, HRT_UB_MEM_KEY_MAX_LEN, key, HRT_UB_MEM_KEY_MAX_LEN);
39 4 : return std::unique_ptr<Serializable>(dto.release());
40 2 : }
41 :
42 0 : std::string LocalCntNotify::Describe() const
43 : {
44 : return StringFormat("UbLocalNotify:notify=%s, addr=0x%llx, keySize=%u, memHandle=0x%llx",
45 0 : notify->Describe().c_str(), addr, keySize, memHandle);
46 : }
47 :
48 49 : LocalCntNotify::~LocalCntNotify()
49 : {
50 49 : if (rdmaHandle && memHandle != 0) {
51 2 : DECTOR_TRY_CATCH("LocalCntNotify", HrtRaUbLocalMemUnreg(rdmaHandle, memHandle));
52 : }
53 49 : }
54 : } // namespace Hccl
|