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 "dispatcher_virtural.h"
12 : #include "hccl_tbe_task.h"
13 :
14 : namespace hccl {
15 524 : DispatcherVirtural::DispatcherVirtural(const s32 deviceLogicId) : DispatcherPub(deviceLogicId) {}
16 :
17 1048 : DispatcherVirtural::~DispatcherVirtural() {}
18 :
19 524 : HcclResult DispatcherVirtural::Init()
20 : {
21 : #ifndef HCCD
22 524 : if (deviceLogicId_ == HOST_DEVICE_ID) {
23 0 : return HCCL_SUCCESS;
24 : }
25 :
26 524 : aclrtContext ctx = nullptr;
27 524 : CHK_RET(hrtCtxGetCurrent(&ctx));
28 524 : if (ctx == nullptr) {
29 0 : CHK_RET(hrtSetDevice(deviceLogicId_));
30 0 : setDeviceFlag_ = true;
31 : }
32 :
33 524 : CHK_RET(HcclTbeTaskInit(deviceLogicId_));
34 : #else
35 : HCCL_ERROR("does not support this interface.");
36 : return HCCL_E_PARA;
37 : #endif
38 524 : return HCCL_SUCCESS;
39 : }
40 :
41 0 : HcclResult DispatcherVirtural::SignalRecord(
42 : HcclRtNotify signal, Stream& stream, u32 userRank, u64 offset, s32 stage, bool inchip, u64 signalAddr, u32 notifyId)
43 : {
44 : TaskLogicInfo info(
45 : 0, TaskLogicType::DISPATCHER_TYPE, TaskLogicFuncType::DISPATCHER_SIGNALRECORD_TYPE, signal, userRank, offset,
46 0 : stage);
47 0 : stream.PushTaskLogicInfo(info);
48 :
49 0 : return HCCL_SUCCESS;
50 0 : }
51 :
52 0 : HcclResult DispatcherVirtural::SignalWait(
53 : HcclRtNotify signal, Stream& stream, u32 userRank, u32 remoteUserRank, s32 stage, bool inchip, u32 notifyId,
54 : u32 timeOut)
55 : {
56 : TaskLogicInfo info(
57 : 0, TaskLogicType::DISPATCHER_TYPE, TaskLogicFuncType::DISPATCHER_SIGNALWAIT_TYPE, signal, userRank,
58 0 : remoteUserRank, stage);
59 0 : stream.PushTaskLogicInfo(info);
60 0 : return HCCL_SUCCESS;
61 0 : }
62 :
63 0 : HcclResult DispatcherVirtural::MemcpyAsync(
64 : hccl::DeviceMem& dst, const hccl::DeviceMem& src, hccl::Stream& stream, u32 remoteUserRank,
65 : hccl::LinkType inLinkType)
66 : {
67 0 : if (dst.size() < src.size()) {
68 0 : HCCL_ERROR(
69 : "The size of dst is smaller than that of src. dst addr[%p], dst size[%llu], src addr[%p], src size[%llu]",
70 : dst.ptr(), dst.size(), src.ptr(), src.size());
71 0 : return HCCL_E_PTR;
72 : }
73 :
74 : TaskLogicInfo info(
75 0 : 0, TaskLogicType::DISPATCHER_TYPE, TaskLogicFuncType::DISPATCHER_MEMCPYASYNC_TYPE, dst.ptr(), dst.size(),
76 0 : src.ptr(), src.size(), HcclRtMemcpyKind::HCCL_RT_MEMCPY_KIND_DEVICE_TO_DEVICE);
77 :
78 0 : stream.PushTaskLogicInfo(info);
79 0 : return HCCL_SUCCESS;
80 0 : }
81 : } // namespace hccl
|