50
50
#include " xls/common/status/status_macros.h"
51
51
#include " xls/data_structures/binary_decision_diagram.h"
52
52
#include " xls/dev_tools/pipeline_metrics.h"
53
+ #include " xls/estimators/area_model/area_estimator.h"
54
+ #include " xls/estimators/area_model/area_estimators.h"
53
55
#include " xls/estimators/delay_model/analyze_critical_path.h"
54
56
#include " xls/estimators/delay_model/delay_estimator.h"
55
57
#include " xls/estimators/delay_model/delay_estimators.h"
@@ -129,6 +131,7 @@ ABSL_FLAG(
129
131
" but at the cost of constraining the schedule and thus increasing area." );
130
132
ABSL_FLAG (bool , enable_resource_sharing, false ,
131
133
" Enable the resource sharing optimization to save area." );
134
+ ABSL_FLAG (std::string, area_model, " " , " Area model name to use from registry." );
132
135
ABSL_FLAG (bool , run_evaluators, true ,
133
136
" Whether to run the JIT and interpreter." );
134
137
ABSL_FLAG (bool , compare_delay_to_synthesis, false ,
@@ -176,7 +179,9 @@ int64_t DurationToMs(absl::Duration duration) {
176
179
177
180
// Run the standard pipeline on the given package and prints stats about the
178
181
// passes and execution time.
179
- absl::Status RunOptimizationAndPrintStats (Package* package) {
182
+ absl::Status RunOptimizationAndPrintStats (Package* package,
183
+ DelayEstimator* delay_estimator,
184
+ AreaEstimator* area_estimator) {
180
185
std::unique_ptr<OptimizationCompoundPass> pipeline =
181
186
CreateOptimizationPassPipeline ();
182
187
@@ -197,6 +202,8 @@ absl::Status RunOptimizationAndPrintStats(Package* package) {
197
202
: std::make_optional (split_next_value_selects);
198
203
pass_options.use_context_narrowing_analysis =
199
204
absl::GetFlag (FLAGS_use_context_narrowing_analysis);
205
+ pass_options.delay_estimator = delay_estimator;
206
+ pass_options.area_estimator = area_estimator;
200
207
PassResults pass_results;
201
208
OptimizationContext context;
202
209
XLS_RETURN_IF_ERROR (
@@ -285,6 +292,18 @@ absl::Status PrintTotalDelay(FunctionBase* f,
285
292
return absl::OkStatus ();
286
293
}
287
294
295
+ absl::Status PrintTotalArea (FunctionBase* f,
296
+ const AreaEstimator& area_estimator) {
297
+ int64_t total_area = 0 ;
298
+ for (Node* node : f->nodes ()) {
299
+ XLS_ASSIGN_OR_RETURN (double op_area,
300
+ area_estimator.GetOperationAreaInSquareMicrons (node));
301
+ total_area += op_area;
302
+ }
303
+ std::cout << absl::StrFormat (" Total area: %.4f um2\n " , total_area);
304
+ return absl::OkStatus ();
305
+ }
306
+
288
307
// Returns the critical-path delay through each pipeline stage.
289
308
absl::StatusOr<std::vector<int64_t >> GetDelayPerStageInPs (
290
309
FunctionBase* f, const PipelineSchedule& schedule,
@@ -695,8 +714,9 @@ absl::Status RunInterpreterAndJit(FunctionBase* function_base,
695
714
696
715
absl::Status AnalyzeAndPrintCriticalPath (
697
716
FunctionBase* f, std::optional<int64_t > effective_clock_period_ps,
698
- const DelayEstimator& delay_estimator, const QueryEngine& query_engine,
699
- PipelineScheduleOrGroup* schedules, synthesis::Synthesizer* synthesizer) {
717
+ const DelayEstimator& delay_estimator, const AreaEstimator* area_estimator,
718
+ const QueryEngine& query_engine, PipelineScheduleOrGroup* schedules,
719
+ synthesis::Synthesizer* synthesizer) {
700
720
XLS_ASSIGN_OR_RETURN (
701
721
std::vector<CriticalPathEntry> critical_path,
702
722
AnalyzeCriticalPath (f, effective_clock_period_ps, delay_estimator));
@@ -718,6 +738,9 @@ absl::Status AnalyzeAndPrintCriticalPath(
718
738
}
719
739
XLS_RETURN_IF_ERROR (PrintCriticalPath (f, query_engine, delay_diff));
720
740
XLS_RETURN_IF_ERROR (PrintTotalDelay (f, delay_estimator));
741
+ if (area_estimator != nullptr ) {
742
+ XLS_RETURN_IF_ERROR (PrintTotalArea (f, *area_estimator));
743
+ }
721
744
return absl::OkStatus ();
722
745
}
723
746
@@ -747,7 +770,19 @@ absl::Status RealMain(std::string_view path) {
747
770
XLS_RETURN_IF_ERROR (
748
771
RunInterpreterAndJit (package->GetTop ().value (), " unoptimized" ));
749
772
}
750
- XLS_RETURN_IF_ERROR (RunOptimizationAndPrintStats (package.get ()));
773
+ DelayEstimator* delay_estimator = nullptr ;
774
+ if (delay_model_flag_passed) {
775
+ XLS_ASSIGN_OR_RETURN (
776
+ delay_estimator,
777
+ GetDelayEstimator (scheduling_options_flags_proto.delay_model ()));
778
+ }
779
+ AreaEstimator* area_estimator = nullptr ;
780
+ if (std::string area_model = absl::GetFlag (FLAGS_area_model);
781
+ !area_model.empty ()) {
782
+ XLS_ASSIGN_OR_RETURN (area_estimator, GetAreaEstimator (area_model));
783
+ }
784
+ XLS_RETURN_IF_ERROR (RunOptimizationAndPrintStats (
785
+ package.get (), delay_estimator, area_estimator));
751
786
752
787
FunctionBase* f = package->GetTop ().value ();
753
788
BddQueryEngine query_engine (BddQueryEngine::kDefaultPathLimit );
@@ -768,15 +803,8 @@ absl::Status RealMain(std::string_view path) {
768
803
100 ;
769
804
}
770
805
}
771
- const DelayEstimator* pdelay_estimator;
772
- if (!delay_model_flag_passed) {
773
- pdelay_estimator = &GetStandardDelayEstimator ();
774
- } else {
775
- XLS_ASSIGN_OR_RETURN (
776
- pdelay_estimator,
777
- GetDelayEstimator (scheduling_options_flags_proto.delay_model ()));
778
- }
779
- const auto & delay_estimator = *pdelay_estimator;
806
+ const DelayEstimator& defaulted_delay_estimator =
807
+ delay_estimator ? *delay_estimator : GetStandardDelayEstimator ();
780
808
std::unique_ptr<synthesis::Synthesizer> synthesizer;
781
809
if (absl::GetFlag (FLAGS_compare_delay_to_synthesis)) {
782
810
synthesis::GrpcSynthesizerParameters parameters (
@@ -794,7 +822,8 @@ absl::Status RealMain(std::string_view path) {
794
822
scheduling_options_flags_proto.pipeline_stages () > 0 ;
795
823
if (!f->IsProc () && !benchmark_codegen) {
796
824
XLS_RETURN_IF_ERROR (AnalyzeAndPrintCriticalPath (
797
- f, effective_clock_period_ps, delay_estimator, query_engine,
825
+ f, effective_clock_period_ps, defaulted_delay_estimator, area_estimator,
826
+ query_engine,
798
827
/* schedules=*/ nullptr , synthesizer.get ()));
799
828
} else if (benchmark_codegen) {
800
829
PipelineScheduleOrGroup schedules = PackagePipelineSchedules ();
@@ -803,17 +832,17 @@ absl::Status RealMain(std::string_view path) {
803
832
SetUpSchedulingOptions (
804
833
scheduling_options_flags_proto, package.get ()));
805
834
absl::Duration scheduling_time;
806
- XLS_ASSIGN_OR_RETURN (schedules,
807
- Schedule (package.get (), scheduling_options,
808
- &delay_estimator , &scheduling_time));
835
+ XLS_ASSIGN_OR_RETURN (
836
+ schedules, Schedule (package.get (), scheduling_options,
837
+ &defaulted_delay_estimator , &scheduling_time));
809
838
std::cout << absl::StreamFormat (" Scheduling time: %dms\n " ,
810
839
scheduling_time / absl::Milliseconds (1 ));
811
840
XLS_RETURN_IF_ERROR (AnalyzeAndPrintCriticalPath (
812
- f, effective_clock_period_ps, delay_estimator, query_engine ,
813
- &schedules, synthesizer.get ()));
841
+ f, effective_clock_period_ps, defaulted_delay_estimator ,
842
+ area_estimator, query_engine, &schedules, synthesizer.get ()));
814
843
815
844
XLS_RETURN_IF_ERROR (PrintScheduleInfo (
816
- f, schedules, query_engine, delay_estimator ,
845
+ f, schedules, query_engine, defaulted_delay_estimator ,
817
846
scheduling_options_flags_proto.has_clock_period_ps ()
818
847
? std::make_optional (
819
848
scheduling_options_flags_proto.clock_period_ps ())
0 commit comments