This commit adds statistics for all resource steps. A resource statistic is incremented by 1 if the resource is spent (via `spendResource`).
Fixes #3751.
${CMAKE_CURRENT_BINARY_DIR}/RegExpType.java
${CMAKE_CURRENT_BINARY_DIR}/ResetAssertionsCommand.java
${CMAKE_CURRENT_BINARY_DIR}/ResetCommand.java
- ${CMAKE_CURRENT_BINARY_DIR}/ResourceManager.java
${CMAKE_CURRENT_BINARY_DIR}/Result.java
${CMAKE_CURRENT_BINARY_DIR}/RoundingMode.java
${CMAKE_CURRENT_BINARY_DIR}/RoundingModeType.java
${CMAKE_CURRENT_BINARY_DIR}/SynthFunCommand.java
${CMAKE_CURRENT_BINARY_DIR}/TesterType.java
${CMAKE_CURRENT_BINARY_DIR}/TheoryId.java
- ${CMAKE_CURRENT_BINARY_DIR}/Timer.java
${CMAKE_CURRENT_BINARY_DIR}/TupleUpdate.java
${CMAKE_CURRENT_BINARY_DIR}/TupleUpdateHashFunction.java
${CMAKE_CURRENT_BINARY_DIR}/Type.java
%include "util/hash.i"
%include "util/proof.i"
%include "util/regexp.i"
-%include "util/resource_manager.i"
%include "util/result.i"
%include "util/sexpr.i"
%include "util/statistics.i"
/** Gets the next decision based on strategies that are enabled */
SatLiteral getNext(bool &stopSearch) {
- NodeManager::currentResourceManager()->spendResource(options::decisionStep());
+ NodeManager::currentResourceManager()->spendResource(
+ ResourceManager::Resource::DecisionStep);
Assert(d_cnfStream != NULL)
<< "Forgot to set cnfStream for decision engine?";
Assert(d_satSolver != NULL)
#endif /* SWIGOCAML */
%ignore CVC4::stats::getStatisticsRegistry(ExprManager*);
+%ignore CVC4::ExprManager::getResourceManager();
%include "expr/expr_manager.h"
// attribute that stores the canonical bound variable list for function types
typedef expr::Attribute<attr::LambdaBoundVarListTag, Node> LambdaBoundVarListAttr;
-NodeManager::NodeManager(ExprManager* exprManager) :
- d_options(new Options()),
- d_statisticsRegistry(new StatisticsRegistry()),
- d_resourceManager(new ResourceManager()),
- d_registrations(new ListenerRegistrationList()),
- next_id(0),
- d_attrManager(new expr::attr::AttributeManager()),
- d_exprManager(exprManager),
- d_nodeUnderDeletion(NULL),
- d_inReclaimZombies(false),
- d_abstractValueCount(0),
- d_skolemCounter(0) {
+NodeManager::NodeManager(ExprManager* exprManager)
+ : d_options(new Options()),
+ d_statisticsRegistry(new StatisticsRegistry()),
+ d_resourceManager(new ResourceManager(*d_statisticsRegistry, *d_options)),
+ d_registrations(new ListenerRegistrationList()),
+ next_id(0),
+ d_attrManager(new expr::attr::AttributeManager()),
+ d_exprManager(exprManager),
+ d_nodeUnderDeletion(NULL),
+ d_inReclaimZombies(false),
+ d_abstractValueCount(0),
+ d_skolemCounter(0)
+{
init();
}
-NodeManager::NodeManager(ExprManager* exprManager,
- const Options& options) :
- d_options(new Options()),
- d_statisticsRegistry(new StatisticsRegistry()),
- d_resourceManager(new ResourceManager()),
- d_registrations(new ListenerRegistrationList()),
- next_id(0),
- d_attrManager(new expr::attr::AttributeManager()),
- d_exprManager(exprManager),
- d_nodeUnderDeletion(NULL),
- d_inReclaimZombies(false),
- d_abstractValueCount(0),
- d_skolemCounter(0)
+NodeManager::NodeManager(ExprManager* exprManager, const Options& options)
+ : d_options(new Options()),
+ d_statisticsRegistry(new StatisticsRegistry()),
+ d_resourceManager(new ResourceManager(*d_statisticsRegistry, *d_options)),
+ d_registrations(new ListenerRegistrationList()),
+ next_id(0),
+ d_attrManager(new expr::attr::AttributeManager()),
+ d_exprManager(exprManager),
+ d_nodeUnderDeletion(NULL),
+ d_inReclaimZombies(false),
+ d_abstractValueCount(0),
+ d_skolemCounter(0)
{
d_options->copyValues(options);
init();
}
// defensive coding, in case destruction-order issues pop up (they often do)
+ delete d_resourceManager;
+ d_resourceManager = NULL;
delete d_statisticsRegistry;
d_statisticsRegistry = NULL;
delete d_registrations;
d_registrations = NULL;
- delete d_resourceManager;
- d_resourceManager = NULL;
delete d_attrManager;
d_attrManager = NULL;
delete d_options;
read_only = true
help = "amount of resources spent for each bitblast step"
+[[option]]
+ name = "bvPropagationStep"
+ category = "expert"
+ long = "bv-propagation-step=N"
+ type = "unsigned"
+ default = "1"
+ read_only = true
+ help = "amount of resources spent for each BV propagation step"
+
+[[option]]
+ name = "bvEagerAssertStep"
+ category = "expert"
+ long = "bv-eager-assert-step=N"
+ type = "unsigned"
+ default = "1"
+ read_only = true
+ help = "amount of resources spent for each eager BV assert step"
+
[[option]]
name = "parseStep"
category = "expert"
dynamic_cast<QuitCommand*>(cmd) == NULL) {
// don't count set-option commands as to not get stuck in an infinite
// loop of resourcing out
- const Options& options = getExprManager()->getOptions();
- d_resourceManager->spendResource(options.getParseStep());
+ d_resourceManager->spendResource(ResourceManager::Resource::ParseStep);
}
return cmd;
}
Expr Parser::nextExpression()
{
Debug("parser") << "nextExpression()" << std::endl;
- const Options& options = getExprManager()->getOptions();
- d_resourceManager->spendResource(options.getParseStep());
+ d_resourceManager->spendResource(ResourceManager::Resource::ParseStep);
Expr result;
if (!done()) {
try {
}
Trace("apply-substs") << "applying to " << (*assertionsToPreprocess)[i]
<< std::endl;
- d_preprocContext->spendResource(options::preprocessStep());
+ d_preprocContext->spendResource(
+ ResourceManager::Resource::PreprocessStep);
assertionsToPreprocess->replace(i,
theory::Rewriter::rewrite(substMap.apply(
(*assertionsToPreprocess)[i])));
AssertionPipeline* assertionsToPreprocess)
{
NodeManager::currentResourceManager()->spendResource(
- options::preprocessStep());
+ ResourceManager::Resource::PreprocessStep);
unsigned size = assertionsToPreprocess->size();
for (unsigned i = 0; i < size; ++i)
AssertionPipeline* assertionsToPreprocess)
{
NodeManager::currentResourceManager()->spendResource(
- options::preprocessStep());
+ ResourceManager::Resource::PreprocessStep);
std::vector<Node> new_assertions;
liftBvToBool(assertionsToPreprocess->ref(), new_assertions);
for (unsigned i = 0; i < assertionsToPreprocess->size(); ++i)
PreprocessingPassResult IteRemoval::applyInternal(AssertionPipeline* assertions)
{
- d_preprocContext->spendResource(options::preprocessStep());
+ d_preprocContext->spendResource(ResourceManager::Resource::PreprocessStep);
// Remove all of the ITE occurrences and normalize
d_preprocContext->getIteRemover()->run(
PreprocessingPassResult ITESimp::applyInternal(
AssertionPipeline* assertionsToPreprocess)
{
- d_preprocContext->spendResource(options::preprocessStep());
+ d_preprocContext->spendResource(ResourceManager::Resource::PreprocessStep);
size_t nasserts = assertionsToPreprocess->size();
for (size_t i = 0; i < nasserts; ++i)
{
- d_preprocContext->spendResource(options::preprocessStep());
+ d_preprocContext->spendResource(ResourceManager::Resource::PreprocessStep);
Node simp = simpITE(&d_iteUtilities, (*assertionsToPreprocess)[i]);
assertionsToPreprocess->replace(i, simp);
if (simp.isConst() && !simp.getConst<bool>())
{
Assert(!options::unsatCores() && !options::fewerPreprocessingHoles());
- d_preprocContext->spendResource(options::preprocessStep());
+ d_preprocContext->spendResource(ResourceManager::Resource::PreprocessStep);
theory::booleans::CircuitPropagator* propagator =
d_preprocContext->getCircuitPropagator();
AssertionPipeline* assertionsToPreprocess)
{
NodeManager::currentResourceManager()->spendResource(
- options::preprocessStep());
+ ResourceManager::Resource::PreprocessStep);
for (unsigned i = 0; i < assertionsToPreprocess->size(); ++i)
{
PreprocessingPassResult UnconstrainedSimplifier::applyInternal(
AssertionPipeline* assertionsToPreprocess)
{
- d_preprocContext->spendResource(options::preprocessStep());
+ d_preprocContext->spendResource(ResourceManager::Resource::PreprocessStep);
std::vector<Node>& assertions = assertionsToPreprocess->ref();
return d_symsInAssertions;
}
- void spendResource(unsigned amount)
+ void spendResource(ResourceManager::Resource r)
{
- d_resourceManager->spendResource(amount);
+ d_resourceManager->spendResource(r);
}
const LogicInfo& getLogicInfo() { return d_smt->d_logic; }
#define CVC4__PROP__BVSATSOLVERNOTIFY_H
#include "prop/sat_solver_types.h"
+#include "util/resource_manager.h"
namespace CVC4 {
namespace prop {
* Notify about a learnt clause.
*/
virtual void notify(SatClause& clause) = 0;
- virtual void spendResource(unsigned amount) = 0;
- virtual void safePoint(unsigned amount) = 0;
+ virtual void spendResource(ResourceManager::Resource r) = 0;
+ virtual void safePoint(ResourceManager::Resource r) = 0;
};/* class BVSatSolverInterface::Notify */
#include "context/cdo.h"
#include "proof/clause_id.h"
#include "proof/resolution_bitvector_proof.h"
+#include "prop/bv_sat_solver_notify.h"
#include "prop/bvminisat/simp/SimpSolver.h"
#include "prop/sat_solver.h"
-#include "prop/bv_sat_solver_notify.h"
+#include "util/resource_manager.h"
#include "util/statistics_registry.h"
namespace CVC4 {
return d_notify->notify(toSatLiteral(lit));
}
void notify(BVMinisat::vec<BVMinisat::Lit>& clause) override;
- void spendResource(unsigned amount) override
+ void spendResource(ResourceManager::Resource r) override
+ {
+ d_notify->spendResource(r);
+ }
+ void safePoint(ResourceManager::Resource r) override
{
- d_notify->spendResource(amount);
+ d_notify->safePoint(r);
}
- void safePoint(unsigned amount) override { d_notify->safePoint(amount); }
};
std::unique_ptr<BVMinisat::SimpSolver> d_minisat;
// NO CONFLICT
bool isWithinBudget;
try {
- isWithinBudget = withinBudget(CVC4::options::bvSatConflictStep());
+ isWithinBudget =
+ withinBudget(ResourceManager::Resource::BvSatConflictsStep);
}
catch (const CVC4::theory::Interrupted& e) {
// do some clean-up and rethrow
while (status == l_Undef){
double rest_base = luby_restart ? luby(restart_inc, curr_restarts) : pow(restart_inc, curr_restarts);
status = search(rest_base * restart_first);
- if (!withinBudget(CVC4::options::bvSatConflictStep())) break;
+ if (!withinBudget(ResourceManager::Resource::BvSatConflictsStep)) break;
curr_restarts++;
}
}
void Solver::setNotify(Notify* toNotify) { d_notify = toNotify; }
-bool Solver::withinBudget(uint64_t amount) const
+bool Solver::withinBudget(ResourceManager::Resource r) const
{
AlwaysAssert(d_notify);
- d_notify->spendResource(amount);
- d_notify->safePoint(0);
+ d_notify->safePoint(r);
return !asynch_interrupt &&
(conflict_budget < 0 || conflicts < (uint64_t)conflict_budget) &&
#include "prop/bvminisat/mtl/Heap.h"
#include "prop/bvminisat/mtl/Vec.h"
#include "prop/bvminisat/utils/Options.h"
-
+#include "util/resource_manager.h"
namespace CVC4 {
*/
virtual void notify(vec<Lit>& learnt) = 0;
- virtual void spendResource(unsigned amount) = 0;
- virtual void safePoint(unsigned amount) = 0;
+ virtual void spendResource(ResourceManager::Resource r) = 0;
+ virtual void safePoint(ResourceManager::Resource r) = 0;
};
//=================================================================================================
CRef reason (Var x) const;
int level (Var x) const;
double progressEstimate () const; // DELETE THIS ?? IT'S NOT VERY USEFUL ...
- bool withinBudget (uint64_t amount) const;
+ bool withinBudget(ResourceManager::Resource r) const;
// Static helpers:
//
<< ", negated = " << (negated ? "true" : "false") << ")" << endl;
if (d_convertAndAssertCounter % ResourceManager::getFrequencyCount() == 0) {
- NodeManager::currentResourceManager()->spendResource(options::cnfStep());
+ NodeManager::currentResourceManager()->spendResource(
+ ResourceManager::Resource::CnfStep);
d_convertAndAssertCounter = 0;
}
++d_convertAndAssertCounter;
}
if ((nof_conflicts >= 0 && conflictC >= nof_conflicts)
- || !withinBudget(options::satConflictStep()))
+ || !withinBudget(ResourceManager::Resource::SatConflictStep))
{
// Reached bound on number of conflicts:
progress_estimate = progressEstimate();
while (status == l_Undef){
double rest_base = luby_restart ? luby(restart_inc, curr_restarts) : pow(restart_inc, curr_restarts);
status = search(rest_base * restart_first);
- if (!withinBudget(options::satConflictStep())) break; // FIXME add restart option?
+ if (!withinBudget(ResourceManager::Resource::SatConflictStep))
+ break; // FIXME add restart option?
curr_restarts++;
}
- if(!withinBudget(options::satConflictStep()))
- status = l_Undef;
+ if (!withinBudget(ResourceManager::Resource::SatConflictStep))
+ status = l_Undef;
if (verbosity >= 1)
printf("===============================================================================\n");
Debug("minisat::lemmas") << "Solver::updateLemmas() begin" << std::endl;
// Avoid adding lemmas indefinitely without resource-out
- proxy->spendResource(options::lemmaStep());
+ proxy->spendResource(ResourceManager::Resource::LemmaStep);
CRef conflict = CRef_Undef;
else if (to[cr].has_extra()) to[cr].calcAbstraction();
}
-inline bool Solver::withinBudget(uint64_t amount) const
+inline bool Solver::withinBudget(ResourceManager::Resource r) const
{
Assert(proxy);
// spendResource sets async_interrupt or throws UnsafeInterruptException
// depending on whether hard-limit is enabled
- proxy->spendResource(amount);
+ proxy->spendResource(r);
- bool within_budget = !asynch_interrupt &&
- (conflict_budget < 0 || conflicts < (uint64_t)conflict_budget) &&
- (propagation_budget < 0 || propagations < (uint64_t)propagation_budget);
+ bool within_budget =
+ !asynch_interrupt
+ && (conflict_budget < 0 || conflicts < (uint64_t)conflict_budget)
+ && (propagation_budget < 0
+ || propagations < (uint64_t)propagation_budget);
return within_budget;
}
-
} /* CVC4::Minisat namespace */
} /* CVC4 namespace */
double progressEstimate () const; // DELETE THIS ?? IT'S NOT VERY USEFUL ...
public:
bool withinBudget (uint64_t amount) const;
-protected:
+ bool withinBudget(ResourceManager::Resource r) const;
+ protected:
// Static helpers:
//
Debug("prop") << "interrupt()" << endl;
}
-void PropEngine::spendResource(unsigned amount)
+void PropEngine::spendResource(ResourceManager::Resource r)
{
- d_resourceManager->spendResource(amount);
+ d_resourceManager->spendResource(r);
}
bool PropEngine::properExplanation(TNode node, TNode expl) const {
#include "options/options.h"
#include "proof/proof_manager.h"
#include "smt_util/lemma_channels.h"
+#include "util/resource_manager.h"
#include "util/result.h"
#include "util/unsafe_interrupt_exception.h"
* Informs the ResourceManager that a resource has been spent. If out of
* resources, can throw an UnsafeInterruptException exception.
*/
- void spendResource(unsigned amount);
+ void spendResource(ResourceManager::Resource r);
/**
* For debugging. Return true if "expl" is a well-formed
}
void TheoryProxy::notifyRestart() {
- d_propEngine->spendResource(options::restartStep());
+ d_propEngine->spendResource(ResourceManager::Resource::RestartStep);
d_theoryEngine->notifyRestart();
static uint32_t lemmaCount = 0;
#endif /* CVC4_REPLAY */
}
-void TheoryProxy::spendResource(unsigned amount)
+void TheoryProxy::spendResource(ResourceManager::Resource r)
{
- d_theoryEngine->spendResource(amount);
+ d_theoryEngine->spendResource(r);
}
bool TheoryProxy::isDecisionRelevant(SatVariable var) {
#include "smt_util/lemma_input_channel.h"
#include "smt_util/lemma_output_channel.h"
#include "theory/theory.h"
+#include "util/resource_manager.h"
#include "util/statistics_registry.h"
namespace CVC4 {
void logDecision(SatLiteral lit);
- void spendResource(unsigned amount);
+ void spendResource(ResourceManager::Resource r);
bool isDecisionEngineDone();
void cleanupPreprocessingPasses() { d_passes.clear(); }
ResourceManager* getResourceManager() { return d_resourceManager; }
- void spendResource(unsigned amount)
+
+ void spendResource(ResourceManager::Resource r)
{
- d_resourceManager->spendResource(amount);
+ d_resourceManager->spendResource(r);
}
void nmNotifyNewSort(TypeNode tn, uint32_t flags) override
// or upward pass).
do {
- spendResource(options::preprocessStep());
+ spendResource(ResourceManager::Resource::PreprocessStep);
// n is the input / original
// node is the output / result
// returns false if simplification led to "false"
bool SmtEnginePrivate::simplifyAssertions()
{
- spendResource(options::preprocessStep());
+ spendResource(ResourceManager::Resource::PreprocessStep);
Assert(d_smt.d_pendingPops == 0);
try {
ScopeCounter depth(d_simplifyAssertionsDepth);
void SmtEnginePrivate::processAssertions() {
TimerStat::CodeTimer paTimer(d_smt.d_stats->d_processAssertionsTime);
- spendResource(options::preprocessStep());
+ spendResource(ResourceManager::Resource::PreprocessStep);
Assert(d_smt.d_fullyInited);
Assert(d_smt.d_pendingPops == 0);
SubstitutionMap& top_level_substs =
Expr SmtEngine::expandDefinitions(const Expr& ex)
{
- d_private->spendResource(options::preprocessStep());
+ d_private->spendResource(ResourceManager::Resource::PreprocessStep);
Assert(ex.getExprManager() == d_exprManager);
SmtScope smts(this);
}
void TheoryArith::check(Effort effortLevel){
- getOutputChannel().spendResource(options::theoryCheckStep());
+ getOutputChannel().spendResource(ResourceManager::Resource::TheoryCheckStep);
d_internal->check(effortLevel);
}
return;
}
- getOutputChannel().spendResource(options::theoryCheckStep());
+ getOutputChannel().spendResource(ResourceManager::Resource::TheoryCheckStep);
TimerStat::CodeTimer checkTimer(d_checkTime);
MinisatEmptyNotify() {}
bool notify(prop::SatLiteral lit) override { return true; }
void notify(prop::SatClause& clause) override {}
- void spendResource(unsigned amount) override
+ void spendResource(ResourceManager::Resource r) override
{
- NodeManager::currentResourceManager()->spendResource(amount);
+ NodeManager::currentResourceManager()->spendResource(r);
}
- void safePoint(unsigned amount) override {}
+
+ void safePoint(ResourceManager::Resource r) override {}
};
// Bitblaster implementation
return;
}
- d_bv->spendResource(options::bitblastStep());
+ d_bv->spendResource(ResourceManager::Resource::BitblastStep);
Debug("bitvector-bitblast") << "Bitblasting node " << node << "\n";
d_termBBStrategies[node.getKind()](node, bits, this);
}
Assert(node.getType().isBitVector());
- d_bv->spendResource(options::bitblastStep());
+ d_bv->spendResource(ResourceManager::Resource::BitblastStep);
Debug("bitvector-bitblast") << "Bitblasting term " << node <<"\n";
++d_statistics.d_numTerms;
}
}
-void TLazyBitblaster::MinisatNotify::spendResource(unsigned amount)
+void TLazyBitblaster::MinisatNotify::spendResource(ResourceManager::Resource r)
{
- d_bv->spendResource(amount);
+ d_bv->spendResource(r);
}
-void TLazyBitblaster::MinisatNotify::safePoint(unsigned amount)
+void TLazyBitblaster::MinisatNotify::safePoint(ResourceManager::Resource r)
{
- d_bv->d_out->safePoint(amount);
+ d_bv->d_out->safePoint(r);
}
EqualityStatus TLazyBitblaster::getEqualityStatus(TNode a, TNode b)
bool notify(prop::SatLiteral lit) override;
void notify(prop::SatClause& clause) override;
- void spendResource(unsigned amount) override;
- void safePoint(unsigned amount) override;
+ void spendResource(ResourceManager::Resource r) override;
+ void safePoint(ResourceManager::Resource r) override;
};
TheoryBV* d_bv;
}
void EagerBitblastSolver::assertFormula(TNode formula) {
- d_bv->spendResource(1);
+ d_bv->spendResource(ResourceManager::Resource::BvEagerAssertStep);
Assert(isInitialized());
Debug("bitvector-eager") << "EagerBitblastSolver::assertFormula " << formula
<< "\n";
// We need to ensure we are fully propagated, so propagate now
if (d_useSatPropagation)
{
- d_bv->spendResource(1);
+ d_bv->spendResource(ResourceManager::Resource::BvPropagationStep);
bool ok = d_bitblaster->propagate();
if (!ok)
{
bool CoreSolver::check(Theory::Effort e) {
Trace("bitvector::core") << "CoreSolver::check \n";
- d_bv->spendResource(options::theoryCheckStep());
+ d_bv->spendResource(ResourceManager::Resource::TheoryCheckStep);
d_checkCalled = true;
Assert(!d_bv->inConflict());
Debug("bv-subtheory-inequality") << "InequalitySolveR::check("<< e <<")\n";
TimerStat::CodeTimer inequalityTimer(d_statistics.d_solveTime);
++(d_statistics.d_numCallstoCheck);
- d_bv->spendResource(options::theoryCheckStep());
+ d_bv->spendResource(ResourceManager::Resource::TheoryCheckStep);
bool ok = true;
while (!done() && ok) {
}
}
-void TheoryBV::spendResource(unsigned amount)
+void TheoryBV::spendResource(ResourceManager::Resource r)
{
- getOutputChannel().spendResource(amount);
+ getOutputChannel().spendResource(r);
}
TheoryBV::Statistics::Statistics():
Statistics d_statistics;
- void spendResource(unsigned amount);
+ void spendResource(ResourceManager::Resource r);
/**
* Return the uninterpreted function symbol corresponding to division-by-zero
*
* @throws Interrupted if the theory can be safely interrupted.
*/
- virtual void safePoint(uint64_t amount) {}
+ virtual void safePoint(ResourceManager::Resource r) {}
/**
* Indicate a theory conflict has arisen.
* long-running operations, they cannot rely on resource() to break
* out of infinite or intractable computations.
*/
- virtual void spendResource(unsigned amount) {}
+ virtual void spendResource(ResourceManager::Resource r) {}
/**
* Handle user attribute.
Node q, std::vector<Node>& terms, bool mkRep, bool modEq, bool doVts)
{
// For resource-limiting (also does a time check).
- d_qe->getOutputChannel().safePoint(options::quantifierStep());
+ d_qe->getOutputChannel().safePoint(ResourceManager::Resource::QuantifierStep);
Assert(!d_qe->inConflict());
Assert(terms.size() == q[0].getNumChildren());
Assert(d_term_db != nullptr);
if (hasSmtEngine &&
d_iterationCount % ResourceManager::getFrequencyCount() == 0) {
- rm->spendResource(options::rewriteStep());
+ rm->spendResource(ResourceManager::Resource::RewriteStep);
d_iterationCount = 0;
}
return;
}
- getOutputChannel().spendResource(options::theoryCheckStep());
+ getOutputChannel().spendResource(ResourceManager::Resource::TheoryCheckStep);
TimerStat::CodeTimer checkTimer(d_checkTime);
Trace("sep-check") << "Sep::check(): " << e << endl;
}
}
-void TheoryEngine::spendResource(unsigned amount)
+void TheoryEngine::spendResource(ResourceManager::Resource r)
{
- d_resourceManager->spendResource(amount);
+ d_resourceManager->spendResource(r);
}
void TheoryEngine::enableTheoryAlternative(const std::string& name){
#include "theory/uf/equality_engine.h"
#include "theory/valuation.h"
#include "util/hash.h"
+#include "util/resource_manager.h"
#include "util/statistics_registry.h"
#include "util/unsafe_interrupt_exception.h"
EngineOutputChannel(TheoryEngine* engine, theory::TheoryId theory)
: d_engine(engine), d_statistics(theory), d_theory(theory) {}
- void safePoint(uint64_t amount) override {
- spendResource(amount);
+ void safePoint(ResourceManager::Resource r) override
+ {
+ spendResource(r);
if (d_engine->d_interrupted) {
throw theory::Interrupted();
}
d_engine->setIncomplete(d_theory);
}
- void spendResource(unsigned amount) override {
- d_engine->spendResource(amount);
+ void spendResource(ResourceManager::Resource r) override
+ {
+ d_engine->spendResource(r);
}
void handleUserAttribute(const char* attr, theory::Theory* t) override {
void interrupt();
/** "Spend" a resource during a search or preprocessing.*/
- void spendResource(unsigned amount);
+ void spendResource(ResourceManager::Resource r);
/**
* Adds a theory. Only one theory per TheoryId can be present, so if
#include "theory/interrupted.h"
#include "theory/output_channel.h"
#include "util/proof.h"
+#include "util/resource_manager.h"
#include "util/unsafe_interrupt_exception.h"
namespace CVC4 {
TestOutputChannel() {}
~TestOutputChannel() override {}
- void safePoint(uint64_t amount) override {}
+ void safePoint(ResourceManager::Resource r) override {}
void conflict(TNode n, std::unique_ptr<Proof> pf) override
{
push(CONFLICT, n);
if (done() && !fullEffort(level)) {
return;
}
- getOutputChannel().spendResource(options::theoryCheckStep());
+ getOutputChannel().spendResource(ResourceManager::Resource::TheoryCheckStep);
TimerStat::CodeTimer checkTimer(d_checkTime);
while (!done() && !d_conflict)
#include "base/check.h"
#include "base/output.h"
#include "options/smt_options.h"
+#include "util/statistics_registry.h"
using namespace std;
return false;
}
+/*---------------------------------------------------------------------------*/
+
+struct ResourceManager::Statistics
+{
+ IntStat d_numBitblastStep;
+ IntStat d_numBvEagerAssertStep;
+ IntStat d_numBvPropagationStep;
+ IntStat d_numBvSatConflictsStep;
+ IntStat d_numCnfStep;
+ IntStat d_numDecisionStep;
+ IntStat d_numLemmaStep;
+ IntStat d_numParseStep;
+ IntStat d_numPreprocessStep;
+ IntStat d_numQuantifierStep;
+ IntStat d_numRestartStep;
+ IntStat d_numRewriteStep;
+ IntStat d_numSatConflictStep;
+ IntStat d_numTheoryCheckStep;
+ Statistics(StatisticsRegistry& stats);
+ ~Statistics();
+
+ private:
+ StatisticsRegistry& d_statisticsRegistry;
+};
+
+ResourceManager::Statistics::Statistics(StatisticsRegistry& stats)
+ : d_numBitblastStep("resource::BitblastStep", 0),
+ d_numBvEagerAssertStep("resource::BvEagerAssertStep", 0),
+ d_numBvPropagationStep("resource::BvPropagationStep", 0),
+ d_numBvSatConflictsStep("resource::BvSatConflictsStep", 0),
+ d_numCnfStep("resource::CnfStep", 0),
+ d_numDecisionStep("resource::DecisionStep", 0),
+ d_numLemmaStep("resource::LemmaStep", 0),
+ d_numParseStep("resource::ParseStep", 0),
+ d_numPreprocessStep("resource::PreprocessStep", 0),
+ d_numQuantifierStep("resource::QuantifierStep", 0),
+ d_numRestartStep("resource::RestartStep", 0),
+ d_numRewriteStep("resource::RewriteStep", 0),
+ d_numSatConflictStep("resource::SatConflictStep", 0),
+ d_numTheoryCheckStep("resource::TheoryCheckStep", 0),
+ d_statisticsRegistry(stats)
+{
+ d_statisticsRegistry.registerStat(&d_numBitblastStep);
+ d_statisticsRegistry.registerStat(&d_numBvEagerAssertStep);
+ d_statisticsRegistry.registerStat(&d_numBvPropagationStep);
+ d_statisticsRegistry.registerStat(&d_numBvSatConflictsStep);
+ d_statisticsRegistry.registerStat(&d_numCnfStep);
+ d_statisticsRegistry.registerStat(&d_numDecisionStep);
+ d_statisticsRegistry.registerStat(&d_numLemmaStep);
+ d_statisticsRegistry.registerStat(&d_numParseStep);
+ d_statisticsRegistry.registerStat(&d_numPreprocessStep);
+ d_statisticsRegistry.registerStat(&d_numQuantifierStep);
+ d_statisticsRegistry.registerStat(&d_numRestartStep);
+ d_statisticsRegistry.registerStat(&d_numRewriteStep);
+ d_statisticsRegistry.registerStat(&d_numSatConflictStep);
+ d_statisticsRegistry.registerStat(&d_numTheoryCheckStep);
+}
+
+ResourceManager::Statistics::~Statistics()
+{
+ d_statisticsRegistry.unregisterStat(&d_numBitblastStep);
+ d_statisticsRegistry.unregisterStat(&d_numBvEagerAssertStep);
+ d_statisticsRegistry.unregisterStat(&d_numBvPropagationStep);
+ d_statisticsRegistry.unregisterStat(&d_numBvSatConflictsStep);
+ d_statisticsRegistry.unregisterStat(&d_numCnfStep);
+ d_statisticsRegistry.unregisterStat(&d_numDecisionStep);
+ d_statisticsRegistry.unregisterStat(&d_numLemmaStep);
+ d_statisticsRegistry.unregisterStat(&d_numParseStep);
+ d_statisticsRegistry.unregisterStat(&d_numPreprocessStep);
+ d_statisticsRegistry.unregisterStat(&d_numQuantifierStep);
+ d_statisticsRegistry.unregisterStat(&d_numRestartStep);
+ d_statisticsRegistry.unregisterStat(&d_numRewriteStep);
+ d_statisticsRegistry.unregisterStat(&d_numSatConflictStep);
+ d_statisticsRegistry.unregisterStat(&d_numTheoryCheckStep);
+}
+
+/*---------------------------------------------------------------------------*/
+
const uint64_t ResourceManager::s_resourceCount = 1000;
-ResourceManager::ResourceManager()
- : d_cumulativeTimer()
- , d_perCallTimer()
- , d_timeBudgetCumulative(0)
- , d_timeBudgetPerCall(0)
- , d_resourceBudgetCumulative(0)
- , d_resourceBudgetPerCall(0)
- , d_cumulativeTimeUsed(0)
- , d_cumulativeResourceUsed(0)
- , d_thisCallResourceUsed(0)
- , d_thisCallTimeBudget(0)
- , d_thisCallResourceBudget(0)
- , d_isHardLimit()
- , d_on(false)
- , d_cpuTime(false)
- , d_spendResourceCalls(0)
- , d_hardListeners()
- , d_softListeners()
+ResourceManager::ResourceManager(StatisticsRegistry& stats, Options& options)
+ : d_cumulativeTimer(),
+ d_perCallTimer(),
+ d_timeBudgetCumulative(0),
+ d_timeBudgetPerCall(0),
+ d_resourceBudgetCumulative(0),
+ d_resourceBudgetPerCall(0),
+ d_cumulativeTimeUsed(0),
+ d_cumulativeResourceUsed(0),
+ d_thisCallResourceUsed(0),
+ d_thisCallTimeBudget(0),
+ d_thisCallResourceBudget(0),
+ d_isHardLimit(),
+ d_on(false),
+ d_cpuTime(false),
+ d_spendResourceCalls(0),
+ d_hardListeners(),
+ d_softListeners(),
+ d_statistics(new ResourceManager::Statistics(stats)),
+ d_options(options)
+
{}
+ResourceManager::~ResourceManager() {}
void ResourceManager::setResourceLimit(uint64_t units, bool cumulative) {
d_on = true;
}
}
+void ResourceManager::spendResource(Resource r)
+{
+ uint32_t amount = 0;
+ switch (r)
+ {
+ case Resource::BitblastStep:
+ amount = d_options[options::bitblastStep];
+ ++d_statistics->d_numBitblastStep;
+ break;
+ case Resource::BvEagerAssertStep:
+ amount = d_options[options::bvEagerAssertStep];
+ ++d_statistics->d_numBvEagerAssertStep;
+ break;
+ case Resource::BvPropagationStep:
+ amount = d_options[options::bvPropagationStep];
+ ++d_statistics->d_numBvPropagationStep;
+ break;
+ case Resource::BvSatConflictsStep:
+ amount = d_options[options::bvSatConflictStep];
+ ++d_statistics->d_numBvSatConflictsStep;
+ break;
+ case Resource::CnfStep:
+ amount = d_options[options::cnfStep];
+ ++d_statistics->d_numCnfStep;
+ break;
+ case Resource::DecisionStep:
+ amount = d_options[options::decisionStep];
+ ++d_statistics->d_numDecisionStep;
+ break;
+ case Resource::LemmaStep:
+ amount = d_options[options::lemmaStep];
+ ++d_statistics->d_numLemmaStep;
+ break;
+ case Resource::ParseStep:
+ amount = d_options[options::parseStep];
+ ++d_statistics->d_numParseStep;
+ break;
+ case Resource::PreprocessStep:
+ amount = d_options[options::preprocessStep];
+ ++d_statistics->d_numPreprocessStep;
+ break;
+ case Resource::QuantifierStep:
+ amount = d_options[options::quantifierStep];
+ ++d_statistics->d_numQuantifierStep;
+ break;
+ case Resource::RestartStep:
+ amount = d_options[options::restartStep];
+ ++d_statistics->d_numRestartStep;
+ break;
+ case Resource::RewriteStep:
+ amount = d_options[options::rewriteStep];
+ ++d_statistics->d_numRewriteStep;
+ break;
+ case Resource::SatConflictStep:
+ amount = d_options[options::satConflictStep];
+ ++d_statistics->d_numSatConflictStep;
+ break;
+ case Resource::TheoryCheckStep:
+ amount = d_options[options::theoryCheckStep];
+ ++d_statistics->d_numTheoryCheckStep;
+ break;
+ default: Unreachable() << "Invalid resource " << std::endl;
+ }
+ spendResource(amount);
+}
+
void ResourceManager::beginCall() {
d_perCallTimer.set(d_timeBudgetPerCall, !d_cpuTime);
#ifndef CVC4__RESOURCE_MANAGER_H
#define CVC4__RESOURCE_MANAGER_H
-#include <cstddef>
#include <sys/time.h>
+#include <cstddef>
+#include <memory>
+
#include "base/exception.h"
#include "base/listener.h"
+#include "options/options.h"
#include "util/unsafe_interrupt_exception.h"
namespace CVC4 {
+class StatisticsRegistry;
+
/**
* A helper class to keep track of a time budget and signal
* the PropEngine when the budget expires.
class CVC4_PUBLIC ResourceManager {
-
- Timer d_cumulativeTimer;
- Timer d_perCallTimer;
-
- /** A user-imposed cumulative time budget, in milliseconds. 0 = no limit. */
- uint64_t d_timeBudgetCumulative;
- /** A user-imposed per-call time budget, in milliseconds. 0 = no limit. */
- uint64_t d_timeBudgetPerCall;
- /** A user-imposed cumulative resource budget. 0 = no limit. */
- uint64_t d_resourceBudgetCumulative;
- /** A user-imposed per-call resource budget. 0 = no limit. */
- uint64_t d_resourceBudgetPerCall;
-
- /** The number of milliseconds used. */
- uint64_t d_cumulativeTimeUsed;
- /** The amount of resource used. */
- uint64_t d_cumulativeResourceUsed;
-
- /** The amount of resource used during this call. */
- uint64_t d_thisCallResourceUsed;
-
- /**
- * The amount of resource budget for this call (min between per call
- * budget and left-over cumulative budget.
- */
- uint64_t d_thisCallTimeBudget;
- uint64_t d_thisCallResourceBudget;
-
- bool d_isHardLimit;
- bool d_on;
- bool d_cpuTime;
- uint64_t d_spendResourceCalls;
-
- /** Counter indicating how often to check resource manager in loops */
- static const uint64_t s_resourceCount;
-
- /** Receives a notification on reaching a hard limit. */
- ListenerCollection d_hardListeners;
-
- /** Receives a notification on reaching a hard limit. */
- ListenerCollection d_softListeners;
-
- /**
- * ResourceManagers cannot be copied as they are given an explicit
- * list of Listeners to respond to.
- */
- ResourceManager(const ResourceManager&) = delete;
-
- /**
- * ResourceManagers cannot be assigned as they are given an explicit
- * list of Listeners to respond to.
- */
- ResourceManager& operator=(const ResourceManager&) = delete;
-
public:
-
- ResourceManager();
-
- bool limitOn() const { return cumulativeLimitOn() || perCallLimitOn(); }
- bool cumulativeLimitOn() const;
- bool perCallLimitOn() const;
-
- bool outOfResources() const;
- bool outOfTime() const;
- bool out() const { return d_on && (outOfResources() || outOfTime()); }
-
-
- /**
- * This returns a const uint64_t& to support being used as a ReferenceStat.
- */
- const uint64_t& getResourceUsage() const;
- uint64_t getTimeUsage() const;
- uint64_t getResourceRemaining() const;
- uint64_t getTimeRemaining() const;
-
- uint64_t getResourceBudgetForThisCall() {
- return d_thisCallResourceBudget;
- }
- // Throws an UnsafeInterruptException if there are no remaining resources.
- void spendResource(unsigned amount);
-
- void setHardLimit(bool value);
- void setResourceLimit(uint64_t units, bool cumulative = false);
- void setTimeLimit(uint64_t millis, bool cumulative = false);
- void useCPUTime(bool cpu);
-
- void enable(bool on);
-
- /**
- * Resets perCall limits to mark the start of a new call,
- * updates budget for current call and starts the timer
- */
- void beginCall();
-
- /**
- * Marks the end of a SmtEngine check call, stops the per
- * call timer, updates cumulative time used.
- */
- void endCall();
-
- static uint64_t getFrequencyCount() { return s_resourceCount; }
-
- /**
- * Registers a listener that is notified on a hard resource out.
- *
- * This Registration must be destroyed by the user before this
- * ResourceManager.
- */
- ListenerCollection::Registration* registerHardListener(Listener* listener);
-
- /**
- * Registers a listener that is notified on a soft resource out.
- *
- * This Registration must be destroyed by the user before this
- * ResourceManager.
- */
- ListenerCollection::Registration* registerSoftListener(Listener* listener);
+ enum class Resource
+ {
+ BitblastStep,
+ BvEagerAssertStep,
+ BvPropagationStep,
+ BvSatConflictsStep,
+ CnfStep,
+ DecisionStep,
+ LemmaStep,
+ ParseStep,
+ PreprocessStep,
+ QuantifierStep,
+ RestartStep,
+ RewriteStep,
+ SatConflictStep,
+ TheoryCheckStep,
+ };
+
+ ResourceManager(StatisticsRegistry& statistics_registry, Options& options);
+ ~ResourceManager();
+
+ bool limitOn() const { return cumulativeLimitOn() || perCallLimitOn(); }
+ bool cumulativeLimitOn() const;
+ bool perCallLimitOn() const;
+
+ bool outOfResources() const;
+ bool outOfTime() const;
+ bool out() const { return d_on && (outOfResources() || outOfTime()); }
+
+ /**
+ * This returns a const uint64_t& to support being used as a ReferenceStat.
+ */
+ const uint64_t& getResourceUsage() const;
+ uint64_t getTimeUsage() const;
+ uint64_t getResourceRemaining() const;
+ uint64_t getTimeRemaining() const;
+
+ uint64_t getResourceBudgetForThisCall() { return d_thisCallResourceBudget; }
+ // Throws an UnsafeInterruptException if there are no remaining resources.
+ void spendResource(Resource r);
+
+ void setHardLimit(bool value);
+ void setResourceLimit(uint64_t units, bool cumulative = false);
+ void setTimeLimit(uint64_t millis, bool cumulative = false);
+ void useCPUTime(bool cpu);
+
+ void enable(bool on);
+
+ /**
+ * Resets perCall limits to mark the start of a new call,
+ * updates budget for current call and starts the timer
+ */
+ void beginCall();
+
+ /**
+ * Marks the end of a SmtEngine check call, stops the per
+ * call timer, updates cumulative time used.
+ */
+ void endCall();
+
+ static uint64_t getFrequencyCount() { return s_resourceCount; }
+
+ /**
+ * Registers a listener that is notified on a hard resource out.
+ *
+ * This Registration must be destroyed by the user before this
+ * ResourceManager.
+ */
+ ListenerCollection::Registration* registerHardListener(Listener* listener);
+
+ /**
+ * Registers a listener that is notified on a soft resource out.
+ *
+ * This Registration must be destroyed by the user before this
+ * ResourceManager.
+ */
+ ListenerCollection::Registration* registerSoftListener(Listener* listener);
+
+private:
+ Timer d_cumulativeTimer;
+ Timer d_perCallTimer;
+
+ /** A user-imposed cumulative time budget, in milliseconds. 0 = no limit. */
+ uint64_t d_timeBudgetCumulative;
+ /** A user-imposed per-call time budget, in milliseconds. 0 = no limit. */
+ uint64_t d_timeBudgetPerCall;
+ /** A user-imposed cumulative resource budget. 0 = no limit. */
+ uint64_t d_resourceBudgetCumulative;
+ /** A user-imposed per-call resource budget. 0 = no limit. */
+ uint64_t d_resourceBudgetPerCall;
+
+ /** The number of milliseconds used. */
+ uint64_t d_cumulativeTimeUsed;
+ /** The amount of resource used. */
+ uint64_t d_cumulativeResourceUsed;
+
+ /** The amount of resource used during this call. */
+ uint64_t d_thisCallResourceUsed;
+
+ /**
+ * The amount of resource budget for this call (min between per call
+ * budget and left-over cumulative budget.
+ */
+ uint64_t d_thisCallTimeBudget;
+ uint64_t d_thisCallResourceBudget;
+
+ bool d_isHardLimit;
+ bool d_on;
+ bool d_cpuTime;
+ uint64_t d_spendResourceCalls;
+
+ /** Counter indicating how often to check resource manager in loops */
+ static const uint64_t s_resourceCount;
+
+ /** Receives a notification on reaching a hard limit. */
+ ListenerCollection d_hardListeners;
+
+ /** Receives a notification on reaching a hard limit. */
+ ListenerCollection d_softListeners;
+
+ /**
+ * ResourceManagers cannot be copied as they are given an explicit
+ * list of Listeners to respond to.
+ */
+ ResourceManager(const ResourceManager&) = delete;
+
+ /**
+ * ResourceManagers cannot be assigned as they are given an explicit
+ * list of Listeners to respond to.
+ */
+ ResourceManager& operator=(const ResourceManager&) = delete;
+
+ void spendResource(unsigned amount);
+
+ struct Statistics;
+ std::unique_ptr<Statistics> d_statistics;
+
+ Options& d_options;
};/* class ResourceManager */
+++ /dev/null
-%{
-#include "util/resource_manager.h"
-%}
-
-%include "util/resource_manager.h"
**/
#include <cxxtest/TestSuite.h>
+
#include <memory>
#include <vector>
#include "theory/theory.h"
#include "theory/theory_engine.h"
#include "util/proof.h"
+#include "util/resource_manager.h"
using namespace CVC4;
using namespace CVC4::theory;
TestOutputChannel() {}
~TestOutputChannel() override {}
- void safePoint(uint64_t amount) override {}
+ void safePoint(ResourceManager::Resource r) override {}
void conflict(TNode n, std::unique_ptr<Proof> pf) override
{
push(CONFLICT, n);