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_reduce_scatter_single_rank_executor.h"
12 :
13 : namespace hccl {
14 :
15 1 : CollReduceScatterSingleRankExecutor::CollReduceScatterSingleRankExecutor(const HcclDispatcher dispatcher,
16 1 : std::unique_ptr<TopoMatcher> &topoMatcher)
17 1 : : CollReduceScatterExecutor(dispatcher, topoMatcher)
18 : {
19 1 : }
20 :
21 0 : HcclResult CollReduceScatterSingleRankExecutor::KernelRun(const OpParam ¶m, ExecMem &execMem)
22 : {
23 0 : HCCL_CONFIG_INFO(HCCL_ALG, "[CollReduceScatterSingleRankExecutor][KernelRun] userRank[%u] starts.", topoAttr_.userRank);
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 :
29 0 : auto originalAlgTypeLevel1 = static_cast<u32>(algType_.algoLevel1);
30 0 : bool hugeData = totalSize > SDMA_SEND_MAX_SIZE;
31 0 : bool smallData = totalSize <= HCCL_SMALL_COUNT_32_KB;
32 0 : u8 deterministic = topoMatcher_->GetExternalInputHcclDeterministic();
33 0 : if (execMem.inputPtr == execMem.outputPtr) {
34 0 : auto opMeta = HcclOpMetaInfo::GetOneForReduceScatter(originalAlgTypeLevel1, param.DataDes.dataType, reduceType,
35 : hugeData, smallData, CopyPattern::ZCOPY, false, deterministic, false); // 通过CopyPattern字段区分不同的子图
36 0 : CHK_RET(InitTask(dispatcher_, const_cast<Stream&>(param.stream), opMeta.isEnableCache, opMeta.GetCacheKey()));
37 : } else { // ranksize = 1; input、output地址不同,input->output
38 0 : auto opMeta = HcclOpMetaInfo::GetOneForReduceScatter(originalAlgTypeLevel1, param.DataDes.dataType, reduceType,
39 : hugeData, smallData, CopyPattern::BCOPY, false, deterministic, false);
40 0 : CHK_RET(InitTask(dispatcher_, const_cast<Stream&>(param.stream), opMeta.isEnableCache, opMeta.GetCacheKey()));
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(LaunchTaskExtend(dispatcher_, const_cast<Stream&>(param.stream), algResResp_->slaveStreams));
46 :
47 0 : return HCCL_SUCCESS;
48 : }
49 :
50 : REGISTER_EXEC("ReduceScatterSingleExecutor", ReduceScatterSingleRank, CollReduceScatterSingleRankExecutor);
51 :
52 : } // namespace hccl
|