Skip to content

Commit 4a868c4

Browse files
authored
feat: merge-train/barretenberg (#17020)
BEGIN_COMMIT_OVERRIDE chore: cycle group cleanup #3 (#16902) fix: improve polynomial structuring in translator and fix bug (#16941) refactor(bb): thread chunk for better work distribution (#16966) fix(bb): shell injection vectors (#16958) chore: cycle group cleanup #4 (#16937) fix: use consistent default build dir in benchmark_remote.sh (#17047) fix: misuse of slice() in cycle_scalar (#16982) vks update docs: improve some Protogalaxy and Translator docs (#17035) fix: edge case in the ECCVM related to splitting scalars (#16816) update vks hash chore: return of the instance (#17043) a second attempt at VK update fix: chmod +x test_civc_standalone_vks_havent_changed.sh fix avm build and update vks chore: Gemini high degree test (#17055) fix: update-vk refactor(bb): Optimize interleaved polynomial batching in Gemini with parallel chunking (#17049) END_COMMIT_OVERRIDE
2 parents 88d0f47 + f2e2a93 commit 4a868c4

File tree

155 files changed

+2451
-1930
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

155 files changed

+2451
-1930
lines changed
Lines changed: 281 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,281 @@
1+
#!/bin/bash
2+
3+
# CPU scaling benchmark that runs benchmarks locally
4+
# This script runs a command multiple times with different HARDWARE_CONCURRENCY values
5+
# and tracks the scaling performance of specific BB_BENCH entries
6+
# Uses --bench_out flag to get JSON output for accurate timing extraction
7+
8+
set -e
9+
10+
# Colors for output
11+
RED='\033[0;31m'
12+
GREEN='\033[0;32m'
13+
YELLOW='\033[1;33m'
14+
BLUE='\033[0;34m'
15+
CYAN='\033[0;36m'
16+
MAGENTA='\033[0;35m'
17+
NC='\033[0m' # No Color
18+
19+
# Parse arguments
20+
if [ $# -lt 2 ]; then
21+
echo -e "${RED}Usage: $0 \"benchmark_name\" \"command\" [cpu_counts]${NC}"
22+
echo -e "Example: $0 \"ClientIvcProve\" \"./build/bin/bb prove --ivc_inputs_path input.msgpack --scheme client_ivc\""
23+
echo -e "Example: $0 \"construct_mock_function_circuit\" \"./build/bin/ultra_honk_bench --benchmark_filter=.*power_of_2.*/15\" \"1,2,4,8\""
24+
exit 1
25+
fi
26+
27+
BENCH_NAME="$1"
28+
COMMAND="$2"
29+
CPU_LIST="${3:-1,2,4,8,16}"
30+
31+
# Convert comma-separated list to array
32+
IFS=',' read -ra CPU_COUNTS <<< "$CPU_LIST"
33+
34+
# Create output directory with timestamp
35+
TIMESTAMP=$(date +%Y%m%d_%H%M%S)
36+
OUTPUT_DIR="bench_scaling_local_${TIMESTAMP}"
37+
mkdir -p "$OUTPUT_DIR"
38+
39+
# Results file
40+
RESULTS_FILE="$OUTPUT_DIR/scaling_results.txt"
41+
CSV_FILE="$OUTPUT_DIR/scaling_results.csv"
42+
43+
echo -e "${GREEN}╔════════════════════════════════════════════════════════════════╗${NC}"
44+
echo -e "${GREEN}║ CPU Scaling Benchmark (Local Execution) ║${NC}"
45+
echo -e "${GREEN}╚════════════════════════════════════════════════════════════════╝${NC}"
46+
echo ""
47+
echo -e "${CYAN}Benchmark Entry:${NC} ${YELLOW}$BENCH_NAME${NC}"
48+
echo -e "${CYAN}Command:${NC} $COMMAND"
49+
echo -e "${CYAN}CPU Counts:${NC} ${CPU_COUNTS[@]}"
50+
echo -e "${CYAN}Machine:${NC} $(hostname)"
51+
echo -e "${CYAN}Output Directory:${NC} $OUTPUT_DIR"
52+
echo ""
53+
54+
# Initialize results file
55+
echo "CPU Scaling Benchmark: $BENCH_NAME" > "$RESULTS_FILE"
56+
echo "Command: $COMMAND" >> "$RESULTS_FILE"
57+
echo "Machine: $(hostname)" >> "$RESULTS_FILE"
58+
echo "Date: $(date)" >> "$RESULTS_FILE"
59+
echo "================================================" >> "$RESULTS_FILE"
60+
echo "" >> "$RESULTS_FILE"
61+
62+
# Initialize CSV file
63+
echo "CPUs,Time_ms,Time_s,Speedup,Efficiency" > "$CSV_FILE"
64+
65+
# Function to extract time for specific benchmark entry from JSON
66+
extract_bench_time() {
67+
local json_file=$1
68+
local bench_name=$2
69+
70+
# Extract time from JSON file using grep and sed
71+
# JSON format is: {"benchmark_name": time_in_nanoseconds, ...}
72+
local time_ns=""
73+
74+
if [ -f "$json_file" ]; then
75+
# Extract the value for the specific benchmark name from JSON
76+
time_ns=$(grep -oP "\"${bench_name//\\/\\\\}\":\s*\K\d+" "$json_file" 2>/dev/null | head -1)
77+
fi
78+
79+
# If JSON extraction failed, try to extract from log file (fallback)
80+
if [ -z "$time_ns" ] && [ -f "${json_file%/bench.json}/output.log" ]; then
81+
local log_file="${json_file%/bench.json}/output.log"
82+
# Try to extract from hierarchical BB_BENCH output
83+
# Look for pattern like: " ├─ ClientIvcProve ... 28.13s"
84+
local time_s=$(grep -E "├─.*${bench_name}" "$log_file" | grep -oP '\d+\.\d+s' | grep -oP '\d+\.\d+' | head -1)
85+
if [ -n "$time_s" ]; then
86+
# Convert seconds to nanoseconds
87+
time_ns=$(awk -v s="$time_s" 'BEGIN{printf "%.0f", s * 1000000000}')
88+
fi
89+
fi
90+
91+
echo "$time_ns"
92+
}
93+
94+
# Store baseline time for speedup calculation
95+
BASELINE_TIME=""
96+
97+
# Arrays to store results
98+
declare -a ALL_CPUS=()
99+
declare -a ALL_TIMES=()
100+
declare -a ALL_SPEEDUPS=()
101+
102+
echo -e "${BLUE}Starting benchmark runs locally...${NC}"
103+
echo ""
104+
105+
# Run benchmark for each CPU count
106+
for cpu_count in "${CPU_COUNTS[@]}"; do
107+
echo -e "${YELLOW}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}"
108+
echo -e "${YELLOW}Running with ${cpu_count} CPU(s)...${NC}"
109+
110+
# Create output subdirectory
111+
run_dir="$OUTPUT_DIR/run_${cpu_count}cpus"
112+
mkdir -p "$run_dir"
113+
log_file="$run_dir/output.log"
114+
bench_json_file="$run_dir/bench.json"
115+
116+
# Run command locally with specified CPU count
117+
echo -e "${CYAN}Executing locally...${NC}"
118+
start_time=$(date +%s.%N)
119+
120+
# Clean up any stale benchmark file
121+
rm -f "$bench_json_file"
122+
123+
# Execute the command locally with HARDWARE_CONCURRENCY environment variable
124+
# Add --bench_out flag to get JSON output
125+
HARDWARE_CONCURRENCY=$cpu_count eval "$COMMAND --bench_out $bench_json_file" 2>&1 | tee "$log_file"
126+
127+
end_time=$(date +%s.%N)
128+
wall_time=$(awk -v e="$end_time" -v s="$start_time" 'BEGIN{printf "%.2f", e-s}')
129+
130+
# Extract the specific benchmark time from JSON file
131+
bench_time_ns=$(extract_bench_time "$bench_json_file" "$BENCH_NAME")
132+
133+
if [ -z "$bench_time_ns" ] || [ "$bench_time_ns" = "0" ]; then
134+
echo -e "${RED}Warning: Could not extract timing for '$BENCH_NAME' from JSON${NC}"
135+
echo -e "${YELLOW}Check the JSON file: $bench_json_file${NC}"
136+
137+
# Show what's in the JSON file for debugging
138+
if [ -f "$bench_json_file" ]; then
139+
echo -e "${YELLOW}JSON content (first 500 chars):${NC}"
140+
head -c 500 "$bench_json_file"
141+
echo ""
142+
fi
143+
144+
echo "CPUs: $cpu_count - No timing data found" >> "$RESULTS_FILE"
145+
continue
146+
fi
147+
148+
# Convert to milliseconds and seconds
149+
bench_time_ms=$(awk -v ns="$bench_time_ns" 'BEGIN{printf "%.2f", ns / 1000000}')
150+
bench_time_s=$(awk -v ns="$bench_time_ns" 'BEGIN{printf "%.3f", ns / 1000000000}')
151+
152+
# Calculate speedup and efficiency
153+
if [ -z "$BASELINE_TIME" ]; then
154+
BASELINE_TIME="$bench_time_ns"
155+
speedup="1.00"
156+
efficiency="100.0"
157+
else
158+
speedup=$(awk -v base="$BASELINE_TIME" -v curr="$bench_time_ns" 'BEGIN{printf "%.2f", base / curr}')
159+
efficiency=$(awk -v sp="$speedup" -v cpus="$cpu_count" 'BEGIN{printf "%.1f", (sp / cpus) * 100}')
160+
fi
161+
162+
# Store results
163+
ALL_CPUS+=("$cpu_count")
164+
ALL_TIMES+=("$bench_time_ms")
165+
ALL_SPEEDUPS+=("$speedup")
166+
167+
# Write to results file
168+
echo "CPUs: $cpu_count" >> "$RESULTS_FILE"
169+
echo " Time: ${bench_time_ms} ms (${bench_time_s} s)" >> "$RESULTS_FILE"
170+
echo " Speedup: ${speedup}x" >> "$RESULTS_FILE"
171+
echo " Efficiency: ${efficiency}%" >> "$RESULTS_FILE"
172+
echo " Wall time: ${wall_time}s" >> "$RESULTS_FILE"
173+
echo "" >> "$RESULTS_FILE"
174+
175+
# Write to CSV
176+
echo "$cpu_count,$bench_time_ms,$bench_time_s,$speedup,$efficiency" >> "$CSV_FILE"
177+
178+
# Display results
179+
echo -e "${GREEN}✓ Completed${NC}"
180+
echo -e " ${CYAN}Time for '$BENCH_NAME':${NC} ${bench_time_ms} ms"
181+
echo -e " ${CYAN}Speedup:${NC} ${speedup}x"
182+
echo -e " ${CYAN}Efficiency:${NC} ${efficiency}%"
183+
echo ""
184+
done
185+
186+
# Generate summary
187+
echo -e "${GREEN}╔════════════════════════════════════════════════════════════════╗${NC}"
188+
echo -e "${GREEN}║ SUMMARY ║${NC}"
189+
echo -e "${GREEN}╚════════════════════════════════════════════════════════════════╝${NC}"
190+
echo ""
191+
192+
# Print table header
193+
printf "${CYAN}%-8s %-15s %-12s %-12s${NC}\n" "CPUs" "Time (ms)" "Speedup" "Efficiency"
194+
printf "${CYAN}%-8s %-15s %-12s %-12s${NC}\n" "────" "──────────" "───────" "──────────"
195+
196+
# Print results table
197+
for i in "${!ALL_CPUS[@]}"; do
198+
cpu="${ALL_CPUS[$i]}"
199+
time="${ALL_TIMES[$i]}"
200+
speedup="${ALL_SPEEDUPS[$i]}"
201+
202+
if [ "$i" -eq 0 ]; then
203+
efficiency="100.0%"
204+
else
205+
efficiency=$(awk -v sp="$speedup" -v cpus="$cpu" 'BEGIN{printf "%.1f%%", (sp / cpus) * 100}')
206+
fi
207+
208+
# Color code based on efficiency
209+
if [ "$i" -eq 0 ]; then
210+
color="${GREEN}"
211+
else
212+
eff_val=$(echo "$efficiency" | sed 's/%//')
213+
if awk -v eff="$eff_val" 'BEGIN {exit !(eff > 75)}'; then
214+
color="${GREEN}"
215+
elif awk -v eff="$eff_val" 'BEGIN {exit !(eff > 50)}'; then
216+
color="${YELLOW}"
217+
else
218+
color="${RED}"
219+
fi
220+
fi
221+
222+
printf "${color}%-8s %-15s %-12s %-12s${NC}\n" "$cpu" "$time" "${speedup}x" "$efficiency"
223+
done
224+
225+
echo ""
226+
echo -e "${MAGENTA}═══════════════════════════════════════════════════════════════${NC}"
227+
echo ""
228+
229+
# Generate scaling plot (ASCII art)
230+
echo -e "${CYAN}Scaling Visualization:${NC}"
231+
echo ""
232+
233+
if [ "${#ALL_TIMES[@]}" -gt 0 ]; then
234+
# Find max time for scaling
235+
max_time=$(printf '%s\n' "${ALL_TIMES[@]}" | sort -rn | head -1)
236+
237+
# Create ASCII bar chart
238+
for i in "${!ALL_CPUS[@]}"; do
239+
cpu="${ALL_CPUS[$i]}"
240+
time="${ALL_TIMES[$i]}"
241+
242+
# Calculate bar length (max 50 chars)
243+
bar_len=$(awk -v t="$time" -v m="$max_time" 'BEGIN{printf "%.0f", (t/m) * 50}')
244+
245+
# Create bar
246+
bar=""
247+
for ((j=0; j<bar_len; j++)); do
248+
bar="${bar}"
249+
done
250+
251+
printf "%-6s │%s %.2f ms\n" "${cpu} CPU" "$bar" "$time"
252+
done
253+
fi
254+
255+
echo ""
256+
echo -e "${GREEN}Results saved to:${NC}"
257+
echo " - Summary: $RESULTS_FILE"
258+
echo " - CSV: $CSV_FILE"
259+
echo " - Logs: $OUTPUT_DIR/run_*cpus/output.log"
260+
echo ""
261+
262+
# Check for scaling issues
263+
if [ "${#ALL_SPEEDUPS[@]}" -gt 1 ]; then
264+
last_speedup="${ALL_SPEEDUPS[-1]}"
265+
last_cpu="${ALL_CPUS[-1]}"
266+
actual_efficiency=$(awk -v sp="$last_speedup" -v cpus="$last_cpu" 'BEGIN{printf "%.1f", (sp / cpus) * 100}')
267+
268+
if awk -v eff="$actual_efficiency" 'BEGIN {exit !(eff < 50)}'; then
269+
echo -e "${YELLOW}⚠ Warning: Poor scaling detected!${NC}"
270+
echo -e " At ${last_cpu} CPUs: ${actual_efficiency}% efficiency"
271+
echo -e " Consider investigating thread contention or memory bottlenecks."
272+
elif awk -v eff="$actual_efficiency" 'BEGIN {exit !(eff < 75)}'; then
273+
echo -e "${YELLOW}Note: Moderate scaling efficiency at high CPU counts.${NC}"
274+
echo -e " At ${last_cpu} CPUs: ${actual_efficiency}% efficiency"
275+
else
276+
echo -e "${GREEN}✓ Good scaling efficiency maintained!${NC}"
277+
echo -e " At ${last_cpu} CPUs: ${actual_efficiency}% efficiency"
278+
fi
279+
fi
280+
281+
echo ""

barretenberg/cpp/scripts/bench_cpu_scaling_remote.sh

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,9 @@ for cpu_count in "${CPU_COUNTS[@]}"; do
127127
echo -e "${CYAN}Executing on remote via benchmark_remote.sh...${NC}"
128128
start_time=$(date +%s.%N)
129129

130+
# Clean up any stale benchmark file from previous runs on remote
131+
ssh $BB_SSH_KEY $BB_SSH_INSTANCE "rm -f /tmp/bench_${cpu_count}.json" 2>/dev/null
132+
130133
# Use benchmark_remote.sh to execute on remote with --bench_out for JSON output
131134
# The benchmark_remote.sh script handles locking and setup
132135
# Use tee to show output in real-time AND save to log file
@@ -135,6 +138,9 @@ for cpu_count in "${CPU_COUNTS[@]}"; do
135138

136139
# Retrieve the JSON file from remote
137140
ssh $BB_SSH_KEY $BB_SSH_INSTANCE "cat /tmp/bench_${cpu_count}.json" > "$bench_json_file" 2>/dev/null
141+
142+
# Clean up the remote benchmark file after retrieval
143+
ssh $BB_SSH_KEY $BB_SSH_INSTANCE "rm -f /tmp/bench_${cpu_count}.json" 2>/dev/null
138144

139145
end_time=$(date +%s.%N)
140146
wall_time=$(awk -v e="$end_time" -v s="$start_time" 'BEGIN{printf "%.2f", e-s}')
@@ -222,9 +228,9 @@ for i in "${!ALL_CPUS[@]}"; do
222228
color="${GREEN}"
223229
else
224230
eff_val=$(echo "$efficiency" | sed 's/%//')
225-
if (( $(echo "$eff_val > 75" | bc -l) )); then
231+
if awk -v eff="$eff_val" 'BEGIN {exit !(eff > 75)}'; then
226232
color="${GREEN}"
227-
elif (( $(echo "$eff_val > 50" | bc -l) )); then
233+
elif awk -v eff="$eff_val" 'BEGIN {exit !(eff > 50)}'; then
228234
color="${YELLOW}"
229235
else
230236
color="${RED}"
@@ -277,11 +283,11 @@ if [ "${#ALL_SPEEDUPS[@]}" -gt 1 ]; then
277283
last_cpu="${ALL_CPUS[-1]}"
278284
actual_efficiency=$(awk -v sp="$last_speedup" -v cpus="$last_cpu" 'BEGIN{printf "%.1f", (sp / cpus) * 100}')
279285

280-
if (( $(echo "$actual_efficiency < 50" | bc -l) )); then
286+
if awk -v eff="$actual_efficiency" 'BEGIN {exit !(eff < 50)}'; then
281287
echo -e "${YELLOW}⚠ Warning: Poor scaling detected!${NC}"
282288
echo -e " At ${last_cpu} CPUs: ${actual_efficiency}% efficiency"
283289
echo -e " Consider investigating thread contention or memory bottlenecks."
284-
elif (( $(echo "$actual_efficiency < 75" | bc -l) )); then
290+
elif awk -v eff="$actual_efficiency" 'BEGIN {exit !(eff < 75)}'; then
285291
echo -e "${YELLOW}Note: Moderate scaling efficiency at high CPU counts.${NC}"
286292
echo -e " At ${last_cpu} CPUs: ${actual_efficiency}% efficiency"
287293
else
@@ -290,4 +296,8 @@ if [ "${#ALL_SPEEDUPS[@]}" -gt 1 ]; then
290296
fi
291297
fi
292298

299+
# Clean up all temporary benchmark files on remote
300+
echo -e "${CYAN}Cleaning up remote temporary files...${NC}"
301+
ssh $BB_SSH_KEY $BB_SSH_INSTANCE "rm -f /tmp/bench_*.json" 2>/dev/null
302+
293303
echo ""

barretenberg/cpp/scripts/benchmark_remote.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ set -eu
1010
BENCHMARK=${1:-client_ivc_bench}
1111
COMMAND=${2:-./$BENCHMARK}
1212
PRESET=${3:-clang20-no-avm}
13-
BUILD_DIR=${4:-build}
13+
BUILD_DIR=${4:-build-no-avm}
1414
HARDWARE_CONCURRENCY=${HARDWARE_CONCURRENCY:-16}
1515

1616
# Move above script dir.

barretenberg/cpp/scripts/test_civc_standalone_vks_havent_changed.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ cd ..
1313
# - Generate a hash for versioning: sha256sum bb-civc-inputs.tar.gz
1414
# - Upload the compressed results: aws s3 cp bb-civc-inputs.tar.gz s3://aztec-ci-artifacts/protocol/bb-civc-inputs-[hash(0:8)].tar.gz
1515
# Note: In case of the "Test suite failed to run ... Unexpected token 'with' " error, need to run: docker pull aztecprotocol/build:3.0
16-
pinned_short_hash="98409939"
16+
pinned_short_hash="5aa55c9f"
1717
pinned_civc_inputs_url="https://aztec-ci-artifacts.s3.us-east-2.amazonaws.com/protocol/bb-civc-inputs-${pinned_short_hash}.tar.gz"
1818

1919
function compress_and_upload {

barretenberg/cpp/src/barretenberg/api/api_ultra_honk.test.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
#include "barretenberg/dsl/acir_format/proof_surgeon.hpp"
99
#include "barretenberg/flavor/ultra_flavor.hpp"
1010
#include "barretenberg/flavor/ultra_rollup_flavor.hpp"
11-
#include "barretenberg/ultra_honk/decider_proving_key.hpp"
11+
#include "barretenberg/ultra_honk/prover_instance.hpp"
1212
#include <chrono>
1313
#include <cstddef>
1414
#include <cstdlib>

0 commit comments

Comments
 (0)