已关闭
[Documentation|文档反馈]: 快速入门的文档无法快速上手 #1777
wangkai创建于  26 天前关闭于  6 天前
wangkai成员
26 天前 创建

Thanks for sending an issue! Please fill in the following template to help quickly solve your problem.

Document Link(文档链接)

https://gitcode.com/cann/asc-devkit/blob/master/docs/zh/guide/getting_started/quick_start/simd_programming/hello_world.md

Issues Section(问题文档片段)

Hello World功能介绍:

在NPU上打印Hello World!!!。

Device端核函数(Kernel)实现:

后缀名为*.asc的代码文件包含Host端与Device端代码,其Device端部分示例如下:

global vector void hello_world()
{
printf("Hello World!!!\n");
}
说明
SIMD算子的核函数(Kernel)需要额外的修饰符,如__vector__修饰符说明该算子仅在向量计算单元上执行。
Host端代码实现:

Host端通过<<<>>>语法糖调用Device端代码片段。

int main(int argc, char const* argv[])
{
...
constexpr uint32_t numBlocks = 8;
...

aclrtStream stream = nullptr;
aclrtCreateStream(&stream);
// Launch kernel <<<numBlocks, dynUBufSize, stream>>>
// numBlocks : Number of blocks. Default to 8 in this example.
// dynUBufSize : Dynamic unified buffer size. Default to 0 in this example.
// stream : Runtime stream. Uses stream created by aclrtCreateStream API in this example.
hello_world<<<numBlocks, 0, stream>>>();
...

}

Existing Issues(存在的问题)

1、host、kernel实现放到2个代码块,无法一次性拷贝保存文件
2、代码样例拷贝后无法编译通过,里面一些列...

参考9.0.0的时候,代码片段1次拷贝源码,1次拷贝编译命令就可以执行,当前退步严重

likedislike
Wwangkai成员
26 天前 添加了label:documentation
liuliu876成员
25 天前 评论:

感谢反馈!关于您的问题,补充说明如下:

  1. 文档开头已提供完整可运行样例链接
    hello_world.md 开头"开始前请参考…"一句中,已给出"完整样例请参考 hello_world"的链接,并附"环境准备"链接。点击进入即可获得包含 hello_world.asc(Host+Device 完整实现)、CMakeLists.txt 与编译运行命令的完整工程,按 README 执行 cmake / make / ./demo 即可直接运行,无需手动拼接正文片段。这条路径覆盖了"从阅读到运行"的完整链路。

  2. 正文代码块的设计意图是讲解,而非可直接运行
    正文将 Device 端核函数与 Host 端调用拆为两个代码块,是为了聚焦讲解概念(vector 修饰符、<<<>>> 调用语法),便于读者理解每段作用,并非作为"拷贝即运行"的脚本。完整可运行版本统一收敛在 examples 样例仓中,这样既能保证讲解的清晰度,也避免文档与样例重复维护、出现不一致。因此只拷贝正文片段(缺少头文件、main 完整实现等)无法直接编译,属于文档与样例分离的预期行为,当前信息是完备的。

likedislike
Lliuliu876成员
25 天前 将 liuliu876 设为负责人
Lliuliu876成员
19 天前 关联了pull request:docs: add full HelloWorld sample code and build/run steps
liuliu876成员
19 天前 评论:

我们接纳您的意见,并在文档( https://gitcode.com/cann/asc-devkit/blob/master/docs/zh/guide/getting_started/quick_start/simd_programming/hello_world.md )中“算子编译与运行”这一章节中,附上了hello_world.asc的完整代码,可以直接拷贝后编译运行。修改PR:https://gitcode.com/cann/asc-devkit/pull/6487

likedislike
louyuxuan成员
10 天前 评论:

SIMT的hello world样例同步修改完成,在helloworld文档 中“算子编译与运行”这一章节中,附上了hello_world.asc的完整代码,修改PR:https://gitcode.com/cann/asc-devkit/pull/6507

likedislike
Lliuliu876成员
6 天前 issue状态由 进行中 改变为 已完成
Lliuliu876成员
6 天前 关闭了 issue
CANN-robotCANN-robot成员
6 天前 添加了label:resolved