Merged
feat(docs): Modify the product name #6558
lyz0328Add on Sep 21
feat(docs): Modify the product name #6558
Merged
lyz0328Add on Sep 21
Total: 525 files changed+3674-3674
@@ -18,9 +18,9 @@
18 18 
19为保持文档体系产品型号表述统一,请使用以下标准命名规范:19为保持文档体系产品型号表述统一,请使用以下标准命名规范:
20 20 
21-- Ascend 950PR/Ascend 950DT21+- Ascend 950PR&950DT系列产品
22-- Atlas A3 训练系列产品/Atlas A3 推理系列产品22+- Atlas A3系列产品
23-- Atlas A2 训练系列产品/Atlas A2 推理系列产品23+- Atlas A2系列产品
24 24 
25### 产品差异说明规范25### 产品差异说明规范
26 26 
@@ -18,9 +18,9 @@ All domain-specific terms must strictly follow the standard expressions in the [
18 18 
19To maintain consistent product model expressions in the documentation system, use the following standard naming conventions:19To maintain consistent product model expressions in the documentation system, use the following standard naming conventions:
20 20 
21-- Ascend 950PR/Ascend 950DT21+- Ascend 950PR&950DT series products
22-- Atlas A3 training series products, Atlas A3 inference series products22+- Atlas A3 series products
23-- Atlas A2 training series products, Atlas A2 inference series products23+- Atlas A2 series products
24 24 
25### Product Difference Description Specification25### Product Difference Description Specification
26 26 
@@ -3,13 +3,13 @@
3## 产品支持情况3## 产品支持情况
4 4 
5<!-- npu="950" id1 -->5<!-- npu="950" id1 -->
6-- Ascend 950PR/Ascend 950DT:支持6+- Ascend 950PR&950DT系列产品:支持
7<!-- end id1 -->7<!-- end id1 -->
8<!-- npu="A3" id2 -->8<!-- npu="A3" id2 -->
9-- Atlas A3 训练系列产品/Atlas A3 推理系列产品:不支持9+- Atlas A3系列产品:不支持
10<!-- end id2 -->10<!-- end id2 -->
11<!-- npu="910b" id3 -->11<!-- npu="910b" id3 -->
12-- Atlas A2 训练系列产品/Atlas A2 推理系列产品:不支持12+- Atlas A2系列产品:不支持
13<!-- end id3 -->13<!-- end id3 -->
14 14 
15## 功能说明15## 功能说明
@@ -3,13 +3,13 @@
3## 产品支持情况3## 产品支持情况
4 4 
5<!-- npu="950" id1 -->5<!-- npu="950" id1 -->
6-- Ascend 950PR/Ascend 950DT:支持6+- Ascend 950PR&950DT系列产品:支持
7<!-- end id1 -->7<!-- end id1 -->
8<!-- npu="A3" id2 -->8<!-- npu="A3" id2 -->
9-- Atlas A3 训练系列产品/Atlas A3 推理系列产品:不支持9+- Atlas A3系列产品:不支持
10<!-- end id2 -->10<!-- end id2 -->
11<!-- npu="910b" id3 -->11<!-- npu="910b" id3 -->
12-- Atlas A2 训练系列产品/Atlas A2 推理系列产品:不支持12+- Atlas A2系列产品:不支持
13<!-- end id3 -->13<!-- end id3 -->
14 14 
15## 功能说明15## 功能说明
@@ -3,13 +3,13 @@
3## 产品支持情况3## 产品支持情况
4 4 
5<!-- npu="950" id1 -->5<!-- npu="950" id1 -->
6-- Ascend 950PR/Ascend 950DT:支持6+- Ascend 950PR&950DT系列产品:支持
7<!-- end id1 -->7<!-- end id1 -->
8<!-- npu="A3" id2 -->8<!-- npu="A3" id2 -->
9-- Atlas A3 训练系列产品/Atlas A3 推理系列产品:不支持9+- Atlas A3系列产品:不支持
10<!-- end id2 -->10<!-- end id2 -->
11<!-- npu="910b" id3 -->11<!-- npu="910b" id3 -->
12-- Atlas A2 训练系列产品/Atlas A2 推理系列产品:不支持12+- Atlas A2系列产品:不支持
13<!-- end id3 -->13<!-- end id3 -->
14 14 
15## 功能说明15## 功能说明
@@ -3,13 +3,13 @@
3## 产品支持情况3## 产品支持情况
4 4 
5<!-- npu="950" id1 -->5<!-- npu="950" id1 -->
6-- Ascend 950PR/Ascend 950DT:支持6+- Ascend 950PR&950DT系列产品:支持
7<!-- end id1 -->7<!-- end id1 -->
8<!-- npu="A3" id2 -->8<!-- npu="A3" id2 -->
9-- Atlas A3 训练系列产品/Atlas A3 推理系列产品:不支持9+- Atlas A3系列产品:不支持
10<!-- end id2 -->10<!-- end id2 -->
11<!-- npu="910b" id3 -->11<!-- npu="910b" id3 -->
12-- Atlas A2 训练系列产品/Atlas A2 推理系列产品:不支持12+- Atlas A2系列产品:不支持
13<!-- end id3 -->13<!-- end id3 -->
14 14 
15## 功能说明15## 功能说明
@@ -3,13 +3,13 @@
3## 产品支持情况3## 产品支持情况
4 4 
5<!-- npu="950" id1 -->5<!-- npu="950" id1 -->
6-- Ascend 950PR/Ascend 950DT:支持6+- Ascend 950PR&950DT系列产品:支持
7<!-- end id1 -->7<!-- end id1 -->
8<!-- npu="A3" id2 -->8<!-- npu="A3" id2 -->
9-- Atlas A3 训练系列产品/Atlas A3 推理系列产品:不支持9+- Atlas A3系列产品:不支持
10<!-- end id2 -->10<!-- end id2 -->
11<!-- npu="910b" id3 -->11<!-- npu="910b" id3 -->
12-- Atlas A2 训练系列产品/Atlas A2 推理系列产品:不支持12+- Atlas A2系列产品:不支持
13<!-- end id3 -->13<!-- end id3 -->
14 14 
15## 功能说明15## 功能说明
@@ -3,13 +3,13 @@
3## 产品支持情况3## 产品支持情况
4 4 
5<!-- npu="950" id1 -->5<!-- npu="950" id1 -->
6-- Ascend 950PR/Ascend 950DT:支持6+- Ascend 950PR&950DT系列产品:支持
7<!-- end id1 -->7<!-- end id1 -->
8<!-- npu="A3" id2 -->8<!-- npu="A3" id2 -->
9-- Atlas A3 训练系列产品/Atlas A3 推理系列产品:不支持9+- Atlas A3系列产品:不支持
10<!-- end id2 -->10<!-- end id2 -->
11<!-- npu="910b" id3 -->11<!-- npu="910b" id3 -->
12-- Atlas A2 训练系列产品/Atlas A2 推理系列产品:不支持12+- Atlas A2系列产品:不支持
13<!-- end id3 -->13<!-- end id3 -->
14 14 
15## 功能说明15## 功能说明
@@ -78,9 +78,9 @@ public:
78 78 
79## 约束说明79## 约束说明
80 80 
81-- 裸整数常量(如42)使用DT_INT64。只有数值超过DT_INT64的上限时,才使用DT_UINT64。裸浮点常量(如3.14)使用DT_FP32。81+- 裸整数常量(如42)使用DT_INT64。只有数值超过DT_INT64的上限时,才使用DT_UINT64。裸浮点常量(如3.14)使用DT_FP32。
82 82 
83-- MXFP8的数据元素使用DT_FP8E4M3FN或DT_FP8E5M2,MXFP4的数据元素使用DT_FP4E2M1或DT_FP4E1M2;两者均使用DT_FP8E8M0保存分组缩放因子。详见[matmul_mx](../cube_computation/matmul_mx.md)和[matmul_mx_acc](../cube_computation/matmul_mx_acc.md)。83+- MXFP8的数据元素使用DT_FP8E4M3FN或DT_FP8E5M2,MXFP4的数据元素使用DT_FP4E2M1或DT_FP4E1M2;两者均使用DT_FP8E8M0保存分组缩放因子。详见[matmul_mx](../cube_computation/matmul_mx.md)和[matmul_mx_acc](../cube_computation/matmul_mx_acc.md)。
84 84 
85## 常用接口85## 常用接口
86 86 
@@ -3,13 +3,13 @@
3## 产品支持情况3## 产品支持情况
4 4 
5<!-- npu="950" id1 -->5<!-- npu="950" id1 -->
6-- Ascend 950PR/Ascend 950DT:支持6+- Ascend 950PR&950DT系列产品:支持
7<!-- end id1 -->7<!-- end id1 -->
8<!-- npu="A3" id2 -->8<!-- npu="A3" id2 -->
9-- Atlas A3 训练系列产品/Atlas A3 推理系列产品:不支持9+- Atlas A3系列产品:不支持
10<!-- end id2 -->10<!-- end id2 -->
11<!-- npu="910b" id3 -->11<!-- npu="910b" id3 -->
12-- Atlas A2 训练系列产品/Atlas A2 推理系列产品:不支持12+- Atlas A2系列产品:不支持
13<!-- end id3 -->13<!-- end id3 -->
14 14 
15## 功能说明15## 功能说明
@@ -3,13 +3,13 @@
3## 产品支持情况3## 产品支持情况
4 4 
5<!-- npu="950" id1 -->5<!-- npu="950" id1 -->
6-- Ascend 950PR/Ascend 950DT:支持6+- Ascend 950PR&950DT系列产品:支持
7<!-- end id1 -->7<!-- end id1 -->
8<!-- npu="A3" id2 -->8<!-- npu="A3" id2 -->
9-- Atlas A3 训练系列产品/Atlas A3 推理系列产品:不支持9+- Atlas A3系列产品:不支持
10<!-- end id2 -->10<!-- end id2 -->
11<!-- npu="910b" id3 -->11<!-- npu="910b" id3 -->
12-- Atlas A2 训练系列产品/Atlas A2 推理系列产品:不支持12+- Atlas A2系列产品:不支持
13<!-- end id3 -->13<!-- end id3 -->
14 14 
15## 功能说明15## 功能说明
@@ -3,13 +3,13 @@
3## 产品支持情况3## 产品支持情况
4 4 
5<!-- npu="950" id1 -->5<!-- npu="950" id1 -->
6-- Ascend 950PR/Ascend 950DT:支持6+- Ascend 950PR&950DT系列产品:支持
7<!-- end id1 -->7<!-- end id1 -->
8<!-- npu="A3" id2 -->8<!-- npu="A3" id2 -->
9-- Atlas A3 训练系列产品/Atlas A3 推理系列产品:不支持9+- Atlas A3系列产品:不支持
10<!-- end id2 -->10<!-- end id2 -->
11<!-- npu="910b" id3 -->11<!-- npu="910b" id3 -->
12-- Atlas A2 训练系列产品/Atlas A2 推理系列产品:不支持12+- Atlas A2系列产品:不支持
13<!-- end id3 -->13<!-- end id3 -->
14 14 
15## 功能说明15## 功能说明
@@ -3,13 +3,13 @@
3## 产品支持情况3## 产品支持情况
4 4 
5<!-- npu="950" id1 -->5<!-- npu="950" id1 -->
6-- Ascend 950PR/Ascend 950DT:支持6+- Ascend 950PR&950DT系列产品:支持
7<!-- end id1 -->7<!-- end id1 -->
8<!-- npu="A3" id2 -->8<!-- npu="A3" id2 -->
9-- Atlas A3 训练系列产品/Atlas A3 推理系列产品:不支持9+- Atlas A3系列产品:不支持
10<!-- end id2 -->10<!-- end id2 -->
11<!-- npu="910b" id3 -->11<!-- npu="910b" id3 -->
12-- Atlas A2 训练系列产品/Atlas A2 推理系列产品:不支持12+- Atlas A2系列产品:不支持
13<!-- end id3 -->13<!-- end id3 -->
14 14 
15## 功能说明15## 功能说明
@@ -1,27 +1,27 @@
1# pypto_pro.language.Ptr1# pypto_pro.language.Ptr
2 2 
3-## 产品支持情况3+## 产品支持情况
4- 4+ 
5-<!-- npu="950" id1 -->5+<!-- npu="950" id1 -->
6-- Ascend 950PR/Ascend 950DT:支持6+- Ascend 950PR&950DT系列产品:支持
7-<!-- end id1 -->7+<!-- end id1 -->
8-<!-- npu="A3" id2 -->8+<!-- npu="A3" id2 -->
9-- Atlas A3 训练系列产品/Atlas A3 推理系列产品:不支持9+- Atlas A3系列产品:不支持
10-<!-- end id2 -->10+<!-- end id2 -->
11-<!-- npu="910b" id3 -->11+<!-- npu="910b" id3 -->
12-- Atlas A2 训练系列产品/Atlas A2 推理系列产品:不支持12+- Atlas A2系列产品:不支持
13-<!-- end id3 -->13+<!-- end id3 -->
14- 14+ 
15## 功能说明15## 功能说明
16 16 
17-指向指定元素类型的GM地址类型标注。17+指向指定元素类型的GM地址类型标注。
18 18 
19-pypto_pro.language.Ptr主要用于:19+pypto_pro.language.Ptr主要用于:
20 20 
21-1. Kernel函数签名中声明GM裸指针参数21+1. Kernel函数签名中声明GM裸指针参数
22-2. 配合[pypto_pro.language.make_ptr](../resource_management/make_ptr.md)创建不同元素类型的指针视图22+2. 配合[pypto_pro.language.make_ptr](../resource_management/make_ptr.md)创建不同元素类型的指针视图
23-3. 配合[pypto_pro.language.addptr](../resource_management/addptr.md)做指针偏移23+3. 配合[pypto_pro.language.addptr](../resource_management/addptr.md)做指针偏移
24-4. 配合[pypto_pro.language.make_tensor](../resource_management/make_tensor.md)从裸指针构造Tensor view24+4. 配合[pypto_pro.language.make_tensor](../resource_management/make_tensor.md)从裸指针构造Tensor view
25 25 
26## 函数原型26## 函数原型
27 27 
@@ -29,23 +29,23 @@ pypto_pro.language.Ptr主要用于:
29pypto_pro.language.Ptr[dtype]29pypto_pro.language.Ptr[dtype]
30```30```
31 31 
32-## 参数说明32+## 参数说明
33 33 
34-| 参数 | 输入/输出 | 说明 |34+| 参数 | 输入/输出 | 说明 |
35-|---|---|---|35+|---|---|---|
36-| dtype | 输入 | 指针指向的元素数据类型,[pypto_pro.language.DataType](DataType.md)枚举值。常用取值:pypto_pro.language.DT_FP16、pypto_pro.language.DT_FP32、pypto_pro.language.DT_INT8。 |36+| dtype | 输入 | 指针指向的元素数据类型,[pypto_pro.language.DataType](DataType.md)枚举值。常用取值:pypto_pro.language.DT_FP16、pypto_pro.language.DT_FP32、pypto_pro.language.DT_INT8。 |
37- 
38-## 约束说明
39- 
40-无。
41- 
42-## 返回值说明
43- 
44-无。
45- 
46-## 调用示例
47 37 
48-本示例在Kernel签名中使用pypto_pro.language.Ptr声明workspace指针,通过pypto_pro.language.addptr将指针偏移64 × 128个FP16元素,再使用pypto_pro.language.make_tensor创建形状为[64, 128]的Tensor视图。示例将输入Tensor中的数据搬入UB,逐元素乘2后写入workspace,再从workspace搬入UB并写入输出Tensor。38+## 约束说明
39+ 
40+无。
41+ 
42+## 返回值说明
43+ 
44+无。
45+ 
46+## 调用示例
47+ 
48+本示例在Kernel签名中使用pypto_pro.language.Ptr声明workspace指针,通过pypto_pro.language.addptr将指针偏移64 × 128个FP16元素,再使用pypto_pro.language.make_tensor创建形状为[64, 128]的Tensor视图。示例将输入Tensor中的数据搬入UB,逐元素乘2后写入workspace,再从workspace搬入UB并写入输出Tensor。
49 49 
50```python50```python
51import pypto_pro.language as pl51import pypto_pro.language as pl
@@ -3,13 +3,13 @@
3## 产品支持情况3## 产品支持情况
4 4 
5<!-- npu="950" id1 -->5<!-- npu="950" id1 -->
6-- Ascend 950PR/Ascend 950DT:支持6+- Ascend 950PR&950DT系列产品:支持
7<!-- end id1 -->7<!-- end id1 -->
8<!-- npu="A3" id2 -->8<!-- npu="A3" id2 -->
9-- Atlas A3 训练系列产品/Atlas A3 推理系列产品:不支持9+- Atlas A3系列产品:不支持
10<!-- end id2 -->10<!-- end id2 -->
11<!-- npu="910b" id3 -->11<!-- npu="910b" id3 -->
12-- Atlas A2 训练系列产品/Atlas A2 推理系列产品:不支持12+- Atlas A2系列产品:不支持
13<!-- end id3 -->13<!-- end id3 -->
14 14 
15## 功能说明15## 功能说明
@@ -3,13 +3,13 @@
3## 产品支持情况3## 产品支持情况
4 4 
5<!-- npu="950" id1 -->5<!-- npu="950" id1 -->
6-- Ascend 950PR/Ascend 950DT:支持6+- Ascend 950PR&950DT系列产品:支持
7<!-- end id1 -->7<!-- end id1 -->
8<!-- npu="A3" id2 -->8<!-- npu="A3" id2 -->
9-- Atlas A3 训练系列产品/Atlas A3 推理系列产品:不支持9+- Atlas A3系列产品:不支持
10<!-- end id2 -->10<!-- end id2 -->
11<!-- npu="910b" id3 -->11<!-- npu="910b" id3 -->
12-- Atlas A2 训练系列产品/Atlas A2 推理系列产品:不支持12+- Atlas A2系列产品:不支持
13<!-- end id3 -->13<!-- end id3 -->
14 14 
15## 功能说明15## 功能说明
@@ -3,13 +3,13 @@
3## 产品支持情况3## 产品支持情况
4 4 
5<!-- npu="950" id1 -->5<!-- npu="950" id1 -->
6-- Ascend 950PR/Ascend 950DT:支持6+- Ascend 950PR&950DT系列产品:支持
7<!-- end id1 -->7<!-- end id1 -->
8<!-- npu="A3" id2 -->8<!-- npu="A3" id2 -->
9-- Atlas A3 训练系列产品/Atlas A3 推理系列产品:不支持9+- Atlas A3系列产品:不支持
10<!-- end id2 -->10<!-- end id2 -->
11<!-- npu="910b" id3 -->11<!-- npu="910b" id3 -->
12-- Atlas A2 训练系列产品/Atlas A2 推理系列产品:不支持12+- Atlas A2系列产品:不支持
13<!-- end id3 -->13<!-- end id3 -->
14 14 
15## 功能说明15## 功能说明
@@ -3,13 +3,13 @@
3## 产品支持情况3## 产品支持情况
4 4 
5<!-- npu="950" id1 -->5<!-- npu="950" id1 -->
6-- Ascend 950PR/Ascend 950DT:支持6+- Ascend 950PR&950DT系列产品:支持
7<!-- end id1 -->7<!-- end id1 -->
8<!-- npu="A3" id2 -->8<!-- npu="A3" id2 -->
9-- Atlas A3 训练系列产品/Atlas A3 推理系列产品:不支持9+- Atlas A3系列产品:不支持
10<!-- end id2 -->10<!-- end id2 -->
11<!-- npu="910b" id3 -->11<!-- npu="910b" id3 -->
12-- Atlas A2 训练系列产品/Atlas A2 推理系列产品:不支持12+- Atlas A2系列产品:不支持
13<!-- end id3 -->13<!-- end id3 -->
14 14 
15## 功能说明15## 功能说明
@@ -3,13 +3,13 @@
3## 产品支持情况3## 产品支持情况
4 4 
5<!-- npu="950" id1 -->5<!-- npu="950" id1 -->
6-- Ascend 950PR/Ascend 950DT:支持6+- Ascend 950PR&950DT系列产品:支持
7<!-- end id1 -->7<!-- end id1 -->
8<!-- npu="A3" id2 -->8<!-- npu="A3" id2 -->
9-- Atlas A3 训练系列产品/Atlas A3 推理系列产品:不支持9+- Atlas A3系列产品:不支持
10<!-- end id2 -->10<!-- end id2 -->
11<!-- npu="910b" id3 -->11<!-- npu="910b" id3 -->
12-- Atlas A2 训练系列产品/Atlas A2 推理系列产品:不支持12+- Atlas A2系列产品:不支持
13<!-- end id3 -->13<!-- end id3 -->
14 14 
15## 功能说明15## 功能说明
@@ -3,13 +3,13 @@
3## 产品支持情况3## 产品支持情况
4 4 
5<!-- npu="950" id1 -->5<!-- npu="950" id1 -->
6-- Ascend 950PR/Ascend 950DT:支持6+- Ascend 950PR&950DT系列产品:支持
7<!-- end id1 -->7<!-- end id1 -->
8<!-- npu="A3" id2 -->8<!-- npu="A3" id2 -->
9-- Atlas A3 训练系列产品/Atlas A3 推理系列产品:不支持9+- Atlas A3系列产品:不支持
10<!-- end id2 -->10<!-- end id2 -->
11<!-- npu="910b" id3 -->11<!-- npu="910b" id3 -->
12-- Atlas A2 训练系列产品/Atlas A2 推理系列产品:不支持12+- Atlas A2系列产品:不支持
13<!-- end id3 -->13<!-- end id3 -->
14 14 
15## 功能说明15## 功能说明
@@ -3,13 +3,13 @@
3## 产品支持情况3## 产品支持情况
4 4 
5<!-- npu="950" id1 -->5<!-- npu="950" id1 -->
6-- Ascend 950PR/Ascend 950DT:支持6+- Ascend 950PR&950DT系列产品:支持
7<!-- end id1 -->7<!-- end id1 -->
8<!-- npu="A3" id2 -->8<!-- npu="A3" id2 -->
9-- Atlas A3 训练系列产品/Atlas A3 推理系列产品:不支持9+- Atlas A3系列产品:不支持
10<!-- end id2 -->10<!-- end id2 -->
11<!-- npu="910b" id3 -->11<!-- npu="910b" id3 -->
12-- Atlas A2 训练系列产品/Atlas A2 推理系列产品:不支持12+- Atlas A2系列产品:不支持
13<!-- end id3 -->13<!-- end id3 -->
14 14 
15## 功能说明15## 功能说明
@@ -1,24 +1,24 @@
1-# pypto_pro.language.TensorLayout1+# pypto_pro.language.TensorLayout
2- 2+ 
3-## 产品支持情况3+## 产品支持情况
4- 4+ 
5-<!-- npu="950" id1 -->5+<!-- npu="950" id1 -->
6-- Ascend 950PR/Ascend 950DT:支持6+- Ascend 950PR&950DT系列产品:支持
7-<!-- end id1 -->7+<!-- end id1 -->
8-<!-- npu="A3" id2 -->8+<!-- npu="A3" id2 -->
9-- Atlas A3 训练系列产品/Atlas A3 推理系列产品:不支持9+- Atlas A3系列产品:不支持
10-<!-- end id2 -->10+<!-- end id2 -->
11-<!-- npu="910b" id3 -->11+<!-- npu="910b" id3 -->
12-- Atlas A2 训练系列产品/Atlas A2 推理系列产品:不支持12+- Atlas A2系列产品:不支持
13-<!-- end id3 -->13+<!-- end id3 -->
14- 14+ 
15-## 功能说明15+## 功能说明
16- 16+ 
17-数据布局枚举,用于描述GM Tensor的存储形式和Tile的数据排列形式。17+数据布局枚举,用于描述GM Tensor的存储形式和Tile的数据排列形式。
18- 18+ 
19-- **GM Tensor**支持ND、NZ,默认ND。19+- **GM Tensor**支持ND、NZ,默认ND。
20-- **Tile**支持ND、DN、NZ、ZN、NN、ZZ,默认值由内存空间决定。20+- **Tile**支持ND、DN、NZ、ZN、NN、ZZ,默认值由内存空间决定。
21- 21+ 
22## 原型定义22## 原型定义
23 23 
24```python24```python
@@ -53,7 +53,7 @@ PYPTO_DECLARE_ENUM(
53- NZ将逻辑[..., M, N]存储为[..., ceil(N/C0), ceil(M/16), 16, C0]。M/N无需分形对齐,但实际存储空间必须按align(M, 16) × align(N, C0)的容量分配并使用上述NZ物理排布;仅分配M × N元素的紧凑buffer不受支持。补齐区不属于逻辑Tensor内容,框架不会为传入的buffer自动扩容或完成packing。DT_FP4E2M1和DT_FP4E1M2的C0为64;DT_INT8、DT_UINT8、DT_FP8E4M3FN、DT_FP8E5M2、DT_FP8E8M0和DT_HF8的C0为32;DT_FP16、DT_BF16、DT_INT16和DT_UINT16的C0为16;DT_FP32、DT_INT32和DT_UINT32的C0为8;DT_INT64和DT_UINT64的C0为4。4位数据类型的M/N同样按逻辑元素计数,不使用packed字节数作为Tensor shape。53- NZ将逻辑[..., M, N]存储为[..., ceil(N/C0), ceil(M/16), 16, C0]。M/N无需分形对齐,但实际存储空间必须按align(M, 16) × align(N, C0)的容量分配并使用上述NZ物理排布;仅分配M × N元素的紧凑buffer不受支持。补齐区不属于逻辑Tensor内容,框架不会为传入的buffer自动扩容或完成packing。DT_FP4E2M1和DT_FP4E1M2的C0为64;DT_INT8、DT_UINT8、DT_FP8E4M3FN、DT_FP8E5M2、DT_FP8E8M0和DT_HF8的C0为32;DT_FP16、DT_BF16、DT_INT16和DT_UINT16的C0为16;DT_FP32、DT_INT32和DT_UINT32的C0为8;DT_INT64和DT_UINT64的C0为4。4位数据类型的M/N同样按逻辑元素计数,不使用packed字节数作为Tensor shape。
54 54 
55- MX矩阵计算使用的E8M0分组缩放因子在GM中仍声明为普通ND Tensor;物理shape和搬运约束见[matmul_mx](../cube_computation/matmul_mx.md)和[load](../memory_data_movement/load.md)。55- MX矩阵计算使用的E8M0分组缩放因子在GM中仍声明为普通ND Tensor;物理shape和搬运约束见[matmul_mx](../cube_computation/matmul_mx.md)和[load](../memory_data_movement/load.md)。
56- 56+ 
57- Tile的布局约束请参见[pypto_pro.language.TileType](TileType.md)。57- Tile的布局约束请参见[pypto_pro.language.TileType](TileType.md)。
58 58 
59## 调用示例59## 调用示例
@@ -1,23 +1,23 @@
1-# pypto_pro.language.TilePad1+# pypto_pro.language.TilePad
2- 2+ 
3## 产品支持情况3## 产品支持情况
4 4 
5<!-- npu="950" id1 -->5<!-- npu="950" id1 -->
6-- Ascend 950PR/Ascend 950DT:支持6+- Ascend 950PR&950DT系列产品:支持
7<!-- end id1 -->7<!-- end id1 -->
8<!-- npu="A3" id2 -->8<!-- npu="A3" id2 -->
9-- Atlas A3 训练系列产品/Atlas A3 推理系列产品:不支持9+- Atlas A3系列产品:不支持
10<!-- end id2 -->10<!-- end id2 -->
11<!-- npu="910b" id3 -->11<!-- npu="910b" id3 -->
12-- Atlas A2 训练系列产品/Atlas A2 推理系列产品:不支持12+- Atlas A2系列产品:不支持
13<!-- end id3 -->13<!-- end id3 -->
14 14 
15-## 功能说明15+## 功能说明
16- 16+ 
17Tile边界不足时的填充方式枚举,用于尾块/非满块场景。17Tile边界不足时的填充方式枚举,用于尾块/非满块场景。
18- 18+ 
19当Tile的有效数据区域小于其shape时(如动态维度的尾块),超出有效区域的部分需要按指定模式填充。19当Tile的有效数据区域小于其shape时(如动态维度的尾块),超出有效区域的部分需要按指定模式填充。
20- 20+ 
21## 原型定义21## 原型定义
22 22 
23```python23```python
@@ -49,10 +49,10 @@ PYPTO_DECLARE_ENUM(
49 49 
50```python50```python
51import pypto_pro.language as pl51import pypto_pro.language as pl
52-# 不填充(默认)52+# 不填充(默认)
53-tt = pl.TileType(shape=[64, 128], dtype=pl.DT_FP16,53+tt = pl.TileType(shape=[64, 128], dtype=pl.DT_FP16,
54- target_memory=pl.MemorySpace.Vec)54+ target_memory=pl.MemorySpace.Vec)
55- 55+ 
56# 补零56# 补零
57tt_pad = pl.TileType(shape=[64, 128], dtype=pl.DT_FP16,57tt_pad = pl.TileType(shape=[64, 128], dtype=pl.DT_FP16,
58 target_memory=pl.MemorySpace.Vec, pad=pl.TilePad.zero)58 target_memory=pl.MemorySpace.Vec, pad=pl.TilePad.zero)
@@ -3,13 +3,13 @@
3## 产品支持情况3## 产品支持情况
4 4 
5<!-- npu="950" id1 -->5<!-- npu="950" id1 -->
6-- Ascend 950PR/Ascend 950DT:支持6+- Ascend 950PR&950DT系列产品:支持
7<!-- end id1 -->7<!-- end id1 -->
8<!-- npu="A3" id2 -->8<!-- npu="A3" id2 -->
9-- Atlas A3 训练系列产品/Atlas A3 推理系列产品:不支持9+- Atlas A3系列产品:不支持
10<!-- end id2 -->10<!-- end id2 -->
11<!-- npu="910b" id3 -->11<!-- npu="910b" id3 -->
12-- Atlas A2 训练系列产品/Atlas A2 推理系列产品:不支持12+- Atlas A2系列产品:不支持
13<!-- end id3 -->13<!-- end id3 -->
14 14 
15## 功能说明15## 功能说明
@@ -1,26 +1,26 @@
1-# pypto_pro.language.system.dcci1+# pypto_pro.language.system.dcci
2- 2+ 
3## 产品支持情况3## 产品支持情况
4 4 
5<!-- npu="950" id1 -->5<!-- npu="950" id1 -->
6-- Ascend 950PR/Ascend 950DT:支持6+- Ascend 950PR&950DT系列产品:支持
7<!-- end id1 -->7<!-- end id1 -->
8<!-- npu="A3" id2 -->8<!-- npu="A3" id2 -->
9-- Atlas A3 训练系列产品/Atlas A3 推理系列产品:不支持9+- Atlas A3系列产品:不支持
10<!-- end id2 -->10<!-- end id2 -->
11<!-- npu="910b" id3 -->11<!-- npu="910b" id3 -->
12-- Atlas A2 训练系列产品/Atlas A2 推理系列产品:不支持12+- Atlas A2系列产品:不支持
13<!-- end id3 -->13<!-- end id3 -->
14 14 
15-## 功能说明15+## 功能说明
16- 16+ 
17对指定地址对应的数据缓存执行清理并失效(Data Cache Clean and Invalidate,DCCI)。典型用途是在跨核或跨流水共享数据时,清除当前执行单元可能持有的旧缓存副本,使后续访问能够观察到已发布的数据。17对指定地址对应的数据缓存执行清理并失效(Data Cache Clean and Invalidate,DCCI)。典型用途是在跨核或跨流水共享数据时,清除当前执行单元可能持有的旧缓存副本,使后续访问能够观察到已发布的数据。
18 18 
19dcci只处理缓存状态,不等价于流水同步、跨核事件或内存屏障。调用者仍须保证生产者写入已经完成,并使用与通信协议匹配的同步接口建立先后关系。19dcci只处理缓存状态,不等价于流水同步、跨核事件或内存屏障。调用者仍须保证生产者写入已经完成,并使用与通信协议匹配的同步接口建立先后关系。
20- 20+ 
21-## 函数原型21+## 函数原型
22- 22+ 
23-```python23+```python
24pypto_pro.language.system.dcci(24pypto_pro.language.system.dcci(
25 target: Union[Tensor, Tile],25 target: Union[Tensor, Tile],
26 offset: Optional[Union[int, Sequence[int], Expr]] = None,26 offset: Optional[Union[int, Sequence[int], Expr]] = None,
@@ -28,13 +28,13 @@ pypto_pro.language.system.dcci(
28 cache_line: CacheLine = pypto_pro.language.CacheLine.ENTIRE_DATA_CACHE,28 cache_line: CacheLine = pypto_pro.language.CacheLine.ENTIRE_DATA_CACHE,
29 dst: DcciDst = pypto_pro.language.DcciDst.AUTO,29 dst: DcciDst = pypto_pro.language.DcciDst.AUTO,
30) -> None30) -> None
31-```31+```
32- 32+ 
33## 参数说明33## 参数说明
34- 34+ 
35-| 参数 | 输入/输出 | 说明 |35+| 参数 | 输入/输出 | 说明 |
36-|---|---|---|36+|---|---|---|
37-| target | 输入 | GM Tensor变量,或已分配在UB中的Tile。 |37+| target | 输入 | GM Tensor变量,或已分配在UB中的Tile。 |
38| offset | 输入 | 可选,元素偏移,单位为target.dtype元素。GM Tensor支持各维偏移列表/元组,也支持整型常量或运行时整型标量表达式表示的线性偏移;列表/元组长度须与Tensor维数一致,框架按Tensor stride换算线性偏移。UB Tile仅支持整型常量或运行时整型标量表达式表示的线性偏移。缺省时为0,即使用目标起始地址;偏移不得使有效地址越出目标已分配范围。 |38| offset | 输入 | 可选,元素偏移,单位为target.dtype元素。GM Tensor支持各维偏移列表/元组,也支持整型常量或运行时整型标量表达式表示的线性偏移;列表/元组长度须与Tensor维数一致,框架按Tensor stride换算线性偏移。UB Tile仅支持整型常量或运行时整型标量表达式表示的线性偏移。缺省时为0,即使用目标起始地址;偏移不得使有效地址越出目标已分配范围。 |
39| cache_line | 输入 | 可选,编译期[pypto_pro.language.CacheLine](../basic_data_structures/CacheLine.md)枚举值,默认pypto_pro.language.CacheLine.ENTIRE_DATA_CACHE。缓存行为64字节;SINGLE_CACHE_LINE的地址无需由用户向下对齐,硬件操作包含该地址的缓存行。若数据跨越多个缓存行,须逐行调用或使用ENTIRE_DATA_CACHE。 |39| cache_line | 输入 | 可选,编译期[pypto_pro.language.CacheLine](../basic_data_structures/CacheLine.md)枚举值,默认pypto_pro.language.CacheLine.ENTIRE_DATA_CACHE。缓存行为64字节;SINGLE_CACHE_LINE的地址无需由用户向下对齐,硬件操作包含该地址的缓存行。若数据跨越多个缓存行,须逐行调用或使用ENTIRE_DATA_CACHE。 |
40| dst | 输入 | 可选,编译期[pypto_pro.language.DcciDst](../basic_data_structures/DcciDst.md)枚举值,默认pypto_pro.language.DcciDst.AUTO。各枚举值的含义和适用目标参见DcciDst。 |40| dst | 输入 | 可选,编译期[pypto_pro.language.DcciDst](../basic_data_structures/DcciDst.md)枚举值,默认pypto_pro.language.DcciDst.AUTO。各枚举值的含义和适用目标参见DcciDst。 |
@@ -46,14 +46,14 @@ pypto_pro.language.system.dcci(
46- ENTIRE_DATA_CACHE作用于整个数据缓存,offset不会缩小其作用范围;该模式开销大于单缓存行操作。46- ENTIRE_DATA_CACHE作用于整个数据缓存,offset不会缩小其作用范围;该模式开销大于单缓存行操作。
47- DCCI不是同步原语。生产者通过MTE3等流水写出数据后,必须先同步到S流水再执行DCCI或发布标志;消费者也必须先完成相应跨核等待,再执行缓存处理和数据读取。具体事件号和同步模式由上层通信协议决定。47- DCCI不是同步原语。生产者通过MTE3等流水写出数据后,必须先同步到S流水再执行DCCI或发布标志;消费者也必须先完成相应跨核等待,再执行缓存处理和数据读取。具体事件号和同步模式由上层通信协议决定。
48- 频繁对整个缓存执行DCCI会造成明显性能损失;已知共享数据范围时应优先按64字节缓存行处理。48- 频繁对整个缓存执行DCCI会造成明显性能损失;已知共享数据范围时应优先按64字节缓存行处理。
49- 49+ 
50## 返回值说明50## 返回值说明
51 51 
52无。52无。
53 53 
54## 调用示例54## 调用示例
55- 55+ 
56-### 单缓存行失效(GM Tensor)56+### 单缓存行失效(GM Tensor)
57 57 
58```python58```python
59import os59import os
@@ -83,12 +83,12 @@ if __name__ == "__main__":
83 assert torch.allclose(out.cpu(), inp.cpu())83 assert torch.allclose(out.cpu(), inp.cpu())
84 print("dcci done")84 print("dcci done")
85```85```
86- 86+ 
87### 全缓存失效87### 全缓存失效
88- 88+ 
89-```python89+```python
90-# 对整个数据缓存执行DCCI,开销大于单缓存行操作,offset不会缩小其作用范围90+# 对整个数据缓存执行DCCI,开销大于单缓存行操作,offset不会缩小其作用范围
91-pl.system.dcci(inp, cache_line=pl.CacheLine.ENTIRE_DATA_CACHE)91+pl.system.dcci(inp, cache_line=pl.CacheLine.ENTIRE_DATA_CACHE)
92```92```
93 93 
94### DCCI搭配同步使用94### DCCI搭配同步使用
@@ -3,13 +3,13 @@
3## 产品支持情况3## 产品支持情况
4 4 
5<!-- npu="950" id1 -->5<!-- npu="950" id1 -->
6-- Ascend 950PR/Ascend 950DT:支持6+- Ascend 950PR&950DT系列产品:支持
7<!-- end id1 -->7<!-- end id1 -->
8<!-- npu="A3" id2 -->8<!-- npu="A3" id2 -->
9-- Atlas A3 训练系列产品/Atlas A3 推理系列产品:不支持9+- Atlas A3系列产品:不支持
10<!-- end id2 -->10<!-- end id2 -->
11<!-- npu="910b" id3 -->11<!-- npu="910b" id3 -->
12-- Atlas A2 训练系列产品/Atlas A2 推理系列产品:不支持12+- Atlas A2系列产品:不支持
13<!-- end id3 -->13<!-- end id3 -->
14 14 
15## 功能说明15## 功能说明
@@ -3,13 +3,13 @@
3## 产品支持情况3## 产品支持情况
4 4 
5<!-- npu="950" id1 -->5<!-- npu="950" id1 -->
6-- Ascend 950PR/Ascend 950DT:支持6+- Ascend 950PR&950DT系列产品:支持
7<!-- end id1 -->7<!-- end id1 -->
8<!-- npu="A3" id2 -->8<!-- npu="A3" id2 -->
9-- Atlas A3 训练系列产品/Atlas A3 推理系列产品:不支持9+- Atlas A3系列产品:不支持
10<!-- end id2 -->10<!-- end id2 -->
11<!-- npu="910b" id3 -->11<!-- npu="910b" id3 -->
12-- Atlas A2 训练系列产品/Atlas A2 推理系列产品:不支持12+- Atlas A2系列产品:不支持
13<!-- end id3 -->13<!-- end id3 -->
14 14 
15## 功能说明15## 功能说明
@@ -3,13 +3,13 @@
3## 产品支持情况3## 产品支持情况
4 4 
5<!-- npu="950" id1 -->5<!-- npu="950" id1 -->
6-- Ascend 950PR/Ascend 950DT:支持6+- Ascend 950PR&950DT系列产品:支持
7<!-- end id1 -->7<!-- end id1 -->
8<!-- npu="A3" id2 -->8<!-- npu="A3" id2 -->
9-- Atlas A3 训练系列产品/Atlas A3 推理系列产品:不支持9+- Atlas A3系列产品:不支持
10<!-- end id2 -->10<!-- end id2 -->
11<!-- npu="910b" id3 -->11<!-- npu="910b" id3 -->
12-- Atlas A2 训练系列产品/Atlas A2 推理系列产品:不支持12+- Atlas A2系列产品:不支持
13<!-- end id3 -->13<!-- end id3 -->
14 14 
15## 功能说明15## 功能说明
@@ -3,13 +3,13 @@
3## 产品支持情况3## 产品支持情况
4 4 
5<!-- npu="950" id1 -->5<!-- npu="950" id1 -->
6-- Ascend 950PR/Ascend 950DT:支持6+- Ascend 950PR&950DT系列产品:支持
7<!-- end id1 -->7<!-- end id1 -->
8<!-- npu="A3" id2 -->8<!-- npu="A3" id2 -->
9-- Atlas A3 训练系列产品/Atlas A3 推理系列产品:不支持9+- Atlas A3系列产品:不支持
10<!-- end id2 -->10<!-- end id2 -->
11<!-- npu="910b" id3 -->11<!-- npu="910b" id3 -->
12-- Atlas A2 训练系列产品/Atlas A2 推理系列产品:不支持12+- Atlas A2系列产品:不支持
13<!-- end id3 -->13<!-- end id3 -->
14 14 
15## 功能说明15## 功能说明
@@ -3,13 +3,13 @@
3## 产品支持情况3## 产品支持情况
4 4 
5<!-- npu="950" id1 -->5<!-- npu="950" id1 -->
6-- Ascend 950PR/Ascend 950DT:支持6+- Ascend 950PR&950DT系列产品:支持
7<!-- end id1 -->7<!-- end id1 -->
8<!-- npu="A3" id2 -->8<!-- npu="A3" id2 -->
9-- Atlas A3 训练系列产品/Atlas A3 推理系列产品:不支持9+- Atlas A3系列产品:不支持
10<!-- end id2 -->10<!-- end id2 -->
11<!-- npu="910b" id3 -->11<!-- npu="910b" id3 -->
12-- Atlas A2 训练系列产品/Atlas A2 推理系列产品:不支持12+- Atlas A2系列产品:不支持
13<!-- end id3 -->13<!-- end id3 -->
14 14 
15## 功能说明15## 功能说明
@@ -3,13 +3,13 @@
3## 产品支持情况3## 产品支持情况
4 4 
5<!-- npu="950" id1 -->5<!-- npu="950" id1 -->
6-- Ascend 950PR/Ascend 950DT:支持6+- Ascend 950PR&950DT系列产品:支持
7<!-- end id1 -->7<!-- end id1 -->
8<!-- npu="A3" id2 -->8<!-- npu="A3" id2 -->
9-- Atlas A3 训练系列产品/Atlas A3 推理系列产品:不支持9+- Atlas A3系列产品:不支持
10<!-- end id2 -->10<!-- end id2 -->
11<!-- npu="910b" id3 -->11<!-- npu="910b" id3 -->
12-- Atlas A2 训练系列产品/Atlas A2 推理系列产品:不支持12+- Atlas A2系列产品:不支持
13<!-- end id3 -->13<!-- end id3 -->
14 14 
15## 功能说明15## 功能说明
@@ -3,13 +3,13 @@
3## 产品支持情况3## 产品支持情况
4 4 
5<!-- npu="950" id1 -->5<!-- npu="950" id1 -->
6-- Ascend 950PR/Ascend 950DT:支持6+- Ascend 950PR&950DT系列产品:支持
7<!-- end id1 -->7<!-- end id1 -->
8<!-- npu="A3" id2 -->8<!-- npu="A3" id2 -->
9-- Atlas A3 训练系列产品/Atlas A3 推理系列产品:不支持9+- Atlas A3系列产品:不支持
10<!-- end id2 -->10<!-- end id2 -->
11<!-- npu="910b" id3 -->11<!-- npu="910b" id3 -->
12-- Atlas A2 训练系列产品/Atlas A2 推理系列产品:不支持12+- Atlas A2系列产品:不支持
13<!-- end id3 -->13<!-- end id3 -->
14 14 
15## 功能说明15## 功能说明
@@ -3,13 +3,13 @@
3## 产品支持情况3## 产品支持情况
4 4 
5<!-- npu="950" id1 -->5<!-- npu="950" id1 -->
6-- Ascend 950PR/Ascend 950DT:支持6+- Ascend 950PR&950DT系列产品:支持
7<!-- end id1 -->7<!-- end id1 -->
8<!-- npu="A3" id2 -->8<!-- npu="A3" id2 -->
9-- Atlas A3 训练系列产品/Atlas A3 推理系列产品:不支持9+- Atlas A3系列产品:不支持
10<!-- end id2 -->10<!-- end id2 -->
11<!-- npu="910b" id3 -->11<!-- npu="910b" id3 -->
12-- Atlas A2 训练系列产品/Atlas A2 推理系列产品:不支持12+- Atlas A2系列产品:不支持
13<!-- end id3 -->13<!-- end id3 -->
14 14 
15## 功能说明15## 功能说明
@@ -3,13 +3,13 @@
3## 产品支持情况3## 产品支持情况
4 4 
5<!-- npu="950" id1 -->5<!-- npu="950" id1 -->
6-- Ascend 950PR/Ascend 950DT:支持6+- Ascend 950PR&950DT系列产品:支持
7<!-- end id1 -->7<!-- end id1 -->
8<!-- npu="A3" id2 -->8<!-- npu="A3" id2 -->
9-- Atlas A3 训练系列产品/Atlas A3 推理系列产品:不支持9+- Atlas A3系列产品:不支持
10<!-- end id2 -->10<!-- end id2 -->
11<!-- npu="910b" id3 -->11<!-- npu="910b" id3 -->
12-- Atlas A2 训练系列产品/Atlas A2 推理系列产品:不支持12+- Atlas A2系列产品:不支持
13<!-- end id3 -->13<!-- end id3 -->
14 14 
15## 功能说明15## 功能说明
@@ -3,13 +3,13 @@
3## 产品支持情况3## 产品支持情况
4 4 
5<!-- npu="950" id1 -->5<!-- npu="950" id1 -->
6-- Ascend 950PR/Ascend 950DT:支持6+- Ascend 950PR&950DT系列产品:支持
7<!-- end id1 -->7<!-- end id1 -->
8<!-- npu="A3" id2 -->8<!-- npu="A3" id2 -->
9-- Atlas A3 训练系列产品/Atlas A3 推理系列产品:不支持9+- Atlas A3系列产品:不支持
10<!-- end id2 -->10<!-- end id2 -->
11<!-- npu="910b" id3 -->11<!-- npu="910b" id3 -->
12-- Atlas A2 训练系列产品/Atlas A2 推理系列产品:不支持12+- Atlas A2系列产品:不支持
13<!-- end id3 -->13<!-- end id3 -->
14 14 
15## 功能说明15## 功能说明
@@ -3,13 +3,13 @@
3## 产品支持情况3## 产品支持情况
4 4 
5<!-- npu="950" id1 -->5<!-- npu="950" id1 -->
6-- Ascend 950PR/Ascend 950DT:支持6+- Ascend 950PR&950DT系列产品:支持
7<!-- end id1 -->7<!-- end id1 -->
8<!-- npu="A3" id2 -->8<!-- npu="A3" id2 -->
9-- Atlas A3 训练系列产品/Atlas A3 推理系列产品:不支持9+- Atlas A3系列产品:不支持
10<!-- end id2 -->10<!-- end id2 -->
11<!-- npu="910b" id3 -->11<!-- npu="910b" id3 -->
12-- Atlas A2 训练系列产品/Atlas A2 推理系列产品:不支持12+- Atlas A2系列产品:不支持
13<!-- end id3 -->13<!-- end id3 -->
14 14 
15## 功能说明15## 功能说明
@@ -3,13 +3,13 @@
3## 产品支持情况3## 产品支持情况
4 4 
5<!-- npu="950" id1 -->5<!-- npu="950" id1 -->
6-- Ascend 950PR/Ascend 950DT:支持6+- Ascend 950PR&950DT系列产品:支持
7<!-- end id1 -->7<!-- end id1 -->
8<!-- npu="A3" id2 -->8<!-- npu="A3" id2 -->
9-- Atlas A3 训练系列产品/Atlas A3 推理系列产品:不支持9+- Atlas A3系列产品:不支持
10<!-- end id2 -->10<!-- end id2 -->
11<!-- npu="910b" id3 -->11<!-- npu="910b" id3 -->
12-- Atlas A2 训练系列产品/Atlas A2 推理系列产品:不支持12+- Atlas A2系列产品:不支持
13<!-- end id3 -->13<!-- end id3 -->
14 14 
15## 功能说明15## 功能说明
@@ -3,13 +3,13 @@
3## 产品支持情况3## 产品支持情况
4 4 
5<!-- npu="950" id1 -->5<!-- npu="950" id1 -->
6-- Ascend 950PR/Ascend 950DT:支持6+- Ascend 950PR&950DT系列产品:支持
7<!-- end id1 -->7<!-- end id1 -->
8<!-- npu="A3" id2 -->8<!-- npu="A3" id2 -->
9-- Atlas A3 训练系列产品/Atlas A3 推理系列产品:不支持9+- Atlas A3系列产品:不支持
10<!-- end id2 -->10<!-- end id2 -->
11<!-- npu="910b" id3 -->11<!-- npu="910b" id3 -->
12-- Atlas A2 训练系列产品/Atlas A2 推理系列产品:不支持12+- Atlas A2系列产品:不支持
13<!-- end id3 -->13<!-- end id3 -->
14 14 
15## 功能说明15## 功能说明
@@ -40,8 +40,8 @@ pypto_pro.language.move(
40| offset | 输入 | 可选,表示小Tile在大Tile中的相对位置,格式为[offset_m, offset_n],单位为元素个数。<br>- 当源操作数的shape >= 目的操作数的shape时,表示从源操作数的第offset_m行offset_n列开始读,数据的搬运量取自目的操作数的valid_shape。<br>- 当源操作数的shape < 目的操作数的shape时,表示从目的操作数的第offset_m行offset_n列开始写,数据的搬运量取自源操作数的valid_shape。 |40| offset | 输入 | 可选,表示小Tile在大Tile中的相对位置,格式为[offset_m, offset_n],单位为元素个数。<br>- 当源操作数的shape >= 目的操作数的shape时,表示从源操作数的第offset_m行offset_n列开始读,数据的搬运量取自目的操作数的valid_shape。<br>- 当源操作数的shape < 目的操作数的shape时,表示从目的操作数的第offset_m行offset_n列开始写,数据的搬运量取自源操作数的valid_shape。 |
41| acc_to_vec_mode | 输入 | 可选,L0C Buffer→UB搬运时是否开启双目标搬运模式,[pypto_pro.language.AccToVecMode](../basic_data_structures/AccToVecMode.md)类型。<br>- DualModeSplitN与phase同时使用时,若N未32对齐,可能出现卡死现象。可以在矩阵乘运算前对L0B Buffer的N设置valid shape,使其向上对齐到32的倍数。 |41| acc_to_vec_mode | 输入 | 可选,L0C Buffer→UB搬运时是否开启双目标搬运模式,[pypto_pro.language.AccToVecMode](../basic_data_structures/AccToVecMode.md)类型。<br>- DualModeSplitN与phase同时使用时,若N未32对齐,可能出现卡死现象。可以在矩阵乘运算前对L0B Buffer的N设置valid shape,使其向上对齐到32的倍数。 |
42| relu_pre_mode | 输入 | 可选,L0C Buffer→UB搬运时是否开启随路ReLU操作,[pypto_pro.language.ReluPreMode](../basic_data_structures/ReluPreMode.md)类型。 |42| relu_pre_mode | 输入 | 可选,L0C Buffer→UB搬运时是否开启随路ReLU操作,[pypto_pro.language.ReluPreMode](../basic_data_structures/ReluPreMode.md)类型。 |
43-| scale | 输入 | 可选,是否使能量化功能及设置量化模式下的量化参数,数据在搬出L0C Buffer时由Fixpipe乘以该比例并转换到目的数据类型。不支持与双目标搬运(AccToVecMode.DualModeSplitM / AccToVecMode.DualModeSplitN)同时使用。不同的传入形式会影响量化粒度,支持如下类型:<br>- **float类型**:直接传入固定值(如scale = 2.0),适用于整块Tile使用同一比例。<br>- **Scalar类型**:量化比例在运行时确定,需按数据类型传值。<br>&nbsp;&nbsp;- DT_FP32:直接传原始比例值(如0.5)。<br>&nbsp;&nbsp;- DT_INT32、DT_INT64:传预编码的float32位模式转成的整数(如struct.pack("!f", 0.5))。<br>- **Tile类型**:每列使用独立比例,需满足以下要求:<br>&nbsp;&nbsp;- 目标存储区域必须为Fixpipe Buffer。<br>&nbsp;&nbsp;- shape为[1, N](列量化),N必须是16的倍数且N ≤ 512。<br>&nbsp;&nbsp;- dtype为DT_INT64。<br>&nbsp;&nbsp;- 目的操作数的Tile数据类型为DT_INT8时,Fixpipe Buffer中的Tile每个DT_INT64元素的bit46需置1,用于选择有符号量化;未置位时L0C Buffer中的负值会被按无符号解读。<br>&nbsp;&nbsp;- 用户需要先把比例数据从GM搬到L1 Buffer,再搬到Fixpipe Buffer,并完成MTE1→FIX同步。|43+| scale | 输入 | 可选,是否使能量化功能及设置量化模式下的量化参数,数据在搬出L0C Buffer时由Fixpipe乘以该比例并转换到目的数据类型。不支持与双目标搬运(AccToVecMode.DualModeSplitM / AccToVecMode.DualModeSplitN)同时使用。不同的传入形式会影响量化粒度,支持如下类型:<br>- **float类型**:直接传入固定值(如scale = 2.0),适用于整块Tile使用同一比例。<br>- **Scalar类型**:量化比例在运行时确定,需按数据类型传值。<br>&nbsp;&nbsp;- DT_FP32:直接传原始比例值(如0.5)。<br>&nbsp;&nbsp;- DT_INT32、DT_INT64:传预编码的float32位模式转成的整数(如struct.pack("!f", 0.5))。<br>- **Tile类型**:每列使用独立比例,需满足以下要求:<br>&nbsp;&nbsp;- 目标存储区域必须为Fixpipe Buffer。<br>&nbsp;&nbsp;- shape为[1, N](列量化),N必须是16的倍数且N ≤ 512。<br>&nbsp;&nbsp;- dtype为DT_INT64。<br>&nbsp;&nbsp;- 目的操作数的Tile数据类型为DT_INT8时,Fixpipe Buffer中的Tile每个DT_INT64元素的bit46需置1,用于选择有符号量化;未置位时L0C Buffer中的负值会被按无符号解读。<br>&nbsp;&nbsp;- 用户需要先把比例数据从GM搬到L1 Buffer,再搬到Fixpipe Buffer,并完成MTE1→FIX同步。|
44-| phase | 输入 | 可选,详见 [phase 使用约束](../cube_computation/phase.md) |44+| phase | 输入 | 可选,详见 [phase 使用约束](../cube_computation/phase.md) |
45 45 
46## 约束说明46## 约束说明
47 47 
@@ -55,7 +55,7 @@ pypto_pro.language.move(
55 | UB → UB(目的Tile的shape大于源Tile) | ND → ND、NZ → NZ。 | 源与目的必须相同,支持DT_INT8、DT_INT32、DT_FP16、DT_BF16、DT_FP32、DT_FP8E4M3FN、DT_FP8E5M2、DT_FP8E8M0、DT_HF8、DT_FP4E2M1、DT_FP4E1M2。 |55 | UB → UB(目的Tile的shape大于源Tile) | ND → ND、NZ → NZ。 | 源与目的必须相同,支持DT_INT8、DT_INT32、DT_FP16、DT_BF16、DT_FP32、DT_FP8E4M3FN、DT_FP8E5M2、DT_FP8E8M0、DT_HF8、DT_FP4E2M1、DT_FP4E1M2。 |
56 | UB → L1 Buffer(目的Tile的shape不大于源Tile) | 源支持ND、NZ,目的不校验分形。 | 源与目的必须相同,支持DT_INT8、DT_FP8E4M3FN、DT_FP8E5M2、DT_HF8、DT_FP16、DT_BF16、DT_FP32、DT_FP4E2M1、DT_FP4E1M2、DT_FP8E8M0。 |56 | UB → L1 Buffer(目的Tile的shape不大于源Tile) | 源支持ND、NZ,目的不校验分形。 | 源与目的必须相同,支持DT_INT8、DT_FP8E4M3FN、DT_FP8E5M2、DT_HF8、DT_FP16、DT_BF16、DT_FP32、DT_FP4E2M1、DT_FP4E1M2、DT_FP8E8M0。 |
57 | UB → L1 Buffer(目的Tile的shape大于源Tile) | 源支持ND、NZ,目的不校验分形。 | 源与目的必须相同,支持DT_INT8、DT_INT32、DT_FP16、DT_BF16、DT_FP32、DT_FP8E4M3FN、DT_FP8E5M2、DT_FP8E8M0、DT_HF8、DT_FP4E2M1、DT_FP4E1M2。 |57 | UB → L1 Buffer(目的Tile的shape大于源Tile) | 源支持ND、NZ,目的不校验分形。 | 源与目的必须相同,支持DT_INT8、DT_INT32、DT_FP16、DT_BF16、DT_FP32、DT_FP8E4M3FN、DT_FP8E5M2、DT_FP8E8M0、DT_HF8、DT_FP4E2M1、DT_FP4E1M2。 |
58- | L1 Buffer → BiasTable Buffer | 目的layout固定为ND。 | 支持DT_INT32 → DT_INT32、DT_FP32 → DT_FP32、DT_FP16 → DT_FP32、DT_BF16 → DT_FP32。 |58+ | L1 Buffer → BiasTable Buffer | 目的layout固定为ND。 | 支持DT_INT32 → DT_INT32、DT_FP32 → DT_FP32、DT_FP16 → DT_FP32、DT_BF16 → DT_FP32。 |
59 | L1 Buffer → Fixpipe Buffer | 不校验分形。 | 目的必须为DT_INT64或DT_UINT64,源数据类型不做限制。 |59 | L1 Buffer → Fixpipe Buffer | 不校验分形。 | 目的必须为DT_INT64或DT_UINT64,源数据类型不做限制。 |
60 | L1 Buffer → L0A_MX Buffer | 源与目的分形均为ZZ。 | 源与目的必须相同,仅支持DT_FP8E8M0。 |60 | L1 Buffer → L0A_MX Buffer | 源与目的分形均为ZZ。 | 源与目的必须相同,仅支持DT_FP8E8M0。 |
61 | L1 Buffer → L0B_MX Buffer | 源与目的分形均为NN。 | 源与目的必须相同,仅支持DT_FP8E8M0。 |61 | L1 Buffer → L0B_MX Buffer | 源与目的分形均为NN。 | 源与目的必须相同,仅支持DT_FP8E8M0。 |
@@ -114,7 +114,7 @@ def kernel(
114 pl.store(out, ac, [0, 0])114 pl.store(out, ac, [0, 0])
115 115 
116 116 
117-if __name__ == "__main__":117+if __name__ == "__main__":
118 device = f"npu:{int(os.environ.get('TILE_FWK_DEVICE_ID', 0))}"118 device = f"npu:{int(os.environ.get('TILE_FWK_DEVICE_ID', 0))}"
119 torch.npu.set_device(device)119 torch.npu.set_device(device)
120 torch.manual_seed(42)120 torch.manual_seed(42)
@@ -128,65 +128,65 @@ if __name__ == "__main__":
128 128 
129 ref = torch.matmul(a.float(), b.float())129 ref = torch.matmul(a.float(), b.float())
130 torch.testing.assert_close(out, ref, rtol=2e-2, atol=2e-2)130 torch.testing.assert_close(out, ref, rtol=2e-2, atol=2e-2)
131- print(f"max diff = {(out - ref).abs().max().item()}")131+ print(f"max diff = {(out - ref).abs().max().item()}")
132-```132+```
133- 133+ 
134-### UB数据转置写入L1 Buffer134+### UB数据转置写入L1 Buffer
135- 135+ 
136-当左矩阵或右矩阵由Vector计算在UB中产生时,可先通过pypto_pro.language.move将ND转换为NZ,再将结果写入L1 Buffer:136+当左矩阵或右矩阵由Vector计算在UB中产生时,可先通过pypto_pro.language.move将ND转换为NZ,再将结果写入L1 Buffer:
137- 137+ 
138-- 不转置时,L1 Buffer Tile使用NZ,shape与UB中的NZ Tile相同。138+- 不转置时,L1 Buffer Tile使用NZ,shape与UB中的NZ Tile相同。
139-- 转置时,L1 Buffer Tile使用ZN,shape的两个维度与UB中的NZ Tile互换。源Tile的NZ [R, C]与目的Tile的ZN [C, R]表示相同的物理分形。139+- 转置时,L1 Buffer Tile使用ZN,shape的两个维度与UB中的NZ Tile互换。源Tile的NZ [R, C]与目的Tile的ZN [C, R]表示相同的物理分形。
140- 140+ 
141-| 矩阵 | 是否转置 | UB中的NZ Tile | L1 Buffer Tile |141+| 矩阵 | 是否转置 | UB中的NZ Tile | L1 Buffer Tile |
142-|---|---|---|---|142+|---|---|---|---|
143-| 左矩阵A[M, K] | 否 | shape=[M, K] | shape=[M, K],NZ |143+| 左矩阵A[M, K] | 否 | shape=[M, K] | shape=[M, K],NZ |
144-| 左矩阵A[M, K] | 是 | shape=[K, M] | shape=[M, K],ZN |144+| 左矩阵A[M, K] | 是 | shape=[K, M] | shape=[M, K],ZN |
145-| 右矩阵B[K, N] | 否 | shape=[K, N] | shape=[K, N],NZ |145+| 右矩阵B[K, N] | 否 | shape=[K, N] | shape=[K, N],NZ |
146-| 右矩阵B[K, N] | 是 | shape=[N, K] | shape=[K, N],ZN |146+| 右矩阵B[K, N] | 是 | shape=[N, K] | shape=[K, N],ZN |
147- 147+ 
148-分块写入L1 Buffer时,可通过offset指定写入位置;源Tile的有效区域必须完整落入目的Tile范围内。148+分块写入L1 Buffer时,可通过offset指定写入位置;源Tile的有效区域必须完整落入目的Tile范围内。
149- 149+ 
150-以下示例中,vector_result表示Vector计算产生的[K, M]数据。第一次move将其转换为NZ,第二次move将其转置写入L1 Buffer,得到供左矩阵使用的[M, K]、ZN数据。150+以下示例中,vector_result表示Vector计算产生的[K, M]数据。第一次move将其转换为NZ,第二次move将其转置写入L1 Buffer,得到供左矩阵使用的[M, K]、ZN数据。
151- 151+ 
152-```python152+```python
153-import pypto_pro.language as pl153+import pypto_pro.language as pl
154- 154+ 
155-M, K = 64, 128155+M, K = 64, 128
156- 156+ 
157-# 前序Vector计算的输出:UB中的ND [K, M]157+# 前序Vector计算的输出:UB中的ND [K, M]
158-vector_result = pl.make_tile(158+vector_result = pl.make_tile(
159- pl.TileType(159+ pl.TileType(
160- shape=[K, M], dtype=pl.DT_FP16,160+ shape=[K, M], dtype=pl.DT_FP16,
161- target_memory=pl.MemorySpace.Vec, layout=pl.ND,161+ target_memory=pl.MemorySpace.Vec, layout=pl.ND,
162- ),162+ ),
163- addr=0x0000,163+ addr=0x0000,
164-)164+)
165- 165+ 
166-# ND转换为NZ时使用的UB Tile166+# ND转换为NZ时使用的UB Tile
167-vector_nz = pl.make_tile(167+vector_nz = pl.make_tile(
168- pl.TileType(168+ pl.TileType(
169- shape=[K, M], dtype=pl.DT_FP16,169+ shape=[K, M], dtype=pl.DT_FP16,
170- target_memory=pl.MemorySpace.Vec, layout=pl.NZ,170+ target_memory=pl.MemorySpace.Vec, layout=pl.NZ,
171- ),171+ ),
172- addr=0x4000,172+ addr=0x4000,
173-)173+)
174- 174+ 
175-# 转置后的数据写入L1 Buffer,逻辑shape为[M, K]175+# 转置后的数据写入L1 Buffer,逻辑shape为[M, K]
176-lhs_l1 = pl.make_tile(176+lhs_l1 = pl.make_tile(
177- pl.TileType(177+ pl.TileType(
178- shape=[M, K], dtype=pl.DT_FP16,178+ shape=[M, K], dtype=pl.DT_FP16,
179- target_memory=pl.MemorySpace.Mat, layout=pl.ZN,179+ target_memory=pl.MemorySpace.Mat, layout=pl.ZN,
180- ),180+ ),
181- addr=0x20000,181+ addr=0x20000,
182-)182+)
183- 183+ 
184-with pl.section_vector():184+with pl.section_vector():
185- pl.move(vector_nz, vector_result) # ND [K, M] → NZ [K, M]185+ pl.move(vector_nz, vector_result) # ND [K, M] → NZ [K, M]
186- pl.move(lhs_l1, vector_nz) # NZ [K, M] → ZN [M, K]186+ pl.move(lhs_l1, vector_nz) # NZ [K, M] → ZN [M, K]
187-```187+```
188- 188+ 
189-### 量化参数的使用189+### 量化参数的使用
190 190 
191```python191```python
192# 方式一:scale为编译期常量192# 方式一:scale为编译期常量
@@ -3,13 +3,13 @@
3## 产品支持情况3## 产品支持情况
4 4 
5<!-- npu="950" id1 -->5<!-- npu="950" id1 -->
6-- Ascend 950PR/Ascend 950DT:支持6+- Ascend 950PR&950DT系列产品:支持
7<!-- end id1 -->7<!-- end id1 -->
8<!-- npu="A3" id2 -->8<!-- npu="A3" id2 -->
9-- Atlas A3 训练系列产品/Atlas A3 推理系列产品:不支持9+- Atlas A3系列产品:不支持
10<!-- end id2 -->10<!-- end id2 -->
11<!-- npu="910b" id3 -->11<!-- npu="910b" id3 -->
12-- Atlas A2 训练系列产品/Atlas A2 推理系列产品:不支持12+- Atlas A2系列产品:不支持
13<!-- end id3 -->13<!-- end id3 -->
14 14 
15## 功能说明15## 功能说明
@@ -3,13 +3,13 @@
3## 产品支持情况3## 产品支持情况
4 4 
5<!-- npu="950" id1 -->5<!-- npu="950" id1 -->
6-- Ascend 950PR/Ascend 950DT:支持6+- Ascend 950PR&950DT系列产品:支持
7<!-- end id1 -->7<!-- end id1 -->
8<!-- npu="A3" id2 -->8<!-- npu="A3" id2 -->
9-- Atlas A3 训练系列产品/Atlas A3 推理系列产品:不支持9+- Atlas A3系列产品:不支持
10<!-- end id2 -->10<!-- end id2 -->
11<!-- npu="910b" id3 -->11<!-- npu="910b" id3 -->
12-- Atlas A2 训练系列产品/Atlas A2 推理系列产品:不支持12+- Atlas A2系列产品:不支持
13<!-- end id3 -->13<!-- end id3 -->
14 14 
15## 功能说明15## 功能说明
@@ -1,58 +1,58 @@
1# pypto_pro.language.dequant1# pypto_pro.language.dequant
2 2 
3-## 产品支持情况3+## 产品支持情况
4- 4+ 
5-<!-- npu="950" id1 -->5+<!-- npu="950" id1 -->
6-- Ascend 950PR/Ascend 950DT:支持6+- Ascend 950PR&950DT系列产品:支持
7-<!-- end id1 -->7+<!-- end id1 -->
8-<!-- npu="A3" id2 -->8+<!-- npu="A3" id2 -->
9-- Atlas A3 训练系列产品/Atlas A3 推理系列产品:不支持9+- Atlas A3系列产品:不支持
10-<!-- end id2 -->10+<!-- end id2 -->
11-<!-- npu="910b" id3 -->11+<!-- npu="910b" id3 -->
12-- Atlas A2 训练系列产品/Atlas A2 推理系列产品:不支持12+- Atlas A2系列产品:不支持
13-<!-- end id3 -->13+<!-- end id3 -->
14- 14+ 
15## 功能说明15## 功能说明
16 16 
17-把INT8或INT16源Tile反量化为FP32。scale[i,0]和offset[i,0]按行广播:17+把INT8或INT16源Tile反量化为FP32。scale[i,0]和offset[i,0]按行广播:
18- 18+ 
19-$$19+$$
20-out_{i,j}=\left(\operatorname{FP32}(src_{i,j})-offset_{i,0}\right)\times scale_{i,0}20+out_{i,j}=\left(\operatorname{FP32}(src_{i,j})-offset_{i,0}\right)\times scale_{i,0}
21-$$21+$$
22- 22+ 
23-计算顺序为:整数源数据扩展并转换为FP32、减去offset、乘以scale。若与[quant](quant.md)配套使用,量化阶段传入的系数通常为本接口scale的倒数。23+计算顺序为:整数源数据扩展并转换为FP32、减去offset、乘以scale。若与[quant](quant.md)配套使用,量化阶段传入的系数通常为本接口scale的倒数。
24 24 
25## 函数原型25## 函数原型
26 26 
27```python27```python
28-pypto_pro.language.dequant(28+pypto_pro.language.dequant(
29- out: Tile,29+ out: Tile,
30- src: Tile,30+ src: Tile,
31- scale: Tile,31+ scale: Tile,
32- offset: Tile,32+ offset: Tile,
33-) -> None33+) -> None
34```34```
35 35 
36-## 参数说明36+## 参数说明
37 37 
38| 参数 | 输入/输出 | 说明 |38| 参数 | 输入/输出 | 说明 |
39|---|---|---|39|---|---|---|
40-| out | 输出 | 目的操作数,Tile类型,存储空间为UB,数据类型为DT_FP32,layout必须为ND;shape和valid_shape须与src一致。 |40+| out | 输出 | 目的操作数,Tile类型,存储空间为UB,数据类型为DT_FP32,layout必须为ND;shape和valid_shape须与src一致。 |
41-| src | 输入 | 源操作数,Tile类型,存储空间为UB,数据类型为DT_INT8或DT_INT16,layout必须为ND;shape和valid_shape须与out一致。 |41+| src | 输入 | 源操作数,Tile类型,存储空间为UB,数据类型为DT_INT8或DT_INT16,layout必须为ND;shape和valid_shape须与out一致。 |
42-| scale | 输入 | 反量化系数,Tile类型,存储空间为UB,数据类型为DT_FP32,layout为ND或DN。若out.valid_shape=[M,N],则scale.valid_shape须为[M,1],shape的行数不得小于M且列数必须为1;有效行数须与输出有效行数一致,物理行数须满足32字节对齐,DT_FP32场景即为8的倍数。第i行的scale[i,0]广播到输出第i行全部有效列。 |42+| scale | 输入 | 反量化系数,Tile类型,存储空间为UB,数据类型为DT_FP32,layout为ND或DN。若out.valid_shape=[M,N],则scale.valid_shape须为[M,1],shape的行数不得小于M且列数必须为1;有效行数须与输出有效行数一致,物理行数须满足32字节对齐,DT_FP32场景即为8的倍数。第i行的scale[i,0]广播到输出第i行全部有效列。 |
43-| offset | 输入 | 量化零点,Tile类型,存储空间为UB,数据类型为DT_FP32,layout为ND或DN,shape和valid_shape均须与scale一致;有效行数须与输出有效行数一致,物理行数须满足32字节对齐,DT_FP32场景即为8的倍数。第i行的offset[i,0]广播到对应数据行。本参数不能省略;对称量化时传入全零Tile。 |43+| offset | 输入 | 量化零点,Tile类型,存储空间为UB,数据类型为DT_FP32,layout为ND或DN,shape和valid_shape均须与scale一致;有效行数须与输出有效行数一致,物理行数须满足32字节对齐,DT_FP32场景即为8的倍数。第i行的offset[i,0]广播到对应数据行。本参数不能省略;对称量化时传入全零Tile。 |
44- 44+ 
45-## 约束说明45+## 约束说明
46- 46+ 
47-无。47+无。
48- 48+ 
49-## 返回值说明49+## 返回值说明
50- 50+ 
51-无。51+无。
52- 52+ 
53## 调用示例53## 调用示例
54 54 
55-```python55+```python
56import pypto_pro.language as pl56import pypto_pro.language as pl
57 57 
58 58 
@@ -1,19 +1,19 @@
1-# pypto_pro.language.quant1+# pypto_pro.language.quant
2- 2+ 
3## 产品支持情况3## 产品支持情况
4 4 
5<!-- npu="950" id1 -->5<!-- npu="950" id1 -->
6-- Ascend 950PR/Ascend 950DT:支持6+- Ascend 950PR&950DT系列产品:支持
7<!-- end id1 -->7<!-- end id1 -->
8<!-- npu="A3" id2 -->8<!-- npu="A3" id2 -->
9-- Atlas A3 训练系列产品/Atlas A3 推理系列产品:不支持9+- Atlas A3系列产品:不支持
10<!-- end id2 -->10<!-- end id2 -->
11<!-- npu="910b" id3 -->11<!-- npu="910b" id3 -->
12-- Atlas A2 训练系列产品/Atlas A2 推理系列产品:不支持12+- Atlas A2系列产品:不支持
13<!-- end id3 -->13<!-- end id3 -->
14 14 
15-## 功能说明15+## 功能说明
16- 16+ 
17把FP32源Tile量化为INT8或UINT8。scale是量化系数(常见量化定义中真实scale的倒数),scale[i, 0]和offset[i, 0]按行广播:17把FP32源Tile量化为INT8或UINT8。scale是量化系数(常见量化定义中真实scale的倒数),scale[i, 0]和offset[i, 0]按行广播:
18 18 
19$$19$$
@@ -24,10 +24,10 @@ out_{i,j}=\begin{cases}
24$$24$$
25 25 
26非对称模式先在FP32中完成乘法和加法,再对合并后的结果执行一次舍入;不是先舍入乘积再添加offset。26非对称模式先在FP32中完成乘法和加法,再对合并后的结果执行一次舍入;不是先舍入乘积再添加offset。
27- 27+ 
28-## 函数原型28+## 函数原型
29- 29+ 
30-```python30+```python
31pypto_pro.language.quant(31pypto_pro.language.quant(
32 out: Tile,32 out: Tile,
33 src: Tile,33 src: Tile,
@@ -36,12 +36,12 @@ pypto_pro.language.quant(
36 mode: QuantMode = pypto_pro.language.QuantMode.SYM,36 mode: QuantMode = pypto_pro.language.QuantMode.SYM,
37 offset: Optional[Tile] = None,37 offset: Optional[Tile] = None,
38) -> None38) -> None
39-```39+```
40- 40+ 
41## 参数说明41## 参数说明
42- 42+ 
43-| 参数 | 输入/输出 | 说明 |43+| 参数 | 输入/输出 | 说明 |
44-|---|---|---|44+|---|---|---|
45| out | 输出 | 目的操作数,Tile类型,存储空间为UB,layout必须为ND。mode=SYM时数据类型为DT_INT8,mode=ASYM时为DT_UINT8;shape和valid_shape须与src一致。 |45| out | 输出 | 目的操作数,Tile类型,存储空间为UB,layout必须为ND。mode=SYM时数据类型为DT_INT8,mode=ASYM时为DT_UINT8;shape和valid_shape须与src一致。 |
46| src | 输入 | 源操作数,Tile类型,存储空间为UB,数据类型为DT_FP32,layout必须为ND;shape和valid_shape须与out一致。 |46| src | 输入 | 源操作数,Tile类型,存储空间为UB,数据类型为DT_FP32,layout必须为ND;shape和valid_shape须与out一致。 |
47| scale | 输入 | 量化系数,Tile类型,存储空间为UB,数据类型为DT_FP32,layout为ND或DN,取值须为有限正数。若src.valid_shape=[M,N],则scale.valid_shape须为[M,1],shape的行数不得小于M且列数必须为1;有效行数须与输出有效行数一致,物理行数须满足32字节对齐,DT_FP32场景即为8的倍数。第i行的scale[i,0]广播到src第i行全部有效列。该值直接与src相乘,因此若使用常见公式$q=round(x/s)$,此处应传入$1/s$。 |47| scale | 输入 | 量化系数,Tile类型,存储空间为UB,数据类型为DT_FP32,layout为ND或DN,取值须为有限正数。若src.valid_shape=[M,N],则scale.valid_shape须为[M,1],shape的行数不得小于M且列数必须为1;有效行数须与输出有效行数一致,物理行数须满足32字节对齐,DT_FP32场景即为8的倍数。第i行的scale[i,0]广播到src第i行全部有效列。该值直接与src相乘,因此若使用常见公式$q=round(x/s)$,此处应传入$1/s$。 |
@@ -51,35 +51,35 @@ pypto_pro.language.quant(
51## 约束说明51## 约束说明
52 52 
53- 计算结果采用就近舍入(中间值取偶),并饱和至目标数据类型的取值范围。53- 计算结果采用就近舍入(中间值取偶),并饱和至目标数据类型的取值范围。
54- 54+ 
55## 返回值说明55## 返回值说明
56 56 
57无。57无。
58 58 
59-## 调用示例59+## 调用示例
60- 60+ 
61```python61```python
62-import pypto_pro.language as pl62+import pypto_pro.language as pl
63- 63+ 
64- 64+ 
65-@pl.jit(auto_mutex=True)65+@pl.jit(auto_mutex=True)
66-def quant_kernel(66+def quant_kernel(
67- src: pl.Tensor[[64, 128], pl.DT_FP32],67+ src: pl.Tensor[[64, 128], pl.DT_FP32],
68- scale: pl.Tensor[[64, 1], pl.DT_FP32],68+ scale: pl.Tensor[[64, 1], pl.DT_FP32],
69- out: pl.Tensor[[64, 128], pl.DT_INT8],69+ out: pl.Tensor[[64, 128], pl.DT_INT8],
70-):70+):
71- tile_src = pl.make_tile_group(type=pl.TileType(shape=[64, 128], dtype=pl.DT_FP32, target_memory=pl.MemorySpace.Vec),71+ tile_src = pl.make_tile_group(type=pl.TileType(shape=[64, 128], dtype=pl.DT_FP32, target_memory=pl.MemorySpace.Vec),
72- addrs=0x0000, mutex_ids=[0])72+ addrs=0x0000, mutex_ids=[0])
73- tile_scale = pl.make_tile_group(type=pl.TileType(shape=[64, 1], dtype=pl.DT_FP32, target_memory=pl.MemorySpace.Vec),73+ tile_scale = pl.make_tile_group(type=pl.TileType(shape=[64, 1], dtype=pl.DT_FP32, target_memory=pl.MemorySpace.Vec),
74- addrs=0x8000, mutex_ids=[1])74+ addrs=0x8000, mutex_ids=[1])
75- tile_out = pl.make_tile_group(type=pl.TileType(shape=[64, 128], dtype=pl.DT_INT8, target_memory=pl.MemorySpace.Vec),75+ tile_out = pl.make_tile_group(type=pl.TileType(shape=[64, 128], dtype=pl.DT_INT8, target_memory=pl.MemorySpace.Vec),
76- addrs=0xA000, mutex_ids=[2])76+ addrs=0xA000, mutex_ids=[2])
77- with pl.section_vector():77+ with pl.section_vector():
78- cur_src = tile_src.current()78+ cur_src = tile_src.current()
79- cur_scale = tile_scale.current()79+ cur_scale = tile_scale.current()
80- cur_out = tile_out.current()80+ cur_out = tile_out.current()
81- pl.load(cur_src, src, [0, 0])81+ pl.load(cur_src, src, [0, 0])
82- pl.load(cur_scale, scale, [0, 0])82+ pl.load(cur_scale, scale, [0, 0])
83- pl.quant(cur_out, cur_src, cur_scale, mode=pl.QuantMode.SYM)83+ pl.quant(cur_out, cur_src, cur_scale, mode=pl.QuantMode.SYM)
84- pl.store(out, cur_out, [0, 0])84+ pl.store(out, cur_out, [0, 0])
85-```85+```
@@ -3,13 +3,13 @@
3## 产品支持情况3## 产品支持情况
4 4 
5<!-- npu="950" id1 -->5<!-- npu="950" id1 -->
6-- Ascend 950PR/Ascend 950DT:支持6+- Ascend 950PR&950DT系列产品:支持
7<!-- end id1 -->7<!-- end id1 -->
8<!-- npu="A3" id2 -->8<!-- npu="A3" id2 -->
9-- Atlas A3 训练系列产品/Atlas A3 推理系列产品:不支持9+- Atlas A3系列产品:不支持
10<!-- end id2 -->10<!-- end id2 -->
11<!-- npu="910b" id3 -->11<!-- npu="910b" id3 -->
12-- Atlas A2 训练系列产品/Atlas A2 推理系列产品:不支持12+- Atlas A2系列产品:不支持
13<!-- end id3 -->13<!-- end id3 -->
14 14 
15## 功能说明15## 功能说明
@@ -20,7 +20,7 @@ $$dstReg0_i = srcReg_{2i}, \quad dstReg1_i = srcReg_{2i+1}$$
20 20 
21**图1** de_interleave解交织示意图21**图1** de_interleave解交织示意图
22 22 
23-![](../../../figures/de_interleave_data_layout.jpg)23+![](../../../figures/de_interleave_data_layout.jpg)
24 24 
25## 函数原型25## 函数原型
26 26 
@@ -154,7 +154,7 @@ if __name__ == "__main__":
154 test_example()154 test_example()
155 print("PASSED")155 print("PASSED")
156```156```
157- 157+ 
158### INT64数据类型示例158### INT64数据类型示例
159 159 
160以下示例先对两个INT64寄存器执行`vf.interleave`,再对结果执行`vf.de_interleave`恢复原始数据,验证往返一致性。160以下示例先对两个INT64寄存器执行`vf.interleave`,再对结果执行`vf.de_interleave`恢复原始数据,验证往返一致性。
@@ -208,4 +208,4 @@ def test_example_int64():
208if __name__ == "__main__":208if __name__ == "__main__":
209 test_example_int64()209 test_example_int64()
210 print("PASSED")210 print("PASSED")
211-```211+```
@@ -3,13 +3,13 @@
3## 产品支持情况3## 产品支持情况
4 4 
5<!-- npu="950" id1 -->5<!-- npu="950" id1 -->
6-- Ascend 950PR/Ascend 950DT:支持6+- Ascend 950PR&950DT系列产品:支持
7<!-- end id1 -->7<!-- end id1 -->
8<!-- npu="A3" id2 -->8<!-- npu="A3" id2 -->
9-- Atlas A3 训练系列产品/Atlas A3 推理系列产品:不支持9+- Atlas A3系列产品:不支持
10<!-- end id2 -->10<!-- end id2 -->
11<!-- npu="910b" id3 -->11<!-- npu="910b" id3 -->
12-- Atlas A2 训练系列产品/Atlas A2 推理系列产品:不支持12+- Atlas A2系列产品:不支持
13<!-- end id3 -->13<!-- end id3 -->
14 14 
15## 功能说明15## 功能说明
@@ -20,7 +20,7 @@ $$dstReg0_{2i} = srcReg0_i, \quad dstReg1_{2i+1} = srcReg1_i$$
20 20 
21**图1** interleave交织示意图21**图1** interleave交织示意图
22 22 
23-![](../../../figures/interleave_data_layout.jpg)23+![](../../../figures/interleave_data_layout.jpg)
24 24 
25## 函数原型25## 函数原型
26 26 
@@ -154,7 +154,7 @@ if __name__ == "__main__":
154 test_example()154 test_example()
155 print("PASSED")155 print("PASSED")
156```156```
157- 157+ 
158### INT64数据类型示例158### INT64数据类型示例
159 159 
160以下示例先对两个INT64寄存器执行`vf.interleave`,再对结果执行`vf.de_interleave`恢复原始数据,验证往返一致性。160以下示例先对两个INT64寄存器执行`vf.interleave`,再对结果执行`vf.de_interleave`恢复原始数据,验证往返一致性。
@@ -208,4 +208,4 @@ def test_example_int64():
208if __name__ == "__main__":208if __name__ == "__main__":
209 test_example_int64()209 test_example_int64()
210 print("PASSED")210 print("PASSED")
211-```211+```
@@ -3,13 +3,13 @@
3## 产品支持情况3## 产品支持情况
4 4 
5<!-- npu="950" id1 -->5<!-- npu="950" id1 -->
6-- Ascend 950PR/Ascend 950DT:支持6+- Ascend 950PR&950DT系列产品:支持
7<!-- end id1 -->7<!-- end id1 -->
8<!-- npu="A3" id2 -->8<!-- npu="A3" id2 -->
9-- Atlas A3 训练系列产品/Atlas A3 推理系列产品:不支持9+- Atlas A3系列产品:不支持
10<!-- end id2 -->10<!-- end id2 -->
11<!-- npu="910b" id3 -->11<!-- npu="910b" id3 -->
12-- Atlas A2 训练系列产品/Atlas A2 推理系列产品:不支持12+- Atlas A2系列产品:不支持
13<!-- end id3 -->13<!-- end id3 -->
14 14 
15## 功能说明15## 功能说明
@@ -20,13 +20,13 @@
20 20 
21**图1** reg_tensor输入pack示意图21**图1** reg_tensor输入pack示意图
22 22 
23-![reg_tensor输入pack示意图](../../../figures/pack_diagram.jpg)23+![reg_tensor输入pack示意图](../../../figures/pack_diagram.jpg)
24 24 
25**mask_reg输入**:将源操作数src中的偶数位,根据part选取的模式,提取到dst的低半部分或高半部分。示意图如下图所示:25**mask_reg输入**:将源操作数src中的偶数位,根据part选取的模式,提取到dst的低半部分或高半部分。示意图如下图所示:
26 26 
27**图2** mask_reg输入pack示意图27**图2** mask_reg输入pack示意图
28 28 
29-![mask_reg输入pack示意图](../../../figures/mask_pack_diagram.jpg)29+![mask_reg输入pack示意图](../../../figures/mask_pack_diagram.jpg)
30 30 
31## 函数原型31## 函数原型
32 32 
@@ -39,8 +39,8 @@ pack(src, part: Optional[PackPart] = None, dtype: Optional[DType] = None) -> dst
39| 参数 | 输入/输出 | 说明 |39| 参数 | 输入/输出 | 说明 |
40|---|---|---|40|---|---|---|
41| src | 输入 | 源操作数,[reg_tensor](../reg_tensor.md)或者[mask_reg](../mask_reg.md)类型。reg_tensor时数据类型为压缩前的宽类型,mask_reg时数据类型不变。 |41| src | 输入 | 源操作数,[reg_tensor](../reg_tensor.md)或者[mask_reg](../mask_reg.md)类型。reg_tensor时数据类型为压缩前的宽类型,mask_reg时数据类型不变。 |
42-| part | 输入 | 可选,用于控制写入dst的低半部分还是高半部分,对应[PackPart](../types/PackPart.md)类型。<br>- pypto_pro.language.PackPart.LOWER:低位模式,写入dst的低半部分。<br>- pypto_pro.language.PackPart.UPPER:高位模式,写入dst的高半部分。<br>默认pypto_pro.language.PackPart.LOWER。双寄存器模式只支持pypto_pro.language.PackPart.LOWER模式。 |42+| part | 输入 | 可选,用于控制写入dst的低半部分还是高半部分,对应[PackPart](../types/PackPart.md)类型。<br>- pypto_pro.language.PackPart.LOWER:低位模式,写入dst的低半部分。<br>- pypto_pro.language.PackPart.UPPER:高位模式,写入dst的高半部分。<br>默认pypto_pro.language.PackPart.LOWER。双寄存器模式只支持pypto_pro.language.PackPart.LOWER模式。 |
43-| dtype | 输入 | 可选,数据类型。<br>- reg_tensor模式必选,指定目标reg_tensor的数据类型(如pypto_pro.language.DT_UINT8、pypto_pro.language.DT_UINT16等)。需要必选的原因在于将宽类型压缩为窄类型(如DT_UINT16→DT_UINT8),目标reg_tensor的数据类型与源reg_tensor不同,无法从源操作数推断,因此必须通过dtype参数显式指定目标数据类型。<br>- mask_reg模式保持寄存器类型,可省略。 |43+| dtype | 输入 | 可选,数据类型。<br>- reg_tensor模式必选,指定目标reg_tensor的数据类型(如pypto_pro.language.DT_UINT8、pypto_pro.language.DT_UINT16等)。需要必选的原因在于将宽类型压缩为窄类型(如DT_UINT16→DT_UINT8),目标reg_tensor的数据类型与源reg_tensor不同,无法从源操作数推断,因此必须通过dtype参数显式指定目标数据类型。<br>- mask_reg模式保持寄存器类型,可省略。 |
44 44 
45## 约束说明45## 约束说明
46 46 
@@ -165,7 +165,7 @@ if __name__ == "__main__":
165 test_example()165 test_example()
166 print("PASSED")166 print("PASSED")
167```167```
168- 168+ 
169### INT64数据类型示例169### INT64数据类型示例
170 170 
171以下示例将INT64寄存器通过`vf.pack`压缩为UINT32(pack的目的数据类型须为无符号),再通过`vf.bit_cast`按位重解释为INT32,最后通过`vf.unpack`恢复为INT64,验证往返一致性。`vf.unpack`对INT32源执行符号扩展(高位填充符号位),正确还原原始INT64值。171以下示例将INT64寄存器通过`vf.pack`压缩为UINT32(pack的目的数据类型须为无符号),再通过`vf.bit_cast`按位重解释为INT32,最后通过`vf.unpack`恢复为INT64,验证往返一致性。`vf.unpack`对INT32源执行符号扩展(高位填充符号位),正确还原原始INT64值。
@@ -214,4 +214,4 @@ def test_example_int64():
214if __name__ == "__main__":214if __name__ == "__main__":
215 test_example_int64()215 test_example_int64()
216 print("PASSED")216 print("PASSED")
217-```217+```
@@ -3,13 +3,13 @@
3## 产品支持情况3## 产品支持情况
4 4 
5<!-- npu="950" id1 -->5<!-- npu="950" id1 -->
6-- Ascend 950PR/Ascend 950DT:支持6+- Ascend 950PR&950DT系列产品:支持
7<!-- end id1 -->7<!-- end id1 -->
8<!-- npu="A3" id2 -->8<!-- npu="A3" id2 -->
9-- Atlas A3 训练系列产品/Atlas A3 推理系列产品:不支持9+- Atlas A3系列产品:不支持
10<!-- end id2 -->10<!-- end id2 -->
11<!-- npu="910b" id3 -->11<!-- npu="910b" id3 -->
12-- Atlas A2 训练系列产品/Atlas A2 推理系列产品:不支持12+- Atlas A2系列产品:不支持
13<!-- end id3 -->13<!-- end id3 -->
14 14 
15## 功能说明15## 功能说明
@@ -20,13 +20,13 @@
20 20 
21**图1** reg_tensor输入unpack示意图21**图1** reg_tensor输入unpack示意图
22 22 
23-![reg_tensor输入unpack示意图](../../../figures/unpack_diagram.jpg)23+![reg_tensor输入unpack示意图](../../../figures/unpack_diagram.jpg)
24 24 
25**mask_reg输入**:根据part选取的模式,将源操作数src的低半部分或者高半部分,展开到目的操作数dst。示意图如下图所示:25**mask_reg输入**:根据part选取的模式,将源操作数src的低半部分或者高半部分,展开到目的操作数dst。示意图如下图所示:
26 26 
27**图2** mask_reg输入unpack示意图27**图2** mask_reg输入unpack示意图
28 28 
29-![mask_reg输入unpack示意图](../../../figures/mask_unpack_diagram.jpg)29+![mask_reg输入unpack示意图](../../../figures/mask_unpack_diagram.jpg)
30 30 
31## 函数原型31## 函数原型
32 32 
@@ -39,8 +39,8 @@ unpack(src, part: Optional[PackPart] = None, dtype: Optional[DType] = None) -> d
39| 参数 | 输入/输出 | 说明 |39| 参数 | 输入/输出 | 说明 |
40|---|---|---|40|---|---|---|
41| src | 输入 | 源操作数,[reg_tensor](../reg_tensor.md)或者[mask_reg](../mask_reg.md)类型,支持的数据类型请参见[约束说明](#约束说明)。reg_tensor时数据类型为展开前的窄类型,mask_reg时数据类型不变。 |41| src | 输入 | 源操作数,[reg_tensor](../reg_tensor.md)或者[mask_reg](../mask_reg.md)类型,支持的数据类型请参见[约束说明](#约束说明)。reg_tensor时数据类型为展开前的窄类型,mask_reg时数据类型不变。 |
42-| part | 输入 | 可选,用于控制读取src的低半部分还是高半部分,对应[PackPart](../types/PackPart.md)类型。<br>- pypto_pro.language.PackPart.LOWER:低位模式,读取src的低半部分。<br>- pypto_pro.language.PackPart.UPPER:高位模式,读取src的高半部分。<br>默认pypto_pro.language.PackPart.LOWER。双寄存器模式只支持pypto_pro.language.PackPart.LOWER模式。 |42+| part | 输入 | 可选,用于控制读取src的低半部分还是高半部分,对应[PackPart](../types/PackPart.md)类型。<br>- pypto_pro.language.PackPart.LOWER:低位模式,读取src的低半部分。<br>- pypto_pro.language.PackPart.UPPER:高位模式,读取src的高半部分。<br>默认pypto_pro.language.PackPart.LOWER。双寄存器模式只支持pypto_pro.language.PackPart.LOWER模式。 |
43-| dtype | 输入 | 可选,数据类型。<br>- reg_tensor模式必选,指定目标reg_tensor的数据类型(如pypto_pro.language.DT_UINT16、pypto_pro.language.DT_UINT32等)。需要必须的原因在于将窄类型展开为宽类型(如DT_UINT8→DT_UINT16),目标reg_tensor的数据类型与源reg_tensor不同,无法从源操作数推断,因此必须通过dtype参数显式指定目标数据类型。<br>- mask_reg模式保持寄存器类型,可省略。 |43+| dtype | 输入 | 可选,数据类型。<br>- reg_tensor模式必选,指定目标reg_tensor的数据类型(如pypto_pro.language.DT_UINT16、pypto_pro.language.DT_UINT32等)。需要必须的原因在于将窄类型展开为宽类型(如DT_UINT8→DT_UINT16),目标reg_tensor的数据类型与源reg_tensor不同,无法从源操作数推断,因此必须通过dtype参数显式指定目标数据类型。<br>- mask_reg模式保持寄存器类型,可省略。 |
44 44 
45## 约束说明45## 约束说明
46 46 
@@ -167,7 +167,7 @@ if __name__ == "__main__":
167 test_example()167 test_example()
168 print("PASSED")168 print("PASSED")
169```169```
170- 170+ 
171### INT64数据类型示例171### INT64数据类型示例
172 172 
173以下示例先通过`vf.pack`将INT64压缩为UINT32(pack的目的数据类型须为无符号),再通过`vf.bit_cast`按位重解释为INT32,最后通过`vf.unpack`恢复为INT64,验证往返一致性。`vf.unpack`对INT32源执行符号扩展(高位填充符号位),正确还原原始INT64值。173以下示例先通过`vf.pack`将INT64压缩为UINT32(pack的目的数据类型须为无符号),再通过`vf.bit_cast`按位重解释为INT32,最后通过`vf.unpack`恢复为INT64,验证往返一致性。`vf.unpack`对INT32源执行符号扩展(高位填充符号位),正确还原原始INT64值。
@@ -216,4 +216,4 @@ def test_example_int64():
216if __name__ == "__main__":216if __name__ == "__main__":
217 test_example_int64()217 test_example_int64()
218 print("PASSED")218 print("PASSED")
219-```219+```
@@ -3,13 +3,13 @@
3## 产品支持情况3## 产品支持情况
4 4 
5<!-- npu="950" id1 -->5<!-- npu="950" id1 -->
6-- Ascend 950PR/Ascend 950DT:支持6+- Ascend 950PR&950DT系列产品:支持
7<!-- end id1 -->7<!-- end id1 -->
8<!-- npu="A3" id2 -->8<!-- npu="A3" id2 -->
9-- Atlas A3 训练系列产品/Atlas A3 推理系列产品:不支持9+- Atlas A3系列产品:不支持
10<!-- end id2 -->10<!-- end id2 -->
11<!-- npu="910b" id3 -->11<!-- npu="910b" id3 -->
12-- Atlas A2 训练系列产品/Atlas A2 推理系列产品:不支持12+- Atlas A2系列产品:不支持
13<!-- end id3 -->13<!-- end id3 -->
14 14 
15## 功能说明15## 功能说明
@@ -40,7 +40,7 @@ unsqueeze(preg) -> dst
40 40 
41## 约束说明41## 约束说明
42 42 
43-无。43+无。
44 44 
45## 返回值说明45## 返回值说明
46 46 
@@ -3,13 +3,13 @@
3## 产品支持情况3## 产品支持情况
4 4 
5<!-- npu="950" id1 -->5<!-- npu="950" id1 -->
6-- Ascend 950PR/Ascend 950DT:支持6+- Ascend 950PR&950DT系列产品:支持
7<!-- end id1 -->7<!-- end id1 -->
8<!-- npu="A3" id2 -->8<!-- npu="A3" id2 -->
9-- Atlas A3 训练系列产品/Atlas A3 推理系列产品:不支持9+- Atlas A3系列产品:不支持
10<!-- end id2 -->10<!-- end id2 -->
11<!-- npu="910b" id3 -->11<!-- npu="910b" id3 -->
12-- Atlas A2 训练系列产品/Atlas A2 推理系列产品:不支持12+- Atlas A2系列产品:不支持
13<!-- end id3 -->13<!-- end id3 -->
14 14 
15## 功能说明15## 功能说明
@@ -42,7 +42,7 @@ abs(src, preg, mode: Optional[MergeMode] = None) -> dst
42|---|---|---|42|---|---|---|
43| src | 输入 | 源操作数,[reg_tensor](../reg_tensor.md)。源操作数src与目的操作数dst的数据类型保持一致。支持的数据类型为:DT_INT8、DT_INT16、DT_INT32、DT_FP16、DT_FP32、DT_INT64。其中DT_FP16和DT_FP32支持双寄存器模式,用于复数取模运算。 |43| src | 输入 | 源操作数,[reg_tensor](../reg_tensor.md)。源操作数src与目的操作数dst的数据类型保持一致。支持的数据类型为:DT_INT8、DT_INT16、DT_INT32、DT_FP16、DT_FP32、DT_INT64。其中DT_FP16和DT_FP32支持双寄存器模式,用于复数取模运算。 |
44| preg | 输入 | [mask_reg](../mask_reg.md)。 |44| preg | 输入 | [mask_reg](../mask_reg.md)。 |
45-| mode | 输入 | 可选,对应[MergeMode](../types/MergeMode.md)类型。<br>- pypto_pro.language.MergeMode.ZEROING(默认),preg未筛选的元素在dst中置0。<br>- pypto_pro.language.MergeMode.MERGING当前不支持。 |45+| mode | 输入 | 可选,对应[MergeMode](../types/MergeMode.md)类型。<br>- pypto_pro.language.MergeMode.ZEROING(默认),preg未筛选的元素在dst中置0。<br>- pypto_pro.language.MergeMode.MERGING当前不支持。 |
46 46 
47## 约束说明47## 约束说明
48 48 
@@ -99,49 +99,49 @@ if __name__ == "__main__":
99 test_example()99 test_example()
100 print("PASSED")100 print("PASSED")
101```101```
102- 102+ 
103-### INT64数据类型示例103+### INT64数据类型示例
104- 104+ 
105-```python105+```python
106-import os106+import os
107-import pypto_pro.language as pl107+import pypto_pro.language as pl
108-import torch108+import torch
109-import torch_npu109+import torch_npu
110- 110+ 
111-@pl.vector_function111+@pl.vector_function
112-def example_vf_int64(src_tile, dst_tile):112+def example_vf_int64(src_tile, dst_tile):
113- preg = vf.create_mask(pattern=pl.MaskPattern.ALL, dtype=pl.DT_INT64)113+ preg = vf.create_mask(pattern=pl.MaskPattern.ALL, dtype=pl.DT_INT64)
114- reg_a = vf.load_align(src_tile, 0)114+ reg_a = vf.load_align(src_tile, 0)
115- reg_out = vf.abs(reg_a, preg)115+ reg_out = vf.abs(reg_a, preg)
116- vf.store_align(dst_tile, reg_out, preg)116+ vf.store_align(dst_tile, reg_out, preg)
117- 117+ 
118-@pl.jit()118+@pl.jit()
119-def example_kernel_int64(119+def example_kernel_int64(
120- a: pl.Tensor[[pl.DYNAMIC, pl.DYNAMIC], pl.DT_INT64],120+ a: pl.Tensor[[pl.DYNAMIC, pl.DYNAMIC], pl.DT_INT64],
121- out: pl.Tensor[[pl.DYNAMIC, pl.DYNAMIC], pl.DT_INT64],121+ out: pl.Tensor[[pl.DYNAMIC, pl.DYNAMIC], pl.DT_INT64],
122-):122+):
123- tf = pl.TileType(shape=[1, 32], dtype=pl.DT_INT64, target_memory=pl.MemorySpace.Vec)123+ tf = pl.TileType(shape=[1, 32], dtype=pl.DT_INT64, target_memory=pl.MemorySpace.Vec)
124 in_a_grp = pl.make_tile_group(type=tf, addrs=0, mutex_ids=[0])124 in_a_grp = pl.make_tile_group(type=tf, addrs=0, mutex_ids=[0])
125 in_a = in_a_grp.current()125 in_a = in_a_grp.current()
126 t_out_grp = pl.make_tile_group(type=tf, addrs=256, mutex_ids=[1])126 t_out_grp = pl.make_tile_group(type=tf, addrs=256, mutex_ids=[1])
127 t_out = t_out_grp.current()127 t_out = t_out_grp.current()
128- with pl.section_vector():128+ with pl.section_vector():
129- pl.load(in_a, a, [0, 0])129+ pl.load(in_a, a, [0, 0])
130- example_vf_int64(in_a, t_out)130+ example_vf_int64(in_a, t_out)
131- pl.store(out, t_out, [0, 0])131+ pl.store(out, t_out, [0, 0])
132- 132+ 
133-def test_example_int64():133+def test_example_int64():
134- device_id = int(os.environ.get("TILE_FWK_DEVICE_ID", 0))134+ device_id = int(os.environ.get("TILE_FWK_DEVICE_ID", 0))
135- device = f"npu:{device_id}"135+ device = f"npu:{device_id}"
136- core_nums = 1136+ core_nums = 1
137- torch.npu.set_device(device)137+ torch.npu.set_device(device)
138- a = torch.randint(-100, 100, [1, 32], device=device, dtype=torch.int64)138+ a = torch.randint(-100, 100, [1, 32], device=device, dtype=torch.int64)
139- out = torch.empty([1, 32], device=device, dtype=torch.int64)139+ out = torch.empty([1, 32], device=device, dtype=torch.int64)
140- example_kernel_int64[None, core_nums](a, out)140+ example_kernel_int64[None, core_nums](a, out)
141- torch.npu.synchronize()141+ torch.npu.synchronize()
142- torch.testing.assert_close(out, torch.abs(a), rtol=0, atol=0)142+ torch.testing.assert_close(out, torch.abs(a), rtol=0, atol=0)
143- 143+ 
144-if __name__ == "__main__":144+if __name__ == "__main__":
145- test_example_int64()145+ test_example_int64()
146- print("PASSED")146+ print("PASSED")
147```147```
@@ -3,13 +3,13 @@
3## 产品支持情况3## 产品支持情况
4 4 
5<!-- npu="950" id1 -->5<!-- npu="950" id1 -->
6-- Ascend 950PR/Ascend 950DT:支持6+- Ascend 950PR&950DT系列产品:支持
7<!-- end id1 -->7<!-- end id1 -->
8<!-- npu="A3" id2 -->8<!-- npu="A3" id2 -->
9-- Atlas A3 训练系列产品/Atlas A3 推理系列产品:不支持9+- Atlas A3系列产品:不支持
10<!-- end id2 -->10<!-- end id2 -->
11<!-- npu="910b" id3 -->11<!-- npu="910b" id3 -->
12-- Atlas A2 训练系列产品/Atlas A2 推理系列产品:不支持12+- Atlas A2系列产品:不支持
13<!-- end id3 -->13<!-- end id3 -->
14 14 
15## 功能说明15## 功能说明
@@ -22,7 +22,7 @@ $$dst_i = src0_i + src1_i$$
22 22 
23**图1** vf.add功能说明23**图1** vf.add功能说明
24 24 
25-![](../../../figures/add_with_carry.jpg)25+![](../../../figures/add_with_carry.jpg)
26 26 
27若需要获取加法进位输出,请参考[vf.addc](addc.md#功能说明)。27若需要获取加法进位输出,请参考[vf.addc](addc.md#功能说明)。
28 28 
@@ -39,11 +39,11 @@ add(src0, src1, preg, mode: Optional[MergeMode] = None) -> dst
39| src0 | 输入 | 源操作数0,[reg_tensor](../reg_tensor.md),源操作数src0、src1和目的操作数dst的数据类型保持一致。支持的数据类型为:DT_INT8、DT_UINT8、DT_INT16、DT_UINT16、DT_INT32、DT_UINT32、DT_FP16、DT_BF16、DT_FP32、DT_INT64、DT_UINT64。 |39| src0 | 输入 | 源操作数0,[reg_tensor](../reg_tensor.md),源操作数src0、src1和目的操作数dst的数据类型保持一致。支持的数据类型为:DT_INT8、DT_UINT8、DT_INT16、DT_UINT16、DT_INT32、DT_UINT32、DT_FP16、DT_BF16、DT_FP32、DT_INT64、DT_UINT64。 |
40| src1 | 输入 | 源操作数1,[reg_tensor](../reg_tensor.md),支持的数据类型和src0中的说明一致。 |40| src1 | 输入 | 源操作数1,[reg_tensor](../reg_tensor.md),支持的数据类型和src0中的说明一致。 |
41| preg | 输入 | [mask_reg](../mask_reg.md)。 |41| preg | 输入 | [mask_reg](../mask_reg.md)。 |
42-| mode | 输入 | 可选,对应[MergeMode](../types/MergeMode.md)类型。<br>- pypto_pro.language.MergeMode.ZEROING(默认),preg未筛选的元素在dst中置0。<br>- pypto_pro.language.MergeMode.MERGING当前不支持。 |42+| mode | 输入 | 可选,对应[MergeMode](../types/MergeMode.md)类型。<br>- pypto_pro.language.MergeMode.ZEROING(默认),preg未筛选的元素在dst中置0。<br>- pypto_pro.language.MergeMode.MERGING当前不支持。 |
43 43 
44## 约束说明44## 约束说明
45 45 
46-无。46+无。
47 47 
48## 返回值说明48## 返回值说明
49 49 
@@ -3,13 +3,13 @@
3## 产品支持情况3## 产品支持情况
4 4 
5<!-- npu="950" id1 -->5<!-- npu="950" id1 -->
6-- Ascend 950PR/Ascend 950DT:支持6+- Ascend 950PR&950DT系列产品:支持
7<!-- end id1 -->7<!-- end id1 -->
8<!-- npu="A3" id2 -->8<!-- npu="A3" id2 -->
9-- Atlas A3 训练系列产品/Atlas A3 推理系列产品:不支持9+- Atlas A3系列产品:不支持
10<!-- end id2 -->10<!-- end id2 -->
11<!-- npu="910b" id3 -->11<!-- npu="910b" id3 -->
12-- Atlas A2 训练系列产品/Atlas A2 推理系列产品:不支持12+- Atlas A2系列产品:不支持
13<!-- end id3 -->13<!-- end id3 -->
14 14 
15## 功能说明15## 功能说明
@@ -24,7 +24,7 @@ Carry flag(进位标志)用于表示加法进位,若src0、src1、carry_sr
24 24 
25**图1** vf.addc适用场景25**图1** vf.addc适用场景
26 26 
27-![](../../../figures/addc_scenario.jpg)27+![](../../../figures/addc_scenario.jpg)
28 28 
29## 函数原型29## 函数原型
30 30 
@@ -43,7 +43,7 @@ addc(src0, src1, carry_src, preg) -> (carry, dst)
43 43 
44## 约束说明44## 约束说明
45 45 
46-无。46+无。
47 47 
48## 返回值说明48## 返回值说明
49 49 
@@ -105,4 +105,4 @@ def test_example():
105if __name__ == "__main__":105if __name__ == "__main__":
106 test_example()106 test_example()
107 print("PASSED")107 print("PASSED")
108-```108+```
@@ -3,13 +3,13 @@
3## 产品支持情况3## 产品支持情况
4 4 
5<!-- npu="950" id1 -->5<!-- npu="950" id1 -->
6-- Ascend 950PR/Ascend 950DT:支持6+- Ascend 950PR&950DT系列产品:支持
7<!-- end id1 -->7<!-- end id1 -->
8<!-- npu="A3" id2 -->8<!-- npu="A3" id2 -->
9-- Atlas A3 训练系列产品/Atlas A3 推理系列产品:不支持9+- Atlas A3系列产品:不支持
10<!-- end id2 -->10<!-- end id2 -->
11<!-- npu="910b" id3 -->11<!-- npu="910b" id3 -->
12-- Atlas A2 训练系列产品/Atlas A2 推理系列产品:不支持12+- Atlas A2系列产品:不支持
13<!-- end id3 -->13<!-- end id3 -->
14 14 
15## 功能说明15## 功能说明
@@ -31,11 +31,11 @@ adds(src, scalar, preg, mode: Optional[MergeMode] = None) -> dst
31| src | 输入 | 源操作数,[reg_tensor](../reg_tensor.md),源操作数src与目的操作数dst的数据类型保持一致。支持的数据类型为:DT_INT8、DT_UINT8、DT_INT16、DT_UINT16、DT_FP16、DT_BF16、DT_INT32、DT_UINT32、DT_FP32、DT_INT64、DT_UINT64。 |31| src | 输入 | 源操作数,[reg_tensor](../reg_tensor.md),源操作数src与目的操作数dst的数据类型保持一致。支持的数据类型为:DT_INT8、DT_UINT8、DT_INT16、DT_UINT16、DT_FP16、DT_BF16、DT_INT32、DT_UINT32、DT_FP32、DT_INT64、DT_UINT64。 |
32| scalar | 输入 | 标量源操作数。 |32| scalar | 输入 | 标量源操作数。 |
33| preg | 输入 | [mask_reg](../mask_reg.md)。 |33| preg | 输入 | [mask_reg](../mask_reg.md)。 |
34-| mode | 输入 | 可选,对应[MergeMode](../types/MergeMode.md)类型。<br>- pypto_pro.language.MergeMode.ZEROING(默认),preg未筛选的元素在dst中置0。<br>- pypto_pro.language.MergeMode.MERGING当前不支持。 |34+| mode | 输入 | 可选,对应[MergeMode](../types/MergeMode.md)类型。<br>- pypto_pro.language.MergeMode.ZEROING(默认),preg未筛选的元素在dst中置0。<br>- pypto_pro.language.MergeMode.MERGING当前不支持。 |
35 35 
36## 约束说明36## 约束说明
37 37 
38-无。38+无。
39 39 
40## 返回值说明40## 返回值说明
41 41 
@@ -88,49 +88,49 @@ if __name__ == "__main__":
88 test_example()88 test_example()
89 print("PASSED")89 print("PASSED")
90```90```
91- 91+ 
92-### INT64数据类型示例92+### INT64数据类型示例
93- 93+ 
94-```python94+```python
95-import os95+import os
96-import pypto_pro.language as pl96+import pypto_pro.language as pl
97-import torch97+import torch
98-import torch_npu98+import torch_npu
99- 99+ 
100-@pl.vector_function100+@pl.vector_function
101-def example_vf_int64(src_tile, dst_tile):101+def example_vf_int64(src_tile, dst_tile):
102- preg = vf.create_mask(pattern=pl.MaskPattern.ALL, dtype=pl.DT_INT64)102+ preg = vf.create_mask(pattern=pl.MaskPattern.ALL, dtype=pl.DT_INT64)
103- reg_a = vf.load_align(src_tile, 0)103+ reg_a = vf.load_align(src_tile, 0)
104- reg_out = vf.adds(reg_a, 3, preg)104+ reg_out = vf.adds(reg_a, 3, preg)
105- vf.store_align(dst_tile, reg_out, preg)105+ vf.store_align(dst_tile, reg_out, preg)
106- 106+ 
107-@pl.jit()107+@pl.jit()
108-def example_kernel_int64(108+def example_kernel_int64(
109- a: pl.Tensor[[pl.DYNAMIC, pl.DYNAMIC], pl.DT_INT64],109+ a: pl.Tensor[[pl.DYNAMIC, pl.DYNAMIC], pl.DT_INT64],
110- out: pl.Tensor[[pl.DYNAMIC, pl.DYNAMIC], pl.DT_INT64],110+ out: pl.Tensor[[pl.DYNAMIC, pl.DYNAMIC], pl.DT_INT64],
111-):111+):
112- tf = pl.TileType(shape=[1, 32], dtype=pl.DT_INT64, target_memory=pl.MemorySpace.Vec)112+ tf = pl.TileType(shape=[1, 32], dtype=pl.DT_INT64, target_memory=pl.MemorySpace.Vec)
113 in_a_grp = pl.make_tile_group(type=tf, addrs=0, mutex_ids=[0])113 in_a_grp = pl.make_tile_group(type=tf, addrs=0, mutex_ids=[0])
114 in_a = in_a_grp.current()114 in_a = in_a_grp.current()
115 t_out_grp = pl.make_tile_group(type=tf, addrs=256, mutex_ids=[1])115 t_out_grp = pl.make_tile_group(type=tf, addrs=256, mutex_ids=[1])
116 t_out = t_out_grp.current()116 t_out = t_out_grp.current()
117- with pl.section_vector():117+ with pl.section_vector():
118- pl.load(in_a, a, [0, 0])118+ pl.load(in_a, a, [0, 0])
119- example_vf_int64(in_a, t_out)119+ example_vf_int64(in_a, t_out)
120- pl.store(out, t_out, [0, 0])120+ pl.store(out, t_out, [0, 0])
121- 121+ 
122-def test_example_int64():122+def test_example_int64():
123- device_id = int(os.environ.get("TILE_FWK_DEVICE_ID", 0))123+ device_id = int(os.environ.get("TILE_FWK_DEVICE_ID", 0))
124- device = f"npu:{device_id}"124+ device = f"npu:{device_id}"
125- core_nums = 1125+ core_nums = 1
126- torch.npu.set_device(device)126+ torch.npu.set_device(device)
127- a = torch.randint(-100, 100, [1, 32], device=device, dtype=torch.int64)127+ a = torch.randint(-100, 100, [1, 32], device=device, dtype=torch.int64)
128- out = torch.empty([1, 32], device=device, dtype=torch.int64)128+ out = torch.empty([1, 32], device=device, dtype=torch.int64)
129- example_kernel_int64[None, core_nums](a, out)129+ example_kernel_int64[None, core_nums](a, out)
130- torch.npu.synchronize()130+ torch.npu.synchronize()
131- torch.testing.assert_close(out, a + 3, rtol=0, atol=0)131+ torch.testing.assert_close(out, a + 3, rtol=0, atol=0)
132- 132+ 
133-if __name__ == "__main__":133+if __name__ == "__main__":
134- test_example_int64()134+ test_example_int64()
135- print("PASSED")135+ print("PASSED")
136```136```
@@ -3,13 +3,13 @@
3## 产品支持情况3## 产品支持情况
4 4 
5<!-- npu="950" id1 -->5<!-- npu="950" id1 -->
6-- Ascend 950PR/Ascend 950DT:支持6+- Ascend 950PR&950DT系列产品:支持
7<!-- end id1 -->7<!-- end id1 -->
8<!-- npu="A3" id2 -->8<!-- npu="A3" id2 -->
9-- Atlas A3 训练系列产品/Atlas A3 推理系列产品:不支持9+- Atlas A3系列产品:不支持
10<!-- end id2 -->10<!-- end id2 -->
11<!-- npu="910b" id3 -->11<!-- npu="910b" id3 -->
12-- Atlas A2 训练系列产品/Atlas A2 推理系列产品:不支持12+- Atlas A2系列产品:不支持
13<!-- end id3 -->13<!-- end id3 -->
14 14 
15## 功能说明15## 功能说明
@@ -31,12 +31,12 @@ div(src0, src1, preg, mode: Optional[MergeMode] = None, precision: Optional[bool
31| src0 | 输入 | 源操作数0,[reg_tensor](../reg_tensor.md),源操作数src0、src1与目的操作数dst的数据类型保持一致。支持的数据类型为:DT_INT16、DT_UINT16、DT_INT32、DT_UINT32、DT_FP16、DT_FP32、DT_INT64、DT_UINT64。 |31| src0 | 输入 | 源操作数0,[reg_tensor](../reg_tensor.md),源操作数src0、src1与目的操作数dst的数据类型保持一致。支持的数据类型为:DT_INT16、DT_UINT16、DT_INT32、DT_UINT32、DT_FP16、DT_FP32、DT_INT64、DT_UINT64。 |
32| src1 | 输入 | 源操作数1,[reg_tensor](../reg_tensor.md),支持的数据类型和src0中的说明一致。 |32| src1 | 输入 | 源操作数1,[reg_tensor](../reg_tensor.md),支持的数据类型和src0中的说明一致。 |
33| preg | 输入 | [mask_reg](../mask_reg.md)。 |33| preg | 输入 | [mask_reg](../mask_reg.md)。 |
34-| mode | 输入 | 可选,对应[MergeMode](../types/MergeMode.md)类型。<br>- pypto_pro.language.MergeMode.ZEROING(默认),preg未筛选的元素在dst中置0。<br>- pypto_pro.language.MergeMode.MERGING当前不支持。 |34+| mode | 输入 | 可选,对应[MergeMode](../types/MergeMode.md)类型。<br>- pypto_pro.language.MergeMode.ZEROING(默认),preg未筛选的元素在dst中置0。<br>- pypto_pro.language.MergeMode.MERGING当前不支持。 |
35| precision | 输入 | 可选,高精度模式开关。True启用高精度模式;False(默认)为标准模式。 |35| precision | 输入 | 可选,高精度模式开关。True启用高精度模式;False(默认)为标准模式。 |
36 36 
37## 约束说明37## 约束说明
38 38 
39-无。39+无。
40 40 
41## 返回值说明41## 返回值说明
42 42 
@@ -3,13 +3,13 @@
3## 产品支持情况3## 产品支持情况
4 4 
5<!-- npu="950" id1 -->5<!-- npu="950" id1 -->
6-- Ascend 950PR/Ascend 950DT:支持6+- Ascend 950PR&950DT系列产品:支持
7<!-- end id1 -->7<!-- end id1 -->
8<!-- npu="A3" id2 -->8<!-- npu="A3" id2 -->
9-- Atlas A3 训练系列产品/Atlas A3 推理系列产品:不支持9+- Atlas A3系列产品:不支持
10<!-- end id2 -->10<!-- end id2 -->
11<!-- npu="910b" id3 -->11<!-- npu="910b" id3 -->
12-- Atlas A2 训练系列产品/Atlas A2 推理系列产品:不支持12+- Atlas A2系列产品:不支持
13<!-- end id3 -->13<!-- end id3 -->
14 14 
15## 功能说明15## 功能说明
@@ -30,12 +30,12 @@ exp(src, preg, mode: Optional[MergeMode] = None, precision: Optional[bool] = Non
30|---|---|---|30|---|---|---|
31| src | 输入 | 源操作数,[reg_tensor](../reg_tensor.md),源操作数src与目的操作数dst的数据类型保持一致。支持的数据类型为:DT_FP16、DT_FP32。 |31| src | 输入 | 源操作数,[reg_tensor](../reg_tensor.md),源操作数src与目的操作数dst的数据类型保持一致。支持的数据类型为:DT_FP16、DT_FP32。 |
32| preg | 输入 | [mask_reg](../mask_reg.md)。 |32| preg | 输入 | [mask_reg](../mask_reg.md)。 |
33-| mode | 输入 | 可选,对应[MergeMode](../types/MergeMode.md)类型。<br>- pypto_pro.language.MergeMode.ZEROING(默认),preg未筛选的元素在dst中置0。<br>- pypto_pro.language.MergeMode.MERGING当前不支持。 |33+| mode | 输入 | 可选,对应[MergeMode](../types/MergeMode.md)类型。<br>- pypto_pro.language.MergeMode.ZEROING(默认),preg未筛选的元素在dst中置0。<br>- pypto_pro.language.MergeMode.MERGING当前不支持。 |
34| precision | 输入 | 可选,高精度模式开关。True启用高精度模式;False(默认)为标准模式。 |34| precision | 输入 | 可选,高精度模式开关。True启用高精度模式;False(默认)为标准模式。 |
35 35 
36## 约束说明36## 约束说明
37 37 
38-无。38+无。
39 39 
40## 返回值说明40## 返回值说明
41 41 
@@ -3,13 +3,13 @@
3## 产品支持情况3## 产品支持情况
4 4 
5<!-- npu="950" id1 -->5<!-- npu="950" id1 -->
6-- Ascend 950PR/Ascend 950DT:支持6+- Ascend 950PR&950DT系列产品:支持
7<!-- end id1 -->7<!-- end id1 -->
8<!-- npu="A3" id2 -->8<!-- npu="A3" id2 -->
9-- Atlas A3 训练系列产品/Atlas A3 推理系列产品:不支持9+- Atlas A3系列产品:不支持
10<!-- end id2 -->10<!-- end id2 -->
11<!-- npu="910b" id3 -->11<!-- npu="910b" id3 -->
12-- Atlas A2 训练系列产品/Atlas A2 推理系列产品:不支持12+- Atlas A2系列产品:不支持
13<!-- end id3 -->13<!-- end id3 -->
14 14 
15## 功能说明15## 功能说明
@@ -31,11 +31,11 @@ leaky_relu(src, scalar, preg, mode: Optional[MergeMode] = None) -> dst
31| src | 输入 | 源操作数,[reg_tensor](../reg_tensor.md),源操作数src与目的操作数dst的数据类型保持一致。支持的数据类型为:DT_FP16、DT_FP32。 |31| src | 输入 | 源操作数,[reg_tensor](../reg_tensor.md),源操作数src与目的操作数dst的数据类型保持一致。支持的数据类型为:DT_FP16、DT_FP32。 |
32| scalar | 输入 | 标量源操作数,scalar。 |32| scalar | 输入 | 标量源操作数,scalar。 |
33| preg | 输入 | [mask_reg](../mask_reg.md)。 |33| preg | 输入 | [mask_reg](../mask_reg.md)。 |
34-| mode | 输入 | 可选,对应[MergeMode](../types/MergeMode.md)类型。<br>- pypto_pro.language.MergeMode.ZEROING(默认),preg未筛选的元素在dst中置0。<br>- pypto_pro.language.MergeMode.MERGING当前不支持。 |34+| mode | 输入 | 可选,对应[MergeMode](../types/MergeMode.md)类型。<br>- pypto_pro.language.MergeMode.ZEROING(默认),preg未筛选的元素在dst中置0。<br>- pypto_pro.language.MergeMode.MERGING当前不支持。 |
35 35 
36## 约束说明36## 约束说明
37 37 
38-无。38+无。
39 39 
40## 返回值说明40## 返回值说明
41 41 
@@ -3,13 +3,13 @@
3## 产品支持情况3## 产品支持情况
4 4 
5<!-- npu="950" id1 -->5<!-- npu="950" id1 -->
6-- Ascend 950PR/Ascend 950DT:支持6+- Ascend 950PR&950DT系列产品:支持
7<!-- end id1 -->7<!-- end id1 -->
8<!-- npu="A3" id2 -->8<!-- npu="A3" id2 -->
9-- Atlas A3 训练系列产品/Atlas A3 推理系列产品:不支持9+- Atlas A3系列产品:不支持
10<!-- end id2 -->10<!-- end id2 -->
11<!-- npu="910b" id3 -->11<!-- npu="910b" id3 -->
12-- Atlas A2 训练系列产品/Atlas A2 推理系列产品:不支持12+- Atlas A2系列产品:不支持
13<!-- end id3 -->13<!-- end id3 -->
14 14 
15## 功能说明15## 功能说明
@@ -30,12 +30,12 @@ ln(src, preg, mode: Optional[MergeMode] = None, precision: Optional[bool] = None
30|---|---|---|30|---|---|---|
31| src | 输入 | 源操作数,[reg_tensor](../reg_tensor.md),必须为正数,源操作数src与目的操作数dst的数据类型保持一致。支持的数据类型为:DT_FP16、DT_FP32。 |31| src | 输入 | 源操作数,[reg_tensor](../reg_tensor.md),必须为正数,源操作数src与目的操作数dst的数据类型保持一致。支持的数据类型为:DT_FP16、DT_FP32。 |
32| preg | 输入 | [mask_reg](../mask_reg.md)。 |32| preg | 输入 | [mask_reg](../mask_reg.md)。 |
33-| mode | 输入 | 可选,对应[MergeMode](../types/MergeMode.md)类型。<br>- pypto_pro.language.MergeMode.ZEROING(默认),preg未筛选的元素在dst中置0。<br>- pypto_pro.language.MergeMode.MERGING当前不支持。 |33+| mode | 输入 | 可选,对应[MergeMode](../types/MergeMode.md)类型。<br>- pypto_pro.language.MergeMode.ZEROING(默认),preg未筛选的元素在dst中置0。<br>- pypto_pro.language.MergeMode.MERGING当前不支持。 |
34| precision | 输入 | 可选,高精度模式开关。True启用高精度模式;False(默认)为标准模式。 |34| precision | 输入 | 可选,高精度模式开关。True启用高精度模式;False(默认)为标准模式。 |
35 35 
36## 约束说明36## 约束说明
37 37 
38-无。38+无。
39 39 
40## 返回值说明40## 返回值说明
41 41 
@@ -3,13 +3,13 @@
3## 产品支持情况3## 产品支持情况
4 4 
5<!-- npu="950" id1 -->5<!-- npu="950" id1 -->
6-- Ascend 950PR/Ascend 950DT:支持6+- Ascend 950PR&950DT系列产品:支持
7<!-- end id1 -->7<!-- end id1 -->
8<!-- npu="A3" id2 -->8<!-- npu="A3" id2 -->
9-- Atlas A3 训练系列产品/Atlas A3 推理系列产品:不支持9+- Atlas A3系列产品:不支持
10<!-- end id2 -->10<!-- end id2 -->
11<!-- npu="910b" id3 -->11<!-- npu="910b" id3 -->
12-- Atlas A2 训练系列产品/Atlas A2 推理系列产品:不支持12+- Atlas A2系列产品:不支持
13<!-- end id3 -->13<!-- end id3 -->
14 14 
15## 功能说明15## 功能说明
@@ -30,12 +30,12 @@ log(src, preg, mode: Optional[MergeMode] = None, precision: Optional[bool] = Non
30|---|---|---|30|---|---|---|
31| src | 输入 | 源操作数,[reg_tensor](../reg_tensor.md),必须为正数,源操作数src与目的操作数dst的数据类型保持一致。支持的数据类型为:DT_FP16、DT_FP32。 |31| src | 输入 | 源操作数,[reg_tensor](../reg_tensor.md),必须为正数,源操作数src与目的操作数dst的数据类型保持一致。支持的数据类型为:DT_FP16、DT_FP32。 |
32| preg | 输入 | [mask_reg](../mask_reg.md)。 |32| preg | 输入 | [mask_reg](../mask_reg.md)。 |
33-| mode | 输入 | 可选,对应[MergeMode](../types/MergeMode.md)类型。<br>- pypto_pro.language.MergeMode.ZEROING(默认),preg未筛选的元素在dst中置0。<br>- pypto_pro.language.MergeMode.MERGING当前不支持。 |33+| mode | 输入 | 可选,对应[MergeMode](../types/MergeMode.md)类型。<br>- pypto_pro.language.MergeMode.ZEROING(默认),preg未筛选的元素在dst中置0。<br>- pypto_pro.language.MergeMode.MERGING当前不支持。 |
34| precision | 输入 | 可选,高精度模式开关。True启用高精度模式;False(默认)为标准模式。 |34| precision | 输入 | 可选,高精度模式开关。True启用高精度模式;False(默认)为标准模式。 |
35 35 
36## 约束说明36## 约束说明
37 37 
38-无。38+无。
39 39 
40## 返回值说明40## 返回值说明
41 41 
@@ -3,13 +3,13 @@
3## 产品支持情况3## 产品支持情况
4 4 
5<!-- npu="950" id1 -->5<!-- npu="950" id1 -->
6-- Ascend 950PR/Ascend 950DT:支持6+- Ascend 950PR&950DT系列产品:支持
7<!-- end id1 -->7<!-- end id1 -->
8<!-- npu="A3" id2 -->8<!-- npu="A3" id2 -->
9-- Atlas A3 训练系列产品/Atlas A3 推理系列产品:不支持9+- Atlas A3系列产品:不支持
10<!-- end id2 -->10<!-- end id2 -->
11<!-- npu="910b" id3 -->11<!-- npu="910b" id3 -->
12-- Atlas A2 训练系列产品/Atlas A2 推理系列产品:不支持12+- Atlas A2系列产品:不支持
13<!-- end id3 -->13<!-- end id3 -->
14 14 
15## 功能说明15## 功能说明
@@ -32,12 +32,12 @@ log10(src, preg, mode: Optional[MergeMode] = None, precision: Optional[bool] = N
32|---|---|---|32|---|---|---|
33| src | 输入 | 源操作数,[reg_tensor](../reg_tensor.md),必须为正数,源操作数src与目的操作数dst的数据类型保持一致。支持的数据类型为:DT_FP16、DT_FP32。 |33| src | 输入 | 源操作数,[reg_tensor](../reg_tensor.md),必须为正数,源操作数src与目的操作数dst的数据类型保持一致。支持的数据类型为:DT_FP16、DT_FP32。 |
34| preg | 输入 | [mask_reg](../mask_reg.md)。 |34| preg | 输入 | [mask_reg](../mask_reg.md)。 |
35-| mode | 输入 | 可选,对应[MergeMode](../types/MergeMode.md)类型。<br>- pypto_pro.language.MergeMode.ZEROING(默认),preg未筛选的元素在dst中置0。<br>- pypto_pro.language.MergeMode.MERGING当前不支持。 |35+| mode | 输入 | 可选,对应[MergeMode](../types/MergeMode.md)类型。<br>- pypto_pro.language.MergeMode.ZEROING(默认),preg未筛选的元素在dst中置0。<br>- pypto_pro.language.MergeMode.MERGING当前不支持。 |
36| precision | 输入 | 可选,高精度模式开关。True启用高精度模式;False(默认)为标准模式。 |36| precision | 输入 | 可选,高精度模式开关。True启用高精度模式;False(默认)为标准模式。 |
37 37 
38## 约束说明38## 约束说明
39 39 
40-无。40+无。
41 41 
42## 返回值说明42## 返回值说明
43 43 
@@ -3,13 +3,13 @@
3## 产品支持情况3## 产品支持情况
4 4 
5<!-- npu="950" id1 -->5<!-- npu="950" id1 -->
6-- Ascend 950PR/Ascend 950DT:支持6+- Ascend 950PR&950DT系列产品:支持
7<!-- end id1 -->7<!-- end id1 -->
8<!-- npu="A3" id2 -->8<!-- npu="A3" id2 -->
9-- Atlas A3 训练系列产品/Atlas A3 推理系列产品:不支持9+- Atlas A3系列产品:不支持
10<!-- end id2 -->10<!-- end id2 -->
11<!-- npu="910b" id3 -->11<!-- npu="910b" id3 -->
12-- Atlas A2 训练系列产品/Atlas A2 推理系列产品:不支持12+- Atlas A2系列产品:不支持
13<!-- end id3 -->13<!-- end id3 -->
14 14 
15## 功能说明15## 功能说明
@@ -32,12 +32,12 @@ log2(src, preg, mode: Optional[MergeMode] = None, precision: Optional[bool] = No
32|---|---|---|32|---|---|---|
33| src | 输入 | 源操作数,[reg_tensor](../reg_tensor.md),必须为正数,源操作数src与目的操作数dst的数据类型保持一致。支持的数据类型为:DT_FP16、DT_FP32。 |33| src | 输入 | 源操作数,[reg_tensor](../reg_tensor.md),必须为正数,源操作数src与目的操作数dst的数据类型保持一致。支持的数据类型为:DT_FP16、DT_FP32。 |
34| preg | 输入 | [mask_reg](../mask_reg.md)。 |34| preg | 输入 | [mask_reg](../mask_reg.md)。 |
35-| mode | 输入 | 可选,对应[MergeMode](../types/MergeMode.md)类型。<br>- pypto_pro.language.MergeMode.ZEROING(默认),preg未筛选的元素在dst中置0。<br>- pypto_pro.language.MergeMode.MERGING当前不支持。 |35+| mode | 输入 | 可选,对应[MergeMode](../types/MergeMode.md)类型。<br>- pypto_pro.language.MergeMode.ZEROING(默认),preg未筛选的元素在dst中置0。<br>- pypto_pro.language.MergeMode.MERGING当前不支持。 |
36| precision | 输入 | 可选,高精度模式开关。True启用高精度模式;False(默认)为标准模式。 |36| precision | 输入 | 可选,高精度模式开关。True启用高精度模式;False(默认)为标准模式。 |
37 37 
38## 约束说明38## 约束说明
39 39 
40-无。40+无。
41 41 
42## 返回值说明42## 返回值说明
43 43 
@@ -3,13 +3,13 @@
3## 产品支持情况3## 产品支持情况
4 4 
5<!-- npu="950" id1 -->5<!-- npu="950" id1 -->
6-- Ascend 950PR/Ascend 950DT:支持6+- Ascend 950PR&950DT系列产品:支持
7<!-- end id1 -->7<!-- end id1 -->
8<!-- npu="A3" id2 -->8<!-- npu="A3" id2 -->
9-- Atlas A3 训练系列产品/Atlas A3 推理系列产品:不支持9+- Atlas A3系列产品:不支持
10<!-- end id2 -->10<!-- end id2 -->
11<!-- npu="910b" id3 -->11<!-- npu="910b" id3 -->
12-- Atlas A2 训练系列产品/Atlas A2 推理系列产品:不支持12+- Atlas A2系列产品:不支持
13<!-- end id3 -->13<!-- end id3 -->
14 14 
15## 功能说明15## 功能说明
@@ -31,7 +31,7 @@ max(src0, src1, preg, mode: Optional[MergeMode] = None) -> dst
31| src0 | 输入 | 源操作数0,[reg_tensor](../reg_tensor.md),源操作数src0与目的操作数dst的数据类型保持一致。支持的数据类型为:DT_INT8、DT_UINT8、DT_INT16、DT_UINT16、DT_FP16、DT_BF16、DT_INT32、DT_UINT32、DT_FP32、DT_INT64、DT_UINT64。 |31| src0 | 输入 | 源操作数0,[reg_tensor](../reg_tensor.md),源操作数src0与目的操作数dst的数据类型保持一致。支持的数据类型为:DT_INT8、DT_UINT8、DT_INT16、DT_UINT16、DT_FP16、DT_BF16、DT_INT32、DT_UINT32、DT_FP32、DT_INT64、DT_UINT64。 |
32| src1 | 输入 | 源操作数1,[reg_tensor](../reg_tensor.md),数据类型与src0一致。 |32| src1 | 输入 | 源操作数1,[reg_tensor](../reg_tensor.md),数据类型与src0一致。 |
33| preg | 输入 | [mask_reg](../mask_reg.md)。 |33| preg | 输入 | [mask_reg](../mask_reg.md)。 |
34-| mode | 输入 | 可选,对应[MergeMode](../types/MergeMode.md)类型。<br>- pypto_pro.language.MergeMode.ZEROING(默认),preg未筛选的元素在dst中置0。<br>- pypto_pro.language.MergeMode.MERGING当前不支持。 |34+| mode | 输入 | 可选,对应[MergeMode](../types/MergeMode.md)类型。<br>- pypto_pro.language.MergeMode.ZEROING(默认),preg未筛选的元素在dst中置0。<br>- pypto_pro.language.MergeMode.MERGING当前不支持。 |
35 35 
36## 约束说明36## 约束说明
37 37 
@@ -94,7 +94,7 @@ if __name__ == "__main__":
94 test_example()94 test_example()
95 print("PASSED")95 print("PASSED")
96```96```
97- 97+ 
98### INT64数据类型示例98### INT64数据类型示例
99 99 
100```python100```python
@@ -145,4 +145,4 @@ def test_example_int64():
145if __name__ == "__main__":145if __name__ == "__main__":
146 test_example_int64()146 test_example_int64()
147 print("PASSED")147 print("PASSED")
148-```148+```
@@ -3,13 +3,13 @@
3## 产品支持情况3## 产品支持情况
4 4 
5<!-- npu="950" id1 -->5<!-- npu="950" id1 -->
6-- Ascend 950PR/Ascend 950DT:支持6+- Ascend 950PR&950DT系列产品:支持
7<!-- end id1 -->7<!-- end id1 -->
8<!-- npu="A3" id2 -->8<!-- npu="A3" id2 -->
9-- Atlas A3 训练系列产品/Atlas A3 推理系列产品:不支持9+- Atlas A3系列产品:不支持
10<!-- end id2 -->10<!-- end id2 -->
11<!-- npu="910b" id3 -->11<!-- npu="910b" id3 -->
12-- Atlas A2 训练系列产品/Atlas A2 推理系列产品:不支持12+- Atlas A2系列产品:不支持
13<!-- end id3 -->13<!-- end id3 -->
14 14 
15## 功能说明15## 功能说明
@@ -31,7 +31,7 @@ maxs(src, scalar, preg, mode: Optional[MergeMode] = None) -> dst
31| src | 输入 | 源操作数,[reg_tensor](../reg_tensor.md),源操作数src与目的操作数dst的数据类型保持一致。支持的数据类型为:DT_INT8、DT_UINT8、DT_INT16、DT_UINT16、DT_FP16、DT_BF16、DT_INT32、DT_UINT32、DT_FP32、DT_INT64、DT_UINT64。 |31| src | 输入 | 源操作数,[reg_tensor](../reg_tensor.md),源操作数src与目的操作数dst的数据类型保持一致。支持的数据类型为:DT_INT8、DT_UINT8、DT_INT16、DT_UINT16、DT_FP16、DT_BF16、DT_INT32、DT_UINT32、DT_FP32、DT_INT64、DT_UINT64。 |
32| scalar | 输入 | 标量源操作数。 |32| scalar | 输入 | 标量源操作数。 |
33| preg | 输入 | [mask_reg](../mask_reg.md)。 |33| preg | 输入 | [mask_reg](../mask_reg.md)。 |
34-| mode | 输入 | 可选,对应[MergeMode](../types/MergeMode.md)类型。<br>- pypto_pro.language.MergeMode.ZEROING(默认),preg未筛选的元素在dst中置0。<br>- pypto_pro.language.MergeMode.MERGING当前不支持。 |34+| mode | 输入 | 可选,对应[MergeMode](../types/MergeMode.md)类型。<br>- pypto_pro.language.MergeMode.ZEROING(默认),preg未筛选的元素在dst中置0。<br>- pypto_pro.language.MergeMode.MERGING当前不支持。 |
35 35 
36## 约束说明36## 约束说明
37 37 
@@ -89,49 +89,49 @@ if __name__ == "__main__":
89 test_example()89 test_example()
90 print("PASSED")90 print("PASSED")
91```91```
92- 92+ 
93-### INT64数据类型示例93+### INT64数据类型示例
94- 94+ 
95-```python95+```python
96-import os96+import os
97-import pypto_pro.language as pl97+import pypto_pro.language as pl
98-import torch98+import torch
99-import torch_npu99+import torch_npu
100- 100+ 
101-@pl.vector_function101+@pl.vector_function
102-def example_vf_int64(src_tile, dst_tile):102+def example_vf_int64(src_tile, dst_tile):
103- preg = vf.create_mask(pattern=pl.MaskPattern.ALL, dtype=pl.DT_INT64)103+ preg = vf.create_mask(pattern=pl.MaskPattern.ALL, dtype=pl.DT_INT64)
104- reg_a = vf.load_align(src_tile, 0)104+ reg_a = vf.load_align(src_tile, 0)
105- reg_out = vf.maxs(reg_a, 0, preg)105+ reg_out = vf.maxs(reg_a, 0, preg)
106- vf.store_align(dst_tile, reg_out, preg)106+ vf.store_align(dst_tile, reg_out, preg)
107- 107+ 
108-@pl.jit()108+@pl.jit()
109-def example_kernel_int64(109+def example_kernel_int64(
110- a: pl.Tensor[[pl.DYNAMIC, pl.DYNAMIC], pl.DT_INT64],110+ a: pl.Tensor[[pl.DYNAMIC, pl.DYNAMIC], pl.DT_INT64],
111- out: pl.Tensor[[pl.DYNAMIC, pl.DYNAMIC], pl.DT_INT64],111+ out: pl.Tensor[[pl.DYNAMIC, pl.DYNAMIC], pl.DT_INT64],
112-):112+):
113- tf = pl.TileType(shape=[1, 32], dtype=pl.DT_INT64, target_memory=pl.MemorySpace.Vec)113+ tf = pl.TileType(shape=[1, 32], dtype=pl.DT_INT64, target_memory=pl.MemorySpace.Vec)
114 in_a_grp = pl.make_tile_group(type=tf, addrs=0, mutex_ids=[0])114 in_a_grp = pl.make_tile_group(type=tf, addrs=0, mutex_ids=[0])
115 in_a = in_a_grp.current()115 in_a = in_a_grp.current()
116 t_out_grp = pl.make_tile_group(type=tf, addrs=256, mutex_ids=[1])116 t_out_grp = pl.make_tile_group(type=tf, addrs=256, mutex_ids=[1])
117 t_out = t_out_grp.current()117 t_out = t_out_grp.current()
118- with pl.section_vector():118+ with pl.section_vector():
119- pl.load(in_a, a, [0, 0])119+ pl.load(in_a, a, [0, 0])
120- example_vf_int64(in_a, t_out)120+ example_vf_int64(in_a, t_out)
121- pl.store(out, t_out, [0, 0])121+ pl.store(out, t_out, [0, 0])
122- 122+ 
123-def test_example_int64():123+def test_example_int64():
124- device_id = int(os.environ.get("TILE_FWK_DEVICE_ID", 0))124+ device_id = int(os.environ.get("TILE_FWK_DEVICE_ID", 0))
125- device = f"npu:{device_id}"125+ device = f"npu:{device_id}"
126- core_nums = 1126+ core_nums = 1
127- torch.npu.set_device(device)127+ torch.npu.set_device(device)
128- a = torch.randint(-100, 100, [1, 32], device=device, dtype=torch.int64)128+ a = torch.randint(-100, 100, [1, 32], device=device, dtype=torch.int64)
129- out = torch.empty([1, 32], device=device, dtype=torch.int64)129+ out = torch.empty([1, 32], device=device, dtype=torch.int64)
130- example_kernel_int64[None, core_nums](a, out)130+ example_kernel_int64[None, core_nums](a, out)
131- torch.npu.synchronize()131+ torch.npu.synchronize()
132- torch.testing.assert_close(out, torch.max(a, torch.tensor(0, dtype=torch.int64, device=device)), rtol=0, atol=0)132+ torch.testing.assert_close(out, torch.max(a, torch.tensor(0, dtype=torch.int64, device=device)), rtol=0, atol=0)
133- 133+ 
134-if __name__ == "__main__":134+if __name__ == "__main__":
135- test_example_int64()135+ test_example_int64()
136- print("PASSED")136+ print("PASSED")
137```137```
@@ -3,13 +3,13 @@
3## 产品支持情况3## 产品支持情况
4 4 
5<!-- npu="950" id1 -->5<!-- npu="950" id1 -->
6-- Ascend 950PR/Ascend 950DT:支持6+- Ascend 950PR&950DT系列产品:支持
7<!-- end id1 -->7<!-- end id1 -->
8<!-- npu="A3" id2 -->8<!-- npu="A3" id2 -->
9-- Atlas A3 训练系列产品/Atlas A3 推理系列产品:不支持9+- Atlas A3系列产品:不支持
10<!-- end id2 -->10<!-- end id2 -->
11<!-- npu="910b" id3 -->11<!-- npu="910b" id3 -->
12-- Atlas A2 训练系列产品/Atlas A2 推理系列产品:不支持12+- Atlas A2系列产品:不支持
13<!-- end id3 -->13<!-- end id3 -->
14 14 
15## 功能说明15## 功能说明
@@ -31,7 +31,7 @@ min(src0, src1, preg, mode: Optional[MergeMode] = None) -> dst
31| src0 | 输入 | 源操作数0,[reg_tensor](../reg_tensor.md),源操作数src0与目的操作数dst的数据类型保持一致。支持的数据类型为:DT_INT8、DT_UINT8、DT_INT16、DT_UINT16、DT_FP16、DT_BF16、DT_INT32、DT_UINT32、DT_FP32、DT_INT64、DT_UINT64。 |31| src0 | 输入 | 源操作数0,[reg_tensor](../reg_tensor.md),源操作数src0与目的操作数dst的数据类型保持一致。支持的数据类型为:DT_INT8、DT_UINT8、DT_INT16、DT_UINT16、DT_FP16、DT_BF16、DT_INT32、DT_UINT32、DT_FP32、DT_INT64、DT_UINT64。 |
32| src1 | 输入 | 源操作数1,[reg_tensor](../reg_tensor.md),数据类型与src0一致。 |32| src1 | 输入 | 源操作数1,[reg_tensor](../reg_tensor.md),数据类型与src0一致。 |
33| preg | 输入 | [mask_reg](../mask_reg.md)。 |33| preg | 输入 | [mask_reg](../mask_reg.md)。 |
34-| mode | 输入 | 可选,对应[MergeMode](../types/MergeMode.md)类型。<br>- pypto_pro.language.MergeMode.ZEROING(默认),preg未筛选的元素在dst中置0。<br>- pypto_pro.language.MergeMode.MERGING当前不支持。 |34+| mode | 输入 | 可选,对应[MergeMode](../types/MergeMode.md)类型。<br>- pypto_pro.language.MergeMode.ZEROING(默认),preg未筛选的元素在dst中置0。<br>- pypto_pro.language.MergeMode.MERGING当前不支持。 |
35 35 
36## 约束说明36## 约束说明
37 37 
@@ -94,49 +94,49 @@ if __name__ == "__main__":
94 test_example()94 test_example()
95 print("PASSED")95 print("PASSED")
96```96```
97- 97+ 
98-### INT64数据类型示例98+### INT64数据类型示例
99- 99+ 
100-```python100+```python
101-import os101+import os
102-import pypto_pro.language as pl102+import pypto_pro.language as pl
103-import torch103+import torch
104-import torch_npu104+import torch_npu
105- 105+ 
106-@pl.vector_function106+@pl.vector_function
107-def example_vf_int64(src_tile, dst_tile):107+def example_vf_int64(src_tile, dst_tile):
108- preg = vf.create_mask(pattern=pl.MaskPattern.ALL, dtype=pl.DT_INT64)108+ preg = vf.create_mask(pattern=pl.MaskPattern.ALL, dtype=pl.DT_INT64)
109- reg_a = vf.load_align(src_tile, 0)109+ reg_a = vf.load_align(src_tile, 0)
110- reg_out = vf.min(reg_a, reg_a, preg)110+ reg_out = vf.min(reg_a, reg_a, preg)
111- vf.store_align(dst_tile, reg_out, preg)111+ vf.store_align(dst_tile, reg_out, preg)
112- 112+ 
113-@pl.jit()113+@pl.jit()
114-def example_kernel_int64(114+def example_kernel_int64(
115- a: pl.Tensor[[pl.DYNAMIC, pl.DYNAMIC], pl.DT_INT64],115+ a: pl.Tensor[[pl.DYNAMIC, pl.DYNAMIC], pl.DT_INT64],
116- out: pl.Tensor[[pl.DYNAMIC, pl.DYNAMIC], pl.DT_INT64],116+ out: pl.Tensor[[pl.DYNAMIC, pl.DYNAMIC], pl.DT_INT64],
117-):117+):
118- tf = pl.TileType(shape=[1, 32], dtype=pl.DT_INT64, target_memory=pl.MemorySpace.Vec)118+ tf = pl.TileType(shape=[1, 32], dtype=pl.DT_INT64, target_memory=pl.MemorySpace.Vec)
119 in_a_grp = pl.make_tile_group(type=tf, addrs=0, mutex_ids=[0])119 in_a_grp = pl.make_tile_group(type=tf, addrs=0, mutex_ids=[0])
120 in_a = in_a_grp.current()120 in_a = in_a_grp.current()
121 t_out_grp = pl.make_tile_group(type=tf, addrs=256, mutex_ids=[1])121 t_out_grp = pl.make_tile_group(type=tf, addrs=256, mutex_ids=[1])
122 t_out = t_out_grp.current()122 t_out = t_out_grp.current()
123- with pl.section_vector():123+ with pl.section_vector():
124- pl.load(in_a, a, [0, 0])124+ pl.load(in_a, a, [0, 0])
125- example_vf_int64(in_a, t_out)125+ example_vf_int64(in_a, t_out)
126- pl.store(out, t_out, [0, 0])126+ pl.store(out, t_out, [0, 0])
127- 127+ 
128-def test_example_int64():128+def test_example_int64():
129- device_id = int(os.environ.get("TILE_FWK_DEVICE_ID", 0))129+ device_id = int(os.environ.get("TILE_FWK_DEVICE_ID", 0))
130- device = f"npu:{device_id}"130+ device = f"npu:{device_id}"
131- core_nums = 1131+ core_nums = 1
132- torch.npu.set_device(device)132+ torch.npu.set_device(device)
133- a = torch.randint(-100, 100, [1, 32], device=device, dtype=torch.int64)133+ a = torch.randint(-100, 100, [1, 32], device=device, dtype=torch.int64)
134- out = torch.empty([1, 32], device=device, dtype=torch.int64)134+ out = torch.empty([1, 32], device=device, dtype=torch.int64)
135- example_kernel_int64[None, core_nums](a, out)135+ example_kernel_int64[None, core_nums](a, out)
136- torch.npu.synchronize()136+ torch.npu.synchronize()
137- torch.testing.assert_close(out, a, rtol=0, atol=0)137+ torch.testing.assert_close(out, a, rtol=0, atol=0)
138- 138+ 
139-if __name__ == "__main__":139+if __name__ == "__main__":
140- test_example_int64()140+ test_example_int64()
141- print("PASSED")141+ print("PASSED")
142```142```
@@ -3,13 +3,13 @@
3## 产品支持情况3## 产品支持情况
4 4 
5<!-- npu="950" id1 -->5<!-- npu="950" id1 -->
6-- Ascend 950PR/Ascend 950DT:支持6+- Ascend 950PR&950DT系列产品:支持
7<!-- end id1 -->7<!-- end id1 -->
8<!-- npu="A3" id2 -->8<!-- npu="A3" id2 -->
9-- Atlas A3 训练系列产品/Atlas A3 推理系列产品:不支持9+- Atlas A3系列产品:不支持
10<!-- end id2 -->10<!-- end id2 -->
11<!-- npu="910b" id3 -->11<!-- npu="910b" id3 -->
12-- Atlas A2 训练系列产品/Atlas A2 推理系列产品:不支持12+- Atlas A2系列产品:不支持
13<!-- end id3 -->13<!-- end id3 -->
14 14 
15## 功能说明15## 功能说明
@@ -31,7 +31,7 @@ mins(src, scalar, preg, mode: Optional[MergeMode] = None) -> dst
31| src | 输入 | 源操作数,[reg_tensor](../reg_tensor.md),源操作数src与目的操作数dst的数据类型保持一致。支持的数据类型为:DT_INT8、DT_UINT8、DT_INT16、DT_UINT16、DT_FP16、DT_BF16、DT_INT32、DT_UINT32、DT_FP32、DT_INT64、DT_UINT64。 |31| src | 输入 | 源操作数,[reg_tensor](../reg_tensor.md),源操作数src与目的操作数dst的数据类型保持一致。支持的数据类型为:DT_INT8、DT_UINT8、DT_INT16、DT_UINT16、DT_FP16、DT_BF16、DT_INT32、DT_UINT32、DT_FP32、DT_INT64、DT_UINT64。 |
32| scalar | 输入 | 标量源操作数。 |32| scalar | 输入 | 标量源操作数。 |
33| preg | 输入 | [mask_reg](../mask_reg.md)。 |33| preg | 输入 | [mask_reg](../mask_reg.md)。 |
34-| mode | 输入 | 可选,对应[MergeMode](../types/MergeMode.md)类型。<br>- pypto_pro.language.MergeMode.ZEROING(默认),preg未筛选的元素在dst中置0。<br>- pypto_pro.language.MergeMode.MERGING当前不支持。 |34+| mode | 输入 | 可选,对应[MergeMode](../types/MergeMode.md)类型。<br>- pypto_pro.language.MergeMode.ZEROING(默认),preg未筛选的元素在dst中置0。<br>- pypto_pro.language.MergeMode.MERGING当前不支持。 |
35 35 
36## 约束说明36## 约束说明
37 37 
@@ -89,49 +89,49 @@ if __name__ == "__main__":
89 test_example()89 test_example()
90 print("PASSED")90 print("PASSED")
91```91```
92- 92+ 
93-### INT64数据类型示例93+### INT64数据类型示例
94- 94+ 
95-```python95+```python
96-import os96+import os
97-import pypto_pro.language as pl97+import pypto_pro.language as pl
98-import torch98+import torch
99-import torch_npu99+import torch_npu
100- 100+ 
101-@pl.vector_function101+@pl.vector_function
102-def example_vf_int64(src_tile, dst_tile):102+def example_vf_int64(src_tile, dst_tile):
103- preg = vf.create_mask(pattern=pl.MaskPattern.ALL, dtype=pl.DT_INT64)103+ preg = vf.create_mask(pattern=pl.MaskPattern.ALL, dtype=pl.DT_INT64)
104- reg_a = vf.load_align(src_tile, 0)104+ reg_a = vf.load_align(src_tile, 0)
105- reg_out = vf.mins(reg_a, 50, preg)105+ reg_out = vf.mins(reg_a, 50, preg)
106- vf.store_align(dst_tile, reg_out, preg)106+ vf.store_align(dst_tile, reg_out, preg)
107- 107+ 
108-@pl.jit()108+@pl.jit()
109-def example_kernel_int64(109+def example_kernel_int64(
110- a: pl.Tensor[[pl.DYNAMIC, pl.DYNAMIC], pl.DT_INT64],110+ a: pl.Tensor[[pl.DYNAMIC, pl.DYNAMIC], pl.DT_INT64],
111- out: pl.Tensor[[pl.DYNAMIC, pl.DYNAMIC], pl.DT_INT64],111+ out: pl.Tensor[[pl.DYNAMIC, pl.DYNAMIC], pl.DT_INT64],
112-):112+):
113- tf = pl.TileType(shape=[1, 32], dtype=pl.DT_INT64, target_memory=pl.MemorySpace.Vec)113+ tf = pl.TileType(shape=[1, 32], dtype=pl.DT_INT64, target_memory=pl.MemorySpace.Vec)
114 in_a_grp = pl.make_tile_group(type=tf, addrs=0, mutex_ids=[0])114 in_a_grp = pl.make_tile_group(type=tf, addrs=0, mutex_ids=[0])
115 in_a = in_a_grp.current()115 in_a = in_a_grp.current()
116 t_out_grp = pl.make_tile_group(type=tf, addrs=256, mutex_ids=[1])116 t_out_grp = pl.make_tile_group(type=tf, addrs=256, mutex_ids=[1])
117 t_out = t_out_grp.current()117 t_out = t_out_grp.current()
118- with pl.section_vector():118+ with pl.section_vector():
119- pl.load(in_a, a, [0, 0])119+ pl.load(in_a, a, [0, 0])
120- example_vf_int64(in_a, t_out)120+ example_vf_int64(in_a, t_out)
121- pl.store(out, t_out, [0, 0])121+ pl.store(out, t_out, [0, 0])
122- 122+ 
123-def test_example_int64():123+def test_example_int64():
124- device_id = int(os.environ.get("TILE_FWK_DEVICE_ID", 0))124+ device_id = int(os.environ.get("TILE_FWK_DEVICE_ID", 0))
125- device = f"npu:{device_id}"125+ device = f"npu:{device_id}"
126- core_nums = 1126+ core_nums = 1
127- torch.npu.set_device(device)127+ torch.npu.set_device(device)
128- a = torch.randint(-100, 100, [1, 32], device=device, dtype=torch.int64)128+ a = torch.randint(-100, 100, [1, 32], device=device, dtype=torch.int64)
129- out = torch.empty([1, 32], device=device, dtype=torch.int64)129+ out = torch.empty([1, 32], device=device, dtype=torch.int64)
130- example_kernel_int64[None, core_nums](a, out)130+ example_kernel_int64[None, core_nums](a, out)
131- torch.npu.synchronize()131+ torch.npu.synchronize()
132- torch.testing.assert_close(out, torch.min(a, torch.tensor(50, dtype=torch.int64, device=device)), rtol=0, atol=0)132+ torch.testing.assert_close(out, torch.min(a, torch.tensor(50, dtype=torch.int64, device=device)), rtol=0, atol=0)
133- 133+ 
134-if __name__ == "__main__":134+if __name__ == "__main__":
135- test_example_int64()135+ test_example_int64()
136- print("PASSED")136+ print("PASSED")
137```137```
@@ -3,13 +3,13 @@
3## 产品支持情况3## 产品支持情况
4 4 
5<!-- npu="950" id1 -->5<!-- npu="950" id1 -->
6-- Ascend 950PR/Ascend 950DT:支持6+- Ascend 950PR&950DT系列产品:支持
7<!-- end id1 -->7<!-- end id1 -->
8<!-- npu="A3" id2 -->8<!-- npu="A3" id2 -->
9-- Atlas A3 训练系列产品/Atlas A3 推理系列产品:不支持9+- Atlas A3系列产品:不支持
10<!-- end id2 -->10<!-- end id2 -->
11<!-- npu="910b" id3 -->11<!-- npu="910b" id3 -->
12-- Atlas A2 训练系列产品/Atlas A2 推理系列产品:不支持12+- Atlas A2系列产品:不支持
13<!-- end id3 -->13<!-- end id3 -->
14 14 
15## 功能说明15## 功能说明
@@ -31,11 +31,11 @@ mul(src0, src1, preg, mode: Optional[MergeMode] = None) -> dst
31| src0 | 输入 | 源操作数0,[reg_tensor](../reg_tensor.md),源操作数src0与目的操作数dst的数据类型保持一致。支持的数据类型为:DT_INT16、DT_UINT16、DT_INT32、DT_UINT32、DT_FP16、DT_BF16、DT_FP32、DT_INT64、DT_UINT64。 |31| src0 | 输入 | 源操作数0,[reg_tensor](../reg_tensor.md),源操作数src0与目的操作数dst的数据类型保持一致。支持的数据类型为:DT_INT16、DT_UINT16、DT_INT32、DT_UINT32、DT_FP16、DT_BF16、DT_FP32、DT_INT64、DT_UINT64。 |
32| src1 | 输入 | 源操作数1,[reg_tensor](../reg_tensor.md),数据类型与src0一致。 |32| src1 | 输入 | 源操作数1,[reg_tensor](../reg_tensor.md),数据类型与src0一致。 |
33| preg | 输入 | [mask_reg](../mask_reg.md)。 |33| preg | 输入 | [mask_reg](../mask_reg.md)。 |
34-| mode | 输入 | 可选,对应[MergeMode](../types/MergeMode.md)类型。<br>- pypto_pro.language.MergeMode.ZEROING(默认),preg未筛选的元素在dst中置0。<br>- pypto_pro.language.MergeMode.MERGING当前不支持。 |34+| mode | 输入 | 可选,对应[MergeMode](../types/MergeMode.md)类型。<br>- pypto_pro.language.MergeMode.ZEROING(默认),preg未筛选的元素在dst中置0。<br>- pypto_pro.language.MergeMode.MERGING当前不支持。 |
35 35 
36## 约束说明36## 约束说明
37 37 
38-无。38+无。
39 39 
40## 返回值说明40## 返回值说明
41 41 
@@ -3,13 +3,13 @@
3## 产品支持情况3## 产品支持情况
4 4 
5<!-- npu="950" id1 -->5<!-- npu="950" id1 -->
6-- Ascend 950PR/Ascend 950DT:支持6+- Ascend 950PR&950DT系列产品:支持
7<!-- end id1 -->7<!-- end id1 -->
8<!-- npu="A3" id2 -->8<!-- npu="A3" id2 -->
9-- Atlas A3 训练系列产品/Atlas A3 推理系列产品:不支持9+- Atlas A3系列产品:不支持
10<!-- end id2 -->10<!-- end id2 -->
11<!-- npu="910b" id3 -->11<!-- npu="910b" id3 -->
12-- Atlas A2 训练系列产品/Atlas A2 推理系列产品:不支持12+- Atlas A2系列产品:不支持
13<!-- end id3 -->13<!-- end id3 -->
14 14 
15## 功能说明15## 功能说明
@@ -24,7 +24,7 @@ $$dst\_hi_i = \lfloor (src0_i \times src1_i) / 2^{bit} \rfloor$$
24 24 
25**图1** vf.mull功能说明25**图1** vf.mull功能说明
26 26 
27-![](../../../figures/mull_diagram.jpg)27+![](../../../figures/mull_diagram.jpg)
28 28 
29## 函数原型29## 函数原型
30 30 
@@ -42,7 +42,7 @@ mull(src0, src1, preg) -> (dst_lo, dst_hi)
42 42 
43## 约束说明43## 约束说明
44 44 
45-无。45+无。
46 46 
47## 返回值说明47## 返回值说明
48 48 
@@ -112,4 +112,4 @@ def test_example():
112if __name__ == "__main__":112if __name__ == "__main__":
113 test_example()113 test_example()
114 print("PASSED")114 print("PASSED")
115-```115+```
@@ -3,13 +3,13 @@
3## 产品支持情况3## 产品支持情况
4 4 
5<!-- npu="950" id1 -->5<!-- npu="950" id1 -->
6-- Ascend 950PR/Ascend 950DT:支持6+- Ascend 950PR&950DT系列产品:支持
7<!-- end id1 -->7<!-- end id1 -->
8<!-- npu="A3" id2 -->8<!-- npu="A3" id2 -->
9-- Atlas A3 训练系列产品/Atlas A3 推理系列产品:不支持9+- Atlas A3系列产品:不支持
10<!-- end id2 -->10<!-- end id2 -->
11<!-- npu="910b" id3 -->11<!-- npu="910b" id3 -->
12-- Atlas A2 训练系列产品/Atlas A2 推理系列产品:不支持12+- Atlas A2系列产品:不支持
13<!-- end id3 -->13<!-- end id3 -->
14 14 
15## 功能说明15## 功能说明
@@ -31,11 +31,11 @@ muls(src, scalar, preg, mode: Optional[MergeMode] = None) -> dst
31| src | 输入 | 源操作数,[reg_tensor](../reg_tensor.md),源操作数src与目的操作数dst的数据类型保持一致。支持的数据类型为:DT_INT16、DT_UINT16、DT_INT32、DT_UINT32、DT_FP16、DT_FP32、DT_INT64、DT_UINT64。 |31| src | 输入 | 源操作数,[reg_tensor](../reg_tensor.md),源操作数src与目的操作数dst的数据类型保持一致。支持的数据类型为:DT_INT16、DT_UINT16、DT_INT32、DT_UINT32、DT_FP16、DT_FP32、DT_INT64、DT_UINT64。 |
32| scalar | 输入 | 标量源操作数。 |32| scalar | 输入 | 标量源操作数。 |
33| preg | 输入 | [mask_reg](../mask_reg.md)。 |33| preg | 输入 | [mask_reg](../mask_reg.md)。 |
34-| mode | 输入 | 可选,对应[MergeMode](../types/MergeMode.md)类型。<br>- pypto_pro.language.MergeMode.ZEROING(默认),preg未筛选的元素在dst中置0。<br>- pypto_pro.language.MergeMode.MERGING当前不支持。 |34+| mode | 输入 | 可选,对应[MergeMode](../types/MergeMode.md)类型。<br>- pypto_pro.language.MergeMode.ZEROING(默认),preg未筛选的元素在dst中置0。<br>- pypto_pro.language.MergeMode.MERGING当前不支持。 |
35 35 
36## 约束说明36## 约束说明
37 37 
38-无。38+无。
39 39 
40## 返回值说明40## 返回值说明
41 41 
@@ -3,13 +3,13 @@
3## 产品支持情况3## 产品支持情况
4 4 
5<!-- npu="950" id1 -->5<!-- npu="950" id1 -->
6-- Ascend 950PR/Ascend 950DT:支持6+- Ascend 950PR&950DT系列产品:支持
7<!-- end id1 -->7<!-- end id1 -->
8<!-- npu="A3" id2 -->8<!-- npu="A3" id2 -->
9-- Atlas A3 训练系列产品/Atlas A3 推理系列产品:不支持9+- Atlas A3系列产品:不支持
10<!-- end id2 -->10<!-- end id2 -->
11<!-- npu="910b" id3 -->11<!-- npu="910b" id3 -->
12-- Atlas A2 训练系列产品/Atlas A2 推理系列产品:不支持12+- Atlas A2系列产品:不支持
13<!-- end id3 -->13<!-- end id3 -->
14 14 
15## 功能说明15## 功能说明
@@ -30,11 +30,11 @@ neg(src, preg, mode: Optional[MergeMode] = None) -> dst
30|---|---|---|30|---|---|---|
31| src | 输入 | 源操作数,[reg_tensor](../reg_tensor.md),源操作数src与目的操作数dst的数据类型保持一致。支持的数据类型为:DT_INT8、DT_INT16、DT_FP16、DT_INT32、DT_FP32、DT_INT64。 |31| src | 输入 | 源操作数,[reg_tensor](../reg_tensor.md),源操作数src与目的操作数dst的数据类型保持一致。支持的数据类型为:DT_INT8、DT_INT16、DT_FP16、DT_INT32、DT_FP32、DT_INT64。 |
32| preg | 输入 | [mask_reg](../mask_reg.md)。 |32| preg | 输入 | [mask_reg](../mask_reg.md)。 |
33-| mode | 输入 | 可选,对应[MergeMode](../types/MergeMode.md)类型。<br>- pypto_pro.language.MergeMode.ZEROING(默认),preg未筛选的元素在dst中置0。<br>- pypto_pro.language.MergeMode.MERGING当前不支持。 |33+| mode | 输入 | 可选,对应[MergeMode](../types/MergeMode.md)类型。<br>- pypto_pro.language.MergeMode.ZEROING(默认),preg未筛选的元素在dst中置0。<br>- pypto_pro.language.MergeMode.MERGING当前不支持。 |
34 34 
35## 约束说明35## 约束说明
36 36 
37-无。37+无。
38 38 
39## 返回值说明39## 返回值说明
40 40 
@@ -3,13 +3,13 @@
3## 产品支持情况3## 产品支持情况
4 4 
5<!-- npu="950" id1 -->5<!-- npu="950" id1 -->
6-- Ascend 950PR/Ascend 950DT:支持6+- Ascend 950PR&950DT系列产品:支持
7<!-- end id1 -->7<!-- end id1 -->
8<!-- npu="A3" id2 -->8<!-- npu="A3" id2 -->
9-- Atlas A3 训练系列产品/Atlas A3 推理系列产品:不支持9+- Atlas A3系列产品:不支持
10<!-- end id2 -->10<!-- end id2 -->
11<!-- npu="910b" id3 -->11<!-- npu="910b" id3 -->
12-- Atlas A2 训练系列产品/Atlas A2 推理系列产品:不支持12+- Atlas A2系列产品:不支持
13<!-- end id3 -->13<!-- end id3 -->
14 14 
15## 功能说明15## 功能说明
@@ -31,11 +31,11 @@ prelu(src, slope, preg, mode: Optional[MergeMode] = None) -> dst
31| src | 输入 | 源操作数,[reg_tensor](../reg_tensor.md),源操作数src与目的操作数dst的数据类型保持一致。支持的数据类型为:DT_FP16、DT_FP32。 |31| src | 输入 | 源操作数,[reg_tensor](../reg_tensor.md),源操作数src与目的操作数dst的数据类型保持一致。支持的数据类型为:DT_FP16、DT_FP32。 |
32| slope | 输入 | 斜率源操作数,[reg_tensor](../reg_tensor.md),数据类型与src一致。 |32| slope | 输入 | 斜率源操作数,[reg_tensor](../reg_tensor.md),数据类型与src一致。 |
33| preg | 输入 | [mask_reg](../mask_reg.md)。 |33| preg | 输入 | [mask_reg](../mask_reg.md)。 |
34-| mode | 输入 | 可选,对应[MergeMode](../types/MergeMode.md)类型。<br>- pypto_pro.language.MergeMode.ZEROING(默认),preg未筛选的元素在dst中置0。<br>- pypto_pro.language.MergeMode.MERGING当前不支持。 |34+| mode | 输入 | 可选,对应[MergeMode](../types/MergeMode.md)类型。<br>- pypto_pro.language.MergeMode.ZEROING(默认),preg未筛选的元素在dst中置0。<br>- pypto_pro.language.MergeMode.MERGING当前不支持。 |
35 35 
36## 约束说明36## 约束说明
37 37 
38-无。38+无。
39 39 
40## 返回值说明40## 返回值说明
41 41 
@@ -3,13 +3,13 @@
3## 产品支持情况3## 产品支持情况
4 4 
5<!-- npu="950" id1 -->5<!-- npu="950" id1 -->
6-- Ascend 950PR/Ascend 950DT:支持6+- Ascend 950PR&950DT系列产品:支持
7<!-- end id1 -->7<!-- end id1 -->
8<!-- npu="A3" id2 -->8<!-- npu="A3" id2 -->
9-- Atlas A3 训练系列产品/Atlas A3 推理系列产品:不支持9+- Atlas A3系列产品:不支持
10<!-- end id2 -->10<!-- end id2 -->
11<!-- npu="910b" id3 -->11<!-- npu="910b" id3 -->
12-- Atlas A2 训练系列产品/Atlas A2 推理系列产品:不支持12+- Atlas A2系列产品:不支持
13<!-- end id3 -->13<!-- end id3 -->
14 14 
15## 功能说明15## 功能说明
@@ -30,11 +30,11 @@ relu(src, preg, mode: Optional[MergeMode] = None) -> dst
30|---|---|---|30|---|---|---|
31| src | 输入 | 源操作数,[reg_tensor](../reg_tensor.md),源操作数src与目的操作数dst的数据类型保持一致。支持的数据类型为:DT_FP16、DT_INT32、DT_FP32、DT_INT64。 |31| src | 输入 | 源操作数,[reg_tensor](../reg_tensor.md),源操作数src与目的操作数dst的数据类型保持一致。支持的数据类型为:DT_FP16、DT_INT32、DT_FP32、DT_INT64。 |
32| preg | 输入 | [mask_reg](../mask_reg.md)。 |32| preg | 输入 | [mask_reg](../mask_reg.md)。 |
33-| mode | 输入 | 可选,对应[MergeMode](../types/MergeMode.md)类型。<br>- pypto_pro.language.MergeMode.ZEROING(默认),preg未筛选的元素在dst中置0。<br>- pypto_pro.language.MergeMode.MERGING当前不支持。 |33+| mode | 输入 | 可选,对应[MergeMode](../types/MergeMode.md)类型。<br>- pypto_pro.language.MergeMode.ZEROING(默认),preg未筛选的元素在dst中置0。<br>- pypto_pro.language.MergeMode.MERGING当前不支持。 |
34 34 
35## 约束说明35## 约束说明
36 36 
37-无。37+无。
38 38 
39## 返回值说明39## 返回值说明
40 40 
@@ -3,13 +3,13 @@
3## 产品支持情况3## 产品支持情况
4 4 
5<!-- npu="950" id1 -->5<!-- npu="950" id1 -->
6-- Ascend 950PR/Ascend 950DT:支持6+- Ascend 950PR&950DT系列产品:支持
7<!-- end id1 -->7<!-- end id1 -->
8<!-- npu="A3" id2 -->8<!-- npu="A3" id2 -->
9-- Atlas A3 训练系列产品/Atlas A3 推理系列产品:不支持9+- Atlas A3系列产品:不支持
10<!-- end id2 -->10<!-- end id2 -->
11<!-- npu="910b" id3 -->11<!-- npu="910b" id3 -->
12-- Atlas A2 训练系列产品/Atlas A2 推理系列产品:不支持12+- Atlas A2系列产品:不支持
13<!-- end id3 -->13<!-- end id3 -->
14 14 
15## 功能说明15## 功能说明
@@ -30,12 +30,12 @@ sqrt(src, preg, mode: Optional[MergeMode] = None, precision: Optional[bool] = No
30|---|---|---|30|---|---|---|
31| src | 输入 | 源操作数,[reg_tensor](../reg_tensor.md),必须为非负数,源操作数src与目的操作数dst的数据类型保持一致。支持的数据类型为:DT_FP16、DT_FP32。 |31| src | 输入 | 源操作数,[reg_tensor](../reg_tensor.md),必须为非负数,源操作数src与目的操作数dst的数据类型保持一致。支持的数据类型为:DT_FP16、DT_FP32。 |
32| preg | 输入 | [mask_reg](../mask_reg.md)。 |32| preg | 输入 | [mask_reg](../mask_reg.md)。 |
33-| mode | 输入 | 可选,对应[MergeMode](../types/MergeMode.md)类型。<br>- pypto_pro.language.MergeMode.ZEROING(默认),preg未筛选的元素在dst中置0。<br>- pypto_pro.language.MergeMode.MERGING当前不支持。 |33+| mode | 输入 | 可选,对应[MergeMode](../types/MergeMode.md)类型。<br>- pypto_pro.language.MergeMode.ZEROING(默认),preg未筛选的元素在dst中置0。<br>- pypto_pro.language.MergeMode.MERGING当前不支持。 |
34| precision | 输入 | 可选,高精度模式开关。True启用高精度模式;False(默认)为标准模式。 |34| precision | 输入 | 可选,高精度模式开关。True启用高精度模式;False(默认)为标准模式。 |
35 35 
36## 约束说明36## 约束说明
37 37 
38-无。38+无。
39 39 
40## 返回值说明40## 返回值说明
41 41 
@@ -3,13 +3,13 @@
3## 产品支持情况3## 产品支持情况
4 4 
5<!-- npu="950" id1 -->5<!-- npu="950" id1 -->
6-- Ascend 950PR/Ascend 950DT:支持6+- Ascend 950PR&950DT系列产品:支持
7<!-- end id1 -->7<!-- end id1 -->
8<!-- npu="A3" id2 -->8<!-- npu="A3" id2 -->
9-- Atlas A3 训练系列产品/Atlas A3 推理系列产品:不支持9+- Atlas A3系列产品:不支持
10<!-- end id2 -->10<!-- end id2 -->
11<!-- npu="910b" id3 -->11<!-- npu="910b" id3 -->
12-- Atlas A2 训练系列产品/Atlas A2 推理系列产品:不支持12+- Atlas A2系列产品:不支持
13<!-- end id3 -->13<!-- end id3 -->
14 14 
15## 功能说明15## 功能说明
@@ -22,7 +22,7 @@ $$dst_i = src0_i - src1_i$$
22 22 
23**图1** vf.sub功能说明23**图1** vf.sub功能说明
24 24 
25-![](../../../figures/sub_with_carry.jpg)25+![](../../../figures/sub_with_carry.jpg)
26 26 
27若需要获取减法借位输出,请参考[vf.subc](subc.md#功能说明)。27若需要获取减法借位输出,请参考[vf.subc](subc.md#功能说明)。
28 28 
@@ -39,11 +39,11 @@ sub(src0, src1, preg, mode: Optional[MergeMode] = None) -> dst
39| src0 | 输入 | 源操作数0,[reg_tensor](../reg_tensor.md),源操作数src0与目的操作数dst的数据类型保持一致。支持的数据类型为:DT_INT8、DT_UINT8、DT_INT16、DT_UINT16、DT_INT32、DT_UINT32、DT_FP16、DT_BF16、DT_FP32、DT_INT64、DT_UINT64。 |39| src0 | 输入 | 源操作数0,[reg_tensor](../reg_tensor.md),源操作数src0与目的操作数dst的数据类型保持一致。支持的数据类型为:DT_INT8、DT_UINT8、DT_INT16、DT_UINT16、DT_INT32、DT_UINT32、DT_FP16、DT_BF16、DT_FP32、DT_INT64、DT_UINT64。 |
40| src1 | 输入 | 源操作数1,[reg_tensor](../reg_tensor.md),数据类型与src0一致。 |40| src1 | 输入 | 源操作数1,[reg_tensor](../reg_tensor.md),数据类型与src0一致。 |
41| preg | 输入 | [mask_reg](../mask_reg.md)。 |41| preg | 输入 | [mask_reg](../mask_reg.md)。 |
42-| mode | 输入 | 可选,对应[MergeMode](../types/MergeMode.md)类型。<br>- pypto_pro.language.MergeMode.ZEROING(默认),preg未筛选的元素在dst中置0。<br>- pypto_pro.language.MergeMode.MERGING当前不支持。 |42+| mode | 输入 | 可选,对应[MergeMode](../types/MergeMode.md)类型。<br>- pypto_pro.language.MergeMode.ZEROING(默认),preg未筛选的元素在dst中置0。<br>- pypto_pro.language.MergeMode.MERGING当前不支持。 |
43 43 
44## 约束说明44## 约束说明
45 45 
46-无。46+无。
47 47 
48## 返回值说明48## 返回值说明
49 49 
@@ -3,13 +3,13 @@
3## 产品支持情况3## 产品支持情况
4 4 
5<!-- npu="950" id1 -->5<!-- npu="950" id1 -->
6-- Ascend 950PR/Ascend 950DT:支持6+- Ascend 950PR&950DT系列产品:支持
7<!-- end id1 -->7<!-- end id1 -->
8<!-- npu="A3" id2 -->8<!-- npu="A3" id2 -->
9-- Atlas A3 训练系列产品/Atlas A3 推理系列产品:不支持9+- Atlas A3系列产品:不支持
10<!-- end id2 -->10<!-- end id2 -->
11<!-- npu="910b" id3 -->11<!-- npu="910b" id3 -->
12-- Atlas A2 训练系列产品/Atlas A2 推理系列产品:不支持12+- Atlas A2系列产品:不支持
13<!-- end id3 -->13<!-- end id3 -->
14 14 
15## 功能说明15## 功能说明
@@ -37,7 +37,7 @@ subc(src0, src1, borrow_src, preg) -> (borrow, dst)
37 37 
38## 约束说明38## 约束说明
39 39 
40-无。40+无。
41 41 
42## 返回值说明42## 返回值说明
43 43 
@@ -3,13 +3,13 @@
3## 产品支持情况3## 产品支持情况
4 4 
5<!-- npu="950" id1 -->5<!-- npu="950" id1 -->
6-- Ascend 950PR/Ascend 950DT:支持6+- Ascend 950PR&950DT系列产品:支持
7<!-- end id1 -->7<!-- end id1 -->
8<!-- npu="A3" id2 -->8<!-- npu="A3" id2 -->
9-- Atlas A3 训练系列产品/Atlas A3 推理系列产品:不支持9+- Atlas A3系列产品:不支持
10<!-- end id2 -->10<!-- end id2 -->
11<!-- npu="910b" id3 -->11<!-- npu="910b" id3 -->
12-- Atlas A2 训练系列产品/Atlas A2 推理系列产品:不支持12+- Atlas A2系列产品:不支持
13<!-- end id3 -->13<!-- end id3 -->
14 14 
15## 功能说明15## 功能说明
@@ -36,7 +36,7 @@ eq(src0, src1, preg) -> dst_mask
36 36 
37## 约束说明37## 约束说明
38 38 
39-无。39+无。
40 40 
41## 返回值说明41## 返回值说明
42 42 
@@ -96,7 +96,7 @@ if __name__ == "__main__":
96 test_example()96 test_example()
97 print("PASSED")97 print("PASSED")
98```98```
99- 99+ 
100### INT64数据类型示例100### INT64数据类型示例
101 101 
102```python102```python
@@ -149,4 +149,4 @@ def test_example_int64():
149if __name__ == "__main__":149if __name__ == "__main__":
150 test_example_int64()150 test_example_int64()
151 print("PASSED")151 print("PASSED")
152-```152+```
@@ -3,13 +3,13 @@
3## 产品支持情况3## 产品支持情况
4 4 
5<!-- npu="950" id1 -->5<!-- npu="950" id1 -->
6-- Ascend 950PR/Ascend 950DT:支持6+- Ascend 950PR&950DT系列产品:支持
7<!-- end id1 -->7<!-- end id1 -->
8<!-- npu="A3" id2 -->8<!-- npu="A3" id2 -->
9-- Atlas A3 训练系列产品/Atlas A3 推理系列产品:不支持9+- Atlas A3系列产品:不支持
10<!-- end id2 -->10<!-- end id2 -->
11<!-- npu="910b" id3 -->11<!-- npu="910b" id3 -->
12-- Atlas A2 训练系列产品/Atlas A2 推理系列产品:不支持12+- Atlas A2系列产品:不支持
13<!-- end id3 -->13<!-- end id3 -->
14 14 
15## 功能说明15## 功能说明
@@ -36,7 +36,7 @@ ge(src0, src1, preg) -> dst_mask
36 36 
37## 约束说明37## 约束说明
38 38 
39-无。39+无。
40 40 
41## 返回值说明41## 返回值说明
42 42 
@@ -96,7 +96,7 @@ if __name__ == "__main__":
96 test_example()96 test_example()
97 print("PASSED")97 print("PASSED")
98```98```
99- 99+ 
100### INT64数据类型示例100### INT64数据类型示例
101 101 
102```python102```python
@@ -149,4 +149,4 @@ def test_example_int64():
149if __name__ == "__main__":149if __name__ == "__main__":
150 test_example_int64()150 test_example_int64()
151 print("PASSED")151 print("PASSED")
152-```152+```
@@ -3,13 +3,13 @@
3## 产品支持情况3## 产品支持情况
4 4 
5<!-- npu="950" id1 -->5<!-- npu="950" id1 -->
6-- Ascend 950PR/Ascend 950DT:支持6+- Ascend 950PR&950DT系列产品:支持
7<!-- end id1 -->7<!-- end id1 -->
8<!-- npu="A3" id2 -->8<!-- npu="A3" id2 -->
9-- Atlas A3 训练系列产品/Atlas A3 推理系列产品:不支持9+- Atlas A3系列产品:不支持
10<!-- end id2 -->10<!-- end id2 -->
11<!-- npu="910b" id3 -->11<!-- npu="910b" id3 -->
12-- Atlas A2 训练系列产品/Atlas A2 推理系列产品:不支持12+- Atlas A2系列产品:不支持
13<!-- end id3 -->13<!-- end id3 -->
14 14 
15## 功能说明15## 功能说明
@@ -36,7 +36,7 @@ gt(src0, src1, preg) -> dst_mask
36 36 
37## 约束说明37## 约束说明
38 38 
39-无。39+无。
40 40 
41## 返回值说明41## 返回值说明
42 42 
@@ -96,7 +96,7 @@ if __name__ == "__main__":
96 test_example()96 test_example()
97 print("PASSED")97 print("PASSED")
98```98```
99- 99+ 
100### INT64数据类型示例100### INT64数据类型示例
101 101 
102```python102```python
@@ -149,4 +149,4 @@ def test_example_int64():
149if __name__ == "__main__":149if __name__ == "__main__":
150 test_example_int64()150 test_example_int64()
151 print("PASSED")151 print("PASSED")
152-```152+```
@@ -3,13 +3,13 @@
3## 产品支持情况3## 产品支持情况
4 4 
5<!-- npu="950" id1 -->5<!-- npu="950" id1 -->
6-- Ascend 950PR/Ascend 950DT:支持6+- Ascend 950PR&950DT系列产品:支持
7<!-- end id1 -->7<!-- end id1 -->
8<!-- npu="A3" id2 -->8<!-- npu="A3" id2 -->
9-- Atlas A3 训练系列产品/Atlas A3 推理系列产品:不支持9+- Atlas A3系列产品:不支持
10<!-- end id2 -->10<!-- end id2 -->
11<!-- npu="910b" id3 -->11<!-- npu="910b" id3 -->
12-- Atlas A2 训练系列产品/Atlas A2 推理系列产品:不支持12+- Atlas A2系列产品:不支持
13<!-- end id3 -->13<!-- end id3 -->
14 14 
15## 功能说明15## 功能说明
@@ -36,7 +36,7 @@ le(src0, src1, preg) -> dst_mask
36 36 
37## 约束说明37## 约束说明
38 38 
39-无。39+无。
40 40 
41## 返回值说明41## 返回值说明
42 42 
@@ -96,7 +96,7 @@ if __name__ == "__main__":
96 test_example()96 test_example()
97 print("PASSED")97 print("PASSED")
98```98```
99- 99+ 
100### INT64数据类型示例100### INT64数据类型示例
101 101 
102```python102```python
@@ -149,4 +149,4 @@ def test_example_int64():
149if __name__ == "__main__":149if __name__ == "__main__":
150 test_example_int64()150 test_example_int64()
151 print("PASSED")151 print("PASSED")
152-```152+```
@@ -3,13 +3,13 @@
3## 产品支持情况3## 产品支持情况
4 4 
5<!-- npu="950" id1 -->5<!-- npu="950" id1 -->
6-- Ascend 950PR/Ascend 950DT:支持6+- Ascend 950PR&950DT系列产品:支持
7<!-- end id1 -->7<!-- end id1 -->
8<!-- npu="A3" id2 -->8<!-- npu="A3" id2 -->
9-- Atlas A3 训练系列产品/Atlas A3 推理系列产品:不支持9+- Atlas A3系列产品:不支持
10<!-- end id2 -->10<!-- end id2 -->
11<!-- npu="910b" id3 -->11<!-- npu="910b" id3 -->
12-- Atlas A2 训练系列产品/Atlas A2 推理系列产品:不支持12+- Atlas A2系列产品:不支持
13<!-- end id3 -->13<!-- end id3 -->
14 14 
15## 功能说明15## 功能说明
@@ -36,7 +36,7 @@ lt(src0, src1, preg) -> dst_mask
36 36 
37## 约束说明37## 约束说明
38 38 
39-无。39+无。
40 40 
41## 返回值说明41## 返回值说明
42 42 
@@ -96,7 +96,7 @@ if __name__ == "__main__":
96 test_example()96 test_example()
97 print("PASSED")97 print("PASSED")
98```98```
99- 99+ 
100### INT64数据类型示例100### INT64数据类型示例
101 101 
102```python102```python
@@ -149,4 +149,4 @@ def test_example_int64():
149if __name__ == "__main__":149if __name__ == "__main__":
150 test_example_int64()150 test_example_int64()
151 print("PASSED")151 print("PASSED")
152-```152+```
@@ -3,13 +3,13 @@
3## 产品支持情况3## 产品支持情况
4 4 
5<!-- npu="950" id1 -->5<!-- npu="950" id1 -->
6-- Ascend 950PR/Ascend 950DT:支持6+- Ascend 950PR&950DT系列产品:支持
7<!-- end id1 -->7<!-- end id1 -->
8<!-- npu="A3" id2 -->8<!-- npu="A3" id2 -->
9-- Atlas A3 训练系列产品/Atlas A3 推理系列产品:不支持9+- Atlas A3系列产品:不支持
10<!-- end id2 -->10<!-- end id2 -->
11<!-- npu="910b" id3 -->11<!-- npu="910b" id3 -->
12-- Atlas A2 训练系列产品/Atlas A2 推理系列产品:不支持12+- Atlas A2系列产品:不支持
13<!-- end id3 -->13<!-- end id3 -->
14 14 
15## 功能说明15## 功能说明
@@ -36,7 +36,7 @@ ne(src0, src1, preg) -> dst_mask
36 36 
37## 约束说明37## 约束说明
38 38 
39-无。39+无。
40 40 
41## 返回值说明41## 返回值说明
42 42 
@@ -96,7 +96,7 @@ if __name__ == "__main__":
96 test_example()96 test_example()
97 print("PASSED")97 print("PASSED")
98```98```
99- 99+ 
100### INT64数据类型示例100### INT64数据类型示例
101 101 
102```python102```python
@@ -149,4 +149,4 @@ def test_example_int64():
149if __name__ == "__main__":149if __name__ == "__main__":
150 test_example_int64()150 test_example_int64()
151 print("PASSED")151 print("PASSED")
152-```152+```
@@ -3,13 +3,13 @@
3## 产品支持情况3## 产品支持情况
4 4 
5<!-- npu="950" id1 -->5<!-- npu="950" id1 -->
6-- Ascend 950PR/Ascend 950DT:支持6+- Ascend 950PR&950DT系列产品:支持
7<!-- end id1 -->7<!-- end id1 -->
8<!-- npu="A3" id2 -->8<!-- npu="A3" id2 -->
9-- Atlas A3 训练系列产品/Atlas A3 推理系列产品:不支持9+- Atlas A3系列产品:不支持
10<!-- end id2 -->10<!-- end id2 -->
11<!-- npu="910b" id3 -->11<!-- npu="910b" id3 -->
12-- Atlas A2 训练系列产品/Atlas A2 推理系列产品:不支持12+- Atlas A2系列产品:不支持
13<!-- end id3 -->13<!-- end id3 -->
14 14 
15## 功能说明15## 功能说明
@@ -34,7 +34,7 @@ select(src0, src1, preg) -> dst
34 34 
35## 约束说明35## 约束说明
36 36 
37-无。37+无。
38 38 
39## 返回值说明39## 返回值说明
40 40 
@@ -200,49 +200,49 @@ if __name__ == "__main__":
200 test_example()200 test_example()
201 print("PASSED")201 print("PASSED")
202```202```
203- 203+ 
204-### INT64数据类型示例204+### INT64数据类型示例
205- 205+ 
206-```python206+```python
207-import os207+import os
208-import pypto_pro.language as pl208+import pypto_pro.language as pl
209-import torch209+import torch
210-import torch_npu210+import torch_npu
211- 211+ 
212-@pl.vector_function212+@pl.vector_function
213-def example_vf_int64(src_tile, dst_tile):213+def example_vf_int64(src_tile, dst_tile):
214- preg = vf.create_mask(pattern=pl.MaskPattern.ALL, dtype=pl.DT_INT64)214+ preg = vf.create_mask(pattern=pl.MaskPattern.ALL, dtype=pl.DT_INT64)
215- reg_a = vf.load_align(src_tile, 0)215+ reg_a = vf.load_align(src_tile, 0)
216- reg_out = vf.select(reg_a, reg_a, preg)216+ reg_out = vf.select(reg_a, reg_a, preg)
217- vf.store_align(dst_tile, reg_out, preg)217+ vf.store_align(dst_tile, reg_out, preg)
218- 218+ 
219-@pl.jit()219+@pl.jit()
220-def example_kernel_int64(220+def example_kernel_int64(
221- a: pl.Tensor[[pl.DYNAMIC, pl.DYNAMIC], pl.DT_INT64],221+ a: pl.Tensor[[pl.DYNAMIC, pl.DYNAMIC], pl.DT_INT64],
222- out: pl.Tensor[[pl.DYNAMIC, pl.DYNAMIC], pl.DT_INT64],222+ out: pl.Tensor[[pl.DYNAMIC, pl.DYNAMIC], pl.DT_INT64],
223-):223+):
224- tf = pl.TileType(shape=[1, 32], dtype=pl.DT_INT64, target_memory=pl.MemorySpace.Vec)224+ tf = pl.TileType(shape=[1, 32], dtype=pl.DT_INT64, target_memory=pl.MemorySpace.Vec)
225 in_a_grp = pl.make_tile_group(type=tf, addrs=0, mutex_ids=[0])225 in_a_grp = pl.make_tile_group(type=tf, addrs=0, mutex_ids=[0])
226 in_a = in_a_grp.current()226 in_a = in_a_grp.current()
227 t_out_grp = pl.make_tile_group(type=tf, addrs=256, mutex_ids=[1])227 t_out_grp = pl.make_tile_group(type=tf, addrs=256, mutex_ids=[1])
228 t_out = t_out_grp.current()228 t_out = t_out_grp.current()
229- with pl.section_vector():229+ with pl.section_vector():
230- pl.load(in_a, a, [0, 0])230+ pl.load(in_a, a, [0, 0])
231- example_vf_int64(in_a, t_out)231+ example_vf_int64(in_a, t_out)
232- pl.store(out, t_out, [0, 0])232+ pl.store(out, t_out, [0, 0])
233- 233+ 
234-def test_example_int64():234+def test_example_int64():
235- device_id = int(os.environ.get("TILE_FWK_DEVICE_ID", 0))235+ device_id = int(os.environ.get("TILE_FWK_DEVICE_ID", 0))
236- device = f"npu:{device_id}"236+ device = f"npu:{device_id}"
237- core_nums = 1237+ core_nums = 1
238- torch.npu.set_device(device)238+ torch.npu.set_device(device)
239- a = torch.randint(-100, 100, [1, 32], device=device, dtype=torch.int64)239+ a = torch.randint(-100, 100, [1, 32], device=device, dtype=torch.int64)
240- out = torch.empty([1, 32], device=device, dtype=torch.int64)240+ out = torch.empty([1, 32], device=device, dtype=torch.int64)
241- example_kernel_int64[None, core_nums](a, out)241+ example_kernel_int64[None, core_nums](a, out)
242- torch.npu.synchronize()242+ torch.npu.synchronize()
243- torch.testing.assert_close(out, a, rtol=0, atol=0)243+ torch.testing.assert_close(out, a, rtol=0, atol=0)
244- 244+ 
245-if __name__ == "__main__":245+if __name__ == "__main__":
246- test_example_int64()246+ test_example_int64()
247- print("PASSED")247+ print("PASSED")
248```248```
@@ -3,13 +3,13 @@
3## 产品支持情况3## 产品支持情况
4 4 
5<!-- npu="950" id1 -->5<!-- npu="950" id1 -->
6-- Ascend 950PR/Ascend 950DT:支持6+- Ascend 950PR&950DT系列产品:支持
7<!-- end id1 -->7<!-- end id1 -->
8<!-- npu="A3" id2 -->8<!-- npu="A3" id2 -->
9-- Atlas A3 训练系列产品/Atlas A3 推理系列产品:不支持9+- Atlas A3系列产品:不支持
10<!-- end id2 -->10<!-- end id2 -->
11<!-- npu="910b" id3 -->11<!-- npu="910b" id3 -->
12-- Atlas A2 训练系列产品/Atlas A2 推理系列产品:不支持12+- Atlas A2系列产品:不支持
13<!-- end id3 -->13<!-- end id3 -->
14 14 
15## 功能说明15## 功能说明
@@ -40,7 +40,7 @@ squeeze(src, preg, gather_mode: Optional[SqueezeMode] = None) -> dst
40 40 
41## 约束说明41## 约束说明
42 42 
43-无。43+无。
44 44 
45## 返回值说明45## 返回值说明
46 46 
@@ -3,13 +3,13 @@
3## 产品支持情况3## 产品支持情况
4 4 
5<!-- npu="950" id1 -->5<!-- npu="950" id1 -->
6-- Ascend 950PR/Ascend 950DT:支持6+- Ascend 950PR&950DT系列产品:支持
7<!-- end id1 -->7<!-- end id1 -->
8<!-- npu="A3" id2 -->8<!-- npu="A3" id2 -->
9-- Atlas A3 训练系列产品/Atlas A3 推理系列产品:不支持9+- Atlas A3系列产品:不支持
10<!-- end id2 -->10<!-- end id2 -->
11<!-- npu="910b" id3 -->11<!-- npu="910b" id3 -->
12-- Atlas A2 训练系列产品/Atlas A2 推理系列产品:不支持12+- Atlas A2系列产品:不支持
13<!-- end id3 -->13<!-- end id3 -->
14 14 
15## 功能说明15## 功能说明
@@ -35,11 +35,11 @@ abs_sub(src0, src1, preg, mode: Optional[MergeMode] = None) -> dst
35| src0 | 输入 | 源操作数0,[reg_tensor](../reg_tensor.md),支持的数据类型为:DT_FP16、DT_FP32、DT_INT64。 |35| src0 | 输入 | 源操作数0,[reg_tensor](../reg_tensor.md),支持的数据类型为:DT_FP16、DT_FP32、DT_INT64。 |
36| src1 | 输入 | 源操作数1,[reg_tensor](../reg_tensor.md),支持的数据类型和src0中的说明一致。 |36| src1 | 输入 | 源操作数1,[reg_tensor](../reg_tensor.md),支持的数据类型和src0中的说明一致。 |
37| preg | 输入 | [mask_reg](../mask_reg.md)。 |37| preg | 输入 | [mask_reg](../mask_reg.md)。 |
38-| mode | 输入 | 可选,对应[MergeMode](../types/MergeMode.md)类型。<br>- pypto_pro.language.MergeMode.ZEROING(默认),preg未筛选的元素在dst中置0。<br>- pypto_pro.language.MergeMode.MERGING当前不支持。 |38+| mode | 输入 | 可选,对应[MergeMode](../types/MergeMode.md)类型。<br>- pypto_pro.language.MergeMode.ZEROING(默认),preg未筛选的元素在dst中置0。<br>- pypto_pro.language.MergeMode.MERGING当前不支持。 |
39 39 
40## 约束说明40## 约束说明
41 41 
42-无。42+无。
43 43 
44## 返回值说明44## 返回值说明
45 45 
@@ -3,13 +3,13 @@
3## 产品支持情况3## 产品支持情况
4 4 
5<!-- npu="950" id1 -->5<!-- npu="950" id1 -->
6-- Ascend 950PR/Ascend 950DT:支持6+- Ascend 950PR&950DT系列产品:支持
7<!-- end id1 -->7<!-- end id1 -->
8<!-- npu="A3" id2 -->8<!-- npu="A3" id2 -->
9-- Atlas A3 训练系列产品/Atlas A3 推理系列产品:不支持9+- Atlas A3系列产品:不支持
10<!-- end id2 -->10<!-- end id2 -->
11<!-- npu="910b" id3 -->11<!-- npu="910b" id3 -->
12-- Atlas A2 训练系列产品/Atlas A2 推理系列产品:不支持12+- Atlas A2系列产品:不支持
13<!-- end id3 -->13<!-- end id3 -->
14 14 
15## 功能说明15## 功能说明
@@ -33,11 +33,11 @@ axpy(src, scalar, preg, mode: Optional[MergeMode] = None) -> dst
33| src | 输入 | 源操作数,[reg_tensor](../reg_tensor.md),源操作数src、scalar与目的操作数dst的数据类型保持一致。支持的数据类型为:DT_FP16、DT_FP32、DT_INT64、DT_UINT64。 |33| src | 输入 | 源操作数,[reg_tensor](../reg_tensor.md),源操作数src、scalar与目的操作数dst的数据类型保持一致。支持的数据类型为:DT_FP16、DT_FP32、DT_INT64、DT_UINT64。 |
34| scalar | 输入 | 标量源操作数。 |34| scalar | 输入 | 标量源操作数。 |
35| preg | 输入 | [mask_reg](../mask_reg.md)。 - 本接口支持寄存器重叠。 |35| preg | 输入 | [mask_reg](../mask_reg.md)。 - 本接口支持寄存器重叠。 |
36-| mode | 输入 | 可选,对应[MergeMode](../types/MergeMode.md)类型。<br>- pypto_pro.language.MergeMode.ZEROING(默认),preg未筛选的元素在dst中置0。<br>- pypto_pro.language.MergeMode.MERGING当前不支持。 |36+| mode | 输入 | 可选,对应[MergeMode](../types/MergeMode.md)类型。<br>- pypto_pro.language.MergeMode.ZEROING(默认),preg未筛选的元素在dst中置0。<br>- pypto_pro.language.MergeMode.MERGING当前不支持。 |
37 37 
38## 约束说明38## 约束说明
39 39 
40-无。40+无。
41 41 
42## 返回值说明42## 返回值说明
43 43 
@@ -3,13 +3,13 @@
3## 产品支持情况3## 产品支持情况
4 4 
5<!-- npu="950" id1 -->5<!-- npu="950" id1 -->
6-- Ascend 950PR/Ascend 950DT:支持6+- Ascend 950PR&950DT系列产品:支持
7<!-- end id1 -->7<!-- end id1 -->
8<!-- npu="A3" id2 -->8<!-- npu="A3" id2 -->
9-- Atlas A3 训练系列产品/Atlas A3 推理系列产品:不支持9+- Atlas A3系列产品:不支持
10<!-- end id2 -->10<!-- end id2 -->
11<!-- npu="910b" id3 -->11<!-- npu="910b" id3 -->
12-- Atlas A2 训练系列产品/Atlas A2 推理系列产品:不支持12+- Atlas A2系列产品:不支持
13<!-- end id3 -->13<!-- end id3 -->
14 14 
15## 功能说明15## 功能说明
@@ -41,8 +41,8 @@ exp_sub(src0, src1, preg, layout: Optional[CastLayout] = None, dtype: Optional[D
41| src0 | 输入 | 源操作数0,[reg_tensor](../reg_tensor.md),支持的数据类型请参见[约束说明](#约束说明)。 |41| src0 | 输入 | 源操作数0,[reg_tensor](../reg_tensor.md),支持的数据类型请参见[约束说明](#约束说明)。 |
42| src1 | 输入 | 源操作数1,[reg_tensor](../reg_tensor.md),支持的数据类型请参见[约束说明](#约束说明)。 |42| src1 | 输入 | 源操作数1,[reg_tensor](../reg_tensor.md),支持的数据类型请参见[约束说明](#约束说明)。 |
43| preg | 输入 | [mask_reg](../mask_reg.md)。 |43| preg | 输入 | [mask_reg](../mask_reg.md)。 |
44-| layout | 输入 | 可选,决定结果放置半区。pypto_pro.language.CastLayout.ZERO(偶数半区,默认)或pypto_pro.language.CastLayout.ONE(奇数半区)。<br>- src类型为DT_FP16类型时,支持pypto_pro.language.CastLayout.ZERO和pypto_pro.language.CastLayout.ONE。<br>- src类型为DT_FP32类型时,配置不生效。|44+| layout | 输入 | 可选,决定结果放置半区。pypto_pro.language.CastLayout.ZERO(偶数半区,默认)或pypto_pro.language.CastLayout.ONE(奇数半区)。<br>- src类型为DT_FP16类型时,支持pypto_pro.language.CastLayout.ZERO和pypto_pro.language.CastLayout.ONE。<br>- src类型为DT_FP32类型时,配置不生效。|
45-| dtype | 输入 | 可选,目标reg_tensor数据类型。当src为DT_FP16时,指定dtype=pypto_pro.language.DT_FP32可将源操作数提升精度到DT_FP32再进行计算,产生DT_FP32结果。 |45+| dtype | 输入 | 可选,目标reg_tensor数据类型。当src为DT_FP16时,指定dtype=pypto_pro.language.DT_FP32可将源操作数提升精度到DT_FP32再进行计算,产生DT_FP32结果。 |
46 46 
47## 约束说明47## 约束说明
48 48 
@@ -59,7 +59,7 @@ exp_sub(src0, src1, preg, layout: Optional[CastLayout] = None, dtype: Optional[D
59 59 
60 **图1** exp_sub高精度示意图60 **图1** exp_sub高精度示意图
61 61 
62- ![](../../../figures/exp_sub_high_precision.jpg)62+ ![](../../../figures/exp_sub_high_precision.jpg)
63 63 
64## 返回值说明64## 返回值说明
65 65 
@@ -121,7 +121,7 @@ if __name__ == "__main__":
121 121 
122### DT_FP16源 → DT_FP32结果122### DT_FP16源 → DT_FP32结果
123 123 
124-当源操作数为DT_FP16、目的操作数为DT_FP32时,寄存器中128个DT_FP16元素按相邻两两分组,layout决定每组中参与计算的元素位置:pypto_pro.language.CastLayout.ZERO(默认)取偶数位(第0个),pypto_pro.language.CastLayout.ONE取奇数位(第1个)。最终输出64个DT_FP32元素。以下示例使用默认的layout=ZERO,即取每组偶数位元素参与计算。124+当源操作数为DT_FP16、目的操作数为DT_FP32时,寄存器中128个DT_FP16元素按相邻两两分组,layout决定每组中参与计算的元素位置:pypto_pro.language.CastLayout.ZERO(默认)取偶数位(第0个),pypto_pro.language.CastLayout.ONE取奇数位(第1个)。最终输出64个DT_FP32元素。以下示例使用默认的layout=ZERO,即取每组偶数位元素参与计算。
125 125 
126```python126```python
127import os127import os
@@ -3,13 +3,13 @@
3## 产品支持情况3## 产品支持情况
4 4 
5<!-- npu="950" id1 -->5<!-- npu="950" id1 -->
6-- Ascend 950PR/Ascend 950DT:支持6+- Ascend 950PR&950DT系列产品:支持
7<!-- end id1 -->7<!-- end id1 -->
8<!-- npu="A3" id2 -->8<!-- npu="A3" id2 -->
9-- Atlas A3 训练系列产品/Atlas A3 推理系列产品:不支持9+- Atlas A3系列产品:不支持
10<!-- end id2 -->10<!-- end id2 -->
11<!-- npu="910b" id3 -->11<!-- npu="910b" id3 -->
12-- Atlas A2 训练系列产品/Atlas A2 推理系列产品:不支持12+- Atlas A2系列产品:不支持
13<!-- end id3 -->13<!-- end id3 -->
14 14 
15## 功能说明15## 功能说明
@@ -37,11 +37,11 @@ mul_add_dst(src0, src1, preg, mode: Optional[MergeMode] = None) -> dst
37| src0 | 输入 | 源操作数0,[reg_tensor](../reg_tensor.md),源操作数src0、src1与目的操作数dst的数据类型保持一致。支持的数据类型为:DT_INT16、DT_UINT16、DT_INT32、DT_UINT32、DT_FP16、DT_BF16、DT_FP32。 |37| src0 | 输入 | 源操作数0,[reg_tensor](../reg_tensor.md),源操作数src0、src1与目的操作数dst的数据类型保持一致。支持的数据类型为:DT_INT16、DT_UINT16、DT_INT32、DT_UINT32、DT_FP16、DT_BF16、DT_FP32。 |
38| src1 | 输入 | 源操作数1,[reg_tensor](../reg_tensor.md),数据类型与src0一致。 |38| src1 | 输入 | 源操作数1,[reg_tensor](../reg_tensor.md),数据类型与src0一致。 |
39| preg | 输入 | [mask_reg](../mask_reg.md)。 |39| preg | 输入 | [mask_reg](../mask_reg.md)。 |
40-| mode | 输入 | 可选,对应[MergeMode](../types/MergeMode.md)类型。<br>- pypto_pro.language.MergeMode.ZEROING(默认),preg未筛选的元素在dst中置0。<br>- pypto_pro.language.MergeMode.MERGING当前不支持。 |40+| mode | 输入 | 可选,对应[MergeMode](../types/MergeMode.md)类型。<br>- pypto_pro.language.MergeMode.ZEROING(默认),preg未筛选的元素在dst中置0。<br>- pypto_pro.language.MergeMode.MERGING当前不支持。 |
41 41 
42## 约束说明42## 约束说明
43 43 
44-无。44+无。
45 45 
46## 返回值说明46## 返回值说明
47 47 
@@ -3,13 +3,13 @@
3## 产品支持情况3## 产品支持情况
4 4 
5<!-- npu="950" id1 -->5<!-- npu="950" id1 -->
6-- Ascend 950PR/Ascend 950DT:支持6+- Ascend 950PR&950DT系列产品:支持
7<!-- end id1 -->7<!-- end id1 -->
8<!-- npu="A3" id2 -->8<!-- npu="A3" id2 -->
9-- Atlas A3 训练系列产品/Atlas A3 推理系列产品:不支持9+- Atlas A3系列产品:不支持
10<!-- end id2 -->10<!-- end id2 -->
11<!-- npu="910b" id3 -->11<!-- npu="910b" id3 -->
12-- Atlas A2 训练系列产品/Atlas A2 推理系列产品:不支持12+- Atlas A2系列产品:不支持
13<!-- end id3 -->13<!-- end id3 -->
14 14 
15## 功能说明15## 功能说明
@@ -37,11 +37,11 @@ mul_dst_add(src0, src1, preg, mode: Optional[MergeMode] = None) -> dst
37| src0 | 输入 | 源操作数0(乘数),[reg_tensor](../reg_tensor.md),源操作数src0、src1与目的操作数dst的数据类型保持一致。支持的数据类型为:DT_FP16、DT_BF16、DT_FP32。 |37| src0 | 输入 | 源操作数0(乘数),[reg_tensor](../reg_tensor.md),源操作数src0、src1与目的操作数dst的数据类型保持一致。支持的数据类型为:DT_FP16、DT_BF16、DT_FP32。 |
38| src1 | 输入 | 源操作数1(加数),[reg_tensor](../reg_tensor.md),数据类型与src0一致。 |38| src1 | 输入 | 源操作数1(加数),[reg_tensor](../reg_tensor.md),数据类型与src0一致。 |
39| preg | 输入 | [mask_reg](../mask_reg.md)。 |39| preg | 输入 | [mask_reg](../mask_reg.md)。 |
40-| mode | 输入 | 可选,对应[MergeMode](../types/MergeMode.md)类型。<br>- pypto_pro.language.MergeMode.ZEROING(默认),preg未筛选的元素在dst中置0。<br>- pypto_pro.language.MergeMode.MERGING当前不支持。 |40+| mode | 输入 | 可选,对应[MergeMode](../types/MergeMode.md)类型。<br>- pypto_pro.language.MergeMode.ZEROING(默认),preg未筛选的元素在dst中置0。<br>- pypto_pro.language.MergeMode.MERGING当前不支持。 |
41 41 
42## 约束说明42## 约束说明
43 43 
44-无。44+无。
45 45 
46## 返回值说明46## 返回值说明
47 47 
@@ -3,13 +3,13 @@
3## 产品支持情况3## 产品支持情况
4 4 
5<!-- npu="950" id1 -->5<!-- npu="950" id1 -->
6-- Ascend 950PR/Ascend 950DT:支持6+- Ascend 950PR&950DT系列产品:支持
7<!-- end id1 -->7<!-- end id1 -->
8<!-- npu="A3" id2 -->8<!-- npu="A3" id2 -->
9-- Atlas A3 训练系列产品/Atlas A3 推理系列产品:不支持9+- Atlas A3系列产品:不支持
10<!-- end id2 -->10<!-- end id2 -->
11<!-- npu="910b" id3 -->11<!-- npu="910b" id3 -->
12-- Atlas A2 训练系列产品/Atlas A2 推理系列产品:不支持12+- Atlas A2系列产品:不支持
13<!-- end id3 -->13<!-- end id3 -->
14 14 
15## 功能说明15## 功能说明
@@ -33,8 +33,8 @@ muls_cast(src, scalar, preg, dtype: DType, layout: Optional[CastLayout] = None)
33| src | 输入 | 源操作数,[reg_tensor](../reg_tensor.md),支持的数据类型请参见[约束说明](#约束说明)。 |33| src | 输入 | 源操作数,[reg_tensor](../reg_tensor.md),支持的数据类型请参见[约束说明](#约束说明)。 |
34| scalar | 输入 | 标量源操作数。 |34| scalar | 输入 | 标量源操作数。 |
35| preg | 输入 | [mask_reg](../mask_reg.md)。 |35| preg | 输入 | [mask_reg](../mask_reg.md)。 |
36-| dtype | 输入 | 指定目标reg_tensor的数据类型,支持的数据类型请参见[约束说明](#约束说明)。由于乘法后进行类型转换(DT_FP32→DT_FP16),目标类型与源类型不同,必须显式指定,通常为pypto_pro.language.DT_FP16。 |36+| dtype | 输入 | 指定目标reg_tensor的数据类型,支持的数据类型请参见[约束说明](#约束说明)。由于乘法后进行类型转换(DT_FP32→DT_FP16),目标类型与源类型不同,必须显式指定,通常为pypto_pro.language.DT_FP16。 |
37-| layout | 输入 | 可选,结果放置半区:pypto_pro.language.CastLayout.ZERO(偶数半区,默认,PART_EVEN)或pypto_pro.language.CastLayout.ONE(奇数半区,PART_ODD),对应[CastLayout](../types/CastLayout.md)类型。计算按照CAST_ROUND模式舍入。 |37+| layout | 输入 | 可选,结果放置半区:pypto_pro.language.CastLayout.ZERO(偶数半区,默认,PART_EVEN)或pypto_pro.language.CastLayout.ONE(奇数半区,PART_ODD),对应[CastLayout](../types/CastLayout.md)类型。计算按照CAST_ROUND模式舍入。 |
38 38 
39## 约束说明39## 约束说明
40 40 
@@ -3,18 +3,18 @@
3## 产品支持情况3## 产品支持情况
4 4 
5<!-- npu="950" id1 -->5<!-- npu="950" id1 -->
6-- Ascend 950PR/Ascend 950DT:支持6+- Ascend 950PR&950DT系列产品:支持
7<!-- end id1 -->7<!-- end id1 -->
8<!-- npu="A3" id2 -->8<!-- npu="A3" id2 -->
9-- Atlas A3 训练系列产品/Atlas A3 推理系列产品:不支持9+- Atlas A3系列产品:不支持
10<!-- end id2 -->10<!-- end id2 -->
11<!-- npu="910b" id3 -->11<!-- npu="910b" id3 -->
12-- Atlas A2 训练系列产品/Atlas A2 推理系列产品:不支持12+- Atlas A2系列产品:不支持
13<!-- end id3 -->13<!-- end id3 -->
14 14 
15## 功能说明15## 功能说明
16 16 
17-清除特殊寄存器(AddrReg寄存器),重置某些VF指令使用的累加寄存器。通常在 @pypto_pro.language.vector_function函数的开头或结尾调用。17+清除特殊寄存器(AddrReg寄存器),重置某些VF指令使用的累加寄存器。通常在 @pypto_pro.language.vector_function函数的开头或结尾调用。
18 18 
19## 函数原型19## 函数原型
20 20 
@@ -28,11 +28,11 @@ clear_spr()
28 28 
29## 约束说明29## 约束说明
30 30 
31-无。31+无。
32 32 
33## 返回值说明33## 返回值说明
34 34 
35-无。35+无。
36 36 
37## 调用示例37## 调用示例
38 38 
@@ -3,13 +3,13 @@
3## 产品支持情况3## 产品支持情况
4 4 
5<!-- npu="950" id1 -->5<!-- npu="950" id1 -->
6-- Ascend 950PR/Ascend 950DT:支持6+- Ascend 950PR&950DT系列产品:支持
7<!-- end id1 -->7<!-- end id1 -->
8<!-- npu="A3" id2 -->8<!-- npu="A3" id2 -->
9-- Atlas A3 训练系列产品/Atlas A3 推理系列产品:不支持9+- Atlas A3系列产品:不支持
10<!-- end id2 -->10<!-- end id2 -->
11<!-- npu="910b" id3 -->11<!-- npu="910b" id3 -->
12-- Atlas A2 训练系列产品/Atlas A2 推理系列产品:不支持12+- Atlas A2系列产品:不支持
13<!-- end id3 -->13<!-- end id3 -->
14 14 
15## 功能说明15## 功能说明
@@ -32,7 +32,7 @@ create_addr_reg(stride0, stride1=None, stride2=None, stride3=None, dtype: Option
32| stride1 | 输入 | 可选,第二层循环轴对应的地址偏移量,单位为元素个数。 |32| stride1 | 输入 | 可选,第二层循环轴对应的地址偏移量,单位为元素个数。 |
33| stride2 | 输入 | 可选,第三层循环轴对应的地址偏移量,单位为元素个数。 |33| stride2 | 输入 | 可选,第三层循环轴对应的地址偏移量,单位为元素个数。 |
34| stride3 | 输入 | 可选,第四层循环轴对应的地址偏移量,单位为元素个数。 |34| stride3 | 输入 | 可选,第四层循环轴对应的地址偏移量,单位为元素个数。 |
35-| dtype | 输入 | 可选,模板参数对应的数据类型(默认pypto_pro.language.DT_FP32)。决定元素宽度:8位宽(DT_INT8、DT_UINT8)/16位宽(DT_INT16、DT_UINT16、DT_FP16、DT_BF16)/32位宽(DT_INT32、DT_UINT32、DT_FP32)/64位宽(DT_INT64、DT_UINT64)。 |35+| dtype | 输入 | 可选,模板参数对应的数据类型(默认pypto_pro.language.DT_FP32)。决定元素宽度:8位宽(DT_INT8、DT_UINT8)/16位宽(DT_INT16、DT_UINT16、DT_FP16、DT_BF16)/32位宽(DT_INT32、DT_UINT32、DT_FP32)/64位宽(DT_INT64、DT_UINT64)。 |
36 36 
37## 约束说明37## 约束说明
38 38 
@@ -3,13 +3,13 @@
3## 产品支持情况3## 产品支持情况
4 4 
5<!-- npu="950" id1 -->5<!-- npu="950" id1 -->
6-- Ascend 950PR/Ascend 950DT:支持6+- Ascend 950PR&950DT系列产品:支持
7<!-- end id1 -->7<!-- end id1 -->
8<!-- npu="A3" id2 -->8<!-- npu="A3" id2 -->
9-- Atlas A3 训练系列产品/Atlas A3 推理系列产品:不支持9+- Atlas A3系列产品:不支持
10<!-- end id2 -->10<!-- end id2 -->
11<!-- npu="910b" id3 -->11<!-- npu="910b" id3 -->
12-- Atlas A2 训练系列产品/Atlas A2 推理系列产品:不支持12+- Atlas A2系列产品:不支持
13<!-- end id3 -->13<!-- end id3 -->
14 14 
15## 功能说明15## 功能说明
@@ -32,12 +32,12 @@ full(src, preg, dtype: Optional[DType] = None, mode: Optional[MergeMode] = None,
32| src | 输入 | 源操作数,为标量值或者[reg_tensor](../reg_tensor.md)。源操作数src与目的操作数dst的数据类型保持一致。<br>- **Scalar模式**:标量值,广播到寄存器各元素。支持的数据类型为:DT_INT8、DT_UINT8、DT_INT16、DT_UINT16、DT_FP16、DT_BF16、DT_INT32、DT_UINT32、DT_FP32、DT_INT64、DT_UINT64。<br>- **Tensor模式**:[reg_tensor](../reg_tensor.md),广播其最低位或最高位元素。支持的数据类型为:DT_INT8、DT_UINT8、DT_INT16、DT_UINT16、DT_FP16、DT_BF16、DT_INT32、DT_UINT32、DT_FP32、DT_INT64、DT_UINT64、DT_FP8E4M3FN、DT_FP8E5M2、DT_FP8E8M0、DT_HF8、DT_FP4E2M1、DT_FP4E1M2。 |32| src | 输入 | 源操作数,为标量值或者[reg_tensor](../reg_tensor.md)。源操作数src与目的操作数dst的数据类型保持一致。<br>- **Scalar模式**:标量值,广播到寄存器各元素。支持的数据类型为:DT_INT8、DT_UINT8、DT_INT16、DT_UINT16、DT_FP16、DT_BF16、DT_INT32、DT_UINT32、DT_FP32、DT_INT64、DT_UINT64。<br>- **Tensor模式**:[reg_tensor](../reg_tensor.md),广播其最低位或最高位元素。支持的数据类型为:DT_INT8、DT_UINT8、DT_INT16、DT_UINT16、DT_FP16、DT_BF16、DT_INT32、DT_UINT32、DT_FP32、DT_INT64、DT_UINT64、DT_FP8E4M3FN、DT_FP8E5M2、DT_FP8E8M0、DT_HF8、DT_FP4E2M1、DT_FP4E1M2。 |
33| preg | 输入 | [mask_reg](../mask_reg.md)。Tensor模式必选;Scalar模式可选。 |33| preg | 输入 | [mask_reg](../mask_reg.md)。Tensor模式必选;Scalar模式可选。 |
34| dtype | 输入 | 可选,指定数据类型。Scalar模式必须输入,Tensor模式可从源寄存器自动推断。 |34| dtype | 输入 | 可选,指定数据类型。Scalar模式必须输入,Tensor模式可从源寄存器自动推断。 |
35-| mode | 输入 | 可选,对应[MergeMode](../types/MergeMode.md)类型。<br>- pypto_pro.language.MergeMode.ZEROING(默认),preg未筛选的元素在dst中置0。<br>- pypto_pro.language.MergeMode.MERGING当前不支持。 |35+| mode | 输入 | 可选,对应[MergeMode](../types/MergeMode.md)类型。<br>- pypto_pro.language.MergeMode.ZEROING(默认),preg未筛选的元素在dst中置0。<br>- pypto_pro.language.MergeMode.MERGING当前不支持。 |
36-| pos | 输入 | 可选,Tensor模式下选择广播源reg_tensor的哪个元素,对应[DuplicatePos](../types/DuplicatePos.md)类型:<br>- pypto_pro.language.DuplicatePos.LOWEST:默认,广播最低位的元素。<br>- pypto_pro.language.DuplicatePos.HIGHEST:指定广播最高位的元素。 |36+| pos | 输入 | 可选,Tensor模式下选择广播源reg_tensor的哪个元素,对应[DuplicatePos](../types/DuplicatePos.md)类型:<br>- pypto_pro.language.DuplicatePos.LOWEST:默认,广播最低位的元素。<br>- pypto_pro.language.DuplicatePos.HIGHEST:指定广播最高位的元素。 |
37 37 
38## 约束说明38## 约束说明
39 39 
40-无。40+无。
41 41 
42## 返回值说明42## 返回值说明
43 43 
@@ -286,49 +286,49 @@ if __name__ == "__main__":
286 test_example_fp8e8m0()286 test_example_fp8e8m0()
287 print("PASSED")287 print("PASSED")
288```288```
289- 289+ 
290-### INT64数据类型示例290+### INT64数据类型示例
291- 291+ 
292-```python292+```python
293-import os293+import os
294-import pypto_pro.language as pl294+import pypto_pro.language as pl
295-import torch295+import torch
296-import torch_npu296+import torch_npu
297- 297+ 
298-@pl.vector_function298+@pl.vector_function
299-def example_vf_int64(src_tile, dst_tile):299+def example_vf_int64(src_tile, dst_tile):
300- preg = vf.create_mask(pattern=pl.MaskPattern.ALL, dtype=pl.DT_INT64)300+ preg = vf.create_mask(pattern=pl.MaskPattern.ALL, dtype=pl.DT_INT64)
301- reg_a = vf.load_align(src_tile, 0)301+ reg_a = vf.load_align(src_tile, 0)
302- reg_out = vf.full(42, preg, dtype=pl.DT_INT64)302+ reg_out = vf.full(42, preg, dtype=pl.DT_INT64)
303- vf.store_align(dst_tile, reg_out, preg)303+ vf.store_align(dst_tile, reg_out, preg)
304- 304+ 
305-@pl.jit()305+@pl.jit()
306-def example_kernel_int64(306+def example_kernel_int64(
307- a: pl.Tensor[[pl.DYNAMIC, pl.DYNAMIC], pl.DT_INT64],307+ a: pl.Tensor[[pl.DYNAMIC, pl.DYNAMIC], pl.DT_INT64],
308- out: pl.Tensor[[pl.DYNAMIC, pl.DYNAMIC], pl.DT_INT64],308+ out: pl.Tensor[[pl.DYNAMIC, pl.DYNAMIC], pl.DT_INT64],
309-):309+):
310- tf = pl.TileType(shape=[1, 32], dtype=pl.DT_INT64, target_memory=pl.MemorySpace.Vec)310+ tf = pl.TileType(shape=[1, 32], dtype=pl.DT_INT64, target_memory=pl.MemorySpace.Vec)
311 in_a_grp = pl.make_tile_group(type=tf, addrs=0, mutex_ids=[0])311 in_a_grp = pl.make_tile_group(type=tf, addrs=0, mutex_ids=[0])
312 in_a = in_a_grp.current()312 in_a = in_a_grp.current()
313 t_out_grp = pl.make_tile_group(type=tf, addrs=256, mutex_ids=[1])313 t_out_grp = pl.make_tile_group(type=tf, addrs=256, mutex_ids=[1])
314 t_out = t_out_grp.current()314 t_out = t_out_grp.current()
315- with pl.section_vector():315+ with pl.section_vector():
316- pl.load(in_a, a, [0, 0])316+ pl.load(in_a, a, [0, 0])
317- example_vf_int64(in_a, t_out)317+ example_vf_int64(in_a, t_out)
318- pl.store(out, t_out, [0, 0])318+ pl.store(out, t_out, [0, 0])
319- 319+ 
320-def test_example_int64():320+def test_example_int64():
321- device_id = int(os.environ.get("TILE_FWK_DEVICE_ID", 0))321+ device_id = int(os.environ.get("TILE_FWK_DEVICE_ID", 0))
322- device = f"npu:{device_id}"322+ device = f"npu:{device_id}"
323- core_nums = 1323+ core_nums = 1
324- torch.npu.set_device(device)324+ torch.npu.set_device(device)
325- a = torch.randint(-100, 100, [1, 32], device=device, dtype=torch.int64)325+ a = torch.randint(-100, 100, [1, 32], device=device, dtype=torch.int64)
326- out = torch.empty([1, 32], device=device, dtype=torch.int64)326+ out = torch.empty([1, 32], device=device, dtype=torch.int64)
327- example_kernel_int64[None, core_nums](a, out)327+ example_kernel_int64[None, core_nums](a, out)
328- torch.npu.synchronize()328+ torch.npu.synchronize()
329- torch.testing.assert_close(out, torch.full([1, 32], 42, dtype=torch.int64, device=device), rtol=0, atol=0)329+ torch.testing.assert_close(out, torch.full([1, 32], 42, dtype=torch.int64, device=device), rtol=0, atol=0)
330- 330+ 
331-if __name__ == "__main__":331+if __name__ == "__main__":
332- test_example_int64()332+ test_example_int64()
333- print("PASSED")333+ print("PASSED")
334```334```
@@ -3,13 +3,13 @@
3## 产品支持情况3## 产品支持情况
4 4 
5<!-- npu="950" id1 -->5<!-- npu="950" id1 -->
6-- Ascend 950PR/Ascend 950DT:支持6+- Ascend 950PR&950DT系列产品:支持
7<!-- end id1 -->7<!-- end id1 -->
8<!-- npu="A3" id2 -->8<!-- npu="A3" id2 -->
9-- Atlas A3 训练系列产品/Atlas A3 推理系列产品:不支持9+- Atlas A3系列产品:不支持
10<!-- end id2 -->10<!-- end id2 -->
11<!-- npu="910b" id3 -->11<!-- npu="910b" id3 -->
12-- Atlas A2 训练系列产品/Atlas A2 推理系列产品:不支持12+- Atlas A2系列产品:不支持
13<!-- end id3 -->13<!-- end id3 -->
14 14 
15## 功能说明15## 功能说明
@@ -18,17 +18,17 @@
18 18 
19**Tile→reg形式**(src为Tile):从Tile中按索引收集数据到reg_tensor。通过data_copy_mode选择收集粒度:19**Tile→reg形式**(src为Tile):从Tile中按索引收集数据到reg_tensor。通过data_copy_mode选择收集粒度:
20 20 
21-- pypto_pro.language.DataCopyMode.NORM(默认):NORM模式,按元素收集,index单位为元素。收集过程如下图所示:21+- pypto_pro.language.DataCopyMode.NORM(默认):NORM模式,按元素收集,index单位为元素。收集过程如下图所示:
22 22 
23 **图1** gather NORM模式功能说明23 **图1** gather NORM模式功能说明
24 24 
25- ![](../../../figures/gather_function.jpg)25+ ![](../../../figures/gather_function.jpg)
26 26 
27-- pypto_pro.language.DataCopyMode.DATA_BLOCK_LOAD:DATA_BLOCK_LOAD模式,按DataBlock(32B)收集,index单位为字节且需32B对齐。收集过程如下图所示:27+- pypto_pro.language.DataCopyMode.DATA_BLOCK_LOAD:DATA_BLOCK_LOAD模式,按DataBlock(32B)收集,index单位为字节且需32B对齐。收集过程如下图所示:
28 28 
29 **图2** gather DATA_BLOCK_LOAD模式功能说明29 **图2** gather DATA_BLOCK_LOAD模式功能说明
30 30 
31- ![](../../../figures/block_mode_gather.jpg)31+ ![](../../../figures/block_mode_gather.jpg)
32 32 
33**reg→reg形式**(src为reg_tensor):reg_tensor到reg_tensor按元素收集,无需mask。33**reg→reg形式**(src为reg_tensor):reg_tensor到reg_tensor按元素收集,无需mask。
34 34 
@@ -44,10 +44,10 @@ gather(src, index, preg, data_copy_mode: Optional[DataCopyMode] = None) -> dst
44 44 
45| 参数 | 输入/输出 | 说明 |45| 参数 | 输入/输出 | 说明 |
46|---|---|---|46|---|---|---|
47-| src | 输入 | 源操作数,可为Tile(Tile→reg形式,基地址需32字节对齐)或[reg_tensor](../reg_tensor.md)(reg→reg形式),支持的数据类型请参见[约束说明](#约束说明)。<br>- NORM模式下,当src为16位宽数据类型且index为DT_UINT32时,每个gather到的16位元素占32位空间(低16位为数据,高16位补零),寄存器中有效元素数量为索引数量(VL/4),而非index为DT_UINT16索引场景的VL/2。存储时需使用pypto_pro.language.StoreDist.NORM_B16按16位粒度写入,输出中偶数位置为有效数据,奇数位置为零。此功能适用于索引数据天然为32位宽的场景。<br>- DATA_BLOCK_LOAD模式和reg→reg形式下,源操作数和目的操作数数据类型必须相同。 |47+| src | 输入 | 源操作数,可为Tile(Tile→reg形式,基地址需32字节对齐)或[reg_tensor](../reg_tensor.md)(reg→reg形式),支持的数据类型请参见[约束说明](#约束说明)。<br>- NORM模式下,当src为16位宽数据类型且index为DT_UINT32时,每个gather到的16位元素占32位空间(低16位为数据,高16位补零),寄存器中有效元素数量为索引数量(VL/4),而非index为DT_UINT16索引场景的VL/2。存储时需使用pypto_pro.language.StoreDist.NORM_B16按16位粒度写入,输出中偶数位置为有效数据,奇数位置为零。此功能适用于索引数据天然为32位宽的场景。<br>- DATA_BLOCK_LOAD模式和reg→reg形式下,源操作数和目的操作数数据类型必须相同。 |
48| index | 输入 | 索引值,[reg_tensor](../reg_tensor.md),支持的数据类型请参见[约束说明](#约束说明)。<br>- Tile→reg NORM模式下为dst中每个元素相对于src的位置,单位:元素。8位宽的数据类型(DT_INT8、DT_UINT8)源数据会被零扩展到16位宽。16位宽源数据类型(DT_INT16、DT_UINT16、DT_FP16、DT_BF16)的索引支持DT_UINT16和DT_UINT32。<br>- Tile→reg DATA_BLOCK_LOAD模式下为每个DataBlock相对于src的位置,且必须32B对齐,即一个索引值对应1个DataBlock。<br>- reg→reg形式下为src中每个元素的位置,单位:元素,数据类型位宽需与src保持一致。<br>index索引值对应的数据必须在Tile有效地址范围内(Tile→reg形式)。如果索引值超出当前reg_tensor中能存储的最大数据元素个数,索引值更新为i % (VL / sizeof(T)),其中VL为256字节(reg→reg形式)。index中的值可以重复。 |48| index | 输入 | 索引值,[reg_tensor](../reg_tensor.md),支持的数据类型请参见[约束说明](#约束说明)。<br>- Tile→reg NORM模式下为dst中每个元素相对于src的位置,单位:元素。8位宽的数据类型(DT_INT8、DT_UINT8)源数据会被零扩展到16位宽。16位宽源数据类型(DT_INT16、DT_UINT16、DT_FP16、DT_BF16)的索引支持DT_UINT16和DT_UINT32。<br>- Tile→reg DATA_BLOCK_LOAD模式下为每个DataBlock相对于src的位置,且必须32B对齐,即一个索引值对应1个DataBlock。<br>- reg→reg形式下为src中每个元素的位置,单位:元素,数据类型位宽需与src保持一致。<br>index索引值对应的数据必须在Tile有效地址范围内(Tile→reg形式)。如果索引值超出当前reg_tensor中能存储的最大数据元素个数,索引值更新为i % (VL / sizeof(T)),其中VL为256字节(reg→reg形式)。index中的值可以重复。 |
49| preg | 输入 | 可选,[mask_reg](../mask_reg.md)。mask功能**仅Tile→reg形式支持**,reg→reg形式不支持此参数。 |49| preg | 输入 | 可选,[mask_reg](../mask_reg.md)。mask功能**仅Tile→reg形式支持**,reg→reg形式不支持此参数。 |
50-| data_copy_mode | 输入 | 可选关键字参数,收集粒度。pypto_pro.language.DataCopyMode.NORM(默认,按元素)或pypto_pro.language.DataCopyMode.DATA_BLOCK_LOAD(按32B DataBlock)。**仅Tile→reg形式支持**,reg→reg形式不支持此参数。 |50+| data_copy_mode | 输入 | 可选关键字参数,收集粒度。pypto_pro.language.DataCopyMode.NORM(默认,按元素)或pypto_pro.language.DataCopyMode.DATA_BLOCK_LOAD(按32B DataBlock)。**仅Tile→reg形式支持**,reg→reg形式不支持此参数。 |
51 51 
52## 约束说明52## 约束说明
53 53 
@@ -452,49 +452,49 @@ if __name__ == "__main__":
452 test_example_fp16_bc()452 test_example_fp16_bc()
453 print("PASSED")453 print("PASSED")
454```454```
455- 455+ 
456-### INT64数据类型示例456+### INT64数据类型示例
457- 457+ 
458-```python458+```python
459-import os459+import os
460-import pypto_pro.language as pl460+import pypto_pro.language as pl
461-import torch461+import torch
462-import torch_npu462+import torch_npu
463- 463+ 
464@pl.vector_function464@pl.vector_function
465def example_vf_int64(src_tile, dst_tile):465def example_vf_int64(src_tile, dst_tile):
466 preg = vf.create_mask(pattern=pl.MaskPattern.ALL, dtype=pl.DT_INT64)466 preg = vf.create_mask(pattern=pl.MaskPattern.ALL, dtype=pl.DT_INT64)
467 reg_idx = vf.arange(0, dtype=pl.DT_UINT32)467 reg_idx = vf.arange(0, dtype=pl.DT_UINT32)
468 reg_out = vf.gather(src_tile, reg_idx, preg)468 reg_out = vf.gather(src_tile, reg_idx, preg)
469- vf.store_align(dst_tile, reg_out, preg)469+ vf.store_align(dst_tile, reg_out, preg)
470- 470+ 
471-@pl.jit()471+@pl.jit()
472-def example_kernel_int64(472+def example_kernel_int64(
473- a: pl.Tensor[[pl.DYNAMIC, pl.DYNAMIC], pl.DT_INT64],473+ a: pl.Tensor[[pl.DYNAMIC, pl.DYNAMIC], pl.DT_INT64],
474- out: pl.Tensor[[pl.DYNAMIC, pl.DYNAMIC], pl.DT_INT64],474+ out: pl.Tensor[[pl.DYNAMIC, pl.DYNAMIC], pl.DT_INT64],
475-):475+):
476- tf = pl.TileType(shape=[1, 32], dtype=pl.DT_INT64, target_memory=pl.MemorySpace.Vec)476+ tf = pl.TileType(shape=[1, 32], dtype=pl.DT_INT64, target_memory=pl.MemorySpace.Vec)
477 in_a_grp = pl.make_tile_group(type=tf, addrs=0, mutex_ids=[0])477 in_a_grp = pl.make_tile_group(type=tf, addrs=0, mutex_ids=[0])
478 in_a = in_a_grp.current()478 in_a = in_a_grp.current()
479 t_out_grp = pl.make_tile_group(type=tf, addrs=256, mutex_ids=[1])479 t_out_grp = pl.make_tile_group(type=tf, addrs=256, mutex_ids=[1])
480 t_out = t_out_grp.current()480 t_out = t_out_grp.current()
481- with pl.section_vector():481+ with pl.section_vector():
482- pl.load(in_a, a, [0, 0])482+ pl.load(in_a, a, [0, 0])
483- example_vf_int64(in_a, t_out)483+ example_vf_int64(in_a, t_out)
484- pl.store(out, t_out, [0, 0])484+ pl.store(out, t_out, [0, 0])
485- 485+ 
486-def test_example_int64():486+def test_example_int64():
487- device_id = int(os.environ.get("TILE_FWK_DEVICE_ID", 0))487+ device_id = int(os.environ.get("TILE_FWK_DEVICE_ID", 0))
488- device = f"npu:{device_id}"488+ device = f"npu:{device_id}"
489- core_nums = 1489+ core_nums = 1
490- torch.npu.set_device(device)490+ torch.npu.set_device(device)
491- a = torch.randint(-100, 100, [1, 32], device=device, dtype=torch.int64)491+ a = torch.randint(-100, 100, [1, 32], device=device, dtype=torch.int64)
492- out = torch.empty([1, 32], device=device, dtype=torch.int64)492+ out = torch.empty([1, 32], device=device, dtype=torch.int64)
493- example_kernel_int64[None, core_nums](a, out)493+ example_kernel_int64[None, core_nums](a, out)
494- torch.npu.synchronize()494+ torch.npu.synchronize()
495- torch.testing.assert_close(out, a, rtol=0, atol=0)495+ torch.testing.assert_close(out, a, rtol=0, atol=0)
496- 496+ 
497-if __name__ == "__main__":497+if __name__ == "__main__":
498- test_example_int64()498+ test_example_int64()
499- print("PASSED")499+ print("PASSED")
500```500```
@@ -3,18 +3,18 @@
3## 产品支持情况3## 产品支持情况
4 4 
5<!-- npu="950" id1 -->5<!-- npu="950" id1 -->
6-- Ascend 950PR/Ascend 950DT:支持6+- Ascend 950PR&950DT系列产品:支持
7<!-- end id1 -->7<!-- end id1 -->
8<!-- npu="A3" id2 -->8<!-- npu="A3" id2 -->
9-- Atlas A3 训练系列产品/Atlas A3 推理系列产品:不支持9+- Atlas A3系列产品:不支持
10<!-- end id2 -->10<!-- end id2 -->
11<!-- npu="910b" id3 -->11<!-- npu="910b" id3 -->
12-- Atlas A2 训练系列产品/Atlas A2 推理系列产品:不支持12+- Atlas A2系列产品:不支持
13<!-- end id3 -->13<!-- end id3 -->
14 14 
15## 功能说明15## 功能说明
16 16 
17-从pypto_pro.language.set_vec_mask设置的掩码寄存器 {MASK1, MASK0} 中读取mask值,并按数据类型对应的格式转换后写入返回值[mask_reg](../mask_reg.md)。17+从pypto_pro.language.set_vec_mask设置的掩码寄存器 {MASK1, MASK0} 中读取mask值,并按数据类型对应的格式转换后写入返回值[mask_reg](../mask_reg.md)。
18 18 
19具体转换方式:19具体转换方式:
20 20 
@@ -31,7 +31,7 @@ get_mask_spr(width: MaskWidth = MaskWidth.B32) -> preg
31 31 
32| 参数 | 输入/输出 | 说明 |32| 参数 | 输入/输出 | 说明 |
33|---|---|---|33|---|---|---|
34-| width | 输入 | 可选,掩码宽度,决定读取的SPR位宽及扩展方式,对应[MaskWidth](../types/MaskWidth.md)类型。<br>- pypto_pro.language.MaskWidth.B32(默认):读取64bit MASK0,每bit扩展为4bit。<br>- pypto_pro.language.MaskWidth.B16:读取128bit {MASK1, MASK0},每bit扩展为2bit。 |34+| width | 输入 | 可选,掩码宽度,决定读取的SPR位宽及扩展方式,对应[MaskWidth](../types/MaskWidth.md)类型。<br>- pypto_pro.language.MaskWidth.B32(默认):读取64bit MASK0,每bit扩展为4bit。<br>- pypto_pro.language.MaskWidth.B16:读取128bit {MASK1, MASK0},每bit扩展为2bit。 |
35 35 
36## 约束说明36## 约束说明
37 37 
@@ -39,12 +39,12 @@ get_mask_spr(width: MaskWidth = MaskWidth.B32) -> preg
39 39 
40 | width | 返回值 |40 | width | 返回值 |
41 |---|---|41 |---|---|
42- | pypto_pro.language.MaskWidth.B32 | mask_reg(对应32位宽:DT_INT32、DT_UINT32、DT_FP32) |42+ | pypto_pro.language.MaskWidth.B32 | mask_reg(对应32位宽:DT_INT32、DT_UINT32、DT_FP32) |
43- | pypto_pro.language.MaskWidth.B16 | mask_reg(对应16位宽:DT_INT16、DT_UINT16、DT_FP16、DT_BF16) |43+ | pypto_pro.language.MaskWidth.B16 | mask_reg(对应16位宽:DT_INT16、DT_UINT16、DT_FP16、DT_BF16) |
44 44 
45- 本接口为兼容性接口,建议优先采用vf.create_mask和vf.update_mask进行mask_reg计算。45- 本接口为兼容性接口,建议优先采用vf.create_mask和vf.update_mask进行mask_reg计算。
46 46 
47-- 本接口使用前需选择与掩码含义一致的模式,并通过pypto_pro.language.set_vec_mask或产生掩码的VF指令设置SPR {MASK1, MASK0}。按位掩码使用norm模式;元素计数使用count模式。47+- 本接口使用前需选择与掩码含义一致的模式,并通过pypto_pro.language.set_vec_mask或产生掩码的VF指令设置SPR {MASK1, MASK0}。按位掩码使用norm模式;元素计数使用count模式。
48 48 
49## 返回值说明49## 返回值说明
50 50 
@@ -52,7 +52,7 @@ get_mask_spr(width: MaskWidth = MaskWidth.B32) -> preg
52 52 
53## 调用示例53## 调用示例
54 54 
55-先用pypto_pro.language.set_vec_mask设置SPR {MASK1, MASK0},再用vf.get_mask_spr读取到mask_reg,最后用该mask_reg控制计算:55+先用pypto_pro.language.set_vec_mask设置SPR {MASK1, MASK0},再用vf.get_mask_spr读取到mask_reg,最后用该mask_reg控制计算:
56 56 
57```python57```python
58import os58import os
@@ -3,13 +3,13 @@
3## 产品支持情况3## 产品支持情况
4 4 
5<!-- npu="950" id1 -->5<!-- npu="950" id1 -->
6-- Ascend 950PR/Ascend 950DT:支持6+- Ascend 950PR&950DT系列产品:支持
7<!-- end id1 -->7<!-- end id1 -->
8<!-- npu="A3" id2 -->8<!-- npu="A3" id2 -->
9-- Atlas A3 训练系列产品/Atlas A3 推理系列产品:不支持9+- Atlas A3系列产品:不支持
10<!-- end id2 -->10<!-- end id2 -->
11<!-- npu="910b" id3 -->11<!-- npu="910b" id3 -->
12-- Atlas A2 训练系列产品/Atlas A2 推理系列产品:不支持12+- Atlas A2系列产品:不支持
13<!-- end id3 -->13<!-- end id3 -->
14 14 
15## 功能说明15## 功能说明
@@ -26,7 +26,7 @@ load(tile, stride) -> dst
26 26 
27| 参数 | 输入/输出 | 说明 |27| 参数 | 输入/输出 | 说明 |
28|---|---|---|28|---|---|---|
29-| tile | 输入 | 源操作数,Tile,起始地址需要32字节对齐。目的操作数与源操作数的数据类型需要保持一致。支持的数据类型为:DT_INT8、DT_UINT8、DT_INT16、DT_UINT16、DT_FP16、DT_BF16、DT_INT32、DT_UINT32、DT_FP32、DT_INT64、DT_UINT64。 |29+| tile | 输入 | 源操作数,Tile,起始地址需要32字节对齐。目的操作数与源操作数的数据类型需要保持一致。支持的数据类型为:DT_INT8、DT_UINT8、DT_INT16、DT_UINT16、DT_FP16、DT_BF16、DT_INT32、DT_UINT32、DT_FP32、DT_INT64、DT_UINT64。 |
30| stride | 输入 | 可选,传入时自动启用post-update模式,搬运后源地址自动累进stride指定的步长。不传时为普通加载模式。 |30| stride | 输入 | 可选,传入时自动启用post-update模式,搬运后源地址自动累进stride指定的步长。不传时为普通加载模式。 |
31 31 
32## 约束说明32## 约束说明
@@ -128,49 +128,49 @@ if __name__ == "__main__":
128 test_example_2()128 test_example_2()
129 print("PASSED")129 print("PASSED")
130```130```
131- 131+ 
132-### INT64数据类型示例132+### INT64数据类型示例
133- 133+ 
134-```python134+```python
135-import os135+import os
136-import pypto_pro.language as pl136+import pypto_pro.language as pl
137-import torch137+import torch
138-import torch_npu138+import torch_npu
139- 139+ 
140-@pl.vector_function140+@pl.vector_function
141-def example_vf_int64(src_tile, dst_tile):141+def example_vf_int64(src_tile, dst_tile):
142- preg = vf.create_mask(pattern=pl.MaskPattern.ALL, dtype=pl.DT_INT64)142+ preg = vf.create_mask(pattern=pl.MaskPattern.ALL, dtype=pl.DT_INT64)
143- reg_a = vf.load_align(src_tile, 0)143+ reg_a = vf.load_align(src_tile, 0)
144- reg_out = vf.load(src_tile, 0)144+ reg_out = vf.load(src_tile, 0)
145- vf.store_align(dst_tile, reg_out, preg)145+ vf.store_align(dst_tile, reg_out, preg)
146- 146+ 
147-@pl.jit()147+@pl.jit()
148-def example_kernel_int64(148+def example_kernel_int64(
149- a: pl.Tensor[[pl.DYNAMIC, pl.DYNAMIC], pl.DT_INT64],149+ a: pl.Tensor[[pl.DYNAMIC, pl.DYNAMIC], pl.DT_INT64],
150- out: pl.Tensor[[pl.DYNAMIC, pl.DYNAMIC], pl.DT_INT64],150+ out: pl.Tensor[[pl.DYNAMIC, pl.DYNAMIC], pl.DT_INT64],
151-):151+):
152- tf = pl.TileType(shape=[1, 32], dtype=pl.DT_INT64, target_memory=pl.MemorySpace.Vec)152+ tf = pl.TileType(shape=[1, 32], dtype=pl.DT_INT64, target_memory=pl.MemorySpace.Vec)
153 in_a_grp = pl.make_tile_group(type=tf, addrs=0, mutex_ids=[0])153 in_a_grp = pl.make_tile_group(type=tf, addrs=0, mutex_ids=[0])
154 in_a = in_a_grp.current()154 in_a = in_a_grp.current()
155 t_out_grp = pl.make_tile_group(type=tf, addrs=256, mutex_ids=[1])155 t_out_grp = pl.make_tile_group(type=tf, addrs=256, mutex_ids=[1])
156 t_out = t_out_grp.current()156 t_out = t_out_grp.current()
157- with pl.section_vector():157+ with pl.section_vector():
158- pl.load(in_a, a, [0, 0])158+ pl.load(in_a, a, [0, 0])
159- example_vf_int64(in_a, t_out)159+ example_vf_int64(in_a, t_out)
160- pl.store(out, t_out, [0, 0])160+ pl.store(out, t_out, [0, 0])
161- 161+ 
162-def test_example_int64():162+def test_example_int64():
163- device_id = int(os.environ.get("TILE_FWK_DEVICE_ID", 0))163+ device_id = int(os.environ.get("TILE_FWK_DEVICE_ID", 0))
164- device = f"npu:{device_id}"164+ device = f"npu:{device_id}"
165- core_nums = 1165+ core_nums = 1
166- torch.npu.set_device(device)166+ torch.npu.set_device(device)
167- a = torch.randint(-100, 100, [1, 32], device=device, dtype=torch.int64)167+ a = torch.randint(-100, 100, [1, 32], device=device, dtype=torch.int64)
168- out = torch.empty([1, 32], device=device, dtype=torch.int64)168+ out = torch.empty([1, 32], device=device, dtype=torch.int64)
169- example_kernel_int64[None, core_nums](a, out)169+ example_kernel_int64[None, core_nums](a, out)
170- torch.npu.synchronize()170+ torch.npu.synchronize()
171- torch.testing.assert_close(out, a, rtol=0, atol=0)171+ torch.testing.assert_close(out, a, rtol=0, atol=0)
172- 172+ 
173-if __name__ == "__main__":173+if __name__ == "__main__":
174- test_example_int64()174+ test_example_int64()
175- print("PASSED")175+ print("PASSED")
176```176```
@@ -3,13 +3,13 @@
3## 产品支持情况3## 产品支持情况
4 4 
5<!-- npu="950" id1 -->5<!-- npu="950" id1 -->
6-- Ascend 950PR/Ascend 950DT:支持6+- Ascend 950PR&950DT系列产品:支持
7<!-- end id1 -->7<!-- end id1 -->
8<!-- npu="A3" id2 -->8<!-- npu="A3" id2 -->
9-- Atlas A3 训练系列产品/Atlas A3 推理系列产品:不支持9+- Atlas A3系列产品:不支持
10<!-- end id2 -->10<!-- end id2 -->
11<!-- npu="910b" id3 -->11<!-- npu="910b" id3 -->
12-- Atlas A2 训练系列产品/Atlas A2 推理系列产品:不支持12+- Atlas A2系列产品:不支持
13<!-- end id3 -->13<!-- end id3 -->
14 14 
15## 功能说明15## 功能说明
@@ -27,9 +27,9 @@ reg_tensor模式支持**连续搬运模式**和**非连续搬运模式**。**连
27 27 
28**图1** vf.load_align连续对齐搬入分布模式图示28**图1** vf.load_align连续对齐搬入分布模式图示
29 29 
30-![](../../../figures/contiguous_aligned_load.jpg)30+![](../../../figures/contiguous_aligned_load.jpg)
31 31 
32-**非连续搬运模式**下,通过data_copy_mode=pypto_pro.language.DataCopyMode.DATA_BLOCK_COPY启用DataBlock搬运模式,实现数据从Tile非连续搬运至reg_tensor。单条指令一次搬运8个DataBlock,block_stride参数表示相邻DataBlock间的间隔。该模式下offset参数改为传入控制有效元素的mask_reg,控制规则如下:32+**非连续搬运模式**下,通过data_copy_mode=pypto_pro.language.DataCopyMode.DATA_BLOCK_COPY启用DataBlock搬运模式,实现数据从Tile非连续搬运至reg_tensor。单条指令一次搬运8个DataBlock,block_stride参数表示相邻DataBlock间的间隔。该模式下offset参数改为传入控制有效元素的mask_reg,控制规则如下:
33 33 
34- 某个DataBlock在mask中对应的32bit有任意一位为1时,该DataBlock对应的数据会被搬入dst。34- 某个DataBlock在mask中对应的32bit有任意一位为1时,该DataBlock对应的数据会被搬入dst。
35- 某个DataBlock在mask中对应的32bit全为0时,该DataBlock对应的数据不会被读取,dst对应位置置0,即使Tile越界也不会报错。35- 某个DataBlock在mask中对应的32bit全为0时,该DataBlock对应的数据不会被读取,dst对应位置置0,即使Tile越界也不会报错。
@@ -40,23 +40,23 @@ reg_tensor模式支持**连续搬运模式**和**非连续搬运模式**。**连
40 40 
41mask_reg目标支持三种分布模式,通过dist关键字参数配置,能够实现上采样、下采样等功能:41mask_reg目标支持三种分布模式,通过dist关键字参数配置,能够实现上采样、下采样等功能:
42 42 
43-- pypto_pro.language.LoadDist.NORM(正常模式,搬运数据量为VL/8)43+- pypto_pro.language.LoadDist.NORM(正常模式,搬运数据量为VL/8)
44-- pypto_pro.language.LoadDist.US(上采样模式,每bit数据重复搬运两次,将VL/16数据扩充为VL/8搬入)44+- pypto_pro.language.LoadDist.US(上采样模式,每bit数据重复搬运两次,将VL/16数据扩充为VL/8搬入)
45-- pypto_pro.language.LoadDist.DS(下采样模式,每间隔1bit舍弃数据,将VL/4数据压缩为VL/8搬入)45+- pypto_pro.language.LoadDist.DS(下采样模式,每间隔1bit舍弃数据,将VL/4数据压缩为VL/8搬入)
46 46 
47各模式示意如下:47各模式示意如下:
48 48 
49-**图2** pypto_pro.language.LoadDist.NORM模式49+**图2** pypto_pro.language.LoadDist.NORM模式
50 50 
51-![LoadDist-NORM模式](../../../figures/load_dist_norm_mode.jpg)51+![LoadDist-NORM模式](../../../figures/load_dist_norm_mode.jpg)
52 52 
53-**图3** pypto_pro.language.LoadDist.US模式53+**图3** pypto_pro.language.LoadDist.US模式
54 54 
55-![LoadDist-US模式](../../../figures/load_dist_us_mode.jpg)55+![LoadDist-US模式](../../../figures/load_dist_us_mode.jpg)
56 56 
57-**图4** pypto_pro.language.LoadDist.DS模式57+**图4** pypto_pro.language.LoadDist.DS模式
58 58 
59-![LoadDist-DS模式](../../../figures/load_dist_ds_mode.jpg)59+![LoadDist-DS模式](../../../figures/load_dist_ds_mode.jpg)
60 60 
61## 函数原型61## 函数原型
62 62 
@@ -68,14 +68,14 @@ load_align(tile, offset=None, dist: Optional[LoadDist] = None, dtype: Optional[D
68 68 
69| 参数 | 输入/输出 | 说明 |69| 参数 | 输入/输出 | 说明 |
70|---|---|---|70|---|---|---|
71-| tile | 输入 | 源操作数,Tile地址。地址需要32字节对齐。支持的数据类型为:DT_INT8、DT_UINT8、DT_INT16、DT_UINT16、DT_FP16、DT_BF16、DT_INT32、DT_UINT32、DT_FP32、DT_INT64、DT_UINT64、DT_FP8E4M3FN、DT_FP8E5M2、DT_FP8E8M0、DT_HF8、DT_FP4E2M1、DT_FP4E1M2。 |71+| tile | 输入 | 源操作数,Tile地址。地址需要32字节对齐。支持的数据类型为:DT_INT8、DT_UINT8、DT_INT16、DT_UINT16、DT_FP16、DT_BF16、DT_INT32、DT_UINT32、DT_FP32、DT_INT64、DT_UINT64、DT_FP8E4M3FN、DT_FP8E5M2、DT_FP8E8M0、DT_HF8、DT_FP4E2M1、DT_FP4E1M2。 |
72-| offset | 输入 | 可选,地址偏移参数,根据传入类型自动分派搬运接口。在**连续搬运模式**和**mask_reg模式**下单位为元素个数,在**非连续搬运模式**时为mask。<br>- **连续搬运模式**:<br>&nbsp;&nbsp;- **整数或[row, col]列表**:整数偏移在代码生成时转换为指针算术Tile + offset。<br>&nbsp;&nbsp;&nbsp;&nbsp;[row, col]列表的线性偏移为row * shape[1] + col,row单位为Tile的列数(即set_validshape[m, n]的n),col单位为元素个数,两者均支持表达式。<br>&nbsp;&nbsp;- **AddrReg**(由vf.create_addr_reg创建):实际搬运Tile地址为Tile + AddrReg中存储的偏移量。<br>&nbsp;&nbsp;&nbsp;&nbsp;每次迭代需先调用vf.create_addr_reg设定偏移量再调用搬运指令。<br>- **非连续搬运模式**(DataBlock加载模式,data_copy_mode=pypto_pro.language.DataCopyMode.DATA_BLOCK_COPY时):该模式下offset位置改为传入控制有效元素的mask_reg,<br>&nbsp;&nbsp;某个DataBlock在mask中对应的32bit有任意一位为1时搬入,全为0时不读取且dst对应位置置0。<br>&nbsp;&nbsp;- 当post_update=True时,搬运后源地址自动累进repeat_stride步长,每次迭代无需手动更新地址。<br>&nbsp;&nbsp;- 当post_update=False时,搬运后地址不更新。<br>- **mask_reg模式**(需先用vf.create_mask预声明):<br>&nbsp;&nbsp;- **整数**:仅在post_update=True时生效;post_update=False时不支持整数offset。<br>&nbsp;&nbsp;- **AddrReg**(由vf.create_addr_reg创建):实际搬运Tile地址为srcAddr + AddrReg中存储的偏移量。 |72+| offset | 输入 | 可选,地址偏移参数,根据传入类型自动分派搬运接口。在**连续搬运模式**和**mask_reg模式**下单位为元素个数,在**非连续搬运模式**时为mask。<br>- **连续搬运模式**:<br>&nbsp;&nbsp;- **整数或[row, col]列表**:整数偏移在代码生成时转换为指针算术Tile + offset。<br>&nbsp;&nbsp;&nbsp;&nbsp;[row, col]列表的线性偏移为row * shape[1] + col,row单位为Tile的列数(即set_validshape[m, n]的n),col单位为元素个数,两者均支持表达式。<br>&nbsp;&nbsp;- **AddrReg**(由vf.create_addr_reg创建):实际搬运Tile地址为Tile + AddrReg中存储的偏移量。<br>&nbsp;&nbsp;&nbsp;&nbsp;每次迭代需先调用vf.create_addr_reg设定偏移量再调用搬运指令。<br>- **非连续搬运模式**(DataBlock加载模式,data_copy_mode=pypto_pro.language.DataCopyMode.DATA_BLOCK_COPY时):该模式下offset位置改为传入控制有效元素的mask_reg,<br>&nbsp;&nbsp;某个DataBlock在mask中对应的32bit有任意一位为1时搬入,全为0时不读取且dst对应位置置0。<br>&nbsp;&nbsp;- 当post_update=True时,搬运后源地址自动累进repeat_stride步长,每次迭代无需手动更新地址。<br>&nbsp;&nbsp;- 当post_update=False时,搬运后地址不更新。<br>- **mask_reg模式**(需先用vf.create_mask预声明):<br>&nbsp;&nbsp;- **整数**:仅在post_update=True时生效;post_update=False时不支持整数offset。<br>&nbsp;&nbsp;- **AddrReg**(由vf.create_addr_reg创建):实际搬运Tile地址为srcAddr + AddrReg中存储的偏移量。 |
73| dist | 输入 | 可选,数据分布模式,对应[LoadDist](../types/LoadDist.md)类型,具体模式根据是**reg_tensor单搬入模式**、**reg_tensor双搬入模式**还是**mask_reg模式**请分别参见[约束说明](#约束说明)中各表。 |73| dist | 输入 | 可选,数据分布模式,对应[LoadDist](../types/LoadDist.md)类型,具体模式根据是**reg_tensor单搬入模式**、**reg_tensor双搬入模式**还是**mask_reg模式**请分别参见[约束说明](#约束说明)中各表。 |
74-| dtype | 输入 | 可选,指定目标[reg_tensor](../reg_tensor.md)或者[mask_reg](../mask_reg.md)的数据类型。当源Tile的数据类型与期望的寄存器数据类型不一致时需要指定(例如源Tile为DT_FP32但需要按DT_UINT32位重解释加载到寄存器)。默认从源Tile的数据类型推断。 |74+| dtype | 输入 | 可选,指定目标[reg_tensor](../reg_tensor.md)或者[mask_reg](../mask_reg.md)的数据类型。当源Tile的数据类型与期望的寄存器数据类型不一致时需要指定(例如源Tile为DT_FP32但需要按DT_UINT32位重解释加载到寄存器)。默认从源Tile的数据类型推断。 |
75| post_update | 输入 | 可选,True时搬运后源地址自动累进,默认False。适用于循环内连续加载,避免手动更新offset。 |75| post_update | 输入 | 可选,True时搬运后源地址自动累进,默认False。适用于循环内连续加载,避免手动更新offset。 |
76-| block_stride | 输入 | 可选,仅在data_copy_mode=pypto_pro.language.DataCopyMode.DATA_BLOCK_COPY模式下有效,其他模式下传入会被忽略。表示相邻DataBlock间的间隔,单位:DataBlock(32字节)。当block_stride=0时,表示重复搬入第一个DataBlock。 |76+| block_stride | 输入 | 可选,仅在data_copy_mode=pypto_pro.language.DataCopyMode.DATA_BLOCK_COPY模式下有效,其他模式下传入会被忽略。表示相邻DataBlock间的间隔,单位:DataBlock(32字节)。当block_stride=0时,表示重复搬入第一个DataBlock。 |
77-| repeat_stride | 输入 | 可选,仅在data_copy_mode=pypto_pro.language.DataCopyMode.DATA_BLOCK_COPY模式且post_update=True时有效。表示重复搬运时的地址更新步长,单位:DataBlock(32字节),需要32字节对齐。post_update=True时,搬运后源地址自动更新为srcAddr += repeat_stride * 32B。 |77+| repeat_stride | 输入 | 可选,仅在data_copy_mode=pypto_pro.language.DataCopyMode.DATA_BLOCK_COPY模式且post_update=True时有效。表示重复搬运时的地址更新步长,单位:DataBlock(32字节),需要32字节对齐。post_update=True时,搬运后源地址自动更新为srcAddr += repeat_stride * 32B。 |
78-| data_copy_mode | 输入 | 可选,数据拷贝模式,对应[DataCopyMode](../types/DataCopyMode.md)类型。仅在**reg_tensor模式**下有效,mask_reg目标不支持此参数。取值:pypto_pro.language.DataCopyMode.NORM(默认,普通连续搬运)或pypto_pro.language.DataCopyMode.DATA_BLOCK_COPY(非连续以DataBlock(32B)为单位进行搬运)。 |78+| data_copy_mode | 输入 | 可选,数据拷贝模式,对应[DataCopyMode](../types/DataCopyMode.md)类型。仅在**reg_tensor模式**下有效,mask_reg目标不支持此参数。取值:pypto_pro.language.DataCopyMode.NORM(默认,普通连续搬运)或pypto_pro.language.DataCopyMode.DATA_BLOCK_COPY(非连续以DataBlock(32B)为单位进行搬运)。 |
79 79 
80## 约束说明80## 约束说明
81 81 
@@ -87,50 +87,50 @@ load_align(tile, offset=None, dist: Optional[LoadDist] = None, dtype: Optional[D
87 87 
88 | dist取值 | 含义 | 搬运对齐约束(Byte) |88 | dist取值 | 含义 | 搬运对齐约束(Byte) |
89 |---|---|---|89 |---|---|---|
90- | pypto_pro.language.LoadDist.NORM | 正常模式,搬运VL数据量。 | 32 |90+ | pypto_pro.language.LoadDist.NORM | 正常模式,搬运VL数据量。 | 32 |
91- | pypto_pro.language.LoadDist.BRC | 广播模式(通用),根据数据类型自动选择B8/B16/B32粒度。 | 1/2/4 |91+ | pypto_pro.language.LoadDist.BRC | 广播模式(通用),根据数据类型自动选择B8/B16/B32粒度。 | 1/2/4 |
92- | pypto_pro.language.LoadDist.BRC_B8 | 搬运一个8位宽类型的数据,并Broadcast到所有元素位置。 | 1 |92+ | pypto_pro.language.LoadDist.BRC_B8 | 搬运一个8位宽类型的数据,并Broadcast到所有元素位置。 | 1 |
93- | pypto_pro.language.LoadDist.BRC_B16 | 搬运一个16位宽类型的数据,并Broadcast到所有元素位置。 | 2 |93+ | pypto_pro.language.LoadDist.BRC_B16 | 搬运一个16位宽类型的数据,并Broadcast到所有元素位置。 | 2 |
94- | pypto_pro.language.LoadDist.BRC_B32 | 搬运一个32位宽类型的数据,并Broadcast到所有元素位置。 | 4 |94+ | pypto_pro.language.LoadDist.BRC_B32 | 搬运一个32位宽类型的数据,并Broadcast到所有元素位置。 | 4 |
95- | pypto_pro.language.LoadDist.US | 上采样模式(通用),根据数据类型自动选择B8/B16粒度。 | min(32, VL/2) |95+ | pypto_pro.language.LoadDist.US | 上采样模式(通用),根据数据类型自动选择B8/B16粒度。 | min(32, VL/2) |
96- | pypto_pro.language.LoadDist.US_B8 | 数据2倍上采样,加载数据量为VL/2,每个输入元素重复两次,数据类型为8位宽类型。 | min(32, VL/2) |96+ | pypto_pro.language.LoadDist.US_B8 | 数据2倍上采样,加载数据量为VL/2,每个输入元素重复两次,数据类型为8位宽类型。 | min(32, VL/2) |
97- | pypto_pro.language.LoadDist.US_B16 | 数据2倍上采样,加载数据量为VL/2,每个输入元素重复两次,数据类型为16位宽类型。 | min(32, VL/2) |97+ | pypto_pro.language.LoadDist.US_B16 | 数据2倍上采样,加载数据量为VL/2,每个输入元素重复两次,数据类型为16位宽类型。 | min(32, VL/2) |
98- | pypto_pro.language.LoadDist.DS | 下采样模式(通用),根据数据类型自动选择B8/B16粒度。 | 32 |98+ | pypto_pro.language.LoadDist.DS | 下采样模式(通用),根据数据类型自动选择B8/B16粒度。 | 32 |
99- | pypto_pro.language.LoadDist.DS_B8 | 数据2倍下采样,加载数据量为2*VL,数据每隔一个保留,数据类型为8位宽类型。 | 32 |99+ | pypto_pro.language.LoadDist.DS_B8 | 数据2倍下采样,加载数据量为2*VL,数据每隔一个保留,数据类型为8位宽类型。 | 32 |
100- | pypto_pro.language.LoadDist.DS_B16 | 数据2倍下采样,加载数据量为2*VL,数据每隔一个保留,数据类型为16位宽类型。 | 32 |100+ | pypto_pro.language.LoadDist.DS_B16 | 数据2倍下采样,加载数据量为2*VL,数据每隔一个保留,数据类型为16位宽类型。 | 32 |
101- | pypto_pro.language.LoadDist.UNPK | 解压缩模式(通用),根据数据类型自动选择B8/B16/B32粒度。 | min(32, VL/2) |101+ | pypto_pro.language.LoadDist.UNPK | 解压缩模式(通用),根据数据类型自动选择B8/B16/B32粒度。 | min(32, VL/2) |
102- | pypto_pro.language.LoadDist.UNPK_B8 | 解压缩模式,按无符号整型u8加载VL/2数据量,每个元素后会补1个值为0元素,即unpack到VL。 | min(32, VL/2) |102+ | pypto_pro.language.LoadDist.UNPK_B8 | 解压缩模式,按无符号整型u8加载VL/2数据量,每个元素后会补1个值为0元素,即unpack到VL。 | min(32, VL/2) |
103- | pypto_pro.language.LoadDist.UNPK_B16 | 解压缩模式,按无符号整型u16加载VL/2数据量,每个元素后会补1个值为0元素,即unpack到VL。 | min(32, VL/2) |103+ | pypto_pro.language.LoadDist.UNPK_B16 | 解压缩模式,按无符号整型u16加载VL/2数据量,每个元素后会补1个值为0元素,即unpack到VL。 | min(32, VL/2) |
104- | pypto_pro.language.LoadDist.UNPK_B32 | 解压缩模式,按无符号整型u32加载VL/2数据量,每个元素后会补1个值为0元素,即unpack到VL。 | min(32, VL/2) |104+ | pypto_pro.language.LoadDist.UNPK_B32 | 解压缩模式,按无符号整型u32加载VL/2数据量,每个元素后会补1个值为0元素,即unpack到VL。 | min(32, VL/2) |
105- | pypto_pro.language.LoadDist.UNPK4 | 4元素解压缩模式,固定按u8加载VL/4数据量,unpack到VL,每个元素后会补3个值为0的元素。 | min(32, VL/4) |105+ | pypto_pro.language.LoadDist.UNPK4 | 4元素解压缩模式,固定按u8加载VL/4数据量,unpack到VL,每个元素后会补3个值为0的元素。 | min(32, VL/4) |
106- | pypto_pro.language.LoadDist.BLK | 读取一个DataBlock(32B),并广播到VL。 | 32 |106+ | pypto_pro.language.LoadDist.BLK | 读取一个DataBlock(32B),并广播到VL。 | 32 |
107- | pypto_pro.language.LoadDist.E2B | 元素扩展到DataBlock模式(通用),根据数据类型自动选择B16/B32粒度。 | VL/16或VL/8 |107+ | pypto_pro.language.LoadDist.E2B | 元素扩展到DataBlock模式(通用),根据数据类型自动选择B16/B32粒度。 | VL/16或VL/8 |
108- | pypto_pro.language.LoadDist.E2B_B16 | 加载(VL/DataBlock)个B16的数据,并将每个元素(16bit)广播到一个DataBlock(32B)中。 | VL/16 |108+ | pypto_pro.language.LoadDist.E2B_B16 | 加载(VL/DataBlock)个B16的数据,并将每个元素(16bit)广播到一个DataBlock(32B)中。 | VL/16 |
109- | pypto_pro.language.LoadDist.E2B_B32 | 加载(VL/DataBlock)个B32的数据,并将每个元素(32bit)广播到一个DataBlock(32B)中。 | VL/8 |109+ | pypto_pro.language.LoadDist.E2B_B32 | 加载(VL/DataBlock)个B32的数据,并将每个元素(32bit)广播到一个DataBlock(32B)中。 | VL/8 |
110 110 
111 **表2** reg_tensor双搬入模式dist参数说明111 **表2** reg_tensor双搬入模式dist参数说明
112 112 
113 | dist取值 | 含义 | 搬运对齐约束(Byte) |113 | dist取值 | 含义 | 搬运对齐约束(Byte) |
114 |---|---|---|114 |---|---|---|
115- | pypto_pro.language.LoadDist.DINTLV_B8 | 双搬入模式,基于元素的交错搬运,将偶数索引的元素存入dst0,奇数索引的元素存入dst1,数据类型为8位宽类型。 | 32 |115+ | pypto_pro.language.LoadDist.DINTLV_B8 | 双搬入模式,基于元素的交错搬运,将偶数索引的元素存入dst0,奇数索引的元素存入dst1,数据类型为8位宽类型。 | 32 |
116- | pypto_pro.language.LoadDist.DINTLV_B16 | 双搬入模式,基于元素的交错搬运,将偶数索引的元素存入dst0,奇数索引的元素存入dst1,数据类型为16位宽类型。 | 32 |116+ | pypto_pro.language.LoadDist.DINTLV_B16 | 双搬入模式,基于元素的交错搬运,将偶数索引的元素存入dst0,奇数索引的元素存入dst1,数据类型为16位宽类型。 | 32 |
117- | pypto_pro.language.LoadDist.DINTLV_B32 | 双搬入模式,基于元素的交错搬运,将偶数索引的元素存入dst0,奇数索引的元素存入dst1,数据类型为32位宽类型。 | 32 |117+ | pypto_pro.language.LoadDist.DINTLV_B32 | 双搬入模式,基于元素的交错搬运,将偶数索引的元素存入dst0,奇数索引的元素存入dst1,数据类型为32位宽类型。 | 32 |
118 118 
119 **表3** mask_reg模式dist参数说明119 **表3** mask_reg模式dist参数说明
120 120 
121 | dist取值 | 含义 | 搬运对齐约束(Byte) |121 | dist取值 | 含义 | 搬运对齐约束(Byte) |
122 |---|---|---|122 |---|---|---|
123- | pypto_pro.language.LoadDist.NORM | 正常模式,搬运数据量为VL/8。 | VL/8 |123+ | pypto_pro.language.LoadDist.NORM | 正常模式,搬运数据量为VL/8。 | VL/8 |
124- | pypto_pro.language.LoadDist.US | 上采样模式,每bit数据重复搬运两次,将VL/16数据扩充为VL/8搬入。 | VL/16 |124+ | pypto_pro.language.LoadDist.US | 上采样模式,每bit数据重复搬运两次,将VL/16数据扩充为VL/8搬入。 | VL/16 |
125- | pypto_pro.language.LoadDist.DS | 下采样模式,每间隔1bit舍弃数据,将VL/4数据压缩为VL/8搬入。 | min(32, VL/4) |125+ | pypto_pro.language.LoadDist.DS | 下采样模式,每间隔1bit舍弃数据,将VL/4数据压缩为VL/8搬入。 | min(32, VL/4) |
126 126 
127## 返回值说明127## 返回值说明
128 128 
129返回dst目的操作数,[reg_tensor](../reg_tensor.md)或者[mask_reg](../mask_reg.md)类型。129返回dst目的操作数,[reg_tensor](../reg_tensor.md)或者[mask_reg](../mask_reg.md)类型。
130 130 
131-- 当目标为reg_tensor时,为**reg_tensor单搬入模式**,支持的数据类型和Tile中的说明一致。131+- 当目标为reg_tensor时,为**reg_tensor单搬入模式**,支持的数据类型和Tile中的说明一致。
132 132 
133-- dst_even/dst_odd**reg_tensor双搬入模式**的偶数/奇数目的操作数,[reg_tensor](../reg_tensor.md),支持的数据类型和Tile中的说明一致。133+- dst_even/dst_odd**reg_tensor双搬入模式**的偶数/奇数目的操作数,[reg_tensor](../reg_tensor.md),支持的数据类型和Tile中的说明一致。
134 134 
135- 当目标已通过vf.create_mask预声明为mask_reg时,自动分派mask_reg加载路径,将Tile中的数据搬入mask_reg。135- 当目标已通过vf.create_mask预声明为mask_reg时,自动分派mask_reg加载路径,将Tile中的数据搬入mask_reg。
136 136 
@@ -576,49 +576,49 @@ if __name__ == "__main__":
576 test_example_hf8_to_fp32()576 test_example_hf8_to_fp32()
577 print("PASSED")577 print("PASSED")
578```578```
579- 579+ 
580-### INT64数据类型示例580+### INT64数据类型示例
581- 581+ 
582-```python582+```python
583-import os583+import os
584-import pypto_pro.language as pl584+import pypto_pro.language as pl
585-import torch585+import torch
586-import torch_npu586+import torch_npu
587- 587+ 
588-@pl.vector_function588+@pl.vector_function
589-def example_vf_int64(src_tile, dst_tile):589+def example_vf_int64(src_tile, dst_tile):
590- preg = vf.create_mask(pattern=pl.MaskPattern.ALL, dtype=pl.DT_INT64)590+ preg = vf.create_mask(pattern=pl.MaskPattern.ALL, dtype=pl.DT_INT64)
591- reg_a = vf.load_align(src_tile, 0)591+ reg_a = vf.load_align(src_tile, 0)
592- reg_out = vf.load_align(src_tile, 0)592+ reg_out = vf.load_align(src_tile, 0)
593- vf.store_align(dst_tile, reg_out, preg)593+ vf.store_align(dst_tile, reg_out, preg)
594- 594+ 
595-@pl.jit()595+@pl.jit()
596-def example_kernel_int64(596+def example_kernel_int64(
597- a: pl.Tensor[[pl.DYNAMIC, pl.DYNAMIC], pl.DT_INT64],597+ a: pl.Tensor[[pl.DYNAMIC, pl.DYNAMIC], pl.DT_INT64],
598- out: pl.Tensor[[pl.DYNAMIC, pl.DYNAMIC], pl.DT_INT64],598+ out: pl.Tensor[[pl.DYNAMIC, pl.DYNAMIC], pl.DT_INT64],
599-):599+):
600- tf = pl.TileType(shape=[1, 32], dtype=pl.DT_INT64, target_memory=pl.MemorySpace.Vec)600+ tf = pl.TileType(shape=[1, 32], dtype=pl.DT_INT64, target_memory=pl.MemorySpace.Vec)
601 in_a_grp = pl.make_tile_group(type=tf, addrs=0, mutex_ids=[0])601 in_a_grp = pl.make_tile_group(type=tf, addrs=0, mutex_ids=[0])
602 in_a = in_a_grp.current()602 in_a = in_a_grp.current()
603 t_out_grp = pl.make_tile_group(type=tf, addrs=256, mutex_ids=[1])603 t_out_grp = pl.make_tile_group(type=tf, addrs=256, mutex_ids=[1])
604 t_out = t_out_grp.current()604 t_out = t_out_grp.current()
605- with pl.section_vector():605+ with pl.section_vector():
606- pl.load(in_a, a, [0, 0])606+ pl.load(in_a, a, [0, 0])
607- example_vf_int64(in_a, t_out)607+ example_vf_int64(in_a, t_out)
608- pl.store(out, t_out, [0, 0])608+ pl.store(out, t_out, [0, 0])
609- 609+ 
610-def test_example_int64():610+def test_example_int64():
611- device_id = int(os.environ.get("TILE_FWK_DEVICE_ID", 0))611+ device_id = int(os.environ.get("TILE_FWK_DEVICE_ID", 0))
612- device = f"npu:{device_id}"612+ device = f"npu:{device_id}"
613- core_nums = 1613+ core_nums = 1
614- torch.npu.set_device(device)614+ torch.npu.set_device(device)
615- a = torch.randint(-100, 100, [1, 32], device=device, dtype=torch.int64)615+ a = torch.randint(-100, 100, [1, 32], device=device, dtype=torch.int64)
616- out = torch.empty([1, 32], device=device, dtype=torch.int64)616+ out = torch.empty([1, 32], device=device, dtype=torch.int64)
617- example_kernel_int64[None, core_nums](a, out)617+ example_kernel_int64[None, core_nums](a, out)
618- torch.npu.synchronize()618+ torch.npu.synchronize()
619- torch.testing.assert_close(out, a, rtol=0, atol=0)619+ torch.testing.assert_close(out, a, rtol=0, atol=0)
620- 620+ 
621-if __name__ == "__main__":621+if __name__ == "__main__":
622- test_example_int64()622+ test_example_int64()
623- print("PASSED")623+ print("PASSED")
624```624```
@@ -3,13 +3,13 @@
3## 产品支持情况3## 产品支持情况
4 4 
5<!-- npu="950" id1 -->5<!-- npu="950" id1 -->
6-- Ascend 950PR/Ascend 950DT:支持6+- Ascend 950PR&950DT系列产品:支持
7<!-- end id1 -->7<!-- end id1 -->
8<!-- npu="A3" id2 -->8<!-- npu="A3" id2 -->
9-- Atlas A3 训练系列产品/Atlas A3 推理系列产品:不支持9+- Atlas A3系列产品:不支持
10<!-- end id2 -->10<!-- end id2 -->
11<!-- npu="910b" id3 -->11<!-- npu="910b" id3 -->
12-- Atlas A2 训练系列产品/Atlas A2 推理系列产品:不支持12+- Atlas A2系列产品:不支持
13<!-- end id3 -->13<!-- end id3 -->
14 14 
15## 功能说明15## 功能说明
@@ -36,13 +36,13 @@
36 36 
37**图1** 非对齐搬入示例37**图1** 非对齐搬入示例
38 38 
39-![](../../../figures/unaligned_load.jpg)39+![](../../../figures/unaligned_load.jpg)
40 40 
41### 连续非对齐搬入搬出原理41### 连续非对齐搬入搬出原理
42 42 
43**图2** 连续非对齐搬入搬出原理(数据类型DT_UINT32)43**图2** 连续非对齐搬入搬出原理(数据类型DT_UINT32)
44 44 
45-![](../../../figures/contiguous_unaligned_load_store.jpg)45+![](../../../figures/contiguous_unaligned_load_store.jpg)
46 46 
47连续非对齐搬入时,vf.load_unalign会将后续未对齐的数据缓存至vf.load_unalign_init创建的ureg,所以下一次搬入不需要再次调用vf.load_unalign_pre,只需在迭代开始前调用一次vf.load_unalign_pre,从而实现非对齐搬入的性能优化。47连续非对齐搬入时,vf.load_unalign会将后续未对齐的数据缓存至vf.load_unalign_init创建的ureg,所以下一次搬入不需要再次调用vf.load_unalign_pre,只需在迭代开始前调用一次vf.load_unalign_pre,从而实现非对齐搬入的性能优化。
48 48 
@@ -70,7 +70,7 @@ load_unalign(align_reg, tile, stride=None, post_update: bool = False) -> dst
70| 参数 | 输入/输出 | 说明 |70| 参数 | 输入/输出 | 说明 |
71|---|---|---|71|---|---|---|
72| align_reg | 输入/输出 | 非对齐寄存器,UnalignRegForLoad类型,用于存储非32字节的数据,寄存器大小为32字节(由vf.load_unalign_init()创建)。 |72| align_reg | 输入/输出 | 非对齐寄存器,UnalignRegForLoad类型,用于存储非32字节的数据,寄存器大小为32字节(由vf.load_unalign_init()创建)。 |
73-| tile | 输入 | 源操作数,Tile地址,起始地址需要32字节对齐。目的操作数与源操作数的数据类型需要保持一致。支持的数据类型为:DT_INT8、DT_UINT8、DT_INT16、DT_UINT16、DT_FP16、DT_BF16、DT_INT32、DT_UINT32、DT_FP32、DT_INT64、DT_UINT64、DT_FP8E4M3FN、DT_FP8E5M2、DT_FP8E8M0、DT_HF8、DT_FP4E2M1、DT_FP4E1M2。 |73+| tile | 输入 | 源操作数,Tile地址,起始地址需要32字节对齐。目的操作数与源操作数的数据类型需要保持一致。支持的数据类型为:DT_INT8、DT_UINT8、DT_INT16、DT_UINT16、DT_FP16、DT_BF16、DT_INT32、DT_UINT32、DT_FP32、DT_INT64、DT_UINT64、DT_FP8E4M3FN、DT_FP8E5M2、DT_FP8E8M0、DT_HF8、DT_FP4E2M1、DT_FP4E1M2。 |
74| stride | 输入 | 可选,地址更新步长,单位:元素个数。仅在post_update=True时有效。 |74| stride | 输入 | 可选,地址更新步长,单位:元素个数。仅在post_update=True时有效。 |
75| post_update | 输入 | 可选,True时搬运后地址自动累进,默认False。 |75| post_update | 输入 | 可选,True时搬运后地址自动累进,默认False。 |
76 76 
@@ -180,51 +180,51 @@ if __name__ == "__main__":
180 test_example_2()180 test_example_2()
181 print("PASSED")181 print("PASSED")
182```182```
183- 183+ 
184-### INT64数据类型示例184+### INT64数据类型示例
185- 185+ 
186-```python186+```python
187-import os187+import os
188-import pypto_pro.language as pl188+import pypto_pro.language as pl
189-import torch189+import torch
190-import torch_npu190+import torch_npu
191- 191+ 
192-@pl.vector_function192+@pl.vector_function
193-def example_vf_int64(src_tile, dst_tile):193+def example_vf_int64(src_tile, dst_tile):
194- preg = vf.create_mask(pattern=pl.MaskPattern.ALL, dtype=pl.DT_INT64)194+ preg = vf.create_mask(pattern=pl.MaskPattern.ALL, dtype=pl.DT_INT64)
195- reg_a = vf.load_align(src_tile, 0)195+ reg_a = vf.load_align(src_tile, 0)
196- ureg = vf.load_unalign_init()196+ ureg = vf.load_unalign_init()
197- vf.load_unalign_pre(ureg, src_tile)197+ vf.load_unalign_pre(ureg, src_tile)
198- reg_out = vf.load_unalign(ureg, src_tile)198+ reg_out = vf.load_unalign(ureg, src_tile)
199- vf.store_align(dst_tile, reg_out, preg)199+ vf.store_align(dst_tile, reg_out, preg)
200- 200+ 
201-@pl.jit()201+@pl.jit()
202-def example_kernel_int64(202+def example_kernel_int64(
203- a: pl.Tensor[[pl.DYNAMIC, pl.DYNAMIC], pl.DT_INT64],203+ a: pl.Tensor[[pl.DYNAMIC, pl.DYNAMIC], pl.DT_INT64],
204- out: pl.Tensor[[pl.DYNAMIC, pl.DYNAMIC], pl.DT_INT64],204+ out: pl.Tensor[[pl.DYNAMIC, pl.DYNAMIC], pl.DT_INT64],
205-):205+):
206- tf = pl.TileType(shape=[1, 32], dtype=pl.DT_INT64, target_memory=pl.MemorySpace.Vec)206+ tf = pl.TileType(shape=[1, 32], dtype=pl.DT_INT64, target_memory=pl.MemorySpace.Vec)
207 in_a_grp = pl.make_tile_group(type=tf, addrs=0, mutex_ids=[0])207 in_a_grp = pl.make_tile_group(type=tf, addrs=0, mutex_ids=[0])
208 in_a = in_a_grp.current()208 in_a = in_a_grp.current()
209 t_out_grp = pl.make_tile_group(type=tf, addrs=256, mutex_ids=[1])209 t_out_grp = pl.make_tile_group(type=tf, addrs=256, mutex_ids=[1])
210 t_out = t_out_grp.current()210 t_out = t_out_grp.current()
211- with pl.section_vector():211+ with pl.section_vector():
212- pl.load(in_a, a, [0, 0])212+ pl.load(in_a, a, [0, 0])
213- example_vf_int64(in_a, t_out)213+ example_vf_int64(in_a, t_out)
214- pl.store(out, t_out, [0, 0])214+ pl.store(out, t_out, [0, 0])
215- 215+ 
216-def test_example_int64():216+def test_example_int64():
217- device_id = int(os.environ.get("TILE_FWK_DEVICE_ID", 0))217+ device_id = int(os.environ.get("TILE_FWK_DEVICE_ID", 0))
218- device = f"npu:{device_id}"218+ device = f"npu:{device_id}"
219- core_nums = 1219+ core_nums = 1
220- torch.npu.set_device(device)220+ torch.npu.set_device(device)
221- a = torch.randint(-100, 100, [1, 32], device=device, dtype=torch.int64)221+ a = torch.randint(-100, 100, [1, 32], device=device, dtype=torch.int64)
222- out = torch.empty([1, 32], device=device, dtype=torch.int64)222+ out = torch.empty([1, 32], device=device, dtype=torch.int64)
223- example_kernel_int64[None, core_nums](a, out)223+ example_kernel_int64[None, core_nums](a, out)
224- torch.npu.synchronize()224+ torch.npu.synchronize()
225- torch.testing.assert_close(out, a, rtol=0, atol=0)225+ torch.testing.assert_close(out, a, rtol=0, atol=0)
226- 226+ 
227-if __name__ == "__main__":227+if __name__ == "__main__":
228- test_example_int64()228+ test_example_int64()
229- print("PASSED")229+ print("PASSED")
230```230```
@@ -3,13 +3,13 @@
3## 产品支持情况3## 产品支持情况
4 4 
5<!-- npu="950" id1 -->5<!-- npu="950" id1 -->
6-- Ascend 950PR/Ascend 950DT:支持6+- Ascend 950PR&950DT系列产品:支持
7<!-- end id1 -->7<!-- end id1 -->
8<!-- npu="A3" id2 -->8<!-- npu="A3" id2 -->
9-- Atlas A3 训练系列产品/Atlas A3 推理系列产品:不支持9+- Atlas A3系列产品:不支持
10<!-- end id2 -->10<!-- end id2 -->
11<!-- npu="910b" id3 -->11<!-- npu="910b" id3 -->
12-- Atlas A2 训练系列产品/Atlas A2 推理系列产品:不支持12+- Atlas A2系列产品:不支持
13<!-- end id3 -->13<!-- end id3 -->
14 14 
15## 功能说明15## 功能说明
@@ -30,7 +30,7 @@ load_unalign_init() -> ureg
30 30 
31## 约束说明31## 约束说明
32 32 
33-无。33+无。
34 34 
35## 返回值说明35## 返回值说明
36 36 
@@ -3,13 +3,13 @@
3## 产品支持情况3## 产品支持情况
4 4 
5<!-- npu="950" id1 -->5<!-- npu="950" id1 -->
6-- Ascend 950PR/Ascend 950DT:支持6+- Ascend 950PR&950DT系列产品:支持
7<!-- end id1 -->7<!-- end id1 -->
8<!-- npu="A3" id2 -->8<!-- npu="A3" id2 -->
9-- Atlas A3 训练系列产品/Atlas A3 推理系列产品:不支持9+- Atlas A3系列产品:不支持
10<!-- end id2 -->10<!-- end id2 -->
11<!-- npu="910b" id3 -->11<!-- npu="910b" id3 -->
12-- Atlas A2 训练系列产品/Atlas A2 推理系列产品:不支持12+- Atlas A2系列产品:不支持
13<!-- end id3 -->13<!-- end id3 -->
14 14 
15## 功能说明15## 功能说明
@@ -27,7 +27,7 @@ load_unalign_pre(align_reg, tile)
27| 参数 | 输入/输出 | 说明 |27| 参数 | 输入/输出 | 说明 |
28|---|---|---|28|---|---|---|
29| align_reg | 输入/输出 | 源操作数,非对齐寄存器,UnalignRegForLoad类型,用于缓存非32字节对齐的数据(由vf.load_unalign_init()创建)。 |29| align_reg | 输入/输出 | 源操作数,非对齐寄存器,UnalignRegForLoad类型,用于缓存非32字节对齐的数据(由vf.load_unalign_init()创建)。 |
30-| tile | 输入 | 源操作数,Tile地址,起始地址需要32字节对齐。支持的数据类型为:DT_INT8、DT_UINT8、DT_INT16、DT_UINT16、DT_FP16、DT_BF16、DT_INT32、DT_UINT32、DT_FP32、DT_INT64、DT_UINT64、DT_FP8E4M3FN、DT_FP8E5M2、DT_FP8E8M0、DT_HF8、DT_FP4E2M1、DT_FP4E1M2。 |30+| tile | 输入 | 源操作数,Tile地址,起始地址需要32字节对齐。支持的数据类型为:DT_INT8、DT_UINT8、DT_INT16、DT_UINT16、DT_FP16、DT_BF16、DT_INT32、DT_UINT32、DT_FP32、DT_INT64、DT_UINT64、DT_FP8E4M3FN、DT_FP8E5M2、DT_FP8E8M0、DT_HF8、DT_FP4E2M1、DT_FP4E1M2。 |
31 31 
32## 约束说明32## 约束说明
33 33 
@@ -35,7 +35,7 @@ load_unalign_pre(align_reg, tile)
35 35 
36## 返回值说明36## 返回值说明
37 37 
38-无。38+无。
39 39 
40## 调用示例40## 调用示例
41 41 
@@ -3,13 +3,13 @@
3## 产品支持情况3## 产品支持情况
4 4 
5<!-- npu="950" id1 -->5<!-- npu="950" id1 -->
6-- Ascend 950PR/Ascend 950DT:支持6+- Ascend 950PR&950DT系列产品:支持
7<!-- end id1 -->7<!-- end id1 -->
8<!-- npu="A3" id2 -->8<!-- npu="A3" id2 -->
9-- Atlas A3 训练系列产品/Atlas A3 推理系列产品:不支持9+- Atlas A3系列产品:不支持
10<!-- end id2 -->10<!-- end id2 -->
11<!-- npu="910b" id3 -->11<!-- npu="910b" id3 -->
12-- Atlas A2 训练系列产品/Atlas A2 推理系列产品:不支持12+- Atlas A2系列产品:不支持
13<!-- end id3 -->13<!-- end id3 -->
14 14 
15## 功能说明15## 功能说明
@@ -20,7 +20,7 @@
20 20 
21**图1**流水线等待示意图21**图1**流水线等待示意图
22 22 
23-![流水线等待示意图](../../../figures/pipeline_wait.jpg)23+![流水线等待示意图](../../../figures/pipeline_wait.jpg)
24 24 
25通过mode选择src→dst的类型组合,共支持12种合法组合(V*表示矢量,*_LD、*_ST、ST_*、LD_*表示标量,*_ALL表示该单元全量屏障):25通过mode选择src→dst的类型组合,共支持12种合法组合(V*表示矢量,*_LD、*_ST、ST_*、LD_*表示标量,*_ALL表示该单元全量屏障):
26 26 
@@ -49,15 +49,15 @@ mem_bar(mode: Optional[MemBarMode] = None)
49 49 
50| 参数 | 输入/输出 | 说明 |50| 参数 | 输入/输出 | 说明 |
51|---|---|---|51|---|---|---|
52-| mode | 输入 | 可选,屏障模式,对应[MemBarMode](../types/MemBarMode.md)类型,pypto_pro.language.MemBarMode枚举(见上表12种组合)。默认pypto_pro.language.MemBarMode.VST_VLD。mode只能取上表12种合法组合之一。 |52+| mode | 输入 | 可选,屏障模式,对应[MemBarMode](../types/MemBarMode.md)类型,pypto_pro.language.MemBarMode枚举(见上表12种组合)。默认pypto_pro.language.MemBarMode.VST_VLD。mode只能取上表12种合法组合之一。 |
53 53 
54## 约束说明54## 约束说明
55 55 
56-无。56+无。
57 57 
58## 返回值说明58## 返回值说明
59 59 
60-无。60+无。
61 61 
62## 调用示例62## 调用示例
63 63 
@@ -3,13 +3,13 @@
3## 产品支持情况3## 产品支持情况
4 4 
5<!-- npu="950" id1 -->5<!-- npu="950" id1 -->
6-- Ascend 950PR/Ascend 950DT:支持6+- Ascend 950PR&950DT系列产品:支持
7<!-- end id1 -->7<!-- end id1 -->
8<!-- npu="A3" id2 -->8<!-- npu="A3" id2 -->
9-- Atlas A3 训练系列产品/Atlas A3 推理系列产品:不支持9+- Atlas A3系列产品:不支持
10<!-- end id2 -->10<!-- end id2 -->
11<!-- npu="910b" id3 -->11<!-- npu="910b" id3 -->
12-- Atlas A2 训练系列产品/Atlas A2 推理系列产品:不支持12+- Atlas A2系列产品:不支持
13<!-- end id3 -->13<!-- end id3 -->
14 14 
15## 功能说明15## 功能说明
@@ -19,7 +19,7 @@
19- **reg_tensor模式**:对src中的有效元素逐个复制写入dst中对应位置,无效位置保留dst原值。19- **reg_tensor模式**:对src中的有效元素逐个复制写入dst中对应位置,无效位置保留dst原值。
20- **mask_reg模式**:将src中的bit复制到dst中对应位置。如果有输入mask,则仅复制被mask选定的有效bit,无效位置填0。机制如下图所示:16位宽(DT_INT16、DT_UINT16、DT_FP16、DT_BF16)类型读取完整128bit的 {MASK1, MASK0},将每个bit复制为2bit;32位宽(DT_INT32、DT_UINT32、DT_FP32)类型读取64bit的MASK0,并将每个bit复制为4bit。20- **mask_reg模式**:将src中的bit复制到dst中对应位置。如果有输入mask,则仅复制被mask选定的有效bit,无效位置填0。机制如下图所示:16位宽(DT_INT16、DT_UINT16、DT_FP16、DT_BF16)类型读取完整128bit的 {MASK1, MASK0},将每个bit复制为2bit;32位宽(DT_INT32、DT_UINT32、DT_FP32)类型读取64bit的MASK0,并将每个bit复制为4bit。
21 21 
22- ![](../../../figures/move_mask_mode.jpg)22+ ![](../../../figures/move_mask_mode.jpg)
23 23 
24## 函数原型24## 函数原型
25 25 
@@ -33,11 +33,11 @@ move(src, preg, mode: Optional[MergeMode] = None) -> dst
33|---|---|---|33|---|---|---|
34| src | 输入 | 源操作数,[reg_tensor](../reg_tensor.md)或者[mask_reg](../mask_reg.md)类型,源操作数src与目的操作数dst的数据类型保持一致。支持的数据类型为:DT_BOOL、DT_INT8、DT_UINT8、DT_INT16、DT_UINT16、DT_FP16、DT_BF16、DT_INT32、DT_UINT32、DT_FP32、DT_INT64、DT_UINT64。 |34| src | 输入 | 源操作数,[reg_tensor](../reg_tensor.md)或者[mask_reg](../mask_reg.md)类型,源操作数src与目的操作数dst的数据类型保持一致。支持的数据类型为:DT_BOOL、DT_INT8、DT_UINT8、DT_INT16、DT_UINT16、DT_FP16、DT_BF16、DT_INT32、DT_UINT32、DT_FP32、DT_INT64、DT_UINT64。 |
35| preg | 输入 | [mask_reg](../mask_reg.md)。控制哪些元素/bit参与操作:<br>- **reg_tensor模式**:preg为元素操作的有效指示。preg选中的位置,将src中对应元素复制写入dst;preg未选中的位置,dst保留原值。<br>- **mask_reg模式**:preg控制哪些bit有效。preg选中的bit,将src中对应bit复制到dst;preg未选中的bit,dst对应位置填0。 |35| preg | 输入 | [mask_reg](../mask_reg.md)。控制哪些元素/bit参与操作:<br>- **reg_tensor模式**:preg为元素操作的有效指示。preg选中的位置,将src中对应元素复制写入dst;preg未选中的位置,dst保留原值。<br>- **mask_reg模式**:preg控制哪些bit有效。preg选中的bit,将src中对应bit复制到dst;preg未选中的bit,dst对应位置填0。 |
36-| mode | 输入 | 可选,对应[MergeMode](../types/MergeMode.md)类型。<br>- pypto_pro.language.MergeMode.MERGING(默认),preg未选中的元素在dst中保留原值。<br>- pypto_pro.language.MergeMode.ZEROING,当前**不支持**。 |36+| mode | 输入 | 可选,对应[MergeMode](../types/MergeMode.md)类型。<br>- pypto_pro.language.MergeMode.MERGING(默认),preg未选中的元素在dst中保留原值。<br>- pypto_pro.language.MergeMode.ZEROING,当前**不支持**。 |
37 37 
38## 约束说明38## 约束说明
39 39 
40-无。40+无。
41 41 
42## 返回值说明42## 返回值说明
43 43 
@@ -191,49 +191,49 @@ if __name__ == "__main__":
191 test_example_fp8()191 test_example_fp8()
192 print("PASSED")192 print("PASSED")
193```193```
194- 194+ 
195-### INT64数据类型示例195+### INT64数据类型示例
196- 196+ 
197-```python197+```python
198-import os198+import os
199-import pypto_pro.language as pl199+import pypto_pro.language as pl
200-import torch200+import torch
201-import torch_npu201+import torch_npu
202- 202+ 
203-@pl.vector_function203+@pl.vector_function
204-def example_vf_int64(src_tile, dst_tile):204+def example_vf_int64(src_tile, dst_tile):
205- preg = vf.create_mask(pattern=pl.MaskPattern.ALL, dtype=pl.DT_INT64)205+ preg = vf.create_mask(pattern=pl.MaskPattern.ALL, dtype=pl.DT_INT64)
206- reg_a = vf.load_align(src_tile, 0)206+ reg_a = vf.load_align(src_tile, 0)
207- reg_out = vf.move(reg_a, preg)207+ reg_out = vf.move(reg_a, preg)
208- vf.store_align(dst_tile, reg_out, preg)208+ vf.store_align(dst_tile, reg_out, preg)
209- 209+ 
210-@pl.jit()210+@pl.jit()
211-def example_kernel_int64(211+def example_kernel_int64(
212- a: pl.Tensor[[pl.DYNAMIC, pl.DYNAMIC], pl.DT_INT64],212+ a: pl.Tensor[[pl.DYNAMIC, pl.DYNAMIC], pl.DT_INT64],
213- out: pl.Tensor[[pl.DYNAMIC, pl.DYNAMIC], pl.DT_INT64],213+ out: pl.Tensor[[pl.DYNAMIC, pl.DYNAMIC], pl.DT_INT64],
214-):214+):
215- tf = pl.TileType(shape=[1, 32], dtype=pl.DT_INT64, target_memory=pl.MemorySpace.Vec)215+ tf = pl.TileType(shape=[1, 32], dtype=pl.DT_INT64, target_memory=pl.MemorySpace.Vec)
216 in_a_grp = pl.make_tile_group(type=tf, addrs=0, mutex_ids=[0])216 in_a_grp = pl.make_tile_group(type=tf, addrs=0, mutex_ids=[0])
217 in_a = in_a_grp.current()217 in_a = in_a_grp.current()
218 t_out_grp = pl.make_tile_group(type=tf, addrs=256, mutex_ids=[1])218 t_out_grp = pl.make_tile_group(type=tf, addrs=256, mutex_ids=[1])
219 t_out = t_out_grp.current()219 t_out = t_out_grp.current()
220- with pl.section_vector():220+ with pl.section_vector():
221- pl.load(in_a, a, [0, 0])221+ pl.load(in_a, a, [0, 0])
222- example_vf_int64(in_a, t_out)222+ example_vf_int64(in_a, t_out)
223- pl.store(out, t_out, [0, 0])223+ pl.store(out, t_out, [0, 0])
224- 224+ 
225-def test_example_int64():225+def test_example_int64():
226- device_id = int(os.environ.get("TILE_FWK_DEVICE_ID", 0))226+ device_id = int(os.environ.get("TILE_FWK_DEVICE_ID", 0))
227- device = f"npu:{device_id}"227+ device = f"npu:{device_id}"
228- core_nums = 1228+ core_nums = 1
229- torch.npu.set_device(device)229+ torch.npu.set_device(device)
230- a = torch.randint(-100, 100, [1, 32], device=device, dtype=torch.int64)230+ a = torch.randint(-100, 100, [1, 32], device=device, dtype=torch.int64)
231- out = torch.empty([1, 32], device=device, dtype=torch.int64)231+ out = torch.empty([1, 32], device=device, dtype=torch.int64)
232- example_kernel_int64[None, core_nums](a, out)232+ example_kernel_int64[None, core_nums](a, out)
233- torch.npu.synchronize()233+ torch.npu.synchronize()
234- torch.testing.assert_close(out, a, rtol=0, atol=0)234+ torch.testing.assert_close(out, a, rtol=0, atol=0)
235- 235+ 
236-if __name__ == "__main__":236+if __name__ == "__main__":
237- test_example_int64()237+ test_example_int64()
238- print("PASSED")238+ print("PASSED")
239```239```
@@ -3,22 +3,22 @@
3## 产品支持情况3## 产品支持情况
4 4 
5<!-- npu="950" id1 -->5<!-- npu="950" id1 -->
6-- Ascend 950PR/Ascend 950DT:支持6+- Ascend 950PR&950DT系列产品:支持
7<!-- end id1 -->7<!-- end id1 -->
8<!-- npu="A3" id2 -->8<!-- npu="A3" id2 -->
9-- Atlas A3 训练系列产品/Atlas A3 推理系列产品:不支持9+- Atlas A3系列产品:不支持
10<!-- end id2 -->10<!-- end id2 -->
11<!-- npu="910b" id3 -->11<!-- npu="910b" id3 -->
12-- Atlas A2 训练系列产品/Atlas A2 推理系列产品:不支持12+- Atlas A2系列产品:不支持
13<!-- end id3 -->13<!-- end id3 -->
14 14 
15## 功能说明15## 功能说明
16 16 
17-该指令会根据索引值index将源操作数src中的元素分散到目的操作数Tile中。分散过程如下图所示:17+该指令会根据索引值index将源操作数src中的元素分散到目的操作数Tile中。分散过程如下图所示:
18 18 
19**图1** vf.scatter功能说明19**图1** vf.scatter功能说明
20 20 
21-![vf.scatter功能说明](../../../figures/scatter_function.jpg)21+![vf.scatter功能说明](../../../figures/scatter_function.jpg)
22 22 
23## 函数原型23## 函数原型
24 24 
@@ -30,7 +30,7 @@ scatter(tile, src, index, preg)
30 30 
31| 参数 | 输入/输出 | 说明 |31| 参数 | 输入/输出 | 说明 |
32|---|---|---|32|---|---|---|
33-| tile | 输出 | 目的操作数,Tile地址,需要32字节对齐。 |33+| tile | 输出 | 目的操作数,Tile地址,需要32字节对齐。 |
34| src | 输入 | 源操作数,[reg_tensor](../reg_tensor.md),支持的数据类型请参见[约束说明](#约束说明)。当src为DT_INT8或者DT_UINT8数据类型时,源操作数中仅偶数位元素有效。即src中的偶数位置[0, 2, 4, ..., 252, 254]的数据会被分散存储到目的操作数中。 |34| src | 输入 | 源操作数,[reg_tensor](../reg_tensor.md),支持的数据类型请参见[约束说明](#约束说明)。当src为DT_INT8或者DT_UINT8数据类型时,源操作数中仅偶数位元素有效。即src中的偶数位置[0, 2, 4, ..., 252, 254]的数据会被分散存储到目的操作数中。 |
35| index | 输入 | 索引值,[reg_tensor](../reg_tensor.md),支持的数据类型请参见[约束说明](#约束说明),src中的每个元素在Tile中相对于基地址的位置,单位:元素个数。index中的值必须唯一,若存在重复的index值,系统仅保留其中一个对应的数据。 |35| index | 输入 | 索引值,[reg_tensor](../reg_tensor.md),支持的数据类型请参见[约束说明](#约束说明),src中的每个元素在Tile中相对于基地址的位置,单位:元素个数。index中的值必须唯一,若存在重复的index值,系统仅保留其中一个对应的数据。 |
36| preg | 输入 | [mask_reg](../mask_reg.md)。 |36| preg | 输入 | [mask_reg](../mask_reg.md)。 |
@@ -57,7 +57,7 @@ scatter(tile, src, index, preg)
57 57 
58## 返回值说明58## 返回值说明
59 59 
60-无。60+无。
61 61 
62## 调用示例62## 调用示例
63 63 
@@ -112,51 +112,51 @@ if __name__ == "__main__":
112 test_example()112 test_example()
113 print("PASSED")113 print("PASSED")
114```114```
115- 115+ 
116-### INT64数据类型示例116+### INT64数据类型示例
117- 117+ 
118-```python118+```python
119-import os119+import os
120-import pypto_pro.language as pl120+import pypto_pro.language as pl
121-import torch121+import torch
122-import torch_npu122+import torch_npu
123- 123+ 
124-@pl.vector_function124+@pl.vector_function
125-def example_vf_int64(src_tile, dst_tile):125+def example_vf_int64(src_tile, dst_tile):
126- preg = vf.create_mask(pattern=pl.MaskPattern.ALL, dtype=pl.DT_INT64)126+ preg = vf.create_mask(pattern=pl.MaskPattern.ALL, dtype=pl.DT_INT64)
127- reg_a = vf.load_align(src_tile, 0)127+ reg_a = vf.load_align(src_tile, 0)
128- reg_idx = vf.full(0, preg, dtype=pl.DT_UINT32)128+ reg_idx = vf.full(0, preg, dtype=pl.DT_UINT32)
129- vf.scatter(dst_tile, reg_a, reg_idx, preg)129+ vf.scatter(dst_tile, reg_a, reg_idx, preg)
130- reg_out = reg_a130+ reg_out = reg_a
131- vf.store_align(dst_tile, reg_out, preg)131+ vf.store_align(dst_tile, reg_out, preg)
132- 132+ 
133-@pl.jit()133+@pl.jit()
134-def example_kernel_int64(134+def example_kernel_int64(
135- a: pl.Tensor[[pl.DYNAMIC, pl.DYNAMIC], pl.DT_INT64],135+ a: pl.Tensor[[pl.DYNAMIC, pl.DYNAMIC], pl.DT_INT64],
136- out: pl.Tensor[[pl.DYNAMIC, pl.DYNAMIC], pl.DT_INT64],136+ out: pl.Tensor[[pl.DYNAMIC, pl.DYNAMIC], pl.DT_INT64],
137-):137+):
138- tf = pl.TileType(shape=[1, 32], dtype=pl.DT_INT64, target_memory=pl.MemorySpace.Vec)138+ tf = pl.TileType(shape=[1, 32], dtype=pl.DT_INT64, target_memory=pl.MemorySpace.Vec)
139 in_a_grp = pl.make_tile_group(type=tf, addrs=0, mutex_ids=[0])139 in_a_grp = pl.make_tile_group(type=tf, addrs=0, mutex_ids=[0])
140 in_a = in_a_grp.current()140 in_a = in_a_grp.current()
141 t_out_grp = pl.make_tile_group(type=tf, addrs=256, mutex_ids=[1])141 t_out_grp = pl.make_tile_group(type=tf, addrs=256, mutex_ids=[1])
142 t_out = t_out_grp.current()142 t_out = t_out_grp.current()
143- with pl.section_vector():143+ with pl.section_vector():
144- pl.load(in_a, a, [0, 0])144+ pl.load(in_a, a, [0, 0])
145- example_vf_int64(in_a, t_out)145+ example_vf_int64(in_a, t_out)
146- pl.store(out, t_out, [0, 0])146+ pl.store(out, t_out, [0, 0])
147- 147+ 
148-def test_example_int64():148+def test_example_int64():
149- device_id = int(os.environ.get("TILE_FWK_DEVICE_ID", 0))149+ device_id = int(os.environ.get("TILE_FWK_DEVICE_ID", 0))
150- device = f"npu:{device_id}"150+ device = f"npu:{device_id}"
151- core_nums = 1151+ core_nums = 1
152- torch.npu.set_device(device)152+ torch.npu.set_device(device)
153- a = torch.randint(-100, 100, [1, 32], device=device, dtype=torch.int64)153+ a = torch.randint(-100, 100, [1, 32], device=device, dtype=torch.int64)
154- out = torch.empty([1, 32], device=device, dtype=torch.int64)154+ out = torch.empty([1, 32], device=device, dtype=torch.int64)
155- example_kernel_int64[None, core_nums](a, out)155+ example_kernel_int64[None, core_nums](a, out)
156- torch.npu.synchronize()156+ torch.npu.synchronize()
157- torch.testing.assert_close(out, a, rtol=0, atol=0)157+ torch.testing.assert_close(out, a, rtol=0, atol=0)
158- 158+ 
159-if __name__ == "__main__":159+if __name__ == "__main__":
160- test_example_int64()160+ test_example_int64()
161- print("PASSED")161+ print("PASSED")
162```162```
@@ -3,13 +3,13 @@
3## 产品支持情况3## 产品支持情况
4 4 
5<!-- npu="950" id1 -->5<!-- npu="950" id1 -->
6-- Ascend 950PR/Ascend 950DT:支持6+- Ascend 950PR&950DT系列产品:支持
7<!-- end id1 -->7<!-- end id1 -->
8<!-- npu="A3" id2 -->8<!-- npu="A3" id2 -->
9-- Atlas A3 训练系列产品/Atlas A3 推理系列产品:不支持9+- Atlas A3系列产品:不支持
10<!-- end id2 -->10<!-- end id2 -->
11<!-- npu="910b" id3 -->11<!-- npu="910b" id3 -->
12-- Atlas A2 训练系列产品/Atlas A2 推理系列产品:不支持12+- Atlas A2系列产品:不支持
13<!-- end id3 -->13<!-- end id3 -->
14 14 
15## 功能说明15## 功能说明
@@ -30,7 +30,7 @@ squeeze_store_unalign(tile, src, align_reg)
30 30 
31| 参数 | 输入/输出 | 说明 |31| 参数 | 输入/输出 | 说明 |
32|---|---|---|32|---|---|---|
33-| tile | 输出 | 目的操作数,Tile地址。 |33+| tile | 输出 | 目的操作数,Tile地址。 |
34| src | 输入 | 源操作数,[reg_tensor](../reg_tensor.md)类型。支持的数据类型为:DT_INT8、DT_UINT8、DT_INT16、DT_UINT16、DT_FP16、DT_BF16、DT_INT32、DT_UINT32、DT_FP32、DT_INT64、DT_UINT64。 |34| src | 输入 | 源操作数,[reg_tensor](../reg_tensor.md)类型。支持的数据类型为:DT_INT8、DT_UINT8、DT_INT16、DT_UINT16、DT_FP16、DT_BF16、DT_INT32、DT_UINT32、DT_FP32、DT_INT64、DT_UINT64。 |
35| align_reg | 输入 | alignment tracker寄存器(由vf.unalign_reg_for_store()创建)。 |35| align_reg | 输入 | alignment tracker寄存器(由vf.unalign_reg_for_store()创建)。 |
36 36 
@@ -44,7 +44,7 @@ squeeze_store_unalign(tile, src, align_reg)
44 44 
45## 返回值说明45## 返回值说明
46 46 
47-无。47+无。
48 48 
49## 调用示例49## 调用示例
50 50 
@@ -3,13 +3,13 @@
3## 产品支持情况3## 产品支持情况
4 4 
5<!-- npu="950" id1 -->5<!-- npu="950" id1 -->
6-- Ascend 950PR/Ascend 950DT:支持6+- Ascend 950PR&950DT系列产品:支持
7<!-- end id1 -->7<!-- end id1 -->
8<!-- npu="A3" id2 -->8<!-- npu="A3" id2 -->
9-- Atlas A3 训练系列产品/Atlas A3 推理系列产品:不支持9+- Atlas A3系列产品:不支持
10<!-- end id2 -->10<!-- end id2 -->
11<!-- npu="910b" id3 -->11<!-- npu="910b" id3 -->
12-- Atlas A2 训练系列产品/Atlas A2 推理系列产品:不支持12+- Atlas A2系列产品:不支持
13<!-- end id3 -->13<!-- end id3 -->
14 14 
15## 功能说明15## 功能说明
@@ -26,7 +26,7 @@ squeeze_store_unalign_post(tile, align_reg)
26 26 
27| 参数 | 输入/输出 | 说明 |27| 参数 | 输入/输出 | 说明 |
28|---|---|---|28|---|---|---|
29-| tile | 输出 | 目的操作数,Tile地址。支持的数据类型为:DT_INT8、DT_UINT8、DT_INT16、DT_UINT16、DT_FP16、DT_BF16、DT_INT32、DT_UINT32、DT_FP32、DT_INT64、DT_UINT64。 |29+| tile | 输出 | 目的操作数,Tile地址。支持的数据类型为:DT_INT8、DT_UINT8、DT_INT16、DT_UINT16、DT_FP16、DT_BF16、DT_INT32、DT_UINT32、DT_FP32、DT_INT64、DT_UINT64。 |
30| align_reg | 输入 | alignment tracker寄存器(由vf.unalign_reg_for_store()创建)。 |30| align_reg | 输入 | alignment tracker寄存器(由vf.unalign_reg_for_store()创建)。 |
31 31 
32## 约束说明32## 约束说明
@@ -35,7 +35,7 @@ squeeze_store_unalign_post(tile, align_reg)
35 35 
36## 返回值说明36## 返回值说明
37 37 
38-无。38+无。
39 39 
40## 调用示例40## 调用示例
41 41 
@@ -3,13 +3,13 @@
3## 产品支持情况3## 产品支持情况
4 4 
5<!-- npu="950" id1 -->5<!-- npu="950" id1 -->
6-- Ascend 950PR/Ascend 950DT:支持6+- Ascend 950PR&950DT系列产品:支持
7<!-- end id1 -->7<!-- end id1 -->
8<!-- npu="A3" id2 -->8<!-- npu="A3" id2 -->
9-- Atlas A3 训练系列产品/Atlas A3 推理系列产品:不支持9+- Atlas A3系列产品:不支持
10<!-- end id2 -->10<!-- end id2 -->
11<!-- npu="910b" id3 -->11<!-- npu="910b" id3 -->
12-- Atlas A2 训练系列产品/Atlas A2 推理系列产品:不支持12+- Atlas A2系列产品:不支持
13<!-- end id3 -->13<!-- end id3 -->
14 14 
15## 功能说明15## 功能说明
@@ -26,17 +26,17 @@ store(tile, src, count)
26 26 
27| 参数 | 输入/输出 | 说明 |27| 参数 | 输入/输出 | 说明 |
28|---|---|---|28|---|---|---|
29-| tile | 输出 | 目的操作数,Tile地址,起始地址需要32字节对齐。 |29+| tile | 输出 | 目的操作数,Tile地址,起始地址需要32字节对齐。 |
30| src | 输入 | 源操作数,[reg_tensor](../reg_tensor.md),源操作数src与目的操作数dst的数据类型保持一致。支持的数据类型为:DT_INT8、DT_UINT8、DT_INT16、DT_UINT16、DT_FP16、DT_BF16、DT_INT32、DT_UINT32、DT_FP32、DT_INT64、DT_UINT64。 |30| src | 输入 | 源操作数,[reg_tensor](../reg_tensor.md),源操作数src与目的操作数dst的数据类型保持一致。支持的数据类型为:DT_INT8、DT_UINT8、DT_INT16、DT_UINT16、DT_FP16、DT_BF16、DT_INT32、DT_UINT32、DT_FP32、DT_INT64、DT_UINT64。 |
31| count | 输入 | 搬运数据量(元素个数)。count不能大于一个reg_tensor能存储的数据个数,即count <= 256B / sizeof(dtype)。 |31| count | 输入 | 搬运数据量(元素个数)。count不能大于一个reg_tensor能存储的数据个数,即count <= 256B / sizeof(dtype)。 |
32 32 
33## 约束说明33## 约束说明
34 34 
35-无。35+无。
36 36 
37## 返回值说明37## 返回值说明
38 38 
39-无。39+无。
40 40 
41## 调用示例41## 调用示例
42 42 
@@ -127,47 +127,47 @@ if __name__ == "__main__":
127 test_example_2()127 test_example_2()
128 print("PASSED")128 print("PASSED")
129```129```
130- 130+ 
131-### INT64数据类型示例131+### INT64数据类型示例
132- 132+ 
133-```python133+```python
134-import os134+import os
135-import pypto_pro.language as pl135+import pypto_pro.language as pl
136-import torch136+import torch
137-import torch_npu137+import torch_npu
138- 138+ 
139@pl.vector_function139@pl.vector_function
140def example_vf_int64(src_tile, dst_tile):140def example_vf_int64(src_tile, dst_tile):
141 reg_a = vf.load_align(src_tile, 0)141 reg_a = vf.load_align(src_tile, 0)
142- vf.store(dst_tile, reg_a)142+ vf.store(dst_tile, reg_a)
143- 143+ 
144-@pl.jit()144+@pl.jit()
145-def example_kernel_int64(145+def example_kernel_int64(
146- a: pl.Tensor[[pl.DYNAMIC, pl.DYNAMIC], pl.DT_INT64],146+ a: pl.Tensor[[pl.DYNAMIC, pl.DYNAMIC], pl.DT_INT64],
147- out: pl.Tensor[[pl.DYNAMIC, pl.DYNAMIC], pl.DT_INT64],147+ out: pl.Tensor[[pl.DYNAMIC, pl.DYNAMIC], pl.DT_INT64],
148-):148+):
149- tf = pl.TileType(shape=[1, 32], dtype=pl.DT_INT64, target_memory=pl.MemorySpace.Vec)149+ tf = pl.TileType(shape=[1, 32], dtype=pl.DT_INT64, target_memory=pl.MemorySpace.Vec)
150 in_a_grp = pl.make_tile_group(type=tf, addrs=0, mutex_ids=[0])150 in_a_grp = pl.make_tile_group(type=tf, addrs=0, mutex_ids=[0])
151 in_a = in_a_grp.current()151 in_a = in_a_grp.current()
152 t_out_grp = pl.make_tile_group(type=tf, addrs=256, mutex_ids=[1])152 t_out_grp = pl.make_tile_group(type=tf, addrs=256, mutex_ids=[1])
153 t_out = t_out_grp.current()153 t_out = t_out_grp.current()
154- with pl.section_vector():154+ with pl.section_vector():
155- pl.load(in_a, a, [0, 0])155+ pl.load(in_a, a, [0, 0])
156- example_vf_int64(in_a, t_out)156+ example_vf_int64(in_a, t_out)
157- pl.store(out, t_out, [0, 0])157+ pl.store(out, t_out, [0, 0])
158- 158+ 
159-def test_example_int64():159+def test_example_int64():
160- device_id = int(os.environ.get("TILE_FWK_DEVICE_ID", 0))160+ device_id = int(os.environ.get("TILE_FWK_DEVICE_ID", 0))
161- device = f"npu:{device_id}"161+ device = f"npu:{device_id}"
162- core_nums = 1162+ core_nums = 1
163- torch.npu.set_device(device)163+ torch.npu.set_device(device)
164- a = torch.randint(-100, 100, [1, 32], device=device, dtype=torch.int64)164+ a = torch.randint(-100, 100, [1, 32], device=device, dtype=torch.int64)
165- out = torch.empty([1, 32], device=device, dtype=torch.int64)165+ out = torch.empty([1, 32], device=device, dtype=torch.int64)
166- example_kernel_int64[None, core_nums](a, out)166+ example_kernel_int64[None, core_nums](a, out)
167- torch.npu.synchronize()167+ torch.npu.synchronize()
168- torch.testing.assert_close(out, a, rtol=0, atol=0)168+ torch.testing.assert_close(out, a, rtol=0, atol=0)
169- 169+ 
170-if __name__ == "__main__":170+if __name__ == "__main__":
171- test_example_int64()171+ test_example_int64()
172- print("PASSED")172+ print("PASSED")
173```173```
@@ -3,13 +3,13 @@
3## 产品支持情况3## 产品支持情况
4 4 
5<!-- npu="950" id1 -->5<!-- npu="950" id1 -->
6-- Ascend 950PR/Ascend 950DT:支持6+- Ascend 950PR&950DT系列产品:支持
7<!-- end id1 -->7<!-- end id1 -->
8<!-- npu="A3" id2 -->8<!-- npu="A3" id2 -->
9-- Atlas A3 训练系列产品/Atlas A3 推理系列产品:不支持9+- Atlas A3系列产品:不支持
10<!-- end id2 -->10<!-- end id2 -->
11<!-- npu="910b" id3 -->11<!-- npu="910b" id3 -->
12-- Atlas A2 训练系列产品/Atlas A2 推理系列产品:不支持12+- Atlas A2系列产品:不支持
13<!-- end id3 -->13<!-- end id3 -->
14 14 
15## 功能说明15## 功能说明
@@ -27,9 +27,9 @@ reg_tensor模式支持**连续搬运模式**和**非连续搬运模式**。连
27 27 
28**图1** vf.store_align连续对齐搬出分布模式图示28**图1** vf.store_align连续对齐搬出分布模式图示
29 29 
30-![](../../../figures/contiguous_aligned_store.jpg)30+![](../../../figures/contiguous_aligned_store.jpg)
31 31 
32-**非连续搬运模式**下,通过data_copy_mode=pypto_pro.language.DataCopyMode.DATA_BLOCK_COPY启用DataBlock搬运模式,实现数据从reg_tensor非连续搬运至Tile。单条指令一次搬运8个DataBlock,block_stride参数表示相邻DataBlock间的间隔。该模式下preg参数位置改为传入控制有效元素的mask_reg,mask控制规则如下:32+**非连续搬运模式**下,通过data_copy_mode=pypto_pro.language.DataCopyMode.DATA_BLOCK_COPY启用DataBlock搬运模式,实现数据从reg_tensor非连续搬运至Tile。单条指令一次搬运8个DataBlock,block_stride参数表示相邻DataBlock间的间隔。该模式下preg参数位置改为传入控制有效元素的mask_reg,mask控制规则如下:
33 33 
34- 某个DataBlock在mask中对应的32bit有任意一位为1时,该DataBlock对应的数据会被搬出到Tile。34- 某个DataBlock在mask中对应的32bit有任意一位为1时,该DataBlock对应的数据会被搬出到Tile。
35- 某个DataBlock在mask中对应的32bit全为0时,该DataBlock对应的数据不会被写出,Tile对应位置不更新,即使Tile越界也不会报错。35- 某个DataBlock在mask中对应的32bit全为0时,该DataBlock对应的数据不会被写出,Tile对应位置不更新,即使Tile越界也不会报错。
@@ -45,29 +45,29 @@ reg_tensor模式支持**连续搬运模式**和**非连续搬运模式**。连
45 45 
46mask_reg源支持两种分布模式,通过dist关键字参数配置:46mask_reg源支持两种分布模式,通过dist关键字参数配置:
47 47 
48-- pypto_pro.language.StoreDist.NORM(正常模式,搬运VL/8数据量)48+- pypto_pro.language.StoreDist.NORM(正常模式,搬运VL/8数据量)
49-- pypto_pro.language.StoreDist.PACK(压缩模式,每间隔1bit舍弃数据,将VL/8的数据压缩为VL/16搬出)49+- pypto_pro.language.StoreDist.PACK(压缩模式,每间隔1bit舍弃数据,将VL/8的数据压缩为VL/16搬出)
50 50 
51mask_reg模式同样支持三类搬运接口(普通搬运/PostUpdate/AddrReg)。51mask_reg模式同样支持三类搬运接口(普通搬运/PostUpdate/AddrReg)。
52 52 
53## 函数原型53## 函数原型
54 54 
55```python55```python
56-store_align(tile, src, preg, offset, dist=None, data_copy_mode=None, block_stride=None, repeat_stride=None, post_update=False)56+store_align(tile, src, preg, offset, dist=None, data_copy_mode=None, block_stride=None, repeat_stride=None, post_update=False)
57```57```
58 58 
59## 参数说明59## 参数说明
60 60 
61| 参数 | 输入/输出 | 说明 |61| 参数 | 输入/输出 | 说明 |
62|---|---|---|62|---|---|---|
63-| tile | 输出 | 目的操作数,Tile地址。地址需要32字节对齐。 |63+| tile | 输出 | 目的操作数,Tile地址。地址需要32字节对齐。 |
64-| src | 输入 | 源操作数,[reg_tensor](../reg_tensor.md)或者[mask_reg](../mask_reg.md)类型。支持的数据类型为:DT_INT8、DT_UINT8、DT_INT16、DT_UINT16、DT_FP16、DT_BF16、DT_INT32、DT_UINT32、DT_FP32、DT_INT64、DT_UINT64、DT_FP8E4M3FN、DT_FP8E5M2、DT_FP8E8M0、DT_HF8、DT_FP4E2M1、DT_FP4E1M2。<br>- 当源为reg_tensor时,单一src时,为**reg_tensor单搬出模式**;输入src_even和src_odd两个src时,为**reg_tensor双搬出模式**。<br>- 当源已通过vf.create_mask预声明为mask_reg时,自动分派mask_reg存储路径,将mask_reg中的数据搬出到Tile。 |64+| src | 输入 | 源操作数,[reg_tensor](../reg_tensor.md)或者[mask_reg](../mask_reg.md)类型。支持的数据类型为:DT_INT8、DT_UINT8、DT_INT16、DT_UINT16、DT_FP16、DT_BF16、DT_INT32、DT_UINT32、DT_FP32、DT_INT64、DT_UINT64、DT_FP8E4M3FN、DT_FP8E5M2、DT_FP8E8M0、DT_HF8、DT_FP4E2M1、DT_FP4E1M2。<br>- 当源为reg_tensor时,单一src时,为**reg_tensor单搬出模式**;输入src_even和src_odd两个src时,为**reg_tensor双搬出模式**。<br>- 当源已通过vf.create_mask预声明为mask_reg时,自动分派mask_reg存储路径,将mask_reg中的数据搬出到Tile。 |
65-| preg | 输入 | [mask_reg](../mask_reg.md),指定写入的元素范围。**mask_reg模式**时无需传入。<br>- **连续搬运模式**下,mask中对应的bit为1时,该元素被写入Tile;为0时,该元素不被写入,Tile对应位置保持原值不变。**非连续搬运模式**(DataBlock模式下data_copy_mode=pypto_pro.language.DataCopyMode.DATA_BLOCK_COPY),该位置改为传入控制有效元素的mask_reg,mask控制规则如下:某个DataBlock在mask中对应的32bit有任意一位为1时搬出,全为0时不写入且Tile对应位置不更新,即使Tile越界也不会报错。 |65+| preg | 输入 | [mask_reg](../mask_reg.md),指定写入的元素范围。**mask_reg模式**时无需传入。<br>- **连续搬运模式**下,mask中对应的bit为1时,该元素被写入Tile;为0时,该元素不被写入,Tile对应位置保持原值不变。**非连续搬运模式**(DataBlock模式下data_copy_mode=pypto_pro.language.DataCopyMode.DATA_BLOCK_COPY),该位置改为传入控制有效元素的mask_reg,mask控制规则如下:某个DataBlock在mask中对应的32bit有任意一位为1时搬出,全为0时不写入且Tile对应位置不更新,即使Tile越界也不会报错。 |
66-| offset | 输入 | 可选,末尾位置参数(第4个),根据模式和post_update取值自动分派语义,单位为元素个数。在**非连续搬运模式**(data_copy_mode=pypto_pro.language.DataCopyMode.DATA_BLOCK_COPY)下该参数位置为block_stride(见下)。<br>- **连续搬运模式 + post_update=False**:作为地址偏移量。<br>&nbsp;&nbsp;- **整数或[row, col]列表**:整数偏移在代码生成时转换为指针算术Tile + offset。传入[row, col]列表或元组,此时线性偏移为row * shape[1] + col,row单位为Tile的列数(即set_validshape[m, n]的n),col单位为元素个数,两者均支持表达式。<br>&nbsp;&nbsp;- **AddrReg**(由vf.create_addr_reg创建):实际搬运Tile地址为Tile + AddrReg中存储的偏移量。每次迭代需先调用vf.create_addr_reg设定偏移量再调用搬运指令。<br>- **连续搬运模式 + post_update=True**:作为PostUpdate地址累进步长(元素数),搬运后目标地址自动更新为dstAddr += stride。默认0。64位宽数据类型(DT_INT64、DT_UINT64)自动翻倍。<br>- **mask_reg模式**(源为mask_reg时):<br>&nbsp;&nbsp;- **整数**:仅在post_update=True时生效,作为地址更新步长;post_update=False时不支持整数offset。<br>&nbsp;&nbsp;- **AddrReg**(由vf.create_addr_reg创建):实际搬运Tile地址为dstAddr + AddrReg中存储的偏移量。 |66+| offset | 输入 | 可选,末尾位置参数(第4个),根据模式和post_update取值自动分派语义,单位为元素个数。在**非连续搬运模式**(data_copy_mode=pypto_pro.language.DataCopyMode.DATA_BLOCK_COPY)下该参数位置为block_stride(见下)。<br>- **连续搬运模式 + post_update=False**:作为地址偏移量。<br>&nbsp;&nbsp;- **整数或[row, col]列表**:整数偏移在代码生成时转换为指针算术Tile + offset。传入[row, col]列表或元组,此时线性偏移为row * shape[1] + col,row单位为Tile的列数(即set_validshape[m, n]的n),col单位为元素个数,两者均支持表达式。<br>&nbsp;&nbsp;- **AddrReg**(由vf.create_addr_reg创建):实际搬运Tile地址为Tile + AddrReg中存储的偏移量。每次迭代需先调用vf.create_addr_reg设定偏移量再调用搬运指令。<br>- **连续搬运模式 + post_update=True**:作为PostUpdate地址累进步长(元素数),搬运后目标地址自动更新为dstAddr += stride。默认0。64位宽数据类型(DT_INT64、DT_UINT64)自动翻倍。<br>- **mask_reg模式**(源为mask_reg时):<br>&nbsp;&nbsp;- **整数**:仅在post_update=True时生效,作为地址更新步长;post_update=False时不支持整数offset。<br>&nbsp;&nbsp;- **AddrReg**(由vf.create_addr_reg创建):实际搬运Tile地址为dstAddr + AddrReg中存储的偏移量。 |
67| dist | 输入 | 可选,数据存储分布模式,对应[StoreDist](../types/StoreDist.md)类型,具体模式根据是**reg_tensor单搬出模式**、**reg_tensor双搬出模式**还是**mask_reg模式**请分别参见[约束说明](#约束说明)中各表。 |67| dist | 输入 | 可选,数据存储分布模式,对应[StoreDist](../types/StoreDist.md)类型,具体模式根据是**reg_tensor单搬出模式**、**reg_tensor双搬出模式**还是**mask_reg模式**请分别参见[约束说明](#约束说明)中各表。 |
68-| data_copy_mode | 输入 | 可选,数据拷贝模式,对应[DataCopyMode](../types/DataCopyMode.md)类型。仅在src为reg_tensor下有效,mask_reg源不支持此参数。取值:pypto_pro.language.DataCopyMode.NORM(默认,普通连续搬运)或pypto_pro.language.DataCopyMode.DATA_BLOCK_COPY(非连续以DataBlock(32B)为单位进行搬运)。 |68+| data_copy_mode | 输入 | 可选,数据拷贝模式,对应[DataCopyMode](../types/DataCopyMode.md)类型。仅在src为reg_tensor下有效,mask_reg源不支持此参数。取值:pypto_pro.language.DataCopyMode.NORM(默认,普通连续搬运)或pypto_pro.language.DataCopyMode.DATA_BLOCK_COPY(非连续以DataBlock(32B)为单位进行搬运)。 |
69-| block_stride | 输入 | 可选,仅在data_copy_mode=pypto_pro.language.DataCopyMode.DATA_BLOCK_COPY模式下有效,其他模式下传入会被忽略。表示相邻DataBlock间的间隔,单位:DataBlock(32字节)。可作位置参数(第4个)或关键字参数传入。 |69+| block_stride | 输入 | 可选,仅在data_copy_mode=pypto_pro.language.DataCopyMode.DATA_BLOCK_COPY模式下有效,其他模式下传入会被忽略。表示相邻DataBlock间的间隔,单位:DataBlock(32字节)。可作位置参数(第4个)或关键字参数传入。 |
70-| repeat_stride | 输入 | 可选,仅在data_copy_mode=pypto_pro.language.DataCopyMode.DATA_BLOCK_COPY模式且post_update=True时有效。表示重复搬运时的地址更新步长,单位:DataBlock(32字节),需要32字节对齐。post_update=True时,搬运后目标地址自动更新为dstAddr += repeat_stride * 32B。可作位置参数(第5个)或关键字参数传入。 |70+| repeat_stride | 输入 | 可选,仅在data_copy_mode=pypto_pro.language.DataCopyMode.DATA_BLOCK_COPY模式且post_update=True时有效。表示重复搬运时的地址更新步长,单位:DataBlock(32字节),需要32字节对齐。post_update=True时,搬运后目标地址自动更新为dstAddr += repeat_stride * 32B。可作位置参数(第5个)或关键字参数传入。 |
71| post_update | 输入 | 可选,True时搬运后目标地址自动累进,默认False。适用于循环内连续存储。 |71| post_update | 输入 | 可选,True时搬运后目标地址自动累进,默认False。适用于循环内连续存储。 |
72 72 
73## 约束说明73## 约束说明
@@ -106,8 +106,8 @@ store_align(tile, src, preg, offset, dist=None, data_copy_mode=None, block_strid
106 106 
107 | dist取值 | 含义 | 对齐约束(Byte) |107 | dist取值 | 含义 | 对齐约束(Byte) |
108 |---|---|---|108 |---|---|---|
109- | pypto_pro.language.StoreDist.NORM | 正常模式,搬运VL/8数据。 | VL/8 |109+ | pypto_pro.language.StoreDist.NORM | 正常模式,搬运VL/8数据。 | VL/8 |
110- | pypto_pro.language.StoreDist.PACK | 压缩模式,每间隔1bit舍弃数据,将VL/8的数据压缩为VL/16搬出。 | VL/16 |110+ | pypto_pro.language.StoreDist.PACK | 压缩模式,每间隔1bit舍弃数据,将VL/8的数据压缩为VL/16搬出。 | VL/16 |
111 111 
112- 接口调用方式说明:112- 接口调用方式说明:
113 113 
@@ -121,7 +121,7 @@ store_align(tile, src, preg, offset, dist=None, data_copy_mode=None, block_strid
121 121 
122## 返回值说明122## 返回值说明
123 123 
124-无。124+无。
125 125 
126## 调用示例126## 调用示例
127 127 
@@ -172,7 +172,7 @@ if __name__ == "__main__":
172 172 
173### interleaved存储示例173### interleaved存储示例
174 174 
175-使用dist=pypto_pro.language.StoreDist.INTLV_B32将偶数/奇数寄存器交错写入Tile:175+使用dist=pypto_pro.language.StoreDist.INTLV_B32将偶数/奇数寄存器交错写入Tile:
176 176 
177```python177```python
178import os178import os
@@ -467,7 +467,7 @@ if __name__ == "__main__":
467 print("PASSED")467 print("PASSED")
468```468```
469 469 
470-### FP8数据存储示例470+### FP8数据存储示例
471 471 
472```python472```python
473import os473import os
@@ -516,48 +516,48 @@ if __name__ == "__main__":
516 test_example_fp8()516 test_example_fp8()
517 print("PASSED")517 print("PASSED")
518```518```
519- 519+ 
520-### INT64数据类型示例520+### INT64数据类型示例
521- 521+ 
522-```python522+```python
523-import os523+import os
524-import pypto_pro.language as pl524+import pypto_pro.language as pl
525-import torch525+import torch
526-import torch_npu526+import torch_npu
527- 527+ 
528@pl.vector_function528@pl.vector_function
529def example_vf_int64(src_tile, dst_tile):529def example_vf_int64(src_tile, dst_tile):
530 preg = vf.create_mask(pattern=pl.MaskPattern.ALL, dtype=pl.DT_INT64)530 preg = vf.create_mask(pattern=pl.MaskPattern.ALL, dtype=pl.DT_INT64)
531 reg_a = vf.load_align(src_tile, 0)531 reg_a = vf.load_align(src_tile, 0)
532- vf.store_align(dst_tile, reg_a, preg)532+ vf.store_align(dst_tile, reg_a, preg)
533- 533+ 
534-@pl.jit()534+@pl.jit()
535-def example_kernel_int64(535+def example_kernel_int64(
536- a: pl.Tensor[[pl.DYNAMIC, pl.DYNAMIC], pl.DT_INT64],536+ a: pl.Tensor[[pl.DYNAMIC, pl.DYNAMIC], pl.DT_INT64],
537- out: pl.Tensor[[pl.DYNAMIC, pl.DYNAMIC], pl.DT_INT64],537+ out: pl.Tensor[[pl.DYNAMIC, pl.DYNAMIC], pl.DT_INT64],
538-):538+):
539- tf = pl.TileType(shape=[1, 32], dtype=pl.DT_INT64, target_memory=pl.MemorySpace.Vec)539+ tf = pl.TileType(shape=[1, 32], dtype=pl.DT_INT64, target_memory=pl.MemorySpace.Vec)
540 in_a_grp = pl.make_tile_group(type=tf, addrs=0, mutex_ids=[0])540 in_a_grp = pl.make_tile_group(type=tf, addrs=0, mutex_ids=[0])
541 in_a = in_a_grp.current()541 in_a = in_a_grp.current()
542 t_out_grp = pl.make_tile_group(type=tf, addrs=256, mutex_ids=[1])542 t_out_grp = pl.make_tile_group(type=tf, addrs=256, mutex_ids=[1])
543 t_out = t_out_grp.current()543 t_out = t_out_grp.current()
544- with pl.section_vector():544+ with pl.section_vector():
545- pl.load(in_a, a, [0, 0])545+ pl.load(in_a, a, [0, 0])
546- example_vf_int64(in_a, t_out)546+ example_vf_int64(in_a, t_out)
547- pl.store(out, t_out, [0, 0])547+ pl.store(out, t_out, [0, 0])
548- 548+ 
549-def test_example_int64():549+def test_example_int64():
550- device_id = int(os.environ.get("TILE_FWK_DEVICE_ID", 0))550+ device_id = int(os.environ.get("TILE_FWK_DEVICE_ID", 0))
551- device = f"npu:{device_id}"551+ device = f"npu:{device_id}"
552- core_nums = 1552+ core_nums = 1
553- torch.npu.set_device(device)553+ torch.npu.set_device(device)
554- a = torch.randint(-100, 100, [1, 32], device=device, dtype=torch.int64)554+ a = torch.randint(-100, 100, [1, 32], device=device, dtype=torch.int64)
555- out = torch.empty([1, 32], device=device, dtype=torch.int64)555+ out = torch.empty([1, 32], device=device, dtype=torch.int64)
556- example_kernel_int64[None, core_nums](a, out)556+ example_kernel_int64[None, core_nums](a, out)
557- torch.npu.synchronize()557+ torch.npu.synchronize()
558- torch.testing.assert_close(out, a, rtol=0, atol=0)558+ torch.testing.assert_close(out, a, rtol=0, atol=0)
559- 559+ 
560-if __name__ == "__main__":560+if __name__ == "__main__":
561- test_example_int64()561+ test_example_int64()
562- print("PASSED")562+ print("PASSED")
563```563```