Merged
【doc】capi示例代码优化 #3896
【doc】capi示例代码优化 #3896
Merged
ChenCangtaoAdd on Jul 2
Total: 14 files changed+39-30
@@ -84,8 +84,7 @@ PIPE_MTE1
84```cpp84```cpp
85// total_length指参与搬运的数据总长度85// total_length指参与搬运的数据总长度
86constexpr uint64_t total_length = 128;86constexpr uint64_t total_length = 128;
87-// dst src分别对应目的操作数的输出地址和源操作数的输入地址87+// dst src分别对应目的操作数的输出地址和源操作数的输入地址,dst是外部输入的int32_t类型的GM地址。
88-__gm__ int32_t dst[total_length];
89__cc__ int32_t src[total_length];88__cc__ int32_t src[total_length];
90// 其余入参均已默认数值传入89// 其余入参均已默认数值传入
91uint16_t n_size = 16;90uint16_t n_size = 16;
@@ -93,7 +92,7 @@ uint16_t m_size = 16;
93uint32_t dst_stride_dst_d = 0;92uint32_t dst_stride_dst_d = 0;
94uint16_t src_stride = 8;93uint16_t src_stride = 8;
95uint8_t unit_flag_mode = 0;94uint8_t unit_flag_mode = 0;
96-uint64_t quant_pre = NoQuant;95+uint64_t quant_pre = QuantMode_t::NoConv;
97uint8_t relu_pre = 0;96uint8_t relu_pre = 0;
98bool channel_split = false;97bool channel_split = false;
99bool nz2nd_en = false;98bool nz2nd_en = false;
@@ -248,8 +248,8 @@ PIPE_FIX
248## 调用示例248## 调用示例
249 249 
250```cpp250```cpp
251-__gm__ bfloat16_t dst[256];251+// dst是外部输入的float类型的GM地址。
252-__cc__ bfloat16_t src[256];252+__cc__ float src[256];
253uint16_t n_size = 1;253uint16_t n_size = 1;
254uint16_t m_size = 1;254uint16_t m_size = 1;
255uint32_t loop_dst_stride = 0;255uint32_t loop_dst_stride = 0;
@@ -257,13 +257,13 @@ uint16_t loop_src_stride = 0;
257uint8_t l2_cache_ctl = 0;257uint8_t l2_cache_ctl = 0;
258uint8_t clip_relu_pre = 0;258uint8_t clip_relu_pre = 0;
259uint8_t unit_flag_ctl = 0;259uint8_t unit_flag_ctl = 0;
260-uint64_t quant_pre = DEQF16;260+uint64_t quant_pre = QuantMode_t::QF322F32_PRE;
261uint8_t relu_pre = 0;261uint8_t relu_pre = 0;
262bool split_en = true;262bool split_en = true;
263-bool NZ2ND_en = true;263+bool NZ2ND_en = false;
264-uint64_t quant_post = VQS162B8_POST;264+uint64_t quant_post = QuantMode_t::NoConv;
265uint8_t relu_post = 0;265uint8_t relu_post = 0;
266-bool clip_relu_post = true;266+bool clip_relu_post = false;
267uint8_t eltwise_op = 0;267uint8_t eltwise_op = 0;
268bool eltwise_antq_en = true;268bool eltwise_antq_en = true;
269bool C0_pad_en = true;269bool C0_pad_en = true;
@@ -94,7 +94,7 @@ uint16_t m_size = 16;
94uint16_t dst_stride = 8;94uint16_t dst_stride = 8;
95uint16_t src_stride = 8;95uint16_t src_stride = 8;
96uint8_t unit_flag_mode = 0;96uint8_t unit_flag_mode = 0;
97-uint64_t quant_pre = DEQF16;97+uint64_t quant_pre = QuantMode_t::NoConv;
98uint8_t relu_pre = 0;98uint8_t relu_pre = 0;
99bool channel_split = false;99bool channel_split = false;
100bool enable_nz2nd_en = false;100bool enable_nz2nd_en = false;
@@ -119,11 +119,11 @@ uint16_t dst_stride = 8;
119uint16_t src_stride = 8;119uint16_t src_stride = 8;
120uint8_t clip_relu_pre = 0;120uint8_t clip_relu_pre = 0;
121uint8_t unit_flag_mode = 0;121uint8_t unit_flag_mode = 0;
122-uint64_t quant_pre = DEQF16;122+uint64_t quant_pre = QuantMode_t::NoConv;
123uint8_t relu_pre = 0;123uint8_t relu_pre = 0;
124bool channel_split = false;124bool channel_split = false;
125bool nz2nd_en = false;125bool nz2nd_en = false;
126-uint64_t quant_post = VQS162B8_POST;126+uint64_t quant_post = QuantMode_t::NoConv;
127uint8_t relu_post = 0;127uint8_t relu_post = 0;
128bool clip_relu_post = false;128bool clip_relu_post = false;
129uint8_t eltwise_op = 0;129uint8_t eltwise_op = 0;
@@ -296,13 +296,13 @@ uint8_t dual_dst_ctl = 5;
296bool sub_blockid = true;296bool sub_blockid = true;
297uint8_t clip_relu_pre = 0;297uint8_t clip_relu_pre = 0;
298uint8_t unit_flag_ctl = 0;298uint8_t unit_flag_ctl = 0;
299-uint64_t quant_pre = DEQF16;299+uint64_t quant_pre = QuantMode_t::F322BF16;
300uint8_t relu_pre = 0;300uint8_t relu_pre = 0;
301-bool split_en = true;301+bool split_en = false;
302bool NZ2ND_en = true;302bool NZ2ND_en = true;
303-uint64_t quant_post = VQS162B8_POST;303+uint64_t quant_post = QuantMode_t::NoConv;
304uint8_t relu_post = 0;304uint8_t relu_post = 0;
305-bool clip_relu_post = true;305+bool clip_relu_post = false;
306uint8_t eltwise_op = 0;306uint8_t eltwise_op = 0;
307bool eltwise_antq_en = true;307bool eltwise_antq_en = true;
308bool C0_pad_en = true;308bool C0_pad_en = true;
@@ -125,7 +125,7 @@ uint16_t index_id = 0;
125uint16_t src_stride = 1;125uint16_t src_stride = 1;
126uint16_t dst_gap = 1;126uint16_t dst_gap = 1;
127bool enable_addr_decrement = false;127bool enable_addr_decrement = false;
128-uint64_t dst_frac_gap = 0;128+uint16_t dst_frac_gap = 0;
129 129 
130// 搬运过程130// 搬运过程
131asc_copy_l12l0a_trans(dst, src, index_id, repeat, src_stride, dst_gap, enable_addr_decrement, dst_frac_gap);131asc_copy_l12l0a_trans(dst, src, index_id, repeat, src_stride, dst_gap, enable_addr_decrement, dst_frac_gap);
@@ -155,7 +155,7 @@ PIPE_V
155 // 跨32B边界的尾块缓存在ureg中155 // 跨32B边界的尾块缓存在ureg中
156 asc_storeunalign_postupdate(dst, ureg, src);156 asc_storeunalign_postupdate(dst, ureg, src);
157 }157 }
158- // 循环结束后调用一次post,将ureg中剩余数据刷至UB;src1_dst已自增至结束位置,offset为0158+ // 循环结束后调用一次post,将ureg中剩余数据刷至UB;dst已自增至结束位置,offset为0
159 asc_storeunalign_post(dst, ureg, 0);159 asc_storeunalign_post(dst, ureg, 0);
160 ```160 ```
161 161 
@@ -52,11 +52,15 @@ PIPE_V
52## 调用示例52## 调用示例
53 53 
54```cpp54```cpp
55+constexpr uint32_t total_length = 128;
56+__ubuf__ half src0_addr[total_length];
57+__ubuf__ half src1_addr[total_length];
58+ 
55vector_half src0;59vector_half src0;
56vector_half src1;60vector_half src1;
57vector_half dst;61vector_half dst;
58vector_bool mask = asc_create_mask_b16(PAT_ALL);62vector_bool mask = asc_create_mask_b16(PAT_ALL);
59-asc_loadalign(src0, src0_addr); // src0_addr是外部输入的UB内存空间地址63+asc_loadalign(src0, src0_addr);
60-asc_loadalign(src1, src1_addr); // src0_addr是外部输入的UB内存空间地址64+asc_loadalign(src1, src1_addr);
61asc_mul(dst, src0, src1, mask);65asc_mul(dst, src0, src1, mask);
62-```66+```
@@ -48,10 +48,11 @@ PIPE_S
48## 调用示例48## 调用示例
49 49 
50```cpp50```cpp
51-// total_length指参与计算的数据长度,dst是外部输入的float类型的GM内存。51+// total_length指参与计算的数据长度,dst是外部输入的int8_t类型的GM内存地址。
52constexpr uint32_t total_length = 256;52constexpr uint32_t total_length = 256;
53__ubuf__ int8_t src0[total_length];53__ubuf__ int8_t src0[total_length];
54__ubuf__ int8_t src1[total_length];54__ubuf__ int8_t src1[total_length];
55+ 
55asc_copy_ub2gm(dst, src0, total_length * sizeof(int8_t));56asc_copy_ub2gm(dst, src0, total_length * sizeof(int8_t));
56asc_sync_pipe(PIPE_MTE3);57asc_sync_pipe(PIPE_MTE3);
57asc_set_atomic_max_int8();58asc_set_atomic_max_int8();
@@ -65,4 +66,4 @@ asc_set_atomic_none();
65输入数据src0:[1, 1, 1, ..., 1] // int8_t类型66输入数据src0:[1, 1, 1, ..., 1] // int8_t类型
66输入数据src1:[2, 2, 2, ..., 2] // int8_t类型67输入数据src1:[2, 2, 2, ..., 2] // int8_t类型
67输出数据dst:[2, 2, 2, ..., 2] // int8_t类型68输出数据dst:[2, 2, 2, ..., 2] // int8_t类型
68-```69+```
@@ -48,10 +48,11 @@ PIPE_S
48## 调用示例48## 调用示例
49 49 
50```cpp50```cpp
51-// total_length指参与计算的数据长度,dst是外部输入的float类型的GM内存。51+// total_length指参与计算的数据长度,dst是外部传入的int8_t类型的GM内存地址。
52constexpr uint32_t total_length = 256;52constexpr uint32_t total_length = 256;
53__ubuf__ int8_t src0[total_length];53__ubuf__ int8_t src0[total_length];
54__ubuf__ int8_t src1[total_length];54__ubuf__ int8_t src1[total_length];
55+ 
55asc_copy_ub2gm(dst, src0, total_length * sizeof(int8_t));56asc_copy_ub2gm(dst, src0, total_length * sizeof(int8_t));
56asc_sync_pipe(PIPE_MTE3);57asc_sync_pipe(PIPE_MTE3);
57asc_set_atomic_min_int8();58asc_set_atomic_min_int8();
@@ -65,4 +66,4 @@ asc_set_atomic_none();
65输入数据src0:[1, 1, 1, ..., 1] // int8_t类型66输入数据src0:[1, 1, 1, ..., 1] // int8_t类型
66输入数据src1:[2, 2, 2, ..., 2] // int8_t类型67输入数据src1:[2, 2, 2, ..., 2] // int8_t类型
67输出数据dst:[1, 1, 1, ..., 1] // int8_t类型68输出数据dst:[1, 1, 1, ..., 1] // int8_t类型
68-```69+```
@@ -19,6 +19,10 @@ union asc_l13d_fmatrix_config {
19};19};
20```20```
21 21 
22+## 约束说明
23+ 
24+`asc_l13d_fmatrix_config`类型的联合体变量被定义后必须对`l1_height`和`l1_width`进行赋值以符合实际场景及取值范围要求。
25+ 
22## 字段详解26## 字段详解
23 27 
24|字段名|字段含义|28|字段名|字段含义|
@@ -45,7 +45,7 @@ uint64_t offset = 0; // 首先为src0申请内
45__ubuf__ half* src0 = (__ubuf__ half*)asc_get_phy_buf_addr(offset); // 获取src0的地址,通过__ubuf__关键字指定该地址指向UB内存。45__ubuf__ half* src0 = (__ubuf__ half*)asc_get_phy_buf_addr(offset); // 获取src0的地址,通过__ubuf__关键字指定该地址指向UB内存。
46offset += 64 * sizeof(half); // 通过offset将src1的起始地址设置在src0之后。46offset += 64 * sizeof(half); // 通过offset将src1的起始地址设置在src0之后。
47__ubuf__ half* src1 = (__ubuf__ half*)asc_get_phy_buf_addr(offset); // 获取src1的地址,通过__ubuf__关键字指定该地址指向UB内存。47__ubuf__ half* src1 = (__ubuf__ half*)asc_get_phy_buf_addr(offset); // 获取src1的地址,通过__ubuf__关键字指定该地址指向UB内存。
48-offset += 64 * sizeof(half); // 通过offset将src1的起始地址设置在src0之后。48+offset += 64 * sizeof(half); // 通过offset将dst的起始地址设置在src1之后。
49__ubuf__ half* dst = (__ubuf__ half*)asc_get_phy_buf_addr(offset); // 获取dst的地址,通过__ubuf__关键字指定该地址指向UB内存。49__ubuf__ half* dst = (__ubuf__ half*)asc_get_phy_buf_addr(offset); // 获取dst的地址,通过__ubuf__关键字指定该地址指向UB内存。
50...... // 使用src0、src1、dst中的数据进行后续计算或数据搬运操作。50...... // 使用src0、src1、dst中的数据进行后续计算或数据搬运操作。
51-```51+```
@@ -26,7 +26,7 @@ __aicore__ inline int64_t asc_get_sub_block_num()
26 26 
27不同Kernel类型下,在AIC和AIV上调用该接口的返回值如下:27不同Kernel类型下,在AIC和AIV上调用该接口的返回值如下:
28 28 
29-|Kernel类型|KERNEL_TYPE_AIV_ONLY|KERNEL_TYPE_AIC_ONLY|KERNEL_TYPE_MIX__AIC_1_2|KERNEL_TYPE_MIX_AIC_1_1|KERNEL_TYPE_MIX_AIC_1_0|KERNEL_TYPE_MIX_AIV_1_0|29+|Kernel类型|KERNEL_TYPE_AIV_ONLY|KERNEL_TYPE_AIC_ONLY|KERNEL_TYPE_MIX_AIC_1_2|KERNEL_TYPE_MIX_AIC_1_1|KERNEL_TYPE_MIX_AIC_1_0|KERNEL_TYPE_MIX_AIV_1_0|
30| :------ | :------------------ | :----------------- | :-------------------- | :--------------------- | :-------------------- | :-------------------- |30| :------ | :------------------ | :----------------- | :-------------------- | :--------------------- | :-------------------- | :-------------------- |
31|AIV |1 |- |2 |1 |- |1 |31|AIV |1 |- |2 |1 |- |1 |
32|AIC |- |1 |1 |1 |1 |- |32|AIC |- |1 |1 |1 |1 |- |
@@ -41,4 +41,4 @@ PIPE_S
41 41 
42## 调用示例42## 调用示例
43 43 
44-无44+无
@@ -14,7 +14,7 @@
14| bit范围 | 含义 | 14| bit范围 | 含义 |
15| :-----------|:------------------------------------------------------------------------------------------------------------------------------------------------------:|15| :-----------|:------------------------------------------------------------------------------------------------------------------------------------------------------:|
16| 31:0 | 存储进行padding时的值。<br>数据位宽为32时,直接使用31:0位;<br> 数据位宽为16时,使用15:0位,31:16位被忽略; <br> 数据位宽为8时,15:8位应与7:0位相同,31:16位被忽略;数据位宽为4时,15:12,11:8,7:4和3:0位应该相同,31:16位被忽略。 |16| 31:0 | 存储进行padding时的值。<br>数据位宽为32时,直接使用31:0位;<br> 数据位宽为16时,使用15:0位,31:16位被忽略; <br> 数据位宽为8时,15:8位应与7:0位相同,31:16位被忽略;数据位宽为4时,15:12,11:8,7:4和3:0位应该相同,31:16位被忽略。 |
17-| 33:32 | 表示所使用的padding模式,当前支持三种模式。<br>2'b00:固定padding;<br>2'b01:按通道padding;<br>2'b010/2'b11:当前保留。 |17+| 33:32 | 表示所使用的padding模式,当前支持三种模式。<br>2'b00:固定padding;<br>2'b01:按通道padding;<br>2'b10/2'b11:当前保留。 |
18 18 
19## 函数原型19## 函数原型
20 20