Skip to content

perf(cuda): ms_ssim_vert_lcs + ms_ssim_horiz — __ldg + __launch_bounds (F3 fix #2, ADR-0757) - #99

Merged
lusoris merged 1 commit into
masterfrom
perf/cuda-ms-ssim-vert-lcs-horiz-ldg-20260529
May 29, 2026
Merged

lusoris merged 1 commit into
masterfrom
perf/cuda-ms-ssim-vert-lcs-horiz-ldg-20260529

Conversation

@lusoris

@lusoris lusoris commented May 29, 2026

Copy link
Copy Markdown
Contributor

Summary

Files changed

  • core/src/feature/cuda/integer_ms_ssim/ms_ssim_score.cu — kernel edits (≈38
    LOC net)
  • docs/adr/0757-cuda-ms-ssim-vert-lcs-horiz-ldg.md — ADR
  • docs/adr/README.md — index row
  • core/src/feature/cuda/AGENTS.md — F3 invariant extended (second application)
  • changelog.d/perf/cuda-ms-ssim-vert-lcs-horiz-ldg.md — changelog fragment
  • docs/rebase-notes.md — no rebase impact noted
  • docs/state.md — perf closure row

Build / correctness verification

# Direct nvcc (CUDA 13.3, sm_89):
nvcc --fatbin -gencode=arch=compute_89,code=sm_89 \
  core/src/feature/cuda/integer_ms_ssim/ms_ssim_score.cu \
  -o /tmp/ms_ssim_score.fatbin \
  -I core/build-cuda/src -I core/src -I core/src/cuda \
  -I core/include -I core/src/feature \
  -DDEVICE_CODE -D_USE_MATH_DEFINES -D__MATH_NO_INLINES \
  --std c++20 -Xcompiler=-ffp-contract=off --fmad=false
# Exit 0, zero warnings.

# SASS check:
cuobjdump --dump-sass /tmp/ms_ssim_score.fatbin | grep -E '(Function|LDG)'
# → LDG.E.CONSTANT in ms_ssim_vert_lcs AND ms_ssim_horiz confirmed.

ncu command (reproducer)

docker exec vmaf-dev-mcp ncu \
  --set basic \
  --kernel-name ms_ssim_vert_lcs,ms_ssim_horiz \
  /usr/local/bin/vmaf \
    --feature ms_ssim --backend cuda \
    --reference /workspace/python/test/resource/yuv/checkerboard_1920_1080_10_3_0_0.yuv \
    --distorted  /workspace/python/test/resource/yuv/checkerboard_1920_1080_10_3_1_0.yuv \
    --width 1920 --height 1080 --pixel_format 420 --bitdepth 8

Deep-dive deliverables checklist

  • Research digest: no digest needed — mechanical application of established F3 pattern (ADR-0754 precedent)
  • Decision matrix: in ADR-0757 ## Alternatives considered
  • AGENTS.md invariant: __ldg() pattern for pass-2 read-only intermediate buffers extended (second application)
  • Reproducer / smoke test: ncu command above
  • changelog.d/perf/cuda-ms-ssim-vert-lcs-horiz-ldg.md
  • docs/rebase-notes.md entry (no rebase impact: fork-local file)

Per-surface docs

no user-discoverable surface change — perf-only kernel annotation; no API,
CLI flag, or metric output change.

state.md

Updated with T-CUDA-MS-SSIM-LDG-F3-20260529 closure row.

PR #93 precedent

ADR-0754 / PR #93 measured 0.00e+00 ULP diff on calculate_ssim_vert_combine
after the same pattern. Expected identical result here (same Gaussian weight
table, no arithmetic change, __ldg() only affects cache routing).

🤖 Generated with Claude Code

@lusoris
lusoris marked this pull request as ready for review May 29, 2026 09:37
…s (F3 fix #2, ADR-0757)

Apply the F3 __ldg() / __restrict__ pointer-extraction pattern (first used in
ADR-0754 for calculate_ssim_vert_combine, PR #93) to the two top ms_ssim audit
candidates identified in PR #96:

- ms_ssim_vert_lcs: extract 5 const float *__restrict__ pointers before K=11
  loop; use __ldg() on all 5x11 = 55 inner-loop loads.
- ms_ssim_horiz: extract 2 const float *__restrict__ pointers before K=11
  loop; use __ldg() on all 2x11 = 22 inner-loop loads.
- Both kernels: add __launch_bounds__(128) (actual launch is 16x8=128 threads).

LDG.E.CONSTANT confirmed in sm_89 SASS via cuobjdump. Build: clean nvcc
compile (zero warnings). Predicted -4 to -6% kernel duration at 1080p
(memory-bound regime where combined intermediate footprint exceeds L2 capacity).

Six deep-dive deliverables: ADR-0757, AGENTS.md invariant extended,
changelog.d/perf/cuda-ms-ssim-vert-lcs-horiz-ldg.md, rebase-notes.md entry,
state.md row, no user-discoverable surface change (perf-only).

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@lusoris
lusoris force-pushed the perf/cuda-ms-ssim-vert-lcs-horiz-ldg-20260529 branch from 01cd110 to 898b8e1 Compare May 29, 2026 09:38
@lusoris
lusoris merged commit f2e2c03 into master May 29, 2026
21 of 37 checks passed
@lusoris
lusoris deleted the perf/cuda-ms-ssim-vert-lcs-horiz-ldg-20260529 branch May 29, 2026 09:38
@lusoris lusoris added this to the 1.0.0 — First release milestone Sep 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant