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