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 "aicpu_symmetric_memory.h"
12 : #include "symmetric_memory/symmetric_memory.h"
13 :
14 : #ifdef CCL_KERNEL_AICPU
15 : namespace hccl {
16 :
17 : class SymmetricMemory::SimpleVaAllocator {
18 : public:
19 : // 不需要任何成员,只要让编译器觉得它是个完整的类就行
20 : SimpleVaAllocator() {}
21 : ~SimpleVaAllocator() {}
22 : };
23 :
24 : SymmetricMemory::~SymmetricMemory() {}
25 : }
26 : #endif // CCL_KERNEL_AICPU
27 :
28 : using namespace hccl;
29 :
30 : #ifdef __cplusplus
31 : extern "C" {
32 : #endif // __cplusplus
33 :
34 2 : HcclResult HcclSymWinGetPeerPointer(HcclCommSymWindow winHandle, size_t offset, uint32_t peerRank, void** ptr)
35 : {
36 2 : CHK_PTR_NULL(winHandle);
37 2 : CHK_PTR_NULL(ptr);
38 2 : SymmetricWindow *symWin = reinterpret_cast<SymmetricWindow *>(winHandle);
39 2 : CHK_PRT_RET(peerRank >= symWin->rankSize,
40 : HCCL_ERROR("[HcclSymWinGetPeerPointer] Invalid peerRank: %d. rankSize[%u]", peerRank, symWin->rankSize), HCCL_E_PARA);
41 2 : CHK_PRT_RET(offset >= symWin->userSize,
42 : HCCL_ERROR("[%s] Invalid offset: %llu. userSize[%llu]", __func__, offset, symWin->userSize), HCCL_E_PARA);
43 :
44 2 : if (symWin->mode == SymmetricMemoryMode::URMA) {
45 0 : CHK_PTR_NULL(symWin->remoteMems);
46 0 : CHK_PRT_RET(peerRank >= symWin->remoteMemNum,
47 : HCCL_ERROR("[HcclSymWinGetPeerPointer] Invalid peerRank: %d. remoteMemNum[%u]",
48 : peerRank, symWin->remoteMemNum), HCCL_E_PARA);
49 0 : CommMem &remoteMem = symWin->remoteMems[peerRank];
50 0 : CHK_PRT_RET(remoteMem.addr == nullptr || remoteMem.type == COMM_MEM_TYPE_INVALID,
51 : HCCL_ERROR("[HcclSymWinGetPeerPointer] remote mem is invalid, peerRank[%u], addr[%p], type[%d].",
52 : peerRank, remoteMem.addr, remoteMem.type), HCCL_E_PARA);
53 0 : CHK_PRT_RET(offset >= remoteMem.size,
54 : HCCL_ERROR("[%s] Invalid offset: %llu. remoteMemSize[%llu]", __func__, offset, remoteMem.size),
55 : HCCL_E_PARA);
56 0 : *ptr = reinterpret_cast<void *>(reinterpret_cast<uintptr_t>(remoteMem.addr) + offset);
57 0 : HCCL_INFO("[HcclSymWinGetPeerPointer] Get URMA Ptr[%p] from winHandle[%p], peerRank[%d], offset[%llu]",
58 : *ptr, winHandle, peerRank, offset);
59 0 : return HCCL_SUCCESS;
60 : }
61 :
62 2 : size_t peerOffset = peerRank * symWin->stride + offset;
63 2 : *ptr = reinterpret_cast<void *>(reinterpret_cast<uintptr_t>(symWin->baseVa) + peerOffset);
64 2 : HCCL_INFO("[HcclSymWinGetPeerPointer] Get Ptr[%p] from winHandle[%p], peerRank[%d], peerOffset[%llu]",
65 : *ptr, winHandle, peerRank, peerOffset);
66 :
67 2 : return HCCL_SUCCESS;
68 : }
69 :
70 : #ifdef __cplusplus
71 : }
72 : #endif // __cplusplus
|