Files
derek.holloway 7502bf64a4
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
Flatten subprojects into a single base monorepo
2026-09-02 16:34:47 -07:00
..

Scratch Memory

Overview

This example stress-tests GPU scratch memory allocation by launching kernels with varying per-thread local memory requirements - small (8 bytes), medium (~700 bytes), and large (~16 KB). It exercises transitions between primary scratch slots and secondary/overflow (USO) allocations by filling primary slots with medium kernels and then launching large kernels that require additional scratch. The program also scales grid dimensions to trigger scratch memory pressure. This is useful for profiling scratch memory allocation events and understanding GPU resource management under memory contention.

Source Files

  • scratch-memory.cpp - Defines three kernels (test_kern_small, test_kern_medium, test_kern_large) with different local array sizes, plus test orchestration functions (test_primary_then_uso, test_gridx, test_scratch) that drive scratch memory allocation scenarios.

Prerequisites

  • CMake 3.25+
  • HIP runtime and hipcc compiler
  • HSA runtime library

Building

Standalone build:

cmake -B <build_dir> -S <project_root>/examples/scratch_memory -DCMAKE_PREFIX_PATH=/opt/rocm
cmake --build <build_dir>

As part of the examples suite:

cmake -B <build_dir> -S <project_root>/examples/ -DCMAKE_PREFIX_PATH=/opt/rocm
cmake --build <build_dir> --target scratch-memory

Running

./scratch-memory

No command-line arguments. The program iterates through all detected GPU agents and runs a fixed set of scratch memory test scenarios.

Profiling with rocprofiler-systems

rocprof-sys-run -- ./scratch-memory
Variable Value Purpose
ROCPROFSYS_ROCM_DOMAINS hip_api,hsa_api,kernel_dispatch,scratch_memory Trace HIP/HSA API and scratch memory events
ROCPROFSYS_ROCM_EVENTS SQ_WAVES Sample GPU wave occupancy
ROCPROFSYS_TRACE true Generate Perfetto trace
rocprof-sys-run \
    -e ROCPROFSYS_ROCM_DOMAINS=hip_api,hsa_api,kernel_dispatch,scratch_memory \
    -e ROCPROFSYS_TRACE=true \
    -- ./scratch-memory