diff --git a/.github/workflows/hyper_threading_benchmarks.yml b/.github/workflows/hyper_threading_benchmarks.yml new file mode 100644 index 0000000000..e4c1294ba2 --- /dev/null +++ b/.github/workflows/hyper_threading_benchmarks.yml @@ -0,0 +1,122 @@ +name: Benchmark Hyper Threading + +on: + pull_request: + branches: [ '**' ] + +jobs: + benchmark: + runs-on: ubuntu-latest + steps: + - name: Checkout PR + uses: actions/checkout@v2 + with: + ref: ${{ github.head_ref }} + + - name: Setup Python + uses: actions/setup-python@v4 + with: + python-version: '3.9' + + - name: Install Dependencies + run: | + pip install -r requirements.txt + sudo apt update + sudo apt-get install -y hyperfine + + - name: Install Rust + uses: dtolnay/rust-toolchain@1.74.1 + with: + components: rustfmt, clippy + + - name: Compile PR Version + run: | + cargo build --release -p hyper_threading + cp target/release/hyper_threading ${{ github.workspace }}/hyper_threading_pr + cp ./examples/hyper_threading/hyper-threading-workflow.sh ${{ github.workspace }}/hyper-threading-workflow.sh + + - name: Upload PR Binary + uses: actions/upload-artifact@v4 + with: + name: hyper_threading_pr_binary + path: ${{ github.workspace }}/hyper_threading_pr + + - name: Upload Workflow Script + uses: actions/upload-artifact@v4 + with: + name: hyper_threading_workflow_script + path: ${{ github.workspace }}/hyper-threading-workflow.sh + + + - name: Checkout Main Branch + uses: actions/checkout@v2 + with: + ref: 'main' + + - name: Compile Main Version + run: | + cargo build --release -p hyper_threading + cp target/release/hyper_threading ${{ github.workspace }}/hyper_threading_main + + - name: Upload Main Binary + uses: actions/upload-artifact@v4 + with: + name: hyper_threading_main_binary + path: ${{ github.workspace }}/hyper_threading_main + + - name: Download hyper_threading_pr_binary + uses: actions/download-artifact@v4 + with: + name: hyper_threading_pr_binary + path: ${{ github.workspace }}/ + + - name: Download hyper_threading_workflow_script + uses: actions/download-artifact@v4 + with: + name: hyper_threading_workflow_script + path: ${{ github.workspace }}/ + + - name: Download hyper_threading_main_binary + uses: actions/download-artifact@v4 + with: + name: hyper_threading_main_binary + path: ${{ github.workspace }}/ + + + - name: Compile programs + run: make cairo_bench_programs + + - name: Run Benchmarks + run: | + cd ${{ github.workspace }} + chmod +x ./hyper_threading_main + chmod +x ./hyper_threading_pr + chmod +x hyper-threading-workflow.sh + ./hyper-threading-workflow.sh + + - name: Compare Results + run: | + cat result.md + + - name: Find comment + uses: peter-evans/find-comment@v2 + id: fc + with: + issue-number: ${{ github.event.pull_request.number }} + comment-author: 'github-actions[bot]' + body-includes: "**Hyper Thereading Benchmark results**" + + - name: Create comment + if: steps.fc.outputs.comment-id == '' + uses: peter-evans/create-or-update-comment@v3 + with: + issue-number: ${{ github.event.pull_request.number }} + body-path: result.md + + - name: Update comment + if: steps.fc.outputs.comment-id != '' + uses: peter-evans/create-or-update-comment@v3 + with: + comment-id: ${{ steps.fc.outputs.comment-id }} + body-path: result.md + edit-mode: replace diff --git a/examples/hyper_threading/hyper-threading b/examples/hyper_threading/hyper-threading new file mode 100644 index 0000000000..912b6cac75 --- /dev/null +++ b/examples/hyper_threading/hyper-threading @@ -0,0 +1,17 @@ +#!/bin/bash + +thread_counts=(1 2 4 6 8 10 12 16 24 32 ) +binary="target/release/hyper_threading" + + +cmd="hyperfine -r 1" + +# Build the command string with all thread counts +for threads in "${thread_counts[@]}"; do + # For hyperfine, wrap each command in 'sh -c' to correctly handle the environment variable + cmd+=" -n \"threads: ${threads}\" 'sh -c \"RAYON_NUM_THREADS=${threads} ${binary}\"'" +done + +# Execute the hyperfine command +echo "Executing benchmark for all thread counts" +eval $cmd diff --git a/examples/hyper_threading/hyper-threading-workflow.sh b/examples/hyper_threading/hyper-threading-workflow.sh new file mode 100644 index 0000000000..87fc937c57 --- /dev/null +++ b/examples/hyper_threading/hyper-threading-workflow.sh @@ -0,0 +1,34 @@ +#!/bin/bash + +# Define a list of RAYON_NUM_THREADS +thread_counts=(2 4) + +# Define binary names +binaries=("hyper_threading_main" "hyper_threading_pr") + +echo "**Hyper Thereading Benchmark results**" >> result.md +echo "\n \n \n " >> result.md + +# Iter over thread_counts +for threads in "${thread_counts[@]}"; do + # Initialize hyperfine command + cmd="hyperfine -r 2" + + # Add each binary to the command with the current threads value + for binary in "${binaries[@]}"; do + cmd+=" -n \"${binary} threads: ${threads}\" 'RAYON_NUM_THREADS=${threads} ./${binary}'" + done + + # Execute + echo "Running benchmark for ${threads} threads" + echo "\n \n \n " >> result.md + echo $cmd >> result.md + eval $cmd >> result.md + echo "\n \n \n " >> result.md +done + +{ + echo '```' + cat result.md + echo '```' +} > temp_result.md && mv temp_result.md result.md diff --git a/examples/hyper_threading/hyper-threading.sh b/examples/hyper_threading/hyper-threading.sh index 912b6cac75..99fab7f0a6 100644 --- a/examples/hyper_threading/hyper-threading.sh +++ b/examples/hyper_threading/hyper-threading.sh @@ -6,9 +6,7 @@ binary="target/release/hyper_threading" cmd="hyperfine -r 1" -# Build the command string with all thread counts for threads in "${thread_counts[@]}"; do - # For hyperfine, wrap each command in 'sh -c' to correctly handle the environment variable cmd+=" -n \"threads: ${threads}\" 'sh -c \"RAYON_NUM_THREADS=${threads} ${binary}\"'" done