Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

metalstream

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.

Getting Started

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).

Building and Running

Build with -O3 optimizations:

clang -O3 -fobjc-arc -framework Foundation -framework Metal -o metalstream metalstream.m

Run with two optional arguments:

  • elements — the number of floats per array (default 100000000). Must be at least 4 and is rounded down to a multiple of 4.
  • times — the number of timed iterations per kernel (default 10). Must be at least 1.
./metalstream 400000000 20

Example Output

---------------------------------------------------------------
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.
---------------------------------------------------------------

Linting Code

Lint code with clang-tidy:

clang-tidy metalstream.m --

Formatting

Format code with clang-format:

clang-format -i metalstream.m

License

MIT — see LICENSE for details.

About

Measures memory bandwidth on Apple Metal

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages