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
66 lines
2.2 KiB
Markdown
66 lines
2.2 KiB
Markdown
# Fork
|
|
|
|
## Overview
|
|
|
|
This example demonstrates profiling across process boundaries by forking child processes from worker threads. Each worker thread creates a child process via `fork()`, and each child spawns its own thread that sleeps for a variable duration before exiting. The parent process waits for all children using `waitpid()` with detailed exit status reporting. The entire workflow is annotated with rocprofiler-systems user API regions (`launch_child`, `child_process`, `child_process_child_thread`, `wait_for_children`) to show how profiling data is captured across `fork()` boundaries.
|
|
|
|
## Source Files
|
|
|
|
- `fork.cpp` - Implements barrier-synchronized thread-to-fork workflow with user API region annotations, child process management with `waitpid()`, and exit status decoding (`WIFEXITED`, `WIFSIGNALED`, etc.).
|
|
- `hipMallocConcurrencyMproc.cpp` - (Optional) HIP GPU memory allocation test across forked processes, built only when `hipcc` is available.
|
|
|
|
## Prerequisites
|
|
|
|
- CMake 3.25+
|
|
- C++ compiler with pthreads support
|
|
- rocprofiler-systems user library
|
|
- (Optional) HIP runtime for `hipMallocConcurrencyMproc`
|
|
|
|
## Building
|
|
|
|
**Standalone build:**
|
|
|
|
```bash
|
|
cmake -B build -DCMAKE_PREFIX_PATH=/opt/rocm
|
|
cmake --build build
|
|
```
|
|
|
|
**As part of the examples suite:**
|
|
|
|
```bash
|
|
cmake -B build -DCMAKE_PREFIX_PATH=/opt/rocm examples/
|
|
cmake --build build --target fork-example
|
|
```
|
|
|
|
## Running
|
|
|
|
```bash
|
|
# Default: 4 child processes, 1 cycle
|
|
./fork-example
|
|
|
|
# Custom: 8 children, 3 cycles
|
|
./fork-example 8 3
|
|
```
|
|
|
|
**Arguments:**
|
|
|
|
| Position | Description | Default |
|
|
| ---------- | ------------- | --------- |
|
|
| 1 | Number of child processes to fork | 4 |
|
|
| 2 | Number of fork/wait cycles to repeat | 1 |
|
|
|
|
## Profiling with rocprofiler-systems
|
|
|
|
```bash
|
|
rocprof-sys-run -- ./fork-example 4 2
|
|
```
|
|
|
|
### Recommended Configuration
|
|
|
|
| Variable | Value | Purpose |
|
|
| ---------- | ------- | --------- |
|
|
| `ROCPROFSYS_TRACE` | `true` | Generate Perfetto trace with cross-process events |
|
|
| `ROCPROFSYS_PROFILE` | `true` | Generate call-stack profile |
|
|
| `ROCPROFSYS_USE_SAMPLING` | `ON` | Sample call stacks in parent and child processes |
|
|
| `ROCPROFSYS_USE_PROCESS_SAMPLING` | `ON` | Enable process-level resource sampling |
|