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