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

precompile some headers #164

Merged
merged 6 commits into from
Dec 10, 2024
Merged
Changes from 1 commit
Commits
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
Prev Previous commit
Next Next commit
optimize proof-producer precompiled headers
AndreyMlashkin committed Dec 10, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
commit 6fb401d893896d24317487b909c457887559938d
13 changes: 13 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -21,6 +21,19 @@ if(${SANITIZE})
add_link_options(-fsanitize=undefined,address,leak)
endif()

# Add dummy target for the more efficient reusing of precompiled headers
file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/generated-dummy.cpp)
add_library(crypto3_precompiled_headers STATIC ${CMAKE_CURRENT_BINARY_DIR}/generated-dummy.cpp)

file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/generated-dummy-23.cpp)
add_library(crypto3_precompiled_headers_23 STATIC ${CMAKE_CURRENT_BINARY_DIR}/generated-dummy-23.cpp)
set_target_properties(crypto3_precompiled_headers_23 PROPERTIES
LINKER_LANGUAGE CXX
EXPORT_NAME proof_generatorOutputArtifacts
CXX_STANDARD 23
CXX_STANDARD_REQUIRED TRUE
)
# End of precompiled headers

add_subdirectory("${CMAKE_CURRENT_LIST_DIR}/crypto3")
if ((${PARALLEL_CRYPTO3_ENABLE}) OR (${PROOF_PRODUCER_ENABLE}) OR (${ZKEVM_FRAMEWORK_ENABLE}))
2 changes: 1 addition & 1 deletion crypto3/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -6,7 +6,7 @@
# http://www.boost.org/LICENSE_1_0.txt
#---------------------------------------------------------------------------#

cmake_minimum_required(VERSION 3.21)
cmake_minimum_required(VERSION 3.22 FATAL_ERROR)

list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake")

4 changes: 1 addition & 3 deletions crypto3/benchmarks/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -49,9 +49,7 @@ macro(define_benchmark benchmark)
target_compile_options(${full_name} PRIVATE "-fconstexpr-ops-limit=4294967295")
endif()

if(NOT ${full_name} STREQUAL "algebra_curves_benchmark")
target_precompile_headers(${full_name} REUSE_FROM algebra_curves_benchmark)
endif()
target_precompile_headers(${full_name} REUSE_FROM crypto3_precompiled_headers)
endmacro()

