ABC: A System for Sequential Synthesis and Verification
 
Loading...
Searching...
No Matches
eSLIM.cpp
Go to the documentation of this file.
1
20
21#include "utils.hpp"
22#include "eSLIMMan.hpp"
24#include "selectionStrategy.hpp"
25
27
28#include "eSLIM.h"
29
31 Gia_Man_t * Gia_ManDeepSyn( Gia_Man_t * pGia, int nIters, int nNoImpr, int TimeOut, int nAnds, int Seed, int fUseTwo, int fVerbose );
33
35
38 config.extended_normality_processing = params->extended_normality_processing;
39 config.apply_strash = params->apply_strash;
40 config.fill_subcircuits = params->fill_subcircuits;
41 config.fix_seed = params->fix_seed;
42 config.trial_limit_active = params->trial_limit_active;
43 config.timeout = params->timeout;
44 config.iterations = params->iterations;
45 config.subcircuit_size_bound = params->subcircuit_size_bound;
46 config.strash_intervall = params->strash_intervall;
47 config.nselection_trials = params->nselection_trials;
48 config.seed = params->seed;
49 config.verbosity_level = params->verbosity_level;
50 config.expansion_probability = params->expansion_probability;
51 return config;
52}
53
55 params->forbidden_pairs = 1;
56 params->extended_normality_processing = 0;
57 params->fill_subcircuits = 0;
58 params->apply_strash = 1;
59 params->fix_seed = 0;
60 params->trial_limit_active = 1;
61 params->apply_inprocessing = 1;
62 params->timeout = 1620;
63 params->timeout_inprocessing = 180;
64 params->iterations = 0;
65 params->subcircuit_size_bound = 6;
66 params->strash_intervall = 100;
67 params->nselection_trials = 100;
68 params->nruns = 1;
69 params->mode = 0;
70 params->seed = 0;
71 params->verbosity_level = 1;
72 params->expansion_probability = 0.4;
73}
74
75Gia_Man_t* selectApproach(Gia_Man_t* pGia, eSLIM::eSLIMConfig params, eSLIM::eSLIMLog& log, int approach, bool allow_forbidden_pairs) {
76 switch (approach) {
77 case 0 :
78 if (allow_forbidden_pairs) {
80 } else {
82 };
83 case 1:
84 if (allow_forbidden_pairs) {
86 } else {
88 };
89 case 2:
90 if (allow_forbidden_pairs) {
92 } else {
94 };
95 default:
96 std::cerr << "eSLIM -- Invalid mode given\n";
97 assert (false && "Invalid approach selected");
98 return nullptr;
99 }
100}
101
102Gia_Man_t* runInprocessing(Gia_Man_t * pGia, const eSLIM_ParamStruct* params, unsigned int it) {
103 Gia_Man_t * tmp = Gia_ManDeepSyn( pGia, 1, ABC_INFINITY, params->timeout_inprocessing, 0, params->seed + it, 0, 0);
104 if ( Gia_ManAndNum(pGia) > Gia_ManAndNum(tmp) ) {
105 Gia_ManStop( pGia );
106 pGia = tmp;
107 } else {
108 Gia_ManStop( tmp );
109 }
110 return pGia;
111}
112
113void printSetting(const eSLIM_ParamStruct* params) {
114 std::cout << "Apply eSLIM (timeout: " << params->timeout << ") ";
115 if (params->apply_inprocessing) {
116 std::cout << "+ deepsyn (timeout: " << params->timeout_inprocessing << ") ";
117 }
118 std::cout << params->nruns << " times.\n";
119 if (params->iterations > 0) {
120 std::cout << "Stop eSLIM runs after " << params->iterations << " iterations.\n";
121 }
122 std::cout << "Consider subcircuits with up to " << params->subcircuit_size_bound << " gates.\n";
123 printf("When expanding subcircuits, select gates with a probability of %.2f %%.\n", 100 * params->expansion_probability);
124 if (params->forbidden_pairs) {
125 std::cout << "Consider subcircuits containing gates, which are connected outside of the subcircuit.\n";
126 }
127 if (params->mode == 0) {
128 std::cout << "Use an incremental SAT encoding for exact synthesis and the SAT solver CaDiCaL.\n";
129 } else {
130 std::cout << "Use a one-shot SAT encoding for exact synthesis and the SAT solver Kissat.\n";
131 }
132}
133
136 config.verbosity_level = params->verbosity_level;
137
138 int eSLIM_reductions = 0;
139 int deepsyn_reductions = 0;
140
141 Gia_Man_t * pThis = Gia_ManDup(pGia);
142 eSLIM::eSLIMLog log(params->subcircuit_size_bound);
143 int initial_size = Gia_ManAndNum(pThis);
144 if (params->verbosity_level > 0) {
145 printSetting(params);
146 std::cout << "Initial size: " << initial_size << "\n";
147 }
148 for (unsigned int i = 0; i < params->nruns; i++) {
149 if (config.fix_seed) {
150 config.seed = params->seed + i;
151 }
152 int size_iteration_start = Gia_ManAndNum(pThis);
153 if (params->verbosity_level > 0) {
154 std::cout << "Start eslim run " << i + 1 << "\n";
155 }
156 pThis = selectApproach(pThis, config, log, params->mode, params->forbidden_pairs);
157 int size_eslim = Gia_ManAndNum(pThis);
158 eSLIM_reductions += size_iteration_start - size_eslim;
159
160 if (params->apply_inprocessing) {
161 if (params->verbosity_level > 0) {
162 std::cout << "Start inprocessing run " << i + 1 << "\n";
163 }
164 pThis = runInprocessing(pThis, params, i);
165 if (params->verbosity_level > 0) {
166 std::cout << "Inprocessing: Initial size: " << size_eslim << " final size: " << Gia_ManAndNum(pThis) << "\n";
167 }
168 deepsyn_reductions += size_eslim - Gia_ManAndNum(pThis);
169 }
170 }
171 if (params->verbosity_level > 0) {
172 int final_size = Gia_ManAndNum(pThis);
173 std::cout << "Final size: " << final_size << "\n";
174 int total_reductions = eSLIM_reductions + deepsyn_reductions;
175 double reduction_ratio = 100 * static_cast<double>(total_reductions) / initial_size;
176 printf("Total reduction: %d (%.2f %%)\n", total_reductions, reduction_ratio);
177 if (params->apply_inprocessing) {
178 std::cout << "#Gates reduced by eSLIM: " << eSLIM_reductions << " ";
179 std::cout << "#Gates reduced by deepsyn: " << deepsyn_reductions << "\n";
180 }
181 }
182
183 if (params->verbosity_level > 1) {
184 std::cout << "Total #iterations: " << log.iteration_count << "\n";
185 std::cout << "Total relation generation time (s): " << log.relation_generation_time << "\n";
186 std::cout << "Total synthesis time (s): " << log.synthesis_time << "\n";
187 std::cout << "#Iterations with forbidden pairs: " << log.subcircuits_with_forbidden_pairs << "\n";
188 }
189 if (params->verbosity_level > 2) {
190 for (int i = 2; i < log.nof_analyzed_circuits_per_size.size(); i++) {
191 int replaced = log.nof_replaced_circuits_per_size.size() > i ? log.nof_replaced_circuits_per_size[i] : 0;
192 int reduced = log.nof_reduced_circuits_per_size.size() > i ? log.nof_reduced_circuits_per_size[i] : 0;
193 std::cout << "#gates: " << i << " - #analysed: " << log.nof_analyzed_circuits_per_size[i] << " - #replaced: " << replaced << " - #reduced: " << reduced << "\n";
194 }
195 if (params->mode == 0) {
196 for (int i = 0; i < log.nof_sat_calls_per_size.size(); i++) {
197 if (log.nof_sat_calls_per_size[i] == 0) {
198 std::cout << "#gates: " << i << " - avg. sat time: -\n";
199 } else {
200 std::cout << "#gates: " << i << " - avg. sat time: " << static_cast<double>(log.cummulative_sat_runtimes_per_size[i]) / (1000 * log.nof_sat_calls_per_size[i]) << " sec\n";
201 }
202 }
203 for (int i = 0; i < log.nof_unsat_calls_per_size.size(); i++) {
204 if (log.nof_unsat_calls_per_size[i] == 0) {
205 std::cout << "#gates: " << i << " - avg. unsat time: -\n";
206 } else {
207 std::cout << "#gates: " << i << " - avg. unsat time: " << static_cast<double>(log.cummulative_unsat_runtimes_per_size[i]) / (1000* log.nof_unsat_calls_per_size[i]) << " sec\n";
208 }
209 }
210 }
211 }
212 return pThis;
213}
214
#define ABC_INFINITY
MACRO DEFINITIONS ///.
Definition abc_global.h:250
#define ABC_NAMESPACE_IMPL_START
#define ABC_NAMESPACE_IMPL_END
#define ABC_NAMESPACE_HEADER_END
#define ABC_NAMESPACE_HEADER_START
NAMESPACES ///.
static Gia_Man_t * applyeSLIM(Gia_Man_t *p, const eSLIMConfig &cfg, eSLIMLog &log)
struct config_s config
void seteSLIMParams(eSLIM_ParamStruct *params)
Definition eSLIM.cpp:54
void printSetting(const eSLIM_ParamStruct *params)
Definition eSLIM.cpp:113
ABC_NAMESPACE_HEADER_END ABC_NAMESPACE_IMPL_START eSLIM::eSLIMConfig getCfg(const eSLIM_ParamStruct *params)
Definition eSLIM.cpp:36
ABC_NAMESPACE_HEADER_START Gia_Man_t * Gia_ManDeepSyn(Gia_Man_t *pGia, int nIters, int nNoImpr, int TimeOut, int nAnds, int Seed, int fUseTwo, int fVerbose)
Definition giaDeep.c:142
Gia_Man_t * applyeSLIM(Gia_Man_t *pGia, const eSLIM_ParamStruct *params)
Definition eSLIM.cpp:134
Gia_Man_t * runInprocessing(Gia_Man_t *pGia, const eSLIM_ParamStruct *params, unsigned int it)
Definition eSLIM.cpp:102
Gia_Man_t * selectApproach(Gia_Man_t *pGia, eSLIM::eSLIMConfig params, eSLIM::eSLIMLog &log, int approach, bool allow_forbidden_pairs)
Definition eSLIM.cpp:75
typedefABC_NAMESPACE_HEADER_START struct eSLIM_ParamStruct_ eSLIM_ParamStruct
Definition eSLIM.h:29
void Gia_ManStop(Gia_Man_t *p)
Definition giaMan.c:82
Gia_Man_t * Gia_ManDup(Gia_Man_t *p)
Definition giaDup.c:720
struct Gia_Man_t_ Gia_Man_t
Definition gia.h:96
std::vector< int > nof_sat_calls_per_size
Definition utils.hpp:72
std::vector< int > nof_reduced_circuits_per_size
Definition utils.hpp:69
std::vector< int > nof_unsat_calls_per_size
Definition utils.hpp:74
unsigned int iteration_count
Definition utils.hpp:62
std::vector< ABC_UINT64_T > cummulative_sat_runtimes_per_size
Definition utils.hpp:71
double synthesis_time
Definition utils.hpp:64
std::vector< int > nof_replaced_circuits_per_size
Definition utils.hpp:68
double relation_generation_time
Definition utils.hpp:63
std::vector< int > nof_analyzed_circuits_per_size
Definition utils.hpp:67
std::vector< ABC_UINT64_T > cummulative_unsat_runtimes_per_size
Definition utils.hpp:73
unsigned int subcircuits_with_forbidden_pairs
Definition utils.hpp:65
#define assert(ex)
Definition util_old.h:213