Created
December 25, 2025 14:18
-
-
Save parsapoorsh/ee7e182911ac1fb531efcab53ff6e180 to your computer and use it in GitHub Desktop.
STREAM Memory Benchmark's Download, Build, and Execution script
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| # STREAM Memory Benchmark's Download, Build, and Execution script | |
| # Usage: ./run-stream-benchmark.sh | |
| set -e | |
| SOURCE_URL="https://raw.githubusercontent.com/jeffhammond/STREAM/refs/heads/master/stream.c" | |
| SOURCE_FILE="./stream.c" | |
| OUTPUT_PATH="./stream_native" | |
| if ! command -v awk >/dev/null; then | |
| echo "awk not found!" | |
| exit 1 | |
| fi | |
| L3_CACHE_MULTIPLIER=8 | |
| AVG_L3_CACHE_SIZE=$(awk '{sum += $1} END {print sum/NR * 1024}' /sys/devices/system/cpu/cpu*/cache/index3/size 2>/dev/null || echo 0) | |
| hline() { | |
| awk 'BEGIN{for(i=1;i<=61;i++)printf "-";print""}' | |
| } | |
| hline | |
| echo "STREAM Memory Benchmark D.B.E script" | |
| if [ "$AVG_L3_CACHE_SIZE" -eq 0 ]; then | |
| hline | |
| echo "WARNING -- Failed to read average L3 cache size, defaulting to 16 MiB." | |
| AVG_L3_CACHE_SIZE=$((16 * 1024 * 1024)) | |
| fi | |
| if [ ! -f "$SOURCE_FILE" ]; then | |
| hline | |
| echo "WARNING -- File $SOURCE_FILE is missing, downloading it..." | |
| if ! command -v curl >/dev/null; then | |
| echo "curl not found!" | |
| exit 1 | |
| fi | |
| if ! curl -fSLo "$SOURCE_FILE" "$SOURCE_URL"; then | |
| echo "Download failed!" | |
| if [ -f "$SOURCE_FILE" ]; then | |
| rm -I "$SOURCE_FILE" | |
| fi | |
| exit 1 | |
| fi | |
| if [ ! -f "$SOURCE_FILE" ]; then | |
| echo "Download success but file $SOURCE_FILE is missing." | |
| exit 1 | |
| fi | |
| echo "Download successful!" | |
| fi | |
| hline | |
| ARRAY_SIZE=$(awk "BEGIN {print $AVG_L3_CACHE_SIZE * $L3_CACHE_MULTIPLIER}") | |
| AVG_L3_CACHE_SIZE_IN_MIB=$(awk "BEGIN {print $AVG_L3_CACHE_SIZE / 1024 / 1024}") | |
| echo "Average L3 cache size is $AVG_L3_CACHE_SIZE_IN_MIB MiB." | |
| ARRAY_SIZE_IN_MIB=$(awk "BEGIN {print $AVG_L3_CACHE_SIZE * $L3_CACHE_MULTIPLIER / 1024 / 1024}") | |
| echo "Set STREAM_ARRAY_SIZE to $ARRAY_SIZE_IN_MIB MiB (x$L3_CACHE_MULTIPLIER of L3 cache)." | |
| echo " Array size should be at least x4 of L3 cache size!" | |
| hline | |
| COMPILE_CMD=( | |
| gcc | |
| "$SOURCE_FILE" | |
| -O3 | |
| -fopenmp | |
| -march=native | |
| -mcpu=native | |
| -mtune=native | |
| -mcmodel=medium | |
| -DSTREAM_ARRAY_SIZE=$ARRAY_SIZE | |
| -o "$OUTPUT_PATH" | |
| ) | |
| echo "Compiler: $(${COMPILE_CMD[0]} --version | awk 'NR==1')" | |
| echo "Compiling command:" | |
| echo "${COMPILE_CMD[@]}" | |
| time ( "${COMPILE_CMD[@]}" && echo -n "Compiled in:" ) | |
| if [ ! -f "$OUTPUT_PATH" ]; then | |
| echo "Compiling failed!" | |
| exit 1 | |
| fi | |
| hline | |
| echo "Executing $OUTPUT_PATH" | |
| time ( "$OUTPUT_PATH" && echo -n "Benchmark time:" ) | |
| hline |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.