ROCm 與 HIP 程式設計入門:實用教程
一份實用且現代的 AMD GPU 編程指南,內容涵蓋 ROCm 與 HIP。從完整的軟體堆疊、安裝流程、建構工作流、核心程式設計、記憶體管理、效能工程、函式庫使用、CUDA 遷移,到生產環境調試實務,全面解析。
課程總覽
📚 內容概要
一本實用且現代化的指南,介紹如何使用 ROCm 與 HIP 進行 AMD GPU 程式設計。內容涵蓋完整的軟體堆疊、安裝流程、建置工作流程、核心程式設計、記憶體管理、效能工程、函式庫使用、CUDA 移植,以及生產環境下的除錯實務。
透過這份技術深度解析,掌握 AMD GPU 程式設計與 CUDA 到 HIP 的可移植性。
作者: EvoClass
致謝: AMD 官方 ROCm 與 HIP 文件基礎,包括 ROCm、HIP 及 ROCm LLVM 等專案。
🎯 學習目標
- 用一句簡潔的句子定義 HIP 及其在 ROCm 生態系統中的角色。
- 区分 ROCm(平台)、HIP(介面)與 ROCm 函式庫(組成元件)。
- 識別從硬體到應用框架之間,ROCm 架構的層級結構。
- 定義 HIP SDK 與不同作業系統上 ROCm 平台的關係。
- 執行系統性的安裝流程,包含支援矩陣驗證與安裝後路徑設定。
- 編譯並執行一個最小化驗證程式,以排除常見的驅動程式與環境存取問題。
- 理解健全的建置策略對於調和原始碼可移植性與架構特定效能的重要性。
- 使用
hipLaunchKernelGGL宏來實現可移植的核心啟動,作為取代 CUDA 三重尖括號語法的替代方案。 - 設定針對特定 ROCm 架構的生產級 CMake 專案,並管理外部函式庫依賴。
- 解析 HIP 核心的組成結構,並套用基本的線程索引執行公式。
課程 共 10 课时 · 预计 30.0h
課程
Lesson
This lesson introduces the ROCm platform and the HIP programming model as a bridge for porting CUDA applications to AMD hardware. Students will learn how to use automated tools like hipify to migrate code while understanding the importance of architecture-aware tuning to achieve optimal performance.
This lesson covers the essential steps for installing and configuring the ROCm software stack, including dependency management, environment variable setup, and user permission requirements. Students will learn how to verify their system environment and ensure successful hardware-software communication through diagnostic tools and proper configuration.
This lesson explores the distinction between source portability and binary performance in the ROCm ecosystem, emphasizing that while HIP code is functionally portable, achieving peak throughput requires architecture-specific compilation. Students will learn to utilize the hipcc toolchain and CMake to manage build configurations that optimize code for specific hardware instruction sets.
This lesson introduces the HIP programming model, focusing on the transition from sequential CPU iteration to spatial GPU parallelism using the Parallel Pivot approach. Students will learn to map independent data tasks to thread grids, manage memory, and implement kernel execution with proper boundary checks and error handling.
AI024: Memory Management and Data Patterns (Lesson 5) explores the memory-centric nature of GPU performance, focusing on the Roofline Model and the critical importance of minimizing data movement between host and device. Students will learn to distinguish between memory-bound and compute-bound kernels while mastering strategies to optimize data residence and bandwidth utilization.
This lesson explores the transition from synchronous to asynchronous GPU execution, focusing on how to use HIP streams to decouple CPU and GPU tasks. Students will learn to optimize performance by implementing non-blocking memory transfers and kernel launches to maximize hardware utilization and eliminate execution bottlenecks.
This lesson introduces a systematic, data-driven approach to performance engineering on AMD GPUs, emphasizing the use of tools like rocprofv3 to identify bottlenecks rather than relying on intuition. Students will learn to follow a six-step scientific workflow to optimize memory access, instruction throughput, and hardware utilization while avoiding common performance "superstitions."
This lesson introduces the Library-First Engineering Principle, which emphasizes using optimized ROCm libraries like rocBLAS and rocFFT to reduce technical debt and ensure hardware portability. Students will learn to prioritize these vendor-tuned solutions over custom kernel development to achieve better performance and easier maintenance across evolving GPU architectures.
AI024: Porting CUDA Applications to HIP (Lesson 9) covers the systematic, incremental migration of CUDA code to the HIP platform using tools like HIPIFY-Clang and HIPIFY-Perl. Students will learn to distinguish between mechanical API translations and architectural optimizations, such as adjusting for warp-size differences, to ensure functional and performance parity on AMD ROCm hardware.
This lesson explores the GPU Developer’s Creed, which prioritizes functional correctness and architectural isolation over raw performance when working with ROCm and HIP. Students will learn to implement systematic debugging, testing, and CI/CD practices to ensure stable, reproducible, and accurate GPU kernel deployments.