From ec8153bef074e740e8b6b0601c79b3906e50e27d Mon Sep 17 00:00:00 2001 From: Brett Date: Thu, 22 Aug 2024 02:45:10 -0400 Subject: [PATCH] cleanup --- CMakeLists.txt | 2 +- examples/symbolic_regression.cpp | 1 + include/blt/gp/stack.h | 7 ++++++- src/tree.cpp | 30 ++++++++++++++---------------- 4 files changed, 22 insertions(+), 18 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index d3d5f2c..6e0a494 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,5 +1,5 @@ cmake_minimum_required(VERSION 3.25) -project(blt-gp VERSION 0.1.20) +project(blt-gp VERSION 0.1.21) include(CTest) diff --git a/examples/symbolic_regression.cpp b/examples/symbolic_regression.cpp index f620edd..4db050b 100644 --- a/examples/symbolic_regression.cpp +++ b/examples/symbolic_regression.cpp @@ -155,6 +155,7 @@ int main() // BLT_TRACE("Allocated: %ld", h); // BLT_TRACE("Deallocated: %ld", u); // BLT_TRACE("Ratio: %lf Difference: %ld", static_cast(h) / static_cast(u), std::abs(h - u)); +// BLT_TRACE("Total Allocated Bytes: %ld", blt::gp::hello_bytes.load()); return 0; } \ No newline at end of file diff --git a/include/blt/gp/stack.h b/include/blt/gp/stack.h index d2e4fe3..71a10a7 100644 --- a/include/blt/gp/stack.h +++ b/include/blt/gp/stack.h @@ -44,6 +44,7 @@ namespace blt::gp } // inline std::atomic_uint64_t hello = 0; +// inline std::atomic_uint64_t hello_bytes = 0; // inline std::atomic_uint64_t unhello = 0; class aligned_allocator @@ -52,12 +53,16 @@ namespace blt::gp void* allocate(blt::size_t bytes) // NOLINT { // hello.fetch_add(1, std::memory_order_relaxed); +// hello_bytes += bytes; // BLT_TRACE("Allocating %ld bytes", bytes); return std::aligned_alloc(8, bytes); } void deallocate(void* ptr, blt::size_t) // NOLINT { +// if (ptr == nullptr && bytes != 0) { +// BLT_ABORT(("Nullptr called with non zero bytes! " + std::to_string(bytes)).c_str()); +// } // if (ptr == nullptr) // return; // unhello.fetch_add(1, std::memory_order_relaxed); @@ -116,7 +121,7 @@ namespace blt::gp } stack_allocator(stack_allocator&& move) noexcept: - data_(std::exchange(move.data_, nullptr)), bytes_stored(move.bytes_stored), size_(move.size_) + data_(std::exchange(move.data_, nullptr)), bytes_stored(std::exchange(move.bytes_stored, 0)), size_(std::exchange(move.size_, 0)) {} stack_allocator& operator=(const stack_allocator& copy) = delete; diff --git a/src/tree.cpp b/src/tree.cpp index 5d6ac32..bf80000 100644 --- a/src/tree.cpp +++ b/src/tree.cpp @@ -247,22 +247,20 @@ namespace blt::gp blt::size_t total_produced = 0; blt::size_t total_consumed = 0; -// for (const auto& operation : blt::reverse_iterate(operations.begin(), operations.end())) -// { -// if (operation.is_value) -// { -// value_stack.transfer_bytes(values_process, operation.type_size); -// total_produced += stack_allocator::aligned_size(operation.type_size); -// bitfield.push_back(false); -// continue; -// } -// auto& info = program.get_operator_info(operation.id); -// for (auto& arg : info.argument_types) -// total_consumed += stack_allocator::aligned_size(program.get_typesystem().get_type(arg).size()); -// operation.func(context, values_process, values_process, &bitfield); -// bitfield.push_back(true); -// total_produced += stack_allocator::aligned_size(program.get_typesystem().get_type(info.return_type).size()); -// } + for (const auto& operation : blt::reverse_iterate(operations.begin(), operations.end())) + { + if (operation.is_value) + { + value_stack.transfer_bytes(values_process, operation.type_size); + total_produced += stack_allocator::aligned_size(operation.type_size); + continue; + } + auto& info = program.get_operator_info(operation.id); + for (auto& arg : info.argument_types) + total_consumed += stack_allocator::aligned_size(program.get_typesystem().get_type(arg).size()); + program.get_operator_info(operation.id).func(context, values_process, values_process); + total_produced += stack_allocator::aligned_size(program.get_typesystem().get_type(info.return_type).size()); + } auto v1 = results.values.bytes_in_head(); auto v2 = static_cast(stack_allocator::aligned_size(operations.front().type_size));