Merged
【doc】capi示例代码优化 #3896
ChenCangtaoAdd on Jul 2
【doc】capi示例代码优化 #3896
Merged
Merged fromChenCangtao/asc-devkitcapi_bugfix_0701intocann/asc-devkitmaster
Total: 14 files changed+39-30
| @@ -84,8 +84,7 @@ PIPE_MTE1 | |||
| 84 | ```cpp | 84 | ```cpp |
| 85 | // total_length指参与搬运的数据总长度 | 85 | // total_length指参与搬运的数据总长度 |
| 86 | constexpr uint64_t total_length = 128; | 86 | constexpr 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 | // 其余入参均已默认数值传入 |
| 91 | uint16_t n_size = 16; | 90 | uint16_t n_size = 16; |
| @@ -93,7 +92,7 @@ uint16_t m_size = 16; | |||
| 93 | uint32_t dst_stride_dst_d = 0; | 92 | uint32_t dst_stride_dst_d = 0; |
| 94 | uint16_t src_stride = 8; | 93 | uint16_t src_stride = 8; |
| 95 | uint8_t unit_flag_mode = 0; | 94 | uint8_t unit_flag_mode = 0; |
| 96 | -uint64_t quant_pre = NoQuant; | 95 | +uint64_t quant_pre = QuantMode_t::NoConv; |
| 97 | uint8_t relu_pre = 0; | 96 | uint8_t relu_pre = 0; |
| 98 | bool channel_split = false; | 97 | bool channel_split = false; |
| 99 | bool nz2nd_en = false; | 98 | bool nz2nd_en = false; |
| @@ -248,8 +248,8 @@ PIPE_FIX | |||
| 248 | ## 调用示例 | 248 | ## 调用示例 |
| 249 | 249 | ||
| 250 | ```cpp | 250 | ```cpp |
| 251 | -__gm__ bfloat16_t dst[256]; | 251 | +// dst是外部输入的float类型的GM地址。 |
| 252 | -__cc__ bfloat16_t src[256]; | 252 | +__cc__ float src[256]; |
| 253 | uint16_t n_size = 1; | 253 | uint16_t n_size = 1; |
| 254 | uint16_t m_size = 1; | 254 | uint16_t m_size = 1; |
| 255 | uint32_t loop_dst_stride = 0; | 255 | uint32_t loop_dst_stride = 0; |
| @@ -257,13 +257,13 @@ uint16_t loop_src_stride = 0; | |||
| 257 | uint8_t l2_cache_ctl = 0; | 257 | uint8_t l2_cache_ctl = 0; |
| 258 | uint8_t clip_relu_pre = 0; | 258 | uint8_t clip_relu_pre = 0; |
| 259 | uint8_t unit_flag_ctl = 0; | 259 | uint8_t unit_flag_ctl = 0; |
| 260 | -uint64_t quant_pre = DEQF16; | 260 | +uint64_t quant_pre = QuantMode_t::QF322F32_PRE; |
| 261 | uint8_t relu_pre = 0; | 261 | uint8_t relu_pre = 0; |
| 262 | bool split_en = true; | 262 | bool 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; |
| 265 | uint8_t relu_post = 0; | 265 | uint8_t relu_post = 0; |
| 266 | -bool clip_relu_post = true; | 266 | +bool clip_relu_post = false; |
| 267 | uint8_t eltwise_op = 0; | 267 | uint8_t eltwise_op = 0; |
| 268 | bool eltwise_antq_en = true; | 268 | bool eltwise_antq_en = true; |
| 269 | bool C0_pad_en = true; | 269 | bool C0_pad_en = true; |
| @@ -94,7 +94,7 @@ uint16_t m_size = 16; | |||
| 94 | uint16_t dst_stride = 8; | 94 | uint16_t dst_stride = 8; |
| 95 | uint16_t src_stride = 8; | 95 | uint16_t src_stride = 8; |
| 96 | uint8_t unit_flag_mode = 0; | 96 | uint8_t unit_flag_mode = 0; |
| 97 | -uint64_t quant_pre = DEQF16; | 97 | +uint64_t quant_pre = QuantMode_t::NoConv; |
| 98 | uint8_t relu_pre = 0; | 98 | uint8_t relu_pre = 0; |
| 99 | bool channel_split = false; | 99 | bool channel_split = false; |
| 100 | bool enable_nz2nd_en = false; | 100 | bool enable_nz2nd_en = false; |
| @@ -119,11 +119,11 @@ uint16_t dst_stride = 8; | |||
| 119 | uint16_t src_stride = 8; | 119 | uint16_t src_stride = 8; |
| 120 | uint8_t clip_relu_pre = 0; | 120 | uint8_t clip_relu_pre = 0; |
| 121 | uint8_t unit_flag_mode = 0; | 121 | uint8_t unit_flag_mode = 0; |
| 122 | -uint64_t quant_pre = DEQF16; | 122 | +uint64_t quant_pre = QuantMode_t::NoConv; |
| 123 | uint8_t relu_pre = 0; | 123 | uint8_t relu_pre = 0; |
| 124 | bool channel_split = false; | 124 | bool channel_split = false; |
| 125 | bool nz2nd_en = false; | 125 | bool nz2nd_en = false; |
| 126 | -uint64_t quant_post = VQS162B8_POST; | 126 | +uint64_t quant_post = QuantMode_t::NoConv; |
| 127 | uint8_t relu_post = 0; | 127 | uint8_t relu_post = 0; |
| 128 | bool clip_relu_post = false; | 128 | bool clip_relu_post = false; |
| 129 | uint8_t eltwise_op = 0; | 129 | uint8_t eltwise_op = 0; |
| @@ -296,13 +296,13 @@ uint8_t dual_dst_ctl = 5; | |||
| 296 | bool sub_blockid = true; | 296 | bool sub_blockid = true; |
| 297 | uint8_t clip_relu_pre = 0; | 297 | uint8_t clip_relu_pre = 0; |
| 298 | uint8_t unit_flag_ctl = 0; | 298 | uint8_t unit_flag_ctl = 0; |
| 299 | -uint64_t quant_pre = DEQF16; | 299 | +uint64_t quant_pre = QuantMode_t::F322BF16; |
| 300 | uint8_t relu_pre = 0; | 300 | uint8_t relu_pre = 0; |
| 301 | -bool split_en = true; | 301 | +bool split_en = false; |
| 302 | bool NZ2ND_en = true; | 302 | bool NZ2ND_en = true; |
| 303 | -uint64_t quant_post = VQS162B8_POST; | 303 | +uint64_t quant_post = QuantMode_t::NoConv; |
| 304 | uint8_t relu_post = 0; | 304 | uint8_t relu_post = 0; |
| 305 | -bool clip_relu_post = true; | 305 | +bool clip_relu_post = false; |
| 306 | uint8_t eltwise_op = 0; | 306 | uint8_t eltwise_op = 0; |
| 307 | bool eltwise_antq_en = true; | 307 | bool eltwise_antq_en = true; |
| 308 | bool C0_pad_en = true; | 308 | bool C0_pad_en = true; |
| @@ -125,7 +125,7 @@ uint16_t index_id = 0; | |||
| 125 | uint16_t src_stride = 1; | 125 | uint16_t src_stride = 1; |
| 126 | uint16_t dst_gap = 1; | 126 | uint16_t dst_gap = 1; |
| 127 | bool enable_addr_decrement = false; | 127 | bool enable_addr_decrement = false; |
| 128 | -uint64_t dst_frac_gap = 0; | 128 | +uint16_t dst_frac_gap = 0; |
| 129 | 129 | ||
| 130 | // 搬运过程 | 130 | // 搬运过程 |
| 131 | asc_copy_l12l0a_trans(dst, src, index_id, repeat, src_stride, dst_gap, enable_addr_decrement, dst_frac_gap); | 131 | asc_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为0 | 158 | + // 循环结束后调用一次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 | ```cpp | 54 | ```cpp |
| 55 | +constexpr uint32_t total_length = 128; | ||
| 56 | +__ubuf__ half src0_addr[total_length]; | ||
| 57 | +__ubuf__ half src1_addr[total_length]; | ||
| 58 | + | ||
| 55 | vector_half src0; | 59 | vector_half src0; |
| 56 | vector_half src1; | 60 | vector_half src1; |
| 57 | vector_half dst; | 61 | vector_half dst; |
| 58 | vector_bool mask = asc_create_mask_b16(PAT_ALL); | 62 | vector_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); |
| 61 | asc_mul(dst, src0, src1, mask); | 65 | asc_mul(dst, src0, src1, mask); |
| 62 | -``` | 66 | +``` |
| @@ -48,10 +48,11 @@ PIPE_S | |||
| 48 | ## 调用示例 | 48 | ## 调用示例 |
| 49 | 49 | ||
| 50 | ```cpp | 50 | ```cpp |
| 51 | -// total_length指参与计算的数据长度,dst是外部输入的float类型的GM内存。 | 51 | +// total_length指参与计算的数据长度,dst是外部输入的int8_t类型的GM内存地址。 |
| 52 | constexpr uint32_t total_length = 256; | 52 | constexpr 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 | + | ||
| 55 | asc_copy_ub2gm(dst, src0, total_length * sizeof(int8_t)); | 56 | asc_copy_ub2gm(dst, src0, total_length * sizeof(int8_t)); |
| 56 | asc_sync_pipe(PIPE_MTE3); | 57 | asc_sync_pipe(PIPE_MTE3); |
| 57 | asc_set_atomic_max_int8(); | 58 | asc_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 | ```cpp | 50 | ```cpp |
| 51 | -// total_length指参与计算的数据长度,dst是外部输入的float类型的GM内存。 | 51 | +// total_length指参与计算的数据长度,dst是外部传入的int8_t类型的GM内存地址。 |
| 52 | constexpr uint32_t total_length = 256; | 52 | constexpr 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 | + | ||
| 55 | asc_copy_ub2gm(dst, src0, total_length * sizeof(int8_t)); | 56 | asc_copy_ub2gm(dst, src0, total_length * sizeof(int8_t)); |
| 56 | asc_sync_pipe(PIPE_MTE3); | 57 | asc_sync_pipe(PIPE_MTE3); |
| 57 | asc_set_atomic_min_int8(); | 58 | asc_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内存。 |
| 46 | offset += 64 * sizeof(half); // 通过offset将src1的起始地址设置在src0之后。 | 46 | offset += 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 | ||