Skip to content

Commit

Permalink
rework handling out of memory in feature generator
Browse files Browse the repository at this point in the history
  • Loading branch information
drexlerd committed Sep 10, 2024
1 parent 6978555 commit cbd5b55
Show file tree
Hide file tree
Showing 8 changed files with 20 additions and 90 deletions.
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from setuptools import setup, find_packages, Extension
from setuptools.command.build_ext import build_ext

__version__ = "0.3.27"
__version__ = "0.3.28"
HERE = Path(__file__).resolve().parent


Expand Down
1 change: 0 additions & 1 deletion src/generator/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ target_sources(dlplangenerator
${GENERATOR_SRC_FILES} ${GENERATOR_PRIVATE_HEADER_FILES} ${GENERATOR_PUBLIC_HEADER_FILES}
"../utils/logging.h" "../utils/logging.cpp"
"../utils/countdown_timer.h" "../utils/countdown_timer.cpp"
"../utils/memory.h" "../utils/memory.cpp"
)
target_link_libraries(dlplangenerator
PUBLIC
Expand Down
18 changes: 16 additions & 2 deletions src/generator/feature_generator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,11 @@ GeneratedFeatures FeatureGeneratorImpl::generate(
int count_numerical_complexity_limit,
int distance_numerical_complexity_limit,
int time_limit,
int feature_limit) {
int feature_limit)
{
// Allow termination with ctrl+c
auto pre_sigint_handler = std::signal(SIGINT, exit_sigint_handler);

// Initialize statistics in each rule.
for (auto& r : m_primitive_rules) r->initialize();
for (auto& r : m_concept_inductive_rules) r->initialize();
Expand All @@ -117,9 +119,21 @@ GeneratedFeatures FeatureGeneratorImpl::generate(
// Initialize cache.
core::DenotationsCaches caches;
generate_base(states, data, caches);
generate_inductively(states, concept_complexity_limit, role_complexity_limit, boolean_complexity_limit, count_numerical_complexity_limit, distance_numerical_complexity_limit, data, caches);

try
{
generate_inductively(states, concept_complexity_limit, role_complexity_limit, boolean_complexity_limit, count_numerical_complexity_limit, distance_numerical_complexity_limit, data, caches);
//auto x = new char[std::numeric_limits<std::size_t>::max() / 10];
//x[1] = 1;
}
catch (const std::bad_alloc& e)
{
std::cout << "Feature generation stopped prematurely due to catching memory exception: " << e.what() << std::endl;
}

// Restore previous sigint handler
std::signal(SIGINT, pre_sigint_handler);

return data.m_generated_features;
}

Expand Down
13 changes: 3 additions & 10 deletions src/generator/generator.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#include "../../include/dlplan/generator.h"

#include "feature_generator.h"
#include "../utils/memory.h"


namespace dlplan::generator {
Expand Down Expand Up @@ -37,15 +36,9 @@ GeneratedFeatures FeatureGenerator::generate(
int count_numerical_complexity_limit,
int distance_numerical_complexity_limit,
int time_limit,
int feature_limit) {

utils::reserve_extra_memory_padding(1);

auto features = m_pImpl->generate(factory, states, concept_complexity_limit, role_complexity_limit, boolean_complexity_limit, count_numerical_complexity_limit, distance_numerical_complexity_limit, time_limit, feature_limit);

utils::release_extra_memory_padding();

return features;
int feature_limit)
{
return m_pImpl->generate(factory, states, concept_complexity_limit, role_complexity_limit, boolean_complexity_limit, count_numerical_complexity_limit, distance_numerical_complexity_limit, time_limit, feature_limit);
}

void FeatureGenerator::set_generate_empty_boolean(bool enable) {
Expand Down
1 change: 0 additions & 1 deletion src/state_space/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ file(GLOB_RECURSE STATE_SPACE_PUBLIC_HEADER_FILES
target_sources(dlplanstatespace
PRIVATE
${STATE_SPACE_SRC_FILES} ${STATE_SPACE_PRIVATE_HEADER_FILES} ${STATE_SPACE_PUBLIC_HEADER_FILES}
"../utils/memory.h" "../utils/memory.cpp"
)

target_link_libraries(dlplanstatespace
Expand Down
5 changes: 0 additions & 5 deletions src/state_space/state_space.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
#include "generator.h"
#include "reader.h"
#include "../utils/collections.h"
#include "../utils/memory.h"

#include <algorithm>
#include <deque>
Expand Down Expand Up @@ -357,13 +356,9 @@ GeneratorResult generate_state_space(
int max_time,
int max_num_states) {

utils::reserve_extra_memory_padding(1);

generator::generate_state_space_files(domain_file, instance_file, max_time, max_num_states);
auto result = reader::read(vocabulary_info, index);

utils::release_extra_memory_padding();

return result;
}

Expand Down
42 changes: 0 additions & 42 deletions src/utils/memory.cpp

This file was deleted.

28 changes: 0 additions & 28 deletions src/utils/memory.h

This file was deleted.

0 comments on commit cbd5b55

Please sign in to comment.