已合并
更新极简样例资料和工程 #620
更新极简样例资料和工程 #620
已合并
lileizheng创建于 1月4日
lileizheng成员
1月4日

描述

1、更新极简样例资料和工程
2、新增add算子的调用样例

关联的Issue

测试

文档更新

类型标签

likedislike
Pull Request已成功合入, 合并人@CANN-robot
(感谢 lileizheng 的贡献)
CANN-robot
CANN-robot成员
1月4日 评论:

Thank your for your pull-request.

The full list of commands accepted by me can be found at here.

You can get sig-info at here

likedislike
CANN-robot
CANN-robot成员
1月4日 评论:

以下是根据您提交的修改文件推荐的Reviewer和Committer序列,需各模块评审通过后方可合入

Module List Reviewers Committers
sig-ops-nn fanqirui, FelixTang7, zhangyuxiang0119, zhou-qilong, lileizheng tangweiwei2, chenqi317, liubo75, crystalhu
likedislike
CANN-robotCANN-robot成员
1月4日 将crystalhu,chenqi317,liubo75,tangweiwei2设为审查人
CANN-robotCANN-robot成员
1月4日 添加了label:cann-cla/yes
CANN-robot
CANN-robot成员
1月4日 评论:

CLA Signature Pass

Thanks for your pull request. All authors of the commits have signed the CLA. 👍

likedislike
CANN-robot
CANN-robot成员
1月4日 评论:

🔵 source code change are detected, tasks labels is removed in this pull request!

likedislike
CANN-robot
CANN-robot成员1月4日进行代码检视1
examples/fast_kernel_launch_example/ascend_ops/__init__.py
@@ -1,1 +1,2 @@
11#!/usr/bin/env python3
2-# -*- coding: UTF-8 -*-
2+# -*- coding: utf-8 -*-
CANN-robot
CANN-robot1月4日评论:

代码可读性: 编码声明从'UTF-8'改为'utf-8',虽然两者在功能上等价,但在Python中推荐使用小写'utf-8',因为这是Python官方文档和PEP 263中使用的标准形式。这种不一致性可能会影响代码的统一性和可读性。

问题类型: 代码可读性
文件路径: examples/fast_kernel_launch_example/ascend_ops/__init__.py
行号: 2
问题代码:

# -*- coding: utf-8 -*-

修改建议:

建议保持编码声明的一致性,如果项目中其他文件使用小写'utf-8',则此修改是正确的;如果项目中其他文件使用大写'UTF-8',则应该统一为大写形式。建议检查项目中其他文件的编码声明,确保一致性。

此评论由代码审查工具自动生成

likedislike
CANN-robot
CANN-robot成员1月4日进行代码检视1
examples/fast_kernel_launch_example/ascend_ops/__init__.py
@@ -11,3 +11,3 @@
1111# ----------------------------------------------------------------------------
1212 
13-from pathlib import Path
13+"""Ascend Ops"""
CANN-robot
CANN-robot1月4日评论:

注释与文档: 新增了模块文档字符串'"""Ascend Ops"""',这是一个好的实践,但文档字符串内容过于简单,没有提供足够的模块信息。对于Ascend Ops这样的重要模块,应该提供更详细的文档说明。

问题类型: 注释与文档
文件路径: examples/fast_kernel_launch_example/ascend_ops/__init__.py
行号: 13
问题代码:

"""Ascend Ops"""

修改建议:

建议扩展模块文档字符串,至少包含以下内容:1) 模块的主要功能和用途;2) 主要提供的类和函数;3) 使用示例或快速入门指南;4) 相关的依赖和安装要求。例如:"""Ascend Ops - Huawei Ascend AI处理器的高性能算子库。提供针对Ascend芯片优化的PyTorch算子扩展。"""

此评论由代码审查工具自动生成

likedislike
CANN-robot
CANN-robot成员1月4日进行代码检视1
examples/fast_kernel_launch_example/ascend_ops/__init__.py
@@ -15,2 +16,2 @@
15-from . import _C
16-from . import ops
16+ 
17+try:
CANN-robot
CANN-robot1月4日评论:

错误处理与异常管理: 新增了try-except块来捕获_C模块的导入错误,这是一个良好的错误处理实践。但是错误消息'Cannot import _C. Please make sure the ascend_ops is properly installed.'过于通用,没有提供具体的解决建议。

问题类型: 错误处理与异常管理
文件路径: examples/fast_kernel_launch_example/ascend_ops/__init__.py
行号: 17
问题代码:

try:
    from . import _C
except ImportError as e:
    raise ImportError(
        "Cannot import _C. Please make sure the `ascend_ops` is properly installed. "
    ) from e

修改建议:

建议改进错误消息,提供更具体的解决建议,例如:1) 检查是否已正确编译和安装扩展;2) 提供编译和安装的文档链接;3) 建议检查Python版本和PyTorch版本的兼容性。例如:"Cannot import _C extension module. This usually means the ascend_ops package was not properly built. Please ensure you have built the extension with 'python setup.py build_ext --inplace' or installed the package via pip."

此评论由代码审查工具自动生成

likedislike
CANN-robot
CANN-robot成员1月4日进行代码检视1
examples/fast_kernel_launch_example/ascend_ops/__init__.py
@@ -12,2 +12,3 @@
1212 
13-from pathlib import Path
13+"""Ascend Ops"""
14+__version__ = "1.0.0"
CANN-robot
CANN-robot1月4日评论:

