已合并
修正 MatmulAbftVerify Example 接口调用与libophost_ras.so的链接问题 #128
starfican创建于 26 天前
修正 MatmulAbftVerify Example 接口调用与libophost_ras.so的链接问题 #128
已合并
starfican创建于 26 天前
共 33 个文件变更+3226-367
@@ -31,7 +31,7 @@ Note that to ensure smooth custom development of your source code, select the ma
31 31 
32## 🛠️Environment Setup32## 🛠️Environment Setup
33 33 
34-[Environment Deployment](docs/zh/install/quick_install.md) is the prerequisite for experiencing the capabilities of this project. Please complete the NPU driver installation, CANN package installation, and so on to ensure the environment is normal.34+[Environment Deployment](docs/en/install/quick_install.md) is the prerequisite for experiencing the capabilities of this project. Please complete the NPU driver installation, CANN package installation, and so on to ensure the environment is normal.
35 35 
36## ⬇️Source Code Download36## ⬇️Source Code Download
37 37 
@@ -46,12 +46,12 @@ git clone -b 9.0.0 https://gitcode.com/cann/ops-ras.git
46 46 
47## 📖Learning Tutorials47## 📖Learning Tutorials
48 48 
49-- [Quick Start](docs/QUICKSTART.md): Quickly experience the core basic capabilities of the project from scratch, covering source code compilation, operator invocation, development, debugging, and other operations.49+- [Quick Start](docs/QUICKSTART_en.md): Quickly experience the core basic capabilities of the project from scratch, covering source code compilation, operator invocation, development, debugging, and other operations.
50-- [Advanced Tutorials](docs/README.md): If you need a deeper understanding of the project's compilation and deployment, operator invocation, development, debugging and tuning, and other capabilities, please refer to the documentation center for detailed guidance.50+- [Advanced Tutorials](docs/README_en.md): If you need a deeper understanding of the project's compilation and deployment, operator invocation, development, debugging and tuning, and other capabilities, please refer to the documentation center for detailed guidance.
51 51 
52## 💬Related Information52## 💬Related Information
53 53 
54-- [Directory Structure](docs/zh/install/dir_structure.md)54+- [Directory Structure](docs/en/install/dir_structure.md)
55- [Contribution Guide](CONTRIBUTING.md)55- [Contribution Guide](CONTRIBUTING.md)
56- [Security Statement](SECURITY.md)56- [Security Statement](SECURITY.md)
57- [License](LICENSE)57- [License](LICENSE)
@@ -28,6 +28,7 @@ function(gen_ophost_symbol)
28 PRIVATE $<BUILD_INTERFACE:intf_pub_cxx17>28 PRIVATE $<BUILD_INTERFACE:intf_pub_cxx17>
29 ${OPHOST_NAME}_obj29 ${OPHOST_NAME}_obj
30 -Wl,--no-as-needed30 -Wl,--no-as-needed
31+ register
31 acl_rt32 acl_rt
32 -Wl,--as-needed33 -Wl,--as-needed
33 -Wl,-Bsymbolic34 -Wl,-Bsymbolic
@@ -7,7 +7,7 @@
7# INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.7# INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.
8# See LICENSE in the root of the software repository for the full text of the License.8# See LICENSE in the root of the software repository for the full text of the License.
9# ----------------------------------------------------------------------------9# ----------------------------------------------------------------------------
10-set(OPBASE_TAG_ID b92c2c8f3d999f315b0251cfb25edb111bb898d5)10+set(OPBASE_TAG_ID 32b1c2ce574d2adaced2c3d27e92d4dda56eea85)
11 11 
12if(EXISTS "${PROJECT_SOURCE_DIR}/../../ops-base")12if(EXISTS "${PROJECT_SOURCE_DIR}/../../ops-base")
13 get_filename_component(OPBASE_SOURCE_PATH13 get_filename_component(OPBASE_SOURCE_PATH
@@ -492,7 +492,7 @@ REG_OP(Unsqueeze)
492 .OUTPUT(y, TensorType::ALL())492 .OUTPUT(y, TensorType::ALL())
493 .ATTR(axes, ListInt, {})493 .ATTR(axes, ListInt, {})
494 .OP_END_FACTORY_REG(Unsqueeze)494 .OP_END_FACTORY_REG(Unsqueeze)
495- 495+ 
496/**496/**
497* @brief Pad a tensor .497* @brief Pad a tensor .
498 498 
@@ -642,7 +642,7 @@ REG_OP(FullyConnection)
642* noop_with_empty_axes: An optional bool. Defaults to "true" .642* noop_with_empty_axes: An optional bool. Defaults to "true" .
643* - If true, when axes = [], not reduce.643* - If true, when axes = [], not reduce.
644* - If false, when axes = [], reduce all.644* - If false, when axes = [], reduce all.
645-* This attribute is valid only for Ascend910_95 AI Processors and later products.645+* This attribute is valid only for Ascend 950PR&Ascend 950DT products and later products.
646 646 
647* @par Outputs:647* @par Outputs:
648* y: A multi-dimensional Tensor, specifying the maximum value of the648* y: A multi-dimensional Tensor, specifying the maximum value of the
@@ -690,13 +690,13 @@ REG_OP(ReduceMax)
690* If the input data contains -inf, -inf is converted into the minimum value of int16. \n690* If the input data contains -inf, -inf is converted into the minimum value of int16. \n
691* @li In the scenarios where the data type is converted from INT32 to INT8: \n691* @li In the scenarios where the data type is converted from INT32 to INT8: \n
692* It can only guarantee that the input data has no precision errors within the range of (-2048, 1920).692* It can only guarantee that the input data has no precision errors within the range of (-2048, 1920).
693-* @li Atlas Inference Series Product in the scenarios where the data type is converted from FLOAT32 to INT8: \n693+* @li Atlas inference products in the scenarios where the data type is converted from FLOAT32 to INT8: \n
694* It can only guarantee that the input data has no precision errors within the range of (-2048, 1920).694* It can only guarantee that the input data has no precision errors within the range of (-2048, 1920).
695-* @li Atlas Inference Series Product in the scenarios where the data type is converted from FLOAT32 to INT64 and from FLOAT32 to UINT8: \n695+* @li Atlas inference products in the scenarios where the data type is converted from FLOAT32 to INT64 and from FLOAT32 to UINT8: \n
696* It can only guarantee that the input data has no precision errors within the range of (-2147483648, 2147483583).696* It can only guarantee that the input data has no precision errors within the range of (-2147483648, 2147483583).
697-* @li Atlas Inference Series Product in the scenarios where the data type is converted from INT64 to FLOAT32: \n697+* @li Atlas inference products in the scenarios where the data type is converted from INT64 to FLOAT32: \n
698* It can only guarantee that the input data has no precision errors within the range of (-2147483648, 2147483647).698* It can only guarantee that the input data has no precision errors within the range of (-2147483648, 2147483647).
699-* @li Ascend 910_95 AI Processor in the scenario where the data type is converted from INT32 to INT4: \n699+* @li Ascend 950PR&Ascend 950DT products in the scenario where the data type is converted from INT32 to INT4: \n
700* The last dim of x must be an even number.700* The last dim of x must be an even number.
701*/701*/
702REG_OP(Cast)702REG_OP(Cast)
@@ -23,19 +23,19 @@
23> 本指南以单算子编译过程为例,也支持编译整个算子库算子、离线编译等多种场景,更多编译参数说明参见[《build参数说明》](zh/install/build.md),编译过程中的常见问题均可参考[《源码构建指南》](zh/install/compile.md)。23> 本指南以单算子编译过程为例,也支持编译整个算子库算子、离线编译等多种场景,更多编译参数说明参见[《build参数说明》](zh/install/build.md),编译过程中的常见问题均可参考[《源码构建指南》](zh/install/compile.md)。
24 24 
25### 1. 进入项目源码25### 1. 进入项目源码
26- 26+ 
27- CANNLab云开发环境:27- CANNLab云开发环境:
28- 28+ 
29 默认提供最新最新版CANN包配套的项目源码,进入源码目录,\$\{gitCode\_id\}替换为开发者个人gitCode账号。29 默认提供最新最新版CANN包配套的项目源码,进入源码目录,\$\{gitCode\_id\}替换为开发者个人gitCode账号。
30- 30+ 
31 ```bash31 ```bash
32 cd /mnt/workspace/gitCode/${gitCode_id}/ops-ras32 cd /mnt/workspace/gitCode/${gitCode_id}/ops-ras
33 ```33 ```
34 34 
35- 非CANNLab云开发环境:35- 非CANNLab云开发环境:
36- 36+ 
37 根据[release仓库](https://gitcode.com/cann/release-management)源码与CANN版本配套关系,执行如下命令下载源码,\$\{tag\_version\}替换为目标分支标签,例如9.0.0。37 根据[release仓库](https://gitcode.com/cann/release-management)源码与CANN版本配套关系,执行如下命令下载源码,\$\{tag\_version\}替换为目标分支标签,例如9.0.0。
38- 38+ 
39 ```bash39 ```bash
40 git clone -b ${tag_version} https://gitcode.com/cann/ops-ras.git && cd ops-ras40 git clone -b ${tag_version} https://gitcode.com/cann/ops-ras.git && cd ops-ras
41 ```41 ```
@@ -57,9 +57,9 @@ bash build.sh --pkg --soc=${soc_version} --ops=add_example -j16
57 57 
58\$\{soc\_version\}取值请访问[CANN下载中心](https://www.hiascend.com/cann/download),根据页面提示查询硬件产品名,产品名对应的${soc_version}取值如下,请按实际场景传参。58\$\{soc\_version\}取值请访问[CANN下载中心](https://www.hiascend.com/cann/download),根据页面提示查询硬件产品名,产品名对应的${soc_version}取值如下,请按实际场景传参。
59 59 
60-- Atlas A2 训练系列产品/Atlas A2 推理系列产品:取值为ascend910b60+- Atlas A2系列产品:取值为ascend910b
61-- Atlas A3 训练系列产品/Atlas A3 推理系列产品:取值为ascend910_9361+- Atlas A3系列产品:取值为ascend910_93
62-- 950系列产品:取值为ascend95062+- Ascend 950PR&950DT系列产品:取值为ascend950
63 63 
64若提示如下信息,说明编译成功。64若提示如下信息,说明编译成功。
65 65 
@@ -4,7 +4,7 @@
4 4 
5This guide aims to help you quickly get started with CANN and the `ops-ras` operator repository. To help you quickly understand the entire process of operator development, we will use the **AddExample** operator as a practical object. Its source code is located in `ops-ras/examples/add_example`. The operation process is as follows:5This guide aims to help you quickly get started with CANN and the `ops-ras` operator repository. To help you quickly understand the entire process of operator development, we will use the **AddExample** operator as a practical object. Its source code is located in `ops-ras/examples/add_example`. The operation process is as follows:
6 6 
7-1. **[Prerequisites](../README.md)**: Complete the environment setup and source code download by referring to the project README. The process is not repeated here. For the quick start scenario, **CANNLab or Docker deployment is recommended** for simple operation.7+1. **[Prerequisites](../README_en.md)**: Complete the environment setup and source code download by referring to the project README. The process is not repeated here. For the quick start scenario, **CANNLab or Docker deployment is recommended** for simple operation.
8 8 
9 > **Note**: The CANNLab or Docker environment provides the latest version of the CANN package by default. If you need to experience the latest capabilities of the master branch, you can manually set up the environment.9 > **Note**: The CANNLab or Docker environment provides the latest version of the CANN package by default. If you need to experience the latest capabilities of the master branch, you can manually set up the environment.
10 10 
@@ -57,9 +57,9 @@ bash build.sh --pkg --soc=${soc_version} --ops=add_example -j16
57 57 
58For the value of `${soc_version}`, visit the [CANN Download Center](https://www.hiascend.com/cann/download) and query the hardware product name according to the page prompts. The corresponding `${soc_version}` values for product names are as follows. Please pass the parameter according to the actual scenario.58For the value of `${soc_version}`, visit the [CANN Download Center](https://www.hiascend.com/cann/download) and query the hardware product name according to the page prompts. The corresponding `${soc_version}` values for product names are as follows. Please pass the parameter according to the actual scenario.
59 59 
60-- Atlas A2 Training Series Products/Atlas A2 Inference Series Products: `ascend910b`60+- Atlas A2 products: `ascend910b`
61-- Atlas A3 Training Series Products/Atlas A3 Inference Series Products: `ascend910_93`61+- Atlas A3 products: `ascend910_93`
62-- Ascend 950 Series Products: `ascend950`62+- Ascend 950PR&950DT products: `ascend950`
63 63 
64If the following information is prompted, the compilation is successful.64If the following information is prompted, the compilation is successful.
65 65 
@@ -272,4 +272,4 @@ int main() {
272 272 
273## Conclusion273## Conclusion
274 274 
275-After experiencing the above processes, you have basically completed the operator development process. If you want to further contribute new operators or learn more advanced development, debugging, and other skills, please visit the project README to learn about [Advanced Tutorials](../README.md#学习教程) and [Contribution Guide](../README.md#相关信息), and so on.275+After experiencing the above processes, you have basically completed the operator development process. If you want to further contribute new operators or learn more advanced development, debugging, and other skills, please visit the project README to learn about [Advanced Tutorials](../README_en.md#learning-tutorials) and [Contribution Guide](../README_en.md#related-information), and so on.
@@ -41,24 +41,24 @@ The Docs directory structure is described as follows:
41 41 
42| Document | Description |42| Document | Description |
43| ------------------------------------------------------------ | ------------------------------------------------------------ |43| ------------------------------------------------------------ | ------------------------------------------------------------ |
44-| [Source Code Build Guide](zh/install/compile.md) | Introduces different source code build methods and verification methods in online and offline scenarios. |44+| [Source Code Build Guide](en/install/compile.md) | Introduces different source code build methods and verification methods in online and offline scenarios. |
45-| [Operator Invocation Guide](zh/invocation/quick_op_invocation.md) | Introduces the method of invoking operator samples and different operator invocation methods (such as aclnn/graph, and so on). |45+| [Operator Invocation Guide](en/invocation/quick_op_invocation.md) | Introduces the method of invoking operator samples and different operator invocation methods (such as aclnn/graph, and so on). |
46-| [Standard Operator Development Guide](zh/develop/aicore_develop_guide.md) | Introduces how to define operator prototypes and implement Tiling and Kernel based on standard engineering. Such operators are called "standard operators".<br>Standard operators support aclnn and graph mode invocation. |46+| [Standard Operator Development Guide](en/develop/aicore_develop_guide.md) | Introduces how to define operator prototypes and implement Tiling and Kernel based on standard engineering. Such operators are called "standard operators".<br>Standard operators support aclnn and graph mode invocation. |
47| [Simple Operator Development Guide](../examples/fast_kernel_launch_example/README.md) | Introduces how to implement fast_kernel_launch based on simple engineering, that is, the `<<<>>>` method. Such operators are called "simple operators".<br>Simple operators only support PyTorch invocation. |47| [Simple Operator Development Guide](../examples/fast_kernel_launch_example/README.md) | Introduces how to implement fast_kernel_launch based on simple engineering, that is, the `<<<>>>` method. Such operators are called "simple operators".<br>Simple operators only support PyTorch invocation. |
48-| [Operator Debugging and Tuning](zh/debug/op_debug_prof.md) | Introduces common operator function debugging and performance tuning methods (such as data collection and simulation pipeline, and so on). |48+| [Operator Debugging and Tuning](en/debug/op_debug_prof.md) | Introduces common operator function debugging and performance tuning methods (such as data collection and simulation pipeline, and so on). |
49 49 
50### API Documents50### API Documents
51 51 
52| Document | Description |52| Document | Description |
53| ----------------------- | ---------------------- |53| ----------------------- | ---------------------- |
54-| [Operator List](zh/op_list.md) | Introduces the list of all operators included in the project. |54+| [Operator List](en/op_list.md) | Introduces the list of all operators included in the project. |
55-| [aclnn List](zh/op_api_list.md) | Introduces the list of all operator aclnn APIs included in the project. To facilitate users to invoke operators on the Host side, C language APIs are provided, that is, APIs with the aclnn prefix. |55+| [aclnn List](en/op_api_list.md) | Introduces the list of all operator aclnn APIs included in the project. To facilitate users to invoke operators on the Host side, C language APIs are provided, that is, APIs with the aclnn prefix. |
56 56 
57### Tool Documents57### Tool Documents
58 58 
59| Document | Description |59| Document | Description |
60| ----------------------- | ---------------------- |60| ----------------------- | ---------------------- |
61-| [Simulator Tool](zh/debug/cann_sim.md) | A SoC-level simulation tool for operator development scenarios, used to analyze the precision and performance data of AI tasks running on the AI simulator at each stage. |61+| [Simulator Tool](en/debug/cann_sim.md) | A SoC-level simulation tool for operator development scenarios, used to analyze the precision and performance data of AI tasks running on the AI simulator at each stage. |
62 62 
63### More Documents63### More Documents
64 64 
@@ -68,5 +68,5 @@ The Docs directory structure is described as follows:
68 68 
69| Document | Description |69| Document | Description |
70| ----------------------------------- | ------------------------------------------------------------ |70| ----------------------------------- | ------------------------------------------------------------ |
71-| [Operator Basic Concepts](zh/context/basic_concept.md) | Introduces basic concepts and terminology in the operator domain, such as quantization/sparse, data types, data formats, and so on. |71+| [Operator Basic Concepts](en/context/basic_concept.md) | Introduces basic concepts and terminology in the operator domain, such as quantization/sparse, data types, data formats, and so on. |
72-| [build Parameter Description](zh/install/build.md) | Introduces the functions and parameter values of the build.sh script in this project, including source code compilation, operator invocation, debugging, and so on. |72+| [build Parameter Description](en/install/build.md) | Introduces the functions and parameter values of the build.sh script in this project, including source code compilation, operator invocation, debugging, and so on. |
@@ -1,7 +1,7 @@
1# aclnn Return Codes1# aclnn Return Codes
2 2 
3When calling aclnn APIs, common interface return codes are shown in [Table 1](#table1).3When calling aclnn APIs, common interface return codes are shown in [Table 1](#table1).
4-For abnormal status code values, you can use the aclGetRecentErrMsg interface (refer to [ACL API (C)](https://www.hiascend.com/document/detail/en/canncommercial/latest/API/appdevgapi/aclcppdevg_03_0004.html)) to obtain exception information. You can troubleshoot the problem based on the error message or contact technical support.4+For abnormal status code values, you can use the aclGetRecentErrMsg interface (refer to [ACL API (C)](https://www.hiascend.com/document/detail/en/canncommercial/latest/API/appdevgapi/aclcppdevg_03_0004.html)) to obtain exception information. You can troubleshoot the problem based on the error message or submit issues.
5 5 
6**Table 1** Return Status Codes6**Table 1** Return Status Codes
7 7 
@@ -6,7 +6,7 @@
6 - [Data Format](./data_format.md)6 - [Data Format](./data_format.md)
7 - [Non Contiguous Tensor](./non_contiguous_tensor.md)7 - [Non Contiguous Tensor](./non_contiguous_tensor.md)
8 - [Broadcast Relationship](./broadcast_relationship.md)8 - [Broadcast Relationship](./broadcast_relationship.md)
9- - [Decuction Relationship](./decuction_relationship.md)9+ - [Deduction Relationship](./deduction_relationship.md)
10 - [Conversion Relationship](./conversion_relationship.md)10 - [Conversion Relationship](./conversion_relationship.md)
11 - [Quant more Introduction](./quant_more_introduction.md)11 - [Quant more Introduction](./quant_more_introduction.md)
12 - [Sparse Mode Introduction](./sparse_mode_introduction.md)12 - [Sparse Mode Introduction](./sparse_mode_introduction.md)
@@ -110,7 +110,7 @@ Common debugging methods are as follows:
110 110 
111## Performance Tuning111## Performance Tuning
112 112 
113-### Method 1 (For Atlas A2/A3 Series Products)113+### Method 1 (For Atlas A2 Products/Atlas A3 Products)
114 114 
115If execution accuracy degradation or abnormal memory usage occurs during operator execution, you can use the [msProf](https://www.hiascend.com/document/detail/en/CANNCommunityEdition/latest/devaids/optool/docs/en/quick_start/msopprof_quick_start.md) performance analysis tool to analyze the operator's performance metrics at each execution stage (such as throughput, memory usage, and latency), thereby identifying the root cause and performing targeted optimization.115If execution accuracy degradation or abnormal memory usage occurs during operator execution, you can use the [msProf](https://www.hiascend.com/document/detail/en/CANNCommunityEdition/latest/devaids/optool/docs/en/quick_start/msopprof_quick_start.md) performance analysis tool to analyze the operator's performance metrics at each execution stage (such as throughput, memory usage, and latency), thereby identifying the root cause and performing targeted optimization.
116 116 
@@ -165,9 +165,9 @@ This chapter uses the [AddExample custom operator](../../../examples/add_example
165 The collection results are in the `$PWD/pipeline_auto/OPPROF_**` directory of this project.165 The collection results are in the `$PWD/pipeline_auto/OPPROF_**` directory of this project.
166 The pipeline-related file path is `OPPROF**/simulator/visualize_data.bin`, which can be viewed using the [mindStudio Insight](https://www.hiascend.com/document/detail/en/mindstudio/latest/visualization_tool/MindStudioInsight/docs/en/user_guide/overview.md) tool.166 The pipeline-related file path is `OPPROF**/simulator/visualize_data.bin`, which can be viewed using the [mindStudio Insight](https://www.hiascend.com/document/detail/en/mindstudio/latest/visualization_tool/MindStudioInsight/docs/en/user_guide/overview.md) tool.
167 167 
168-### Method 2 (For Ascend 950PR)168+### Method 2 (For Ascend 950PR&950DT products)
169 169 
170-If execution accuracy degradation or abnormal memory usage occurs during operator development, you can use the [CANN Simulator](./cann_simulator.md) simulation tool to analyze the operator's instruction pipeline situation, thereby identifying the root cause and performing targeted optimization.170+If execution accuracy degradation or abnormal memory usage occurs during operator development, you can use the [CANN Simulator](./cann_sim.md) simulation tool to analyze the operator's instruction pipeline situation, thereby identifying the root cause and performing targeted optimization.
171 171 
172This chapter uses the [AddExample custom operator](../../../examples/add_example/) as an example to introduce the use of the simulation tool. It describes how to perform accuracy and performance tuning through the simulation tool.172This chapter uses the [AddExample custom operator](../../../examples/add_example/) as an example to introduce the use of the simulation tool. It describes how to perform accuracy and performance tuning through the simulation tool.
173 173 
@@ -187,4 +187,4 @@ This chapter uses the [AddExample custom operator](../../../examples/add_example
187 trace_core0.json187 trace_core0.json
188 ```188 ```
189 189 
190-3. Enter "chrome://tracing" in the Chrome browser and drag the generated instruction pipeline diagram file (trace_core0.json) to the blank area to open it. For specific parameter descriptions, refer to the [Simulation Result Analysis](./cann_simulator.md#simulation-result-analysis-instructions) section in CANN Simulator.190+3. Enter "chrome://tracing" in the Chrome browser and drag the generated instruction pipeline diagram file (trace_core0.json) to the blank area to open it. For specific parameter descriptions, refer to the [Simulation Result Analysis](./cann_sim.md#simulation-result-analysis-instructions) section in CANN Simulator.
@@ -54,7 +54,7 @@ If compiling in an environment with internet access, third-party dependencies ar
54 # bash build.sh --pkg --experimental --soc=ascend910b --ops=add_example -j1654 # bash build.sh --pkg --experimental --soc=ascend910b --ops=add_example -j16
55 ```55 ```
56 56 
57- - --soc: ${soc_version} indicates the NPU model. Use "ascend910b" (default) for Atlas A2 Training Series/Atlas A2 Inference Series, "ascend910_93" for Atlas A3 Training Series/Atlas A3 Inference Series, and "ascend950" for Ascend 950PR/Ascend 950DT.57+ - --soc: ${soc_version} indicates the NPU model. Use "ascend910b" (default) for Atlas A2 products, "ascend910_93" for Atlas A3 products, and "ascend950" for Ascend 950PR&950DT products.
58 - --vendor_name (optional): ${vendor_name} indicates the name of the custom operator package to build. The default name is custom.58 - --vendor_name (optional): ${vendor_name} indicates the name of the custom operator package to build. The default name is custom.
59 - --ops (optional): ${op_list} indicates the operators to compile. If not specified, all operators are compiled by default. The format is "add_example,crypto,...", with multiple operators separated by commas ",".59 - --ops (optional): ${op_list} indicates the operators to compile. If not specified, all operators are compiled by default. The format is "add_example,crypto,...", with multiple operators separated by commas ",".
60 - --experimental (optional): Indicates that operators saved by users in the experimental contribution directory should be compiled.60 - --experimental (optional): Indicates that operators saved by users in the experimental contribution directory should be compiled.
@@ -101,7 +101,7 @@ If compiling in an environment with internet access, third-party dependencies ar
101 # bash build.sh --pkg --experimental [--jit] --soc=${soc_version} [-j${n}]101 # bash build.sh --pkg --experimental [--jit] --soc=${soc_version} [-j${n}]
102 ```102 ```
103 103 
104- - --soc: ${soc_version} indicates the NPU model. Use "ascend910b" (default) for Atlas A2 Training Series/Atlas A2 Inference Series, "ascend910_93" for Atlas A3 Training Series/Atlas A3 Inference Series, and "ascend950" for Ascend 950PR/Ascend 950DT.104+ - --soc: ${soc_version} indicates the NPU model. Use "ascend910b" (default) for Atlas A2 products, "ascend910_93" for Atlas A3 products, and "ascend950" for Ascend 950PR&950DT products.
105 - --jit (optional): If set, indicates that operator binary files are not compiled. If you need to use aclnn to invoke operators, this option does not need to be set.105 - --jit (optional): If set, indicates that operator binary files are not compiled. If you need to use aclnn to invoke operators, this option does not need to be set.
106 - --experimental (optional): Indicates that operators saved by users in the experimental directory should be compiled.106 - --experimental (optional): Indicates that operators saved by users in the experimental directory should be compiled.
107 - -j (optional): Specifies the number of compilation threads to speed up compilation.107 - -j (optional): Specifies the number of compilation threads to speed up compilation.
@@ -132,7 +132,7 @@ If compiling in an environment with internet access, third-party dependencies ar
132 132 
133### ops-ras Static Library133### ops-ras Static Library
134 134 
135-> Description: The static library only supports Atlas A2 and Atlas A3 series products. The experimental operators do not currently support the use of static libraries.135+> Description: The static library only supports Atlas A2 products and Atlas A3 products. The experimental operators do not currently support the use of static libraries.
136 136 
1371. **Compile the ops-ras static library**1371. **Compile the ops-ras static library**
138 138 
@@ -142,7 +142,7 @@ If compiling in an environment with internet access, third-party dependencies ar
142 bash build.sh --pkg --static --soc=${soc_version} [-j${n}]142 bash build.sh --pkg --static --soc=${soc_version} [-j${n}]
143 ```143 ```
144 144 
145- - --soc: ${soc_version} indicates the NPU model. Use "ascend910b" (default) for Atlas A2 series products and "ascend910_93" for Atlas A3 series products.145+ - --soc: ${soc_version} indicates the NPU model. Use "ascend910b" (default) for Atlas A2 products and "ascend910_93" for Atlas A3 products.
146 - -j (optional): Specifies the number of compilation threads to speed up compilation.146 - -j (optional): Specifies the number of compilation threads to speed up compilation.
147 When the following message appears, the compilation and compression are successful.147 When the following message appears, the compilation and compression are successful.
148 148 
@@ -282,4 +282,4 @@ The default installation directory requires the current user to have read, write
282 282 
283 ```bash283 ```bash
284 sudo -E ./build_out/cann-ops-ras-*linux*.run284 sudo -E ./build_out/cann-ops-ras-*linux*.run
285- ```285+ ```
@@ -3,7 +3,7 @@
3## Prerequisites3## Prerequisites
4 4 
5- Environment deployment: Before invoking an operator, complete the basic environment setup by following [Environment Deployment](../install/quick_install.md).5- Environment deployment: Before invoking an operator, complete the basic environment setup by following [Environment Deployment](../install/quick_install.md).
6-- Operator invocation list: The operators available for invocation in the project are listed in [Operator List](../../zh/op_list.md), and the corresponding aclnn interfaces are listed in [aclnn List](../../zh/op_api_list.md).6+- Operator invocation list: The operators available for invocation in the project are listed in [Operator List](../../en/op_list.md), and the corresponding aclnn interfaces are listed in [aclnn List](../../en/op_api_list.md).
7- build.sh: Operator invocation depends on the build.sh script in the root directory. You can view the functions through the `bash build.sh --help` command. For parameter descriptions, refer to [build Parameter Description](../install/build.md).7- build.sh: Operator invocation depends on the build.sh script in the root directory. You can view the functions through the `bash build.sh --help` command. For parameter descriptions, refer to [build Parameter Description](../install/build.md).
8 8 
9## Source Code Compilation9## Source Code Compilation
@@ -56,7 +56,7 @@ After preparing the open-source third-party software, you can choose from the fo
56 # bash build.sh --pkg --experimental --soc=ascend910b --ops=${experimental_op}56 # bash build.sh --pkg --experimental --soc=ascend910b --ops=${experimental_op}
57 ```57 ```
58 58 
59- - --soc: ${soc_version} represents the NPU model. For Atlas A2 series products, use "ascend910b" (default). For Atlas A3 series products, use "ascend910_93". For Ascend 950PR/Ascend 950DT products, use "ascend950".59+ - --soc: ${soc_version} represents the NPU model. For Atlas A2 products, use "ascend910b" (default). For Atlas A3 products, use "ascend910_93". For Ascend 950PR&950DT products, use "ascend950".
60 - --vendor_name (optional): ${vendor_name} represents the name of the custom operator package to build. The default name is custom.60 - --vendor_name (optional): ${vendor_name} represents the name of the custom operator package to build. The default name is custom.
61 - --ops (optional): ${op_list} represents the operators to compile. If not specified, all operators are compiled by default. The format is "add_example,...", with multiple operators separated by commas.61 - --ops (optional): ${op_list} represents the operators to compile. If not specified, all operators are compiled by default. The format is "add_example,...", with multiple operators separated by commas.
62 - --experimental (optional): Indicates compiling operators in the experimental contribution directory. ${experimental_op} is the directory name of the new contributed operator. For contribution instructions, refer to the [Contribution Guide](../../../CONTRIBUTING.md).62 - --experimental (optional): Indicates compiling operators in the experimental contribution directory. ${experimental_op} is the directory name of the new contributed operator. For contribution instructions, refer to the [Contribution Guide](../../../CONTRIBUTING.md).
@@ -98,7 +98,7 @@ After preparing the open-source third-party software, you can choose from the fo
98 # bash build.sh --pkg --experimental --soc=${soc_version}98 # bash build.sh --pkg --experimental --soc=${soc_version}
99 ```99 ```
100 100 
101- - --soc: ${soc_version} represents the NPU model. For Atlas A2 series products, use "ascend910b" (default). For Atlas A3 series products, use "ascend910_93". For Ascend 950PR/Ascend 950DT products, use "ascend950".101+ - --soc: ${soc_version} represents the NPU model. For Atlas A2 products, use "ascend910b" (default). For Atlas A3 products, use "ascend910_93". For Ascend 950PR&950DT products, use "ascend950".
102 - --experimental (optional): Indicates compiling operators in the experimental contribution directory.102 - --experimental (optional): Indicates compiling operators in the experimental contribution directory.
103 103 
104 If the following message appears, the compilation is successful.104 If the following message appears, the compilation is successful.
@@ -127,7 +127,7 @@ After preparing the open-source third-party software, you can choose from the fo
127 127 
128#### ops-ras Static Library128#### ops-ras Static Library
129 129 
130-> Note: The static library only supports Atlas A2 and Atlas A3 series products. Experimental operators do not support the static library at this time.130+> Note: The static library only supports Atlas A2 product and Atlas A3 products. Experimental operators do not support the static library at this time.
131 131 
1321. **Compile the ops-ras static library**1321. **Compile the ops-ras static library**
133 133 
@@ -137,7 +137,7 @@ After preparing the open-source third-party software, you can choose from the fo
137 bash build.sh --pkg --static --soc=${soc_version}137 bash build.sh --pkg --static --soc=${soc_version}
138 ```138 ```
139 139 
140- ${soc_version} represents the NPU model. For Atlas A2 series products, use "ascend910b" (default). For Atlas A3 series products, use "ascend910_93".140+ ${soc_version} represents the NPU model. For Atlas A2 products, use "ascend910b" (default). For Atlas A3 products, use "ascend910_93".
141 141 
142 If the following message appears, the compilation and compression are successful.142 If the following message appears, the compilation and compression are successful.
143 143 
@@ -233,7 +233,7 @@ Run operators and UT test cases through the build.sh script in the project root
233 233 
234### Run Operator Samples234### Run Operator Samples
235 235 
236-> **Note**: For Ascend 950PR products, use simulation to run operator samples. For details, refer to [Simulation Guide](../debug/op_debug_prof.md#method-2-for-ascend-950pr).236+> **Note**: For Ascend 950PR products, use simulation to run operator samples. For details, refer to [Simulation Guide](../debug/op_debug_prof.md#method-2-for-ascend-950pr950dt-products).
237 237 
238- Run operator samples based on a **custom operator package**. After the package is installed, execute the following command:238- Run operator samples based on a **custom operator package**. After the package is installed, execute the following command:
239 239 
@@ -1,7 +1,7 @@
1# aclnn返回码1# aclnn返回码
2 2 
3调用aclnn API时,常见的接口返回码如[表1](#table1)所示。3调用aclnn API时,常见的接口返回码如[表1](#table1)所示。
4-对于异常状态码值,可以通过aclGetRecentErrMsg接口([《Runtime运行时API》](https://hiascend.com/document/redirect/CannCommunityRuntimeApi))获取异常信息,您可以根据报错提示排查问题或者联系技术支持。4+对于异常状态码值,可以通过aclGetRecentErrMsg接口([《Runtime运行时API》](https://hiascend.com/document/redirect/CannCommunityRuntimeApi))获取异常信息,您可以根据报错提示排查问题或者提交issue。
5 5 
6**表1** 返回状态码 <a id="table1"></a>6**表1** 返回状态码 <a id="table1"></a>
7 7 
@@ -162,7 +162,7 @@
162 采集结果在本项目`$PWD/pipeline_auto/OPPROF_**`目录中。162 采集结果在本项目`$PWD/pipeline_auto/OPPROF_**`目录中。
163 其中流水相关文件路径为`OPPROF**/simulator/visualize_data.bin`,可以借助[MindStudio Insight](https://www.hiascend.com/document/redirect/MindStudioInsight)工具查看。163 其中流水相关文件路径为`OPPROF**/simulator/visualize_data.bin`,可以借助[MindStudio Insight](https://www.hiascend.com/document/redirect/MindStudioInsight)工具查看。
164 164 
165-### 方式二(针对Ascend 950PR/Ascend 950DT系列产品)165+### 方式二(针对Ascend 950PR&950DT系列产品系列产品)
166 166 
167算子开发过程中,如果出现执行精度下降、内存占用异常等问题,可以通过[CANN Simulator](./cann_sim.md)仿真工具分析算子的指令流水情况,从而确定问题根源,并针对性地优化。167算子开发过程中,如果出现执行精度下降、内存占用异常等问题,可以通过[CANN Simulator](./cann_sim.md)仿真工具分析算子的指令流水情况,从而确定问题根源,并针对性地优化。
168 168 
@@ -184,4 +184,4 @@
184 trace_core0.json184 trace_core0.json
185 ```185 ```
186 186 
187-3. 在Chrome浏览器中输入“chrome://tracing”地址,并将生成的指令流水图文件(trace_core0.json)拖到空白处打开,具体参数介绍参考CANN Simulator中[“仿真结果解析”](./cann_sim.md#仿真结果解析)章节。187+3. 在Chrome浏览器中输入“chrome://tracing”地址,并将生成的指令流水图文件(trace_core0.json)拖到空白处打开,具体参数介绍参考CANN Simulator中[“仿真结果解析”](./cann_sim.md#仿真结果解析说明)章节。
@@ -54,7 +54,7 @@
54 # bash build.sh --pkg --experimental --soc=ascend910b --ops=add_example -j1654 # bash build.sh --pkg --experimental --soc=ascend910b --ops=add_example -j16
55 ```55 ```
56 56 
57- - --soc:\$\{soc\_version\}表示NPU型号。Atlas A2 训练系列产品/Atlas A2 推理系列产品使用"ascend910b"(默认),Atlas A3 训练系列产品/Atlas A3 推理系列产品使用"ascend910_93",Ascend 950PR/Ascend 950DT产品使用"ascend950"。57+ - --soc:\$\{soc\_version\}表示NPU型号。Atlas A2 训练系列产品/Atlas A2 推理系列产品使用"ascend910b"(默认),Atlas A3 训练系列产品/Atlas A3 推理系列产品使用"ascend910_93",Ascend 950PR&950DT系列产品产品使用"ascend950"。
58 - --vendor_name(可选):\$\{vendor\_name\}表示构建的自定义算子包名,默认名为custom。58 - --vendor_name(可选):\$\{vendor\_name\}表示构建的自定义算子包名,默认名为custom。
59 - --ops(可选):\$\{op\_list\}表示待编译算子,不指定时默认编译所有算子。格式形如"add_example,crypto,...",多算子之间用英文逗号","分隔。59 - --ops(可选):\$\{op\_list\}表示待编译算子,不指定时默认编译所有算子。格式形如"add_example,crypto,...",多算子之间用英文逗号","分隔。
60 - --experimental(可选):表示编译用户保存在experimental贡献目录下的算子。60 - --experimental(可选):表示编译用户保存在experimental贡献目录下的算子。
@@ -101,7 +101,7 @@
101 # bash build.sh --pkg --experimental [--jit] --soc=${soc_version} [-j${n}]101 # bash build.sh --pkg --experimental [--jit] --soc=${soc_version} [-j${n}]
102 ```102 ```
103 103 
104- - --soc:\$\{soc\_version\}表示NPU型号。Atlas A2 训练系列产品/Atlas A2 推理系列产品使用"ascend910b"(默认),Atlas A3 训练系列产品/Atlas A3 推理系列产品使用"ascend910_93",Ascend 950PR/Ascend 950DT产品使用"ascend950"。104+ - --soc:\$\{soc\_version\}表示NPU型号。Atlas A2 训练系列产品/Atlas A2 推理系列产品使用"ascend910b"(默认),Atlas A3 训练系列产品/Atlas A3 推理系列产品使用"ascend910_93",Ascend 950PR&950DT系列产品产品使用"ascend950"。
105 - --jit(可选):设置后表示不编译算子二进制文件,如需使用aclnn调用算子,该选项无需设置。105 - --jit(可选):设置后表示不编译算子二进制文件,如需使用aclnn调用算子,该选项无需设置。
106 - --experimental(可选):表示编译用户保存在experimental目录下的算子。106 - --experimental(可选):表示编译用户保存在experimental目录下的算子。
107 - -j(可选):指定编译线程数,加快编译速度。107 - -j(可选):指定编译线程数,加快编译速度。
@@ -111,7 +111,7 @@
111 ```bash111 ```bash
112 Self-extractable archive "cann-${soc_name}-ops-ras_${cann_version}_linux-${arch}.run" successfully created.112 Self-extractable archive "cann-${soc_name}-ops-ras_${cann_version}_linux-${arch}.run" successfully created.
113 ```113 ```
114- 114+ 
115 \$\{soc\_name\}表示NPU型号名称,即\$\{soc\_version\}删除"ascend"后剩余的内容。编译成功后,run包存放于build_out目录下。115 \$\{soc\_name\}表示NPU型号名称,即\$\{soc\_version\}删除"ascend"后剩余的内容。编译成功后,run包存放于build_out目录下。
116 116 
1172. **安装ops-ras包**1172. **安装ops-ras包**
@@ -186,36 +186,36 @@
186 将下载好的第三方软件上传至离线环境,可存放在`third_party`目录或自定义目录下。**推荐前者,其编译命令与联网编译场景下的命令一致。**186 将下载好的第三方软件上传至离线环境,可存放在`third_party`目录或自定义目录下。**推荐前者,其编译命令与联网编译场景下的命令一致。**
187 187 
188 - **third\_party目录**(推荐)188 - **third\_party目录**(推荐)
189- 189+ 
190 请在本项目根目录创建`third_party`目录(若有则无需创建),将第三方软件拷贝到该指定目录。此时编译命令与联网编译命令一致,具体参考[联网编译](#联网编译)。190 请在本项目根目录创建`third_party`目录(若有则无需创建),将第三方软件拷贝到该指定目录。此时编译命令与联网编译命令一致,具体参考[联网编译](#联网编译)。
191- 191+ 
192 - **自定义目录**192 - **自定义目录**
193- 193+ 
194 在离线环境的任意位置新建`${cann_3rd_lib_path}`目录,将第三方软件拷贝到该目录,请确保该目录有权限访问。194 在离线环境的任意位置新建`${cann_3rd_lib_path}`目录,将第三方软件拷贝到该目录,请确保该目录有权限访问。
195 195 
196 ```bash196 ```bash
197 mkdir -p ${cann_3rd_lib_path}197 mkdir -p ${cann_3rd_lib_path}
198 ```198 ```
199- 199+ 
200 此时编译命令需在联网编译命令基础上额外增加`--cann_3rd_lib_path=${cann_3rd_lib_path}`用于指定第三方软件所在路径。假设存放路径为`/path/cann_3rd_lib_path`,不同编译方式对应的命令如下:200 此时编译命令需在联网编译命令基础上额外增加`--cann_3rd_lib_path=${cann_3rd_lib_path}`用于指定第三方软件所在路径。假设存放路径为`/path/cann_3rd_lib_path`,不同编译方式对应的命令如下:
201- 201+ 
202 - 自定义算子包202 - 自定义算子包
203- 203+ 
204 ```bash204 ```bash
205 bash build.sh --pkg --soc=${soc_version} [--vendor_name=${vendor_name}] [--ops=${op_list}] --cann_3rd_lib_path=${cann_3rd_lib_path}205 bash build.sh --pkg --soc=${soc_version} [--vendor_name=${vendor_name}] [--ops=${op_list}] --cann_3rd_lib_path=${cann_3rd_lib_path}
206 # 以AddExample算子编译为例206 # 以AddExample算子编译为例
207 # bash build.sh --pkg --soc=ascend910b --ops=add_example -j16 --cann_3rd_lib_path=/path/cann_3rd_lib_path207 # bash build.sh --pkg --soc=ascend910b --ops=add_example -j16 --cann_3rd_lib_path=/path/cann_3rd_lib_path
208 ```208 ```
209- 209+ 
210 - ops-ras整包210 - ops-ras整包
211- 211+ 
212 ```bash212 ```bash
213 bash build.sh --pkg [--jit] --soc=${soc_version} --cann_3rd_lib_path=${cann_3rd_lib_path}213 bash build.sh --pkg [--jit] --soc=${soc_version} --cann_3rd_lib_path=${cann_3rd_lib_path}
214 # bash build.sh --pkg --soc=ascend910b --cann_3rd_lib_path=/path/cann_3rd_lib_path214 # bash build.sh --pkg --soc=ascend910b --cann_3rd_lib_path=/path/cann_3rd_lib_path
215 ```215 ```
216- 216+ 
217 - ops-ras静态库217 - ops-ras静态库
218- 218+ 
219 ```bash219 ```bash
220 bash build.sh --pkg --static --soc=${soc_version} --cann_3rd_lib_path=${cann_3rd_lib_path}220 bash build.sh --pkg --static --soc=${soc_version} --cann_3rd_lib_path=${cann_3rd_lib_path}
221 # bash build.sh --pkg --static --soc=ascend910b --cann_3rd_lib_path=/path/cann_3rd_lib_path221 # bash build.sh --pkg --static --soc=ascend910b --cann_3rd_lib_path=/path/cann_3rd_lib_path
@@ -263,23 +263,23 @@ Global Environment TearDown
263[100%] Built target ras_op_host_ut263[100%] Built target ras_op_host_ut
264```264```
265 265 
266-\$\{n\}表示执行了n个用例,\$\{m\}表示m项测试,\$\{x\}表示执行用例消耗的时间,单位为毫秒。266+\$\{n\}表示执行了n个用例,\$\{m\}表示m项测试,\$\{x\}表示执行用例消耗的时间,单位为毫秒。
267- 267+ 
268-## FAQ268+## FAQ
269- 269+ 
270-### 安装自定义run包报错权限不足270+### 安装自定义run包报错权限不足
271- 271+ 
272-默认安装目录需要当前用户具备读、写和执行权限。若提示权限不足,可选择以下一种方式:272+默认安装目录需要当前用户具备读、写和执行权限。若提示权限不足,可选择以下一种方式:
273- 273+ 
274-- 推荐安装到当前用户可写的绝对路径,并加载安装包生成的环境变量脚本:274+- 推荐安装到当前用户可写的绝对路径,并加载安装包生成的环境变量脚本:
275- 275+ 
276- ```bash276+ ```bash
277- ./build_out/cann-ops-ras-*linux*.run --install-path=/absolute/path/to/opp277+ ./build_out/cann-ops-ras-*linux*.run --install-path=/absolute/path/to/opp
278- source /absolute/path/to/opp/vendors/custom_ras/bin/set_env.bash278+ source /absolute/path/to/opp/vendors/custom_ras/bin/set_env.bash
279- ```279+ ```
280- 280+ 
281-- 确需安装到系统CANN目录时,使用`sudo -E`保留当前已配置的CANN环境变量:281+- 确需安装到系统CANN目录时,使用`sudo -E`保留当前已配置的CANN环境变量:
282- 282+ 
283- ```bash283+ ```bash
284- sudo -E ./build_out/cann-ops-ras-*linux*.run284+ sudo -E ./build_out/cann-ops-ras-*linux*.run
285 ```285 ```
@@ -33,7 +33,7 @@
33 # bash build.sh --pkg --experimental --soc=ascend910b --ops=${experimental_op}33 # bash build.sh --pkg --experimental --soc=ascend910b --ops=${experimental_op}
34 ```34 ```
35 35 
36- - --soc:\$\{soc\_version\}表示NPU型号。Atlas A2系列产品使用"ascend910b"(默认),Atlas A3系列产品使用"ascend910_93",Ascend 950PR/Ascend 950DT产品使用"ascend950"。36+ - --soc:\$\{soc\_version\}表示NPU型号。Atlas A2系列产品使用"ascend910b"(默认),Atlas A3系列产品使用"ascend910_93",Ascend 950PR&950DT系列产品产品使用"ascend950"。
37 - --vendor_name(可选):\$\{vendor\_name\}表示构建的自定义算子包名,默认名为custom。37 - --vendor_name(可选):\$\{vendor\_name\}表示构建的自定义算子包名,默认名为custom。
38 - --ops(可选):\$\{op\_list\}表示待编译算子,不指定时默认编译所有算子。格式形如"add_example,...",多算子之间用英文逗号","分隔。38 - --ops(可选):\$\{op\_list\}表示待编译算子,不指定时默认编译所有算子。格式形如"add_example,...",多算子之间用英文逗号","分隔。
39 - --experimental(可选):表示编译experimental贡献目录下的算子,${experimental_op}为新贡献算子目录名,贡献说明参见[贡献指南](../../../CONTRIBUTING.md)。39 - --experimental(可选):表示编译experimental贡献目录下的算子,${experimental_op}为新贡献算子目录名,贡献说明参见[贡献指南](../../../CONTRIBUTING.md)。
@@ -78,7 +78,7 @@
78 ```78 ```
79 79 
80 - --jit(可选):设置后表示不编译算子二进制文件,如需使用aclnn调用算子,该选项无需设置。80 - --jit(可选):设置后表示不编译算子二进制文件,如需使用aclnn调用算子,该选项无需设置。
81- - --soc:\$\{soc\_version\}表示NPU型号。Atlas A2系列产品使用"ascend910b"(默认),Atlas A3系列产品使用"ascend910_93",Ascend 950PR/Ascend 950DT产品使用"ascend950"。81+ - --soc:\$\{soc\_version\}表示NPU型号。Atlas A2系列产品使用"ascend910b"(默认),Atlas A3系列产品使用"ascend910_93",Ascend 950PR&950DT系列产品产品使用"ascend950"。
82 - --experimental(可选):表示编译experimental贡献目录下的算子。82 - --experimental(可选):表示编译experimental贡献目录下的算子。
83 83 
84 若提示如下信息,说明编译成功。84 若提示如下信息,说明编译成功。
@@ -107,7 +107,7 @@
107 107 
108### ops-ras静态库108### ops-ras静态库
109 109 
110-> 说明:Ascend 950PR/Ascend 950DT暂不支持使用静态库。110+> 说明:Ascend 950PR&950DT系列产品暂不支持使用静态库。
111 111 
1121. **编译ops-ras静态库**1121. **编译ops-ras静态库**
113 113 
@@ -167,7 +167,7 @@
167 167 
168- **执行算子样例**168- **执行算子样例**
169 169 
170- > **说明**:Ascend 950PR/Ascend 950DT产品使用仿真执行算子样例,请见[仿真指导](../debug/op_debug_prof.md#方式二针对ascend-950pr)。170+ > **说明**:Ascend 950PR&950DT系列产品产品使用仿真执行算子样例,请见[仿真指导](../debug/op_debug_prof.md#方式二针对ascend-950pr)。
171 171 
172 - 完成自定义算子包安装后,执行如下命令:172 - 完成自定义算子包安装后,执行如下命令:
173 173 
@@ -69,7 +69,7 @@ $$
69 <th>调用方式</th>69 <th>调用方式</th>
70 <th>调用样例</th>70 <th>调用样例</th>
71 <th>说明</th>71 <th>说明</th>
72- </tr><thrad>72+ </tr></thead>
73 <tbody>73 <tbody>
74 <tr>74 <tr>
75 <td>aclnn调用</td>75 <td>aclnn调用</td>
@@ -81,4 +81,4 @@ $$
81 <td><a href="./examples/test_geir_add_example.cpp">test_geir_add_example</a></td>81 <td><a href="./examples/test_geir_add_example.cpp">test_geir_add_example</a></td>
82 </tr>82 </tr>
83 </tbody>83 </tbody>
84-</table>84+</table>
@@ -0,0 +1,84 @@
1+# AddExample
2+ 
3+## Product Support
4+ 
5+| Product | Supported |
6+| ---- | :----:|
7+| Atlas A3 products | √ |
8+| Atlas A2 products | √ |
9+ 
10+## Function Description
11+ 
12+- Operator function: implements addition computation.
13+ 
14+- Computation formula:
15+ 
16+$$
17+y = x1 + x2
18+$$
19+ 
20+## Parameter Description
21+ 
22+<table style="undefined;table-layout: fixed; width: 980px"><colgroup>
23+ <col style="width: 100px">
24+ <col style="width: 150px">
25+ <col style="width: 280px">
26+ <col style="width: 330px">
27+ <col style="width: 120px">
28+ </colgroup>
29+ <thead>
30+ <tr>
31+ <th>Parameter</th>
32+ <th>Input/Output/Attribute</th>
33+ <th>Description</th>
34+ <th>Data Type</th>
35+ <th>Data Format</th>
36+ </tr></thead>
37+ <tbody>
38+ <tr>
39+ <td>x1</td>
40+ <td>Input</td>
41+ <td>Input parameter for add_example computation, x1 in the formula.</td>
42+ <td>FLOAT, INT32</td>
43+ <td>ND</td>
44+ </tr>
45+ <tr>
46+ <td>x2</td>
47+ <td>Input</td>
48+ <td>Input parameter for add_example computation, x2 in the formula.</td>
49+ <td>FLOAT, INT32</td>
50+ <td>ND</td>
51+ </tr>
52+ <tr>
53+ <td>y</td>
54+ <td>Output</td>
55+ <td>Output parameter for add_example computation, y in the formula.</td>
56+ <td>FLOAT, INT32</td>
57+ <td>ND</td>
58+ </tr>
59+ </tbody></table>
60+ 
61+## Precautions
62+ 
63+None
64+ 
65+## Invocation Description
66+ 
67+<table><thead>
68+ <tr>
69+ <th>Invocation Method</th>
70+ <th>Invocation Sample</th>
71+ <th>Description</th>
72+ </tr></thead>
73+ <tbody>
74+ <tr>
75+ <td>aclnn invocation</td>
76+ <td><a href="./examples/test_aclnn_add_example.cpp">test_aclnn_add_example</a></td>
77+ <td rowspan="2">Refer to [Operator Invocation](../../docs/en/invocation/quick_op_invocation.md) to complete operator compilation and verification.</td>
78+ </tr>
79+ <tr>
80+ <td>Graph mode invocation</td>
81+ <td><a href="./examples/test_geir_add_example.cpp">test_geir_add_example</a></td>
82+ </tr>
83+ </tbody>
84+</table>
@@ -69,11 +69,11 @@ $$
69 <th>调用方式</th>69 <th>调用方式</th>
70 <th>调用样例</th>70 <th>调用样例</th>
71 <th>说明</th>71 <th>说明</th>
72- </tr><thrad>72+ </tr></thead>
73 <tbody>73 <tbody>
74 <tr>74 <tr>
75 <td>aclnn调用</td>75 <td>aclnn调用</td>
76- <td><a href="./examples/test_aclnn_add_example_aicpu.cpp">test_aclnn_add_example_aicpu</a></td>76+ <td><a href="./examples/test_geir_add_example_aicpu.cpp">test_aclnn_add_example_aicpu</a></td>
77 <td rowspan="2">参见<a href="../../docs/zh/invocation/quick_op_invocation.md">算子调用</a>完成算子编译和验证。</td>77 <td rowspan="2">参见<a href="../../docs/zh/invocation/quick_op_invocation.md">算子调用</a>完成算子编译和验证。</td>
78 </tr>78 </tr>
79 <tr>79 <tr>
@@ -81,4 +81,4 @@ $$
81 <td><a href="./examples/test_geir_add_example_aicpu.cpp">test_geir_add_example_aicpu</a></td>81 <td><a href="./examples/test_geir_add_example_aicpu.cpp">test_geir_add_example_aicpu</a></td>
82 </tr>82 </tr>
83 </tbody>83 </tbody>
84-</table>84+</table>
@@ -0,0 +1,84 @@
1+# AddExample
2+ 
3+## Product Support
4+ 
5+| Product | Supported |
6+| ---- | :----:|
7+| Atlas A3 products | √ |
8+| Atlas A2 products | √ |
9+ 
10+## Function Description
11+ 
12+- Operator function: implements addition computation.
13+ 
14+- Computation formula:
15+ 
16+$$
17+y = x1 + x2
18+$$
19+ 
20+## Parameter Description
21+ 
22+<table style="undefined;table-layout: fixed; width: 980px"><colgroup>
23+ <col style="width: 100px">
24+ <col style="width: 150px">
25+ <col style="width: 280px">
26+ <col style="width: 330px">
27+ <col style="width: 120px">
28+ </colgroup>
29+ <thead>
30+ <tr>
31+ <th>Parameter</th>
32+ <th>Input/Output/Attribute</th>
33+ <th>Description</th>
34+ <th>Data Type</th>
35+ <th>Data Format</th>
36+ </tr></thead>
37+ <tbody>
38+ <tr>
39+ <td>x1</td>
40+ <td>Input</td>
41+ <td>Input parameter for add_example computation, x1 in the formula.</td>
42+ <td>FLOAT, INT32</td>
43+ <td>ND</td>
44+ </tr>
45+ <tr>
46+ <td>x2</td>
47+ <td>Input</td>
48+ <td>Input parameter for add_example computation, x2 in the formula.</td>
49+ <td>FLOAT, INT32</td>
50+ <td>ND</td>
51+ </tr>
52+ <tr>
53+ <td>y</td>
54+ <td>Output</td>
55+ <td>Output parameter for add_example computation, y in the formula.</td>
56+ <td>FLOAT, INT32</td>
57+ <td>ND</td>
58+ </tr>
59+ </tbody></table>
60+ 
61+## Precautions
62+ 
63+None
64+ 
65+## Invocation Description
66+ 
67+<table><thead>
68+ <tr>
69+ <th>Invocation Method</th>
70+ <th>Invocation Sample</th>
71+ <th>Description</th>
72+ </tr></thead>
73+ <tbody>
74+ <tr>
75+ <td>aclnn invocation</td>
76+ <td><a href="./examples/test_geir_add_example_aicpu.cpp">test_aclnn_add_example_aicpu</a></td>
77+ <td rowspan="2">Refer to [Operator Invocation](../../docs/zh/invocation/quick_op_invocation.md) to complete operator compilation and verification.</td>
78+ </tr>
79+ <tr>
80+ <td>Graph mode invocation</td>
81+ <td><a href="./examples/test_geir_add_example_aicpu.cpp">test_geir_add_example_aicpu</a></td>
82+ </tr>
83+ </tbody>
84+</table>
@@ -2,9 +2,8 @@
2 2 
3## 产品支持情况3## 产品支持情况
4 4 
5- 
6<!-- npu="950" id1 -->5<!-- npu="950" id1 -->
7-- <term>Ascend 950PR/Ascend 950DT</term>:不支持6+- <term>Ascend 950PR&950DT系列产品</term>:不支持
8<!-- end id1 -->7<!-- end id1 -->
9<!-- npu="A3" id2 -->8<!-- npu="A3" id2 -->
10- <term>Atlas A3 训练系列产品/Atlas A3 推理系列产品</term>:支持9- <term>Atlas A3 训练系列产品/Atlas A3 推理系列产品</term>:支持
@@ -33,6 +32,7 @@
33## 函数原型32## 函数原型
34 33 
35每个算子分为两段式接口,必须先调用“aclnnCryptoGetWorkspaceSize”接口获取计算所需workspace大小以及包含了算子计算流程的执行器,再调用“aclnnCrypto”接口执行计算。34每个算子分为两段式接口,必须先调用“aclnnCryptoGetWorkspaceSize”接口获取计算所需workspace大小以及包含了算子计算流程的执行器,再调用“aclnnCrypto”接口执行计算。
35+ 
36```c++36```c++
37aclnnStatus aclnnCryptoAicpuGetWorkspaceSize(37aclnnStatus aclnnCryptoAicpuGetWorkspaceSize(
38 const aclTensor *key,38 const aclTensor *key,
@@ -3,7 +3,7 @@
3## 产品支持情况3## 产品支持情况
4 4 
5<!-- npu="950" id1 -->5<!-- npu="950" id1 -->
6-- <term>Ascend 950PR/Ascend 950DT</term>:不支持6+- <term>Ascend 950PR&950DT系列产品</term>:不支持
7<!-- end id1 -->7<!-- end id1 -->
8<!-- npu="A3" id2 -->8<!-- npu="A3" id2 -->
9- <term>Atlas A3 训练系列产品/Atlas A3 推理系列产品</term>:支持9- <term>Atlas A3 训练系列产品/Atlas A3 推理系列产品</term>:支持
@@ -3,7 +3,7 @@
3## Product Support3## Product Support
4 4 
5<!-- npu="950" id1 -->5<!-- npu="950" id1 -->
6-- <term>Ascend 950PR/Ascend 950DT</term>: Not supported6+- <term>Ascend 950PR&950DT系列产品</term>: Not supported
7<!-- end id1 -->7<!-- end id1 -->
8<!-- npu="A3" id2 -->8<!-- npu="A3" id2 -->
9- <term>Atlas A3 Training Series/Atlas A3 Inference Series</term>: Supported9- <term>Atlas A3 Training Series/Atlas A3 Inference Series</term>: Supported
@@ -57,44 +57,12 @@ struct TestArgs {
57 int64_t k = 4096;57 int64_t k = 4096;
58 int32_t deviceId = 0;58 int32_t deviceId = 0;
59 double eMax = 0.001;59 double eMax = 0.001;
60- int64_t reduceCores = 8;
61 int32_t verbose = 1;60 int32_t verbose = 1;
62 61 
63 void Print() const62 void Print() const
64 {63 {
65- LOG_PRINT("Args: m=%ld n=%ld k=%ld eMax=%f reduceCores=%ld "64+ LOG_PRINT("Args: m=%ld n=%ld k=%ld eMax=%f verbose=%d deviceId=%d\n",
66- "verbose=%d deviceId=%d\n",65+ m, n, k, eMax, verbose, deviceId);
67- m, n, k, eMax, reduceCores, verbose, deviceId);
68- }
69- 
70- int Parse(int argc, const char** argv)
71- {
72- const std::string helper =
73- "test_aclnn_matmul_abft_verify_bf16 m n k eMax reduceCores verbose [deviceId]";
74- enum {
75- M_IDX = 1,
76- N_IDX,
77- K_IDX,
78- EMAX_IDX,
79- RED_CORES_IDX,
80- VERBOSE_IDX,
81- DEVICE_ID_IDX,
82- ARGS_MAX
83- };
84- if (argc < DEVICE_ID_IDX || argc > ARGS_MAX) {
85- std::cerr << helper << std::endl;
86- return -1;
87- }
88- m = std::atol(argv[M_IDX]);
89- n = std::atol(argv[N_IDX]);
90- k = std::atol(argv[K_IDX]);
91- eMax = std::stod(argv[EMAX_IDX]);
92- reduceCores = std::atol(argv[RED_CORES_IDX]);
93- verbose = std::atoi(argv[VERBOSE_IDX]);
94- if (argc == ARGS_MAX) {
95- deviceId = std::atoi(argv[DEVICE_ID_IDX]);
96- }
97- return 0;
98 }66 }
99};67};
100 68 
@@ -156,268 +124,196 @@ int InitAcl(int32_t deviceId, aclrtContext* context, aclrtStream* stream)
156 return ACL_SUCCESS;124 return ACL_SUCCESS;
157}125}
158 126 
159-void PrintChecksum(const std::vector<int64_t>& shape, void* deviceAddr, aclDataType dataType,127+void PrintFloatChecksum(const std::vector<int64_t>& shape, void* deviceAddr, const char* name)
160- const char* name)128+{
129+ std::vector<float> hostData(GetShapeSize(shape), 0.0F);
130+ if (CopyDeviceToHost(hostData, deviceAddr, name) != ACL_SUCCESS) {
131+ return;
132+ }
133+ double sum = 0.0;
134+ for (auto value : hostData) {
135+ sum += static_cast<double>(value);
136+ }
137+ LOG_PRINT("%s (FP32) first 8:", name);
138+ for (int64_t i = 0; i < std::min<int64_t>(hostData.size(), 8); ++i) {
139+ LOG_PRINT(" %.6f", hostData[i]);
140+ }
141+ LOG_PRINT(" checksum: %.6f\n", sum);
142+}
143+ 
144+void PrintBf16Checksum(const std::vector<int64_t>& shape, void* deviceAddr, const char* name)
145+{
146+ std::vector<Bf16> hostData(GetShapeSize(shape), 0);
147+ if (CopyDeviceToHost(hostData, deviceAddr, name) != ACL_SUCCESS) {
148+ return;
149+ }
150+ double sum = 0.0;
151+ for (auto value : hostData) {
152+ sum += static_cast<double>(Bf16ToFloat(value));
153+ }
154+ LOG_PRINT("%s (BF16) first 8:", name);
155+ for (int64_t i = 0; i < std::min<int64_t>(hostData.size(), 8); ++i) {
156+ LOG_PRINT(" %.6f", Bf16ToFloat(hostData[i]));
157+ }
158+ LOG_PRINT(" checksum: %.6f\n", sum);
159+}
160+ 
161+void PrintUint8Checksum(const std::vector<int64_t>& shape, void* deviceAddr, const char* name)
162+{
163+ std::vector<uint8_t> hostData(GetShapeSize(shape), 0);
164+ if (CopyDeviceToHost(hostData, deviceAddr, name) != ACL_SUCCESS) {
165+ return;
166+ }
167+ uint64_t sum = 0;
168+ for (auto value : hostData) {
169+ sum += static_cast<uint64_t>(value);
170+ }
171+ LOG_PRINT("%s (U8) first 8:", name);
172+ for (int64_t i = 0; i < std::min<int64_t>(hostData.size(), 8); ++i) {
173+ LOG_PRINT(" %u", static_cast<uint32_t>(hostData[i]));
174+ }
175+ LOG_PRINT(" checksum: %lu\n", sum);
176+}
177+ 
178+void PrintChecksum(const std::vector<int64_t>& shape, void* deviceAddr, aclDataType dataType, const char* name)
161{179{
162- auto elementCount = GetShapeSize(shape);
163 if (dataType == ACL_FLOAT) {180 if (dataType == ACL_FLOAT) {
164- std::vector<float> hostData(elementCount, 0.0F);181+ PrintFloatChecksum(shape, deviceAddr, name);
165- auto ret = aclrtMemcpy(hostData.data(), hostData.size() * sizeof(float),
166- deviceAddr, hostData.size() * sizeof(float), ACL_MEMCPY_DEVICE_TO_HOST);
167- CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("copy %s from device to host failed. ERROR: %d\n", name, ret); return);
168- 
169- double sum = 0.0;
170- for (auto v : hostData) {
171- sum += static_cast<double>(v);
172- }
173- LOG_PRINT("%s (FP32) first 8:", name);
174- int64_t limit = elementCount < 8 ? elementCount : 8;
175- for (int64_t i = 0; i < limit; ++i) {
176- LOG_PRINT(" %.6f", hostData[i]);
177- }
178- LOG_PRINT(" checksum: %.6f\n", sum);
179- 
180 } else if (dataType == ACL_BF16) {182 } else if (dataType == ACL_BF16) {
181- std::vector<Bf16> hostData(elementCount, 0);183+ PrintBf16Checksum(shape, deviceAddr, name);
182- auto ret = aclrtMemcpy(hostData.data(), hostData.size() * sizeof(Bf16),
183- deviceAddr, hostData.size() * sizeof(Bf16), ACL_MEMCPY_DEVICE_TO_HOST);
184- CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("copy %s from device to host failed. ERROR: %d\n", name, ret); return);
185- 
186- double sum = 0.0;
187- for (auto v : hostData) {
188- sum += static_cast<double>(Bf16ToFloat(v));
189- }
190- LOG_PRINT("%s (BF16) first 8:", name);
191- int64_t limit = elementCount < 8 ? elementCount : 8;
192- for (int64_t i = 0; i < limit; ++i) {
193- LOG_PRINT(" %.6f", Bf16ToFloat(hostData[i]));
194- }
195- LOG_PRINT(" checksum: %.6f\n", sum);
196- 
197 } else if (dataType == ACL_UINT8) {184 } else if (dataType == ACL_UINT8) {
198- std::vector<uint8_t> hostData(elementCount, 0);185+ PrintUint8Checksum(shape, deviceAddr, name);
199- auto ret = aclrtMemcpy(hostData.data(), hostData.size() * sizeof(uint8_t),
200- deviceAddr, hostData.size() * sizeof(uint8_t), ACL_MEMCPY_DEVICE_TO_HOST);
201- CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("copy %s from device to host failed. ERROR: %d\n", name, ret); return);
202- 
203- uint64_t sum = 0;
204- for (auto v : hostData) {
205- sum += static_cast<uint64_t>(v);
206- }
207- LOG_PRINT("%s (U8) first 8:", name);
208- int64_t limit = elementCount < 8 ? elementCount : 8;
209- for (int64_t i = 0; i < limit; ++i) {
210- LOG_PRINT(" %u", static_cast<uint32_t>(hostData[i]));
211- }
212- LOG_PRINT(" checksum: %lu\n", sum);
213 }186 }
214}187}
215 188 
216-int main(int argc, const char** argv)189+struct ExampleShapes {
190+ std::vector<int64_t> a;
191+ std::vector<int64_t> b;
192+ std::vector<int64_t> xv;
193+ std::vector<int64_t> c;
194+ std::vector<int64_t> compRow;
195+};
196+ 
197+ExampleShapes CreateExampleShapes(const TestArgs& args)
217{198{
218- TestArgs args;199+ const int64_t splitN = (args.n + 255) / 256;
219- if (args.Parse(argc, argv) != 0) {200+ return {{args.m, args.k}, {args.k, args.n}, {args.n}, {args.m, args.n},
220- return -1;201+ {((args.m + 7) / 8) * splitN}};
221- }202+}
222- args.Print();
223 203 
224- const int64_t M = args.m;204+struct ExampleData {
225- const int64_t N = args.n;205+ std::vector<Bf16> a;
226- const int64_t K = args.k;206+ std::vector<Bf16> b;
227- const int64_t splitN = (N + 256 - 1) / 256; // L1_TILE_N = 256207+ std::vector<Bf16> xv;
228- const int64_t bStatBlock = (splitN + 8 - 1) / 8; // FLOAT_ELEMENTS_PER_BLOCK = 8208+ std::vector<float> c;
229- const int64_t bStatLen = bStatBlock * 8 + 8; // aligned length for B stats209+ std::vector<uint8_t> compRow;
230- const int64_t rowSplitLen = M * splitN; // length of per-row split outputs210+};
231- const int64_t beLen = K * splitN; // length of BE / BMaxSlice etc.
232 211 
233- // ── Input shapes ──212+ExampleData CreateExampleData(const ExampleShapes& shapes)
234- const std::vector<int64_t> aShape = {M, K};213+{
235- const std::vector<int64_t> bShape = {K, N};214+ ExampleData data;
236- const std::vector<int64_t> xvShape = {N};215+ data.a.assign(GetShapeSize(shapes.a), 0);
237- const std::vector<int64_t> vxForAeShape = {K};216+ data.b.assign(GetShapeSize(shapes.b), 0);
238- 217+ data.xv.assign(GetShapeSize(shapes.xv), 0);
239- // ── Output shapes (from infershape) ──218+ data.c.assign(GetShapeSize(shapes.c), 0.0F);
240- const std::vector<int64_t> zRowColShape = {rowSplitLen};219+ data.compRow.assign(GetShapeSize(shapes.compRow), 0);
241- const std::vector<int64_t> compRowShape = {((M + 7) / 8) * splitN};
242- const std::vector<int64_t> cShape = {M, N};
243- const std::vector<int64_t> bStatShape = {bStatLen};
244- const std::vector<int64_t> beShape = {beLen};
245- const std::vector<int64_t> aRedShape = {M};
246- 
247- // ── Init ACL ──
248- aclrtContext context = nullptr;
249- aclrtStream stream = nullptr;
250- auto ret = InitAcl(args.deviceId, &context, &stream);
251- CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("Init acl failed. ERROR: %d\n", ret); return ret);
252- 
253- // ── Fill host data ──
254 std::mt19937 rng(42);220 std::mt19937 rng(42);
255 std::uniform_real_distribution<float> dist(-1.0F, 1.0F);221 std::uniform_real_distribution<float> dist(-1.0F, 1.0F);
256- 222+ for (auto& value : data.a) {
257- std::vector<Bf16> hostA(GetShapeSize(aShape), 0);223+ value = FloatToBf16(dist(rng));
258- std::vector<Bf16> hostB(GetShapeSize(bShape), 0);
259- std::vector<Bf16> hostXv(GetShapeSize(xvShape), 0);
260- std::vector<Bf16> hostVxForAe(GetShapeSize(vxForAeShape), 0);
261- 
262- for (auto& v : hostA) {
263- v = FloatToBf16(dist(rng));
264 }224 }
265- for (auto& v : hostB) {225+ for (auto& value : data.b) {
266- v = FloatToBf16(dist(rng));226+ value = FloatToBf16(dist(rng));
267 }227 }
268- for (auto& v : hostXv) {228+ for (auto& value : data.xv) {
269- v = FloatToBf16(1.0F);229+ value = FloatToBf16(1.0F);
270- }
271- for (auto& v : hostVxForAe) {
272- v = FloatToBf16(1.0F / static_cast<float>(K));
273 }230 }
231+ return data;
232+}
274 233 
275- // Output data (zero-initialised)234+struct ExampleTensors {
276- std::vector<float> hostZRow(GetShapeSize(zRowColShape), 0.0F);235+ void *devA = nullptr, *devB = nullptr, *devXv = nullptr, *devC = nullptr, *devCompRow = nullptr;
277- std::vector<float> hostDRow(GetShapeSize(zRowColShape), 0.0F);236+ aclTensor *a = nullptr, *b = nullptr, *xv = nullptr, *c = nullptr, *compRow = nullptr;
278- std::vector<uint8_t> hostCompRow(GetShapeSize(compRowShape), 0);237+};
279- std::vector<float> hostC(GetShapeSize(cShape), 0.0F);
280- std::vector<float> hostThreshold(GetShapeSize(zRowColShape), 0.0F);
281- std::vector<float> hostBMeanAbs(GetShapeSize(bStatShape), 0.0F);
282- std::vector<float> hostBMeanSquare(GetShapeSize(bStatShape), 0.0F);
283- std::vector<float> hostBVar(GetShapeSize(bStatShape), 0.0F);
284- std::vector<Bf16> hostBe(GetShapeSize(beShape), 0);
285- std::vector<float> hostBeForAiv(GetShapeSize(beShape), 0.0F);
286- std::vector<float> hostBMaxSlice(GetShapeSize(beShape), 0.0F);
287- std::vector<float> hostBMinSlice(GetShapeSize(beShape), 0.0F);
288- std::vector<float> hostAMax(GetShapeSize(aRedShape), 0.0F);
289- std::vector<float> hostAMean(GetShapeSize(aRedShape), 0.0F);
290- std::vector<float> hostAMin(GetShapeSize(aRedShape), 0.0F);
291 238 
292- // ── Create device tensors ──239+int CreateExampleTensors(const ExampleData& data, const ExampleShapes& shapes, ExampleTensors* tensors)
293- void *devA = nullptr, *devB = nullptr, *devXv = nullptr, *devVxForAe = nullptr;240+{
294- void *devZRow = nullptr, *devDRow = nullptr;241+ auto ret = CreateAclTensor(data.a, shapes.a, &tensors->devA, ACL_BF16, &tensors->a);
295- void *devCompRow = nullptr, *devGemmAddend = nullptr, *devC = nullptr;242+ CHECK_RET(ret == ACL_SUCCESS, return ret);
296- void *devThreshold = nullptr;243+ ret = CreateAclTensor(data.b, shapes.b, &tensors->devB, ACL_BF16, &tensors->b);
297- void *devBMeanAbs = nullptr, *devBMeanSquare = nullptr, *devBVar = nullptr;244+ CHECK_RET(ret == ACL_SUCCESS, return ret);
298- void *devBe = nullptr, *devBeForAiv = nullptr;245+ ret = CreateAclTensor(data.xv, shapes.xv, &tensors->devXv, ACL_BF16, &tensors->xv);
299- void *devBMaxSlice = nullptr, *devBMinSlice = nullptr;246+ CHECK_RET(ret == ACL_SUCCESS, return ret);
300- void *devAMax = nullptr, *devAMean = nullptr, *devAMin = nullptr;247+ ret = CreateAclTensor(data.c, shapes.c, &tensors->devC, ACL_FLOAT, &tensors->c);
248+ CHECK_RET(ret == ACL_SUCCESS, return ret);
249+ return CreateAclTensor(data.compRow, shapes.compRow, &tensors->devCompRow, ACL_UINT8, &tensors->compRow);
250+}
301 251 
302- aclTensor *tA = nullptr, *tB = nullptr, *tXv = nullptr, *tVxForAe = nullptr;252+void DestroyExampleTensors(ExampleTensors* tensors)
303- aclTensor *tZRow = nullptr, *tDRow = nullptr;253+{
304- aclTensor *tCompRow = nullptr, *tGemmAddend = nullptr, *tC = nullptr;254+ auto destroy = [](aclTensor*& tensor) { if (tensor) { aclDestroyTensor(tensor); tensor = nullptr; } };
305- aclTensor *tThreshold = nullptr;255+ auto free = [](void*& address) { if (address) { aclrtFree(address); address = nullptr; } };
306- aclTensor *tBMeanAbs = nullptr, *tBMeanSquare = nullptr, *tBVar = nullptr;256+ destroy(tensors->a); destroy(tensors->b); destroy(tensors->xv); destroy(tensors->c); destroy(tensors->compRow);
307- aclTensor *tBe = nullptr, *tBeForAiv = nullptr;257+ free(tensors->devA); free(tensors->devB); free(tensors->devXv); free(tensors->devC); free(tensors->devCompRow);
308- aclTensor *tBMaxSlice = nullptr, *tBMinSlice = nullptr;258+}
309- aclTensor *tAMax = nullptr, *tAMean = nullptr, *tAMin = nullptr;
310 259 
311- CHECK_RET(CreateAclTensor(hostA, aShape, &devA, ACL_BF16, &tA) == ACL_SUCCESS, return ret);260+int ExecuteMatmulAbftVerify(const TestArgs& args, const ExampleTensors& tensors, aclrtStream stream)
312- CHECK_RET(CreateAclTensor(hostB, bShape, &devB, ACL_BF16, &tB) == ACL_SUCCESS, return ret);261+{
313- CHECK_RET(CreateAclTensor(hostXv, xvShape, &devXv, ACL_BF16, &tXv) == ACL_SUCCESS, return ret);
314- CHECK_RET(CreateAclTensor(hostVxForAe, vxForAeShape, &devVxForAe, ACL_BF16, &tVxForAe) == ACL_SUCCESS, return ret);
315- 
316- CHECK_RET(CreateAclTensor(hostZRow, zRowColShape, &devZRow, ACL_FLOAT, &tZRow) == ACL_SUCCESS, return ret);
317- CHECK_RET(CreateAclTensor(hostDRow, zRowColShape, &devDRow, ACL_FLOAT, &tDRow) == ACL_SUCCESS, return ret);
318- CHECK_RET(CreateAclTensor(hostCompRow, compRowShape, &devCompRow, ACL_UINT8, &tCompRow) == ACL_SUCCESS, return ret);
319- CHECK_RET(CreateAclTensor(hostC, cShape, &devGemmAddend, ACL_FLOAT, &tGemmAddend) == ACL_SUCCESS, return ret);
320- CHECK_RET(CreateAclTensor(hostC, cShape, &devC, ACL_FLOAT, &tC) == ACL_SUCCESS, return ret);
321- CHECK_RET(CreateAclTensor(hostThreshold, zRowColShape, &devThreshold, ACL_FLOAT, &tThreshold) == ACL_SUCCESS, return ret);
322- CHECK_RET(CreateAclTensor(hostBMeanAbs, bStatShape, &devBMeanAbs, ACL_FLOAT, &tBMeanAbs) == ACL_SUCCESS, return ret);
323- CHECK_RET(CreateAclTensor(hostBMeanSquare, bStatShape, &devBMeanSquare, ACL_FLOAT, &tBMeanSquare) == ACL_SUCCESS, return ret);
324- CHECK_RET(CreateAclTensor(hostBVar, bStatShape, &devBVar, ACL_FLOAT, &tBVar) == ACL_SUCCESS, return ret);
325- CHECK_RET(CreateAclTensor(hostBe, beShape, &devBe, ACL_BF16, &tBe) == ACL_SUCCESS, return ret);
326- CHECK_RET(CreateAclTensor(hostBeForAiv, beShape, &devBeForAiv, ACL_FLOAT, &tBeForAiv) == ACL_SUCCESS, return ret);
327- CHECK_RET(CreateAclTensor(hostBMaxSlice, beShape, &devBMaxSlice, ACL_FLOAT, &tBMaxSlice) == ACL_SUCCESS, return ret);
328- CHECK_RET(CreateAclTensor(hostBMinSlice, beShape, &devBMinSlice, ACL_FLOAT, &tBMinSlice) == ACL_SUCCESS, return ret);
329- CHECK_RET(CreateAclTensor(hostAMax, aRedShape, &devAMax, ACL_FLOAT, &tAMax) == ACL_SUCCESS, return ret);
330- CHECK_RET(CreateAclTensor(hostAMean, aRedShape, &devAMean, ACL_FLOAT, &tAMean) == ACL_SUCCESS, return ret);
331- CHECK_RET(CreateAclTensor(hostAMin, aRedShape, &devAMin, ACL_FLOAT, &tAMin) == ACL_SUCCESS, return ret);
332- 
333- // ── Launch MatmulAbftVerify ──
334 uint64_t workspaceSize = 0;262 uint64_t workspaceSize = 0;
335 aclOpExecutor* executor = nullptr;263 aclOpExecutor* executor = nullptr;
336- 264+ auto ret = aclnnMatmulAbftVerifyGetWorkspaceSize(tensors.a, tensors.b, tensors.c, tensors.xv, args.eMax,
337- ret = aclnnMatmulAbftVerifyGetWorkspaceSize(265+ tensors.compRow, &workspaceSize, &executor);
338- tA, tB, tC, tXv, tVxForAe,266+ CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("aclnnMatmulAbftVerifyGetWorkspaceSize failed. ERROR: %d\n", ret); return ret);
339- args.eMax,
340- args.reduceCores,
341- tZRow, tDRow, tCompRow,
342- tThreshold,
343- tBMeanAbs, tBMeanSquare, tBVar,
344- tBe, tBeForAiv,
345- tBMaxSlice, tBMinSlice,
346- tAMax, tAMean, tAMin,
347- &workspaceSize, &executor);
348- CHECK_RET(ret == ACL_SUCCESS,
349- LOG_PRINT("aclnnMatmulAbftVerifyGetWorkspaceSize failed. ERROR: %d.\n[ERROR msg]%s\n",
350- ret, aclGetRecentErrMsg());
351- return ret);
352- 
353 void* workspaceAddr = nullptr;267 void* workspaceAddr = nullptr;
354 if (workspaceSize > 0) {268 if (workspaceSize > 0) {
355 ret = aclrtMalloc(&workspaceAddr, workspaceSize, ACL_MEM_MALLOC_HUGE_FIRST);269 ret = aclrtMalloc(&workspaceAddr, workspaceSize, ACL_MEM_MALLOC_HUGE_FIRST);
356 CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("allocate workspace failed. ERROR: %d\n", ret); return ret);270 CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("allocate workspace failed. ERROR: %d\n", ret); return ret);
357 }271 }
358- 
359 ret = aclnnMatmulAbftVerify(workspaceAddr, workspaceSize, executor, stream);272 ret = aclnnMatmulAbftVerify(workspaceAddr, workspaceSize, executor, stream);
360- CHECK_RET(ret == ACL_SUCCESS,273+ if (ret == ACL_SUCCESS) {
361- LOG_PRINT("aclnnMatmulAbftVerify failed. ERROR: %d.\n[ERROR msg]%s\n",274+ ret = aclrtSynchronizeStream(stream);
362- ret, aclGetRecentErrMsg());
363- return ret);
364- 
365- ret = aclrtSynchronizeStream(stream);
366- CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("aclrtSynchronizeStream failed. ERROR: %d\n", ret); return ret);
367- 
368- LOG_PRINT("MatmulAbftVerify run finished successfully.\n\n");
369- // ── Print results ──
370- if (args.verbose) {
371- PrintChecksum(cShape, devC, ACL_FLOAT, "c");
372- PrintChecksum(zRowColShape, devZRow, ACL_FLOAT, "zRow");
373- PrintChecksum(zRowColShape, devDRow, ACL_FLOAT, "dRow");
374- PrintChecksum(compRowShape, devCompRow, ACL_UINT8, "compRow");
375- PrintChecksum(zRowColShape, devThreshold, ACL_FLOAT, "threshold");
376- PrintChecksum(bStatShape, devBMeanAbs, ACL_FLOAT, "bMeanAbs");
377- PrintChecksum(bStatShape, devBMeanSquare, ACL_FLOAT, "bMeanSquare");
378- PrintChecksum(bStatShape, devBVar, ACL_FLOAT, "bVar");
379- PrintChecksum(beShape, devBe, ACL_BF16, "be");
380- PrintChecksum(beShape, devBeForAiv, ACL_FLOAT, "beForAiv");
381- PrintChecksum(beShape, devBMaxSlice, ACL_FLOAT, "bMaxSlice");
382- PrintChecksum(beShape, devBMinSlice, ACL_FLOAT, "bMinSlice");
383- PrintChecksum(aRedShape, devAMax, ACL_FLOAT, "aMax");
384- PrintChecksum(aRedShape, devAMean, ACL_FLOAT, "aMean");
385- PrintChecksum(aRedShape, devAMin, ACL_FLOAT, "aMin");
386 }275 }
276+ aclrtFree(workspaceAddr);
277+ aclDestroyAclOpExecutor(executor);
278+ return ret;
279+}
387 280 
388- ret = aclDestroyAclOpExecutor(executor);281+int RunMatmulAbftVerify(const TestArgs& args, aclrtStream stream)
389- CHECK_RET(ret == ACL_SUCCESS,282+{
390- LOG_PRINT("aclDestroyAclOpExecutor failed. ERROR: %d\n", ret);283+ const auto shapes = CreateExampleShapes(args);
391- return ret);284+ const auto data = CreateExampleData(shapes);
392- executor = nullptr;285+ ExampleTensors tensors;
393- 286+ auto ret = CreateExampleTensors(data, shapes, &tensors);
394- // ── Cleanup ──287+ if (ret == ACL_SUCCESS) {
395- auto Destroy = [](aclTensor*& t) { if (t) { aclDestroyTensor(t); t = nullptr; } };288+ ret = ExecuteMatmulAbftVerify(args, tensors, stream);
396- auto Free = [](void*& p) { if (p) { aclrtFree(p); p = nullptr; } };289+ }
397- 290+ if (ret == ACL_SUCCESS && args.verbose) {
398- Destroy(tA); Destroy(tB); Destroy(tXv); Destroy(tVxForAe);291+ PrintChecksum(shapes.c, tensors.devC, ACL_FLOAT, "c");
399- Destroy(tZRow); Destroy(tDRow);292+ PrintChecksum(shapes.compRow, tensors.devCompRow, ACL_UINT8, "compRow");
400- Destroy(tCompRow); Destroy(tGemmAddend); Destroy(tC);293+ }
401- Destroy(tThreshold);294+ DestroyExampleTensors(&tensors);
402- Destroy(tBMeanAbs); Destroy(tBMeanSquare); Destroy(tBVar);295+ return ret;
403- Destroy(tBe); Destroy(tBeForAiv);296+}
404- Destroy(tBMaxSlice); Destroy(tBMinSlice);
405- Destroy(tAMax); Destroy(tAMean); Destroy(tAMin);
406- 
407- Free(devA); Free(devB); Free(devXv); Free(devVxForAe);
408- Free(devZRow); Free(devDRow);
409- Free(devCompRow); Free(devGemmAddend); Free(devC);
410- Free(devThreshold);
411- Free(devBMeanAbs); Free(devBMeanSquare); Free(devBVar);
412- Free(devBe); Free(devBeForAiv);
413- Free(devBMaxSlice); Free(devBMinSlice);
414- Free(devAMax); Free(devAMean); Free(devAMin);
415- Free(workspaceAddr);
416 297 
298+void FinalizeAcl(int32_t deviceId, aclrtContext context, aclrtStream stream)
299+{
417 aclrtDestroyStream(stream);300 aclrtDestroyStream(stream);
418 aclrtDestroyContext(context);301 aclrtDestroyContext(context);
419- aclrtResetDevice(args.deviceId);302+ aclrtResetDevice(deviceId);
420 aclFinalize();303 aclFinalize();
421- 304+}
422- return 0;305+ 
306+int main()
307+{
308+ TestArgs args;
309+ args.Print();
310+ 
311+ aclrtContext context = nullptr;
312+ aclrtStream stream = nullptr;
313+ auto ret = InitAcl(args.deviceId, &context, &stream);
314+ CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("Init acl failed. ERROR: %d\n", ret); return ret);
315+ 
316+ ret = RunMatmulAbftVerify(args, stream);
317+ FinalizeAcl(args.deviceId, context, stream);
318+ return ret;
423}319}
@@ -3,7 +3,7 @@
3## 产品支持情况3## 产品支持情况
4 4 
5<!-- npu="950" id1 -->5<!-- npu="950" id1 -->
6-- <term>Ascend 950PR/Ascend 950DT</term>:不支持6+- <term>Ascend 950PR&950DT系列产品</term>:不支持
7<!-- end id1 -->7<!-- end id1 -->
8<!-- npu="A3" id2 -->8<!-- npu="A3" id2 -->
9- <term>Atlas A3 训练系列产品/Atlas A3 推理系列产品</term>:不支持9- <term>Atlas A3 训练系列产品/Atlas A3 推理系列产品</term>:不支持
@@ -3,7 +3,7 @@
3## 产品支持情况3## 产品支持情况
4 4 
5<!-- npu="950" id1 -->5<!-- npu="950" id1 -->
6-- <term>Ascend 950PR/Ascend 950DT</term>:不支持6+- <term>Ascend 950PR&950DT系列产品</term>:不支持
7<!-- end id1 -->7<!-- end id1 -->
8<!-- npu="A3" id2 -->8<!-- npu="A3" id2 -->
9- <term>Atlas A3 训练系列产品/Atlas A3 推理系列产品</term>:不支持9- <term>Atlas A3 训练系列产品/Atlas A3 推理系列产品</term>:不支持
@@ -0,0 +1,495 @@
1+# aclnnObfuscationCalculateV2
2+ 
3+## Product Support
4+ 
5+<!-- npu="950" id1 -->
6+- <term>Ascend 950PR&950DT products</term>: Not supported
7+<!-- end id1 -->
8+<!-- npu="A3" id2 -->
9+- <term>Atlas A3 products</term>: Not supported
10+<!-- end id2 -->
11+<!-- npu="910b" id3 -->
12+- <term>Atlas A2 products</term>: Supported
13+<!-- end id3 -->
14+<!-- npu="310b" id4 -->
15+- <term>Atlas 200I/500 A2 inference products</term>: Not supported
16+<!-- end id4 -->
17+<!-- npu="310p" id5 -->
18+- <term>Atlas inference products</term>: Supported
19+<!-- end id5 -->
20+<!-- npu="910" id6 -->
21+- <term>Atlas training products</term>: Not supported
22+<!-- end id6 -->
23+ 
24+## Function Description
25+ 
26+- API function: sends tensor x and configuration parameters (such as param and cmd) to the PMCC obfuscation engine. The CA module of the engine calls the TA module to perform tensor obfuscation processing, and returns the obfuscated tensor y with the same shape as x.
27+ 
28+- Background: The PMCC (Privacy and Model Confidential Computing) model obfuscation feature uses the TrustZone trusted execution environment in CPU cores to isolate and store obfuscation factors, derive obfuscation masks, and perform dynamic mask addition. Based on the NPU TrustZone, the PMCC builds the model obfuscation engine CA (Client Application in the general OS) and the model obfuscation engine TA (Trusted Application in the TEE OS). To enable the model to access the model obfuscation engine TA during inference execution, the AICPU operator mechanism and the on-card localhost socket of the NPU are used for relay. This API adds the obfCoefficient parameter. In the full-specification DeepSeek version, an obfuscation coefficient is added to ensure that the model obfuscation performance meets the requirements. Input data is processed according to the obfuscation coefficient ratio.
29+ 
30+## Function Prototype
31+ 
32+Each operator uses a [two-phase API](../../../docs/en/context/two_phase_api.md). Call the "aclnnObfuscationCalculateV2GetWorkspaceSize" API to obtain the required workspace size and the executor that contains the operator computation flow, and then call the "aclnnObfuscationCalculateV2" API to execute the computation.
33+ 
34+```c++
35+aclnnStatus aclnnObfuscationCalculateV2GetWorkspaceSize(
36+ int32_t fd,
37+ const aclTensor *x,
38+ int32_t param,
39+ int32_t cmd,
40+ float obfCoefficient,
41+ aclTensor *y,
42+ uint64_t *workspaceSize,
43+ aclOpExecutor **executor)
44+```
45+ 
46+```c++
47+aclnnStatus aclnnObfuscationCalculateV2(
48+ void *workspace,
49+ uint64_t workspaceSize,
50+ aclOpExecutor *executor,
51+ aclrtStream stream)
52+```
53+ 
54+## aclnnObfuscationCalculateV2GetWorkspaceSize
55+ 
56+- **Parameter Description**
57+ <table style="undefined;table-layout: fixed; width: 1452px"><colgroup>
58+ <col style="width: 174px">
59+ <col style="width: 121px">
60+ <col style="width: 253px">
61+ <col style="width: 262px">
62+ <col style="width: 213px">
63+ <col style="width: 115px">
64+ <col style="width: 169px">
65+ <col style="width: 145px">
66+ </colgroup>
67+ <thead>
68+ <tr>
69+ <th>Parameter</th>
70+ <th>Input/Output</th>
71+ <th>Description</th>
72+ <th>Usage</th>
73+ <th>Data Type</th>
74+ <th>Data Format</th>
75+ <th>Shape</th>
76+ <th>Non-contiguous Tensor</th>
77+ </tr></thead>
78+ <tbody>
79+ <tr>
80+ <td>fd (int32_t)</td>
81+ <td>Input</td>
82+ <td>Socket connection descriptor.</td>
83+ <td>Enter fd[0] from the output of aclnnObfuscationSetupV2 during resource initialization.</td>
84+ <td>INT32</td>
85+ <td>ND</td>
86+ <td>-</td>
87+ <td>-</td>
88+ </tr>
89+ <tr>
90+ <td>x (const aclTensor*)</td>
91+ <td>Input</td>
92+ <td>Tensor to be obfuscated.</td>
93+ <td>Empty tensors are not supported.</td>
94+ <td>FLOAT, FLOAT16, INT8, BFLOAT16</td>
95+ <td>ND</td>
96+ <td>[...,H]</td>
97+ <td>x</td>
98+ </tr>
99+ <tr>
100+ <td>param (int32_t)</td>
101+ <td>Input</td>
102+ <td>Reserved parameter field.</td>
103+ <td>Only 0 is supported in the current version.</td>
104+ <td>INT32</td>
105+ <td>-</td>
106+ <td>-</td>
107+ <td>-</td>
108+ </tr>
109+ <tr>
110+ <td>cmd (int32_t)</td>
111+ <td>Input</td>
112+ <td>Obfuscation operator command ID.</td>
113+ <td>Only 1 is supported in the current version.</td>
114+ <td>INT32</td>
115+ <td>-</td>
116+ <td>-</td>
117+ <td>-</td>
118+ </tr>
119+ <tr>
120+ <td>obfCoefficient (float)</td>
121+ <td>Input</td>
122+ <td>Obfuscation coefficient used for obfuscation processing.</td>
123+ <td>The value range is (0.0, 1.0].</td>
124+ <td>-</td>
125+ <td>-</td>
126+ <td>-</td>
127+ <td>-</td>
128+ </tr>
129+ <tr>
130+ <td>y (aclTensor*)</td>
131+ <td>Output</td>
132+ <td>Obfuscated tensor.</td>
133+ <td>The data type and shape are the same as x.</td>
134+ <td>FLOAT, FLOAT16, INT8, BFLOAT16</td>
135+ <td>ND</td>
136+ <td>[...,H]</td>
137+ <td>x</td>
138+ </tr>
139+ <tr>
140+ <td>workspaceSize (uint64_t*)</td>
141+ <td>Output</td>
142+ <td>Returns the workspace size that the user needs to allocate on the device side.</td>
143+ <td>-</td>
144+ <td>-</td>
145+ <td>-</td>
146+ <td>-</td>
147+ <td>-</td>
148+ </tr>
149+ <tr>
150+ <td>executor (aclOpExecutor**)</td>
151+ <td>Output</td>
152+ <td>Returns the operator executor, which contains the operator computation flow.</td>
153+ <td>-</td>
154+ <td>-</td>
155+ <td>-</td>
156+ <td>-</td>
157+ <td>-</td>
158+ </tr>
159+ </tbody>
160+ </table>
161+ 
162+<!-- npu="310p" id7 -->
163+- <term>Atlas inference products</term>: BFLOAT16 is not supported
164+ 
165+<!-- end id7 -->
166+- **Return Value**
167+ 
168+ aclnnStatus: status code. For details, refer to [aclnn Return Codes](../../../docs/en/context/aclnn_return_code.md).
169+ 
170+ The first-phase API performs input parameter validation. An error is reported in the following scenarios:
171+ 
172+ <table style="undefined;table-layout: fixed;width: 1202px"><colgroup>
173+ <col style="width: 262px">
174+ <col style="width: 121px">
175+ <col style="width: 819px">
176+ </colgroup>
177+ <thead>
178+ <tr>
179+ <th>Return Value</th>
180+ <th>Error Code</th>
181+ <th>Description</th>
182+ </tr>
183+ </thead>
184+ <tbody>
185+ <tr>
186+ <td>ACLNN_ERR_PARAM_NULLPTR</td>
187+ <td>161001</td>
188+ <td>The input x or y is a null pointer.</td>
189+ </tr>
190+ <tr>
191+ <td rowspan="3">ACLNN_ERR_PARAM_INVALID</td>
192+ <td rowspan="3">161002</td>
193+ <td>The data type and data format of x are not within the supported range.</td>
194+ </tr>
195+ <tr>
196+ <td>The data types of x and y are inconsistent.</td>
197+ </tr>
198+ <tr>
199+ <td>The shapes of x and y are inconsistent.</td>
200+ </tr>
201+ </tbody>
202+ </table>
203+ 
204+## aclnnObfuscationCalculateV2
205+ 
206+- **Parameter Description**
207+ 
208+ <table style="undefined;table-layout: fixed; width: 1154px"><colgroup>
209+ <col style="width: 153px">
210+ <col style="width: 121px">
211+ <col style="width: 880px">
212+ </colgroup>
213+ <thead>
214+ <tr>
215+ <th>Parameter</th>
216+ <th>Input/Output</th>
217+ <th>Description</th>
218+ </tr></thead>
219+ <tbody>
220+ <tr>
221+ <td>workspace</td>
222+ <td>Input</td>
223+ <td>Workspace memory address allocated on the device side.</td>
224+ </tr>
225+ <tr>
226+ <td>workspaceSize</td>
227+ <td>Input</td>
228+ <td>Workspace size allocated on the device side, obtained from the first-phase API aclnnObfuscationCalculateV2GetWorkspaceSize.</td>
229+ </tr>
230+ <tr>
231+ <td>executor</td>
232+ <td>Input</td>
233+ <td>Operator executor, which contains the operator computation flow.</td>
234+ </tr>
235+ <tr>
236+ <td>stream</td>
237+ <td>Input</td>
238+ <td>Stream used to execute the task.</td>
239+ </tr>
240+ </tbody>
241+ </table>
242+ 
243+- **Return Value**
244+ 
245+ Returns the aclnnStatus status code. For details, refer to [aclnn Return Codes](../../../docs/en/context/aclnn_return_code.md).
246+ 
247+## Precautions
248+ 
249+- Deterministic computation:
250+ - aclnnObfuscationCalculateV2 uses the deterministic implementation by default.
251+ 
252+- This API is used together with aclnnObfuscationSetupV2 to implement the PMCC model obfuscation feature. The usage is as follows:
253+ - Call aclnnObfuscationSetupV2 for resource initialization. This API can be called multiple times, and the last initialization takes effect.
254+ - Call aclnnObfuscationCalculateV2 multiple times for tensor obfuscation processing.
255+ - Call aclnnObfuscationSetupV2 for resource release. This API can be called only once. Alternatively, resource release can be achieved by terminating the program process instead of explicitly calling the release API.
256+ 
257+## Invocation Sample
258+ 
259+The following sample code is for reference only. For the specific compilation and execution process, refer to [Compilation and Execution Sample](../../../docs/en/context/compile_and_run_sample.md).
260+ 
261+```C++
262+#include <iostream>
263+#include <vector>
264+#include "acl/acl.h"
265+#include "aclnnop/aclnn_obfuscation_setup_v2.h"
266+#include "aclnnop/aclnn_obfuscation_calculate_v2.h"
267+ 
268+#define CHECK_RET(cond, return_expr) \
269+ do { \
270+ if (!(cond)) { \
271+ return_expr; \
272+ } \
273+ } while (0)
274+ 
275+#define LOG_PRINT(message, ...) \
276+ do { \
277+ printf(message, ##__VA_ARGS__); \
278+ } while (0)
279+ 
280+int64_t GetShapeSize(const std::vector<int64_t>& shape) {
281+ int64_t shapeSize = 1;
282+ for (auto i : shape) {
283+ shapeSize *= i;
284+ }
285+ return shapeSize;
286+}
287+ 
288+int Init(int32_t deviceId, aclrtStream* stream) {
289+ // Fixed pattern: resource initialization
290+ auto ret = aclInit(nullptr);
291+ CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("aclInit failed. ERROR: %d\n", ret); return ret);
292+ ret = aclrtSetDevice(deviceId);
293+ CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("aclrtSetDevice failed. ERROR: %d\n", ret); return ret);
294+ ret = aclrtCreateStream(stream);
295+ CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("aclrtCreateStream failed. ERROR: %d\n", ret); return ret);
296+ return 0;
297+}
298+ 
299+template <typename T>
300+int CreateAclTensor(const std::vector<T>& hostData, const std::vector<int64_t>& shape, void** deviceAddr,
301+ aclDataType dataType, aclTensor** tensor) {
302+ auto size = GetShapeSize(shape) * sizeof(T);
303+ // Call aclrtMalloc to allocate device memory
304+ auto ret = aclrtMalloc(deviceAddr, size, ACL_MEM_MALLOC_HUGE_FIRST);
305+ CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("aclrtMalloc failed. ERROR: %d\n", ret); return ret);
306+ // Call aclrtMemcpy to copy host data to device memory
307+ ret = aclrtMemcpy(*deviceAddr, size, hostData.data(), size, ACL_MEMCPY_HOST_TO_DEVICE);
308+ CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("aclrtMemcpy failed. ERROR: %d\n", ret); return ret);
309+ 
310+ // Compute strides for contiguous tensor
311+ std::vector<int64_t> strides(shape.size(), 1);
312+ for (int64_t i = shape.size() - 2; i >= 0; i--) {
313+ strides[i] = shape[i + 1] * strides[i + 1];
314+ }
315+ 
316+ // Call aclCreateTensor to create aclTensor
317+ *tensor = aclCreateTensor(shape.data(), shape.size(), dataType, strides.data(), 0, aclFormat::ACL_FORMAT_ND,
318+ shape.data(), shape.size(), *deviceAddr);
319+ return 0;
320+}
321+ 
322+int main() {
323+ // 1. (Fixed pattern) device/stream initialization. Refer to the acl API manual.
324+ // Set deviceId based on the actual device.
325+ int32_t deviceId = 0;
326+ aclrtStream stream;
327+ auto ret = Init(deviceId, &stream);
328+ CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("Init acl failed. ERROR: %d\n", ret); return ret);
329+ 
330+ // 2. Construct input and output based on the API interface.
331+ std::vector<int64_t> fdShape = {1};
332+ void* fdDeviceAddr = nullptr;
333+ 
334+ int32_t fdToClose = 0;
335+ int32_t dataType = 0;
336+ int32_t hiddenSize = 4;
337+ int32_t tpRank = 0;
338+ int32_t modelObfSeedId = 123456;
339+ int32_t dataObfSeedId = 654321;
340+ int32_t cmd = 1;
341+ int32_t threadNum = 4;
342+ float obfCoefficient = 0.5;
343+ aclTensor* fd = nullptr;
344+ std::vector<float> fdHostData = {-1};
345+ 
346+ // Create fd aclTensor
347+ ret = CreateAclTensor(fdHostData, fdShape, &fdDeviceAddr, aclDataType::ACL_INT32, &fd);
348+ CHECK_RET(ret == ACL_SUCCESS, return ret);
349+ 
350+ // 3. Call the CANN operator library API. Replace with the specific API name.
351+ uint64_t workspaceSize = 0;
352+ aclOpExecutor* executor;
353+ 
354+ // Call the first-phase API of aclnnObfuscationSetupV2
355+ ret = aclnnObfuscationSetupV2GetWorkspaceSize(fdToClose, dataType, hiddenSize, tpRank, modelObfSeedId,dataObfSeedId, cmd, threadNum, obfCoefficient, fd, &workspaceSize, &executor);
356+ CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("aclnnObfuscationSetupV2GetWorkspaceSize failed. ERROR: %d\n", ret); return ret);
357+ 
358+ // Allocate device memory based on the workspaceSize from the first-phase API
359+ void* workspaceAddr = nullptr;
360+ if (workspaceSize > 0) {
361+ ret = aclrtMalloc(&workspaceAddr, workspaceSize, ACL_MEM_MALLOC_HUGE_FIRST);
362+ CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("allocate workspace failed. ERROR: %d\n", ret); return ret);
363+ }
364+ 
365+ // Call the second-phase API of aclnnObfuscationSetupV2
366+ ret = aclnnObfuscationSetupV2(workspaceAddr, workspaceSize, executor, stream);
367+ CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("aclnnObfuscationSetupV2 failed. ERROR: %d\n", ret); return ret);
368+ 
369+ // 4. (Fixed pattern) Synchronize and wait for task completion
370+ ret = aclrtSynchronizeStream(stream);
371+ CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("aclrtSynchronizeStream failed. ERROR: %d\n", ret); return ret);
372+ 
373+ // 5. Get the output value. Copy the result from device memory to host side. Modify based on the specific API interface.
374+ auto fdSize = GetShapeSize(fdShape);
375+ std::vector<int32_t> fdData(fdSize, 0);
376+ ret = aclrtMemcpy(fdData.data(), fdData.size() * sizeof(fdData[0]), fdDeviceAddr, fdSize * sizeof(int32_t),ACL_MEMCPY_DEVICE_TO_HOST);
377+ CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("copy result from device to host failed. ERROR : %d\n", ret); return ret);
378+ for (int64_t i = 0; i < fdSize; i++) {
379+ LOG_PRINT("fdData[%ld] is : %d\n", i, fdData[i]);
380+ }
381+ 
382+ // 6. Construct input and output based on the API interface.
383+ std::vector<int64_t> xShape = {2, 4};
384+ std::vector<int64_t> yShape = {2, 4};
385+ void *xDeviceAddr = nullptr;
386+ void *yDeviceAddr = nullptr;
387+ 
388+ int32_t fdInput = fdData[0];
389+ int32_t param = 4;
390+ aclTensor *x = nullptr;
391+ int32_t cmd2 = 1;
392+ aclTensor *y = nullptr;
393+ std::vector<float> xHostData = {0.86, 0.79, 0.43, 0.37, 0.51, 0.89, 0.34, 0.49};
394+ std::vector<float> yHostData = {0, 0, 0, 0, 0, 0, 0, 0};
395+ 
396+ // Create x aclTensor
397+ ret = CreateAclTensor(xHostData, xShape, &xDeviceAddr, aclDataType::ACL_FLOAT, &x);
398+ CHECK_RET(ret == ACL_SUCCESS, return ret);
399+ 
400+ // Create y aclTensor
401+ ret = CreateAclTensor(yHostData, yShape, &yDeviceAddr, aclDataType::ACL_FLOAT, &y);
402+ CHECK_RET(ret == ACL_SUCCESS, return ret);
403+ 
404+ // 7. Call the CANN operator library API. Replace with the specific API.
405+ uint64_t workspaceSize2 = 0;
406+ aclOpExecutor *executor2;
407+ 
408+ // Call the first-phase API of aclnnObfuscationCalculateV2
409+ ret = aclnnObfuscationCalculateV2GetWorkspaceSize(fdInput, x, param, cmd2, obfCoefficient, y, &workspaceSize2, &executor2);
410+ CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("aclnnObfuscationCalculateV2GetWorkspaceSize failed. ERROR : %d\n",ret); return ret);
411+ // Allocate device memory based on the workspaceSize from the first-phase API
412+ void *workspaceAddr2 = nullptr;
413+ if (workspaceSize2 > 0) {
414+ ret = aclrtMalloc(&workspaceAddr2, workspaceSize2, ACL_MEM_MALLOC_HUGE_FIRST);
415+ CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("allocate workspace failed. ERROR: %d\n", ret); return ret);
416+ }
417+ 
418+ // Call the second-phase API of aclnnObfuscationCalculateV2
419+ ret = aclnnObfuscationCalculateV2(workspaceAddr2, workspaceSize2, executor2, stream);
420+ CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("aclnnObfuscationCalculateV2 failed. ERROR : %d\n", ret); return ret);
421+ // 8. (Fixed pattern) Synchronize and wait for task completion
422+ ret = aclrtSynchronizeStream(stream);
423+ CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("aclrtSynchronizeStream failed. ERROR : %d\n", ret); return ret);
424+ 
425+ // 9. Get the output value. y represents the obfuscated data. Copy the result from device memory to host side. Modify based on the specific API interface.
426+ // y
427+ auto ySize = GetShapeSize(yShape);
428+ std::vector<float> yData(ySize, 0);
429+ ret = aclrtMemcpy(yData.data(), yData.size() * sizeof(yData[0]), yDeviceAddr, ySize * sizeof(float),ACL_MEMCPY_DEVICE_TO_HOST);
430+ CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("copy result from device to host failed. ERROR : %d\n", ret); return ret);
431+ for (int64_t i = 0; i < ySize; i++) {
432+ LOG_PRINT("yData[%ld] is : %f\n", i, yData[i]);
433+ }
434+ 
435+ // 10. Construct input and output based on the API interface.
436+ fdToClose = fdInput;
437+ dataType = 0;
438+ hiddenSize = 0;
439+ tpRank = 0;
440+ modelObfSeedId = 0;
441+ dataObfSeedId = 0;
442+ cmd = 16;
443+ threadNum = 4;
444+ 
445+ // 11. Call the CANN operator library API. Replace with the specific API name.
446+ uint64_t workspaceSize3 = 0;
447+ aclOpExecutor* executor3;
448+ 
449+ // Call the first-phase API of aclnnObfuscationSetupV2
450+ ret = aclnnObfuscationSetupV2GetWorkspaceSize(fdToClose, dataType, hiddenSize, tpRank, modelObfSeedId,dataObfSeedId, cmd, threadNum, obfCoefficient, fd, &workspaceSize3, &executor3);
451+ CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("aclnnObfuscationSetupV2GetWorkspaceSize failed. ERROR: %d\n", ret); return ret);
452+ 
453+ // Allocate device memory based on the workspaceSize from the first-phase API
454+ void* workspaceAddr3 = nullptr;
455+ if (workspaceSize3 > 0) {
456+ ret = aclrtMalloc(&workspaceAddr3, workspaceSize3, ACL_MEM_MALLOC_HUGE_FIRST);
457+ CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("allocate workspace failed. ERROR: %d\n", ret); return ret);
458+ }
459+ 
460+ // Call the second-phase API of aclnnObfuscationSetupV2
461+ ret = aclnnObfuscationSetupV2(workspaceAddr3, workspaceSize3, executor3, stream);
462+ CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("aclnnObfuscationSetupV2 failed. ERROR: %d\n", ret); return ret);
463+ 
464+ // 12. (Fixed pattern) Synchronize and wait for task completion
465+ ret = aclrtSynchronizeStream(stream);
466+ CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("aclrtSynchronizeStream failed. ERROR: %d\n", ret); return ret);
467+ 
468+ // 13. Release aclTensor and aclScalar used by the ObfuscationCalculateV2 API. Modify based on the specific API interface.
469+ aclDestroyTensor(x);
470+ aclDestroyTensor(y);
471+ aclDestroyTensor(fd);
472+ 
473+ // 14. Release device resources used by the ObfuscationCalculateV2 API. Modify based on the specific API interface.
474+ aclrtFree(xDeviceAddr);
475+ aclrtFree(yDeviceAddr);
476+ aclrtFree(fdDeviceAddr);
477+ 
478+ if (workspaceSize > 0) {
479+ aclrtFree(workspaceAddr);
480+ }
481+ if (workspaceSize2 > 0) {
482+ aclrtFree(workspaceAddr2);
483+ }
484+ if (workspaceSize3 > 0) {
485+ aclrtFree(workspaceAddr3);
486+ }
487+ // 15. Release device resources used by the ObfuscationSetupV2 API
488+ aclrtDestroyStream(stream);
489+ aclrtResetDevice(deviceId);
490+ aclFinalize();
491+ 
492+ return 0;
493+}
494+ 
495+```
@@ -0,0 +1,483 @@
1+# aclnnObfuscationCalculate
2+ 
3+## Product Support
4+ 
5+<!-- npu="950" id1 -->
6+- <term>Ascend 950PR&950DT products</term>: Not supported
7+<!-- end id1 -->
8+<!-- npu="A3" id2 -->
9+- <term>Atlas A3 products</term>: Not supported
10+<!-- end id2 -->
11+<!-- npu="910b" id3 -->
12+- <term>Atlas A2 products</term>: Supported
13+<!-- end id3 -->
14+<!-- npu="310b" id4 -->
15+- <term>Atlas 200I/500 A2 inference products</term>: Not supported
16+<!-- end id4 -->
17+<!-- npu="310p" id5 -->
18+- <term>Atlas inference products</term>: Supported
19+<!-- end id5 -->
20+<!-- npu="910" id6 -->
21+- <term>Atlas training products</term>: Not supported
22+<!-- end id6 -->
23+ 
24+## Function Description
25+ 
26+- API function: sends tensor x and configuration parameters (such as param and cmd) to the PMCC obfuscation engine. The CA module of the engine calls the TA module to perform tensor obfuscation processing, and returns the obfuscated tensor y with the same shape as x.
27+ 
28+- Background: The PMCC (Privacy and Model Confidential Computing) model obfuscation feature uses the TrustZone trusted execution environment in CPU cores to isolate and store obfuscation factors, derive obfuscation masks, and perform dynamic mask addition. Based on the NPU TrustZone, the PMCC builds the model obfuscation engine CA (Client Application in the general OS) and the model obfuscation engine TA (Trusted Application in the TEE OS). To enable the model to access the model obfuscation engine TA during inference execution, the AICPU operator mechanism and the on-card localhost socket of the NPU are used for relay.
29+ 
30+## Function Prototype
31+ 
32+Each operator uses a [two-phase API](../../../docs/en/context/two_phase_api.md). Call the "aclnnObfuscationCalculateGetWorkspaceSize" API to obtain the required workspace size and the executor that contains the operator computation flow, and then call the "aclnnObfuscationCalculate" API to execute the computation.
33+ 
34+```c++
35+aclnnStatus aclnnObfuscationCalculateGetWorkspaceSize(
36+ int32_t fd,
37+ const aclTensor *x,
38+ int32_t param,
39+ int32_t cmd,
40+ aclTensor *y,
41+ uint64_t *workspaceSize,
42+ aclOpExecutor **executor)
43+```
44+ 
45+```c++
46+aclnnStatus aclnnObfuscationCalculate(
47+ void *workspace,
48+ uint64_t workspaceSize,
49+ aclOpExecutor *executor,
50+ aclrtStream stream)
51+```
52+ 
53+## aclnnObfuscationCalculateGetWorkspaceSize
54+ 
55+- **Parameter Description**
56+ 
57+ <table style="undefined;table-layout: fixed; width: 1452px"><colgroup>
58+ <col style="width: 174px">
59+ <col style="width: 121px">
60+ <col style="width: 253px">
61+ <col style="width: 262px">
62+ <col style="width: 213px">
63+ <col style="width: 115px">
64+ <col style="width: 169px">
65+ <col style="width: 145px">
66+ </colgroup>
67+ <thead>
68+ <tr>
69+ <th>Parameter</th>
70+ <th>Input/Output</th>
71+ <th>Description</th>
72+ <th>Usage</th>
73+ <th>Data Type</th>
74+ <th>Data Format</th>
75+ <th>Shape</th>
76+ <th>Non-contiguous Tensor</th>
77+ </tr></thead>
78+ <tbody>
79+ <tr>
80+ <td>fd (int32_t)</td>
81+ <td>Input</td>
82+ <td>Socket connection descriptor.</td>
83+ <td>The data type is INT32.</td>
84+ <td>INT32</td>
85+ <td>ND</td>
86+ <td>-</td>
87+ <td>-</td>
88+ </tr>
89+ <tr>
90+ <td>x (const aclTensor*)</td>
91+ <td>Input</td>
92+ <td>Tensor to be obfuscated.</td>
93+ <td>Empty tensors are not supported.</td>
94+ <td>FLOAT, FLOAT16, INT8, BFLOAT16</td>
95+ <td>ND</td>
96+ <td>[...,H]</td>
97+ <td>x</td>
98+ </tr>
99+ <tr>
100+ <td>param (int32_t)</td>
101+ <td>Input</td>
102+ <td>Reserved parameter field.</td>
103+ <td>Only 0 is supported in the current version.</td>
104+ <td>INT32</td>
105+ <td>-</td>
106+ <td>-</td>
107+ <td>-</td>
108+ </tr>
109+ <tr>
110+ <td>cmd (int32_t)</td>
111+ <td>Input</td>
112+ <td>Obfuscation operator command ID.</td>
113+ <td>Only 1 is supported in the current version.</td>
114+ <td>INT32</td>
115+ <td>-</td>
116+ <td>-</td>
117+ <td>-</td>
118+ </tr>
119+ <tr>
120+ <td>y (aclTensor*)</td>
121+ <td>Output</td>
122+ <td>Obfuscated tensor.</td>
123+ <td>The data type and shape are the same as x.</td>
124+ <td>FLOAT, FLOAT16, INT8, BFLOAT16</td>
125+ <td>ND</td>
126+ <td>[...,H]</td>
127+ <td>x</td>
128+ </tr>
129+ <tr>
130+ <td>workspaceSize (uint64_t*)</td>
131+ <td>Output</td>
132+ <td>Returns the workspace size that the user needs to allocate on the device side.</td>
133+ <td>-</td>
134+ <td>-</td>
135+ <td>-</td>
136+ <td>-</td>
137+ <td>-</td>
138+ </tr>
139+ <tr>
140+ <td>executor (aclOpExecutor**)</td>
141+ <td>Output</td>
142+ <td>Returns the operator executor, which contains the operator computation flow.</td>
143+ <td>-</td>
144+ <td>-</td>
145+ <td>-</td>
146+ <td>-</td>
147+ <td>-</td>
148+ </tr>
149+ </tbody>
150+ </table>
151+ 
152+<!-- npu="310p" id7 -->
153+- <term>Atlas inference products</term>: BFLOAT16 is not supported
154+ 
155+<!-- end id7 -->
156+- **Return Value**
157+ 
158+ aclnnStatus: status code. For details, refer to [aclnn Return Codes](../../../docs/en/context/aclnn_return_code.md).
159+ 
160+ The first-phase API performs input parameter validation. An error is reported in the following scenarios:
161+ 
162+ <table style="undefined;table-layout: fixed;width: 1202px"><colgroup>
163+ <col style="width: 262px">
164+ <col style="width: 121px">
165+ <col style="width: 819px">
166+ </colgroup>
167+ <thead>
168+ <tr>
169+ <th>Return Value</th>
170+ <th>Error Code</th>
171+ <th>Description</th>
172+ </tr>
173+ </thead>
174+ <tbody>
175+ <tr>
176+ <td>ACLNN_ERR_PARAM_NULLPTR</td>
177+ <td>161001</td>
178+ <td>The input x or y is a null pointer.</td>
179+ </tr>
180+ <tr>
181+ <td rowspan="3">ACLNN_ERR_PARAM_INVALID</td>
182+ <td rowspan="3">161002</td>
183+ <td>The data type and data format of x are not within the supported range.</td>
184+ </tr>
185+ <tr>
186+ <td>The data types of x and y are inconsistent.</td>
187+ </tr>
188+ <tr>
189+ <td>The shapes of x and y are inconsistent.</td>
190+ </tr>
191+ </tbody>
192+ </table>
193+ 
194+## aclnnObfuscationCalculate
195+ 
196+- **Parameter Description**
197+ <table style="undefined;table-layout: fixed; width: 1154px"><colgroup>
198+ <col style="width: 153px">
199+ <col style="width: 121px">
200+ <col style="width: 880px">
201+ </colgroup>
202+ <thead>
203+ <tr>
204+ <th>Parameter</th>
205+ <th>Input/Output</th>
206+ <th>Description</th>
207+ </tr></thead>
208+ <tbody>
209+ <tr>
210+ <td>workspace</td>
211+ <td>Input</td>
212+ <td>Workspace memory address allocated on the device side.</td>
213+ </tr>
214+ <tr>
215+ <td>workspaceSize</td>
216+ <td>Input</td>
217+ <td>Workspace size allocated on the device side, obtained from the first-phase API aclnnObfuscationCalculateGetWorkspaceSize.</td>
218+ </tr>
219+ <tr>
220+ <td>executor</td>
221+ <td>Input</td>
222+ <td>Operator executor, which contains the operator computation flow.</td>
223+ </tr>
224+ <tr>
225+ <td>stream</td>
226+ <td>Input</td>
227+ <td>Stream used to execute the task.</td>
228+ </tr>
229+ </tbody>
230+ </table>
231+ 
232+- **Return Value**
233+ 
234+ Returns the aclnnStatus status code. For details, refer to [aclnn Return Codes](../../../docs/en/context/aclnn_return_code.md).
235+ 
236+## Precautions
237+ 
238+- Deterministic computation:
239+ - aclnnObfuscationCalculate uses the deterministic implementation by default.
240+ 
241+- This API is used together with aclnnObfuscationSetup to implement the PMCC model obfuscation feature. The usage is as follows:
242+ - Call aclnnObfuscationSetup for resource initialization. This API can be called multiple times, and the last initialization takes effect.
243+ - Call aclnnObfuscationCalculate multiple times for tensor obfuscation processing.
244+ - Call aclnnObfuscationSetup for resource release. This API can be called only once. Alternatively, resource release can be achieved by terminating the program process instead of explicitly calling the release API.
245+ 
246+## Invocation Sample
247+ 
248+The following sample code is for reference only. For the specific compilation and execution process, refer to [Compilation and Execution Sample](../../../docs/en/context/compile_and_run_sample.md).
249+ 
250+```cpp
251+#include <iostream>
252+#include <vector>
253+#include "acl/acl.h"
254+#include "aclnnop/aclnn_obfuscation_setup.h"
255+#include "aclnnop/aclnn_obfuscation_calculate.h"
256+ 
257+#define CHECK_RET(cond, return_expr) \
258+ do { \
259+ if (!(cond)) { \
260+ return_expr; \
261+ } \
262+ } while (0)
263+ 
264+#define LOG_PRINT(message, ...) \
265+ do { \
266+ printf(message, ##__VA_ARGS__); \
267+ } while (0)
268+ 
269+int64_t GetShapeSize(const std::vector<int64_t>& shape) {
270+ int64_t shapeSize = 1;
271+ for (auto i : shape) {
272+ shapeSize *= i;
273+ }
274+ return shapeSize;
275+}
276+ 
277+int Init(int32_t deviceId, aclrtStream* stream) {
278+ // Fixed pattern: resource initialization
279+ auto ret = aclInit(nullptr);
280+ CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("aclInit failed. ERROR: %d\n", ret); return ret);
281+ ret = aclrtSetDevice(deviceId);
282+ CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("aclrtSetDevice failed. ERROR: %d\n", ret); return ret);
283+ ret = aclrtCreateStream(stream);
284+ CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("aclrtCreateStream failed. ERROR: %d\n", ret); return ret);
285+ return 0;
286+}
287+ 
288+template <typename T>
289+int CreateAclTensor(const std::vector<T>& hostData, const std::vector<int64_t>& shape, void** deviceAddr,
290+ aclDataType dataType, aclTensor** tensor) {
291+ auto size = GetShapeSize(shape) * sizeof(T);
292+ // Call aclrtMalloc to allocate device memory
293+ auto ret = aclrtMalloc(deviceAddr, size, ACL_MEM_MALLOC_HUGE_FIRST);
294+ CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("aclrtMalloc failed. ERROR: %d\n", ret); return ret);
295+ // Call aclrtMemcpy to copy host data to device memory
296+ ret = aclrtMemcpy(*deviceAddr, size, hostData.data(), size, ACL_MEMCPY_HOST_TO_DEVICE);
297+ CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("aclrtMemcpy failed. ERROR: %d\n", ret); return ret);
298+ 
299+ // Compute strides for contiguous tensor
300+ std::vector<int64_t> strides(shape.size(), 1);
301+ for (int64_t i = shape.size() - 2; i >= 0; i--) {
302+ strides[i] = shape[i + 1] * strides[i + 1];
303+ }
304+ 
305+ // Call aclCreateTensor to create aclTensor
306+ *tensor = aclCreateTensor(shape.data(), shape.size(), dataType, strides.data(), 0, aclFormat::ACL_FORMAT_ND,
307+ shape.data(), shape.size(), *deviceAddr);
308+ return 0;
309+}
310+ 
311+int main() {
312+ // 1. (Fixed pattern) device/stream initialization. Refer to the acl API manual.
313+ // Set deviceId based on the actual device.
314+ int32_t deviceId = 0;
315+ aclrtStream stream;
316+ auto ret = Init(deviceId, &stream);
317+ CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("Init acl failed. ERROR: %d\n", ret); return ret);
318+ 
319+ // 2. Construct input and output based on the API interface.
320+ std::vector<int64_t> fdShape = {1};
321+ void* fdDeviceAddr = nullptr;
322+ 
323+ int32_t fdToClose = 0;
324+ int32_t dataType = 0;
325+ int32_t hiddenSize = 4;
326+ int32_t tpRank = 0;
327+ int32_t modelObfSeedId = 123456;
328+ int32_t dataObfSeedId = 654321;
329+ int32_t cmd = 1;
330+ int32_t threadNum = 4;
331+ aclTensor* fd = nullptr;
332+ std::vector<float> fdHostData = {-1};
333+ 
334+ // Create fd aclTensor
335+ ret = CreateAclTensor(fdHostData, fdShape, &fdDeviceAddr, aclDataType::ACL_INT32, &fd);
336+ CHECK_RET(ret == ACL_SUCCESS, return ret);
337+ 
338+ // 3. Call the CANN operator library API. Replace with the specific API name.
339+ uint64_t workspaceSize = 0;
340+ aclOpExecutor* executor;
341+ 
342+ // Call the first-phase API of aclnnObfuscationSetup
343+ ret = aclnnObfuscationSetupGetWorkspaceSize(fdToClose, dataType, hiddenSize, tpRank, modelObfSeedId,dataObfSeedId, cmd, threadNum, fd, &workspaceSize, &executor);
344+ CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("aclnnObfuscationSetupGetWorkspaceSize failed. ERROR: %d\n", ret); return ret);
345+ 
346+ // Allocate device memory based on the workspaceSize from the first-phase API
347+ void* workspaceAddr = nullptr;
348+ if (workspaceSize > 0) {
349+ ret = aclrtMalloc(&workspaceAddr, workspaceSize, ACL_MEM_MALLOC_HUGE_FIRST);
350+ CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("allocate workspace failed. ERROR: %d\n", ret); return ret);
351+ }
352+ 
353+ // Call the second-phase API of aclnnObfuscationSetup
354+ ret = aclnnObfuscationSetup(workspaceAddr, workspaceSize, executor, stream);
355+ CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("aclnnObfuscationSetup failed. ERROR: %d\n", ret); return ret);
356+ 
357+ // 4. (Fixed pattern) Synchronize and wait for task completion
358+ ret = aclrtSynchronizeStream(stream);
359+ CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("aclrtSynchronizeStream failed. ERROR: %d\n", ret); return ret);
360+ 
361+ // 5. Get the output value. Copy the result from device memory to host side. Modify based on the specific API interface.
362+ auto fdSize = GetShapeSize(fdShape);
363+ std::vector<int32_t> fdData(fdSize, 0);
364+ ret = aclrtMemcpy(fdData.data(), fdData.size() * sizeof(fdData[0]), fdDeviceAddr, fdSize * sizeof(int32_t),ACL_MEMCPY_DEVICE_TO_HOST);
365+ CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("copy result from device to host failed. ERROR : %d\n", ret); return ret);
366+ for (int64_t i = 0; i < fdSize; i++) {
367+ LOG_PRINT("fdData[%ld] is : %d\n", i, fdData[i]);
368+ }
369+ 
370+ // 6. Construct input and output based on the API interface.
371+ std::vector<int64_t> xShape = {2, 4};
372+ std::vector<int64_t> yShape = {2, 4};
373+ void *xDeviceAddr = nullptr;
374+ void *yDeviceAddr = nullptr;
375+ 
376+ int32_t fdInput = fdData[0];
377+ int32_t param = 4;
378+ aclTensor *x = nullptr;
379+ int32_t cmd2 = 1;
380+ aclTensor *y = nullptr;
381+ std::vector<float> xHostData = {0.86, 0.79, 0.43, 0.37, 0.51, 0.89, 0.34, 0.49};
382+ std::vector<float> yHostData = {0, 0, 0, 0, 0, 0, 0, 0};
383+ 
384+ // Create x aclTensor
385+ ret = CreateAclTensor(xHostData, xShape, &xDeviceAddr, aclDataType::ACL_FLOAT, &x);
386+ CHECK_RET(ret == ACL_SUCCESS, return ret);
387+ 
388+ // Create y aclTensor
389+ ret = CreateAclTensor(yHostData, yShape, &yDeviceAddr, aclDataType::ACL_FLOAT, &y);
390+ CHECK_RET(ret == ACL_SUCCESS, return ret);
391+ 
392+ // 7. Call the CANN operator library API. Replace with the specific API.
393+ uint64_t workspaceSize2 = 0;
394+ aclOpExecutor *executor2;
395+ 
396+ // Call the first-phase API of aclnnObfuscationCalculate
397+ ret = aclnnObfuscationCalculateGetWorkspaceSize(fdInput, x, param, cmd2, y, &workspaceSize2, &executor2);
398+ CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("aclnnObfuscationCalculateGetWorkspaceSize failed. ERROR : %d\n",ret); return ret);
399+ // Allocate device memory based on the workspaceSize from the first-phase API
400+ void *workspaceAddr2 = nullptr;
401+ if (workspaceSize2 > 0) {
402+ ret = aclrtMalloc(&workspaceAddr2, workspaceSize2, ACL_MEM_MALLOC_HUGE_FIRST);
403+ CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("allocate workspace failed. ERROR: %d\n", ret); return ret);
404+ }
405+ 
406+ // Call the second-phase API of aclnnObfuscationCalculate
407+ ret = aclnnObfuscationCalculate(workspaceAddr2, workspaceSize2, executor2, stream);
408+ CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("aclnnObfuscationCalculate failed. ERROR : %d\n", ret); return ret);
409+ // 8. (Fixed pattern) Synchronize and wait for task completion
410+ ret = aclrtSynchronizeStream(stream);
411+ CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("aclrtSynchronizeStream failed. ERROR : %d\n", ret); return ret);
412+ 
413+ // 9. Get the output value. y represents the obfuscated data. Copy the result from device memory to host side. Modify based on the specific API interface.
414+ // y
415+ auto ySize = GetShapeSize(yShape);
416+ std::vector<float> yData(ySize, 0);
417+ ret = aclrtMemcpy(yData.data(), yData.size() * sizeof(yData[0]), yDeviceAddr, ySize * sizeof(float),ACL_MEMCPY_DEVICE_TO_HOST);
418+ CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("copy result from device to host failed. ERROR : %d\n", ret); return ret);
419+ for (int64_t i = 0; i < ySize; i++) {
420+ LOG_PRINT("yData[%ld] is : %f\n", i, yData[i]);
421+ }
422+ 
423+ // 10. Construct input and output based on the API interface.
424+ fdToClose = fdInput;
425+ dataType = 0;
426+ hiddenSize = 0;
427+ tpRank = 0;
428+ modelObfSeedId = 0;
429+ dataObfSeedId = 0;
430+ cmd = 16;
431+ threadNum = 4;
432+ 
433+ // 11. Call the CANN operator library API. Replace with the specific API name.
434+ uint64_t workspaceSize3 = 0;
435+ aclOpExecutor* executor3;
436+ 
437+ // Call the first-phase API of aclnnObfuscationSetup
438+ ret = aclnnObfuscationSetupGetWorkspaceSize(fdToClose, dataType, hiddenSize, tpRank, modelObfSeedId,dataObfSeedId, cmd, threadNum, fd, &workspaceSize3, &executor3);
439+ CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("aclnnObfuscationSetupGetWorkspaceSize failed. ERROR: %d\n", ret); return ret);
440+ 
441+ // Allocate device memory based on the workspaceSize from the first-phase API
442+ void* workspaceAddr3 = nullptr;
443+ if (workspaceSize3 > 0) {
444+ ret = aclrtMalloc(&workspaceAddr3, workspaceSize3, ACL_MEM_MALLOC_HUGE_FIRST);
445+ CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("allocate workspace failed. ERROR: %d\n", ret); return ret);
446+ }
447+ 
448+ // Call the second-phase API of aclnnObfuscationSetup
449+ ret = aclnnObfuscationSetup(workspaceAddr3, workspaceSize3, executor3, stream);
450+ CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("aclnnObfuscationSetup failed. ERROR: %d\n", ret); return ret);
451+ 
452+ // 12. (Fixed pattern) Synchronize and wait for task completion
453+ ret = aclrtSynchronizeStream(stream);
454+ CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("aclrtSynchronizeStream failed. ERROR: %d\n", ret); return ret);
455+ 
456+ // 13. Release aclTensor and aclScalar used by the ObfuscationCalculate API. Modify based on the specific API interface.
457+ aclDestroyTensor(x);
458+ aclDestroyTensor(y);
459+ aclDestroyTensor(fd);
460+ 
461+ // 14. Release device resources used by the ObfuscationCalculate API. Modify based on the specific API interface.
462+ aclrtFree(xDeviceAddr);
463+ aclrtFree(yDeviceAddr);
464+ aclrtFree(fdDeviceAddr);
465+ 
466+ if (workspaceSize > 0) {
467+ aclrtFree(workspaceAddr);
468+ }
469+ if (workspaceSize2 > 0) {
470+ aclrtFree(workspaceAddr2);
471+ }
472+ if (workspaceSize3 > 0) {
473+ aclrtFree(workspaceAddr3);
474+ }
475+ // 15. Release device resources used by the ObfuscationSetup API
476+ aclrtDestroyStream(stream);
477+ aclrtResetDevice(deviceId);
478+ aclFinalize();
479+ 
480+ return 0;
481+}
482+ 
483+```
@@ -3,7 +3,7 @@
3## 产品支持情况3## 产品支持情况
4 4 
5<!-- npu="950" id1 -->5<!-- npu="950" id1 -->
6-- <term>Ascend 950PR/Ascend 950DT</term>:不支持6+- <term>Ascend 950PR&950DT系列产品</term>:不支持
7<!-- end id1 -->7<!-- end id1 -->
8<!-- npu="A3" id2 -->8<!-- npu="A3" id2 -->
9- <term>Atlas A3 训练系列产品/Atlas A3 推理系列产品</term>:不支持9- <term>Atlas A3 训练系列产品/Atlas A3 推理系列产品</term>:不支持
@@ -3,7 +3,7 @@
3## 产品支持情况3## 产品支持情况
4 4 
5<!-- npu="950" id1 -->5<!-- npu="950" id1 -->
6-- <term>Ascend 950PR/Ascend 950DT</term>:不支持6+- <term>Ascend 950PR&950DT系列产品</term>:不支持
7<!-- end id1 -->7<!-- end id1 -->
8<!-- npu="A3" id2 -->8<!-- npu="A3" id2 -->
9- <term>Atlas A3 训练系列产品/Atlas A3 推理系列产品</term>:不支持9- <term>Atlas A3 训练系列产品/Atlas A3 推理系列产品</term>:不支持
@@ -0,0 +1,538 @@
1+# aclnnObfuscationSetupV2
2+ 
3+## Product Support
4+ 
5+<!-- npu="950" id1 -->
6+- <term>Ascend 950PR&950DT products</term>: Not supported
7+<!-- end id1 -->
8+<!-- npu="A3" id2 -->
9+- <term>Atlas A3 products</term>: Not supported
10+<!-- end id2 -->
11+<!-- npu="910b" id3 -->
12+- <term>Atlas A2 products</term>: Supported
13+<!-- end id3 -->
14+<!-- npu="310b" id4 -->
15+- <term>Atlas 200I/500 A2 inference products</term>: Not supported
16+<!-- end id4 -->
17+<!-- npu="310p" id5 -->
18+- <term>Atlas inference products</term>: Supported
19+<!-- end id5 -->
20+<!-- npu="910" id6 -->
21+- <term>Atlas training products</term>: Not supported
22+<!-- end id6 -->
23+ 
24+## Function Description
25+ 
26+- API function: initializes and releases resources for the PMCC model obfuscation engine.
27+ 
28+ - Resource initialization: establishes a socket connection with the PMCC obfuscation engine CA, initializes the CA and TA, and returns the socket connection descriptor.
29+ - Resource release: disconnects the socket connection with the PMCC obfuscation engine CA.
30+ 
31+- Background: The PMCC (Privacy and Model Confidential Computing) model obfuscation feature uses the TrustZone trusted execution environment in CPU cores to isolate and store obfuscation factors, derive obfuscation masks, and perform dynamic mask addition. Based on the NPU TrustZone, the PMCC builds the model obfuscation engine CA (Client Application in the general OS) and the model obfuscation engine TA (Trusted Application in the TEE OS). To enable the model to access the model obfuscation engine TA during inference execution, the AICPU operator mechanism and the on-card localhost socket of the NPU are used for relay. This API adds the obfCoefficient parameter. In the full-specification DeepSeek version, an obfuscation coefficient is added to ensure that the model obfuscation performance meets the requirements. Input data is processed according to the obfuscation coefficient ratio.
32+ 
33+## Function Prototype
34+ 
35+Each operator uses a [two-phase API](../../../docs/en/context/two_phase_api.md). Call the "aclnnObfuscationSetupV2GetWorkspaceSize" API to obtain the required workspace size and the executor that contains the operator computation flow, and then call the "aclnnObfuscationSetupV2" API to execute the computation.
36+ 
37+```c++
38+aclnnStatus aclnnObfuscationSetupV2GetWorkspaceSize(
39+ int32_t fdToClose,
40+ int32_t dataType,
41+ int32_t hiddenSize,
42+ int32_t tpRank,
43+ int32_t modelObfSeedId,
44+ int32_t dataObfSeedId,
45+ int32_t cmd,
46+ int32_t threadNum,
47+ float obfCoefficient,
48+ aclTensor *fd,
49+ uint64_t *workspaceSize,
50+ aclOpExecutor **executor)
51+```
52+ 
53+```c++
54+aclnnStatus aclnnObfuscationSetupV2(
55+ void *workspace,
56+ uint64_t workspaceSize,
57+ aclOpExecutor *executor,
58+ aclrtStream stream)
59+```
60+ 
61+## aclnnObfuscationSetupV2GetWorkspaceSize
62+ 
63+- **Parameter Description**
64+ <table style="undefined;table-layout: fixed; width: 1452px"><colgroup>
65+ <col style="width: 174px">
66+ <col style="width: 121px">
67+ <col style="width: 253px">
68+ <col style="width: 361px">
69+ <col style="width: 213px">
70+ <col style="width: 110px">
71+ <col style="width: 110px">
72+ <col style="width: 110px">
73+ </colgroup>
74+ <thead>
75+ <tr>
76+ <th>Parameter</th>
77+ <th>Input/Output</th>
78+ <th>Description</th>
79+ <th>Usage</th>
80+ <th>Data Type</th>
81+ <th>Data Format</th>
82+ <th>Shape</th>
83+ <th>Non-contiguous Tensor</th>
84+ </tr></thead>
85+ <tbody>
86+ <tr>
87+ <td>fdToClose (int32_t)</td>
88+ <td>Input</td>
89+ <td>Socket connection descriptor to be closed.</td>
90+ <td>When cmd is set to 3, enter the fd returned by this operator when cmd is set to 1. Otherwise, enter 0.</td>
91+ <td>INT32</td>
92+ <td>-</td>
93+ <td>-</td>
94+ <td>-</td>
95+ </tr>
96+ <tr>
97+ <td>dataType (int32_t)</td>
98+ <td>Input</td>
99+ <td>ID representing the tensor data type.</td>
100+ <td>
@@ -0,0 +1,526 @@
1+# aclnnObfuscationSetup
2+ 
3+## Product Support
4+ 
5+<!-- npu="950" id1 -->
6+- <term>Ascend 950PR&950DT products</term>: Not supported
7+<!-- end id1 -->
8+<!-- npu="A3" id2 -->
9+- <term>Atlas A3 products</term>: Not supported
10+<!-- end id2 -->
11+<!-- npu="910b" id3 -->
12+- <term>Atlas A2 products</term>: Supported
13+<!-- end id3 -->
14+<!-- npu="310b" id4 -->
15+- <term>Atlas 200I/500 A2 inference products</term>: Not supported
16+<!-- end id4 -->
17+<!-- npu="310p" id5 -->
18+- <term>Atlas inference products</term>: Supported
19+<!-- end id5 -->
20+<!-- npu="910" id6 -->
21+- <term>Atlas training products</term>: Not supported
22+<!-- end id6 -->
23+ 
24+## Function Description
25+ 
26+- API function: initializes and releases resources for the PMCC model obfuscation engine.
27+ 
28+ - Resource initialization: establishes a socket connection with the PMCC obfuscation engine CA, initializes the CA and TA, and returns the socket connection descriptor.
29+ - Resource release: disconnects the socket connection with the PMCC obfuscation engine CA.
30+ 
31+- Background: The PMCC (Privacy and Model Confidential Computing) model obfuscation feature uses the TrustZone trusted execution environment in CPU cores to isolate and store obfuscation factors, derive obfuscation masks, and perform dynamic mask addition. Based on the NPU TrustZone, the PMCC builds the model obfuscation engine CA (Client Application in the general OS) and the model obfuscation engine TA (Trusted Application in the TEE OS). To enable the model to access the model obfuscation engine TA during inference execution, the AICPU operator mechanism and the on-card localhost socket of the NPU are used for relay.
32+ 
33+## Function Prototype
34+ 
35+Each operator uses a [two-phase API](../../../docs/en/context/two_phase_api.md). Call the "aclnnObfuscationSetupGetWorkspaceSize" API to obtain the required workspace size and the executor that contains the operator computation flow, and then call the "aclnnObfuscationSetup" API to execute the computation.
36+ 
37+```c++
38+aclnnStatus aclnnObfuscationSetupGetWorkspaceSize(
39+ int32_t fdToClose,
40+ int32_t dataType,
41+ int32_t hiddenSize,
42+ int32_t tpRank,
43+ int32_t modelObfSeedId,
44+ int32_t dataObfSeedId,
45+ int32_t cmd,
46+ int32_t threadNum,
47+ aclTensor *fd,
48+ uint64_t *workspaceSize,
49+ aclOpExecutor **executor)
50+```
51+ 
52+```c++
53+aclnnStatus aclnnObfuscationSetup(
54+ void *workspace,
55+ uint64_t workspaceSize,
56+ aclOpExecutor *executor,
57+ aclrtStream stream)
58+```
59+ 
60+## aclnnObfuscationSetupGetWorkspaceSize
61+ 
62+- **Parameter Description**
63+ 
64+ <table style="undefined;table-layout: fixed; width: 1452px"><colgroup>
65+ <col style="width: 174px">
66+ <col style="width: 121px">
67+ <col style="width: 253px">
68+ <col style="width: 361px">
69+ <col style="width: 213px">
70+ <col style="width: 110px">
71+ <col style="width: 110px">
72+ <col style="width: 110px">
73+ </colgroup>
74+ <thead>
75+ <tr>
76+ <th>Parameter</th>
77+ <th>Input/Output</th>
78+ <th>Description</th>
79+ <th>Usage</th>
80+ <th>Data Type</th>
81+ <th>Data Format</th>
82+ <th>Shape</th>
83+ <th>Non-contiguous Tensor</th>
84+ </tr></thead>
85+ <tbody>
86+ <tr>
87+ <td>fdToClose (int32_t)</td>
88+ <td>Input</td>
89+ <td>Socket connection descriptor to be closed.</td>
90+ <td>When cmd is set to 3, enter the fd returned by this operator when cmd is set to 1. Otherwise, enter 0.</td>
91+ <td>INT32</td>
92+ <td>-</td>
93+ <td>-</td>
94+ <td>-</td>
95+ </tr>
96+ <tr>
97+ <td>dataType (int32_t)</td>
98+ <td>Input</td>
99+ <td>ID representing the tensor data type.</td>
100+ <td>