已合并
modify document #45358
m0_68000167创建于 12 天前
modify document #45358
已合并
共 6 个文件变更+34-34
| @@ -14,9 +14,9 @@ | |||
| 14 | │ │ └── opapi # aclnn operator adapter directory | 14 | │ │ └── opapi # aclnn operator adapter directory |
| 15 | │ │ ├── AbsKernelNpuOpApi.cpp | 15 | │ │ ├── AbsKernelNpuOpApi.cpp |
| 16 | │ │ └── ... | 16 | │ │ └── ... |
| 17 | -| ├── python | 17 | +│ ├── python |
| 18 | -| │ └── meta | 18 | +│ │ └── meta |
| 19 | -| │ └── _meta_registrations.py # Operator meta implementation registration file | 19 | +│ │ └── _meta_registrations.py # Operator meta implementation registration file |
| 20 | │ ├── OpInterface.h # Auto-generated header file for op_plugin external interfaces (for framework-side operator invocation) | 20 | │ ├── OpInterface.h # Auto-generated header file for op_plugin external interfaces (for framework-side operator invocation) |
| 21 | │ ├── OpInterface.cpp # Auto-generated routing implementation for op_plugin external interfaces (internal branch selection logic for different operator types) | 21 | │ ├── OpInterface.cpp # Auto-generated routing implementation for op_plugin external interfaces (internal branch selection logic for different operator types) |
| 22 | │ ├── AclOpsInterface.h # Auto-generated header file for aclop operator plugin adapter | 22 | │ ├── AclOpsInterface.h # Auto-generated header file for aclop operator plugin adapter |
| @@ -28,8 +28,8 @@ | |||
| 28 | ├── test | 28 | ├── test |
| 29 | │ ├── allowlist_for_publicAPI.json # Public interface allowlist | 29 | │ ├── allowlist_for_publicAPI.json # Public interface allowlist |
| 30 | │ ├── core_tests | 30 | │ ├── core_tests |
| 31 | -│ | └── torch_npu_OpApi_schema_all.json # Operator interface schema configuration file | 31 | +│ │ └── torch_npu_OpApi_schema_all.json # Operator interface schema configuration file |
| 32 | -| └── test_custom_ops # Operator developer test directory | 32 | +│ └── test_custom_ops # Operator developer test directory |
| 33 | │ └── ... | 33 | │ └── ... |
| 34 | ``` | 34 | ``` |
| 35 | 35 | ||
| @@ -72,7 +72,7 @@ Parameters | |||
| 72 | 72 | ||
| 73 | - `all_version`: Indicates all versions supported by the current PyTorch. The version list will be adjusted as torch_npu evolves, and the actual code shall prevail. You can use `[]` to specify the version range supported by an operator. For example, `[v2.1, newest]` indicates that the operator supports versions from v2.1 to the latest. | 73 | - `all_version`: Indicates all versions supported by the current PyTorch. The version list will be adjusted as torch_npu evolves, and the actual code shall prevail. You can use `[]` to specify the version range supported by an operator. For example, `[v2.1, newest]` indicates that the operator supports versions from v2.1 to the latest. |
| 74 | - `official` and `custom`: Respectively indicate that operators under these fields are PyTorch native operators and custom operators. The `symint` field indicates that the operator supports symint-type input parameters. For such operators, refer to [Symint Operator Adaptation](#symint-operator-adaptation). | 74 | - `official` and `custom`: Respectively indicate that operators under these fields are PyTorch native operators and custom operators. The `symint` field indicates that the operator supports symint-type input parameters. For such operators, refer to [Symint Operator Adaptation](#symint-operator-adaptation). |
| 75 | -- `func`: Defines the operator schema (operator description specification). Its content fully follows the schema definition rules of PyTorch native Aten IR operators and completely describes the operator calling interface and semantic constraints through the structured form of "operator name + input parameter list + return parameter". For specific rules, refer to [PyTorch schema rules](reference.md#section001). | 75 | +- `func`: Defines the operator schema (operator description specification). Its content fully follows the schema definition rules of PyTorch native Aten IR operators and completely describes the operator calling interface and semantic constraints through the structured form of "operator name + input parameter list + return parameter". For specific rules, refer to [PyTorch schema rules](reference.md#pytorch-schema-rules). |
| 76 | - `acl_op`: Indicates that acl_op calls are supported in this version. If the supported versions are the same as the versions indicated by `all_version`, you can use `all_version` instead. This is an optional field. | 76 | - `acl_op`: Indicates that acl_op calls are supported in this version. If the supported versions are the same as the versions indicated by `all_version`, you can use `all_version` instead. This is an optional field. |
| 77 | - `op_api`: Indicates that op_api calls are supported in this version. If the supported versions are the same as the versions indicated by `all_version`, you can use `all_version` instead. This is an optional field. | 77 | - `op_api`: Indicates that op_api calls are supported in this version. If the supported versions are the same as the versions indicated by `all_version`, you can use `all_version` instead. This is an optional field. |
| 78 | - `gen_opapi`: For operators that support op_api calls, if the adaptation code is simple and the underlying operator can be called directly without additional adaptation, you can consider using structured adaptation to automatically generate the adaptation code. For details, see [(Optional) Structured Adaptation](#optional-structured-adaptation). | 78 | - `gen_opapi`: For operators that support op_api calls, if the adaptation code is simple and the underlying operator can be called directly without additional adaptation, you can consider using structured adaptation to automatically generate the adaptation code. For details, see [(Optional) Structured Adaptation](#optional-structured-adaptation). |
| @@ -224,7 +224,7 @@ The adaptation file path for aclnn operators is `op_plugin/ops/opapi/AbsKernelNp | |||
| 224 | ``` | 224 | ``` |
| 225 | 225 | ||
| 226 | > [!NOTE] | 226 | > [!NOTE] |
| 227 | - > For more common API interfaces used in operator adaptation, see [LINK](reference.md#section002). For more common macro definitions, see [LINK](reference.md#section003). | 227 | + > For more common API interfaces used in operator adaptation, see [LINK](reference.md#common-api-interfaces-for-operator-adaptation). For more common macro definitions, see [LINK](reference.md#common-macro-definitions-for-operator-adaptation). |
| 228 | 228 | ||
| 229 | 3. If the interface contains multiple variants, such as a variant with an `out` parameter or an in-place operation variant, you need to add the corresponding adaptation code. Refer to the following for adaptation: | 229 | 3. If the interface contains multiple variants, such as a variant with an `out` parameter or an in-place operation variant, you need to add the corresponding adaptation code. Refer to the following for adaptation: |
| 230 | 230 | ||
| @@ -455,7 +455,7 @@ aclop operators are an earlier operator implementation method and are not recomm | |||
| 455 | if (!npu_utils::check_match(&result)) { | 455 | if (!npu_utils::check_match(&result)) { |
| 456 | // If result is non-contiguous, create a contiguous tensor (contig_tensor) to receive the output of the ACLOP operator (abs). Then copy contig_tensor to the original output result | 456 | // If result is non-contiguous, create a contiguous tensor (contig_tensor) to receive the output of the ACLOP operator (abs). Then copy contig_tensor to the original output result |
| 457 | at::Tensor contiguous_result = npu_utils::format_contiguous(result); | 457 | at::Tensor contiguous_result = npu_utils::format_contiguous(result); |
| 458 | - abs_out_nocheck(contigTensor, self); | 458 | + abs_out_nocheck(ccontiguous_result, self); |
| 459 | npu_utils::format_fresh_view(result, contiguous_result); | 459 | npu_utils::format_fresh_view(result, contiguous_result); |
| 460 | } else { | 460 | } else { |
| 461 | // If result is contiguous, directly call the ACLOP operator | 461 | // If result is contiguous, directly call the ACLOP operator |
| @@ -34,7 +34,7 @@ After completing the development of the adaptation plugin for the PyTorch framew | |||
| 34 | Copy the following information to the `custom` node in `op_plugin_functions.yaml`. | 34 | Copy the following information to the `custom` node in `op_plugin_functions.yaml`. |
| 35 | 35 | ||
| 36 | ```yaml | 36 | ```yaml |
| 37 | - - func: npu_add_custom(Tensor x, Tensor y, *, Scalar alpha=1) -> Tensor | 37 | + - func: npu_add_custom(Tensor x, Tensor y, *, Scalar alpha=1) -> Tensor |
| 38 | op_api: v2.7 | 38 | op_api: v2.7 |
| 39 | - func: npu_add_custom_backward(Tensor grad) -> (Tensor, Tensor) | 39 | - func: npu_add_custom_backward(Tensor grad) -> (Tensor, Tensor) |
| 40 | op_api: v2.7 | 40 | op_api: v2.7 |
| @@ -44,7 +44,7 @@ After completing the development of the adaptation plugin for the PyTorch framew | |||
| 44 | 44 | ||
| 45 | ```yaml | 45 | ```yaml |
| 46 | custom: | 46 | custom: |
| 47 | - - func: npu_add_custom(Tensor x, Tensor y, *, Scalar alpha=1) -> Tensor | 47 | + - func: npu_add_custom(Tensor x, Tensor y, *, Scalar alpha=1) -> Tensor |
| 48 | op_api: v2.7 | 48 | op_api: v2.7 |
| 49 | - func: npu_add_custom_backward(Tensor grad) -> (Tensor, Tensor) | 49 | - func: npu_add_custom_backward(Tensor grad) -> (Tensor, Tensor) |
| 50 | op_api: v2.7 | 50 | op_api: v2.7 |
| @@ -81,7 +81,7 @@ After completing the development of the adaptation plugin for the PyTorch framew | |||
| 81 | 81 | ||
| 82 | ```yaml | 82 | ```yaml |
| 83 | custom: | 83 | custom: |
| 84 | - - func: npu_add_custom(Tensor x, Tensor y, *, Scalar alpha=1) -> Tensor | 84 | + - func: npu_add_custom(Tensor x, Tensor y, *, Scalar alpha=1) -> Tensor |
| 85 | op_api: v2.7 | 85 | op_api: v2.7 |
| 86 | gen_opapi: | 86 | gen_opapi: |
| 87 | out: | 87 | out: |
| @@ -102,8 +102,8 @@ After completing the development of the adaptation plugin for the PyTorch framew | |||
| 102 | 2. After completing the operator adaptation, the complete `AddCustomKernelNpuOpApi.cpp` file is as follows. | 102 | 2. After completing the operator adaptation, the complete `AddCustomKernelNpuOpApi.cpp` file is as follows. |
| 103 | 103 | ||
| 104 | ```cpp | 104 | ```cpp |
| 105 | - #include "op_plugin/OpApiInterface.h" | 105 | + #include "op_plugin/OpApiInterface.h" |
| 106 | - #include "op_plugin/utils/op_api_common.h" | 106 | + #include "op_plugin/utils/op_api_common.h" |
| 107 | 107 | ||
| 108 | namespace op_api { | 108 | namespace op_api { |
| 109 | using npu_preparation = at_npu::native::OpPreparation; | 109 | using npu_preparation = at_npu::native::OpPreparation; |
| @@ -117,7 +117,7 @@ After completing the development of the adaptation plugin for the PyTorch framew | |||
| 117 | // Call the EXEC_NPU_CMD interface to compute the output result | 117 | // Call the EXEC_NPU_CMD interface to compute the output result |
| 118 | // The format of the first input parameter is aclnn+Optype, and the subsequent parameters are the inputs and outputs respectively | 118 | // The format of the first input parameter is aclnn+Optype, and the subsequent parameters are the inputs and outputs respectively |
| 119 | EXEC_NPU_CMD(aclnnAdd, x, y, alpha, result); | 119 | EXEC_NPU_CMD(aclnnAdd, x, y, alpha, result); |
| 120 | - return result; | 120 | + return result; |
| 121 | } | 121 | } |
| 122 | 122 | ||
| 123 | // Backward interface | 123 | // Backward interface |
| @@ -4,10 +4,10 @@ | |||
| 4 | 4 | ||
| 5 | 通过此环境变量可控制是否启用MFusion融合优化功能。MFusion是一种针对NPU平台的图融合优化技术,能够自动融合多个算子为单一kernel,从而减少数据传输开销,提升整体计算性能。 | 5 | 通过此环境变量可控制是否启用MFusion融合优化功能。MFusion是一种针对NPU平台的图融合优化技术,能够自动融合多个算子为单一kernel,从而减少数据传输开销,提升整体计算性能。 |
| 6 | 6 | ||
| 7 | -- 配置为"0"或未配置时:禁用MFusion融合优化。 | 7 | +- 配置为“0”或未配置时:禁用MFusion融合优化。 |
| 8 | -- 配置为"1"时:启用MFusion融合优化。 | 8 | +- 配置为“1”时:启用MFusion融合优化。 |
| 9 | 9 | ||
| 10 | -此环境变量默认配置为"0"。 | 10 | +此环境变量默认配置为“0”。 |
| 11 | 11 | ||
| 12 | ## 配置示例 | 12 | ## 配置示例 |
| 13 | 13 | ||
| @@ -25,7 +25,7 @@ export TORCHINDUCTOR_ENABLE_MFUSION="1" | |||
| 25 | 25 | ||
| 26 | ## 使用约束 | 26 | ## 使用约束 |
| 27 | 27 | ||
| 28 | -- 该功能仅在torch.compile图编译后端为"Inductor"生效。 | 28 | +- 该功能仅在torch.compile图编译后端为“Inductor”生效。 |
| 29 | - 该功能仅在PyTorch2.7.1和2.9.0版本生效。 | 29 | - 该功能仅在PyTorch2.7.1和2.9.0版本生效。 |
| 30 | 30 | ||
| 31 | ## 支持的型号 | 31 | ## 支持的型号 |
| @@ -4,11 +4,11 @@ | |||
| 4 | 4 | ||
| 5 | 通过此环境变量可配置图模式(Inductor)下的后端优化策略,支持在Triton、MLIR、DVM等模式之间切换。 | 5 | 通过此环境变量可配置图模式(Inductor)下的后端优化策略,支持在Triton、MLIR、DVM等模式之间切换。 |
| 6 | 6 | ||
| 7 | -- 配置为"default"或未配置时:使用默认的Triton模式。 | 7 | +- 配置为“default”或未配置时:使用默认的Triton模式。 |
| 8 | -- 配置为"mlir"时:使用MLIR模式。 | 8 | +- 配置为“mlir”时:使用MLIR模式。 |
| 9 | -- 配置为"dvm"时:使用DVM模式。 | 9 | +- 配置为“dvm”时:使用DVM模式。 |
| 10 | 10 | ||
| 11 | -此环境变量默认配置为"default"。 | 11 | +此环境变量默认配置为“default”。 |
| 12 | 12 | ||
| 13 | ## 配置示例 | 13 | ## 配置示例 |
| 14 | 14 | ||
| @@ -14,9 +14,9 @@ | |||
| 14 | │ │ └── opapi # aclnn算子适配目录 | 14 | │ │ └── opapi # aclnn算子适配目录 |
| 15 | │ │ ├── AbsKernelNpuOpApi.cpp | 15 | │ │ ├── AbsKernelNpuOpApi.cpp |
| 16 | │ │ └── ... | 16 | │ │ └── ... |
| 17 | -| ├── python | 17 | +│ ├── python |
| 18 | -| │ └── meta | 18 | +│ │ └── meta |
| 19 | -| │ └── _meta_registrations.py # 算子meta实现注册文件 | 19 | +│ │ └── _meta_registrations.py # 算子meta实现注册文件 |
| 20 | │ ├── OpInterface.h # 编译自动生成OpPlugin对外接口的头文件,用于框架侧调用算子 | 20 | │ ├── OpInterface.h # 编译自动生成OpPlugin对外接口的头文件,用于框架侧调用算子 |
| 21 | │ ├── OpInterface.cpp # 编译自动生成OpPlugin对外接口路由实现,内部实现不同类型算子分支选择代码 | 21 | │ ├── OpInterface.cpp # 编译自动生成OpPlugin对外接口路由实现,内部实现不同类型算子分支选择代码 |
| 22 | │ ├── AclOpsInterface.h # 编译自动生成aclop算子插件适配所对应头文件 | 22 | │ ├── AclOpsInterface.h # 编译自动生成aclop算子插件适配所对应头文件 |
| @@ -28,8 +28,8 @@ | |||
| 28 | ├── test | 28 | ├── test |
| 29 | │ ├── allowlist_for_publicAPI.json # 对外公开接口白名单 | 29 | │ ├── allowlist_for_publicAPI.json # 对外公开接口白名单 |
| 30 | │ ├── core_tests | 30 | │ ├── core_tests |
| 31 | -│ | └── torch_npu_OpApi_schema_all.json # 算子接口schema配置文件 | 31 | +│ │ └── torch_npu_OpApi_schema_all.json # 算子接口schema配置文件 |
| 32 | -| └── test_custom_ops # 算子开发者测试目录 | 32 | +│ └── test_custom_ops # 算子开发者测试目录 |
| 33 | │ └── ... | 33 | │ └── ... |
| 34 | ``` | 34 | ``` |
| 35 | 35 | ||
| @@ -455,7 +455,7 @@ aclop算子是早期的算子实现方式,不推荐使用。适配文件路径 | |||
| 455 | if (!npu_utils::check_match(&result)) { | 455 | if (!npu_utils::check_match(&result)) { |
| 456 | // 若result非连续,创建连续tensor(contig_tensor),接收ACLOP算子(abs)的输出。再将contig_tensor拷贝到原始输出result。 | 456 | // 若result非连续,创建连续tensor(contig_tensor),接收ACLOP算子(abs)的输出。再将contig_tensor拷贝到原始输出result。 |
| 457 | at::Tensor contiguous_result = npu_utils::format_contiguous(result); | 457 | at::Tensor contiguous_result = npu_utils::format_contiguous(result); |
| 458 | - abs_out_nocheck(contigTensor, self); | 458 | + abs_out_nocheck(contiguous_result, self); |
| 459 | npu_utils::format_fresh_view(result, contiguous_result); | 459 | npu_utils::format_fresh_view(result, contiguous_result); |
| 460 | } else { | 460 | } else { |
| 461 | // 若result连续,直接调用ACLOP算子。 | 461 | // 若result连续,直接调用ACLOP算子。 |
| @@ -34,7 +34,7 @@ | |||
| 34 | 将如下信息拷贝至op\_plugin\_functions.yaml中的custom节点下。 | 34 | 将如下信息拷贝至op\_plugin\_functions.yaml中的custom节点下。 |
| 35 | 35 | ||
| 36 | ```yaml | 36 | ```yaml |
| 37 | - - func: npu_add_custom(Tensor x, Tensor y, *, Scalar alpha=1) -> Tensor | 37 | + - func: npu_add_custom(Tensor x, Tensor y, *, Scalar alpha=1) -> Tensor |
| 38 | op_api: v2.7 | 38 | op_api: v2.7 |
| 39 | - func: npu_add_custom_backward(Tensor grad) -> (Tensor, Tensor) | 39 | - func: npu_add_custom_backward(Tensor grad) -> (Tensor, Tensor) |
| 40 | op_api: v2.7 | 40 | op_api: v2.7 |
| @@ -44,7 +44,7 @@ | |||
| 44 | 44 | ||
| 45 | ```yaml | 45 | ```yaml |
| 46 | custom: | 46 | custom: |
| 47 | - - func: npu_add_custom(Tensor x, Tensor y, *, Scalar alpha=1) -> Tensor | 47 | + - func: npu_add_custom(Tensor x, Tensor y, *, Scalar alpha=1) -> Tensor |
| 48 | op_api: v2.7 | 48 | op_api: v2.7 |
| 49 | - func: npu_add_custom_backward(Tensor grad) -> (Tensor, Tensor) | 49 | - func: npu_add_custom_backward(Tensor grad) -> (Tensor, Tensor) |
| 50 | op_api: v2.7 | 50 | op_api: v2.7 |
| @@ -81,7 +81,7 @@ | |||
| 81 | 81 | ||
| 82 | ```yaml | 82 | ```yaml |
| 83 | custom: | 83 | custom: |
| 84 | - - func: npu_add_custom(Tensor x, Tensor y, *, Scalar alpha=1) -> Tensor | 84 | + - func: npu_add_custom(Tensor x, Tensor y, *, Scalar alpha=1) -> Tensor |
| 85 | op_api: v2.7 | 85 | op_api: v2.7 |
| 86 | gen_opapi: | 86 | gen_opapi: |
| 87 | out: | 87 | out: |
| @@ -102,8 +102,8 @@ | |||
| 102 | 2. 完成算子适配,完整的AddCustomKernelNpuOpApi.cpp文件如下。 | 102 | 2. 完成算子适配,完整的AddCustomKernelNpuOpApi.cpp文件如下。 |
| 103 | 103 | ||
| 104 | ```cpp | 104 | ```cpp |
| 105 | - #include "op_plugin/OpApiInterface.h" | 105 | + #include "op_plugin/OpApiInterface.h" |
| 106 | - #include "op_plugin/utils/op_api_common.h" | 106 | + #include "op_plugin/utils/op_api_common.h" |
| 107 | 107 | ||
| 108 | namespace op_api { | 108 | namespace op_api { |
| 109 | using npu_preparation = at_npu::native::OpPreparation; | 109 | using npu_preparation = at_npu::native::OpPreparation; |
| @@ -117,7 +117,7 @@ | |||
| 117 | // 调用EXEC_NPU_CMD接口,完成输出结果的计算 | 117 | // 调用EXEC_NPU_CMD接口,完成输出结果的计算 |
| 118 | // 第一个入参格式为aclnn+Optype,之后的参数分别为输入输出 | 118 | // 第一个入参格式为aclnn+Optype,之后的参数分别为输入输出 |
| 119 | EXEC_NPU_CMD(aclnnAdd, x, y, alpha, result); | 119 | EXEC_NPU_CMD(aclnnAdd, x, y, alpha, result); |
| 120 | - return result; | 120 | + return result; |
| 121 | } | 121 | } |
| 122 | 122 | ||
| 123 | // 反向接口 | 123 | // 反向接口 |