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_single_rank_executor.h"
12 :
13 : namespace hccl {
14 :
15 0 : CollReduceSingleRankExecutor::CollReduceSingleRankExecutor(const HcclDispatcher dispatcher,
16 0 : std::unique_ptr<TopoMatcher> &topoMatcher)
17 0 : : CollReduceExecutor(dispatcher, topoMatcher)
18 : {
19 0 : }
20 :
21 0 : HcclResult CollReduceSingleRankExecutor::KernelRun(const OpParam ¶m, ExecMem &execMem)
22 : {
23 0 : HCCL_CONFIG_INFO(HCCL_ALG, "[CollReduceSingleRankExecutor][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 0 : auto autoSelectedAlgTypeLevel1 = static_cast<u32>(algType_.algoLevel1);
30 0 : bool isRootRank = param.root == topoAttr_.realUserRank ? true : false;
31 0 : bool hugeData = IsHugeData(totalSize); // override
32 0 : u8 deterministic = topoMatcher_->GetExternalInputHcclDeterministic();
33 :
34 0 : auto opMeta = HcclOpMetaInfo::GetOneForReduce(isRootRank, param.root, autoSelectedAlgTypeLevel1,
35 0 : param.DataDes.dataType, reduceType, hugeData, deterministic);
36 0 : CHK_RET(InitTask(dispatcher_, const_cast<Stream&>(param.stream), opMeta.isEnableCache, opMeta.GetCacheKey()));
37 :
38 0 : DeviceMem srcMem(execMem.inputPtr, totalSize);
39 0 : DeviceMem dstMem(execMem.outputPtr, totalSize);
40 0 : CHK_RET(HcclD2DMemcpyAsync(dispatcher_, dstMem, srcMem, const_cast<Stream &>(param.stream)));
41 0 : CHK_RET(LaunchTask(dispatcher_, const_cast<Stream &>(param.stream)));
42 0 : return HCCL_SUCCESS;
43 0 : }
44 :
45 : REGISTER_EXEC("ReduceSingleExecutor", ReduceSingleRank, CollReduceSingleRankExecutor);
46 :
47 : } // namespace hccl
|