11#include " nitpick_include.hh"
22#include < chrono>
3+ #include " scalar_node.hh"
34// only get us the variables
45#define NITPICK_IDE_IGNORE
56
@@ -10,11 +11,14 @@ using namespace bparser;
1011#include NITPICK_GEN_FILE
1112
1213int main () {
14+ const uint N = 1048576 ; // 2^20 //1073741824U; //2^30
1315
1416 const uint max_vec_size = 2000 ;
15- const size_t buffer_size = sizeof (double ) * max_vec_size + 500000 ;
17+ const size_t buffer_size = sizeof (double ) * N * 64 ;
1618
17- const uint N = 1073741824U ; // 2^30
19+ std::cout << " Buffer size: " << buffer_size << std::endl;
20+ int simd_size = bparser::get_simd_size ();
21+ std::cout << " SIMD size: " << simd_size << std::endl;
1822
1923 void * buffer = ::operator new (buffer_size);
2024 ExprCase exprcase (max_vec_size, (void *)buffer, buffer_size);
@@ -25,31 +29,61 @@ int main() {
2529 Throw () << " No expression was set!" ;
2630 }
2731
28- std::vector<uint> subset = { 0 , 1 , 2 , 3 , 4 ,5 ,6 ,7 ,8 ,9 ,10 ,11 ,12 }; // ctverice doubluu //TODO: autocreate from vec_size
2932 std::vector<uint> vec_sizes ({ 16U , 64U , 256U , 1024U });
3033
3134 PatchArenaPtr arena = exprcase.get_patch_arena ();
3235 for (uint vec_size : vec_sizes) {
3336
3437 uint n_repeats = N / vec_size;
35-
38+
3639 std::cout << " Running \" " << exprcase.get_expression () << " \" " << n_repeats << " x for vec_size: " << vec_size << std::endl;
37- exprcase.allocate (vec_size);
40+
41+ // exprcase.allocate(vec_size);
42+ exprcase.allocate (N);
43+
44+ Parser& p = exprcase.get_parser ();
45+ p.compile ();
46+ auto nodes = p.result_array ().elements ();
47+ std::vector<ScalarNodePtr> value_nodes = {};
48+ std::vector<ScalarNodePtr> val_copy_nodes = {};
49+ for (uint i = 0 ; i < nodes.size (); i++) {
50+ ScalarNodePtr n = nodes[i];
51+ if (n->result_storage == value) {
52+ value_nodes.push_back (n);
53+ }
54+ else if (n->result_storage == value_copy) {
55+ val_copy_nodes.push_back (n);
56+ }
57+ }
58+
59+ auto dangerous_shift = [&](uint a) {
60+ for (auto n : value_nodes) {
61+ n->values_ += a;
62+ }
63+ for (auto n : val_copy_nodes) {
64+ details::ValueCopyNode& vcn = dynamic_cast <details::ValueCopyNode&>(*n);
65+ vcn.source_ptr_ += a;
66+ }
67+ };
3868
3969 // Get autogenerated dag;
4070 ExpressionDAG se = gen (exprcase.get_node_map ());
71+ // I would expect vec_size instead of max_vec_size but that certainly does not work because the processor decides to go out of program reach and run memory -LV
72+ ProcessorBase* processor = ProcessorBase::create_processor (se, max_vec_size, simd_size, arena); // get arena from ExprCase
4173
42- ProcessorBase* processor = ProcessorBase::create_processor (se, max_vec_size, bparser::get_simd_size (), arena); // get arena from ExprCase
43- processor->set_subset (subset);
74+ std::vector<uint> subset (std::ceil (vec_size / (float )simd_size)); // ex: 32/4 = 8 =>
75+ std::iota (subset.begin (), subset.end (), 1 ); // => {1, 2, 3, 4, 5, 6, 7, 8}
76+ processor->set_subset (subset); // all subsets
4477
4578 auto start_time = std::chrono::high_resolution_clock::now ();
4679 for (uint i_rep = 0 ; i_rep < n_repeats; i_rep++) {
4780 processor->run ();
81+ dangerous_shift (vec_size);
4882 }
4983 auto end_time = std::chrono::high_resolution_clock::now ();
5084
5185 double time = std::chrono::duration_cast<std::chrono::duration<double >>(end_time - start_time).count ();
52- std::cout << " Finished in " << time << std::endl;
86+ std::cout << std::fixed << " Finished in " << time << std::defaultfloat << std::endl;
5387
5488
5589 exprcase.deallocate (); // processor is allocated in arena
0 commit comments