已合并
refactor: 隔离 arch5162 ApiMbuf 组件 #4254
refactor: 隔离 arch5162 ApiMbuf 组件 #4254
已合并
zhangpengpeng8创建于 8月14日
5 个文件变更+233-6
@@ -0,0 +1,159 @@
1+/**
2+ * Copyright (c) 2026 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+#include "api.hpp"
11+ 
12+#ifdef __cplusplus
13+extern "C" {
14+#endif // __cplusplus
15+ 
16+VISIBILITY_DEFAULT
17+rtError_t rtMbufInit(rtMemBuffCfg_t* cfg)
18+{
19+ UNUSED(cfg);
20+ return ACL_ERROR_RT_FEATURE_NOT_SUPPORT;
21+}
22+ 
23+VISIBILITY_DEFAULT
24+rtError_t rtMbufBuild(void* buff, const uint64_t size, rtMbufPtr_t* mbufPtr)
25+{
26+ UNUSED(buff);
27+ UNUSED(size);
28+ UNUSED(mbufPtr);
29+ return ACL_ERROR_RT_FEATURE_NOT_SUPPORT;
30+}
31+ 
32+VISIBILITY_DEFAULT
33+rtError_t rtMbufAlloc(rtMbufPtr_t* memBuf, uint64_t size)
34+{
35+ UNUSED(memBuf);
36+ UNUSED(size);
37+ return ACL_ERROR_RT_FEATURE_NOT_SUPPORT;
38+}
39+ 
40+VISIBILITY_DEFAULT
41+rtError_t rtMbufAllocEx(rtMbufPtr_t* memBuf, uint64_t size, uint64_t flag, int32_t grpId)
42+{
43+ UNUSED(memBuf);
44+ UNUSED(size);
45+ UNUSED(flag);
46+ UNUSED(grpId);
47+ return ACL_ERROR_RT_FEATURE_NOT_SUPPORT;
48+}
49+ 
50+VISIBILITY_DEFAULT
51+rtError_t rtMbufUnBuild(const rtMbufPtr_t mbufPtr, void** buff, uint64_t* size)
52+{
53+ UNUSED(mbufPtr);
54+ UNUSED(buff);
55+ UNUSED(size);
56+ return ACL_ERROR_RT_FEATURE_NOT_SUPPORT;
57+}
58+ 
59+VISIBILITY_DEFAULT
60+rtError_t rtBuffGet(const rtMbufPtr_t mbufPtr, void* buff, const uint64_t size)
61+{
62+ UNUSED(mbufPtr);
63+ UNUSED(buff);
64+ UNUSED(size);
65+ return ACL_ERROR_RT_FEATURE_NOT_SUPPORT;
66+}
67+ 
68+VISIBILITY_DEFAULT
69+rtError_t rtBuffPut(const rtMbufPtr_t mbufPtr, void* buff)
70+{
71+ UNUSED(mbufPtr);
72+ UNUSED(buff);
73+ return ACL_ERROR_RT_FEATURE_NOT_SUPPORT;
74+}
75+ 
76+VISIBILITY_DEFAULT
77+rtError_t rtMbufFree(rtMbufPtr_t memBuf)
78+{
79+ UNUSED(memBuf);
80+ return ACL_ERROR_RT_FEATURE_NOT_SUPPORT;
81+}
82+ 
83+VISIBILITY_DEFAULT
84+rtError_t rtMbufSetDataLen(rtMbufPtr_t memBuf, uint64_t len)
85+{
86+ UNUSED(memBuf);
87+ UNUSED(len);
88+ return ACL_ERROR_RT_FEATURE_NOT_SUPPORT;
89+}
90+ 
91+VISIBILITY_DEFAULT
92+rtError_t rtMbufGetDataLen(rtMbufPtr_t memBuf, uint64_t* len)
93+{
94+ UNUSED(memBuf);
95+ UNUSED(len);
96+ return ACL_ERROR_RT_FEATURE_NOT_SUPPORT;
97+}
98+ 
99+VISIBILITY_DEFAULT
100+rtError_t rtMbufGetBuffAddr(rtMbufPtr_t memBuf, void** buf)
101+{
102+ UNUSED(memBuf);
103+ UNUSED(buf);
104+ return ACL_ERROR_RT_FEATURE_NOT_SUPPORT;
105+}
106+ 
107+VISIBILITY_DEFAULT
108+rtError_t rtMbufGetBuffSize(rtMbufPtr_t memBuf, uint64_t* totalSize)
109+{
110+ UNUSED(memBuf);
111+ UNUSED(totalSize);
112+ return ACL_ERROR_RT_FEATURE_NOT_SUPPORT;
113+}
114+ 
115+VISIBILITY_DEFAULT
116+rtError_t rtMbufGetPrivInfo(rtMbufPtr_t memBuf, void** priv, uint64_t* size)
117+{
118+ UNUSED(memBuf);
119+ UNUSED(priv);
120+ UNUSED(size);
121+ return ACL_ERROR_RT_FEATURE_NOT_SUPPORT;
122+}
123+ 
124+VISIBILITY_DEFAULT
125+rtError_t rtMbufCopyBufRef(rtMbufPtr_t memBuf, rtMbufPtr_t* newMemBuf)
126+{
127+ UNUSED(memBuf);
128+ UNUSED(newMemBuf);
129+ return ACL_ERROR_RT_FEATURE_NOT_SUPPORT;
130+}
131+ 
132+VISIBILITY_DEFAULT
133+rtError_t rtMbufChainAppend(rtMbufPtr_t memBufChainHead, rtMbufPtr_t memBuf)
134+{
135+ UNUSED(memBufChainHead);
136+ UNUSED(memBuf);
137+ return ACL_ERROR_RT_FEATURE_NOT_SUPPORT;
138+}
139+ 
140+VISIBILITY_DEFAULT
141+rtError_t rtMbufChainGetMbufNum(rtMbufPtr_t memBufChainHead, uint32_t* num)
142+{
143+ UNUSED(memBufChainHead);
144+ UNUSED(num);
145+ return ACL_ERROR_RT_FEATURE_NOT_SUPPORT;
146+}
147+ 
148+VISIBILITY_DEFAULT
149+rtError_t rtMbufChainGetMbuf(rtMbufPtr_t memBufChainHead, uint32_t index, rtMbufPtr_t* memBuf)
150+{
151+ UNUSED(memBufChainHead);
152+ UNUSED(index);
153+ UNUSED(memBuf);
154+ return ACL_ERROR_RT_FEATURE_NOT_SUPPORT;
155+}
156+ 
157+#ifdef __cplusplus
158+}
159+#endif // __cplusplus
@@ -0,0 +1,22 @@
1+/**
2+ * Copyright (c) 2026 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+#include "api_impl_creator.hpp"
11+ 
12+namespace cce {
13+namespace runtime {
14+ 
15+bool IsImplMbufSupported() { return false; }
Y
Yyanhaiyan28 天前

建议使用弱符号的方式隔离,不需要新增该文件。

likedislike
zhangpengpeng8
28 天前 评论:
16+ 
17+ApiMbuf* CreateImplMbufAndGet() { return nullptr; }
18+ 
19+void DestroyImplMbuf(ApiMbuf*& apiImplMbuf) { apiImplMbuf = nullptr; }
20+ 
21+} // namespace runtime
22+} // namespace cce
@@ -58,8 +58,8 @@ set(libruntime_api_src_files
58 ${RUNTIME_DIR}/src/runtime/api/api_c_context.cc58 ${RUNTIME_DIR}/src/runtime/api/api_c_context.cc
59 ${RUNTIME_DIR}/src/runtime/api/api_c_device.cc59 ${RUNTIME_DIR}/src/runtime/api/api_c_device.cc
60 ${RUNTIME_DIR}/src/runtime/api/api_c_event.cc60 ${RUNTIME_DIR}/src/runtime/api/api_c_event.cc
61+ ${RUNTIME_DIR}/src/runtime/api/api_c_mbuf_stub.cc
61 ${RUNTIME_DIR}/src/runtime/api/api_c_kernel.cc62 ${RUNTIME_DIR}/src/runtime/api/api_c_kernel.cc
62- ${RUNTIME_DIR}/src/runtime/api/api_c_mbuf.cc
63 ${RUNTIME_DIR}/src/runtime/api/api_c_memory.cc63 ${RUNTIME_DIR}/src/runtime/api/api_c_memory.cc
64 ${RUNTIME_DIR}/src/runtime/api/api_c_model.cc64 ${RUNTIME_DIR}/src/runtime/api/api_c_model.cc
65 ${RUNTIME_DIR}/src/runtime/api/api_c_soc.cc65 ${RUNTIME_DIR}/src/runtime/api/api_c_soc.cc
@@ -77,7 +77,7 @@ set(libruntime_api_impl_src_files
77 ${RUNTIME_API_DIR}/impl/api_error.cc77 ${RUNTIME_API_DIR}/impl/api_error.cc
78 ${RUNTIME_API_DIR}/impl/api_impl.cc78 ${RUNTIME_API_DIR}/impl/api_impl.cc
79 ${RUNTIME_API_DIR}/impl/api_impl_creator.cc79 ${RUNTIME_API_DIR}/impl/api_impl_creator.cc
80- ${RUNTIME_API_DIR}/impl/api_impl_mbuf.cc80+ ${RUNTIME_API_DIR}/impl/api_impl_mbuf_stub.cc
81 ${RUNTIME_API_DIR}/impl/api_impl_event_common.cc81 ${RUNTIME_API_DIR}/impl/api_impl_event_common.cc
82 ${RUNTIME_API_DIR}/impl/api_impl_stub.cc82 ${RUNTIME_API_DIR}/impl/api_impl_stub.cc
83 ${RUNTIME_API_DIR}/impl/api_impl_arch5162.cc83 ${RUNTIME_API_DIR}/impl/api_impl_arch5162.cc
@@ -426,7 +426,6 @@ macro(add_runtime_library target_name)
426 ${RUNTIME_DIR}/src/runtime/driver/npu_driver.cc426 ${RUNTIME_DIR}/src/runtime/driver/npu_driver.cc
427 ${RUNTIME_DIR}/src/runtime/driver/npu_driver_mem.cc427 ${RUNTIME_DIR}/src/runtime/driver/npu_driver_mem.cc
428 ${RUNTIME_DIR}/src/runtime/driver/npu_driver_queue.cc428 ${RUNTIME_DIR}/src/runtime/driver/npu_driver_queue.cc
429- ${RUNTIME_DIR}/src/runtime/driver/npu_driver_mbuf.cc
430 ${RUNTIME_DIR}/src/runtime/driver/npu_driver_res.cc429 ${RUNTIME_DIR}/src/runtime/driver/npu_driver_res.cc
431 ${RUNTIME_DIR}/src/runtime/driver/npu_driver_tiny.cpp430 ${RUNTIME_DIR}/src/runtime/driver/npu_driver_tiny.cpp
432 ${RUNTIME_DIR}/src/runtime/driver/npu_driver_dcache_lock_common.cpp431 ${RUNTIME_DIR}/src/runtime/driver/npu_driver_dcache_lock_common.cpp
@@ -79,8 +79,8 @@ set(runtimeut_src_api_list
79 ${TOP_DIR}/src/runtime/api/api_c_context.cc79 ${TOP_DIR}/src/runtime/api/api_c_context.cc
80 ${TOP_DIR}/src/runtime/api/api_c_device.cc80 ${TOP_DIR}/src/runtime/api/api_c_device.cc
81 ${TOP_DIR}/src/runtime/api/api_c_event.cc81 ${TOP_DIR}/src/runtime/api/api_c_event.cc
82+ ${TOP_DIR}/src/runtime/api/api_c_mbuf_stub.cc
82 ${TOP_DIR}/src/runtime/api/api_c_kernel.cc83 ${TOP_DIR}/src/runtime/api/api_c_kernel.cc
83- ${TOP_DIR}/src/runtime/api/api_c_mbuf.cc
84 ${TOP_DIR}/src/runtime/api/api_c_memory.cc84 ${TOP_DIR}/src/runtime/api/api_c_memory.cc
85 ${TOP_DIR}/src/runtime/api/api_c_model.cc85 ${TOP_DIR}/src/runtime/api/api_c_model.cc
86 ${TOP_DIR}/src/runtime/api/api_c_soc.cc86 ${TOP_DIR}/src/runtime/api/api_c_soc.cc
@@ -99,7 +99,7 @@ set(runtimeut_src_api_impl_list
99 ${TOP_DIR}/src/runtime/api/impl/api_impl.cc99 ${TOP_DIR}/src/runtime/api/impl/api_impl.cc
100 ${TOP_DIR}/src/runtime/api/impl/api_impl_creator.cc100 ${TOP_DIR}/src/runtime/api/impl/api_impl_creator.cc
101 ${TOP_DIR}/src/runtime/api/impl/api_impl_event_common.cc101 ${TOP_DIR}/src/runtime/api/impl/api_impl_event_common.cc
102- ${TOP_DIR}/src/runtime/api/impl/api_impl_mbuf.cc102+ ${TOP_DIR}/src/runtime/api/impl/api_impl_mbuf_stub.cc
103 ${TOP_DIR}/src/runtime/api/impl/api_impl_stub.cc103 ${TOP_DIR}/src/runtime/api/impl/api_impl_stub.cc
104 ${TOP_DIR}/src/runtime/api/impl/api_impl_arch5162.cc104 ${TOP_DIR}/src/runtime/api/impl/api_impl_arch5162.cc
105 ${TOP_DIR}/src/runtime/api/impl/v100/api_impl_creator_c.cc105 ${TOP_DIR}/src/runtime/api/impl/v100/api_impl_creator_c.cc
@@ -336,7 +336,6 @@ add_executable(runtime_utest_arch5162
336 ${TOP_DIR}/src/runtime/driver/npu_driver.cc336 ${TOP_DIR}/src/runtime/driver/npu_driver.cc
337 ${TOP_DIR}/src/runtime/driver/npu_driver_mem.cc337 ${TOP_DIR}/src/runtime/driver/npu_driver_mem.cc
338 ${TOP_DIR}/src/runtime/driver/npu_driver_queue.cc338 ${TOP_DIR}/src/runtime/driver/npu_driver_queue.cc
339- ${TOP_DIR}/src/runtime/driver/npu_driver_mbuf.cc
340 ${TOP_DIR}/src/runtime/driver/npu_driver_res.cc339 ${TOP_DIR}/src/runtime/driver/npu_driver_res.cc
341 ${TOP_DIR}/src/runtime/driver/npu_driver_dcache_lock_opb.cpp340 ${TOP_DIR}/src/runtime/driver/npu_driver_dcache_lock_opb.cpp
342 ${TOP_DIR}/src/runtime/driver/v100/npu_driver.cc341 ${TOP_DIR}/src/runtime/driver/v100/npu_driver.cc
@@ -345,6 +344,7 @@ add_executable(runtime_utest_arch5162
345 rt_utest_task_arch5162.cc344 rt_utest_task_arch5162.cc
346 rt_utest_task_execute_time_arch5162.cc345 rt_utest_task_execute_time_arch5162.cc
347 rt_utest_mem_arch5162.cc346 rt_utest_mem_arch5162.cc
347+ ${TOP_DIR}/tests/ut/runtime/runtime/test/rt_utest_mbuf_stub.cc
Y
Yyanhaiyan28 天前

这个路径是不是不对?直接用文件名称就可以了?

likedislike
zhangpengpeng8
28 天前 评论:
348 rt_utest_device_arch5162.cc348 rt_utest_device_arch5162.cc
349)349)
350 350 
@@ -0,0 +1,47 @@
1+/**
2+ * Copyright (c) 2026 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+#include "gtest/gtest.h"
11+#include "api_impl_creator.hpp"
12+#include "rt_error_codes.h"
13+#include "runtime/rt.h"
14+ 
15+using namespace cce::runtime;
16+ 
17+TEST(ApiMbufStubTest, MbufImplLifecycleNotSupport)
18+{
19+ EXPECT_FALSE(IsImplMbufSupported());
20+ ApiMbuf* apiImplMbuf = CreateImplMbufAndGet();
21+ EXPECT_EQ(apiImplMbuf, nullptr);
22+ 
23+ DestroyImplMbuf(apiImplMbuf);
24+ 
25+ EXPECT_EQ(apiImplMbuf, nullptr);
26+}
27+ 
28+TEST(ApiMbufStubTest, MbufApisNotSupport)
29+{
30+ EXPECT_EQ(rtMbufInit(nullptr), ACL_ERROR_RT_FEATURE_NOT_SUPPORT);
31+ EXPECT_EQ(rtMbufBuild(nullptr, 0U, nullptr), ACL_ERROR_RT_FEATURE_NOT_SUPPORT);
32+ EXPECT_EQ(rtMbufAlloc(nullptr, 0U), ACL_ERROR_RT_FEATURE_NOT_SUPPORT);
33+ EXPECT_EQ(rtMbufAllocEx(nullptr, 0U, 0U, 0), ACL_ERROR_RT_FEATURE_NOT_SUPPORT);
34+ EXPECT_EQ(rtMbufUnBuild(nullptr, nullptr, nullptr), ACL_ERROR_RT_FEATURE_NOT_SUPPORT);
35+ EXPECT_EQ(rtBuffGet(nullptr, nullptr, 0U), ACL_ERROR_RT_FEATURE_NOT_SUPPORT);
36+ EXPECT_EQ(rtBuffPut(nullptr, nullptr), ACL_ERROR_RT_FEATURE_NOT_SUPPORT);
37+ EXPECT_EQ(rtMbufFree(nullptr), ACL_ERROR_RT_FEATURE_NOT_SUPPORT);
38+ EXPECT_EQ(rtMbufSetDataLen(nullptr, 0U), ACL_ERROR_RT_FEATURE_NOT_SUPPORT);
39+ EXPECT_EQ(rtMbufGetDataLen(nullptr, nullptr), ACL_ERROR_RT_FEATURE_NOT_SUPPORT);
40+ EXPECT_EQ(rtMbufGetBuffAddr(nullptr, nullptr), ACL_ERROR_RT_FEATURE_NOT_SUPPORT);
41+ EXPECT_EQ(rtMbufGetBuffSize(nullptr, nullptr), ACL_ERROR_RT_FEATURE_NOT_SUPPORT);
42+ EXPECT_EQ(rtMbufGetPrivInfo(nullptr, nullptr, nullptr), ACL_ERROR_RT_FEATURE_NOT_SUPPORT);
43+ EXPECT_EQ(rtMbufCopyBufRef(nullptr, nullptr), ACL_ERROR_RT_FEATURE_NOT_SUPPORT);
44+ EXPECT_EQ(rtMbufChainAppend(nullptr, nullptr), ACL_ERROR_RT_FEATURE_NOT_SUPPORT);
45+ EXPECT_EQ(rtMbufChainGetMbufNum(nullptr, nullptr), ACL_ERROR_RT_FEATURE_NOT_SUPPORT);
46+ EXPECT_EQ(rtMbufChainGetMbuf(nullptr, 0U, nullptr), ACL_ERROR_RT_FEATURE_NOT_SUPPORT);
47+}