Skip to content

multiload: use parallel accumulators in stream-sum - #61

Open
superworm wants to merge 1 commit into
google:masterfrom
superworm:stream-sum-parallel-reduction
Open

superworm wants to merge 1 commit into
google:masterfrom
superworm:stream-sum-parallel-reduction

Conversation

@superworm

Copy link
Copy Markdown
Contributor

The Makefile builds with -fno-unroll-loops. In clang this also disables loop-vectorizer interleaving, so the stream-sum reduction is vectorized with a single accumulator. Every iteration then waits on the previous vector add, which caps one thread at one 16-byte add per add latency (8 B/cycle on Neoverse N4, 16 B/cycle with 128-bit vpaddq on x86). Below DRAM sizes stream-sum was measuring this add chain, not the memory hierarchy.

Request an interleave count of 4 on the stream-sum loop so clang keeps four independent accumulators. Explicit loop hints are honored even with -fno-unroll-loops. The pragma is guarded by clang because GCC warns about unknown pragmas and the Makefile uses -Werror. GCC builds are unchanged.

Single-thread stream-sum, MiB/s, median of 3 runs (pinned, -H):

Neoverse N4 (3.6 GHz) 32k 27343 -> 91700 1m 27070 -> 74800
64m 27340 -> 52600 1g 24030 -> 25040
Xeon 6985P-C (GNR) 32k 62780 -> 124270 1m 63900 -> 93640
64m 28770 -> 28770 4g 21950 -> 21960

The Makefile builds with -fno-unroll-loops. In clang this also disables
loop-vectorizer interleaving, so the stream-sum reduction is vectorized
with a single accumulator. Every iteration then waits on the previous
vector add, which caps one thread at one 16-byte add per add latency
(8 B/cycle on Neoverse N4, 16 B/cycle with 128-bit vpaddq on x86).
Below DRAM sizes stream-sum was measuring this add chain, not the memory
hierarchy.

Request an interleave count of 4 on the stream-sum loop so clang keeps
four independent accumulators. Explicit loop hints are honored even
with -fno-unroll-loops. The pragma is guarded by __clang__ because GCC
warns about unknown pragmas and the Makefile uses -Werror. GCC builds
are unchanged.

Single-thread stream-sum, MiB/s, median of 3 runs (pinned, -H):

  Neoverse N4 (3.6 GHz)  32k 27343 -> 91700   1m 27070 -> 74800
                         64m 27340 -> 52600   1g 24030 -> 25040
  Xeon 6985P-C (GNR)     32k 62780 -> 124270  1m 63900 -> 93640
                         64m 28770 -> 28770   4g 21950 -> 21960

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request modifies multiload.c to add a Clang-specific loop pragma (#pragma clang loop interleave_count(4)) inside the load_stream_sum function. This change requests independent accumulators to ensure the loop remains load-bound, bypassing the limitation where -fno-unroll-loops disables Clang vectorizer interleaving. The pragma is guarded with a preprocessor check for Clang to prevent GCC compiler warnings. There are no review comments, and we have no feedback to provide.

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