set(BENCHMARK_NAMES
22 changes: 11 additions & 11 deletions crypto3/libs/blueprint/test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -36,6 +36,16 @@ if(BLUEPRINT_PLACEHOLDER_PROOF_GEN)
add_definitions(-DBLUEPRINT_PLACEHOLDER_PROOF_GEN_ENABLED)
endif()

cm_test_link_libraries(${CMAKE_WORKSPACE_NAME}_${CURRENT_PROJECT_NAME}
${${CURRENT_PROJECT_NAME}_INTERFACE_LIBRARIES}
crypto3::blueprint
crypto3::algebra
crypto3::zk
crypto3::random
crypto3::hash
)
target_precompile_headers(_cm_internal_tests-crypto3-blueprint-test REUSE_FROM crypto3_precompiled_headers)

macro(define_blueprint_test test)
string(REPLACE "/" "_" full_test_name blueprint_${test}_test)

@@ -49,14 +59,6 @@ macro(define_blueprint_test test)
target_include_directories(${full_test_name} PRIVATE
${Boost_INCLUDE_DIRS})

target_link_libraries(${full_test_name}
crypto3::blueprint
crypto3::algebra
crypto3::zk
crypto3::random
crypto3::hash
)

set_target_properties(${full_test_name} PROPERTIES CXX_STANDARD 17)

target_compile_definitions(${full_test_name} PRIVATE TEST_DATA_DIR="${CMAKE_CURRENT_SOURCE_DIR}/zkevm/data/")
@@ -74,9 +76,7 @@ macro(define_blueprint_test test)

endif()

if(NOT ${full_test_name} STREQUAL "blueprint_test_plonk_component_test")
target_precompile_headers(${full_test_name} REUSE_FROM blueprint_test_plonk_component_test)
endif()
target_precompile_headers(${full_test_name} REUSE_FROM crypto3_precompiled_headers)
endmacro()

set(COMMON_TEST_FILES
17 changes: 11 additions & 6 deletions crypto3/libs/containers/test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -25,6 +25,16 @@

include(CMTest)

cm_test_link_libraries(${CMAKE_WORKSPACE_NAME}_${CURRENT_PROJECT_NAME}

${CMAKE_WORKSPACE_NAME}::algebra
${CMAKE_WORKSPACE_NAME}::hash

Boost::unit_test_framework
Boost::random
)
target_precompile_headers(_cm_internal_tests-crypto3-containers-test REUSE_FROM crypto3_precompiled_headers)

macro(define_storage_test test)
get_filename_component(test_name ${test} NAME)
set(full_test_name ${CMAKE_WORKSPACE_NAME}_${CURRENT_PROJECT_NAME}_${test_name}_test)
@@ -37,12 +47,6 @@ macro(define_storage_test test)

cm_test(NAME ${full_test_name} SOURCES ${test}.cpp)

target_include_directories(${full_test_name} PRIVATE
"$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>"
"$<BUILD_INTERFACE:${CMAKE_BINARY_DIR}/include>"

${Boost_INCLUDE_DIRS})

target_link_libraries(${full_test_name}
${CMAKE_WORKSPACE_NAME}::containers
${CMAKE_WORKSPACE_NAME}::algebra
@@ -59,6 +63,7 @@ macro(define_storage_test test)
elseif (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
target_compile_options(${full_test_name} PRIVATE "-fconstexpr-ops-limit=4294967295" "-ftemplate-backtrace-limit=0")
endif()
target_precompile_headers(${full_test_name} REUSE_FROM crypto3_precompiled_headers)
endmacro()

set(TESTS_NAMES
2 changes: 2 additions & 0 deletions crypto3/libs/hash/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -147,6 +147,8 @@ target_link_libraries(${CMAKE_WORKSPACE_NAME}_${CURRENT_PROJECT_NAME} INTERFACE
${CMAKE_WORKSPACE_NAME}::algebra

Boost::container)
target_link_libraries(crypto3_precompiled_headers ${CMAKE_WORKSPACE_NAME}_${CURRENT_PROJECT_NAME})
target_link_libraries(crypto3_precompiled_headers_23 ${CMAKE_WORKSPACE_NAME}_${CURRENT_PROJECT_NAME})

target_include_directories(${CMAKE_WORKSPACE_NAME}_${CURRENT_PROJECT_NAME} INTERFACE
"$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>"
7 changes: 3 additions & 4 deletions crypto3/libs/hash/test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -12,6 +12,8 @@ cm_test_link_libraries(${CMAKE_WORKSPACE_NAME}_${CURRENT_PROJECT_NAME}
${${CURRENT_PROJECT_NAME}_INTERFACE_LIBRARIES}
Boost::unit_test_framework)

target_precompile_headers(_cm_internal_tests-crypto3-hash-test REUSE_FROM crypto3_precompiled_headers)

macro(define_hash_test name)
set(test_name "hash_${name}_test")

@@ -44,13 +46,10 @@ macro(define_hash_test name)
target_compile_options(${test_name} PRIVATE "-fconstexpr-ops-limit=4294967295")
endif()

target_precompile_headers(${test_name} REUSE_FROM _cm_internal_tests-crypto3-hash-test)
target_precompile_headers(${test_name} REUSE_FROM crypto3_precompiled_headers)
endmacro()

set(TESTS_NAMES
"tiger"
"blake2b"
"crc"
"keccak"
"pack"
"sha2"
5 changes: 3 additions & 2 deletions crypto3/libs/marshalling/zk/test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -22,6 +22,8 @@ cm_test_link_libraries(${CMAKE_WORKSPACE_NAME}_${CURRENT_PROJECT_NAME}
${CMAKE_WORKSPACE_NAME}::marshalling-algebra
${CMAKE_WORKSPACE_NAME}::marshalling-core)

target_precompile_headers(_cm_internal_tests-crypto3-marshalling-zk-test REUSE_FROM crypto3_precompiled_headers)

macro(define_marshalling_test test)

get_filename_component(name ${test} NAME)
@@ -45,8 +47,7 @@ macro(define_marshalling_test test)
elseif(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
target_compile_options(${full_test_name} PRIVATE "-fconstexpr-ops-limit=4294967295")
endif()

target_precompile_headers(${full_test_name} REUSE_FROM _cm_internal_tests-crypto3-hash-test)
target_precompile_headers(${full_test_name} REUSE_FROM crypto3_precompiled_headers)
endmacro()

set(TESTS_NAMES
2 changes: 0 additions & 2 deletions crypto3/libs/random/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -6,8 +6,6 @@
# http://www.boost.org/LICENSE_1_0.txt
#---------------------------------------------------------------------------#

cmake_minimum_required(VERSION 3.5)

set(BOOST_CMAKE FALSE)

include(CMConfig)
3 changes: 2 additions & 1 deletion crypto3/libs/random/test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -12,6 +12,7 @@ include(CMTest)
cm_test_link_libraries(${CMAKE_WORKSPACE_NAME}_${CURRENT_PROJECT_NAME}
${CMAKE_WORKSPACE_NAME}::multiprecision
Boost::unit_test_framework)
target_precompile_headers(_cm_internal_tests-crypto3-random-test REUSE_FROM crypto3_precompiled_headers)

macro(define_random_test test)
get_filename_component(name ${test} NAME)
@@ -32,7 +33,7 @@ macro(define_random_test test)
elseif(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
target_compile_options(${full_test_name} PRIVATE "-fconstexpr-ops-limit=4294967295")
endif()
target_precompile_headers(${full_test_name} REUSE_FROM _cm_internal_tests-crypto3-hash-test)
target_precompile_headers(${full_test_name} REUSE_FROM crypto3_precompiled_headers)
endmacro()

# TODO(uncomment the failing tests once they pass)
2 changes: 0 additions & 2 deletions crypto3/libs/transpiler/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -6,8 +6,6 @@
# http://www.boost.org/LICENSE_1_0.txt
#---------------------------------------------------------------------------#

cmake_minimum_required(VERSION 3.22 FATAL_ERROR)

find_package(CM REQUIRED)
include(CMConfig)
include(CMSetupVersion)
3 changes: 2 additions & 1 deletion crypto3/libs/transpiler/test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -17,6 +17,7 @@ cm_test_link_libraries(${CMAKE_WORKSPACE_NAME}_${CURRENT_PROJECT_NAME}
crypto3::random
crypto3::zk
${Boost_LIBRARIES})
target_precompile_headers(_cm_internal_tests-crypto3-transpiler-test REUSE_FROM crypto3_precompiled_headers)

add_custom_target(compile_and_run_transpiler_tests)

@@ -48,7 +49,7 @@ macro(define_transpiler_test name)
)
add_dependencies(compile_and_run_transpiler_tests ${full_test_name}_run)

target_precompile_headers(${full_test_name} REUSE_FROM _cm_internal_tests-crypto3-hash-test)
target_precompile_headers(${full_test_name} REUSE_FROM crypto3_precompiled_headers)
endmacro()

set(TESTS_NAMES
3 changes: 2 additions & 1 deletion crypto3/libs/zk/test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -19,6 +19,7 @@ cm_test_link_libraries(${CMAKE_WORKSPACE_NAME}_${CURRENT_PROJECT_NAME}
Boost::unit_test_framework
Boost::log
)
target_precompile_headers(_cm_internal_tests-crypto3-zk-test REUSE_FROM crypto3_precompiled_headers)

if(PROFILING_ENABLED)
add_definitions(-DPROFILING_ENABLED)
@@ -43,7 +44,7 @@ macro(define_zk_test test)
elseif(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
target_compile_options(${full_test_name} PRIVATE "-fconstexpr-ops-limit=4294967295")
endif()
target_precompile_headers(${full_test_name} REUSE_FROM _cm_internal_tests-crypto3-hash-test)
target_precompile_headers(${full_test_name} REUSE_FROM crypto3_precompiled_headers)
endmacro()

set(TESTS_NAMES
3 changes: 2 additions & 1 deletion parallel-crypto3/benchmarks/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -35,7 +35,7 @@ macro(define_bench_test name)
${Boost_INCLUDE_DIRS})

set_target_properties(${test_name} PROPERTIES CXX_STANDARD 17)

target_precompile_headers(${test_name} REUSE_FROM crypto3_precompiled_headers)
endmacro()

cm_test_link_libraries(
@@ -45,6 +45,7 @@ cm_test_link_libraries(
crypto3::random
${Boost_LIBRARIES}
)
target_precompile_headers(_cm_internal_tests--parallel-crypto3-benchmarks REUSE_FROM crypto3_precompiled_headers)

set(TESTS_NAMES
"polynomial_dfs_benchmark"
5 changes: 2 additions & 3 deletions parallel-crypto3/libs/parallel-containers/test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -26,11 +26,10 @@
include(CMTest)

cm_test_link_libraries(${CMAKE_WORKSPACE_NAME}_${CURRENT_PROJECT_NAME}

crypto3::algebra
crypto3::hash

Boost::random)
target_precompile_headers(_cm_internal_tests-actor-containers-test REUSE_FROM crypto3_precompiled_headers)

macro(define_storage_test test)
get_filename_component(test_name ${test} NAME)
@@ -74,7 +73,7 @@ macro(define_storage_test test)
elseif (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
target_compile_options(${target_name} PRIVATE "-fconstexpr-ops-limit=4294967295" "-ftemplate-backtrace-limit=0")
endif()
target_precompile_headers(${target_name} REUSE_FROM _cm_internal_tests-actor-containers-test)
target_precompile_headers(${target_name} REUSE_FROM crypto3_precompiled_headers)
endmacro()

set(TESTS_NAMES
3 changes: 2 additions & 1 deletion parallel-crypto3/libs/parallel-zk/test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -19,6 +19,7 @@ cm_test_link_libraries(${CMAKE_WORKSPACE_NAME}_${CURRENT_PROJECT_NAME}
Boost::unit_test_framework
Boost::log
)
target_precompile_headers(_cm_internal_tests-actor-zk-test REUSE_FROM crypto3_precompiled_headers)

if(PROFILING_ENABLED)
add_definitions(-DPROFILING_ENABLED)
@@ -45,7 +46,7 @@ macro(define_zk_test test)
target_compile_options(${full_test_name} PRIVATE "-fconstexpr-ops-limit=4294967295")
endif()

target_precompile_headers(${full_test_name} REUSE_FROM _cm_internal_tests-actor-zk-test)
target_precompile_headers(${full_test_name} REUSE_FROM crypto3_precompiled_headers)
endmacro()

set(TESTS_NAMES
4 changes: 2 additions & 2 deletions proof-producer/bin/proof-producer/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -74,7 +74,6 @@ function(setup_proof_generator_target)
EXPORT_NAME ${ARG_TARGET_NAME}
CXX_STANDARD 23
CXX_STANDARD_REQUIRED TRUE)

if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
target_compile_options(${ARG_TARGET_NAME} PRIVATE "-fconstexpr-steps=2147483647")
elseif (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
@@ -85,11 +84,12 @@ endfunction()

set(SINGLE_THREADED_TARGET "${CURRENT_PROJECT_NAME}-single-threaded")
setup_proof_generator_target(TARGET_NAME ${SINGLE_THREADED_TARGET} ADDITIONAL_DEPENDENCIES crypto3::all)

set(MULTI_THREADED_TARGET "${CURRENT_PROJECT_NAME}-multi-threaded")
setup_proof_generator_target(TARGET_NAME ${MULTI_THREADED_TARGET} ADDITIONAL_DEPENDENCIES parallel-crypto3::all crypto3::common)
target_precompile_headers(${MULTI_THREADED_TARGET} REUSE_FROM ${SINGLE_THREADED_TARGET})

# Install

install(TARGETS ${SINGLE_THREADED_TARGET} RUNTIME DESTINATION bin)
install(TARGETS ${MULTI_THREADED_TARGET} RUNTIME DESTINATION bin)

3 changes: 3 additions & 0 deletions proof-producer/libs/output_artifacts/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -25,6 +25,9 @@ set_target_properties(proof_generatorOutputArtifacts PROPERTIES
CXX_STANDARD_REQUIRED TRUE
)

# TODO: reactivate, when it will be a static library
# target_precompile_headers(proof_generatorOutputArtifacts REUSE_FROM crypto3_precompiled_headers_23)

install(TARGETS proof_generatorOutputArtifacts
DESTINATION ${CMAKE_INSTALL_LIBDIR})

3 changes: 3 additions & 0 deletions proof-producer/tests/bin/proof-producer/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -39,6 +39,7 @@ function(add_prover_test target)
set_properties(${target}_multi_thread)
target_link_libraries(${target}_single_thread PRIVATE
crypto3::all

)
target_link_libraries(${target}_multi_thread PRIVATE
parallel-crypto3::all
@@ -47,6 +48,8 @@ function(add_prover_test target)

add_dependencies(tests_prover_single_thread ${target}_single_thread)
add_dependencies(tests_prover_multi_thread ${target}_multi_thread)

target_precompile_headers(${target}_single_thread REUSE_FROM ${target}_multi_thread)
endfunction()

add_prover_test(test_zkevm_bbf_circuits)
7 changes: 5 additions & 2 deletions proof-producer/tests/libs/output_artifacts/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -14,9 +14,7 @@ function(set_properties target)
CXX_STANDARD 23
CXX_STANDARD_REQUIRED TRUE
)

target_compile_definitions(${target} PRIVATE TEST_DATA_DIR="${CMAKE_CURRENT_SOURCE_DIR}/resources/")

gtest_discover_tests(${target})
endfunction()

@@ -36,6 +34,11 @@ function(add_output_artifacts_test target)
crypto3::common
)

if (NOT target STREQUAL "test_range")
target_precompile_headers(${target}_single_thread REUSE_FROM test_range_single_thread)
endif()
target_precompile_headers(${target}_multi_thread REUSE_FROM test_range_single_thread)

add_dependencies(tests_output_artifacts_single_thread ${target}_single_thread)
add_dependencies(tests_output_artifacts_multi_thread ${target}_multi_thread)
endfunction()