File size: 7,273 Bytes
5cdf637
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
// SPDX-License-Identifier: BSD-3-Clause
// Copyright (c) 2020-2025, The OpenROAD Authors

%{
#include "ord/OpenRoad.hh"
#include "gpl/Replace.h"
#include "odb/db.h"
#include "utl/options.h"

namespace ord {
OpenRoad*
getOpenRoad();

gpl::Replace*
getReplace();
}

static gpl::PlaceOptions getOptions(
    const std::map<std::string, std::string>& keys,
    const std::map<std::string, std::string>& flags)
{
  using utl::checkFlag;
  using utl::checkKey;

  gpl::PlaceOptions options;
  checkFlag(flags, "-timing_driven", options.timingDrivenMode);
  checkFlag(flags, "-timing_driven_repair_timing", options.timingDrivenRepairTiming);
  checkFlag(flags, "-routability_driven", options.routabilityDrivenMode);
  checkFlag(flags, "-virtual_cts", options.virtualCtsMode);
  checkFlag(flags, "-routability_use_grt", options.routabilityUseRudy, false);
  checkFlag(
      flags, "-disable_revert_if_diverge", options.disableRevertIfDiverge);
  checkFlag(
      flags, "-disable_pin_density_adjust", options.disablePinDensityAdjust);
  checkFlag(
      flags, "-enable_routing_congestion", options.enable_routing_congestion);
  checkFlag(flags, "-force_center_initial_place", options.forceCenterInitialPlace);
  checkFlag(flags, "-skip_initial_place", [&](bool) {
    options.initialPlaceMaxIter = 0;
  });
  checkKey(keys, "-initial_place_max_iter", options.initialPlaceMaxIter);
  checkKey(keys, "-initial_place_max_fanout", options.initialPlaceMaxFanout);
  checkKey(
      keys, "-routability_check_overflow", options.routabilityCheckOverflow);
  checkKey(
      keys,
      "-routability_snapshot_overflow",
      options.routabilitySnapshotOverflow);
  checkKey(keys, "-routability_max_density", options.routabilityMaxDensity);
  checkKey(
      keys, "-routability_target_rc_metric", options.routabilityTargetRcMetric);
  checkKey(keys,
           "-routability_inflation_ratio_coef",
           options.routabilityInflationRatioCoef);
  checkKey(keys,
           "-routability_max_inflation_ratio",
           options.routabilityMaxInflationRatio);
  checkKey(keys,
           "-routability_min_congestion_for_inflation",
           options.routabilityMinCongestionForInflation);
  checkKey(keys, "-pad_left", options.padLeft);
  checkKey(keys, "-pad_right", options.padRight);
  checkKey(keys,
           "-routability_rc_coefficients",
           std::tie(options.routabilityRcK1,
                    options.routabilityRcK2,
                    options.routabilityRcK3,
                    options.routabilityRcK4));
  checkKey(keys,
           "-timing_driven_net_reweight_overflow",
           options.timingNetWeightOverflows);
  checkKey(keys, "-overflow", options.overflow);
  checkKey(keys, "-timing_driven_net_weight_max", options.timingNetWeightMax);
  checkKey(
      keys, "-keep_resize_below_overflow", options.keepResizeBelowOverflow);
  checkKey(keys,
           "-virtual_cts_max_skew_fraction",
           options.virtualCtsMaxSkewFraction);
  checkKey(keys, "-timing_driven_nets_percentage", options.timingDrivenNetsPercentage);
  checkKey(keys, "-min_phi_coef", options.minPhiCoef);
  checkKey(keys, "-max_phi_coef", options.maxPhiCoef);
  checkKey(keys, "-init_density_penalty", options.initDensityPenaltyFactor);
  checkKey(keys, "-init_wirelength_coef", options.initWireLengthCoef);
  checkKey(keys, "-reference_hpwl", options.referenceHpwl);
  checkKey(keys,
           "-timing_driven_repair_tns_end_percent",
           options.timingDrivenRepairTnsEndPercent);
  checkKey(keys, "-random_seed", options.initialPlacePerturbationSeed);
  checkKey(keys, "-perturb_dist", options.initialPlacePerturbationDist);

  if (auto it = keys.find("-density"); it != keys.end()) {
    if (it->second == "uniform") {
      options.uniformTargetDensityMode = true;
    } else {
      options.density = std::stof(it->second);
    }
  }
  if (auto it = keys.find("-bin_grid_count"); it != keys.end()) {
    options.binGridCntX = std::stoi(it->second);
    options.binGridCntY = options.binGridCntX;
  }
  checkFlag(flags, "-skip_io", [&](bool) { options.skipIo(); });
  checkFlag(flags, "-place_ios", options.placeIosMode);
  return options;
}

using ord::getOpenRoad;
using ord::getReplace;
using gpl::Replace;

%}

