Initial import of libdpf.
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
commit
e4e666f459
4563 changed files with 1690372 additions and 0 deletions
31
examples/evaluation/eval_full.cpp
Normal file
31
examples/evaluation/eval_full.cpp
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
#include <iostream>
|
||||
|
||||
#include "dpf.hpp"
|
||||
|
||||
int main(int arc, char * argv[])
|
||||
{
|
||||
uint16_t x = 42; // Input value
|
||||
using prg = dpf::prg::counter_wrapper<dpf::prg::dummy>; // This is just to count the number of PRG invocations
|
||||
auto before = prg::count(); // In order to show how much this program cost
|
||||
auto [dpf0, dpf1] = dpf::make_dpf<prg>(x);
|
||||
auto after = prg::count();
|
||||
std::cout << "dpf::make_dpf used " << (after-before) << "\n";
|
||||
|
||||
before = prg::count();
|
||||
auto [buf0, iter0] = dpf::eval_full(dpf0);
|
||||
after = prg::count();
|
||||
std::cout << "dpf::eval_full(dpf0) used " << (after-before) << "\n";
|
||||
before = prg::count();
|
||||
auto [buf1, iter1] = dpf::eval_full(dpf1);
|
||||
after = prg::count();
|
||||
std::cout << "dpf::eval_full(dpf1) used " << (after-before) << "\n";
|
||||
// Retrieve the original input by iterating over the two buffers
|
||||
for (size_t i = 0; i < buf0.size(); ++i) {
|
||||
bool item1 = buf0[i];
|
||||
bool item2 = buf1[i];
|
||||
if (item1 ^ item2) std::cout << "The original input is: " << i << std::endl;
|
||||
}
|
||||
|
||||
std::cout << "Total PRG invocation: " << prg::count() << "\n";
|
||||
return 0;
|
||||
}
|
||||
42
examples/evaluation/eval_interval.cpp
Normal file
42
examples/evaluation/eval_interval.cpp
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
#include <iostream>
|
||||
#include "dpf.hpp"
|
||||
|
||||
int main(int arc, char * argv[])
|
||||
{
|
||||
uint16_t x = 42, y;
|
||||
using prg = dpf::prg::counter_wrapper<dpf::prg::dummy>;
|
||||
|
||||
// Make the DPF
|
||||
auto before = prg::count();
|
||||
auto [dpf0, dpf1] = dpf::make_dpf<prg>(x);
|
||||
auto after = prg::count();
|
||||
std::cout << "dpf::make_dpf prg invocation: " << (after-before) << "\n";
|
||||
|
||||
// Evaluate the DPF by interval
|
||||
before = prg::count();
|
||||
int from = 0, to = 49;
|
||||
auto [buf0, iter0] = dpf::eval_interval(dpf0, from, to);
|
||||
auto [buf1, iter1] = dpf::eval_interval(dpf1, from, to);
|
||||
after = prg::count();
|
||||
std::cout << "dpf::eval_interval prg invocation: " << (after-before) << "\n";
|
||||
|
||||
// Retrieve the original input by iterating over the two buffers
|
||||
std::vector<bool> result;
|
||||
for (size_t i = from; i < to+1; ++i) {
|
||||
bool item1 = buf0[i];
|
||||
bool item2 = buf1[i];
|
||||
result.push_back(item1 ^ item2);
|
||||
if (item1 ^ item2) y=i;
|
||||
}
|
||||
// Print out the XOR interval
|
||||
for (const auto& item : result) {
|
||||
std::cout << static_cast<bool>(item);
|
||||
}
|
||||
std::cout << std::endl;
|
||||
if (y == x) std::cout << "The orginal value is: " << x << std::endl;
|
||||
else std::cout << "The evaluated inputs did not match the original value." << std::endl;
|
||||
|
||||
std::cout << "Total PRG invocation: " << prg::count() << std::endl;
|
||||
|
||||
return 0;
|
||||
}
|
||||
17
examples/evaluation/eval_point.cpp
Normal file
17
examples/evaluation/eval_point.cpp
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
#include <iostream>
|
||||
|
||||
#include "dpf.hpp"
|
||||
|
||||
int main(int arc, char * argv[])
|
||||
{
|
||||
uint16_t x = 42;
|
||||
auto [dpf0, dpf1] = dpf::make_dpf(x);
|
||||
|
||||
auto res = dpf::eval_point(dpf0, x);
|
||||
|
||||
std::cout << *dpf::eval_point(dpf0, 41) << " ^ " << *dpf::eval_point(dpf1, 41) << " = " << (*dpf::eval_point(dpf0, 41) ^ *dpf::eval_point(dpf1, 41)) << "\n"; // = 0
|
||||
std::cout << *dpf::eval_point(dpf0, x) << " ^ " << *dpf::eval_point(dpf1, x) << " = " << (*dpf::eval_point(dpf0, x) ^ *dpf::eval_point(dpf1, x)) << "\n"; // = 1
|
||||
std::cout << *dpf::eval_point(dpf0, 43) << " ^ " << *dpf::eval_point(dpf1, 43) << " = " << (*dpf::eval_point(dpf0, 43) ^ *dpf::eval_point(dpf1, 43)) << "\n"; // = 0
|
||||
|
||||
return 0;
|
||||
}
|
||||
54
examples/evaluation/eval_sequence.cpp
Normal file
54
examples/evaluation/eval_sequence.cpp
Normal file
|
|
@ -0,0 +1,54 @@
|
|||
#include <chrono>
|
||||
#include <iostream>
|
||||
#include "dpf.hpp"
|
||||
|
||||
using std::chrono::high_resolution_clock;
|
||||
using std::chrono::duration_cast;
|
||||
using std::chrono::duration;
|
||||
using std::chrono::milliseconds;
|
||||
|
||||
int main(int argc, char * argv[])
|
||||
{
|
||||
using input_type = uint8_t;
|
||||
using prg = dpf::prg::counter_wrapper<dpf::prg::dummy>;
|
||||
|
||||
constexpr int N = 50;
|
||||
std::array<input_type, N> keys{};
|
||||
for(int i=0; i<N; i++) keys[i] = i; // Create an array of keys
|
||||
|
||||
// eval_sequence with recipe
|
||||
input_type x = 42;
|
||||
auto [dpf0, dpf1] = dpf::make_dpf<prg>(x); // First DPF to be able to create the recipe
|
||||
auto t1 = high_resolution_clock::now(); // To measure the time of execution
|
||||
auto before = prg::count(); // To count the number of PRG invocations
|
||||
auto recipe0 = dpf::make_sequence_recipe(dpf0, std::begin(keys), std::end(keys)); // Create a recipe
|
||||
auto recipe1 = dpf::make_sequence_recipe(dpf1, std::begin(keys), std::end(keys)); // Create a recipe
|
||||
for (int i=0; i<N; i++)
|
||||
{
|
||||
auto [dpf00, dpf11] = dpf::make_dpf<prg>(i); // Make 50 DPFs
|
||||
dpf::eval_sequence(dpf0, recipe0); // Evaluate the DPFs with the recipe
|
||||
dpf::eval_sequence(dpf1, recipe0); // Evaluate the DPFs with the recipe
|
||||
}
|
||||
auto after = prg::count(); // Count the number of PRG invocations
|
||||
std::cout << "dpf::eval_sequence with recipe " << (after-before) << "\n";
|
||||
|
||||
// eval_sequence without the recipe
|
||||
auto t2 = high_resolution_clock::now();
|
||||
duration<double, std::milli> ms_double = t2 - t1;
|
||||
std::cout << "Time of execution: " << ms_double.count() << "ms\n";
|
||||
auto t3 = high_resolution_clock::now();
|
||||
before = prg::count();
|
||||
for (int i=0; i<N; i++)
|
||||
{
|
||||
auto [dpf00, dpf11] = dpf::make_dpf<prg>(i);
|
||||
dpf::eval_sequence(dpf00, std::begin(keys), std::end(keys));
|
||||
dpf::eval_sequence(dpf11, std::begin(keys), std::end(keys));
|
||||
}
|
||||
after = prg::count();
|
||||
std::cout << "dpf::eval_sequence used " << (after-before) << "\n";
|
||||
auto t4 = high_resolution_clock::now();
|
||||
duration<double, std::milli> ms_double2 = t4 - t3;
|
||||
std::cout << "Time of execution with the memoizers: " << ms_double2.count() << "ms\n";
|
||||
|
||||
return 0;
|
||||
}
|
||||
50
examples/evaluation/memoizers.cpp
Normal file
50
examples/evaluation/memoizers.cpp
Normal file
|
|
@ -0,0 +1,50 @@
|
|||
#include <iostream>
|
||||
#include <chrono>
|
||||
#include "dpf.hpp"
|
||||
|
||||
using std::chrono::high_resolution_clock;
|
||||
using std::chrono::duration_cast;
|
||||
using std::chrono::duration;
|
||||
using std::chrono::milliseconds;
|
||||
|
||||
int main(int arc, char * argv[])
|
||||
{
|
||||
// Making the DPF with an integer value
|
||||
uint16_t x = 42;
|
||||
using prg = dpf::prg::counter_wrapper<dpf::prg::dummy>;
|
||||
auto [dpf0, dpf1] = dpf::make_dpf<prg>(x);
|
||||
|
||||
// Evaluating the DPF and counting how much it cost without memoizers
|
||||
auto t1 = high_resolution_clock::now();
|
||||
auto before = prg::count();
|
||||
for (int i = 0; i<1024*1024; i++)
|
||||
{
|
||||
dpf::eval_point(dpf0, i);
|
||||
|
||||
}
|
||||
// Printing out the results
|
||||
auto after = prg::count();
|
||||
std::cout << "Without memoizers: " << "\n";
|
||||
std::cout << "PRG invocation: " << after-before << "\n";
|
||||
auto t2 = high_resolution_clock::now();
|
||||
duration<double, std::milli> ms_double = t2 - t1;
|
||||
std::cout << "Time of execution: " << ms_double.count() << "ms\n";
|
||||
|
||||
// Evaluating the DPF and counting how much it cost with memoizers
|
||||
auto t3 = high_resolution_clock::now();
|
||||
before = prg::count();
|
||||
auto path = dpf::make_basic_path_memoizer(dpf0);
|
||||
for (int i = 0; i<1024*1024; i++)
|
||||
{
|
||||
dpf::eval_point(dpf0, i, path);
|
||||
}
|
||||
// Printing out the results
|
||||
after = prg::count();
|
||||
std::cout << "With memoizers: " << "\n";
|
||||
std::cout << "PRG invocation: " << after-before << "\n";
|
||||
auto t4 = high_resolution_clock::now();
|
||||
duration<double, std::milli> ms_double2 = t4 - t3;
|
||||
std::cout << "Time of execution with the memoizers: " << ms_double2.count() << "ms\n";
|
||||
|
||||
return 0;
|
||||
}
|
||||
6
examples/evaluation/output_buffers.cpp
Normal file
6
examples/evaluation/output_buffers.cpp
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
#include "dpf.hpp"
|
||||
|
||||
int main(int argc, char * argv[])
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue