Measures per-kernel hot working sets, memory traffic, and FLOPs in MPI C/C++/Fortran codes for GPU memory planning. Uses Linux /proc/self/clear_refs and smaps, with optional PAPI and perf support.
Ships in Hot Memory. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them.
Hot Memory measures the hot working set of each kernel in an MPI application — the actual bytes touched during execution, not just total allocation. This is the key input for GPU memory planning.
It also measures memory traffic and FLOPs when hardware counters are available, giving FLOP/byte ratios that classify kernels as memory-bound or compute-bound.
Analysis model: MPI-only. OpenMP must be disabled or ignored. Build
with OpenMP disabled, or run with OMP_NUM_THREADS=1 and interpret results
as MPI-only. Hardware counters only measure the main thread; the hot-byte
measurement is process-wide. Mixed MPI+OpenMP runs do not produce consistent
metrics.
The target machine must have:
/proc/self/clear_refs and /proc/self/smapsmpicc, mpif90) and makelibpapi-dev) for FP and memory-traffic counting (optional: degrades
gracefully to 0 FLOPs if unavailable)perf (linux-tools-generic) for hotspot discovery (optional: Phase 2
is skipped if perf is unavailable)For the full feature set, an administrator may need to set:
sudo sysctl kernel.perf_event_paranoid=0
Hot-byte measurement (the core feature) works without this — it only needs
write access to /proc/self/clear_refs, which is available to regular users
on most Linux systems.
The profiler source is bundled with this skill in the wss_profiler/
directory next to this SKILL.md — it ships inside the
RIKEN-RCCS/hpc-agentic-sdk repository, so no download is needed. Copy it
into the project:
# <SKILL_DIR> = absolute path of the directory that contains this SKILL.md.
# The agent knows this path: it is the location it opened this skill from.
cp -r <SKILL_DIR>/wss_profiler wss_profiler
chmod +x wss_profiler/wss_check
Resolve <SKILL_DIR> to the absolute directory holding this SKILL.md
(e.g. .../.crush/skills/hot-memory, .../.claude/skills/hot-memory, or
wherever the skill was installed). The bundled wss_profiler/ contains
wss_profiler.h, wss_profiler.c, wss_profiler_f.c,
wss_profiler_mod.f90, wss_runtime_probe.c, wss_probe_fp_events.c,
and the wss_check script.
Fallback only if the bundled wss_profiler/ is absent (someone installed
just SKILL.md without the bundle) — fetch from the upstream mirror:
mkdir -p wss_profiler
BASE=https://raw.githubusercontent.com/william-dawson/hot-memory/main/wss_profiler
wget -P wss_profiler/ $BASE/wss_profiler.h
wget -P wss_profiler/ $BASE/wss_profiler.c
wget -P wss_profiler/ $BASE/wss_profiler_f.c
wget -P wss_profiler/ $BASE/wss_profiler_mod.f90
wget -P wss_profiler/ $BASE/wss_runtime_probe.c
wget -P wss_profiler/ $BASE/wss_probe_fp_events.c
wget -P wss_profiler/ $BASE/wss_check
chmod +x wss_profiler/wss_check
cd wss_profiler
mpicc -DPROFILE_WSS -c wss_profiler.c -o wss_profiler.o
mpicc -DPROFILE_WSS -c wss_profiler_f.c -o wss_profiler_f.o
mpif90 -c wss_profiler_mod.f90 -o wss_profiler_mod.o
ar rcs libwss_profiler.a wss_profiler.o wss_profiler_f.o wss_profiler_mod.o
cp wss_profiler_mod.mod . 2>/dev/null || true
gcc -O2 -o wss_probe_fp_events wss_probe_fp_events.c
mpicc -O2 -DPROFILE_WSS -o wss_runtime_probe wss_runtime_probe.c -L. -lwss_profiler -lpapi
cd ..
After this, wss_profiler/ contains libwss_profiler.a, the .h/.f90
source, the .mod file, and the diagnostic binaries. Instrumented code
links against this library:
-I<project>/wss_profiler -L<project>/wss_profiler -lwss_profiler -lpapi
Always run this first, before any profiling. It tells you what this machine can measure.
cd wss_profiler && PATH="$PWD:$PATH" ./wss_check
Or run the runtime probe directly for machine-readable output:
cd wss_profiler && PATH="$PWD:$PATH" mpirun -np 1 ./wss_runtime_probe
The probe reports KEY=VALUE lines:
| Key | Meaning |
|---|---|
HOT_BYTES_OK=1 | Hot-byte measurement works (the core feature) |
FP_OK=1 | FLOP counting works |
MEM_BYTES_OK=1 | Byte-based memory traffic (PAPI load/store) |
MEM_OK=1 | Some memory-access metric available |
FP_SOURCE | papi, perf_fallback, or none |
WSS_PERF_FP_EVENTS_ENV | The FP event codes that worked (e.g. 0x74,0x75) |
HOT_BYTES_OK=0, the machine cannot write /proc/self/clear_refs.
Profiling cannot proceed without root or elevated permissions.FP_OK=0 and FP_SOURCE=none, try discovering FP event codes:
eval $(cd wss_profiler && PATH="$PWD:$PATH" ./wss_probe_fp_events 2>/dev/null)
echo $WSS_PERF_FP_EVENTS
The probe ships architecture-specific defaults: aarch64 probes 0x74,0x75
(FP_FIXED_OPS_SPEC, FP_SCALE_OPS_SPEC); x86_64 probes 0x1c7,0x4c7 (Intel
fp_arith_inst_retired scalar and 256-bit-packed double). On AMD or other
x86_64 microarchitectures these may report 0; pass explicit codes from
perf list and the CPU PMU reference manual. Raw PERF_TYPE_RAW codes are
encoded as (umask << 8) | event; e.g. event 0xc7 with umask 0x01
(scalar double) is 0x1c7.
On Intel hybrid CPUs (P-core/E-core, e.g. Alder Lake+) the raw PMU event
can land on a core where it does not count, so the probe may return 0 on
the first try. Re-run it once or twice; once the codes work they are
stable for the profiled run.WSS_PERF_FP_EVENTS=0x74,0x75 mpirun -np 4 ./myapp
Never use a separate export — each shell command is an independent
session, and MPI launchers may strip inherited environment variables.env_prefix (WSS_PERF_FP_EVENTS=0x74,0x75 or empty) for
use in every profiled run below.Before profiling, build the code normally and run it. Verify it exits cleanly with the expected output. Do not proceed until the baseline works.
If the code has OpenMP support, disable it for the profiled run.
Use the project's own build system (Makefile, CMakeLists.txt, configure
script). Do not improvise a handwritten compile line unless the project has
no build system at all.
Run the unmodified binary under /usr/bin/time -v to measure peak RSS
(rank 0 only):
mpirun -np 4 /usr/bin/time -v ./myapp [args] 2>&1 | tee phase1_peak_memory.log
For MPI codes, wrap so only rank 0 is measured. A simple approach:
cat > /tmp/rank0_time.sh << 'EOF'
#!/bin/sh
if [ "$OMPI_COMM_WORLD_RANK" = "0" ]; then
exec /usr/bin/time -v "$@"
else
exec "$@" 2>/dev/null
fi
EOF
chmod +x /tmp/rank0_time.sh
mpirun -np 4 /tmp/rank0_time.sh ./myapp [args] 2>&1 | tee phase1_peak_memory.log
Parse Maximum resident set size (kbytes) and divide by 1024 to get MB.
This is the upper bound — per-kernel hot sets will be fractions of this.
Check for warnings: if the binary exits non-zero, runs in under 500ms, or prints error patterns, diagnose before proceeding. Common causes: wrong working directory, missing input file, silent crash.
If the capability check showed perf_stat_ok, sample the code to decide
which kernels to instrument:
mpirun -np 4 /tmp/rank0_time.sh perf record -e cycles -F 99 --call-graph=dwarf \
-o /tmp/wss_perf.data -- ./myapp [args] 2>&1 | tee phase2_perf.log
perf report -n --stdio -i /tmp/wss_perf.data | head -200 > phase2_report.txt
Build for attribution, not for speed. Perf can only name functions that
survive as distinct symbols. A normal -O2 build inlines static helpers into
their callers (everything collapses into main), so the report cannot guide
instrumentation. Rebuild with -O0 -g -fno-inline (or -Og -g) for this
phase, then switch back to the project's normal flags for the profiled run.
If --call-graph=dwarf fails with failed to process type: ... or an
unparseable perf.data, the dwarf unwinder is incompatible with this
kernel/perf combo. Retry with frame-pointer unwinding (-g --) or no
call-graph capture (drop --call-graph=dwarf):
mpirun -np 4 /tmp/rank0_time.sh perf record -e cycles -F 99 -g -- \
-o /tmp/wss_perf.data -- ./myapp [args] 2>&1 | tee phase2_perf.log
Identify the top functions by sample percentage. Note which are in user code vs. MPI/library code. Tell the user which functions appear hottest and ask which to instrument, or make a recommendation based on the data.
If perf is not available, skip this step. Ask the user which kernels to instrument, or read the source to identify the main compute loops.
This step modifies the user's source code. Ask permission before editing files. Explain which files and functions you plan to instrument and why that granularity is appropriate.
#include "wss_profiler.h"
int main(int argc, char **argv) {
MPI_Init(&argc, &argv);
WSS_INIT();
// ...
WSS_BEGIN();
matvec(A, p, Ap);
WSS_END("matvec");
WSS_BEGIN();
precondition(M, r, z);
WSS_END("preconditioner");
// ...
}
Build with profiling:
mpicc -DPROFILE_WSS -I./wss_profiler -o myapp myapp.c -L./wss_profiler -lwss_profiler -lpapi
use wss_profiler_mod
call mpi_init(ierr)
call wss_init()
call wss_begin()
call matvec(A, p, Ap, ierr)
call wss_end_named("matvec")
call wss_begin()
call precondition(M, r, z, ierr)
call wss_end_named("preconditioner")
Build with profiling (note: mpif90 does not search system paths for
.mod files — pass -I explicitly):
mpif90 -DPROFILE_WSS -I./wss_profiler -o myapp myapp.f90 -L./wss_profiler -lwss_profiler -lpapi
Run with the FP event prefix from the capability check inlined:
WSS_PERF_FP_EVENTS=0x74,0x75 mpirun -np 4 ./myapp [args] 2>&1 | tee phase3_run.log
If WSS_PERF_FP_EVENTS was empty (PAPI provides FP events, or no FP
counting available), omit the prefix.
After the run, confirm the output does NOT contain WSS_PERF_FP_EVENTS not set. If it does, the inline prefix was missing from that command —
add it and rerun.
Do not pipe the run through head or tail. The [WSS] lines stream
live as each kernel finishes; appending | head sends SIGPIPE upstream,
which kills mpirun early and silently truncates the run. Redirect to a
file (> phase3_run.log 2>&1) and inspect it afterward.
Parse the [WSS] lines from the log:
[WSS] matvec 512.0 MB hot 1024.0 MB accessed 0.480 GFLOP 0.98 FLOP/B-hot 0.47 FLOP/B-acc
Process:
"matvec", "preconditioner", not "step1".The profiler uses a single global PAPI eventset and a single clear_refs
state. Nesting corrupts both. To measure at multiple levels, do separate
runs: one coarse, one fine.
All macros compile away to nothing. The same source file works for both profiling and normal builds.
Each [WSS] line reports:
| Field | Meaning |
|---|---|
hot MB | Unique pages touched — the GPU memory this kernel needs |
accessed MB | Total bytes loaded+stored (0 if PAPI load/store unavailable) |
M accesses | Memory-access event count (aarch64 PMU fallback when PAPI load/store unavailable) |
GFLOP | Floating-point operations (0 if no FP counters) |
FLOP/B-hot | FLOPs per byte of working set |
FLOP/B-acc | FLOPs per byte of traffic (closest to roofline arithmetic intensity) |
FLOP/access | FLOPs per memory-access event (aarch64 PMU fallback) |
When accessed MB > hot MB, the kernel revisits data (reuse ratio =
accessed/hot). When they're close, the kernel streams through data once.
Always include baseline peak RSS as context:
Peak memory (rank 0): 3072 MB
| Kernel | % Time | Hot MB | % of Peak | Accessed MB | Reuse | GFLOP | FLOP/B-hot | FLOP/B-acc | Assessment |
|---------------|--------|--------|-----------|-------------|-------|-------|------------|------------|--------------|
| stencil_apply | 42.3% | 512 | 16.7% | 1024 | 2.0x | 0.48 | 0.98 | 0.47 | memory-bound |
| fft_forward | 28.1% | 128 | 4.2% | 256 | 2.0x | 0.19 | 1.57 | 0.74 | borderline |
Show unavailable counter columns as "n/a" rather than 0. Hot MB and % of Peak always work.
OMP_NUM_THREADS=1.GPU memory planning is not about total allocation. It is about the maximum hot working set across all kernels, plus what needs to stay resident between them.
max_hot_mb = max(hot_mb across all profiled kernels)
device_mem_mb = <device memory in MB, e.g. 81920 for A100 80GB>
if max_hot_mb < device_mem_mb:
"The heaviest kernel's working set is [max_hot_mb] MB, which fits in
[device] memory ([device_mem_mb] MB). Total allocation is [total] GB
but no single kernel needs all of it."
else:
"The heaviest kernel ([name]) needs [max_hot_mb] MB, which exceeds
[device] memory by [max_hot_mb - device_mem_mb] MB. Tiling or
explicit swapping will be required."
Reason about execution order. For a time-stepping loop:
hot(B) - overlap(A,B), not hot(B).swap_per_step ≤ sum(hot MB for all kernels in one timestep) [worst case: no reuse]
swap_per_step ≥ max(hot MB) [best case: all fits]
| Macro | Where | What it does |
|---|---|---|
WSS_INIT() | Once, after MPI_Init() | Identifies rank 0, initialises PAPI |
WSS_BEGIN() | Before each kernel call | Clears /proc/self/clear_refs, starts counters |
WSS_END("name") | After each kernel call | Stops counters, reads smaps, prints [WSS] line |
Without -DPROFILE_WSS, all macros compile away to nothing.
use wss_profiler_mod
call wss_init()
call wss_begin()
call some_kernel(...)
call wss_end_named("kernel_name")
The globals (_wss_rank, _wss_eventset, etc.) are declared extern in
the header so every translation unit shares one copy. Without this,
WSS_INIT() in main.c would set its own copy of _wss_rank while
WSS_BEGIN() in other files reads uninitialized copies and silently skips
all measurements.
PAPI_DP_OPS, PAPI_SP_OPS, then PAPI_FP_OPS).perf_event_open
with raw PMU event codes from the WSS_PERF_FP_EVENTS environment
variable (comma-separated hex codes, one fd per code, counts summed).wss_probe_fp_events to discover which codes work on this machine.WSS_PERF_FP_EVENTS is not set and PAPI has no FP events, FLOPs = 0.When PAPI load/store events are unavailable, the profiler falls back to
raw PMU mem_access events via perf_event_open. Set WSS_PERF_MEM_EVENTS
to a comma-separated list of hex event codes. On aarch64, defaults to
0x13 (architectural MEM_ACCESS) if not set. Reports "M accesses" and
"FLOP/access" instead of "MB accessed" and "FLOP/B-acc".
On x86_64 there are no bundled WSS_PERF_MEM_EVENTS defaults; memory-event
codes are model-specific and not verified across vendors. In practice the
accessed MB column on x86_64 usually requires PAPI load/store events. If
PAPI lacks them and no working WSS_PERF_MEM_EVENTS codes are supplied,
accessed MB stays 0; hot-byte and FLOP measurements are unaffected.
| Symptom | Likely cause | Fix |
|---|---|---|
WSS_PERF_FP_EVENTS not set in profiled output | Env var not inlined on that command | Prefix inline: WSS_PERF_FP_EVENTS=0x74,0x75 mpirun ... — never use a separate export |
All kernels report 0.000 GFLOP despite capability check finding FP events | env_prefix not applied to that specific command | Re-run capability check, then immediately run profiled binary with the inline prefix |
0 GFLOP and capability check showed no FP events at all | No PAPI and no working PMU codes | Run eval $(./wss_probe_fp_events) then re-run capability check with those codes |
perf record fails with Permission denied | perf_event_paranoid too high | Skip Phase 2; proceed to Phase 3 if you know target kernels. Ask admin: sudo sysctl kernel.perf_event_paranoid=0 |
cannot open /proc/self/clear_refs | No write access to clear_refs | Run with root or elevated permissions (CAP_SYS_RESOURCE) |
mpirun: not enough slots | OpenMPI slot detection broken | OMPI_MCA_rmaps_base_oversubscribe=1 |
0 GFLOP even though WSS_PERF_FP_EVENTS is set | OpenMPI CPU binding pins rank 0 | Add --bind-to none to mpirun, or set OMPI_MCA_hwloc_base_binding_policy=none |
| Hot MB is 0 for all kernels | clear_refs write failed silently | Check the first [WSS] line for the error; ensure write access to /proc/self/clear_refs |
Critical rule: if you see WSS_PERF_FP_EVENTS not set or 0.000 GFLOP
when you expected FP counting to work, stop and diagnose before
reporting results. Do not present 0 GFLOP as the answer if the capability
check found FP events.
wss_profiler/wss_check (opens in a new tab)wss_profiler/wss_probe_fp_events.c (opens in a new tab)wss_profiler/wss_profiler.c (opens in a new tab)wss_profiler/wss_profiler.h (opens in a new tab)wss_profiler/wss_profiler_f.c (opens in a new tab)wss_profiler/wss_profiler_mod.f90 (opens in a new tab)wss_profiler/wss_runtime_probe.c (opens in a new tab)What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
Other plugins' skills for the same job
/riken-rccs-hot-memory-hot-memory:hot-memoryfrom Hot Memory
Generated from the plugin's indexed repository (riken-rccs/hpc-agentic-sdk) — no native marketplace selected
npx claudepluginhub p/riken-rccs-hot-memory-hot-memory