Skip to content

Commit 231438e

Browse files
authored
Merge pull request #2844 from verilog-to-routing/read_write_simple_lookahead
Simple Place Delay Model Read/Write
2 parents ce706d5 + 6b597f4 commit 231438e

File tree

2 files changed

+83
-2
lines changed

2 files changed

+83
-2
lines changed

vpr/src/place/place_delay_model.cpp

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,14 @@ float SimpleDelayModel::delay(const t_physical_tile_loc& from_loc, int /*from_pi
170170
"is disable because VTR_ENABLE_CAPNPROTO=OFF." \
171171
"Re-compile with CMake option VTR_ENABLE_CAPNPROTO=ON to enable."
172172

173+
void SimpleDelayModel::read(const std::string& /*file*/) {
174+
VPR_THROW(VPR_ERROR_PLACE, "SimpleDelayModel::read " DISABLE_ERROR);
175+
}
176+
177+
void SimpleDelayModel::write(const std::string& /*file*/) const {
178+
VPR_THROW(VPR_ERROR_PLACE, "SimpleDelayModel::write " DISABLE_ERROR);
179+
}
180+
173181
void DeltaDelayModel::read(const std::string& /*file*/) {
174182
VPR_THROW(VPR_ERROR_PLACE, "DeltaDelayModel::read " DISABLE_ERROR);
175183
}
@@ -198,6 +206,64 @@ static void FromFloat(VprFloatEntry::Builder* out, const float& in) {
198206
out->setValue(in);
199207
}
200208

209+
void SimpleDelayModel::read(const std::string& file) {
210+
// MmapFile object creates an mmap of the specified path, and will munmap
211+
// when the object leaves scope.
212+
MmapFile f(file);
213+
214+
/* Increase reader limit to 1G words to allow for large files. */
215+
::capnp::ReaderOptions opts = default_large_capnp_opts();
216+
217+
// FlatArrayMessageReader is used to read the message from the data array
218+
// provided by MmapFile.
219+
::capnp::FlatArrayMessageReader reader(f.getData(), opts);
220+
221+
// When reading capnproto files the Reader object to use is named
222+
// <schema name>::Reader.
223+
//
224+
// Initially this object is an empty VprDeltaDelayModel.
225+
VprDeltaDelayModel::Reader model;
226+
227+
// The reader.getRoot performs a cast from the generic capnproto to fit
228+
// with the specified schema.
229+
//
230+
// Note that capnproto does not validate that the incoming data matches the
231+
// schema. If this property is required, some form of check would be
232+
// required.
233+
model = reader.getRoot<VprDeltaDelayModel>();
234+
235+
// ToNdMatrix is a generic function for converting a Matrix capnproto
236+
// to a vtr::NdMatrix.
237+
//
238+
// The user must supply the matrix dimension (5 in this case), the source
239+
// capnproto type (VprFloatEntry),
240+
// target C++ type (flat), and a function to convert from the source capnproto
241+
// type to the target C++ type (ToFloat).
242+
//
243+
// The second argument should be of type Matrix<X>::Reader where X is the
244+
// capnproto element type.
245+
ToNdMatrix<5, VprFloatEntry, float>(&delays_, model.getDelays(), ToFloat);
246+
}
247+
248+
void SimpleDelayModel::write(const std::string& file) const {
249+
// MallocMessageBuilder object generates capnproto message builder,
250+
// using malloc for buffer allocation.
251+
::capnp::MallocMessageBuilder builder;
252+
253+
// initRoot<X> returns a X::Builder object that can be used to set the
254+
// fields in the message.
255+
auto model = builder.initRoot<VprDeltaDelayModel>();
256+
257+
// FromNdMatrix is a generic function for converting a vtr::NdMatrix to a
258+
// Matrix message. It is the mirror function of ToNdMatrix described in
259+
// read above.
260+
auto delay_values = model.getDelays();
261+
FromNdMatrix<5, VprFloatEntry, float>(&delay_values, delays_, FromFloat);
262+
263+
// writeMessageToFile writes message to the specified file.
264+
writeMessageToFile(file, &builder);
265+
}
266+
201267
void DeltaDelayModel::read(const std::string& file) {
202268
// MmapFile object creates an mmap of the specified path, and will munmap
203269
// when the object leaves scope.

vpr/src/place/place_delay_model.h

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,15 @@ class SimpleDelayModel : public PlaceDelayModel {
235235
public:
236236
SimpleDelayModel() {}
237237

238+
/**
239+
* @brief Initializes the `delays_` data structure. This involves retrieving the corresponding delays for each entry from
240+
* the router lookahead and storing the minimum among them.
241+
*
242+
* @param router The router used to retrieve information from the router lookahead.
243+
* @param placer_opts Placment parameters.
244+
* @param router_opts Routing parameters.
245+
* @param longest_length The length of the longest routing track.
246+
*/
238247
void compute(
239248
RouterDelayProfiler& router,
240249
const t_placer_opts& placer_opts,
@@ -243,8 +252,14 @@ class SimpleDelayModel : public PlaceDelayModel {
243252
float delay(const t_physical_tile_loc& from_loc, int /*from_pin*/, const t_physical_tile_loc& to_loc, int /*to_pin*/) const override;
244253
void dump_echo(std::string /*filepath*/) const override {}
245254

246-
void read(const std::string& /*file*/) override {}
247-
void write(const std::string& /*file*/) const override {}
255+
void read(const std::string& /*file*/) override;
256+
void write(const std::string& /*file*/) const override;
257+
/**
258+
@brief Returns a reference to the array containing the placement delay matrix.
259+
*/
260+
const vtr::NdMatrix<float, 5>& delays() const {
261+
return delays_;
262+
}
248263

249264
private:
250265
/**

0 commit comments

Comments
 (0)