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 "coll_all_to_all_single_rank_executor.h"
12 :
13 : namespace hccl {
14 0 : CollAlltoAllSingleRankExecutor::CollAlltoAllSingleRankExecutor(const HcclDispatcher dispatcher,
15 0 : std::unique_ptr<TopoMatcher> &topoMatcher)
16 0 : : CollAlltoAllExecutor(dispatcher, topoMatcher)
17 : {
18 0 : }
19 :
20 0 : HcclResult CollAlltoAllSingleRankExecutor::Orchestrate(OpParam& param, AlgResourceResponse& algRes)
21 : {
22 0 : HcclUs startut = TIME_NOW();
23 0 : HcclResult ret = HCCL_SUCCESS;
24 0 : tag_ = param.tag;
25 0 : algResResp_ = &algRes;
26 0 : AlltoAllVParam_ = param;
27 0 : ExecMem execMem;
28 0 : execMem.count = 0;
29 0 : execMem.inputPtr = param.inputPtr;
30 0 : execMem.outputPtr = param.outputPtr;
31 :
32 0 : ret = KernelRun(param, execMem);
33 :
34 0 : CHK_PRT_RET(ret != HCCL_SUCCESS,
35 : HCCL_ERROR("[CollAlltoAllSingleRankExecutor][Orchestrate]errNo[0x%016llx]executor run failed",
36 : HCCL_ERROR_CODE(ret)), ret);
37 :
38 0 : HCCL_INFO("tag[%s], AlltoAllSingleRankExecutor orchestrate success, take time [%lld]us.",
39 : param.tag.c_str(), DURATION_US(TIME_NOW() - startut));
40 0 : return HCCL_SUCCESS;
41 0 : }
42 :
43 0 : HcclResult CollAlltoAllSingleRankExecutor::GetAdjInfo(AlgResourceResponse& algRes, AdjInfo& adjInfo)
44 : {
45 : (void) algRes;
46 : (void) adjInfo;
47 0 : return HCCL_SUCCESS;
48 : }
49 :
50 0 : HcclResult CollAlltoAllSingleRankExecutor::KernelRun(const OpParam ¶m, ExecMem &execMem)
51 : {
52 0 : HCCL_CONFIG_INFO(HCCL_ALG, "[CollAlltoAllSingleRankExecutor][KernelRun] userRank[%u] starts.", topoAttr_.userRank);
53 0 : u64 sendCount = 0 ;
54 0 : u64 totalSize = 0 ;
55 0 : u64 unitSize = SIZE_TABLE[param.All2AllDataDes.sendType] ;
56 0 : CopyPattern copyPattern = (execMem.inputPtr == execMem.outputPtr) ? CopyPattern::ZCOPY : CopyPattern::BCOPY ;
57 0 : HcclOpMetaInfo opMeta ;
58 0 : if (param.opType == HcclCMDType::HCCL_CMD_ALLTOALL || param.opType == HcclCMDType::HCCL_CMD_ALLTOALLVC){
59 0 : sendCount = *(static_cast<u64 *>(param.All2AllDataDes.sendCountMatrix));
60 0 : totalSize = sendCount * unitSize ;
61 0 : opMeta = HcclOpMetaInfo::GetOneForAllToAllVC(copyPattern, totalSize, totalSize > SDMA_SEND_MAX_SIZE);
62 : } else {
63 0 : sendCount = *(static_cast<u64 *>(param.All2AllDataDes.sendCounts)) ;
64 0 : totalSize = sendCount * unitSize ;
65 0 : opMeta = HcclOpMetaInfo::GetOneForAllToAllVC(copyPattern, totalSize, totalSize > SDMA_SEND_MAX_SIZE);
66 : }
67 0 : CHK_RET(InitTask(dispatcher_, const_cast<Stream&>(param.stream), opMeta.isEnableCache, opMeta.GetCacheKey()));
68 :
69 0 : if (execMem.inputPtr != execMem.outputPtr) {
70 0 : DeviceMem srcMem(execMem.inputPtr, totalSize);
71 0 : DeviceMem dstMem(execMem.outputPtr, totalSize);
72 0 : CHK_RET(HcclD2DMemcpyAsync(dispatcher_, dstMem, srcMem, const_cast<Stream&>(param.stream)));
73 0 : }
74 0 : CHK_RET(LaunchTaskExtend(dispatcher_, const_cast<Stream&>(param.stream), algResResp_->slaveStreams));
75 0 : return HCCL_SUCCESS;
76 : }
77 :
78 : REGISTER_EXEC("RunAlltoAllSingleExecutor", AlltoAllSingleRank, CollAlltoAllSingleRankExecutor);
79 :
80 : } // namespace hccl
|