ABC: A System for Sequential Synthesis and Verification
 
Loading...
Searching...
No Matches
rrr::Scheduler< Ntk, Opt, Par >::CompareJobPointers Struct Reference

#include <rrrScheduler.h>

Public Member Functions

bool operator() (Job const *lhs, Job const *rhs) const
 
 Scheduler (Ntk *pNtk, Parameter const *pPar)
 
 ~Scheduler ()
 
void Run ()
 

Detailed Description

template<typename Ntk, typename Opt, typename Par>
struct rrr::Scheduler< Ntk, Opt, Par >::CompareJobPointers

Definition at line 132 of file rrrScheduler.h.

Constructor & Destructor Documentation

◆ ~Scheduler()

rrr::Scheduler< Ntk, Opt, Par >::~Scheduler ( )

Definition at line 99 of file rrrScheduler.h.

487 {
488#ifdef ABC_USE_PTHREADS
489 if(fMultiThreading) {
490 {
492 fTerminate = true;
493 condPendingJobs.notify_all();
494 }
495 for(std::thread &t: vThreads) {
496 t.join();
497 }
498 return;
499 }
500#endif
501 delete pOpt;
502 }

Member Function Documentation

◆ operator()()

template<typename Ntk, typename Opt, typename Par>
bool rrr::Scheduler< Ntk, Opt, Par >::CompareJobPointers::operator() ( Job const * lhs,
Job const * rhs ) const
inline

Definition at line 134 of file rrrScheduler.h.

134 {
135 return lhs->id > rhs->id;
136 }

◆ Run()

void rrr::Scheduler< Ntk, Opt, Par >::Run ( )

Definition at line 102 of file rrrScheduler.h.

509 {
510 timeStart = GetCurrentTime();
511 double costStart = CostFunction(pNtk);
512 if(fPartitioning) {
513 fDeterministic = false; // it is deterministic anyways as we wait until all jobs finish each round
514 pNtk->Sweep();
515 par.AssignNetwork(pNtk);
516 while(nCreatedJobs < nJobs) {
517 assert(nParallelPartitions > 0);
518 if(nCreatedJobs < nFinishedJobs + nParallelPartitions) {
519 Ntk *pSubNtk = par.Extract(iSeed + nCreatedJobs);
520 if(pSubNtk) {
521 Job *pJob = CreateJob(pSubNtk, iSeed + nCreatedJobs, CostFunction(pSubNtk));
522 Print(1, pJob->prefix, "created ", ":", "i/o", "=", pJob->pNtk->GetNumPis(), "/", pJob->pNtk->GetNumPos(), ",", "node", "=", pJob->pNtk->GetNumInts(), ",", "level", "=", pJob->pNtk->GetNumLevels(), ",", "cost", "=", pJob->costInitial);
523 continue;
524 }
525 }
526 if(nCreatedJobs == nFinishedJobs) {
527 PrintWarning("failed to partition");
528 break;
529 }
530 while(nFinishedJobs < nCreatedJobs) {
531 OnJobEnd([&](Job *pJob) {
532 double cost = CostFunction(pJob->pNtk);
533 Print(1, pJob->prefix, "finished", ":", "i/o", "=", pJob->pNtk->GetNumPis(), "/", pJob->pNtk->GetNumPos(), ",", "node", "=", pJob->pNtk->GetNumInts(), ",", "level", "=", pJob->pNtk->GetNumLevels(), ",", "cost", "=", cost);
534 Print(0, "", "job", pJob->id, "(", nFinishedJobs + 1, "/", nJobs, ")", ":", "i/o", "=", pJob->pNtk->GetNumPis(), "/", pJob->pNtk->GetNumPos(), ",", "node", "=", pJob->pNtk->GetNumInts(), ",", "level", "=", pJob->pNtk->GetNumLevels(), ",", "cost", "=", cost, "(", 100 * (cost - pJob->costInitial) / pJob->costInitial, "%", ")", ",", "duration", "=", pJob->duration, "s", ",", "elapsed", "=", GetElapsedTime(), "s");
535 par.Insert(pJob->pNtk);
536 });
537 }
538 if(fOptOnInsert) {
540 CallAbc(pNtk, std::string("&put; ") + pCompress2rs + "; dc2; &get");
542 par.AssignNetwork(pNtk);
543 double cost = CostFunction(pNtk);
544 Print(0, "", "c2rs; dc2", ":", std::string(34, ' '), "node", "=", pNtk->GetNumInts(), ",", "level", "=", pNtk->GetNumLevels(), ",", "cost", "=", cost, "(", 100 * (cost - costStart) / costStart, "%", ")", ",", "duration", "=", Duration(timeStartLocal, timeEndLocal), "s", ",", "elapsed", "=", GetElapsedTime(), "s");
545 }
546 }
547 while(nFinishedJobs < nCreatedJobs) {
548 OnJobEnd([&](Job *pJob) {
549 double cost = CostFunction(pJob->pNtk);
550 Print(1, pJob->prefix, "finished", ":", "i/o", "=", pJob->pNtk->GetNumPis(), "/", pJob->pNtk->GetNumPos(), ",", "node", "=", pJob->pNtk->GetNumInts(), ",", "level", "=", pJob->pNtk->GetNumLevels(), ",", "cost", "=", CostFunction(pJob->pNtk));
551 Print(0, "", "job", pJob->id, "(", nFinishedJobs + 1, "/", nJobs, ")", ":", "i/o", "=", pJob->pNtk->GetNumPis(), "/", pJob->pNtk->GetNumPos(), ",", "node", "=", pJob->pNtk->GetNumInts(), ",", "level", "=", pJob->pNtk->GetNumLevels(), ",", "cost", "=", cost, "(", 100 * (cost - pJob->costInitial) / pJob->costInitial, "%", ")", ",", "duration", "=", pJob->duration, "s", ",", "elapsed", "=", GetElapsedTime(), "s");
552 par.Insert(pJob->pNtk);
553 });
554 }
555 if(fOptOnInsert) {
556 CallAbc(pNtk, std::string("&put; ") + pCompress2rs + "; dc2; &get");
557 par.AssignNetwork(pNtk);
558 }
559 } else if(nJobs > 1) {
560 double costBest = costStart;
561 for(int i = 0; i < nJobs; i++) {
562 Ntk *pCopy = new Ntk(*pNtk);
563 CreateJob(pCopy, iSeed + i, costBest);
564 }
565 for(int i = 0; i < nJobs; i++) {
566 OnJobEnd([&](Job *pJob) {
567 double cost = CostFunction(pJob->pNtk);
568 Print(0, "", "job", pJob->id, "(", nFinishedJobs + 1, "/", nJobs, ")", ":", "node", "=", pJob->pNtk->GetNumInts(), ",", "level", "=", pJob->pNtk->GetNumLevels(), ",", "cost", "=", cost, "(", 100 * (cost - pJob->costInitial) / pJob->costInitial, "%", ")", ",", "duration", "=", pJob->duration, "s", ",", "elapsed", "=", GetElapsedTime(), "s");
569 if(cost < costBest) {
570 costBest = cost;
571 *pNtk = *(pJob->pNtk);
572 }
573 delete pJob->pNtk;
574 });
575 }
576 } else {
577 CreateJob(pNtk, iSeed, costStart);
578 OnJobEnd([&](Job *pJob) {
579 double cost = CostFunction(pJob->pNtk);
580 Print(0, "", "job", pJob->id, "(", nFinishedJobs + 1, "/", nJobs, ")", ":", "node", "=", pJob->pNtk->GetNumInts(), ",", "level", "=", pJob->pNtk->GetNumLevels(), ",", "cost", "=", cost, "(", 100 * (cost - pJob->costInitial) / pJob->costInitial, "%", ")", ",", "duration", "=", pJob->duration, "s", ",", "elapsed", "=", GetElapsedTime(), "s");
581 });
582 }
583 double cost = CostFunction(pNtk);
584 double duration = GetElapsedTime();
585 Print(0, "\n", "stats summary", ":");
586 for(std::string key: vStatsSummaryKeys) {
587 Print(0, "\t", SW{30, true}, key, ":", SW{10}, mStatsSummary[key]);
588 }
589 Print(0, "", "runtime summary", ":");
590 for(std::string key: vTimesSummaryKeys) {
591 Print(0, "\t", SW{30, true}, key, ":", mTimesSummary[key], "s", "(", 100 * mTimesSummary[key] / duration, "%", ")");
592 }
593 Print(0, "", "end", ":", "cost", "=", cost, "(", 100 * (cost - costStart) / costStart, "%", ")", ",", "time", "=", duration, "s");
594 }
#define assert(ex)
Definition util_old.h:213

◆ Scheduler()

rrr::Scheduler< Ntk, Opt, Par >::Scheduler ( Ntk * pNtk,
Parameter const * pPar )

Definition at line 98 of file rrrScheduler.h.

448 :
449 pNtk(pNtk),
450 nVerbose(pPar->nSchedulerVerbose),
451 iSeed(pPar->iSeed),
452 nFlow(pPar->nSchedulerFlow),
453 nJobs(pPar->nJobs),
454 fMultiThreading(pPar->nThreads > 1),
455 fPartitioning(pPar->nPartitionSize > 0),
456 fDeterministic(pPar->fDeterministic),
457 nParallelPartitions(pPar->nParallelPartitions),
458 fOptOnInsert(pPar->fOptOnInsert),
459 nTimeout(pPar->nTimeout),
460 nCreatedJobs(0),
461 nFinishedJobs(0),
462 par(pPar),
463 pOpt(NULL) {
464 // prepare cost function
465 CostFunction = [](Ntk *pNtk) {
466 int nTwoInputSize = 0;
467 pNtk->ForEachInt([&](int id) {
468 nTwoInputSize += pNtk->GetNumFanins(id) - 1;
469 });
470 return nTwoInputSize;
471 };
472#ifdef ABC_USE_PTHREADS
473 fTerminate = false;
474 if(fMultiThreading) {
475 vThreads.reserve(pPar->nThreads);
476 for(int i = 0; i < pPar->nThreads; i++) {
477 vThreads.emplace_back(std::bind(&Scheduler::Thread, this, pPar));
478 }
479 return;
480 }
481#endif
482 assert(!fMultiThreading);
483 pOpt = new Opt(pPar, CostFunction);
484 }

The documentation for this struct was generated from the following file: