Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(bb): wasmtime and remote benchmarking #4204

Merged
merged 56 commits into from
Jan 30, 2024
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
Show all changes
56 commits
Select commit Hold shift + click to select a range
7dea003
feat: initial bb wasmtime running again
ludamad0 Jan 24, 2024
0d5bb36
proof of concept, running benchmark
ludamad0 Jan 24, 2024
9a771a2
feat: wasm-bench preset
ludamad0 Jan 24, 2024
d25785a
wasm benchmarking hacks
ludamad0 Jan 25, 2024
47439bd
feat: benchmark script
ludamad0 Jan 25, 2024
368b7cb
revert: use parallel_for_mutex_pool
ludamad0 Jan 25, 2024
91d22d0
hack the cores
ludamad0 Jan 25, 2024
c4500f9
fix: google benchmark commits
ludamad0 Jan 25, 2024
388b059
fuzzing simplification
ludamad0 Jan 25, 2024
d06b016
refactor: standardize benchmarking
ludamad0 Jan 25, 2024
9d84372
fix: manual bench mains
ludamad0 Jan 25, 2024
688462e
fix: remove main.cpp's for bench
ludamad0 Jan 25, 2024
d6a54fc
whitespace
ludamad0 Jan 25, 2024
8a51141
Revert readme
ludamad0 Jan 25, 2024
0f2cf85
fix: prootogalaxy_bench
ludamad0 Jan 25, 2024
0b76a39
fix: forgotten file
ludamad0 Jan 29, 2024
014b821
revert
ludamad Jan 29, 2024
79910e7
new-style cli
ludamad0 Jan 29, 2024
0e3707d
feat: remote benchmarking scripts
ludamad0 Jan 29, 2024
01550af
feat: fixed remote scripts
ludamad0 Jan 29, 2024
6f82415
feat: fixed remote scripts
ludamad0 Jan 29, 2024
5fe02b7
fix wasm remote
ludamad0 Jan 29, 2024
d669b6e
Merge branch 'master' into feat/wasm-bench
ludamad Jan 29, 2024
1e7eb21
Update protocol-circuits-gate-diff.yml
ludamad Jan 29, 2024
3119b45
feat: initial bb wasmtime running again
ludamad0 Jan 24, 2024
a32630a
proof of concept, running benchmark
ludamad0 Jan 24, 2024
1518fa8
feat: wasm-bench preset
ludamad0 Jan 24, 2024
ebd9d11
wasm benchmarking hacks
ludamad0 Jan 25, 2024
334b970
feat: benchmark script
ludamad0 Jan 25, 2024
6b3ff95
revert: use parallel_for_mutex_pool
ludamad0 Jan 25, 2024
21d0fec
hack the cores
ludamad0 Jan 25, 2024
09a65d4
fix: google benchmark commits
ludamad0 Jan 25, 2024
3ba9ef7
fuzzing simplification
ludamad0 Jan 25, 2024
401dce4
refactor: standardize benchmarking
ludamad0 Jan 25, 2024
b73eeeb
fix: manual bench mains
ludamad0 Jan 25, 2024
ef62c2a
fix: remove main.cpp's for bench
ludamad0 Jan 25, 2024
0193829
whitespace
ludamad0 Jan 25, 2024
57e1e26
Revert readme
ludamad0 Jan 25, 2024
7d18ef1
fix: prootogalaxy_bench
ludamad0 Jan 25, 2024
98dfa7f
fix: forgotten file
ludamad0 Jan 29, 2024
d61a73d
revert
ludamad Jan 29, 2024
610f51a
new-style cli
ludamad0 Jan 29, 2024
2e37e8c
feat: remote benchmarking scripts
ludamad0 Jan 29, 2024
7d527cb
feat: fixed remote scripts
ludamad0 Jan 29, 2024
f5d76a8
feat: fixed remote scripts
ludamad0 Jan 29, 2024
8ea2ff7
fix wasm remote
ludamad0 Jan 29, 2024
666ad69
fix: publish bb
ludamad0 Jan 29, 2024
b6327eb
Merge remote-tracking branch 'origin/feat/wasm-bench' into feat/wasm-…
ludamad0 Jan 29, 2024
f16d21a
Revert
ludamad0 Jan 29, 2024
b0f3f53
LOCKING
ludamad0 Jan 30, 2024
f57f1fb
Add command option
ludamad0 Jan 30, 2024
55401dd
Update gtest.cmake
ludamad Jan 30, 2024
99b3123
Merge branch 'master' into feat/wasm-bench
ludamad Jan 30, 2024
2d8117f
revert
ludamad0 Jan 30, 2024
9ee594e
Merge branch 'master' into feat/wasm-bench
ludamad Jan 30, 2024
78a45e7
Merge remote-tracking branch 'origin/feat/wasm-bench' into feat/wasm-…
ludamad0 Jan 30, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 1 addition & 13 deletions barretenberg/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -242,22 +242,10 @@ A default configuration for VS Code is provided by the file [`barretenberg.code-

### Integration tests with Aztec in Monorepo

CI will automatically run integration tests against Aztec. It is located in the `barretenberg` folder.
CI will automatically run integration tests against Aztec. The tests in `circuits/cpp` folder use the embedded barretenberg, and can be used to integration test it.

### Integration tests with Aztec in Barretenberg Standalone Repo

CI will automatically run integration tests against Aztec's circuits which live [here](https://github.com/AztecProtocol/aztec-packages/tree/master/circuits). To change which Aztec branch or commit for CI to test against, modify [`.aztec-packages-commit`](./cpp/.aztec-packages-commit).

When working on a PR, you may want to point this file to a different Aztec branch or commit, but then it should probably be pointed back to master before merging.

### Testing locally in docker

A common issue that arises is that our CI system has a different compiler version e.g. namely for GCC. If you need to mimic the CI operating system locally you can use bootstrap_docker.sh or run dockerfiles directly. However, there is a more efficient workflow for iterative development:

```
cd barretenberg/cpp
./scripts/docker_interactive.sh
mv build build-native # your native build folders are mounted, but will not work! have to clear them
cmake --preset gcc ; cmake --build build
```
This will allow you to rebuild as efficiently as if you were running native code, and not have to see a full compile cycle.
22 changes: 3 additions & 19 deletions barretenberg/cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have removed the TESTING and BENCHMARK options in favour of simplifying the build pipeline, but I'm happy to revert it if desired

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)
Expand Down Expand Up @@ -52,30 +49,17 @@ 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")
message(STATUS "Compiling for WebAssembly.")
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()
Expand Down
38 changes: 34 additions & 4 deletions barretenberg/cpp/CMakePresets.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -151,10 +164,6 @@
"CFLAGS": "-fsanitize=memory",
"CXXFLAGS": "-fsanitize=memory",
"LDFLAGS": "-fsanitize=memory"
},
"cacheVariables": {
"BENCHMARK": "OFF",
"TESTING": "OFF"
}
},
{
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -336,6 +355,11 @@
"inherits": "default",
"configurePreset": "tsan"
},
{
"name": "ubsan",
"inherits": "default",
"configurePreset": "ubsan"
},
{
"name": "coverage",
"inherits": "default",
Expand Down Expand Up @@ -368,6 +392,12 @@
"jobs": 0,
"targets": ["barretenberg.wasm"]
},
{
"name": "wasm-bench",
"configurePreset": "wasm-bench",
"inheritConfigureEnvironment": true,
"jobs": 0
},
{
"name": "xray",
"configurePreset": "xray",
Expand Down
36 changes: 15 additions & 21 deletions barretenberg/cpp/cmake/benchmark.cmake
Original file line number Diff line number Diff line change
@@ -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()
86 changes: 43 additions & 43 deletions barretenberg/cpp/cmake/gtest.cmake
Original file line number Diff line number Diff line change
@@ -1,51 +1,51 @@
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")
# # TODO only in wasm?
# set(gtest_disable_pthreads OFF CACHE BOOL "gTest pthreads disabled")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stray TODO. I assume you want to delete the set?


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()
74 changes: 38 additions & 36 deletions barretenberg/cpp/cmake/module.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -184,7 +184,6 @@ function(barretenberg_module MODULE_NAME)
${MODULE_NAME}_${FUZZER_NAME_STEM}_fuzzer
PRIVATE
"-fsanitize=fuzzer"
${SANITIZER_OPTIONS}
)

target_link_libraries(
Expand All @@ -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
$<TARGET_OBJECTS:${MODULE_NAME}_bench_objects>
)
list(APPEND exe_targets ${MODULE_NAME}_bench)
add_executable(
${BENCHMARK_NAME}_bench
$<TARGET_OBJECTS:${BENCHMARK_NAME}_bench_objects>
)
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)
Expand Down
8 changes: 2 additions & 6 deletions barretenberg/cpp/docs/Fuzzing.md
Original file line number Diff line number Diff line change
Expand Up @@ -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=<PATH_TO_SYMBOLIZER>`.
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
Expand Down
Loading
Loading