Barretenberg
The ZK-SNARK library at the core of Aztec
Loading...
Searching...
No Matches
c_bind.cpp
Go to the documentation of this file.
1#include "./c_bind.hpp"
2#include "./mem.hpp"
3#include "./serialize.hpp"
5#include "./timer.hpp"
6#include <algorithm>
7
8#ifndef NO_MULTITHREADING
9#include <thread>
10
12 std::atomic<uint32_t> counter = 0;
13 size_t iterations = 0;
14};
15
17{
18 Timer t;
19 // info("thread start with counter at: ", static_cast<size_t>(v->counter));
20 std::vector<uint8_t> data(1024);
21 for (size_t i = 0; i < v->iterations; ++i) {
22 // Do some meaningless work.
23 std::for_each(data.begin(), data.end(), [](auto& i) { i = i & 0x80; });
24 std::for_each(data.begin(), data.end(), [](auto& i) { i = i | 0x01; });
25 std::for_each(data.begin(), data.end(), [](auto& i) { i = static_cast<uint8_t>(i << 3); });
26 (v->counter)++;
27 }
28 // info("thread end with counter at: ", static_cast<size_t>(v->counter), " ", t.seconds(), "s");
29}
30
31void thread_test_abort_entry_point(void* /*unused*/)
32{
33 info("thread_test_abort aborting");
34 std::abort();
35}
36
37WASM_EXPORT void test_threads(uint32_t const* thread_num, uint32_t const* iterations, uint32_t* out)
38{
39 info("test starting...");
40 Timer t;
41 size_t NUM_THREADS = ntohl(*thread_num);
42 std::vector<std::thread> threads(NUM_THREADS);
43 test_threads_data test_data;
44 test_data.iterations = ntohl(*iterations) / NUM_THREADS;
45
46 for (size_t i = 0; i < NUM_THREADS; i++) {
47 threads[i] = std::thread(thread_test_entry_point, &test_data);
48 }
49
50 info("joining...");
51 for (size_t i = 0; i < NUM_THREADS; i++) {
52 threads[i].join();
53 }
54
55 info("test complete with counter at: ", static_cast<size_t>(test_data.counter), " ", t.seconds(), "s");
56 *out = htonl(test_data.counter);
57}
58
60{
61 std::thread thread(thread_test_abort_entry_point, (void*)nullptr);
62 thread.join();
63}
64
66{
67 info("test_abort aborting");
68 std::abort();
69}
70
71#endif
72
74{
75 // refactoring our file access methods to fix this warning is not worth it!
76 // NOLINTBEGIN(cppcoreguidelines-pro-type-vararg)
77 static_cast<void>(fprintf(stdout, "c: hello stdout!"));
78 static_cast<void>(fflush(stdout));
79 static_cast<void>(fprintf(stderr, "c: hello stderr!"));
80 // NOLINTEND(cppcoreguidelines-pro-type-vararg)
81 std::cout << "c++: hello stdout!" << std::flush;
82 std::cerr << "c++: hello stderr!";
83}
84
85WASM_EXPORT void common_init_slab_allocator(uint32_t const* circuit_size)
86{
87 bb::init_slab_allocator(ntohl(*circuit_size));
88}
Get the execution between a block of code.
Definition timer.hpp:12
double seconds() const
Return the number of seconds elapsed since the start of the timer.
Definition timer.hpp:70
void thread_test_abort_entry_point(void *)
Definition c_bind.cpp:31
WASM_EXPORT void test_threads(uint32_t const *thread_num, uint32_t const *iterations, uint32_t *out)
Definition c_bind.cpp:37
WASM_EXPORT void common_init_slab_allocator(uint32_t const *circuit_size)
Definition c_bind.cpp:85
WASM_EXPORT void test_stdout_stderr()
Definition c_bind.cpp:73
void thread_test_entry_point(test_threads_data *v)
Definition c_bind.cpp:16
WASM_EXPORT void test_thread_abort()
Definition c_bind.cpp:59
WASM_EXPORT void test_abort()
Definition c_bind.cpp:65
void info(Args... args)
Definition log.hpp:70
const std::vector< FF > data
void init_slab_allocator(size_t circuit_subgroup_size)
constexpr decltype(auto) get(::tuplet::tuple< T... > &&t) noexcept
Definition tuple.hpp:13
size_t iterations
Definition c_bind.cpp:13
std::atomic< uint32_t > counter
Definition c_bind.cpp:12
#define WASM_EXPORT