diff --git a/libs/algebra/example/short_weierstrass_coordinates.cpp b/libs/algebra/example/short_weierstrass_coordinates.cpp index 9e4a8cad6..0748c2f75 100644 --- a/libs/algebra/example/short_weierstrass_coordinates.cpp +++ b/libs/algebra/example/short_weierstrass_coordinates.cpp @@ -51,7 +51,7 @@ void coordinates_examples() { std::cout << "c2 value: " << (c2) << std::endl; std::cout << "c1 + c2 value: " << (c1 + c2) << std::endl; std::cout << "c1 - c2 value: " << (c1 - c2) << std::endl; - std::cout << "Doubled c1 value: " << (c1.doubled()) << std::endl; +// std::cout << "Doubled c1 value: " << (c1.doubled()) << std::endl; } int main() { diff --git a/libs/algebra/include/nil/crypto3/algebra/type_traits.hpp b/libs/algebra/include/nil/crypto3/algebra/type_traits.hpp index 0065083b6..0c8d9a088 100644 --- a/libs/algebra/include/nil/crypto3/algebra/type_traits.hpp +++ b/libs/algebra/include/nil/crypto3/algebra/type_traits.hpp @@ -54,6 +54,8 @@ namespace nil { BOOST_TTI_HAS_TYPE(g2_type) BOOST_TTI_HAS_TYPE(gt_type) + BOOST_TTI_HAS_TEMPLATE(g2_type) + BOOST_TTI_HAS_TYPE(group_type) BOOST_TTI_HAS_STATIC_MEMBER_DATA(value_bits) diff --git a/libs/algebra/test/bench_test/CMakeLists.txt b/libs/algebra/test/bench_test/CMakeLists.txt index e46a45a56..211d40e49 100644 --- a/libs/algebra/test/bench_test/CMakeLists.txt +++ b/libs/algebra/test/bench_test/CMakeLists.txt @@ -10,7 +10,7 @@ include(CMTest) add_custom_target(algebra_runtime_bench_tests) -macro(define_runtime_algebra_test name) +macro(define_algebra_benchmark name) set(test_name "algebra_${name}_bench_test") add_dependencies(algebra_runtime_bench_tests ${test_name}) @@ -22,7 +22,13 @@ macro(define_runtime_algebra_test name) ${Boost_INCLUDE_DIRS}) - set_target_properties(${test_name} PROPERTIES CXX_STANDARD 17 + target_link_libraries(${test_name} + ${CMAKE_WORKSPACE_NAME}::benchmark_tools + ) + + set_target_properties(${test_name} + PROPERTIES + CXX_STANDARD 17 CXX_STANDARD_REQUIRED TRUE) if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang") @@ -31,16 +37,16 @@ macro(define_runtime_algebra_test name) target_compile_options(${test_name} PRIVATE "-fconstexpr-ops-limit=4294967295") endif() - target_compile_definitions(${test_name} PRIVATE TEST_DATA_DIR="${CMAKE_CURRENT_SOURCE_DIR}/data/") endmacro() -set(RUNTIME_TESTS_NAMES +set(BENCHMARK_NAMES "bench_curves" "bench_fields" "bench_multiexp" - ) +) -foreach(TEST_NAME ${RUNTIME_TESTS_NAMES}) - define_runtime_algebra_test(${TEST_NAME}) +foreach(BENCH_NAME ${BENCHMARK_NAMES}) + define_algebra_benchmark(${BENCH_NAME}) endforeach() + diff --git a/libs/algebra/test/bench_test/bench_curves.cpp b/libs/algebra/test/bench_test/bench_curves.cpp index e011e96d5..0415e3be9 100644 --- a/libs/algebra/test/bench_test/bench_curves.cpp +++ b/libs/algebra/test/bench_test/bench_curves.cpp @@ -25,27 +25,18 @@ #define BOOST_TEST_MODULE algebra_curves_bench_test -#include -#include -#include -#include - #include #include #include -#include -#include +#include -#include +#include -#include -#include -#include +#include #include #include -#include #include #include #include @@ -54,201 +45,117 @@ #include #include #include - #include #include -#include -#include - -#include +#include +#include using namespace nil::crypto3::algebra; - -BOOST_AUTO_TEST_SUITE(curves_manual_tests) -/**/ - -template -void curve_operations_perf_test(std::string const& curve_name) { - using namespace nil::crypto3; - using namespace nil::crypto3::algebra; - - typedef typename AffineCurveGroup::value_type affine_value_type; - typedef typename CurveGroup::value_type value_type; - typedef typename CurveGroup::curve_type::scalar_field_type::value_type scalar_type; - - std::vector points1; - std::vector points2; - std::vector constants; - - size_t SAMPLE_POINTS = 1000; - for (int i = 0; i < SAMPLE_POINTS; ++i) { - auto p1 = algebra::random_element(); - auto p1a = p1.to_affine(); - - points1.push_back(value_type::from_affine(p1a)); - points2.push_back(algebra::random_element()); - constants.push_back(algebra::random_element()); - } - - using duration = std::chrono::duration; - - auto run_batched_test = [&]( - std::string const& test_name, - std::size_t BATCHES, - std::size_t samples_per_batch, - std::vector const& B, - std::function opfunc) - { - std::vector batch_duration; - batch_duration.resize(BATCHES); - - auto res = B[0]; - - for(size_t b = 0; b < BATCHES; ++b) { - if (b % (BATCHES/10) == 0) std::cerr << "Batch progress:" << b << std::endl; - auto start = std::chrono::high_resolution_clock::now(); - for(size_t i = 0; i < samples_per_batch; ++i) { - opfunc(res, B[i*i % SAMPLE_POINTS]); - } - - auto finish = std::chrono::high_resolution_clock::now(); - batch_duration[b] = (finish - start) * 1.0 / samples_per_batch; - } - - std::cout << res << std::endl; - - /* To filter 10% outliers, sort results and set margin to BATCHES/20 = 5% */ - // sort(batch_duration.begin(), batch_duration.end()); - std::size_t margin = 0; // BATCHES/20; - auto s = batch_duration[margin]; - for(size_t b = margin+1; b < batch_duration.size()-margin; ++b) { - s += batch_duration[b]; - } - - - s /= batch_duration.size() - margin*2; - std::cout << test_name << ": " << std::fixed << std::setprecision(3) << s.count() << std::endl; - - return batch_duration; - }; - - size_t SAMPLES_PER_BATCH = 10000; - size_t BATCHES = 1000; - - for(int MULTIPLICATOR = 1; MULTIPLICATOR <= 10; ++MULTIPLICATOR) { - std::cout << "MULT: " << MULTIPLICATOR << std::endl; - - auto madd_res = run_batched_test( - "madd", - BATCHES, SAMPLES_PER_BATCH / MULTIPLICATOR, - points1, - [&]( value_type & A, value_type const& B) { - for(int m = 0; m < MULTIPLICATOR; ++m) - A.mixed_add(B); - } ); - - auto add_res = run_batched_test( - "add", - BATCHES, SAMPLES_PER_BATCH / MULTIPLICATOR, - points1, - [&]( value_type & A, value_type const& B) { - for(int m = 0; m < MULTIPLICATOR; ++m) - A += B; - } ); - - auto dbl_res = run_batched_test( - "dbl", - BATCHES, SAMPLES_PER_BATCH / MULTIPLICATOR, - points1, - [&]( value_type & A, value_type const& B) { - for(int m = 0; m < MULTIPLICATOR; ++m) +using namespace nil::crypto3::bench; + +template +void benchmark_curve_operations(std::string const& curve_name) +{ + using g1_type = typename curve_type::template g1_type<>; + using base_field = typename curve_type::base_field_type; + using scalar_field = typename curve_type::scalar_field_type; + + run_benchmark( + curve_name + " Fp addition", + [](typename base_field::value_type& A, typename base_field::value_type const& B) { + return A += B; + }); + run_benchmark( + curve_name + " Fp multiplication", + [](typename base_field::value_type& A, typename base_field::value_type const& B) { + return A *= B; + }); + run_benchmark( + curve_name + " Fp inverse", + [](typename base_field::value_type& A) { + return A.inversed(); + }); + run_benchmark( + curve_name + " Fq addition", + [](typename scalar_field::value_type& A, typename scalar_field::value_type const& B) { + return A += B; + }); + run_benchmark( + curve_name + " Fq multiplication", + [](typename scalar_field::value_type& A, typename scalar_field::value_type const& B) { + return A *= B; + }); + run_benchmark( + curve_name + " Fq inverse", + [](typename scalar_field::value_type& A) { + return A.inversed(); + }); + run_benchmark( + curve_name + " G1 addition", + [](typename g1_type::value_type& A, typename g1_type::value_type const& B) { + return A += B; + }); + run_benchmark( + curve_name + " G1 doubling", + [](typename g1_type::value_type& A) { + A.double_inplace();// += A; + return A; + }); + run_benchmark( + curve_name + " G1 scalar multiplication", + [](typename g1_type::value_type& A, typename scalar_field::value_type const& B) { + return A *= B; + }); + + if constexpr (has_template_g2_type::value) { + using g2_type = typename curve_type::template g2_type<>; + run_benchmark( + curve_name + " G2 addition", + [](typename g2_type::value_type& A, typename g2_type::value_type const& B) { + return A += B; + }); + run_benchmark( + curve_name + " G2 doubling", + [](typename g2_type::value_type& A) { A.double_inplace(); - } ); - - auto smul_res = run_batched_test( - "smul", - BATCHES, SAMPLES_PER_BATCH / 256 / MULTIPLICATOR, - points1, - [&]( value_type & A, value_type const& B) { - for(int m = 0; m < MULTIPLICATOR; ++m) - A = A * constants[0]; - } ); - - char filename[200]= {0}; - sprintf(filename,"%s-curve-ops-%03d.csv", curve_name.c_str(), MULTIPLICATOR); - - std::ofstream f(filename, std::ofstream::out); - f << "# " << typeid(CurveGroup).name() << std::endl; - f << "madd,add,dbl,smul" << std::endl; - std::size_t prec = 4; - for(std::size_t i = 0; i < BATCHES; ++i) { - f - << std::fixed << std::setprecision(prec) << madd_res[i].count() << "," - << std::fixed << std::setprecision(prec) << add_res[i].count() << "," - << std::fixed << std::setprecision(prec) << dbl_res[i].count() << "," - << std::fixed << std::setprecision(prec) << smul_res[i].count() - << std::endl; - } - + return A; + //return A += A; + }); + run_benchmark( + curve_name + " G2 scalar multiplication", + [](typename g2_type::value_type& A, typename scalar_field::value_type const& B) { + return A *= B; + }); + } else { + std::cout << "Curve " << curve_name << " does not have G2, skipping benchmarks" << std::endl; } } -BOOST_AUTO_TEST_CASE(perf_test_bls12_381_g1) { - using policy_type = nil::crypto3::algebra::curves::bls12<381>::g1_type< - nil::crypto3::algebra::curves::coordinates::jacobian_with_a4_0, - nil::crypto3::algebra::curves::forms::short_weierstrass>; - - using affine_policy_type = nil::crypto3::algebra::curves::bls12<381>::g1_type; +BOOST_AUTO_TEST_SUITE(curves_benchmark) - curve_operations_perf_test("bls12-381-j0"); +BOOST_AUTO_TEST_CASE(pallas) +{ + benchmark_curve_operations("Pallas"); } -BOOST_AUTO_TEST_CASE(perf_test_pallas) { - using policy_type = nil::crypto3::algebra::curves::pallas::g1_type< - nil::crypto3::algebra::curves::coordinates::jacobian_with_a4_0, - nil::crypto3::algebra::curves::forms::short_weierstrass>; - - using affine_policy_type = nil::crypto3::algebra::curves::pallas::g1_type; - - curve_operations_perf_test("pallas-j0"); +BOOST_AUTO_TEST_CASE(vesta) +{ + benchmark_curve_operations("Vesta"); } -BOOST_AUTO_TEST_CASE(perf_test_mnt4) { - using policy_type = nil::crypto3::algebra::curves::mnt4<298>::g1_type< - nil::crypto3::algebra::curves::coordinates::projective, - nil::crypto3::algebra::curves::forms::short_weierstrass>; - - using affine_policy_type = nil::crypto3::algebra::curves::mnt4<298>::g1_type< - nil::crypto3::algebra::curves::coordinates::affine, - nil::crypto3::algebra::curves::forms::short_weierstrass>; - - curve_operations_perf_test("mnt4-p"); +BOOST_AUTO_TEST_CASE(bls12_381) +{ + benchmark_curve_operations>("BLS12-381"); } -BOOST_AUTO_TEST_CASE(perf_test_mnt6) { - using policy_type = nil::crypto3::algebra::curves::mnt6<298>::g1_type< - nil::crypto3::algebra::curves::coordinates::projective, - nil::crypto3::algebra::curves::forms::short_weierstrass>; - - using affine_policy_type = nil::crypto3::algebra::curves::mnt6<298>::g1_type< - nil::crypto3::algebra::curves::coordinates::affine, - nil::crypto3::algebra::curves::forms::short_weierstrass>; - - curve_operations_perf_test("mnt6-p"); +BOOST_AUTO_TEST_CASE(mnt4_298) +{ + benchmark_curve_operations>("MNT4-298"); } -BOOST_AUTO_TEST_CASE(perf_test_ed25519) { - using policy_type = nil::crypto3::algebra::curves::ed25519::g1_type< - nil::crypto3::algebra::curves::coordinates::extended_with_a_minus_1, - nil::crypto3::algebra::curves::forms::twisted_edwards>; - - using affine_policy_type = nil::crypto3::algebra::curves::ed25519::g1_type< - nil::crypto3::algebra::curves::coordinates::affine, - nil::crypto3::algebra::curves::forms::twisted_edwards>; - - curve_operations_perf_test("ed25519-ex-1"); +BOOST_AUTO_TEST_CASE(mnt6_298) +{ + benchmark_curve_operations>("MNT6-298"); } diff --git a/libs/algebra/test/bench_test/bench_fields.cpp b/libs/algebra/test/bench_test/bench_fields.cpp index 84750d1e7..0a7861a90 100644 --- a/libs/algebra/test/bench_test/bench_fields.cpp +++ b/libs/algebra/test/bench_test/bench_fields.cpp @@ -161,7 +161,7 @@ void run_perf_test(std::string const& field_name) { std::ofstream f(filename, std::ofstream::out); f << "# " << typeid(Field).name() << std::endl; - f << "sum,mul,sqr,inv" << std::endl; + f << "sum,mul,sub,sqr,inv" << std::endl; for(size_t i = 0; i < plus_results.size(); ++i) { f << std::fixed << std::setprecision(3) << plus_results[i].count() << "," diff --git a/libs/benchmark_tools/CMakeLists.txt b/libs/benchmark_tools/CMakeLists.txt new file mode 100644 index 000000000..56d258100 --- /dev/null +++ b/libs/benchmark_tools/CMakeLists.txt @@ -0,0 +1,29 @@ +#---------------------------------------------------------------------------# +# Copyright (c) 2024 Vasiliy Olekhov +# +# SPDX-License-Identifier: MIT +#---------------------------------------------------------------------------# + +include(CMConfig) +include(CMSetupVersion) + +cm_project(benchmark_tools WORKSPACE_NAME ${CMAKE_WORKSPACE_NAME} LANGUAGES CXX) + +include(CMDeploy) + +cm_setup_version(VERSION 0.1.0 PREFIX ${CMAKE_WORKSPACE_NAME}_${CURRENT_PROJECT_NAME}) + +add_library(${CMAKE_WORKSPACE_NAME}_${CURRENT_PROJECT_NAME} INTERFACE) + +set_target_properties(${CMAKE_WORKSPACE_NAME}_${CURRENT_PROJECT_NAME} PROPERTIES + EXPORT_NAME ${CURRENT_PROJECT_NAME}) + +target_include_directories(${CMAKE_WORKSPACE_NAME}_${CURRENT_PROJECT_NAME} INTERFACE + $ + $) + +cm_deploy(TARGETS ${CMAKE_WORKSPACE_NAME}_${CURRENT_PROJECT_NAME} + INCLUDE include + NAMESPACE ${CMAKE_WORKSPACE_NAME}::) + +include(CMTest) diff --git a/libs/benchmark_tools/include/nil/crypto3/bench/benchmark.hpp b/libs/benchmark_tools/include/nil/crypto3/bench/benchmark.hpp new file mode 100644 index 000000000..32e357737 --- /dev/null +++ b/libs/benchmark_tools/include/nil/crypto3/bench/benchmark.hpp @@ -0,0 +1,189 @@ +//---------------------------------------------------------------------------// +// Copyright (c) 2024 Vasiliy Olekhov +// +// SPDX-License-Identifier: MIT +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in all +// copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. +//---------------------------------------------------------------------------// + + +#ifndef CRYPTO3_BENCHMARK_HPP +#define CRYPTO3_BENCHMARK_HPP + +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +#include + +namespace nil { + namespace crypto3 { + namespace bench { + +/* Amount of elements that will not fit into L1D cache. + * Goldilocks field is the smallest object to benchmark, 64 bits, 8 bytes, + * so 8192 samples take 64kb, that is twice as large as L1D cache (32kb) + * Largest object to benchmark is BLS12-381 Fp12, 2over3over2, 72 bytes each, + * This will take 589kb + * */ +constexpr std::size_t SAMPLES_COUNT = 8192; + +template +std::vector generate_samples() +{ + std::vector samples; + for(std::size_t i = 0; i < SAMPLES_COUNT; ++i) { + samples.emplace_back(algebra::random_element()); + } + return samples; +} + +template +std::tuple...> allocate_samples() +{ + return std::make_tuple(generate_samples()...); +} + + +template +std::array calculate_strides() +{ + /* For each type of argument calculate stride used to traverse array of samples + * Stride is twice larger than a cache line to ensure values for benchmarked + * operation are not cached */ + return { (1 + sysconf(_SC_LEVEL1_DCACHE_LINESIZE)*2 / sizeof(typename A::value_type)) ... }; + // stride = 0 means the same element is used in all operations, maximum cache utilization + // return {(0*sizeof(typename A::value_type)) ...}; +} + + +template +auto make_slice_impl( + std::tuple...>& samples, + const std::array& strides, + std::size_t i, + std::index_sequence +) -> std::tuple +{ + return std::tuple( + std::get(samples)[i * strides[I] % SAMPLES_COUNT]... + ); +} + + +template +auto make_slice( + std::tuple...>& samples, + const std::array& strides, + std::size_t i +) -> std::tuple +{ + return make_slice_impl( + samples, strides, i, std::index_sequence_for{} + ); +} + + +template +void run_benchmark(std::string const& name, F && func) +{ + using duration = std::chrono::duration; + + auto samples = allocate_samples(); + auto strides = calculate_strides(); + + auto run_batch = [&] (std::size_t batch_size) { + for(std::size_t i = 0; i < batch_size; ++i) { + auto args = make_slice(samples, strides, i); + /* volatile hints to compiler that it has important side effects + * and call should not be optimized out */ + volatile auto r = std::apply(func, args); + (void) r; + } + }; + + auto run_at_least = [&] (duration const& dur) { + std::size_t WARMUP_BATCH_SIZE = 1000, total_runs = 0; + auto start = std::chrono::high_resolution_clock::now(); + while (std::chrono::high_resolution_clock::now() - start < dur) { + run_batch(WARMUP_BATCH_SIZE); + total_runs += WARMUP_BATCH_SIZE; + } + return total_runs; + }; + + std::size_t MEASUREMENTS = 100; + duration WARMUP_DURATION = std::chrono::seconds(3); + + std::size_t BATCH_SIZE = 1 + run_at_least(WARMUP_DURATION)/MEASUREMENTS/10; + + std::vector durations(MEASUREMENTS); + for(std::size_t m = 0; m < MEASUREMENTS; ++m) { + auto start = std::chrono::high_resolution_clock::now(); + run_batch(BATCH_SIZE); + auto finish = std::chrono::high_resolution_clock::now(); + durations[m] = (finish - start).count()*1.0 / BATCH_SIZE; + } + + std::sort(durations.begin(), durations.end()); + + // discard top 20% outliers + durations.resize(MEASUREMENTS * 0.8); + + double median = durations[durations.size()/2]; + double mean = 0, stddiv = 0; + + for(auto &dur : durations) { + mean += dur; + stddiv += dur*dur; + } + + mean /= durations.size(); + // stddiv^2 = E x^2 - (E x)^2 + stddiv = sqrt(stddiv / durations.size() - mean * mean); + + // https://support.numxl.com/hc/en-us/articles/115001223503-MdAPE-Median-Absolute-Percentage-Error + for(auto &dur : durations) { + dur = (dur - median) / dur; + if ( dur < 0 ) { + dur = -dur; + } + } + std::sort(durations.begin(), durations.end()); + double MdAPE = durations[durations.size()/2]; + + std::cout << std::fixed << std::setprecision(3); + std::cout << name << + " mean: " << mean << "ns err: " << (MdAPE*100) << + "% median: " << median << "ns stddiv: " << stddiv << + std::endl; +} + + } + } +} + +#endif /* CRYPTO3_BENCHMARK_HPP */ diff --git a/libs/benchmark_tools/include/nil/crypto3/bench/scoped_profiler.hpp b/libs/benchmark_tools/include/nil/crypto3/bench/scoped_profiler.hpp new file mode 100644 index 000000000..09b8be504 --- /dev/null +++ b/libs/benchmark_tools/include/nil/crypto3/bench/scoped_profiler.hpp @@ -0,0 +1,130 @@ +//---------------------------------------------------------------------------// +// Copyright (c) 2023 Martun Karapetyan +// Copyright (c) 2024 Vasiliy Olekhov +// +// MIT License +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in all +// copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. +//---------------------------------------------------------------------------// + +#ifndef CRYPTO3_SCOPED_PROFILER_HPP +#define CRYPTO3_SCOPED_PROFILER_HPP + +#include +#include +#include +#include +#include + +namespace nil { + namespace crypto3 { + namespace bench { + namespace detail { + +// Measures execution time of a given function just once. Prints +// the time when leaving the function in which this class was created. +class scoped_profiler +{ + public: + inline scoped_profiler(std::string name) + : start(std::chrono::high_resolution_clock::now()) + , name(name) { + } + + inline ~scoped_profiler() { + auto elapsed = std::chrono::duration_cast( + std::chrono::high_resolution_clock::now() - start); + std::cout << name << ": " << std::fixed << std::setprecision(3) + << elapsed.count() << " ms" << std::endl; + } + + private: + std::chrono::time_point start; + std::string name; +}; + +class call_stats { + public: + // Make this class singleton. + static call_stats& get_stats() { + static call_stats instance; + return instance; + } + + void add_stat(const std::string& name, uint64_t time_ms) { + call_counts[name]++; + call_miliseconds[name] += time_ms; + } + + private: + call_stats() {} + ~call_stats() { + for (const auto& [name, count]: call_counts) { + uint64_t miliseconds = call_miliseconds[name] / 1000000; + std::cout << name << ": " << count << " calls " + << miliseconds / 1000 << " sec " + << miliseconds % 1000 << " ms" << std::endl; + } + } + + std::unordered_map call_counts; + std::unordered_map call_miliseconds; +}; + +// Measures the total execution time of the functions it's placed in, and the number of calls. +// Prints the time and number of calls on program exit. +class scoped_aggregate_profiler +{ + public: + inline scoped_aggregate_profiler(std::string name) + : start(std::chrono::high_resolution_clock::now()) + , name(name) { + } + + inline ~scoped_aggregate_profiler() { + auto elapsed = std::chrono::duration_cast( + std::chrono::high_resolution_clock::now() - start); + call_stats::get_stats().add_stat(name, elapsed.count()); + } + + private: + std::chrono::time_point start; + std::string name; +}; + + } // namespace detail + } // namespace bench + } // namespace crypto3 +} // namespace nil + +#ifdef PROFILING_ENABLED + #define PROFILE_SCOPE(name) \ + nil::crypto3::bench::detail::scoped_profiler profiler(name); +#else + #define PROFILE_SCOPE(name) +#endif + +#ifdef PROFILING_ENABLED + #define PROFILE_FUNCTION_CALLS() \ + nil::crypto3::bench::detail::scoped_aggregate_profiler profiler(__PRETTY_FUNCTION__ ); +#else + #define PROFILE_FUNCTION_CALLS() +#endif + +#endif // CRYPTO3_SCOPED_PROFILER_HPP diff --git a/libs/marshalling/core/example/CMakeLists.txt b/libs/marshalling/core/example/CMakeLists.txt index fce0014d6..6d6bfa2a6 100644 --- a/libs/marshalling/core/example/CMakeLists.txt +++ b/libs/marshalling/core/example/CMakeLists.txt @@ -14,8 +14,6 @@ macro(define_marshalling_example name) add_executable(marshalling_${name}_example ${name}.cpp) target_link_libraries(marshalling_${name}_example PRIVATE - ${CMAKE_WORKSPACE_NAME}::core - Boost::container) target_include_directories(marshalling_${name}_example PRIVATE diff --git a/libs/marshalling/zk/example/CMakeLists.txt b/libs/marshalling/zk/example/CMakeLists.txt index 55af1dcc5..34c6f5867 100644 --- a/libs/marshalling/zk/example/CMakeLists.txt +++ b/libs/marshalling/zk/example/CMakeLists.txt @@ -15,15 +15,11 @@ macro(define_marshalling_example name) add_executable(marshalling_${name}_example ${name}.cpp) target_link_libraries(marshalling_${name}_example PRIVATE - crypto3::multiprecision crypto3::algebra crypto3::zk ${CMAKE_WORKSPACE_NAME}::marshalling-multiprecision ${CMAKE_WORKSPACE_NAME}::marshalling-algebra - ${CMAKE_WORKSPACE_NAME}::crypto3_zk - ${CMAKE_WORKSPACE_NAME}::core - Boost::container) target_include_directories(marshalling_${name}_example PRIVATE diff --git a/libs/zk/CMakeLists.txt b/libs/zk/CMakeLists.txt index 82a674124..08e64325e 100644 --- a/libs/zk/CMakeLists.txt +++ b/libs/zk/CMakeLists.txt @@ -5,14 +5,14 @@ if(NOT CMAKE_WORKSPACE_NAME OR NOT ("${CMAKE_WORKSPACE_NAME}" STREQUAL "crypto3" cm_workspace(crypto3) endif() -option(ZK_PLACEHOLDER_PROFILING_ENABLED "Build with placeholder profiling" FALSE) +option(PROFILING_ENABLED "Build with placeholder profiling" FALSE) option(ZK_PLACEHOLDER_DEBUG_ENABLED "Build with placeholder testing inside" FALSE) -if(ZK_PLACEHOLDER_PROFILING) - add_definitions(-DZK_PLACEHOLDER_PROFILING_ENABLED) +if(PROFILING_ENABLED) + add_definitions(-DPROFILING_ENABLED) endif() -if(ZK_PLACEHOLDER_DEBUG) +if(ZK_PLACEHOLDER_DEBUG_ENABLED) add_definitions(-DZK_PLACEHOLDER_DEBUG_ENABLED) endif() @@ -45,6 +45,7 @@ target_link_libraries(${CMAKE_WORKSPACE_NAME}_${CURRENT_PROJECT_NAME} INTERFACE ${CMAKE_WORKSPACE_NAME}::multiprecision ${CMAKE_WORKSPACE_NAME}::containers ${CMAKE_WORKSPACE_NAME}::marshalling-zk + ${CMAKE_WORKSPACE_NAME}::benchmark_tools ) cm_deploy(TARGETS ${CMAKE_WORKSPACE_NAME}_${CURRENT_PROJECT_NAME} diff --git a/libs/zk/include/nil/crypto3/zk/commitments/detail/polynomial/basic_fri.hpp b/libs/zk/include/nil/crypto3/zk/commitments/detail/polynomial/basic_fri.hpp index 1f3c838ed..5db51d804 100644 --- a/libs/zk/include/nil/crypto3/zk/commitments/detail/polynomial/basic_fri.hpp +++ b/libs/zk/include/nil/crypto3/zk/commitments/detail/polynomial/basic_fri.hpp @@ -51,7 +51,8 @@ #include #include #include -#include + +#include namespace nil { namespace crypto3 { @@ -446,7 +447,7 @@ namespace nil { std::shared_ptr> D, const std::size_t fri_step ) { - PROFILE_PLACEHOLDER_SCOPE("Basic FRI Precommit time"); + PROFILE_SCOPE("Basic FRI Precommit time"); for (std::size_t i = 0; i < poly.size(); ++i) { if (poly[i].size() != D->size()) { diff --git a/libs/zk/include/nil/crypto3/zk/snark/arithmetization/plonk/constraint_system.hpp b/libs/zk/include/nil/crypto3/zk/snark/arithmetization/plonk/constraint_system.hpp index 7aea3b4fc..6300afef3 100644 --- a/libs/zk/include/nil/crypto3/zk/snark/arithmetization/plonk/constraint_system.hpp +++ b/libs/zk/include/nil/crypto3/zk/snark/arithmetization/plonk/constraint_system.hpp @@ -290,7 +290,7 @@ namespace nil { } } for (const auto& table : _lookup_tables) { - for( const auto &lookup_options: table.lookup_options ){ + for (std::size_t i = 0; i < table.lookup_options.size(); ++i) { // +3 because now any lookup option is lookup_column * lookup_selector * (1-q_last-q_blind) -- three polynomials degree rows_amount-1 if( lookup_chunk + 3 >= max_quotient_chunks ){ lookup_parts.push_back(lookup_part); diff --git a/libs/zk/include/nil/crypto3/zk/snark/systems/plonk/placeholder/detail/placeholder_scoped_profiler.hpp b/libs/zk/include/nil/crypto3/zk/snark/systems/plonk/placeholder/detail/placeholder_scoped_profiler.hpp deleted file mode 100644 index 2b069cb0c..000000000 --- a/libs/zk/include/nil/crypto3/zk/snark/systems/plonk/placeholder/detail/placeholder_scoped_profiler.hpp +++ /dev/null @@ -1,128 +0,0 @@ -//---------------------------------------------------------------------------// -// Copyright (c) 2023 Martun Karapetyan -// -// MIT License -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in all -// copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -// SOFTWARE. -//---------------------------------------------------------------------------// - -#ifndef CRYPTO3_PLACEHOLDER_SCOPED_PROFILER_HPP -#define CRYPTO3_PLACEHOLDER_SCOPED_PROFILER_HPP - -#include -#include - -namespace nil { - namespace crypto3 { - namespace zk { - namespace snark { - namespace detail { - - // Measures execution time of a given function just once. Prints - // the time when leaving the function in which this class was created. - class placeholder_scoped_profiler - { - public: - inline placeholder_scoped_profiler(std::string name) - : start(std::chrono::high_resolution_clock::now()) - , name(name) { - } - - inline ~placeholder_scoped_profiler() { - auto elapsed = std::chrono::duration_cast( - std::chrono::high_resolution_clock::now() - start); - std::cout << name << ": " << std::fixed << std::setprecision(3) - << elapsed.count() << " ms" << std::endl; - } - - private: - std::chrono::time_point start; - std::string name; - }; - - class call_stats { - public: - // Make this class singleton. - static call_stats& get_stats() { - static call_stats instance; - return instance; - } - - void add_stat(const std::string& name, uint64_t time_ms) { - call_counts[name]++; - call_miliseconds[name] += time_ms; - } - - private: - call_stats() {} - ~call_stats() { - for (const auto& [name, count]: call_counts) { - uint64_t miliseconds = call_miliseconds[name] / 1000000; - std::cout << name << ": " << count << " calls " - << miliseconds / 1000 << " sec " - << miliseconds % 1000 << " ms" << std::endl; - } - } - - std::unordered_map call_counts; - std::unordered_map call_miliseconds; - }; - - // Measures the total execution time of the functions it's placed in, and the number of calls. - // Prints the time and number of calls on program exit. - class placeholder_scoped_aggregate_profiler - { - public: - inline placeholder_scoped_aggregate_profiler(std::string name) - : start(std::chrono::high_resolution_clock::now()) - , name(name) { - } - - inline ~placeholder_scoped_aggregate_profiler() { - auto elapsed = std::chrono::duration_cast( - std::chrono::high_resolution_clock::now() - start); - call_stats::get_stats().add_stat(name, elapsed.count()); - } - - private: - std::chrono::time_point start; - std::string name; - }; - - } // namespace detail - } // namespace snark - } // namespace zk - } // namespace crypto3 -} // namespace nil - -#ifdef ZK_PLACEHOLDER_PROFILING_ENABLED - #define PROFILE_PLACEHOLDER_SCOPE(name) \ - nil::crypto3::zk::snark::detail::placeholder_scoped_profiler profiler(name); -#else - #define PROFILE_PLACEHOLDER_SCOPE(name) -#endif - -#ifdef ZK_PLACEHOLDER_PROFILING_ENABLED - #define PROFILE_PLACEHOLDER_FUNCTION_CALLS() \ - nil::crypto3::zk::snark::detail::placeholder_scoped_aggregate_profiler profiler(__PRETTY_FUNCTION__ ); -#else - #define PROFILE_PLACEHOLDER_FUNCTION_CALLS() -#endif - -#endif // CRYPTO3_PLACEHOLDER_SCOPED_PROFILER_HPP diff --git a/libs/zk/include/nil/crypto3/zk/snark/systems/plonk/placeholder/gates_argument.hpp b/libs/zk/include/nil/crypto3/zk/snark/systems/plonk/placeholder/gates_argument.hpp index 75710a898..0823a1b6d 100644 --- a/libs/zk/include/nil/crypto3/zk/snark/systems/plonk/placeholder/gates_argument.hpp +++ b/libs/zk/include/nil/crypto3/zk/snark/systems/plonk/placeholder/gates_argument.hpp @@ -52,6 +52,8 @@ #include #include +#include + namespace nil { namespace crypto3 { namespace zk { @@ -112,7 +114,7 @@ namespace nil { std::uint32_t max_gates_degree, const polynomial_dfs_type &mask_polynomial, transcript_type& transcript) { - PROFILE_PLACEHOLDER_SCOPE("gate_argument_time"); + PROFILE_SCOPE("gate_argument_time"); // max_gates_degree that comes from the outside does not take into account multiplication // by selector. diff --git a/libs/zk/include/nil/crypto3/zk/snark/systems/plonk/placeholder/lookup_argument.hpp b/libs/zk/include/nil/crypto3/zk/snark/systems/plonk/placeholder/lookup_argument.hpp index 189f9dc64..ddc6d14f5 100644 --- a/libs/zk/include/nil/crypto3/zk/snark/systems/plonk/placeholder/lookup_argument.hpp +++ b/libs/zk/include/nil/crypto3/zk/snark/systems/plonk/placeholder/lookup_argument.hpp @@ -46,7 +46,8 @@ #include #include #include -#include + +#include namespace nil { namespace crypto3 { @@ -151,7 +152,7 @@ namespace nil { } prover_lookup_result prove_eval() { - PROFILE_PLACEHOLDER_SCOPE("Lookup argument prove eval time"); + PROFILE_SCOPE("Lookup argument prove eval time"); // Construct lookup gates math::polynomial_dfs one_polynomial( @@ -469,7 +470,7 @@ namespace nil { visitor.visit(expr); math::cached_expression_evaluator evaluator(expr, - [&domain=basic_domain, &assignments=plonk_columns, &rotated_variable_values] + [&assignments=plonk_columns, &rotated_variable_values] (const DfsVariableType &var) -> const polynomial_dfs_type& { if (var.rotation == 0) { return assignments.get_variable_value_without_rotation(var); diff --git a/libs/zk/include/nil/crypto3/zk/snark/systems/plonk/placeholder/permutation_argument.hpp b/libs/zk/include/nil/crypto3/zk/snark/systems/plonk/placeholder/permutation_argument.hpp index fa60e4333..56a6fe7e3 100644 --- a/libs/zk/include/nil/crypto3/zk/snark/systems/plonk/placeholder/permutation_argument.hpp +++ b/libs/zk/include/nil/crypto3/zk/snark/systems/plonk/placeholder/permutation_argument.hpp @@ -42,9 +42,10 @@ #include #include #include -#include #include +#include + namespace nil { namespace crypto3 { namespace zk { @@ -76,7 +77,7 @@ namespace nil { typename ParamsType::commitment_scheme_type& commitment_scheme, transcript_type& transcript ) { - PROFILE_PLACEHOLDER_SCOPE("permutation_argument_prove_eval_time"); + PROFILE_SCOPE("permutation_argument_prove_eval_time"); const std::vector> &S_sigma = preprocessed_data.permutation_polynomials; diff --git a/libs/zk/include/nil/crypto3/zk/snark/systems/plonk/placeholder/preprocessor.hpp b/libs/zk/include/nil/crypto3/zk/snark/systems/plonk/placeholder/preprocessor.hpp index 593633720..dc08b02ee 100644 --- a/libs/zk/include/nil/crypto3/zk/snark/systems/plonk/placeholder/preprocessor.hpp +++ b/libs/zk/include/nil/crypto3/zk/snark/systems/plonk/placeholder/preprocessor.hpp @@ -43,7 +43,6 @@ #include #include #include -#include #include #include #include @@ -52,6 +51,8 @@ #include #include +#include + namespace nil { namespace crypto3 { namespace zk { @@ -517,7 +518,7 @@ namespace nil { const std::size_t max_quotient_poly_chunks = 0, const typename FieldType::value_type& delta=algebra::fields::arithmetic_params::multiplicative_generator ) { - PROFILE_PLACEHOLDER_SCOPE("Placeholder public preprocessor"); + PROFILE_SCOPE("Placeholder public preprocessor"); std::size_t N_rows = table_description.rows_amount; std::size_t usable_rows = table_description.usable_rows_amount; diff --git a/libs/zk/include/nil/crypto3/zk/snark/systems/plonk/placeholder/prover.hpp b/libs/zk/include/nil/crypto3/zk/snark/systems/plonk/placeholder/prover.hpp index dbd4ddfba..8ec7b78d8 100644 --- a/libs/zk/include/nil/crypto3/zk/snark/systems/plonk/placeholder/prover.hpp +++ b/libs/zk/include/nil/crypto3/zk/snark/systems/plonk/placeholder/prover.hpp @@ -40,13 +40,14 @@ #include #include #include -#include #include #include #include #include #include +#include + namespace nil { namespace crypto3 { namespace zk { @@ -56,7 +57,7 @@ namespace nil { static inline std::vector> split_polynomial(const math::polynomial &f, std::size_t max_degree) { - PROFILE_PLACEHOLDER_SCOPE("split_polynomial_time"); + PROFILE_SCOPE("split_polynomial_time"); std::vector> f_splitted; @@ -131,13 +132,13 @@ namespace nil { } placeholder_proof process() { - PROFILE_PLACEHOLDER_SCOPE("Placeholder prover, total time"); + PROFILE_SCOPE("Placeholder prover, total time"); // 2. Commit witness columns and public_input columns _commitment_scheme.append_to_batch(VARIABLE_VALUES_BATCH, _polynomial_table->witnesses()); _commitment_scheme.append_to_batch(VARIABLE_VALUES_BATCH, _polynomial_table->public_inputs()); { - PROFILE_PLACEHOLDER_SCOPE("variable_values_precommit_time"); + PROFILE_SCOPE("variable_values_precommit_time"); _proof.commitments[VARIABLE_VALUES_BATCH] = _commitment_scheme.commit(VARIABLE_VALUES_BATCH); } transcript(_proof.commitments[VARIABLE_VALUES_BATCH]); @@ -208,7 +209,7 @@ namespace nil { generate_evaluation_points(); { - PROFILE_PLACEHOLDER_SCOPE("commitment scheme proof eval time"); + PROFILE_SCOPE("commitment scheme proof eval time"); _proof.eval_proof.eval_proof = _commitment_scheme.proof_eval(transcript); } @@ -222,7 +223,7 @@ namespace nil { quotient_polynomial(), table_description.rows_amount - 1 ); - PROFILE_PLACEHOLDER_SCOPE("split_polynomial_dfs_conversion_time"); + PROFILE_SCOPE("split_polynomial_dfs_conversion_time"); std::size_t split_polynomial_size = std::max( (preprocessed_public_data.identity_polynomials.size() + 2) * (preprocessed_public_data.common_data.desc.rows_amount -1 ), @@ -257,7 +258,7 @@ namespace nil { } polynomial_type quotient_polynomial() { - PROFILE_PLACEHOLDER_SCOPE("quotient_polynomial_time"); + PROFILE_SCOPE("quotient_polynomial_time"); // 7.1. Get $\alpha_0, \dots, \alpha_8 \in \mathbb{F}$ from $hash(\text{transcript})$ std::array alphas = @@ -283,7 +284,7 @@ namespace nil { typename placeholder_lookup_argument_prover::prover_lookup_result lookup_argument() { - PROFILE_PLACEHOLDER_SCOPE("lookup_argument_time"); + PROFILE_SCOPE("lookup_argument_time"); typename placeholder_lookup_argument_prover< FieldType, @@ -311,7 +312,7 @@ namespace nil { } commitment_type T_commit(const std::vector& T_splitted_dfs) { - PROFILE_PLACEHOLDER_SCOPE("T_splitted_precommit_time"); + PROFILE_SCOPE("T_splitted_precommit_time"); _commitment_scheme.append_to_batch(QUOTIENT_BATCH, T_splitted_dfs); return _commitment_scheme.commit(QUOTIENT_BATCH); } @@ -343,7 +344,7 @@ namespace nil { } void generate_evaluation_points() { - PROFILE_PLACEHOLDER_SCOPE("evaluation_points_generated_time"); + PROFILE_SCOPE("evaluation_points_generated_time"); _omega = preprocessed_public_data.common_data.basic_domain->get_domain_element(1); const std::size_t witness_columns = table_description.witness_columns; diff --git a/libs/zk/include/nil/crypto3/zk/snark/systems/plonk/placeholder/verifier.hpp b/libs/zk/include/nil/crypto3/zk/snark/systems/plonk/placeholder/verifier.hpp index 65045c78b..fbd573402 100644 --- a/libs/zk/include/nil/crypto3/zk/snark/systems/plonk/placeholder/verifier.hpp +++ b/libs/zk/include/nil/crypto3/zk/snark/systems/plonk/placeholder/verifier.hpp @@ -40,6 +40,8 @@ #include #include +#include + namespace nil { namespace crypto3 { namespace zk { @@ -67,7 +69,7 @@ namespace nil { typename FieldType::value_type challenge, bool _is_lookup_enabled ) { - PROFILE_PLACEHOLDER_SCOPE("evaluation_points_generated_time"); + PROFILE_SCOPE("evaluation_points_generated_time"); const std::size_t witness_columns = table_description.witness_columns; const std::size_t public_input_columns = table_description.public_input_columns; diff --git a/libs/zk/test/CMakeLists.txt b/libs/zk/test/CMakeLists.txt index c58e1849d..bb813e1f9 100644 --- a/libs/zk/test/CMakeLists.txt +++ b/libs/zk/test/CMakeLists.txt @@ -17,10 +17,8 @@ cm_test_link_libraries(${CMAKE_WORKSPACE_NAME}_${CURRENT_PROJECT_NAME} crypto3::marshalling-zk Boost::unit_test_framework) -option(ZK_PLACEHOLDER_PROFILING_ENABLED "Build with placeholder profiling" FALSE) - -if(ZK_PLACEHOLDER_PROFILING) - add_definitions(-DZK_PLACEHOLDER_PROFILING_ENABLED) +if(PROFILING_ENABLED) + add_definitions(-DPROFILING_ENABLED) endif() macro(define_zk_test test) diff --git a/libs/zk/test/bench_test/lpc.cpp b/libs/zk/test/bench_test/lpc.cpp index fbee5d86e..d2fc71ee0 100644 --- a/libs/zk/test/bench_test/lpc.cpp +++ b/libs/zk/test/bench_test/lpc.cpp @@ -27,7 +27,7 @@ #define BOOST_TEST_MODULE lpc_test // Do it manually for all performance tests -#define ZK_PLACEHOLDER_PROFILING_ENABLED +#define PROFILING_ENABLED #include @@ -49,7 +49,8 @@ #include #include #include -#include + +#include using namespace nil::crypto3; using namespace nil::crypto3::zk::snark; @@ -126,7 +127,7 @@ inline std::vector generate_random_step_list(const std::size_t r, c BOOST_AUTO_TEST_SUITE(lpc_performance_test_suite) BOOST_AUTO_TEST_CASE(step_list_1) { - PROFILE_PLACEHOLDER_SCOPE("LPC step list 1 test"); + PROFILE_SCOPE("LPC step list 1 test"); typedef algebra::curves::bls12<381> curve_type; typedef typename curve_type::scalar_field_type FieldType; @@ -188,7 +189,7 @@ BOOST_AUTO_TEST_SUITE(lpc_performance_test_suite) std::map commitments; { - PROFILE_PLACEHOLDER_SCOPE("polynomial commitment"); + PROFILE_SCOPE("polynomial commitment"); lpc_scheme_prover.append_to_batch(0, poly); commitments[0] = lpc_scheme_prover.commit(0); } @@ -197,7 +198,7 @@ BOOST_AUTO_TEST_SUITE(lpc_performance_test_suite) typename lpc_scheme_type::proof_type proof; std::array x_data{}; { - PROFILE_PLACEHOLDER_SCOPE("proof generation"); + PROFILE_SCOPE("proof generation"); lpc_scheme_prover.append_eval_point(0, algebra::fields::arithmetic_params::multiplicative_generator); zk::transcript::fiat_shamir_heuristic_sequential transcript(x_data); @@ -205,7 +206,7 @@ BOOST_AUTO_TEST_SUITE(lpc_performance_test_suite) } { - PROFILE_PLACEHOLDER_SCOPE("verification"); + PROFILE_SCOPE("verification"); zk::transcript::fiat_shamir_heuristic_sequential transcript_verifier(x_data); lpc_scheme_verifier.set_batch_size(0, proof.z.get_batch_size(0)); @@ -217,7 +218,7 @@ BOOST_AUTO_TEST_SUITE(lpc_performance_test_suite) } BOOST_AUTO_TEST_CASE(step_list_3) { - PROFILE_PLACEHOLDER_SCOPE("LPC step list 3 test"); + PROFILE_SCOPE("LPC step list 3 test"); typedef algebra::curves::bls12<381> curve_type; typedef typename curve_type::scalar_field_type FieldType; @@ -279,7 +280,7 @@ BOOST_AUTO_TEST_SUITE(lpc_performance_test_suite) std::map commitments; { - PROFILE_PLACEHOLDER_SCOPE("polynomial commitment"); + PROFILE_SCOPE("polynomial commitment"); lpc_scheme_prover.append_to_batch(0, poly); commitments[0] = lpc_scheme_prover.commit(0); } @@ -288,7 +289,7 @@ BOOST_AUTO_TEST_SUITE(lpc_performance_test_suite) typename lpc_scheme_type::proof_type proof; std::array x_data{}; { - PROFILE_PLACEHOLDER_SCOPE("proof generation"); + PROFILE_SCOPE("proof generation"); lpc_scheme_prover.append_eval_point(0, algebra::fields::arithmetic_params::multiplicative_generator); zk::transcript::fiat_shamir_heuristic_sequential transcript(x_data); @@ -296,7 +297,7 @@ BOOST_AUTO_TEST_SUITE(lpc_performance_test_suite) } { - PROFILE_PLACEHOLDER_SCOPE("verification"); + PROFILE_SCOPE("verification"); zk::transcript::fiat_shamir_heuristic_sequential transcript_verifier(x_data); lpc_scheme_verifier.set_batch_size(0, proof.z.get_batch_size(0)); @@ -308,7 +309,7 @@ BOOST_AUTO_TEST_SUITE(lpc_performance_test_suite) } BOOST_AUTO_TEST_CASE(step_list_5) { - PROFILE_PLACEHOLDER_SCOPE("LPC step list 5 test"); + PROFILE_SCOPE("LPC step list 5 test"); typedef algebra::curves::bls12<381> curve_type; typedef typename curve_type::scalar_field_type FieldType; @@ -369,7 +370,7 @@ BOOST_AUTO_TEST_SUITE(lpc_performance_test_suite) std::map commitments; { - PROFILE_PLACEHOLDER_SCOPE("polynomial commitment"); + PROFILE_SCOPE("polynomial commitment"); lpc_scheme_prover.append_to_batch(0, poly); commitments[0] = lpc_scheme_prover.commit(0); } @@ -378,7 +379,7 @@ BOOST_AUTO_TEST_SUITE(lpc_performance_test_suite) typename lpc_scheme_type::proof_type proof; std::array x_data{}; { - PROFILE_PLACEHOLDER_SCOPE("proof generation"); + PROFILE_SCOPE("proof generation"); lpc_scheme_prover.append_eval_point(0, algebra::fields::arithmetic_params::multiplicative_generator); zk::transcript::fiat_shamir_heuristic_sequential transcript(x_data); @@ -386,7 +387,7 @@ BOOST_AUTO_TEST_SUITE(lpc_performance_test_suite) } { - PROFILE_PLACEHOLDER_SCOPE("verification"); + PROFILE_SCOPE("verification"); zk::transcript::fiat_shamir_heuristic_sequential transcript_verifier(x_data); lpc_scheme_verifier.set_batch_size(0, proof.z.get_batch_size(0)); @@ -397,4 +398,4 @@ BOOST_AUTO_TEST_SUITE(lpc_performance_test_suite) } } -BOOST_AUTO_TEST_SUITE_END() \ No newline at end of file +BOOST_AUTO_TEST_SUITE_END() diff --git a/libs/zk/test/commitment/lpc_performance.cpp b/libs/zk/test/commitment/lpc_performance.cpp index 16eadf6fb..a9c8ef128 100644 --- a/libs/zk/test/commitment/lpc_performance.cpp +++ b/libs/zk/test/commitment/lpc_performance.cpp @@ -27,7 +27,7 @@ #define BOOST_TEST_MODULE lpc_test // Do it manually for all performance tests -#define ZK_PLACEHOLDER_PROFILING_ENABLED +#define PROFILING_ENABLED #include @@ -49,7 +49,8 @@ #include #include #include -#include + +#include using namespace nil::crypto3; using namespace nil::crypto3::zk::snark; @@ -127,7 +128,7 @@ BOOST_AUTO_TEST_SUITE(lpc_performance_test_suite) // TODO(martun): move this to bench folder. BOOST_AUTO_TEST_CASE(step_list_1, *boost::unit_test::disabled()) { - PROFILE_PLACEHOLDER_SCOPE("LPC step list 1 test"); + PROFILE_SCOPE("LPC step list 1 test"); typedef algebra::curves::bls12<381> curve_type; typedef typename curve_type::scalar_field_type FieldType; @@ -189,7 +190,7 @@ BOOST_AUTO_TEST_CASE(step_list_1, *boost::unit_test::disabled()) { std::map commitments; { - PROFILE_PLACEHOLDER_SCOPE("polynomial commitment"); + PROFILE_SCOPE("polynomial commitment"); lpc_scheme_prover.append_to_batch(0, poly); commitments[0] = lpc_scheme_prover.commit(0); } @@ -198,7 +199,7 @@ BOOST_AUTO_TEST_CASE(step_list_1, *boost::unit_test::disabled()) { typename lpc_scheme_type::proof_type proof; std::array x_data{}; { - PROFILE_PLACEHOLDER_SCOPE("proof generation"); + PROFILE_SCOPE("proof generation"); lpc_scheme_prover.append_eval_point(0, algebra::fields::arithmetic_params::multiplicative_generator); zk::transcript::fiat_shamir_heuristic_sequential transcript(x_data); @@ -206,7 +207,7 @@ BOOST_AUTO_TEST_CASE(step_list_1, *boost::unit_test::disabled()) { } { - PROFILE_PLACEHOLDER_SCOPE("verification"); + PROFILE_SCOPE("verification"); zk::transcript::fiat_shamir_heuristic_sequential transcript_verifier(x_data); lpc_scheme_verifier.set_batch_size(0, proof.z.get_batch_size(0)); @@ -218,7 +219,7 @@ BOOST_AUTO_TEST_CASE(step_list_1, *boost::unit_test::disabled()) { } BOOST_AUTO_TEST_CASE(step_list_3, *boost::unit_test::disabled()) { - PROFILE_PLACEHOLDER_SCOPE("LPC step list 3 test"); + PROFILE_SCOPE("LPC step list 3 test"); typedef algebra::curves::bls12<381> curve_type; typedef typename curve_type::scalar_field_type FieldType; @@ -280,7 +281,7 @@ BOOST_AUTO_TEST_CASE(step_list_3, *boost::unit_test::disabled()) { std::map commitments; { - PROFILE_PLACEHOLDER_SCOPE("polynomial commitment"); + PROFILE_SCOPE("polynomial commitment"); lpc_scheme_prover.append_to_batch(0, poly); commitments[0] = lpc_scheme_prover.commit(0); } @@ -289,7 +290,7 @@ BOOST_AUTO_TEST_CASE(step_list_3, *boost::unit_test::disabled()) { typename lpc_scheme_type::proof_type proof; std::array x_data{}; { - PROFILE_PLACEHOLDER_SCOPE("proof generation"); + PROFILE_SCOPE("proof generation"); lpc_scheme_prover.append_eval_point(0, algebra::fields::arithmetic_params::multiplicative_generator); zk::transcript::fiat_shamir_heuristic_sequential transcript(x_data); @@ -297,7 +298,7 @@ BOOST_AUTO_TEST_CASE(step_list_3, *boost::unit_test::disabled()) { } { - PROFILE_PLACEHOLDER_SCOPE("verification"); + PROFILE_SCOPE("verification"); zk::transcript::fiat_shamir_heuristic_sequential transcript_verifier(x_data); lpc_scheme_verifier.set_batch_size(0, proof.z.get_batch_size(0)); @@ -309,7 +310,7 @@ BOOST_AUTO_TEST_CASE(step_list_3, *boost::unit_test::disabled()) { } BOOST_AUTO_TEST_CASE(step_list_5, *boost::unit_test::disabled()) { - PROFILE_PLACEHOLDER_SCOPE("LPC step list 5 test"); + PROFILE_SCOPE("LPC step list 5 test"); typedef algebra::curves::bls12<381> curve_type; typedef typename curve_type::scalar_field_type FieldType; @@ -370,7 +371,7 @@ BOOST_AUTO_TEST_CASE(step_list_5, *boost::unit_test::disabled()) { std::map commitments; { - PROFILE_PLACEHOLDER_SCOPE("polynomial commitment"); + PROFILE_SCOPE("polynomial commitment"); lpc_scheme_prover.append_to_batch(0, poly); commitments[0] = lpc_scheme_prover.commit(0); } @@ -379,7 +380,7 @@ BOOST_AUTO_TEST_CASE(step_list_5, *boost::unit_test::disabled()) { typename lpc_scheme_type::proof_type proof; std::array x_data{}; { - PROFILE_PLACEHOLDER_SCOPE("proof generation"); + PROFILE_SCOPE("proof generation"); lpc_scheme_prover.append_eval_point(0, algebra::fields::arithmetic_params::multiplicative_generator); zk::transcript::fiat_shamir_heuristic_sequential transcript(x_data); @@ -387,7 +388,7 @@ BOOST_AUTO_TEST_CASE(step_list_5, *boost::unit_test::disabled()) { } { - PROFILE_PLACEHOLDER_SCOPE("verification"); + PROFILE_SCOPE("verification"); zk::transcript::fiat_shamir_heuristic_sequential transcript_verifier(x_data); lpc_scheme_verifier.set_batch_size(0, proof.z.get_batch_size(0)); diff --git a/libs/zk/test/systems/plonk/placeholder/circuits.hpp b/libs/zk/test/systems/plonk/placeholder/circuits.hpp index 3f97de80a..199befe01 100644 --- a/libs/zk/test/systems/plonk/placeholder/circuits.hpp +++ b/libs/zk/test/systems/plonk/placeholder/circuits.hpp @@ -694,14 +694,6 @@ namespace nil { table[2][0] = zero; table[2][1] = one; - plonk_variable x0(0, 0, false, plonk_variable::column_type::witness); - plonk_variable x1(0, 1, false, plonk_variable::column_type::witness); - plonk_variable p0(1, 0, false, plonk_variable::column_type::public_input); - plonk_variable p1(1, 1, false, plonk_variable::column_type::public_input); - -// test_circuit.copy_constraints.push_back(plonk_copy_constraint(x0, p0)); -// test_circuit.copy_constraints.push_back(plonk_copy_constraint(x1, p1)); - for (std::size_t i = 2; i < test_circuit.usable_rows - 1; i++) { table[0][i] = table[0][i-2] + table[0][i-1]; table[1][i] = zero;