已合并
rename asc_get_buf to asc_lock #1387
rename asc_get_buf to asc_lock #1387
已合并
lihong130创建于 4月1日
8 个文件变更+108-66
@@ -63,7 +63,7 @@ asc-devkit:
63 - impl/adv_api/detail/hccl/impl/hccl_impl.h63 - impl/adv_api/detail/hccl/impl/hccl_impl.h
64 - impl/c_api/instr_impl/npu_arch_2201/sync_impl/asc_sync_data_barrier_impl.h64 - impl/c_api/instr_impl/npu_arch_2201/sync_impl/asc_sync_data_barrier_impl.h
65 - impl/c_api/instr_impl/npu_arch_3510/sync_impl/asc_sync_data_barrier_impl.h65 - impl/c_api/instr_impl/npu_arch_3510/sync_impl/asc_sync_data_barrier_impl.h
66- - impl/c_api/instr_impl/npu_arch_3510/sync_impl/asc_get_buf_impl.h66+ - impl/c_api/instr_impl/npu_arch_3510/sync_impl/asc_lock_impl.h
67 - impl/c_api/instr_impl/npu_arch_2201/sync_impl.h67 - impl/c_api/instr_impl/npu_arch_2201/sync_impl.h
68 - impl/c_api/instr_impl/npu_arch_3510/sync_impl.h68 - impl/c_api/instr_impl/npu_arch_3510/sync_impl.h
69 - impl/c_api/instr_impl/npu_arch_2201/vector_compute_impl/asc_transto5hd_impl.h69 - impl/c_api/instr_impl/npu_arch_2201/vector_compute_impl/asc_transto5hd_impl.h
@@ -208,7 +208,7 @@ C API文档目录,整体使用时可以引入asc_simd.h,C API列表如下:
208| API名称 | 说明 |208| API名称 | 说明 |
209|----------|-----------|209|----------|-----------|
210| <cann-filter npu_type = "950"> [asc_release_buf](sync/asc_release_buf.md)| 释放缓存。</cann-filter> |210| <cann-filter npu_type = "950"> [asc_release_buf](sync/asc_release_buf.md)| 释放缓存。</cann-filter> |
211-| <cann-filter npu_type = "950"> [asc_get_buf](sync/asc_get_buf.md)| AI Core内部异步流水线同步的指令。</cann-filter> |211+| <cann-filter npu_type = "950"> [asc_lock](sync/asc_lock.md)| 用于AI Core内部异步流水线同步的接口。</cann-filter> |
212| [asc_sync_notify](sync/asc_sync_notify.md)| 设置同步标志。 |212| [asc_sync_notify](sync/asc_sync_notify.md)| 设置同步标志。 |
213| [asc_sync_wait](sync/asc_sync_wait.md)| 等待同步标志。 |213| [asc_sync_wait](sync/asc_sync_wait.md)| 等待同步标志。 |
214| [asc_sync_pipe](sync/asc_sync_pipe.md)| 等待指定流水线操作完成。 |214| [asc_sync_pipe](sync/asc_sync_pipe.md)| 等待指定流水线操作完成。 |
@@ -1,51 +0,0 @@
1-# asc_get_buf
2- 
3-## 产品支持情况
4- 
5-| 产品 | 是否支持 |
6-| :-----------| :------: |
7-| Ascend 950PR/Ascend 950DT | √ |
8- 
9-## 功能说明
10- 
11-用于AI Core内部异步流水线同步的指令,用于阻塞指定流水线的执行。
12- 
13-## 函数原型
14- 
15-```cpp
16-__aicore__ inline void asc_get_buf(pipe_t pipe, uint8_t buf_id, bool mode)
17-```
18- 
19-## 参数说明
20- 
21-| 参数名 | 输入/输出 | 描述 |
22-| :--- | :--- | :--- |
23-| pipe | 输入 | 设置这条指令所在的流水类型。|
24-| buf_id | 输入 | buffer标号。取值范围[0, 31]。|
25-| mode | 输入 | 执行模式。<br>&bull; false:该指令阻塞pipe所对应的流水线的执行,直到程序顺序中,相同buf_id的所有前序asc_release_buf指令执行完成。<br>&bull; true:该指令不阻塞pipe流水线的执行。|
26- 
27-## 返回值说明
28- 
29-
30- 
31-## 流水类型
32- 
33-PIPE_S
34- 
35-## 约束说明
36- 
37-- asc_get_buf与asc_release_buf必须按严格的顺序成对使用,且需要使用相同的buf_id与mode。此外,asc_release_buf必须始终插在对应的asc_get_buf指令之后,否则硬件行为无定义。
38-- 具有相同buf_id的asc_get_buf与asc_release_buf组合,无论pipe与mode是否相同,均不得在编程顺序中嵌套,否则硬件行为将不可预测。
39-- 成对的asc_get_buf和asc_release_buf必须使用相同的mode,否则硬件行为将不可预测。
40-- 对于程序顺序中连续出现的,具有相同pipe与buf_id的指令对,后一个asc_get_buf将不再阻塞流水线运行,若需实现同一流水线的依赖关系,则必须使用指令asc_sync_pipe。
41- 
42-## 调用示例
43- 
44-```cpp
45-//buffer标号为1
46-uint8_t buf_id = 1;
47-//等待PIPE_S中所有前置指令完成后释放标号为1的缓存
48-bool mode = false;
49-asc_get_buf(PIPE_S, buf_id, mode);
50-asc_release_buf(PIPE_S, buf_id, mode);
51-```
@@ -0,0 +1,54 @@
1+# asc_lock
2+ 
3+## 产品支持情况
4+ 
5+| 产品 | 是否支持 |
6+| :-----------| :------: |
7+| Ascend 950PR/Ascend 950DT | √ |
8+ 
9+## 功能说明
10+ 
11+该接口用于AI Core内部异步流水线之间的同步,可按需阻塞指定流水线的执行。
12+ 
13+## 函数原型
14+ 
15+```cpp
16+enum ascMutexExecuteMode {
17+ ASC_LOCK_BLOCK = 0,
18+ ASC_LOCK_NON_BLOCK = 1
19+};
20+ 
21+__aicore__ inline void asc_lock(pipe_t pipe, uint8_t mutex_id)
22+__aicore__ inline void asc_lock(pipe_t pipe, uint8_t mutex_id, const ascMutexExecuteMode mode)
23+```
24+ 
25+## 参数说明
26+ 
27+| 参数名 | 输入/输出 | 描述 |
28+| :--- | :--- | :--- |
29+| pipe | 输入 | 指定当前接口所属的流水类型。|
30+| mutex_id | 输入 | mutex标号,取值范围为[0, 31]。|
31+| mode | 输入 | 可选参数,用于指定是否阻塞流水线,默认值为ASC_LOCK_BLOCK。<br>&bull; ASC_LOCK_BLOCK:阻塞pipe对应流水线的执行,直到代码中位于当前asc_lock之前且mutex_id相同的所有asc_unlock调用均已执行完成。<br>&bull; ASC_LOCK_NON_BLOCK:不阻塞pipe对应流水线的执行。|
32+ 
33+## 返回值说明
34+ 
35+
36+ 
37+## 流水类型
38+ 
39+PIPE_S
40+ 
41+## 约束说明
42+ 
43+- asc_lock与asc_unlock必须严格成对使用,并使用相同的mutex_id与mode。此外,对应的asc_unlock必须始终写在asc_lock之后,否则硬件行为无定义。
44+- 对于mutex_id相同的asc_lock与asc_unlock组合,无论pipe和mode是否相同,都不得在代码中嵌套使用,否则硬件行为将不可预测。
45+- 成对使用的asc_lock和asc_unlock必须配置相同的mode,否则硬件行为将不可预测。
46+- 如果代码中连续出现多个pipe和mutex_id均相同的调用,则后一个asc_lock不会再阻塞流水线运行。若需要表达同一流水线内的依赖关系,必须使用接口asc_sync_pipe。
47+ 
48+## 调用示例
49+ 
50+```cpp
51+uint8_t mutex_id = 1;
52+asc_lock(PIPE_S, mutex_id);
53+asc_unlock(PIPE_S, mutex_id);
54+```
@@ -16,6 +16,6 @@
16#include "instr_impl/npu_arch_3510/sync_impl/asc_sync_pipe_impl.h"16#include "instr_impl/npu_arch_3510/sync_impl/asc_sync_pipe_impl.h"
17#include "instr_impl/npu_arch_3510/sync_impl/asc_sync_block_arrive_impl.h"17#include "instr_impl/npu_arch_3510/sync_impl/asc_sync_block_arrive_impl.h"
18#include "instr_impl/npu_arch_3510/sync_impl/asc_sync_data_barrier_impl.h"18#include "instr_impl/npu_arch_3510/sync_impl/asc_sync_data_barrier_impl.h"
19-#include "instr_impl/npu_arch_3510/sync_impl/asc_get_buf_impl.h"19+#include "instr_impl/npu_arch_3510/sync_impl/asc_lock_impl.h"
20 20 
21#endif21#endif
Rimpl/c_api/instr_impl/npu_arch_3510/sync_impl/asc_get_buf_impl.himpl/c_api/instr_impl/npu_arch_3510/sync_impl/asc_lock_impl.h+12-5
@@ -9,23 +9,30 @@
9 */9 */
10 10 
11/* !11/* !
12- * \file asc_get_buf_impl.h12+ * \file asc_lock_impl.h
13 * \brief13 * \brief
14 */14 */
15 15 
16#if !defined(ASCENDC_C_API_INCLUDE_COMPILER_INTERNAL_HEADERS)16#if !defined(ASCENDC_C_API_INCLUDE_COMPILER_INTERNAL_HEADERS)
17#warning \17#warning \
18- "impl/c_api/instr_impl/npu_arch_3510/sync_impl/asc_get_buf_impl.h is an internal header file and must not be used directly. Functions or variables defined in this file maybe removed in the future. Please use "#include "c_api/asc_simd.h"" and use public functions or variables defined in interface headers files."18+ "impl/c_api/instr_impl/npu_arch_3510/sync_impl/asc_lock_impl.h is an internal header file and must not be used directly. Functions or variables defined in this file maybe removed in the future. Please use "#include "c_api/asc_simd.h"" and use public functions or variables defined in interface headers files."
19#define ASCENDC_C_API_INCLUDE_COMPILER_INTERNAL_HEADERS19#define ASCENDC_C_API_INCLUDE_COMPILER_INTERNAL_HEADERS
20#define UNDEF_ASCENDC_C_API_INCLUDE_COMPILER_INTERNAL_HEADERS_ASCENDC20#define UNDEF_ASCENDC_C_API_INCLUDE_COMPILER_INTERNAL_HEADERS_ASCENDC
21#endif21#endif
22 22 
23-#ifndef IMPL_C_API_INSTR_IMPL_NPU_ARCH_3510_SYNC_IMPL_ASC_GET_BUF_IMPL_H23+#ifndef IMPL_C_API_INSTR_IMPL_NPU_ARCH_3510_SYNC_IMPL_ASC_LOCK_IMPL_H
24-#define IMPL_C_API_INSTR_IMPL_NPU_ARCH_3510_SYNC_IMPL_ASC_GET_BUF_IMPL_H24+#define IMPL_C_API_INSTR_IMPL_NPU_ARCH_3510_SYNC_IMPL_ASC_LOCK_IMPL_H
25 25 
26#include "instr_impl/npu_arch_3510/utils_impl/utils_impl.h"26#include "instr_impl/npu_arch_3510/utils_impl/utils_impl.h"
27 27 
28-#define asc_get_buf_impl(pipe, buf_id, mode) get_buf((pipe), (buf_id), (mode))28+#define asc_lock_impl(pipe, mutex_id, mode) \
29+ do { \
30+ if constexpr ((mode) == ASC_LOCK_BLOCK) { \
31+ get_buf((pipe), (mutex_id), false); \
32+ } else { \
33+ get_buf((pipe), (mutex_id), true); \
34+ } \
35+ } while (0)
29 36 
30#endif37#endif
31 38 
@@ -63,7 +63,12 @@ __aicore__ inline void asc_sync();
63 63 
64#define asc_release_buf(pipe, buf_id, mode) rls_buf((pipe), (buf_id), (mode))64#define asc_release_buf(pipe, buf_id, mode) rls_buf((pipe), (buf_id), (mode))
65 65 
66-#define asc_get_buf(pipe, buf_id, mode) asc_get_buf_impl((pipe), (buf_id), (mode))66+enum ascMutexExecuteMode {
67+ ASC_LOCK_BLOCK = 0, // Block the execution of the pipeline indicated by pipe (Default).
68+ ASC_LOCK_NON_BLOCK = 1 // Won't block execution of the pipeline.
69+};
70+ 
71+#define asc_lock(pipe, mutex_id, ...) asc_lock_impl((pipe), (mutex_id), (ASC_LOCK_BLOCK, ##__VA_ARGS__))
67 72 
68#endif73#endif
69 74 
Rtests/api/c_api/npu_arch_3510/sync/test_get_buf.cpptests/api/c_api/npu_arch_3510/sync/test_asc_lock.cpp+33-6
@@ -13,27 +13,54 @@
13#include "c_api/stub/cce_stub.h"13#include "c_api/stub/cce_stub.h"
14#include "include/c_api/asc_simd.h"14#include "include/c_api/asc_simd.h"
15 15 
16-class TestSysVarGetBufCAPI : public testing::Test {16+class TestAscLockCAPI : public testing::Test {
17protected:17protected:
18 void SetUp() {}18 void SetUp() {}
19 void TearDown() {}19 void TearDown() {}
20};20};
21 21 
22namespace {22namespace {
23-void get_buf_stub(pipe_t pipe, uint8_t buf_id, bool mode)23+void get_buf_block_stub(pipe_t pipe, uint8_t mutex_id, bool mode)
24{24{
25 EXPECT_EQ(pipe, pipe_t::PIPE_MTE3);25 EXPECT_EQ(pipe, pipe_t::PIPE_MTE3);
26- EXPECT_EQ(buf_id, static_cast<uint8_t>(10));26+ EXPECT_EQ(mutex_id, static_cast<uint8_t>(10));
27 EXPECT_EQ(mode, false);27 EXPECT_EQ(mode, false);
28}28}
29+ 
30+void get_buf_non_block_stub(pipe_t pipe, uint8_t mutex_id, bool mode)
31+{
32+ EXPECT_EQ(pipe, pipe_t::PIPE_MTE3);
33+ EXPECT_EQ(mutex_id, static_cast<uint8_t>(10));
34+ EXPECT_EQ(mode, true);
35+}
29}36}
30 37 
31-TEST_F(TestSysVarGetBufCAPI, c_api_get_buf_Succ)38+TEST_F(TestAscLockCAPI, asc_lock_DefaultBlockSucc)
32{39{
33 MOCKER_CPP(get_buf, void(pipe_t, uint8_t, bool))40 MOCKER_CPP(get_buf, void(pipe_t, uint8_t, bool))
34 .times(1)41 .times(1)
35- .will(invoke(get_buf_stub));42+ .will(invoke(get_buf_block_stub));
36 43 
37- asc_get_buf(pipe_t::PIPE_MTE3, static_cast<uint8_t>(10), false);44+ asc_lock(pipe_t::PIPE_MTE3, static_cast<uint8_t>(10));
45+ GlobalMockObject::verify();
46+}
47+ 
48+TEST_F(TestAscLockCAPI, asc_lock_BlockSucc)
49+{
50+ MOCKER_CPP(get_buf, void(pipe_t, uint8_t, bool))
51+ .times(1)
52+ .will(invoke(get_buf_block_stub));
53+ 
54+ asc_lock(pipe_t::PIPE_MTE3, static_cast<uint8_t>(10), ASC_LOCK_BLOCK);
55+ GlobalMockObject::verify();
56+}
57+ 
58+TEST_F(TestAscLockCAPI, asc_lock_NonBlockSucc)
59+{
60+ MOCKER_CPP(get_buf, void(pipe_t, uint8_t, bool))
61+ .times(1)
62+ .will(invoke(get_buf_non_block_stub));
63+ 
64+ asc_lock(pipe_t::PIPE_MTE3, static_cast<uint8_t>(10), ASC_LOCK_NON_BLOCK);
38 GlobalMockObject::verify();65 GlobalMockObject::verify();
39}66}