Hello GPU 学习\qquad对应Task 0 章节对应Jupyter Notebook中的Chapter 0和Chapter 1Task 0:\qquad对应内容为第 1 章・环境准备学习时间安排在第 1–3 天建议用时 3 天截止时间为第 3 天结束前当前状态为待安排。学习内容包含四项一是了解课程结构找到教程和实验环境指南二是确认显卡、系统及 ROCm 环境三是完成依赖同步与环境激活四是跑通教程中的最小示例。打卡要求为提交一张运行成功截图附上显卡型号及环境配置中的问题没有问题可写 “无”。运行效果截图★在 AMD Radeon Cloud 上把%%hip编通实测走通的完整修法报错是套了三层的别被最外层骗了CalledProcessError: Command [ninja,-v] returned non-zero exit status 1 └─ RuntimeError: HIP compilation failed. ... Full output: build.log └─ FAILED: [code1] kernel_hip.cuda.o ← ninja 的摘要行不是原因 └─ hello_gpu_generated_wrapper:34:21: error: no type named HIPGuardMasqueradingAsCUDA in namespace c10::hip ← 真正的原因kernel.hiptemplates/header.hip 你的 kernel templates/binary_f32.hipbinary_f32.hip第 3 行有#line 1 hello_gpu_generated_wrapper所以报错行号 34 / 46 换算回该文件正是第 37 / 49 行两处 guard。这台镜像的 torch 到底提供什么实测查过torch/include这段是判断一切的依据类型定义在哪有吗c10::hip::HIPGuardc10/hip/HIPGuard.h✅c10::hip::HIPGuardMasqueradingAsCUDA——❌不存在最初报错的根因c10::cuda::CUDAGuardc10/cuda/CUDAGuard.h✅模板里那句注释// ROCm PyTorch keeps the public CUDA namespace in HIPGuard.h.是说只 includec10/hip/HIPGuard.h就能顺带拿到c10::cuda::CUDAGuard——这在教程那台 torch 上成立在这台不成立所以还得显式 include 那一行。四步修法顺序别颠倒第 ③ 步最反直觉、也最容易漏。每格都是单行/零缩进Jupyter 里直接粘贴运行①确认模板是新版guard 写法应为c10::cuda::CUDAGuardimporthello_gpu,pathlib;tpathlib.Path(hello_gpu.__file__).parent/templates;s(t/binary_f32.hip).read_text();print(旧写法,s.count(HIPGuardMasqueradingAsCUDA),| 新写法,s.count(c10::cuda::CUDAGuard),| hello_gpu ,hello_gpu.__file__)期望旧写法 0 | 新写法 2且hello_gpu /workspace/notebooks/common/src/hello_gpu/__init__.py。若旧写法不是 0→ 用仓库里的同名文件覆盖云上那份。②给header.hip补一行 include幂等跑两次也只加一次importhello_gpu,pathlib;tpathlib.Path(hello_gpu.__file__).parent/templates/header.hip;Lt.read_text().splitlines();A[]ifany(c10/cuda/CUDAGuard.hinlforlinL)else[#include c10/cuda/CUDAGuard.h];t.write_text(\n.join(LA)\n);print(新补的 include 行数 ,len(A))③ ★删掉构建缓存importshutil,pathlib;Bpathlib.Path(/workspace/notebooks/.artifacts/build);shutil.rmtree(B,ignore_errorsTrue);print(已清空 ,B,| 还存在吗 ,B.exists())为什么非删不可编译器实际吃的不是kernel.hip而是它 hipify 出来的副本kernel_hip.hip看原始报错的-c .../kernel_hip.hip。第一次失败留下那份副本不会跟着模板刷新→ 于是kernel.hip明明已是新版build.log里却永远抄着旧报错怎么改都没反应。只改模板不清缓存 白改。④只编自己这张卡镜像预置了 9 个架构gfx90a…gfx1151hip.py:_target_architecture()会原样采用importos,torch;os.environ[PYTORCH_ROCM_ARCH]torch.cuda.get_device_properties(0).gcnArchName.split(:)[0];print(编译目标架构,os.environ[PYTORCH_ROCM_ARCH])W7900D 应打印gfx1100。顺带把编译时间从 9 倍压回 1 倍。然后重跑%%hip那一格即可不用重启内核模板每次编译现读→ 应看到smoke_add · 编译完成 · x.xx s · 现在可以用 smoke_add(a, b) 调用。