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 "alltoallv_staged_base.h"
12 : #include "log.h"
13 :
14 : namespace hccl {
15 : using namespace std;
16 :
17 2 : AlltoAllVStagedBase::AlltoAllVStagedBase(const HcclDispatcher dispatcher) : AlgTemplateBase(dispatcher) {}
18 :
19 2 : AlltoAllVStagedBase::~AlltoAllVStagedBase() {}
20 :
21 3 : HcclResult AlltoAllVStagedBase::Prepare(
22 : DeviceMem& sendMem, DeviceMem& recvMem, StageAlltoAllVAddrInfo& sendAddrInfo, StageAlltoAllVAddrInfo& recvAddrInfo,
23 : bool isAlltoAllZCopyMode, Stream& mainStream)
24 : {
25 3 : sendMem_ = sendMem;
26 3 : recvMem_ = recvMem;
27 3 : sendAddrInfo_ = sendAddrInfo;
28 3 : recvAddrInfo_ = recvAddrInfo;
29 3 : isAlltoAllZCopyMode_ = isAlltoAllZCopyMode;
30 3 : mainStreamPtr_ = &mainStream;
31 3 : return HCCL_SUCCESS;
32 : }
33 :
34 0 : HcclResult AlltoAllVStagedBase::LocalCopy(u32 rank)
35 : {
36 0 : if (sendAddrInfo_.find(rank) == sendAddrInfo_.end()) {
37 0 : HCCL_ERROR("[AlltoAllVStaged][LocalCopy] Invalid Rank[%u]", rank);
38 0 : return HCCL_E_INTERNAL;
39 : }
40 :
41 0 : for (auto it = sendAddrInfo_[rank].begin(); it != sendAddrInfo_[rank].end(); it++) {
42 0 : u8* dstAddr = static_cast<u8*>(recvMem_.ptr()) + it->remoteOffset;
43 0 : u64 destMax = it->remoteLength;
44 0 : u8* srcAddr = static_cast<u8*>(sendMem_.ptr()) + it->localOffset;
45 0 : u64 size = it->localLength;
46 0 : DeviceMem dst = DeviceMem::create(dstAddr, destMax);
47 0 : DeviceMem src = DeviceMem::create(srcAddr, size);
48 :
49 0 : HCCL_DEBUG(
50 : "[AlltoAllVStagedPairwise][LocalCopy]: Rank[%u] destAddr[%p], destMax[%llu], srcAddr[%p], size[%llu]", rank,
51 : dstAddr, destMax, srcAddr, size);
52 0 : CHK_RET(HcclD2DMemcpyAsync(dispatcher_, dst, src, *mainStreamPtr_));
53 0 : }
54 :
55 0 : return HCCL_SUCCESS;
56 : }
57 : } // namespace hccl
|