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 "workspace_resource_impl.h"
12 : #include "workspace_resource.h"
13 :
14 : namespace hccl {
15 521 : WorkspaceResource::WorkspaceResource(u32 devicePhyId, s32 deviceLogicId, CCLBufferManager *cclBufferManagerPtr)
16 : {
17 521 : pimpl_.reset((new (std::nothrow)WorkspaceResourceImpl(devicePhyId, deviceLogicId, cclBufferManagerPtr)));
18 521 : }
19 :
20 519 : WorkspaceResource::~WorkspaceResource()
21 : {
22 519 : }
23 :
24 91 : HcclResult WorkspaceResource::GetWorkspaceMemSize(const std::string &opType, u64 count,
25 : HcclDataType dataType, u32 rankSize, u64 &memSize, DevType deviceType) const
26 : {
27 91 : CHK_SMART_PTR_NULL(pimpl_);
28 91 : return pimpl_->GetWorkspaceMemSize(opType, count, dataType, rankSize, memSize, deviceType);
29 : }
30 :
31 0 : HcclResult WorkspaceResource::RegisterMaster(const std::string &tag, Stream stream)
32 : {
33 0 : CHK_SMART_PTR_NULL(pimpl_);
34 0 : return pimpl_->RegisterMaster(tag, stream);
35 : }
36 :
37 : // 基于tag 初始设置资源,包含 Stream 资源 和 内存 资源
38 155 : HcclResult WorkspaceResource::SetWorkspaceResource(const std::string &tag, void *memPtr,
39 : u64 &maxSize, std::vector<rtStream_t> &stream)
40 : {
41 155 : CHK_SMART_PTR_NULL(pimpl_);
42 155 : return pimpl_->SetWorkspaceResource(tag, memPtr, maxSize, stream);
43 : }
44 :
45 : // 基于 tag 销毁资源,包含 Stream 资源 和 内存 资源
46 16 : void WorkspaceResource::DestroyWorkspaceResource(const std::string &tag)
47 : {
48 16 : CHK_SMART_PTR_RET_NULL(pimpl_);
49 14 : pimpl_->DestroyWorkspaceResource(tag);
50 16 : return;
51 : }
52 :
53 : // 销毁 Workspace全局资源,包含 Stream 资源 和 内存 资源
54 0 : void WorkspaceResource::DestroyWorkspaceResource()
55 : {
56 0 : CHK_SMART_PTR_RET_NULL(pimpl_);
57 0 : pimpl_->DestroyWorkspaceResource();
58 0 : return;
59 : }
60 :
61 : // 基于tag 分配 Stream 资源
62 15 : std::vector<Stream> WorkspaceResource::AllocSlaveStreams(const std::string &tag, u32 num)
63 : {
64 15 : HCCL_DEBUG("[WorkspaceResource][AllocSlaveStreams]requesting for [%u] slaves, tag[%s].", num, tag.c_str());
65 : // 安全性的保护,无实际业务意义
66 16 : if (!pimpl_) {
67 0 : HCCL_ERROR("[WorkspaceResource][AllocSlaveStreams] pimpl_ is nullptr.");
68 0 : return std::vector<Stream>();
69 : }
70 16 : return pimpl_->AllocSlaveStreams(tag, num);
71 : }
72 :
73 : // 基于tag 销毁 Stream 资源
74 0 : HcclResult WorkspaceResource::DestroyStream(const std::string &tag)
75 : {
76 0 : CHK_SMART_PTR_NULL(pimpl_);
77 0 : return pimpl_->DestroyStream(tag);
78 : }
79 :
80 24 : DeviceMem WorkspaceResource::AllocDeviceMem(const std::string &tag, u64 size)
81 : {
82 : // 安全性的保护,无实际业务意义
83 24 : if (!pimpl_) {
84 0 : HCCL_ERROR("[WorkspaceResource][AllocDeviceMem] pimpl_ is nullptr.");
85 0 : return DeviceMem::create(nullptr, 0);
86 : }
87 24 : return pimpl_->AllocDeviceMem(tag, size);
88 : }
89 :
90 : // 基于tag 销毁 DeviceMem 资源
91 0 : HcclResult WorkspaceResource::DestroyDeviceMem(const std::string &tag)
92 : {
93 0 : CHK_SMART_PTR_NULL(pimpl_);
94 0 : return pimpl_->DestroyDeviceMem(tag);
95 : }
96 :
97 95 : HcclResult WorkspaceResource::CreateOpBasedResources(const HcclCMDType &opType, const std::string &tag,
98 : const HcomCollOpInfo &opInfo)
99 : {
100 95 : CHK_SMART_PTR_NULL(pimpl_);
101 95 : return pimpl_->CreateOpBasedResources(opType, tag, opInfo);
102 : }
103 :
104 0 : HcclResult WorkspaceResource::CreateRemoteOpBasedResources(u64 memSize, const std::string &tag)
105 : {
106 0 : CHK_SMART_PTR_NULL(pimpl_);
107 0 : return pimpl_->CreateRemoteOpBasedResources(memSize, tag);
108 : }
109 :
110 0 : HcclResult WorkspaceResource::CreateOrUpdateRemoteOpBasedResources(u64 memSize, const std::string &tag)
111 : {
112 0 : CHK_SMART_PTR_NULL(pimpl_);
113 0 : return pimpl_->CreateOrUpdateRemoteOpBasedResources(memSize, tag);
114 : }
115 :
116 0 : HcclResult WorkspaceResource::DestroyRemoteOpBasedMem(const std::string &tag)
117 : {
118 0 : CHK_SMART_PTR_NULL(pimpl_);
119 0 : return pimpl_->DestroyRemoteOpBasedMem(tag);
120 : }
121 : } // namespace hccl
|