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 "independent_op.h"
12 : #include "launch_aicpu.h"
13 : #include "manager_common.h"
14 : #include "comm_configer.h"
15 : #include "adapter_prof.h"
16 : #include "hcom_host_profiling.h"
17 :
18 : namespace hccl {
19 :
20 653 : IndependentOp::IndependentOp() {};
21 :
22 235 : HcclResult IndependentOp::SetIndependentOpConfig(
23 : const CommConfig& commConfig, [[maybe_unused]] const RankTable_t& rankTable, const HcclTopoAttr& topoAttr,
24 : const aclrtBinHandle binHandle, HDCommunicateParams& kfcControlTransferH2DParams,
25 : HDCommunicateParams& kfcStatusTransferD2HParams, CCLBufferManager& bufferManager)
26 : {
27 235 : commEngine_ = HCCL_COMM_ENGINE_CONFIG_NOT_SET;
28 235 : threadNum_ = HCCL_COMM_THREADNUM_CONFIG_NOT_SET;
29 235 : notifyNumPerThread_ = HCCL_COMM_NOTIFY_NUM_PER_THREAD_CONFIG_NOT_SET;
30 235 : cclBufferSize_ = commConfig.GetConfigBufferSize();
31 235 : commId_ = commConfig.GetConfigCommName();
32 235 : commMemMgr_.CommSetHcclBufferManager(bufferManager);
33 235 : binHandle_ = binHandle;
34 :
35 : // aicpu侧初始化状态的回调函数
36 235 : ManagerCallbacks callbacks;
37 471 : callbacks.getAicpuCommState = [this]() {
38 1 : return this->GetAicpuCommState();
39 235 : };
40 471 : callbacks.setAicpuCommState = [this](bool state) {
41 1 : this->SetAicpuCommState(state);
42 235 : };
43 471 : callbacks.kernelLaunchAicpuCommInit = [this]() {
44 1 : return this->KernelLaunchAicpuCommInit();
45 235 : };
46 :
47 235 : CHK_PRT(engineResMgr_.Init(threadNum_, notifyNumPerThread_, commId_, binHandle, callbacks));
48 235 : CHK_PRT(channelMgr_.Init(binHandle, topoAttr.userRank, callbacks));
49 :
50 : // Aicpu通信域初始化参数
51 235 : snprintf_s(commAicpuParam_.hcomId, HCOMID_MAX_SIZE, HCOMID_MAX_SIZE - 1, "%s", commId_.c_str());
52 235 : commAicpuParam_.deviceLogicId = topoAttr.deviceLogicId;
53 235 : commAicpuParam_.devicePhyId = topoAttr.devicePhyId;
54 235 : commAicpuParam_.deviceType = static_cast<u32>(topoAttr.deviceType);
55 235 : commAicpuParam_.kfcControlTransferH2DParams = kfcControlTransferH2DParams;
56 235 : commAicpuParam_.kfcStatusTransferD2HParams = kfcStatusTransferD2HParams;
57 235 : commAicpuParam_.userRank = topoAttr.userRank;
58 235 : commAicpuParam_.userRankSize = topoAttr.userRankSize;
59 235 : CHK_PRT(channelMgr_.SetHcclQos(commConfig.GetConfigHcclQos()));
60 235 : HCCL_INFO(
61 : "[IndependentOp][%s] Hcom[%s] threadNum[%u], notifyPerThread[%u], cclBufferSize[%llu], deviceLogicId[%u], "
62 : "devicePhyId[%u], deviceType[%u], userRank[%u], userRankSize[%u]",
63 : __func__, commId_.c_str(), threadNum_, notifyNumPerThread_, cclBufferSize_, commAicpuParam_.deviceLogicId,
64 : commAicpuParam_.devicePhyId, commAicpuParam_.deviceType, commAicpuParam_.userRank,
65 : commAicpuParam_.userRankSize);
66 235 : return HCCL_SUCCESS;
67 235 : }
68 :
69 2 : bool IndependentOp::GetAicpuCommState() { return isAicpuCommInit_; }
70 :
71 1 : void IndependentOp::SetAicpuCommState(bool aicpuCommState)
72 : {
73 1 : isAicpuCommInit_ = aicpuCommState;
74 1 : return;
75 : }
76 :
77 1 : HcclResult IndependentOp::KernelLaunchAicpuCommInit()
78 : {
79 : // 创建局部流
80 1 : uint64_t beginTime = hrtMsprofSysCycleTime();
81 1 : Stream localStream(StreamType::STREAM_TYPE_ONLINE);
82 1 : constexpr u32 aicpuStreamMode = 1;
83 1 : CHK_RET(hrtStreamSetMode(localStream.ptr(), aicpuStreamMode));
84 :
85 : // 下kernel进行自定义算子aicpu侧通信域的公共初始化
86 1 : std::string kernelName = "RunAicpuCommInit";
87 :
88 1 : u16 timeOut = NOTIFY_DEFAULT_WAIT_TIME > std::numeric_limits<uint16_t>::max() ?
89 : std::numeric_limits<uint16_t>::max() :
90 : NOTIFY_DEFAULT_WAIT_TIME;
91 1 : CHK_RET(AicpuAclKernelLaunch(
92 : localStream.ptr(), reinterpret_cast<void*>(&commAicpuParam_), sizeof(commAicpuParam_), binHandle_, kernelName,
93 : true, timeOut));
94 3 : CHK_RET(hcclStreamSynchronize(localStream.ptr(), CommConfiger::GetInstance().GetCommConfigExecTimeOut("")));
95 :
96 : // 打印增加初始化对应的参数
97 1 : HCCL_RUN_INFO("[%s] KernelLaunchAicpuCommInit Success", __func__);
98 1 : const std::string profName = "RunAicpuCommInit";
99 1 : HCCL_INFO("[%s] RunAicpuCommInit", __func__);
100 : // 上报初始化kernel的时间
101 1 : HcommProfilingReportKernel(beginTime, profName.c_str());
102 1 : return HCCL_SUCCESS;
103 1 : }
104 :
105 404 : HcclResult IndependentOp::SetChannelCallbacks(const ChannelManagerCallbacks& channelCallbacks)
106 : {
107 404 : return channelMgr_.SetChannelCallbacks(channelCallbacks);
108 : }
109 :
110 : } // namespace hccl
|