CodeQL / Analyze (actions) (push) Canceled after 0s
CodeQL / Analyze (python) (push) Canceled after 0s
pre-commit / pre-commit (push) Canceled after 0s
Multi-Arch CI / setup (push) Canceled after 0s
Publish build_manylinux_x86_64 images / publish_build_manylinux_x86_64 (push) Canceled after 0s
Setup (Multi-Arch) / setup (push) Canceled after 0s
Multi-Arch CI / Linux::${{ fromJSON(needs.setup.outputs.linux_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubi10 image / publish_no_rocm_image_ubi10 (push) Canceled after 0s
Multi-Arch CI / Windows::${{ fromJSON(needs.setup.outputs.windows_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Multi-Arch CI / Manifest Diff (push) Canceled after 0s
TheRock Manifest Diff Report / Generate Manifest Diff Report (push) Canceled after 0s
Multi-Arch CI / CI Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_ocl_rt images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_rocgdb images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Unit Tests / Unit Tests :: ubuntu-24.04 (push) Canceled after 0s
Unit Tests / Unit Tests :: windows-2022 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_media (push) Canceled after 0s
Unit Tests / Unit Tests Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_openmpi (push) Canceled after 0s
86 lines
3.3 KiB
ReStructuredText
86 lines
3.3 KiB
ReStructuredText
.. meta::
|
|
:description: GPU programming patterns and tutorials
|
|
:keywords: AMD, ROCm, HIP, GPU, programming patterns, parallel computing, tutorial
|
|
|
|
.. _gpu_programming-patterns:
|
|
|
|
********************************************************************************
|
|
GPU programming patterns
|
|
********************************************************************************
|
|
|
|
GPU programming patterns are fundamental algorithmic structures that enable
|
|
efficient parallel computation on GPUs. Understanding these
|
|
patterns is essential for developers looking to effectively harness the massive parallel
|
|
processing capabilities of modern GPUs for scientific computing, machine learning,
|
|
image processing, and other computationally intensive applications.
|
|
|
|
These tutorials describe core programming patterns demonstrating how to
|
|
efficiently implement common parallel algorithms using the HIP runtime API and
|
|
kernel extensions. Each pattern addresses a specific computational challenge and
|
|
provides practical implementations with detailed explanations.
|
|
|
|
Common GPU programming challenges
|
|
==================================
|
|
|
|
GPU programming introduces unique challenges not present in traditional CPU
|
|
programming:
|
|
|
|
* **Memory coherence**: GPUs lack robust cache coherence mechanisms, requiring
|
|
careful coordination when multiple threads access shared memory.
|
|
|
|
* **Race conditions**: Concurrent memory access requires atomic operations or
|
|
careful algorithm design.
|
|
|
|
* **Irregular parallelism**: Real-world algorithms often have varying amounts of
|
|
parallel work across iterations.
|
|
|
|
* **CPU-GPU communication**: Data transfer overhead between host and device must
|
|
be minimized.
|
|
|
|
Tutorial overview
|
|
=================
|
|
|
|
This collection provides comprehensive tutorials on essential GPU programming
|
|
patterns:
|
|
|
|
* :doc:`Two-dimensional kernels <./programming-patterns/matrix_multiplication>`:
|
|
Processing grid-structured data such as matrices and images.
|
|
|
|
* :doc:`Stencil operations <./programming-patterns/stencil_operations>`:
|
|
Updating array elements based on neighboring values.
|
|
|
|
* :doc:`Atomic operations <./programming-patterns/atomic_operations_histogram>`:
|
|
Ensuring data integrity during concurrent memory access.
|
|
|
|
* :doc:`Multi-kernel applications <./programming-patterns/multikernel_bfs>`:
|
|
Coordinating multiple GPU kernels to solve complex problems.
|
|
|
|
* :doc:`CPU-GPU cooperation <./programming-patterns/cpu_gpu_kmeans>`: Strategic
|
|
work distribution between CPU and GPU.
|
|
|
|
Prerequisites
|
|
-------------
|
|
|
|
To get the most from these tutorials, you should have:
|
|
|
|
* Basic understanding of C/C++ programming.
|
|
|
|
* Familiarity with parallel programming concepts.
|
|
|
|
* HIP runtime environment installed (see :doc:`../install/install`).
|
|
|
|
* Basic knowledge of GPU architecture (recommended).
|
|
|
|
Getting started
|
|
---------------
|
|
|
|
Each tutorial is self-contained and can be studied independently, though we
|
|
recommend following the order presented for a comprehensive understanding:
|
|
|
|
1. **Start with Two-dimensional kernels** to understand basic GPU thread
|
|
organization and memory access patterns.
|
|
2. **Progress to stencil operations** to learn about neighborhood dependencies.
|
|
3. **Study atomic operations** to understand concurrent memory access.
|
|
4. **Explore multi-kernel programming** for complex algorithmic patterns.
|
|
5. **Check CPU-GPU cooperation** to handle mixed-parallelism workloads.
|