变量命名: 新增了__version__ = "1.0.0",这是一个好的实践,但版本号硬编码为字符串字面量。如果项目使用集中化的版本管理(如通过setup.py或pyproject.toml),这种硬编码可能导致版本不一致。

问题类型: 变量命名
文件路径: examples/fast_kernel_launch_example/ascend_ops/__init__.py
行号: 14
问题代码:

__version__ = "1.0.0"

修改建议:

建议考虑从单一源获取版本号,例如:1) 从setup.py或pyproject.toml导入;2) 使用importlib.metadata读取已安装包的版本;3) 或者至少确保此处的版本号与项目其他地方的版本声明保持一致。

此评论由代码审查工具自动生成

likedislike
CANN-robot
CANN-robot成员1月4日进行代码检视1
examples/fast_kernel_launch_example/csrc/add/ascend910b/add.cpp
@@ -0,0 +34,4 @@
34+// Meta function implementation of Add
35+torch::Tensor add_meta(const torch::Tensor &x, const torch::Tensor &y)
36+{
37+ TORCH_CHECK(x.sizes() == y.sizes(), "The shapes of x and y must be the same.");
CANN-robot
CANN-robot1月4日评论:

错误处理: add_meta函数中只检查了x和y的sizes是否相等,但没有检查它们的dtype是否兼容。虽然kernel通过AT_DISPATCH_SWITCH处理不同类型,但如果x和y的dtype不同,结果可能不正确。

问题类型: 错误处理
文件路径: examples/fast_kernel_launch_example/csrc/add/ascend910b/add.cpp
行号: 37
问题代码:

TORCH_CHECK(x.sizes() == y.sizes(), "The shapes of x and y must be the same.");

修改建议:

添加dtype检查:`TORCH_CHECK(x.scalar_type() == y.scalar_type(), "The dtypes of x and y must be the same.");` 或者考虑类型提升逻辑。

此评论由代码审查工具自动生成

likedislike
CANN-robot
CANN-robot成员
1月4日 评论:

问题/功能描述

本次PR对昇腾NPU算子开发示例项目的构建系统进行了全面重构与功能增强。主要解决了原有CMake配置复杂冗长、不易维护和扩展,以及缺少标准化测试验证的问题。通过引入模块化构建系统、新增高性能算子示例和完善测试框架,旨在提升算子开发效率、项目可维护性及代码质量。

修改方案描述

重构了项目的构建系统,将单体CMakeLists.txt拆分为多个模块化配置文件(如ascend.cmake, torch.cmake),并引入对象文件列表机制来简化算子编译流程。新增了针对Ascend 910B的高性能张量加法算子示例,展示了利用AscendC流水线技术的实现。同时,完善了Python扩展模块的初始化机制,重构了setup.py以支持生成ABI3兼容的wheel包,并新增了参数化的单元测试(test_add.py)来验证自定义算子的功能正确性。

likedislike
lileizheng成员
1月4日 评论:

compile

likedislike
CANN-robot
CANN-robot成员
1月4日 评论:

🔵 ops-nn pipeline is running. Please wait a moment... (Link 2419)
🔵 Already succeed task list is: [Anti_Virus], will not be build again this time !

likedislike
CANN-robotCANN-robot成员
1月4日 添加了label:ci-pipeline-running
CANN-robot
CANN-robot成员
1月4日 评论:
Check Name Build Result Log Report Package Link
CI_Ascend_Ops-Nn_Compile SUCCESS #2419 >>>
check-commit-message SUCCESS >>>
download-business-code SUCCESS >>>
Compile_Ascend_X86 SUCCESS >>> >>>
Compile_Ascend_ARM SUCCESS >>> >>>
Compile_Ascend_ARM-single SUCCESS >>> >>>
Check_pr SUCCESS >>>
UT_Test_ophost SUCCESS >>>
UT_Test_opapi SUCCESS >>>
UT_Test_kernel SUCCESS >>>
Smoke_Test_A900 SUCCESS >>>
likedislike
CANN-robot
CANN-robot成员
1月4日 评论:
Check Name Build Result Log Report Package Link
Anti Virus ✅ PASS >>> N/A
Codescan ✅ PASS >>> N/A
Code_Check ✅ PASS >>> N/A
likedislike
CANN-robotCANN-robot成员
1月4日 删除了label:ci-pipeline-running
CANN-robotCANN-robot成员
1月4日 添加了label:ci-pipeline-passed
Llileizheng成员
1月4日 关联了issue:[Documentation|文档反馈]: 更新极简调用的工程和资料
范其瑞
范其瑞成员
1月4日 评论:

/lgtm

likedislike
chenqi317成员
1月5日 评论:

/approve

likedislike
CANN-robotCANN-robot成员
1月5日 添加了label:lgtmapproved
CANN-robot
CANN-robot成员
1月5日 评论:

Review Guide

This Pull-Request Passes Review.
Committers who writed a comment of /approve are: chenqi317.
Reviewers who writed a comment of /lgtm are: fanqirui, chenqi317.

likedislike
CANN-robotCANN-robot成员
1月5日 合入了pull request