diff --git a/.vscode/settings.json b/.vscode/settings.json index 394dd741ab1..bb29728a078 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -153,5 +153,8 @@ "C_Cpp.default.enableConfigurationSquiggles": false, "C_Cpp.formatting": "disabled", "C_Cpp.vcpkg.enabled": false, - "C_Cpp.default.includePath": ["barretenberg/cpp/src"], + "C_Cpp.default.includePath": [ + "barretenberg/cpp/src" + ], + "cmake.sourceDirectory": "/mnt/user-data/adam/aztec-packages/barretenberg/cpp", } diff --git a/barretenberg/cpp/CMakeLists.txt b/barretenberg/cpp/CMakeLists.txt index c4fc0abad92..056233c1c14 100644 --- a/barretenberg/cpp/CMakeLists.txt +++ b/barretenberg/cpp/CMakeLists.txt @@ -16,14 +16,11 @@ configure_file( @ONLY ) - option(DISABLE_ASM "Disable custom assembly" OFF) option(DISABLE_ADX "Disable ADX assembly variant" OFF) option(MULTITHREADING "Enable multi-threading" ON) option(OMP_MULTITHREADING "Enable OMP multi-threading" OFF) -option(TESTING "Build tests" ON) -option(BENCHMARKS "Build benchmarks" ON) -option(FUZZING "Build fuzzing harnesses" OFF) +option(FUZZING "Build ONLY fuzzing harnesses" OFF) option(DISABLE_TBB "Intel Thread Building Blocks" ON) option(COVERAGE "Enable collecting coverage from tests" OFF) option(ENABLE_ASAN "Address sanitizer for debugging tricky memory corruption" OFF) @@ -52,22 +49,10 @@ if(FUZZING) add_definitions(-DDISABLE_CUSTOM_MUTATORS=1) endif() - set(SANITIZER_OPTIONS "") - - if(ADDRESS_SANITIZER) - set(SANITIZER_OPTIONS ${SANITIZER_OPTIONS} -fsanitize=address) - endif() - - if(UNDEFINED_BEHAVIOUR_SANITIZER) - set(SANITIZER_OPTIONS ${SANITIZER_OPTIONS} -fsanitize=undefined -fno-sanitize=alignment) - endif() - - add_compile_options(-fsanitize=fuzzer-no-link ${SANITIZER_OPTIONS}) + add_compile_options(-fsanitize=fuzzer) + add_link_options(-fsanitize=fuzzer) - set(WASM OFF) - set(BENCHMARKS OFF) set(MULTITHREADING OFF) - set(TESTING OFF) endif() if(CMAKE_SYSTEM_PROCESSOR MATCHES "wasm32") @@ -75,7 +60,6 @@ if(CMAKE_SYSTEM_PROCESSOR MATCHES "wasm32") set(WASM ON) set(DISABLE_ASM ON) set(OMP_MULTITHREADING OFF) - set(BENCHMARKS OFF) set(DISABLE_TBB 1) add_compile_definitions(_WASI_EMULATED_PROCESS_CLOCKS=1) endif() diff --git a/barretenberg/cpp/CMakePresets.json b/barretenberg/cpp/CMakePresets.json index 7b22541e785..075068e6cd4 100644 --- a/barretenberg/cpp/CMakePresets.json +++ b/barretenberg/cpp/CMakePresets.json @@ -140,6 +140,19 @@ "LDFLAGS": "-fsanitize=thread" } }, + { + "name": "ubsan", + "displayName": "Debugging build with undefined behaviour sanitizer on Clang-16", + "description": "Build with undefined behaviour sanitizer on clang16 with debugging information", + "inherits": "clang16-dbg", + "binaryDir": "build-ubsan", + "generator": "Unix Makefiles", + "environment": { + "CFLAGS": "-fsanitize=undefined", + "CXXFLAGS": "-fsanitize=undefined", + "LDFLAGS": "-fsanitize=undefined" + } + }, { "name": "msan", "displayName": "Debugging build with memory sanitizer on Clang-16", @@ -151,10 +164,6 @@ "CFLAGS": "-fsanitize=memory", "CXXFLAGS": "-fsanitize=memory", "LDFLAGS": "-fsanitize=memory" - }, - "cacheVariables": { - "BENCHMARK": "OFF", - "TESTING": "OFF" } }, { @@ -228,6 +237,16 @@ "MULTITHREADING": "ON" } }, + { + "name": "wasm-bench", + "displayName": "WASM benchmarking.", + "description": "WASM benchmarking.", + "inherits": "wasm-threads", + "binaryDir": "build-wasm-bench", + "environment": { + "CXXFLAGS": "-DWASMTIME_ENV_HACK" + } + }, { "name": "xray", "displayName": "Build with multi-threaded XRay Profiling", @@ -336,6 +355,11 @@ "inherits": "default", "configurePreset": "tsan" }, + { + "name": "ubsan", + "inherits": "default", + "configurePreset": "ubsan" + }, { "name": "coverage", "inherits": "default", @@ -368,6 +392,12 @@ "jobs": 0, "targets": ["barretenberg.wasm"] }, + { + "name": "wasm-bench", + "configurePreset": "wasm-bench", + "inheritConfigureEnvironment": true, + "jobs": 0 + }, { "name": "xray", "configurePreset": "xray", diff --git a/barretenberg/cpp/cmake/benchmark.cmake b/barretenberg/cpp/cmake/benchmark.cmake index c8f90548d66..10e13113b92 100644 --- a/barretenberg/cpp/cmake/benchmark.cmake +++ b/barretenberg/cpp/cmake/benchmark.cmake @@ -1,25 +1,19 @@ -if(NOT TESTING) - set(BENCHMARKS OFF) -endif() - -if(BENCHMARKS) - include(FetchContent) +include(FetchContent) - FetchContent_Declare( - benchmark - GIT_REPOSITORY https://github.com/google/benchmark - GIT_TAG v1.7.1 - FIND_PACKAGE_ARGS - ) +FetchContent_Declare( + benchmark + GIT_REPOSITORY https://github.com/AztecProtocol/google-benchmark + GIT_TAG 7638387d2727853d970fc9420dcf95cf3e9bd112 + FIND_PACKAGE_ARGS +) - set(BENCHMARK_ENABLE_TESTING OFF CACHE BOOL "Benchmark tests off") - set(BENCHMARK_ENABLE_INSTALL OFF CACHE BOOL "Benchmark installation off") +set(BENCHMARK_ENABLE_TESTING OFF CACHE BOOL "Benchmark tests off") +set(BENCHMARK_ENABLE_INSTALL OFF CACHE BOOL "Benchmark installation off") - FetchContent_MakeAvailable(benchmark) - if(NOT benchmark_FOUND) - # FetchContent_MakeAvailable calls FetchContent_Populate if `find_package` is unsuccessful - # so these variables will be available if we reach this case - set_property(DIRECTORY ${benchmark_SOURCE_DIR} PROPERTY EXCLUDE_FROM_ALL) - set_property(DIRECTORY ${benchmark_BINARY_DIR} PROPERTY EXCLUDE_FROM_ALL) - endif() +FetchContent_MakeAvailable(benchmark) +if(NOT benchmark_FOUND) + # FetchContent_MakeAvailable calls FetchContent_Populate if `find_package` is unsuccessful + # so these variables will be available if we reach this case + set_property(DIRECTORY ${benchmark_SOURCE_DIR} PROPERTY EXCLUDE_FROM_ALL) + set_property(DIRECTORY ${benchmark_BINARY_DIR} PROPERTY EXCLUDE_FROM_ALL) endif() diff --git a/barretenberg/cpp/cmake/gtest.cmake b/barretenberg/cpp/cmake/gtest.cmake index e86bf49756e..c3551ea481a 100644 --- a/barretenberg/cpp/cmake/gtest.cmake +++ b/barretenberg/cpp/cmake/gtest.cmake @@ -1,51 +1,49 @@ -if(TESTING) - include(GoogleTest) - include(FetchContent) - - FetchContent_Declare( - GTest - GIT_REPOSITORY https://github.com/google/googletest.git - # Version 1.12.1 is not compatible with WASI-SDK 12 - GIT_TAG release-1.10.0 - FIND_PACKAGE_ARGS +include(GoogleTest) +include(FetchContent) + +FetchContent_Declare( + GTest + GIT_REPOSITORY https://github.com/google/googletest.git + # Version 1.12.1 is not compatible with WASI-SDK 12 + GIT_TAG release-1.10.0 + FIND_PACKAGE_ARGS +) + +set(BUILD_GMOCK OFF CACHE BOOL "Build with gMock disabled") +set(INSTALL_GTEST OFF CACHE BOOL "gTest installation disabled") + +FetchContent_MakeAvailable(GTest) + +if (NOT GTest_FOUND) + # FetchContent_MakeAvailable calls FetchContent_Populate if `find_package` is unsuccessful + # so these variables will be available if we reach this case + set_property(DIRECTORY ${gtest_SOURCE_DIR} PROPERTY EXCLUDE_FROM_ALL) + set_property(DIRECTORY ${gtest_BINARY_DIR} PROPERTY EXCLUDE_FROM_ALL) + + # Disable all warning when compiling gtest + target_compile_options( + gtest + PRIVATE + -w ) - set(BUILD_GMOCK OFF CACHE BOOL "Build with gMock disabled") - set(INSTALL_GTEST OFF CACHE BOOL "gTest installation disabled") - - FetchContent_MakeAvailable(GTest) - - if (NOT GTest_FOUND) - # FetchContent_MakeAvailable calls FetchContent_Populate if `find_package` is unsuccessful - # so these variables will be available if we reach this case - set_property(DIRECTORY ${gtest_SOURCE_DIR} PROPERTY EXCLUDE_FROM_ALL) - set_property(DIRECTORY ${gtest_BINARY_DIR} PROPERTY EXCLUDE_FROM_ALL) - - # Disable all warning when compiling gtest - target_compile_options( + if(WASM) + target_compile_definitions( gtest PRIVATE - -w - ) - - if(WASM) - target_compile_definitions( - gtest - PRIVATE - -DGTEST_HAS_EXCEPTIONS=0 - -DGTEST_HAS_STREAM_REDIRECTION=0 - ) - endif() - - mark_as_advanced( - BUILD_GMOCK BUILD_GTEST BUILD_SHARED_LIBS - gmock_build_tests gtest_build_samples gtest_build_tests - gtest_disable_pthreads gtest_force_shared_crt gtest_hide_internal_symbols + -DGTEST_HAS_EXCEPTIONS=0 + -DGTEST_HAS_STREAM_REDIRECTION=0 ) - - add_library(GTest::gtest ALIAS gtest) - add_library(GTest::gtest_main ALIAS gtest_main) endif() - enable_testing() + mark_as_advanced( + BUILD_GMOCK BUILD_GTEST BUILD_SHARED_LIBS + gmock_build_tests gtest_build_samples gtest_build_tests + gtest_disable_pthreads gtest_force_shared_crt gtest_hide_internal_symbols + ) + + add_library(GTest::gtest ALIAS gtest) + add_library(GTest::gtest_main ALIAS gtest_main) endif() + +enable_testing() diff --git a/barretenberg/cpp/cmake/module.cmake b/barretenberg/cpp/cmake/module.cmake index 40bb18932be..d394c024b9f 100644 --- a/barretenberg/cpp/cmake/module.cmake +++ b/barretenberg/cpp/cmake/module.cmake @@ -65,7 +65,7 @@ function(barretenberg_module MODULE_NAME) endif() file(GLOB_RECURSE TEST_SOURCE_FILES *.test.cpp) - if(TESTING AND TEST_SOURCE_FILES) + if(TEST_SOURCE_FILES AND NOT FUZZING) add_library( ${MODULE_NAME}_test_objects OBJECT @@ -184,7 +184,6 @@ function(barretenberg_module MODULE_NAME) ${MODULE_NAME}_${FUZZER_NAME_STEM}_fuzzer PRIVATE "-fsanitize=fuzzer" - ${SANITIZER_OPTIONS} ) target_link_libraries( @@ -196,44 +195,47 @@ function(barretenberg_module MODULE_NAME) endif() file(GLOB_RECURSE BENCH_SOURCE_FILES *.bench.cpp) - if(BENCHMARKS AND BENCH_SOURCE_FILES) - add_library( - ${MODULE_NAME}_bench_objects - OBJECT - ${BENCH_SOURCE_FILES} - ) - list(APPEND lib_targets ${MODULE_NAME}_bench_objects) + if(BENCH_SOURCE_FILES AND NOT FUZZING) + foreach(BENCHMARK_SOURCE ${BENCH_SOURCE_FILES}) + get_filename_component(BENCHMARK_NAME ${BENCHMARK_SOURCE} NAME_WE) # extract name without extension + add_library( + ${BENCHMARK_NAME}_bench_objects + OBJECT + ${BENCHMARK_SOURCE} + ) + list(APPEND lib_targets ${BENCHMARK_NAME}_bench_objects) - target_link_libraries( - ${MODULE_NAME}_bench_objects - PRIVATE - benchmark::benchmark - ${TBB_IMPORTED_TARGETS} - ) + target_link_libraries( + ${BENCHMARK_NAME}_bench_objects + PRIVATE + benchmark::benchmark + ${TBB_IMPORTED_TARGETS} + ) - add_executable( - ${MODULE_NAME}_bench - $ - ) - list(APPEND exe_targets ${MODULE_NAME}_bench) + add_executable( + ${BENCHMARK_NAME}_bench + $ + ) + list(APPEND exe_targets ${MODULE_NAME}_bench) - target_link_libraries( - ${MODULE_NAME}_bench - PRIVATE - ${MODULE_LINK_NAME} - ${ARGN} - benchmark::benchmark - ${TBB_IMPORTED_TARGETS} - ) + target_link_libraries( + ${BENCHMARK_NAME}_bench + PRIVATE + ${MODULE_LINK_NAME} + ${ARGN} + benchmark::benchmark + ${TBB_IMPORTED_TARGETS} + ) - # enable msgpack downloading via dependency (solves race condition) - add_dependencies(${MODULE_NAME}_bench_objects msgpack-c) - add_dependencies(${MODULE_NAME}_bench msgpack-c) - add_custom_target( - run_${MODULE_NAME}_bench - COMMAND ${MODULE_NAME}_bench - WORKING_DIRECTORY ${CMAKE_BINARY_DIR} - ) + # enable msgpack downloading via dependency (solves race condition) + add_dependencies(${BENCHMARK_NAME}_bench_objects msgpack-c) + add_dependencies(${BENCHMARK_NAME}_bench msgpack-c) + add_custom_target( + run_${BENCHMARK_NAME}_bench + COMMAND ${BENCHMARK_NAME}_bench + WORKING_DIRECTORY ${CMAKE_BINARY_DIR} + ) + endforeach() endif() set(${MODULE_NAME}_lib_targets ${lib_targets} PARENT_SCOPE) diff --git a/barretenberg/cpp/docs/Fuzzing.md b/barretenberg/cpp/docs/Fuzzing.md index bbe85a62a1f..c413ba3ddfb 100644 --- a/barretenberg/cpp/docs/Fuzzing.md +++ b/barretenberg/cpp/docs/Fuzzing.md @@ -15,15 +15,11 @@ cmake --build --preset fuzzing Fuzzing build turns off building tests and benchmarks, since they are incompatible with libfuzzer interface. -To turn on address sanitizer add `-DADDRESS_SANITIZER=ON`. Note that address sanitizer can be used to explore crashes. +To turn on address sanitizer instead run `cmake --preset asan -DFUZZING=ON`. Note that address sanitizer can be used to explore crashes. Sometimes you might have to specify the address of llvm-symbolizer. You have to do it with `export ASAN_SYMBOLIZER_PATH=`. -For undefined behavior sanitizer `-DUNDEFINED_BEHAVIOUR_SANITIZER=ON`. +For undefined behavior sanitizer use `cmake --preset ubsan -DFUZZING=ON`. Note that the fuzzer can be orders of magnitude slower with ASan (2-3x slower) or UBSan on, so it is best to run a non-sanitized build first, minimize the testcase and then run it for a bit of time with sanitizers. -Building with clang 13 or later is recommended, since libfuzzer contains and by default utilizes the entropic power schedule, which is considered more efficient -than the standard one present in previous versions. -You can downloadload the latest clang+llvm release here: https://github.com/llvm/llvm-project/releases - To set up cmake with another version of clang and fuzzing on: ```bash diff --git a/barretenberg/cpp/scripts/_benchmark_remote_lock.sh b/barretenberg/cpp/scripts/_benchmark_remote_lock.sh new file mode 100644 index 00000000000..551a26b9070 --- /dev/null +++ b/barretenberg/cpp/scripts/_benchmark_remote_lock.sh @@ -0,0 +1,27 @@ +# NOTE: This script is NOT meant to be ran, only sourced. +# This sets up all the necessary machinery to lock ~/BENCHMARK_IN_PROGRESS +# + +# Function to clean up lock file +function cleanup() { + ssh $BB_SSH_KEY $BB_SSH_INSTANCE "rm -f ~/BENCHMARK_IN_PROGRESS" + echo "Benchmarking lock deleted." +} + +# Check for existing lock file +if ssh $BB_SSH_KEY $BB_SSH_INSTANCE "test -f ~/BENCHMARK_IN_PROGRESS"; then + echo "Benchmarking is already in progress. If htop on the remote machine is not active, ~/BENCHMARK_IN_PROGRESS may need to be deleted." + # Important: Exits the script that called this! + # This implements the lock + exit 1 +fi + +# Create lock file +ssh $BB_SSH_KEY $BB_SSH_INSTANCE "touch ~/BENCHMARK_IN_PROGRESS" + +echo "Benchmarking lock created at ~/BENCHMARK_IN_PROGRESS." + +# Trap to ensure cleanup runs on ANY exit, including from a signal +trap cleanup EXIT + +# don't exit, the caller script will run \ No newline at end of file diff --git a/barretenberg/cpp/scripts/benchmark.sh b/barretenberg/cpp/scripts/benchmark.sh new file mode 100755 index 00000000000..2c51a0c0485 --- /dev/null +++ b/barretenberg/cpp/scripts/benchmark.sh @@ -0,0 +1,14 @@ +#!/usr/bin/env bash +set -eu + +BENCHMARK=${1:-goblin_bench} + +# Move above script dir. +cd $(dirname $0)/.. + +# Configure and build. +cmake --preset clang16 +cmake --build --preset clang16 --target $BENCHMARK + +cd build +./bin/$BENCHMARK \ No newline at end of file diff --git a/barretenberg/cpp/scripts/benchmark_remote.sh b/barretenberg/cpp/scripts/benchmark_remote.sh new file mode 100755 index 00000000000..e1d5907eab2 --- /dev/null +++ b/barretenberg/cpp/scripts/benchmark_remote.sh @@ -0,0 +1,28 @@ +#!/usr/bin/env bash +# This script automates the process of benchmarking native on a remote EC2 instance. +# Prerequisites: +# 1. Define the following environment variables: +# - BB_SSH_KEY: SSH key for EC2 instance, e.g., '-i key.pem' +# - BB_SSH_INSTANCE: EC2 instance URL +# - BB_SSH_CPP_PATH: Path to barretenberg/cpp in a cloned repository on the EC2 instance +set -eu + +BENCHMARK=${1:-goblin_bench} +COMMAND=${2:-./$BENCHMARK} + +# Move above script dir. +cd $(dirname $0)/.. + +# Create lock file +ssh $BB_SSH_KEY $BB_SSH_INSTANCE "touch ~/BENCHMARKING_IN_PROGRESS" + +# Configure and build. +cmake --preset clang16 +cmake --build --preset clang16 --target $BENCHMARK + +source scripts/_benchmark_remote_lock.sh + +cd build +scp $BB_SSH_KEY ./bin/$BENCHMARK $BB_SSH_INSTANCE:$BB_SSH_CPP_PATH/build +ssh $BB_SSH_KEY $BB_SSH_INSTANCE \ + "cd $BB_SSH_CPP_PATH/build ; $COMMAND" diff --git a/barretenberg/cpp/scripts/benchmark_wasm.sh b/barretenberg/cpp/scripts/benchmark_wasm.sh new file mode 100755 index 00000000000..f4288604f7a --- /dev/null +++ b/barretenberg/cpp/scripts/benchmark_wasm.sh @@ -0,0 +1,14 @@ +#!/usr/bin/env bash +set -eu + +BENCHMARK=${1:-goblin_bench} + +# Move above script dir. +cd $(dirname $0)/.. + +# Configure and build. +cmake --preset wasm-bench +cmake --build --preset wasm-bench --target $BENCHMARK + +cd build-wasm-bench +wasmtime run -Wthreads=y -Sthreads=y ./bin/$BENCHMARK \ No newline at end of file diff --git a/barretenberg/cpp/scripts/benchmark_wasm_remote.sh b/barretenberg/cpp/scripts/benchmark_wasm_remote.sh new file mode 100755 index 00000000000..f131cc63a6f --- /dev/null +++ b/barretenberg/cpp/scripts/benchmark_wasm_remote.sh @@ -0,0 +1,25 @@ +#!/usr/bin/env bash +# This script automates the process of benchmarking WASM on a remote EC2 instance. +# Prerequisites: +# 1. Define the following environment variables: +# - BB_SSH_KEY: SSH key for EC2 instance, e.g., '-i key.pem' +# - BB_SSH_INSTANCE: EC2 instance URL +# - BB_SSH_CPP_PATH: Path to barretenberg/cpp in a cloned repository on the EC2 instance +set -eu + +BENCHMARK=${1:-goblin_bench} +COMMAND=${2:-./$BENCHMARK} + +# Move above script dir. +cd $(dirname $0)/.. + +# Configure and build. +cmake --preset wasm-bench +cmake --build --preset wasm-bench --target $BENCHMARK + +source scripts/_benchmark_remote_lock.sh + +cd build-wasm-bench +scp $BB_SSH_KEY ./bin/$BENCHMARK $BB_SSH_INSTANCE:$BB_SSH_CPP_PATH/build-wasm-bench +ssh $BB_SSH_KEY $BB_SSH_INSTANCE \ + "cd $BB_SSH_CPP_PATH/build-wasm-bench ; /home/ubuntu/.wasmtime/bin/wasmtime run -Wthreads=y -Sthreads=y $COMMAND" diff --git a/barretenberg/cpp/src/CMakeLists.txt b/barretenberg/cpp/src/CMakeLists.txt index 352a7d1cafe..42734bf5cd1 100644 --- a/barretenberg/cpp/src/CMakeLists.txt +++ b/barretenberg/cpp/src/CMakeLists.txt @@ -12,7 +12,7 @@ set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib) # Specifying `-Wno-${ERROR_NAME}` will silence the error completely. # To preserve the warning, but prevent them from causing the build to fail, # use the flag `-Wno-error=${ERROR_NAME}` -add_compile_options(-Werror -Wall -Wextra -Wconversion -Wsign-conversion) +add_compile_options(-Werror -Wall -Wextra -Wconversion -Wsign-conversion -Wfatal-errors) if(CMAKE_CXX_COMPILER_ID MATCHES "Clang") add_compile_options(-fcolor-diagnostics -fconstexpr-steps=100000000) @@ -85,9 +85,7 @@ if(SMT) add_subdirectory(barretenberg/smt_verification) endif() -if(BENCHMARKS) - add_subdirectory(barretenberg/benchmark) -endif() +add_subdirectory(barretenberg/benchmark) include(GNUInstallDirs) diff --git a/barretenberg/cpp/src/barretenberg/benchmark/CMakeLists.txt b/barretenberg/cpp/src/barretenberg/benchmark/CMakeLists.txt index e86e72df09d..285f2bb5937 100644 --- a/barretenberg/cpp/src/barretenberg/benchmark/CMakeLists.txt +++ b/barretenberg/cpp/src/barretenberg/benchmark/CMakeLists.txt @@ -1,4 +1,3 @@ -add_subdirectory(commit_bench) add_subdirectory(decrypt_bench) add_subdirectory(ipa_bench) add_subdirectory(pippenger_bench) diff --git a/barretenberg/cpp/src/barretenberg/benchmark/basics_bench/CMakeLists.txt b/barretenberg/cpp/src/barretenberg/benchmark/basics_bench/CMakeLists.txt index d23c4f6597f..1740ea9ecb6 100644 --- a/barretenberg/cpp/src/barretenberg/benchmark/basics_bench/CMakeLists.txt +++ b/barretenberg/cpp/src/barretenberg/benchmark/basics_bench/CMakeLists.txt @@ -1,18 +1 @@ -# Each source represents a separate benchmark suite -set(BENCHMARK_SOURCES - basics.bench.cpp -) - -# Required libraries for benchmark suites -set(LINKED_LIBRARIES - benchmark::benchmark - ecc -) - -# Add executable and custom target for each suite, e.g. ultra_honk_bench -foreach(BENCHMARK_SOURCE ${BENCHMARK_SOURCES}) - get_filename_component(BENCHMARK_NAME ${BENCHMARK_SOURCE} NAME_WE) # extract name without extension - add_executable(${BENCHMARK_NAME}_bench ${BENCHMARK_SOURCE}) - target_link_libraries(${BENCHMARK_NAME}_bench ${LINKED_LIBRARIES}) - add_custom_target(run_${BENCHMARK_NAME} COMMAND ${BENCHMARK_NAME} WORKING_DIRECTORY ${CMAKE_BINARY_DIR}) -endforeach() \ No newline at end of file +barretenberg_module(basics_bench ecc) \ No newline at end of file diff --git a/barretenberg/cpp/src/barretenberg/benchmark/commit_bench/CMakeLists.txt b/barretenberg/cpp/src/barretenberg/benchmark/commit_bench/CMakeLists.txt deleted file mode 100644 index 3bca58463b1..00000000000 --- a/barretenberg/cpp/src/barretenberg/benchmark/commit_bench/CMakeLists.txt +++ /dev/null @@ -1,18 +0,0 @@ -# Each source represents a separate benchmark suite -set(BENCHMARK_SOURCES - commit.bench.cpp -) - -# Required libraries for benchmark suites -set(LINKED_LIBRARIES - commitment_schemes - benchmark::benchmark -) - -# Add executable and custom target for each suite, e.g. ultra_honk_bench -foreach(BENCHMARK_SOURCE ${BENCHMARK_SOURCES}) - get_filename_component(BENCHMARK_NAME ${BENCHMARK_SOURCE} NAME_WE) # extract name without extension - add_executable(${BENCHMARK_NAME}_bench main.bench.cpp ${BENCHMARK_SOURCE}) - target_link_libraries(${BENCHMARK_NAME}_bench ${LINKED_LIBRARIES}) - add_custom_target(run_${BENCHMARK_NAME} COMMAND ${BENCHMARK_NAME} WORKING_DIRECTORY ${CMAKE_BINARY_DIR}) -endforeach() \ No newline at end of file diff --git a/barretenberg/cpp/src/barretenberg/benchmark/commit_bench/main.bench.cpp b/barretenberg/cpp/src/barretenberg/benchmark/commit_bench/main.bench.cpp deleted file mode 100644 index 71fefa04722..00000000000 --- a/barretenberg/cpp/src/barretenberg/benchmark/commit_bench/main.bench.cpp +++ /dev/null @@ -1,3 +0,0 @@ -#include - -BENCHMARK_MAIN(); diff --git a/barretenberg/cpp/src/barretenberg/benchmark/decrypt_bench/CMakeLists.txt b/barretenberg/cpp/src/barretenberg/benchmark/decrypt_bench/CMakeLists.txt index c58e1e64171..da70f1faed8 100644 --- a/barretenberg/cpp/src/barretenberg/benchmark/decrypt_bench/CMakeLists.txt +++ b/barretenberg/cpp/src/barretenberg/benchmark/decrypt_bench/CMakeLists.txt @@ -1,11 +1,13 @@ -add_executable( - decrypt_bench - main.cpp -) +if (NOT FUZZING) + add_executable( + decrypt_bench + main.cpp + ) -target_link_libraries( - decrypt_bench - PRIVATE - ecc - common -) \ No newline at end of file + target_link_libraries( + decrypt_bench + PRIVATE + ecc + common + ) +endif() \ No newline at end of file diff --git a/barretenberg/cpp/src/barretenberg/benchmark/goblin_bench/CMakeLists.txt b/barretenberg/cpp/src/barretenberg/benchmark/goblin_bench/CMakeLists.txt index 5b3734936f2..b7bd08f19cb 100644 --- a/barretenberg/cpp/src/barretenberg/benchmark/goblin_bench/CMakeLists.txt +++ b/barretenberg/cpp/src/barretenberg/benchmark/goblin_bench/CMakeLists.txt @@ -1,21 +1 @@ -# Each source represents a separate benchmark suite -set(BENCHMARK_SOURCES - goblin.bench.cpp - eccvm.bench.cpp -) - -# Required libraries for benchmark suites -set(LINKED_LIBRARIES - ultra_honk - eccvm - stdlib_recursion - benchmark::benchmark -) - -# Add executable and custom target for each suite, e.g. ultra_honk_bench -foreach(BENCHMARK_SOURCE ${BENCHMARK_SOURCES}) - get_filename_component(BENCHMARK_NAME ${BENCHMARK_SOURCE} NAME_WE) # extract name without extension - add_executable(${BENCHMARK_NAME}_bench main.bench.cpp ${BENCHMARK_SOURCE}) - target_link_libraries(${BENCHMARK_NAME}_bench ${LINKED_LIBRARIES}) - add_custom_target(run_${BENCHMARK_NAME} COMMAND ${BENCHMARK_NAME} WORKING_DIRECTORY ${CMAKE_BINARY_DIR}) -endforeach() \ No newline at end of file +barretenberg_module(goblin_bench ultra_honk eccvm stdlib_recursion) \ No newline at end of file diff --git a/barretenberg/cpp/src/barretenberg/benchmark/goblin_bench/eccvm.bench.cpp b/barretenberg/cpp/src/barretenberg/benchmark/goblin_bench/eccvm.bench.cpp index 4c89b375de5..949658c5bd0 100644 --- a/barretenberg/cpp/src/barretenberg/benchmark/goblin_bench/eccvm.bench.cpp +++ b/barretenberg/cpp/src/barretenberg/benchmark/goblin_bench/eccvm.bench.cpp @@ -70,4 +70,6 @@ void eccvm_prove(State& state) noexcept BENCHMARK(eccvm_generate_prover)->Unit(kMillisecond)->DenseRange(10, 20); BENCHMARK(eccvm_prove)->Unit(kMillisecond)->DenseRange(10, 20); -} // namespace \ No newline at end of file +} // namespace + +BENCHMARK_MAIN(); diff --git a/barretenberg/cpp/src/barretenberg/benchmark/goblin_bench/goblin.bench.cpp b/barretenberg/cpp/src/barretenberg/benchmark/goblin_bench/goblin.bench.cpp index 839c8237de4..4389074c83b 100644 --- a/barretenberg/cpp/src/barretenberg/benchmark/goblin_bench/goblin.bench.cpp +++ b/barretenberg/cpp/src/barretenberg/benchmark/goblin_bench/goblin.bench.cpp @@ -133,4 +133,6 @@ void goblin_translator_prove(State& state) noexcept BENCHMARK(goblin_full)->Unit(kMillisecond)->DenseRange(0, 7); BENCHMARK(goblin_accumulate)->Unit(kMillisecond)->DenseRange(0, 7); BENCHMARK(goblin_eccvm_prove)->Unit(kMillisecond)->DenseRange(0, 7); -BENCHMARK(goblin_translator_prove)->Unit(kMillisecond)->DenseRange(0, 7); \ No newline at end of file +BENCHMARK(goblin_translator_prove)->Unit(kMillisecond)->DenseRange(0, 7); + +BENCHMARK_MAIN(); diff --git a/barretenberg/cpp/src/barretenberg/benchmark/goblin_bench/main.bench.cpp b/barretenberg/cpp/src/barretenberg/benchmark/goblin_bench/main.bench.cpp deleted file mode 100644 index 71fefa04722..00000000000 --- a/barretenberg/cpp/src/barretenberg/benchmark/goblin_bench/main.bench.cpp +++ /dev/null @@ -1,3 +0,0 @@ -#include - -BENCHMARK_MAIN(); diff --git a/barretenberg/cpp/src/barretenberg/benchmark/ipa_bench/CMakeLists.txt b/barretenberg/cpp/src/barretenberg/benchmark/ipa_bench/CMakeLists.txt index 6e66ce2cf36..25d49f8ddea 100644 --- a/barretenberg/cpp/src/barretenberg/benchmark/ipa_bench/CMakeLists.txt +++ b/barretenberg/cpp/src/barretenberg/benchmark/ipa_bench/CMakeLists.txt @@ -1,18 +1 @@ -# Each source represents a separate benchmark suite -set(BENCHMARK_SOURCES - ipa.bench.cpp -) - -# Required libraries for benchmark suites -set(LINKED_LIBRARIES - benchmark::benchmark - ultra_honk -) - -# Add executable and custom target for each suite, e.g. ultra_honk_bench -foreach(BENCHMARK_SOURCE ${BENCHMARK_SOURCES}) - get_filename_component(BENCHMARK_NAME ${BENCHMARK_SOURCE} NAME_WE) # extract name without extension - add_executable(${BENCHMARK_NAME}_bench ${BENCHMARK_SOURCE}) - target_link_libraries(${BENCHMARK_NAME}_bench ${LINKED_LIBRARIES}) - add_custom_target(run_${BENCHMARK_NAME} COMMAND ${BENCHMARK_NAME} WORKING_DIRECTORY ${CMAKE_BINARY_DIR}) -endforeach() \ No newline at end of file +barretenberg_module(ipa_bench ultra_honk) diff --git a/barretenberg/cpp/src/barretenberg/benchmark/pippenger_bench/CMakeLists.txt b/barretenberg/cpp/src/barretenberg/benchmark/pippenger_bench/CMakeLists.txt index bbcbaa8677d..95bf621c1e0 100644 --- a/barretenberg/cpp/src/barretenberg/benchmark/pippenger_bench/CMakeLists.txt +++ b/barretenberg/cpp/src/barretenberg/benchmark/pippenger_bench/CMakeLists.txt @@ -1,13 +1,15 @@ -add_executable(pippenger_bench main.cpp) +if (NOT FUZZING) + add_executable(pippenger_bench main.cpp) -target_link_libraries( - pippenger_bench - polynomials - srs -) + target_link_libraries( + pippenger_bench + polynomials + srs + ) -add_custom_target( - run_pippenger_bench - COMMAND pippenger_bench - WORKING_DIRECTORY ${CMAKE_BINARY_DIR} -) \ No newline at end of file + add_custom_target( + run_pippenger_bench + COMMAND pippenger_bench + WORKING_DIRECTORY ${CMAKE_BINARY_DIR} + ) +endif() \ No newline at end of file diff --git a/barretenberg/cpp/src/barretenberg/benchmark/plonk_bench/CMakeLists.txt b/barretenberg/cpp/src/barretenberg/benchmark/plonk_bench/CMakeLists.txt index 0746ecaa44e..ddcf9da9d11 100644 --- a/barretenberg/cpp/src/barretenberg/benchmark/plonk_bench/CMakeLists.txt +++ b/barretenberg/cpp/src/barretenberg/benchmark/plonk_bench/CMakeLists.txt @@ -1,20 +1 @@ -# Each source represents a separate benchmark suite -set(BENCHMARK_SOURCES - plonk.bench.cpp - standard_plonk.bench.cpp -) - -# Required libraries for benchmark suites -set(LINKED_LIBRARIES - plonk - stdlib_primitives - benchmark::benchmark -) - -# Add executable and custom target for each suite, e.g. ultra_honk_bench -foreach(BENCHMARK_SOURCE ${BENCHMARK_SOURCES}) - get_filename_component(BENCHMARK_NAME ${BENCHMARK_SOURCE} NAME_WE) # extract name without extension - add_executable(${BENCHMARK_NAME}_bench main.bench.cpp ${BENCHMARK_SOURCE}) - target_link_libraries(${BENCHMARK_NAME}_bench ${LINKED_LIBRARIES}) - add_custom_target(run_${BENCHMARK_NAME} COMMAND ${BENCHMARK_NAME} WORKING_DIRECTORY ${CMAKE_BINARY_DIR}) -endforeach() +barretenberg_module(plonk_bench plonk stdlib_primitives) diff --git a/barretenberg/cpp/src/barretenberg/benchmark/plonk_bench/main.bench.cpp b/barretenberg/cpp/src/barretenberg/benchmark/plonk_bench/main.bench.cpp deleted file mode 100644 index 71fefa04722..00000000000 --- a/barretenberg/cpp/src/barretenberg/benchmark/plonk_bench/main.bench.cpp +++ /dev/null @@ -1,3 +0,0 @@ -#include - -BENCHMARK_MAIN(); diff --git a/barretenberg/cpp/src/barretenberg/benchmark/plonk_bench/plonk.bench.cpp b/barretenberg/cpp/src/barretenberg/benchmark/plonk_bench/plonk.bench.cpp index 0089fa48b42..64cfe4f92f2 100644 --- a/barretenberg/cpp/src/barretenberg/benchmark/plonk_bench/plonk.bench.cpp +++ b/barretenberg/cpp/src/barretenberg/benchmark/plonk_bench/plonk.bench.cpp @@ -107,4 +107,6 @@ void verify_proofs_bench(State& state) noexcept state.ResumeTiming(); } } -BENCHMARK(verify_proofs_bench)->RangeMultiplier(2)->Range(START, MAX_GATES); \ No newline at end of file +BENCHMARK(verify_proofs_bench)->RangeMultiplier(2)->Range(START, MAX_GATES); + +BENCHMARK_MAIN(); diff --git a/barretenberg/cpp/src/barretenberg/benchmark/plonk_bench/standard_plonk.bench.cpp b/barretenberg/cpp/src/barretenberg/benchmark/plonk_bench/standard_plonk.bench.cpp index 1a1eff70e7a..c4d85d3fde0 100644 --- a/barretenberg/cpp/src/barretenberg/benchmark/plonk_bench/standard_plonk.bench.cpp +++ b/barretenberg/cpp/src/barretenberg/benchmark/plonk_bench/standard_plonk.bench.cpp @@ -20,4 +20,6 @@ static void construct_proof_standard_power_of_2(State& state) noexcept BENCHMARK(construct_proof_standard_power_of_2) // 2**15 gates to 2**20 gates ->DenseRange(15, 20) - ->Unit(::benchmark::kMillisecond); \ No newline at end of file + ->Unit(::benchmark::kMillisecond); + +BENCHMARK_MAIN(); \ No newline at end of file diff --git a/barretenberg/cpp/src/barretenberg/benchmark/protogalaxy_bench/CMakeLists.txt b/barretenberg/cpp/src/barretenberg/benchmark/protogalaxy_bench/CMakeLists.txt index 75ba98e2d9e..5547f9311d3 100644 --- a/barretenberg/cpp/src/barretenberg/benchmark/protogalaxy_bench/CMakeLists.txt +++ b/barretenberg/cpp/src/barretenberg/benchmark/protogalaxy_bench/CMakeLists.txt @@ -1,20 +1 @@ -# Each source represents a separate benchmark suite -set(BENCHMARK_SOURCES - protogalaxy.bench.cpp -) - -# Required libraries for benchmark suites -set(LINKED_LIBRARIES - ultra_honk - protogalaxy - stdlib_primitives - benchmark::benchmark -) - -# Add executable and custom target for each suite, e.g. ultra_honk_bench -foreach(BENCHMARK_SOURCE ${BENCHMARK_SOURCES}) - get_filename_component(BENCHMARK_NAME ${BENCHMARK_SOURCE} NAME_WE) # extract name without extension - add_executable(${BENCHMARK_NAME}_bench main.bench.cpp ${BENCHMARK_SOURCE}) - target_link_libraries(${BENCHMARK_NAME}_bench ${LINKED_LIBRARIES}) - add_custom_target(run_${BENCHMARK_NAME} COMMAND ${BENCHMARK_NAME} WORKING_DIRECTORY ${CMAKE_BINARY_DIR}) -endforeach() \ No newline at end of file +barretenberg_module(protogalaxy_bench ultra_honk protogalaxy stdlib_primitives) diff --git a/barretenberg/cpp/src/barretenberg/benchmark/protogalaxy_bench/main.bench.cpp b/barretenberg/cpp/src/barretenberg/benchmark/protogalaxy_bench/main.bench.cpp deleted file mode 100644 index 71fefa04722..00000000000 --- a/barretenberg/cpp/src/barretenberg/benchmark/protogalaxy_bench/main.bench.cpp +++ /dev/null @@ -1,3 +0,0 @@ -#include - -BENCHMARK_MAIN(); diff --git a/barretenberg/cpp/src/barretenberg/benchmark/protogalaxy_bench/protogalaxy.bench.cpp b/barretenberg/cpp/src/barretenberg/benchmark/protogalaxy_bench/protogalaxy.bench.cpp index b0a4f05afbf..26bebca3da7 100644 --- a/barretenberg/cpp/src/barretenberg/benchmark/protogalaxy_bench/protogalaxy.bench.cpp +++ b/barretenberg/cpp/src/barretenberg/benchmark/protogalaxy_bench/protogalaxy.bench.cpp @@ -38,4 +38,6 @@ void fold_one(State& state) noexcept } BENCHMARK(fold_one)->/* vary the circuit size */ DenseRange(14, 20)->Unit(kMillisecond); -} // namespace bb::honk \ No newline at end of file +} // namespace bb::honk + +BENCHMARK_MAIN(); diff --git a/barretenberg/cpp/src/barretenberg/benchmark/relations_bench/CMakeLists.txt b/barretenberg/cpp/src/barretenberg/benchmark/relations_bench/CMakeLists.txt index 31f4834f4bc..7b4f4e0307b 100644 --- a/barretenberg/cpp/src/barretenberg/benchmark/relations_bench/CMakeLists.txt +++ b/barretenberg/cpp/src/barretenberg/benchmark/relations_bench/CMakeLists.txt @@ -1,20 +1 @@ -# Each source represents a separate benchmark suite -set(BENCHMARK_SOURCES - barycentric.bench.cpp - relations.bench.cpp -) - -# Required libraries for benchmark suites -set(LINKED_LIBRARIES - proof_system - benchmark::benchmark - transcript -) - -# Add executable and custom target for each suite, e.g. ultra_honk_bench -foreach(BENCHMARK_SOURCE ${BENCHMARK_SOURCES}) - get_filename_component(BENCHMARK_NAME ${BENCHMARK_SOURCE} NAME_WE) # extract name without extension - add_executable(${BENCHMARK_NAME}_bench main.bench.cpp ${BENCHMARK_SOURCE}) - target_link_libraries(${BENCHMARK_NAME}_bench ${LINKED_LIBRARIES}) - add_custom_target(run_${BENCHMARK_NAME} COMMAND ${BENCHMARK_NAME} WORKING_DIRECTORY ${CMAKE_BINARY_DIR}) -endforeach() \ No newline at end of file +barretenberg_module(relations_bench proof_system transcript) diff --git a/barretenberg/cpp/src/barretenberg/benchmark/relations_bench/barycentric.bench.cpp b/barretenberg/cpp/src/barretenberg/benchmark/relations_bench/barycentric.bench.cpp index b11d6b4771a..64db936c71a 100644 --- a/barretenberg/cpp/src/barretenberg/benchmark/relations_bench/barycentric.bench.cpp +++ b/barretenberg/cpp/src/barretenberg/benchmark/relations_bench/barycentric.bench.cpp @@ -23,4 +23,6 @@ void extend_2_to_6(State& state) noexcept } BENCHMARK(extend_2_to_6); -} // namespace bb::benchmark \ No newline at end of file +} // namespace bb::benchmark + +BENCHMARK_MAIN(); \ No newline at end of file diff --git a/barretenberg/cpp/src/barretenberg/benchmark/relations_bench/main.bench.cpp b/barretenberg/cpp/src/barretenberg/benchmark/relations_bench/main.bench.cpp deleted file mode 100644 index 71fefa04722..00000000000 --- a/barretenberg/cpp/src/barretenberg/benchmark/relations_bench/main.bench.cpp +++ /dev/null @@ -1,3 +0,0 @@ -#include - -BENCHMARK_MAIN(); diff --git a/barretenberg/cpp/src/barretenberg/benchmark/relations_bench/relations.bench.cpp b/barretenberg/cpp/src/barretenberg/benchmark/relations_bench/relations.bench.cpp index 7541c609754..076da57aa17 100644 --- a/barretenberg/cpp/src/barretenberg/benchmark/relations_bench/relations.bench.cpp +++ b/barretenberg/cpp/src/barretenberg/benchmark/relations_bench/relations.bench.cpp @@ -57,3 +57,5 @@ BENCHMARK(execute_relation>); BENCHMARK(execute_relation>); } // namespace bb::benchmark::relations + +BENCHMARK_MAIN(); \ No newline at end of file diff --git a/barretenberg/cpp/src/barretenberg/benchmark/ultra_bench/CMakeLists.txt b/barretenberg/cpp/src/barretenberg/benchmark/ultra_bench/CMakeLists.txt index 9c0826d009c..323ad1613b0 100644 --- a/barretenberg/cpp/src/barretenberg/benchmark/ultra_bench/CMakeLists.txt +++ b/barretenberg/cpp/src/barretenberg/benchmark/ultra_bench/CMakeLists.txt @@ -1,25 +1,6 @@ -# Each source represents a separate benchmark suite -set(BENCHMARK_SOURCES - ultra_honk.bench.cpp - ultra_honk_rounds.bench.cpp - ultra_plonk.bench.cpp - ultra_plonk_rounds.bench.cpp -) - -# Required libraries for benchmark suites -set(LINKED_LIBRARIES +barretenberg_module(ultra_bench ultra_honk stdlib_sha256 stdlib_keccak stdlib_merkle_tree - stdlib_recursion - benchmark::benchmark -) - -# Add executable and custom target for each suite, e.g. ultra_honk_bench -foreach(BENCHMARK_SOURCE ${BENCHMARK_SOURCES}) - get_filename_component(BENCHMARK_NAME ${BENCHMARK_SOURCE} NAME_WE) # extract name without extension - add_executable(${BENCHMARK_NAME}_bench main.bench.cpp ${BENCHMARK_SOURCE}) - target_link_libraries(${BENCHMARK_NAME}_bench ${LINKED_LIBRARIES}) - add_custom_target(run_${BENCHMARK_NAME} COMMAND ${BENCHMARK_NAME} WORKING_DIRECTORY ${CMAKE_BINARY_DIR}) -endforeach() \ No newline at end of file + stdlib_recursion) diff --git a/barretenberg/cpp/src/barretenberg/benchmark/ultra_bench/main.bench.cpp b/barretenberg/cpp/src/barretenberg/benchmark/ultra_bench/main.bench.cpp deleted file mode 100644 index 71fefa04722..00000000000 --- a/barretenberg/cpp/src/barretenberg/benchmark/ultra_bench/main.bench.cpp +++ /dev/null @@ -1,3 +0,0 @@ -#include - -BENCHMARK_MAIN(); diff --git a/barretenberg/cpp/src/barretenberg/benchmark/ultra_bench/mock_proofs.hpp b/barretenberg/cpp/src/barretenberg/benchmark/ultra_bench/mock_proofs.hpp index 6bbc81a5872..8e7284729b6 100644 --- a/barretenberg/cpp/src/barretenberg/benchmark/ultra_bench/mock_proofs.hpp +++ b/barretenberg/cpp/src/barretenberg/benchmark/ultra_bench/mock_proofs.hpp @@ -35,7 +35,7 @@ template void generate_basic_arithmetic_circuit(Builder& buil stdlib::field_t c(&builder); size_t passes = (1UL << log2_num_gates) / 4 - 4; if (static_cast(passes) <= 0) { - throw std::runtime_error("too few gates"); + throw_or_abort("too few gates"); } for (size_t i = 0; i < passes; ++i) { diff --git a/barretenberg/cpp/src/barretenberg/benchmark/ultra_bench/ultra_honk.bench.cpp b/barretenberg/cpp/src/barretenberg/benchmark/ultra_bench/ultra_honk.bench.cpp index f560475a7af..fb99554b940 100644 --- a/barretenberg/cpp/src/barretenberg/benchmark/ultra_bench/ultra_honk.bench.cpp +++ b/barretenberg/cpp/src/barretenberg/benchmark/ultra_bench/ultra_honk.bench.cpp @@ -49,4 +49,6 @@ BENCHMARK_CAPTURE(construct_proof_ultrahonk, BENCHMARK(construct_proof_ultrahonk_power_of_2) // 2**15 gates to 2**20 gates ->DenseRange(15, 20) - ->Unit(kMillisecond); \ No newline at end of file + ->Unit(kMillisecond); + +BENCHMARK_MAIN(); diff --git a/barretenberg/cpp/src/barretenberg/benchmark/ultra_bench/ultra_honk_rounds.bench.cpp b/barretenberg/cpp/src/barretenberg/benchmark/ultra_bench/ultra_honk_rounds.bench.cpp index 8fd06307cec..c931892ec4b 100644 --- a/barretenberg/cpp/src/barretenberg/benchmark/ultra_bench/ultra_honk_rounds.bench.cpp +++ b/barretenberg/cpp/src/barretenberg/benchmark/ultra_bench/ultra_honk_rounds.bench.cpp @@ -78,3 +78,5 @@ ROUND_BENCHMARK(LOG_DERIVATIVE_INVERSE)->Iterations(1); ROUND_BENCHMARK(GRAND_PRODUCT_COMPUTATION)->Iterations(1); ROUND_BENCHMARK(RELATION_CHECK); ROUND_BENCHMARK(ZEROMORPH); + +BENCHMARK_MAIN(); diff --git a/barretenberg/cpp/src/barretenberg/benchmark/ultra_bench/ultra_plonk.bench.cpp b/barretenberg/cpp/src/barretenberg/benchmark/ultra_bench/ultra_plonk.bench.cpp index a02fba5eb8a..ea3df79e241 100644 --- a/barretenberg/cpp/src/barretenberg/benchmark/ultra_bench/ultra_plonk.bench.cpp +++ b/barretenberg/cpp/src/barretenberg/benchmark/ultra_bench/ultra_plonk.bench.cpp @@ -47,4 +47,6 @@ BENCHMARK_CAPTURE(construct_proof_ultraplonk, BENCHMARK(construct_proof_ultraplonk_power_of_2) // 2**15 gates to 2**20 gates ->DenseRange(15, 20) - ->Unit(kMillisecond); \ No newline at end of file + ->Unit(kMillisecond); + +BENCHMARK_MAIN(); diff --git a/barretenberg/cpp/src/barretenberg/benchmark/ultra_bench/ultra_plonk_rounds.bench.cpp b/barretenberg/cpp/src/barretenberg/benchmark/ultra_bench/ultra_plonk_rounds.bench.cpp index b78b825ce77..ca0d1bd021c 100644 --- a/barretenberg/cpp/src/barretenberg/benchmark/ultra_bench/ultra_plonk_rounds.bench.cpp +++ b/barretenberg/cpp/src/barretenberg/benchmark/ultra_bench/ultra_plonk_rounds.bench.cpp @@ -77,3 +77,5 @@ ROUND_BENCHMARK(THIRD_FIAT_SHAMIR_BETA_GAMMA)->Iterations(1); ROUND_BENCHMARK(FOURTH_FIAT_SHAMIR_ALPHA_AND_COMMIT)->Iterations(1); ROUND_BENCHMARK(FIFTH_COMPUTE_QUOTIENT_EVALUTION)->Iterations(1); ROUND_BENCHMARK(SIXTH_BATCH_OPEN)->Iterations(1); + +BENCHMARK_MAIN(); diff --git a/barretenberg/cpp/src/barretenberg/benchmark/widgets_bench/CMakeLists.txt b/barretenberg/cpp/src/barretenberg/benchmark/widgets_bench/CMakeLists.txt index 35eebc6d27d..588ffe92d33 100644 --- a/barretenberg/cpp/src/barretenberg/benchmark/widgets_bench/CMakeLists.txt +++ b/barretenberg/cpp/src/barretenberg/benchmark/widgets_bench/CMakeLists.txt @@ -1,21 +1 @@ -# Each source represents a separate benchmark suite -set(BENCHMARK_SOURCES - widget.bench.cpp -) - -# Required libraries for benchmark suites -set(LINKED_LIBRARIES - polynomials - proof_system - benchmark::benchmark - transcript - stdlib_primitives -) - -# Add executable and custom target for each suite, e.g. ultra_honk_bench -foreach(BENCHMARK_SOURCE ${BENCHMARK_SOURCES}) - get_filename_component(BENCHMARK_NAME ${BENCHMARK_SOURCE} NAME_WE) # extract name without extension - add_executable(${BENCHMARK_NAME}_bench main.bench.cpp ${BENCHMARK_SOURCE}) - target_link_libraries(${BENCHMARK_NAME}_bench ${LINKED_LIBRARIES}) - add_custom_target(run_${BENCHMARK_NAME} COMMAND ${BENCHMARK_NAME} WORKING_DIRECTORY ${CMAKE_BINARY_DIR}) -endforeach() \ No newline at end of file +barretenberg_module(widgets_bench polynomials proof_system transcript stdlib_primitives) diff --git a/barretenberg/cpp/src/barretenberg/benchmark/widgets_bench/main.bench.cpp b/barretenberg/cpp/src/barretenberg/benchmark/widgets_bench/main.bench.cpp deleted file mode 100644 index 71fefa04722..00000000000 --- a/barretenberg/cpp/src/barretenberg/benchmark/widgets_bench/main.bench.cpp +++ /dev/null @@ -1,3 +0,0 @@ -#include - -BENCHMARK_MAIN(); diff --git a/barretenberg/cpp/src/barretenberg/benchmark/widgets_bench/widget.bench.cpp b/barretenberg/cpp/src/barretenberg/benchmark/widgets_bench/widget.bench.cpp index 9b94063e3c2..061d58cb83c 100644 --- a/barretenberg/cpp/src/barretenberg/benchmark/widgets_bench/widget.bench.cpp +++ b/barretenberg/cpp/src/barretenberg/benchmark/widgets_bench/widget.bench.cpp @@ -114,3 +114,5 @@ BENCHMARK(accumulate_contribution>); BENCHMARK(accumulate_contribution>); } // namespace bb::plonk + +BENCHMARK_MAIN(); diff --git a/barretenberg/cpp/src/barretenberg/benchmark/commit_bench/commit.bench.cpp b/barretenberg/cpp/src/barretenberg/commitment_schemes/commit.bench.cpp similarity index 86% rename from barretenberg/cpp/src/barretenberg/benchmark/commit_bench/commit.bench.cpp rename to barretenberg/cpp/src/barretenberg/commitment_schemes/commit.bench.cpp index 76990104285..e0b87c902d6 100644 --- a/barretenberg/cpp/src/barretenberg/benchmark/commit_bench/commit.bench.cpp +++ b/barretenberg/cpp/src/barretenberg/commitment_schemes/commit.bench.cpp @@ -1,5 +1,6 @@ #include "barretenberg/commitment_schemes/commitment_key.hpp" +#include "barretenberg/srs/factories/mem_bn254_crs_factory.hpp" #include namespace bb { @@ -14,8 +15,7 @@ std::shared_ptr> create_commitment_key(const siz static_assert(std::same_as); srs_path = "../srs_db/grumpkin"; } - std::shared_ptr> crs_factory( - new bb::srs::factories::FileCrsFactory(srs_path, num_points)); + auto crs_factory = std::make_shared>(srs_path, num_points); return std::make_shared>(num_points, crs_factory); } @@ -36,3 +36,5 @@ template void bench_commit(::benchmark::State& state) BENCHMARK(bench_commit)->DenseRange(10, MAX_LOG_NUM_POINTS)->Unit(benchmark::kMillisecond); } // namespace bb + +BENCHMARK_MAIN(); diff --git a/barretenberg/cpp/src/barretenberg/common/thread.cpp b/barretenberg/cpp/src/barretenberg/common/thread.cpp index 12334d272c6..22cc724b32e 100644 --- a/barretenberg/cpp/src/barretenberg/common/thread.cpp +++ b/barretenberg/cpp/src/barretenberg/common/thread.cpp @@ -20,7 +20,7 @@ * and OMP seems well designed to handle this. It actually looks like OMP consumes more cpu time in htop, and this * maybe due to aggressive spin-locking and may explain why it performs well in these scenarios. * - * My theory as to why spawning seems to counter-intuitively perfrom so well, is that spawning a new thread may actually + * My theory as to why spawning seems to counter-intuitively perform so well, is that spawning a new thread may actually * be cheaper than waking a sleeping thread. Or joining is somehow very efficient. Or it's because there's very low * other overhead. Or libc++ STL does some magic. Ok, that's not much of a theory... * diff --git a/barretenberg/cpp/src/barretenberg/env/hardware_concurrency.cpp b/barretenberg/cpp/src/barretenberg/env/hardware_concurrency.cpp index 3aedfcbd83c..7814a02e406 100644 --- a/barretenberg/cpp/src/barretenberg/env/hardware_concurrency.cpp +++ b/barretenberg/cpp/src/barretenberg/env/hardware_concurrency.cpp @@ -12,9 +12,14 @@ uint32_t env_hardware_concurrency() #ifndef __wasm__ try { #endif - static auto val = std::getenv("HARDWARE_CONCURRENCY"); - static const uint32_t cores = val ? (uint32_t)std::stoul(val) : std::thread::hardware_concurrency(); - return cores; +#ifdef WASMTIME_ENV_HACK + // TODO(https://github.com/AztecProtocol/barretenberg/issues/837): Undo this hack, rely on WASI. + return 16; +#else + static auto val = std::getenv("HARDWARE_CONCURRENCY"); + static const uint32_t cores = val ? (uint32_t)std::stoul(val) : std::thread::hardware_concurrency(); + return cores; +#endif #ifndef __wasm__ } catch (std::exception const&) { throw std::runtime_error("HARDWARE_CONCURRENCY invalid."); diff --git a/barretenberg/cpp/src/barretenberg/srs/global_crs.cpp b/barretenberg/cpp/src/barretenberg/srs/global_crs.cpp index f6ac2e05c71..c8c73f98e36 100644 --- a/barretenberg/cpp/src/barretenberg/srs/global_crs.cpp +++ b/barretenberg/cpp/src/barretenberg/srs/global_crs.cpp @@ -21,18 +21,42 @@ void init_crs_factory(std::vector const& points, g2::affine_ // Initializes crs from a file path this we use in the entire codebase void init_crs_factory(std::string crs_path) { - crs_factory = std::make_shared>(crs_path); +#ifdef WASMTIME_ENV_HACK + static_cast(crs_path); + // We only need this codepath in wasmtime because the SRS cannot be loaded in our usual ways + // and we don't need a real CRS for our purposes. + // TODO(https://github.com/AztecProtocol/barretenberg/issues/837): make this a real SRS. + std::vector points; + for (int i = 0; i < 262144; i++) { + points.push_back(g1::affine_element::random_element()); + } + init_crs_factory(points, g2::affine_element{ fq::random_element(), fq::random_element() }); +#else + crs_factory = std::make_shared>(crs_path); +#endif } // Initializes the crs using the memory buffers -void init_grumpkin_crs_factory(std::vector const& points) +void init_grumpkin_crs_factory(std::vector const& points) { grumpkin_crs_factory = std::make_shared(points); } void init_grumpkin_crs_factory(std::string crs_path) { +#ifdef WASMTIME_ENV_HACK + // We only need this codepath in wasmtime because the SRS cannot be loaded in our usual ways + // and we don't need a real CRS for our purposes. + // TODO(https://github.com/AztecProtocol/barretenberg/issues/837): make this a real SRS. + static_cast(crs_path); + std::vector points; + for (int i = 0; i < 262144; i++) { + points.push_back(curve::Grumpkin::AffineElement::random_element()); + } + init_grumpkin_crs_factory(points); +#else grumpkin_crs_factory = std::make_shared>(crs_path); +#endif } std::shared_ptr> get_crs_factory() diff --git a/barretenberg/cpp/src/barretenberg/stdlib/hash/benchmarks/CMakeLists.txt b/barretenberg/cpp/src/barretenberg/stdlib/hash/benchmarks/CMakeLists.txt index ef200979db3..7b46659e0ed 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib/hash/benchmarks/CMakeLists.txt +++ b/barretenberg/cpp/src/barretenberg/stdlib/hash/benchmarks/CMakeLists.txt @@ -1,3 +1 @@ -add_subdirectory(sha256) -add_subdirectory(external) -add_subdirectory(celer) \ No newline at end of file +barretenberg_module(hash_benchmarks stdlib_primitives crypto_sha256 stdlib_sha256 stdlib_blake3s) \ No newline at end of file diff --git a/barretenberg/cpp/src/barretenberg/stdlib/hash/benchmarks/celer/CMakeLists.txt b/barretenberg/cpp/src/barretenberg/stdlib/hash/benchmarks/celer/CMakeLists.txt deleted file mode 100644 index e79cbdf5776..00000000000 --- a/barretenberg/cpp/src/barretenberg/stdlib/hash/benchmarks/celer/CMakeLists.txt +++ /dev/null @@ -1 +0,0 @@ -barretenberg_module(celer stdlib_sha256) \ No newline at end of file diff --git a/barretenberg/cpp/src/barretenberg/stdlib/hash/benchmarks/celer/sha256.bench.cpp b/barretenberg/cpp/src/barretenberg/stdlib/hash/benchmarks/celer_sha256.bench.cpp similarity index 100% rename from barretenberg/cpp/src/barretenberg/stdlib/hash/benchmarks/celer/sha256.bench.cpp rename to barretenberg/cpp/src/barretenberg/stdlib/hash/benchmarks/celer_sha256.bench.cpp index e7defb06836..ac65931761d 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib/hash/benchmarks/celer/sha256.bench.cpp +++ b/barretenberg/cpp/src/barretenberg/stdlib/hash/benchmarks/celer_sha256.bench.cpp @@ -6,8 +6,8 @@ * @date 2023-08-02 * */ -#include "barretenberg/stdlib/hash/sha256/sha256.hpp" #include "barretenberg/plonk/composer/ultra_composer.hpp" +#include "barretenberg/stdlib/hash/sha256/sha256.hpp" #include #include diff --git a/barretenberg/cpp/src/barretenberg/stdlib/hash/benchmarks/external/CMakeLists.txt b/barretenberg/cpp/src/barretenberg/stdlib/hash/benchmarks/external/CMakeLists.txt deleted file mode 100644 index 2ef6b1656c7..00000000000 --- a/barretenberg/cpp/src/barretenberg/stdlib/hash/benchmarks/external/CMakeLists.txt +++ /dev/null @@ -1 +0,0 @@ -barretenberg_module(external stdlib_primitives crypto_sha256 stdlib_sha256 stdlib_blake3s) \ No newline at end of file diff --git a/barretenberg/cpp/src/barretenberg/stdlib/hash/benchmarks/external/external.bench.cpp b/barretenberg/cpp/src/barretenberg/stdlib/hash/benchmarks/external_sha256_blake3s.bench.cpp similarity index 100% rename from barretenberg/cpp/src/barretenberg/stdlib/hash/benchmarks/external/external.bench.cpp rename to barretenberg/cpp/src/barretenberg/stdlib/hash/benchmarks/external_sha256_blake3s.bench.cpp diff --git a/barretenberg/cpp/src/barretenberg/stdlib/hash/benchmarks/sha256/CMakeLists.txt b/barretenberg/cpp/src/barretenberg/stdlib/hash/benchmarks/sha256/CMakeLists.txt deleted file mode 100644 index f3f408e1fe5..00000000000 --- a/barretenberg/cpp/src/barretenberg/stdlib/hash/benchmarks/sha256/CMakeLists.txt +++ /dev/null @@ -1 +0,0 @@ -barretenberg_module(stdlib_sha256_just stdlib_sha256) \ No newline at end of file diff --git a/barretenberg/cpp/src/barretenberg/stdlib/hash/benchmarks/sha256/sha256.bench.cpp b/barretenberg/cpp/src/barretenberg/stdlib/hash/benchmarks/stdlib_sha256.bench.cpp similarity index 100% rename from barretenberg/cpp/src/barretenberg/stdlib/hash/benchmarks/sha256/sha256.bench.cpp rename to barretenberg/cpp/src/barretenberg/stdlib/hash/benchmarks/stdlib_sha256.bench.cpp index d0c7cfd2f79..605b86e3397 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib/hash/benchmarks/sha256/sha256.bench.cpp +++ b/barretenberg/cpp/src/barretenberg/stdlib/hash/benchmarks/stdlib_sha256.bench.cpp @@ -1,5 +1,5 @@ -#include "barretenberg/stdlib/hash/sha256/sha256.hpp" #include "barretenberg/plonk/composer/ultra_composer.hpp" +#include "barretenberg/stdlib/hash/sha256/sha256.hpp" #include using namespace benchmark;