Files
TheRock/rocm-systems/projects/rocprofiler-systems/examples/thread-limit/README.md
T
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

64 lines
2.0 KiB
Markdown

# Thread Limit
## Overview
This example stress-tests the threading subsystem by creating a large number of threads (up to 8000 by default) that each perform recursive Fibonacci computations. Threads are launched in batches matching the hardware concurrency level, with each batch completing before the next starts. The program reports average execution time per thread and total throughput, making it useful for profiling thread creation/destruction overhead, scheduler behavior, and profiler scalability under high thread counts.
## Source Files
- `thread-limit.cpp` - Implements batched thread creation using `std::thread`, each computing `fib(n)` recursively. Uses `std::mutex` to accumulate per-thread timing into a global total. `MAX_THREADS` is configurable at compile time (default 4000).
## Prerequisites
- CMake 3.25+
- C++ compiler with pthreads support
## Building
**Standalone build:**
```bash
cmake -B <build_dir> -S <project_root>/examples/thread-limit
cmake --build <build_dir>
```
**As part of the examples suite:**
```bash
cmake -B <build_dir> -S <project_root>/examples/
cmake --build <build_dir> --target thread-limit
```
## Running
```bash
# Default: fib(35), concurrency=ncpus, 8000 total threads
./thread-limit
# Custom: fib(30), 8 threads per batch, 2000 total
./thread-limit 30 8 2000
```
**Arguments:**
| Position | Description | Default |
| ---------- | ------------- | --------- |
| 1 | Fibonacci number to compute | 35 |
| 2 | Concurrency (threads per batch) | hardware_concurrency() |
| 3 | Total number of threads to launch | 2 * MAX_THREADS (8000) |
## Profiling with rocprofiler-systems
```bash
rocprof-sys-run -- ./thread-limit 30 4 500
```
### Recommended Configuration
| Variable | Value | Purpose |
| ---------- | ------- | --------- |
| `ROCPROFSYS_TRACE` | `true` | Generate Perfetto trace showing thread lifecycle |
| `ROCPROFSYS_PROFILE` | `true` | Generate call-stack profile |
| `ROCPROFSYS_USE_SAMPLING` | `ON` | Enable statistical sampling of thread stacks |
| `ROCPROFSYS_SAMPLING_FREQ` | `50` | Sampling frequency (interrupts/sec) |