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 : std::pair<u64, u64> alignBuf = BufAlign(addr, size);
23 49 : bufKey_ = BufferKey<uintptr_t, u64>{alignBuf.first, alignBuf.second};
24 49 : auto tokenIdInfoPair = RdmaHandleManager::GetInstance().GetTokenIdInfo(rdmaHandle, bufKey_);
25 49 : tokenIdHandle_ = tokenIdInfoPair.first;
26 49 : tokenId = tokenIdInfoPair.second;
27 147 : HCCL_INFO("[LocalCntNotify] tokenIdHandle=0x[%llx].", tokenIdHandle_);
28 49 : HrtRaUbLocMemRegParam memRegInput(alignBuf.first, alignBuf.second, tokenValue, tokenIdHandle_);
29 49 : reqReg = HrtRaUbLocalMemReg(rdmaHandle, memRegInput);
30 49 : keySize = reqReg.keySize;
31 49 : memHandle = reqReg.handle;
32 49 : (void)memcpy_s(key, HRT_UB_MEM_KEY_MAX_LEN, reqReg.key, HRT_UB_MEM_KEY_MAX_LEN);
33 49 : }
34 :
35 2 : std::unique_ptr<Serializable> LocalCntNotify::GetExchangeDto()
36 : {
37 : std::unique_ptr<ExchangeUbBufferDto> dto
38 2 : = make_unique<ExchangeUbBufferDto>(addr, size, tokenValue, tokenId, keySize, notify->GetId());
39 2 : (void)memcpy_s(dto->key, HRT_UB_MEM_KEY_MAX_LEN, key, HRT_UB_MEM_KEY_MAX_LEN);
40 4 : return std::unique_ptr<Serializable>(dto.release());
41 2 : }
42 :
43 0 : std::string LocalCntNotify::Describe() const
44 : {
45 : return StringFormat("UbLocalNotify:notify=%s, addr=0x%llx, keySize=%u, memHandle=0x%llx",
46 0 : notify->Describe().c_str(), addr, keySize, memHandle);
47 : }
48 :
49 49 : LocalCntNotify::~LocalCntNotify()
50 : {
51 49 : if (rdmaHandle && memHandle != 0) {
52 2 : DECTOR_TRY_CATCH("LocalCntNotify", HrtRaUbLocalMemUnreg(rdmaHandle, memHandle));
53 : }
54 :
55 49 : if (rdmaHandle) {
56 49 : RdmaHandleManager::GetInstance().PutTokenIdInfo(rdmaHandle, bufKey_, tokenIdHandle_);
57 : }
58 49 : }
59 : } // namespace Hccl
|