%include "../../options.i"
%import <std_vector.i>
%import "dbtypes.i"
%import "dbenums.i"
%include "../../Exception.i"

%inline %{

void
placement_cluster_cmd(const std::vector<odb::dbInst*>& cluster)
{
  Replace* replace = getReplace();
  replace->addPlacementCluster(cluster);
}

void 
replace_reset_cmd() 
{
  Replace* replace = getReplace();  
  replace->reset();
}

void 
replace_initial_place_cmd(const std::map<std::string, std::string>& keys,
                          const std::map<std::string, std::string>& flags)
{
  gpl::PlaceOptions options = getOptions(keys, flags);

  Replace* replace = getReplace();
  int threads = ord::OpenRoad::openRoad()->getThreadCount();
  replace->doInitialPlace(threads, options);
}

void 
replace_nesterov_place_cmd(const std::map<std::string, std::string>& keys,
                           const std::map<std::string, std::string>& flags)
{
  gpl::PlaceOptions options = getOptions(keys, flags);
  Replace* replace = getReplace();
  int threads = ord::OpenRoad::openRoad()->getThreadCount();
  replace->doNesterovPlace(threads, options);
}


void
replace_run_mbff_cmd(int max_sz, float alpha, float beta, int num_paths,
                     float clock_power_weight)
{
  Replace* replace = getReplace();
  int threads = ord::OpenRoad::openRoad()->getThreadCount();
  replace->runMBFF(max_sz, alpha, beta, threads, num_paths, clock_power_weight);
}


void
replace_incremental_place_cmd(const std::map<std::string, std::string>& keys,
                              const std::map<std::string, std::string>& flags)
{
  gpl::PlaceOptions options = getOptions(keys, flags);
  Replace* replace = getReplace();
  int threads = ord::OpenRoad::openRoad()->getThreadCount();
  replace->doIncrementalPlace(threads, options);
}


float
get_global_placement_uniform_density_cmd(
  const std::map<std::string, std::string>& keys,
  const std::map<std::string, std::string>& flags)
{
  gpl::PlaceOptions options = getOptions(keys, flags);
  Replace* replace = getReplace();
  int threads = ord::OpenRoad::openRoad()->getThreadCount();
  return replace->getUniformTargetDensity(options, threads);
}

void
set_debug_cmd(int pause_iterations,
              int update_iterations,
              bool draw_bins,
              bool initial,
              const char* inst_name,
              int start_iter,
              int start_rudy,
              int rudy_stride,
              bool generate_images,
              const char* images_path)
{
  Replace* replace = getReplace();
  odb::dbInst* inst = nullptr;
  if (inst_name) {
    auto block = ord::OpenRoad::openRoad()->getDb()->getChip()->getBlock();
    inst = block->findInst(inst_name);
  }

  std::string resolved_path = (images_path && *images_path)
                                  ? images_path
                                  : "REPORTS_DIR";

  replace->setDebug(pause_iterations, update_iterations, draw_bins,
                    initial, inst, start_iter, start_rudy, rudy_stride,
                    generate_images, resolved_path);
}

%} // inline