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