having some issues with the allocator
parent
9795a54ad0
commit
2a8734f0c0
|
@ -1,5 +1,5 @@
|
|||
cmake_minimum_required(VERSION 3.25)
|
||||
project(lilfbtf5 VERSION 0.1.3)
|
||||
project(lilfbtf5 VERSION 0.1.4)
|
||||
|
||||
option(ENABLE_ADDRSAN "Enable the address sanitizer" OFF)
|
||||
option(ENABLE_UBSAN "Enable the ub sanitizer" OFF)
|
||||
|
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
|
@ -53,28 +53,28 @@ namespace fb
|
|||
ADD, SUB, MUL, DIV, VALUE, END
|
||||
};
|
||||
|
||||
type_t random_type()
|
||||
inline type_t random_type()
|
||||
{
|
||||
static std::random_device dev;
|
||||
static std::uniform_int_distribution dist(0, static_cast<int>(type_t::END) - 1);
|
||||
return static_cast<type_t>(dist(engine.get()));
|
||||
}
|
||||
|
||||
type_t random_type_sub()
|
||||
inline type_t random_type_sub()
|
||||
{
|
||||
static std::random_device dev;
|
||||
static std::uniform_int_distribution dist(0, static_cast<int>(type_t::END) - 2);
|
||||
return static_cast<type_t>(dist(engine.get()));
|
||||
}
|
||||
|
||||
double random_value()
|
||||
inline double random_value()
|
||||
{
|
||||
static std::random_device dev;
|
||||
static std::uniform_real_distribution dist(-2.0, 2.0);
|
||||
return dist(engine.get());
|
||||
}
|
||||
|
||||
bool choice()
|
||||
inline bool choice()
|
||||
{
|
||||
static std::random_device dev;
|
||||
static std::uniform_int_distribution dist(0, 1);
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
#include <blt/parse/argparse.h>
|
||||
#include <lilfbtf/test2.h>
|
||||
#include <lilfbtf/test3.h>
|
||||
#include "blt/profiling/profiler_v2.h"
|
||||
|
||||
struct data {
|
||||
float f;
|
||||
|
@ -46,8 +47,12 @@ int main(int argc, const char** argv)
|
|||
|
||||
if (args.contains("--tests"))
|
||||
{
|
||||
// fb::test2();
|
||||
//fb::test2();
|
||||
fb::test3();
|
||||
|
||||
BLT_PRINT_PROFILE("Tree Construction");
|
||||
BLT_PRINT_PROFILE("Tree Evaluation");
|
||||
BLT_PRINT_PROFILE("Tree Destruction");
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
|
|
@ -199,11 +199,7 @@ namespace fb
|
|||
void test2()
|
||||
{
|
||||
bump<blt::bump_allocator_old<true>>();
|
||||
bump<blt::bump_allocator<4096 * 512, true, 4096 * 512>>();
|
||||
bump<blt::bump_allocator<4096 * 512, true, 4096 * 512, false>>();
|
||||
bump<blt::bump_allocator<4096 * 512, false, 4096 * 512>>();
|
||||
|
||||
BLT_PRINT_PROFILE("Tree Construction");
|
||||
BLT_PRINT_PROFILE("Tree Evaluation");
|
||||
BLT_PRINT_PROFILE("Tree Destruction");
|
||||
}
|
||||
}
|
|
@ -20,8 +20,8 @@
|
|||
#include "blt/std/utility.h"
|
||||
#include "blt/std/logging.h"
|
||||
#include "blt/std/allocator.h"
|
||||
#include "blt/profiling/profiler_v2.h"
|
||||
#include <lilfbtf/test2.h>
|
||||
#include <random>
|
||||
#include <stack>
|
||||
|
||||
namespace fb
|
||||
|
@ -104,8 +104,6 @@ namespace fb
|
|||
|
||||
class value_t : public base_t
|
||||
{
|
||||
private:
|
||||
TYPE value = 0;
|
||||
public:
|
||||
value_t(): base_t(0)
|
||||
{
|
||||
|
@ -116,7 +114,7 @@ namespace fb
|
|||
{}
|
||||
};
|
||||
|
||||
blt::bump_allocator alloc;
|
||||
blt::bump_allocator<blt::BLT_2MB_SIZE, true> alloc;
|
||||
|
||||
base_t* create_node_type(type_t i)
|
||||
{
|
||||
|
@ -150,11 +148,15 @@ namespace fb
|
|||
{}
|
||||
|
||||
void evaluate()
|
||||
{
|
||||
if (type->argc() > 0)
|
||||
{
|
||||
TYPE v1 = children[0]->type->getValue();
|
||||
TYPE v2 = children[1]->type->getValue();
|
||||
TYPE d[2]{v1, v2};
|
||||
type->call(blt::span{d});
|
||||
} else
|
||||
type->call({});
|
||||
}
|
||||
|
||||
double evaluate_tree()
|
||||
|
@ -178,18 +180,18 @@ namespace fb
|
|||
node_stack.top()->evaluate();
|
||||
node_stack.pop();
|
||||
}
|
||||
return value;
|
||||
return type->getValue();
|
||||
}
|
||||
|
||||
~node_t()
|
||||
{
|
||||
alloc.destroy(type);
|
||||
alloc.deallocate(type);
|
||||
for (blt::size_t i = 0; i < type->argc(); i++)
|
||||
{
|
||||
alloc.destroy(children[i]);
|
||||
alloc.deallocate(children[i]);
|
||||
}
|
||||
alloc.destroy(type);
|
||||
alloc.deallocate(type);
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -209,7 +211,7 @@ namespace fb
|
|||
//BLT_WARN("gen type %ld with argc: %ld", node->type, node->argc);
|
||||
stack.pop();
|
||||
//BLT_TRACE0_STREAM << "Size: " << stack.size() << "\n";
|
||||
for (blt::i32 i = 0; i < node->argc; i++)
|
||||
for (blt::size_t i = 0; i < node->type->argc(); i++)
|
||||
{
|
||||
if (depth >= size)
|
||||
{
|
||||
|
@ -239,13 +241,176 @@ namespace fb
|
|||
|
||||
~tree2()
|
||||
{
|
||||
BLT_START_INTERVAL("Tree Destruction", blt::type_string<ALLOC>() + ": Single Class Tree");
|
||||
BLT_START_INTERVAL("Tree Destruction", "Inheritance Tree");
|
||||
alloc.destroy(root);
|
||||
alloc.deallocate(root);
|
||||
BLT_END_INTERVAL("Tree Destruction", blt::type_string<ALLOC>() + ": Single Class Tree");
|
||||
BLT_END_INTERVAL("Tree Destruction", "Inheritance Tree");
|
||||
}
|
||||
};
|
||||
|
||||
class tree3
|
||||
{
|
||||
private:
|
||||
struct node_t
|
||||
{
|
||||
base_t* type = nullptr;
|
||||
node_t** children = nullptr;
|
||||
|
||||
explicit node_t(type_t type): type(create_node_type(type))
|
||||
{
|
||||
if (this->type == nullptr)
|
||||
throw std::bad_alloc();
|
||||
children = alloc.emplace_many<node_t*>(this->type->argc());
|
||||
}
|
||||
|
||||
void evaluate() const
|
||||
{
|
||||
if (type->argc() > 0)
|
||||
{
|
||||
TYPE v1 = children[0]->type->getValue();
|
||||
TYPE v2 = children[1]->type->getValue();
|
||||
TYPE d[2]{v1, v2};
|
||||
type->call(blt::span{d});
|
||||
} else
|
||||
type->call({});
|
||||
}
|
||||
|
||||
double evaluate_tree()
|
||||
{
|
||||
std::stack<node_t*> nodes;
|
||||
std::stack<node_t*> node_stack;
|
||||
|
||||
nodes.push(this);
|
||||
|
||||
while (!nodes.empty())
|
||||
{
|
||||
auto* top = nodes.top();
|
||||
node_stack.push(top);
|
||||
nodes.pop();
|
||||
for (blt::size_t i = 0; i < top->type->argc(); i++)
|
||||
nodes.push(top->children[i]);
|
||||
}
|
||||
|
||||
while (!node_stack.empty())
|
||||
{
|
||||
node_stack.top()->evaluate();
|
||||
node_stack.pop();
|
||||
}
|
||||
return type->getValue();
|
||||
}
|
||||
|
||||
~node_t()
|
||||
{
|
||||
if (children != nullptr)
|
||||
{
|
||||
for (blt::size_t i = 0; i < type->argc(); i++)
|
||||
{
|
||||
alloc.destroy(children[i]);
|
||||
alloc.deallocate(children[i]);
|
||||
}
|
||||
} else
|
||||
if (type->argc() != 0)
|
||||
BLT_WARN("Hey wtf is up %ld", type->argc());
|
||||
alloc.destroy(children);
|
||||
alloc.deallocate(children);
|
||||
alloc.destroy(type);
|
||||
alloc.deallocate(type);
|
||||
}
|
||||
};
|
||||
|
||||
node_t* root = nullptr;
|
||||
public:
|
||||
tree3()
|
||||
{
|
||||
// BLT_INFO(alignof(node_t*));
|
||||
// BLT_TRACE(alignof(node_t*[2]));
|
||||
// BLT_DEBUG(alignof(node_t*[3]));
|
||||
// BLT_INFO(sizeof(node_t*));
|
||||
// std::exit(0);
|
||||
}
|
||||
|
||||
void create(blt::u64 size)
|
||||
{
|
||||
root = alloc.template emplace<node_t>(random_type());
|
||||
std::stack<std::pair<node_t*, blt::size_t>> stack;
|
||||
stack.emplace(root, 0);
|
||||
while (!stack.empty())
|
||||
{
|
||||
auto top = stack.top();
|
||||
auto* node = top.first;
|
||||
auto depth = top.second;
|
||||
//BLT_WARN("gen type %ld with argc: %ld", node->type, node->argc);
|
||||
stack.pop();
|
||||
//BLT_TRACE0_STREAM << "Size: " << stack.size() << "\n";
|
||||
for (blt::size_t i = 0; i < node->type->argc(); i++)
|
||||
{
|
||||
if (depth >= size)
|
||||
{
|
||||
node->children[i] = alloc.template emplace<node_t>(type_t::VALUE);
|
||||
//BLT_INFO("Skipping due to size, value %lf", node->children[i]->value);
|
||||
continue;
|
||||
}
|
||||
if (choice())
|
||||
node->children[i] = alloc.template emplace<node_t>(random_type());
|
||||
else
|
||||
node->children[i] = alloc.template emplace<node_t>(random_type_sub());
|
||||
//BLT_INFO("child %p to %p has type generated %ld with argc %d, value %lf", node->children[i], node,
|
||||
// static_cast<int>(node->children[i]->type), node->children[i]->argc, node->children[i]->value);
|
||||
if (depth < size)
|
||||
stack.emplace(node->children[i], depth + 1);
|
||||
}
|
||||
//BLT_TRACE0_STREAM << "Size: " << stack.size() << "\n";
|
||||
}
|
||||
// BLT_INFO("We have %ld adds, %ld subs, %ld mul, %ld div, %ld val, == %ld", t1_add, t1_sub, t1_mul, t1_div, t1_val,
|
||||
// t1_add + t1_sub + t1_mul + t1_val + t1_div);
|
||||
}
|
||||
|
||||
double evaluate()
|
||||
{
|
||||
return root->evaluate_tree();
|
||||
}
|
||||
|
||||
~tree3()
|
||||
{
|
||||
BLT_START_INTERVAL("Tree Destruction", "Inheritance Tree v2");
|
||||
alloc.destroy(root);
|
||||
alloc.deallocate(root);
|
||||
BLT_END_INTERVAL("Tree Destruction", "Inheritance Tree v2");
|
||||
}
|
||||
};
|
||||
|
||||
void run()
|
||||
{
|
||||
constexpr auto size = 512;
|
||||
constexpr auto tree_size = 17;
|
||||
engine.reset();
|
||||
tree2 love[size];
|
||||
BLT_START_INTERVAL("Tree Construction", "Inheritance Tree");
|
||||
for (auto& i : love)
|
||||
i.create(tree_size);
|
||||
BLT_END_INTERVAL("Tree Construction", "Inheritance Tree");
|
||||
BLT_START_INTERVAL("Tree Evaluation", "Inheritance Tree");
|
||||
for (auto& i : love)
|
||||
blt::black_box(i.evaluate());
|
||||
BLT_END_INTERVAL("Tree Evaluation", "Inheritance Tree");
|
||||
}
|
||||
|
||||
void run2()
|
||||
{
|
||||
constexpr auto size = 512;
|
||||
constexpr auto tree_size = 17;
|
||||
engine.reset();
|
||||
tree3 love[size];
|
||||
BLT_START_INTERVAL("Tree Construction", "Inheritance Tree v2");
|
||||
for (auto& i : love)
|
||||
i.create(tree_size);
|
||||
BLT_END_INTERVAL("Tree Construction", "Inheritance Tree v2");
|
||||
BLT_START_INTERVAL("Tree Evaluation", "Inheritance Tree v2");
|
||||
for (auto& i : love)
|
||||
blt::black_box(i.evaluate());
|
||||
BLT_END_INTERVAL("Tree Evaluation", "Inheritance Tree v2");
|
||||
}
|
||||
|
||||
void test3()
|
||||
{
|
||||
auto cum = new blt::u8[512];
|
||||
|
@ -266,5 +431,8 @@ namespace fb
|
|||
blt::black_box(v);
|
||||
|
||||
delete[] cum;
|
||||
|
||||
//run();
|
||||
run2();
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue