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_reduce_single_rank_executor.h"
12 :
13 : namespace hccl {
14 :
15 0 : CollAllReduceSingleRankExecutor::CollAllReduceSingleRankExecutor(const HcclDispatcher dispatcher,
16 0 : std::unique_ptr<TopoMatcher> &topoMatcher)
17 0 : : CollAllReduceExecutor(dispatcher, topoMatcher)
18 : {
19 0 : }
20 :
21 0 : HcclResult CollAllReduceSingleRankExecutor::KernelRun(const OpParam ¶m, ExecMem &execMem)
22 : {
23 0 : HCCL_CONFIG_INFO(HCCL_ALG, "[CollAllReduceSingleRankExecutor][KernelRun] AllReduce single rank");
24 0 : u64 totalSize = execMem.count * SIZE_TABLE[param.DataDes.dataType];
25 0 : ReduceType reduceType =
26 0 : ((param.reduceType != HCCL_REDUCE_PROD) && (param.DataDes.dataType != HCCL_DATA_TYPE_INT64)) ?
27 : ReduceType::INLINE_REDUCE : ReduceType::TBE_REDUCE;
28 0 : auto originalAlgTypeLevel1 = static_cast<u32>(algType_.algoLevel1);
29 0 : bool hugeData = totalSize > SDMA_SEND_MAX_SIZE;
30 0 : if (execMem.inputPtr == execMem.outputPtr) {
31 0 : auto opMeta = HcclOpMetaInfo::GetOneForAllReduce(originalAlgTypeLevel1, param.DataDes.dataType, reduceType,
32 : totalSize <= HCCL_SMALL_COUNT_128_KB, 1, hugeData, CopyPattern::ZCOPY); // 通过CopyPattern字段区分不同子图
33 0 : CHK_RET(InitTask(dispatcher_, const_cast<Stream&>(param.stream), opMeta.isEnableCache, opMeta.GetCacheKey()));
34 : } else {
35 0 : auto opMeta = HcclOpMetaInfo::GetOneForAllReduce(originalAlgTypeLevel1, param.DataDes.dataType, reduceType,
36 : totalSize <= HCCL_SMALL_COUNT_128_KB, 1, hugeData, CopyPattern::BCOPY); // 通过CopyPattern字段区分不同子图
37 0 : CHK_RET(InitTask(dispatcher_, const_cast<Stream&>(param.stream), opMeta.isEnableCache, opMeta.GetCacheKey()));
38 : // ranksize = 1; input、output地址不同,input->output
39 0 : DeviceMem srcMem(execMem.inputPtr, totalSize);
40 0 : DeviceMem dstMem(execMem.outputPtr, totalSize);
41 0 : CHK_RET(HcclD2DMemcpyAsync(dispatcher_, dstMem, srcMem, const_cast<Stream&>(param.stream)));
42 0 : }
43 0 : CHK_RET(LaunchTask(dispatcher_, const_cast<Stream&>(param.stream)));
44 0 : return HCCL_SUCCESS;
45 : }
46 :
47 : REGISTER_EXEC("AllReduceSingleExecutor", AllReduceSingleRank, CollAllReduceSingleRankExecutor);
48 :
49 : } // namespace hccl
|