From fd72b2a716ae15d8255b80ace69b9628fb99eb0a Mon Sep 17 00:00:00 2001 From: Brett Date: Sat, 31 Aug 2024 22:44:34 -0400 Subject: [PATCH] tracking allocations --- CMakeLists.txt | 2 +- include/blt/gp/fwdecl.h | 2 +- include/blt/gp/program.h | 30 +++++++++++++++--------------- include/blt/gp/tree.h | 4 ++-- src/transformers.cpp | 12 ++++++------ src/tree.cpp | 6 +++--- 6 files changed, 28 insertions(+), 28 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 65a80e1..1b40123 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,5 +1,5 @@ cmake_minimum_required(VERSION 3.25) -project(blt-gp VERSION 0.1.36) +project(blt-gp VERSION 0.1.37) include(CTest) diff --git a/include/blt/gp/fwdecl.h b/include/blt/gp/fwdecl.h index a00407f..24319e0 100644 --- a/include/blt/gp/fwdecl.h +++ b/include/blt/gp/fwdecl.h @@ -137,7 +137,7 @@ namespace blt::gp template void construct(U* p, Args&& ... args) { - new(p) T(args...); + new(p) T(std::forward(args)...); } template diff --git a/include/blt/gp/program.h b/include/blt/gp/program.h index ac0be48..d682ee5 100644 --- a/include/blt/gp/program.h +++ b/include/blt/gp/program.h @@ -70,7 +70,7 @@ namespace blt::gp struct operator_info { // types of the arguments - std::vector argument_types; + tracked_vector argument_types; // return type of this operator type_id return_type; // number of arguments for this operator @@ -82,15 +82,15 @@ namespace blt::gp struct program_operator_storage_t { // indexed from return TYPE ID, returns index of operator - blt::expanding_buffer> terminals; - blt::expanding_buffer> non_terminals; - blt::expanding_buffer>> operators_ordered_terminals; + blt::expanding_buffer> terminals; + blt::expanding_buffer> non_terminals; + blt::expanding_buffer>> operators_ordered_terminals; // indexed from OPERATOR ID (operator number) blt::hashset_t ephemeral_leaf_operators; - std::vector operators; - std::vector print_funcs; - std::vector destroy_funcs; - std::vector> names; + tracked_vector operators; + tracked_vector print_funcs; + tracked_vector destroy_funcs; + tracked_vector> names; detail::eval_func_t eval_func; @@ -110,7 +110,7 @@ namespace blt::gp template program_operator_storage_t& build(Operators& ... operators) { - std::vector sizes; + tracked_vector sizes; (sizes.push_back(add_operator(operators)), ...); blt::size_t largest = 0; for (auto v : sizes) @@ -153,7 +153,7 @@ namespace blt::gp if (op_r.second.empty()) continue; auto return_type = op_r.first; - std::vector> ordered_terminals; + tracked_vector> ordered_terminals; for (const auto& op : op_r.second) { // count number of terminals @@ -675,12 +675,12 @@ namespace blt::gp return storage.names[id]; } - [[nodiscard]] inline std::vector& get_type_terminals(type_id id) + [[nodiscard]] inline tracked_vector& get_type_terminals(type_id id) { return storage.terminals[id]; } - [[nodiscard]] inline std::vector& get_type_non_terminals(type_id id) + [[nodiscard]] inline tracked_vector& get_type_non_terminals(type_id id) { return storage.non_terminals[id]; } @@ -715,7 +715,7 @@ namespace blt::gp { std::array arr; - std::vector> values; + tracked_vector> values; values.reserve(current_pop.get_individuals().size()); for (const auto& ind : blt::enumerate(current_pop.get_individuals())) @@ -789,11 +789,11 @@ namespace blt::gp std::atomic_bool fitness_should_exit = false; population_stats current_stats{}; - std::vector statistic_history; + tracked_vector statistic_history; struct concurrency_storage { - std::vector> threads; + tracked_vector> threads; std::mutex thread_function_control{}; std::condition_variable thread_function_condition{}; diff --git a/include/blt/gp/tree.h b/include/blt/gp/tree.h index 51d833f..f25ba60 100644 --- a/include/blt/gp/tree.h +++ b/include/blt/gp/tree.h @@ -156,7 +156,7 @@ namespace blt::gp bool check(gp_program& program, void* context) const; - void find_child_extends(gp_program& program, std::vector& vec, blt::size_t parent_node, blt::size_t argc) const; + void find_child_extends(gp_program& program, tracked_vector& vec, blt::size_t parent_node, blt::size_t argc) const; blt::ptrdiff_t find_endpoint(blt::gp::gp_program& program, blt::ptrdiff_t start) const; @@ -251,7 +251,7 @@ namespace blt::gp std::atomic average_fitness = 0; std::atomic best_fitness = 0; std::atomic worst_fitness = 1; - std::vector normalized_fitness{}; + tracked_vector normalized_fitness{}; void clear() { diff --git a/src/transformers.cpp b/src/transformers.cpp index 9e0d355..5dc65ea 100644 --- a/src/transformers.cpp +++ b/src/transformers.cpp @@ -85,8 +85,8 @@ namespace blt::gp stack_allocator& c2_stack = c2.get_values(); // we have to make a copy because we will modify the underlying storage. - static thread_local std::vector c1_operators; - static thread_local std::vector c2_operators; + static thread_local tracked_vector c1_operators; + static thread_local tracked_vector c2_operators; c1_operators.clear(); c2_operators.clear(); @@ -359,7 +359,7 @@ namespace blt::gp auto& replacement_func_info = program.get_operator_info(random_replacement); // cache memory used for offset data. - thread_local static std::vector children_data; + thread_local static tracked_vector children_data; children_data.clear(); c.find_child_extends(program, children_data, c_node, current_func_info.argument_types.size()); @@ -586,7 +586,7 @@ namespace blt::gp if (argument_index == -1ul) continue; - static thread_local std::vector child_data; + static thread_local tracked_vector child_data; child_data.clear(); c.find_child_extends(program, child_data, c_node, info.argument_types.size()); @@ -670,7 +670,7 @@ namespace blt::gp to = pt; } - static thread_local std::vector child_data; + static thread_local tracked_vector child_data; child_data.clear(); c.find_child_extends(program, child_data, c_node, info.argument_types.size()); @@ -700,7 +700,7 @@ namespace blt::gp vals.copy_from(from_ptr, from_bytes); vals.copy_from(after_ptr, after_to_bytes); - static thread_local std::vector op_copy; + static thread_local tracked_vector op_copy; op_copy.clear(); op_copy.insert(op_copy.begin(), ops.begin() + from_child.start, ops.begin() + from_child.end); diff --git a/src/tree.cpp b/src/tree.cpp index ed41957..e57a579 100644 --- a/src/tree.cpp +++ b/src/tree.cpp @@ -145,8 +145,8 @@ namespace blt::gp blt::size_t depth = 0; auto operations_stack = operations; - std::vector values_process; - std::vector value_stack; + tracked_vector values_process; + tracked_vector value_stack; for (const auto& op : operations_stack) { @@ -275,7 +275,7 @@ namespace blt::gp return true; } - void tree_t::find_child_extends(gp_program& program, std::vector& vec, blt::size_t parent_node, blt::size_t argc) const + void tree_t::find_child_extends(gp_program& program, tracked_vector& vec, blt::size_t parent_node, blt::size_t argc) const { while (vec.size() < argc) {