Measures memory bandwidth on Apple Metal. Reports the Copy/Scale/Add/Triad best rate, average, minimum, and maximum time, and validates the results on the GPU.
Inspired by STREAM by John D. McCalpin, University of Virginia.
This project is written in Objective-C and relies on the Foundation and Metal frameworks to compile and run. Make sure you have the Xcode Command Line Tools installed (xcode-select --install).
Requires macOS 15.0 or later (the MTLCompileOptions.mathMode API used for shader compilation).
Build with -O3 optimizations:
clang -O3 -fobjc-arc -framework Foundation -framework Metal -o metalstream metalstream.mRun with two optional arguments:
elements— the number of floats per array (default100000000). Must be at least 4 and is rounded down to a multiple of 4.times— the number of timed iterations per kernel (default10). Must be at least 1.
./metalstream 400000000 20---------------------------------------------------------------
metalstream version 1.0.0
---------------------------------------------------------------
Device = Apple M5
Recommended max working set size = 25559.05 MiB (= 24.96 GiB)
Max buffer length = 19169.28 MiB (= 18.72 GiB)
Has unified memory = yes
---------------------------------------------------------------
Array size = 100000000 (elements), Element size = 4 (bytes)
Memory per array = 381.47 MiB (= 0.37 GiB)
Total memory = 1144.41 MiB (= 1.12 GiB)
---------------------------------------------------------------
The *best* time for each kernel (excluding the first iteration)
will be used to compute the reported bandwidth.
---------------------------------------------------------------
Each kernel will be executed 10 times.
---------------------------------------------------------------
Function Best Rate MB/s Avg time Min time Max time
Copy: 131718.86 0.006169 0.006074 0.006517
Scale: 133738.26 0.006137 0.005982 0.006485
Add: 128807.77 0.009386 0.009316 0.009528
Triad: 129431.80 0.009339 0.009271 0.009531
---------------------------------------------------------------
Solution validates: error less than 1.000000e-06 on all arrays.
---------------------------------------------------------------
Lint code with clang-tidy:
clang-tidy metalstream.m --Format code with clang-format:
clang-format -i metalstream.mMIT — see LICENSE for details.