Skip to content

Commit

Permalink
Merge pull request #2844 from verilog-to-routing/read_write_simple_lo…
Browse files Browse the repository at this point in the history
…okahead

Simple Place Delay Model Read/Write
  • Loading branch information
vaughnbetz authored Dec 16, 2024
2 parents ce706d5 + 6b597f4 commit 231438e
Show file tree
Hide file tree
Showing 2 changed files with 83 additions and 2 deletions.
66 changes: 66 additions & 0 deletions vpr/src/place/place_delay_model.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,14 @@ float SimpleDelayModel::delay(const t_physical_tile_loc& from_loc, int /*from_pi
"is disable because VTR_ENABLE_CAPNPROTO=OFF." \
"Re-compile with CMake option VTR_ENABLE_CAPNPROTO=ON to enable."

void SimpleDelayModel::read(const std::string& /*file*/) {
VPR_THROW(VPR_ERROR_PLACE, "SimpleDelayModel::read " DISABLE_ERROR);
}

void SimpleDelayModel::write(const std::string& /*file*/) const {
VPR_THROW(VPR_ERROR_PLACE, "SimpleDelayModel::write " DISABLE_ERROR);
}

void DeltaDelayModel::read(const std::string& /*file*/) {
VPR_THROW(VPR_ERROR_PLACE, "DeltaDelayModel::read " DISABLE_ERROR);
}
Expand Down Expand Up @@ -198,6 +206,64 @@ static void FromFloat(VprFloatEntry::Builder* out, const float& in) {
out->setValue(in);
}

void SimpleDelayModel::read(const std::string& file) {
// MmapFile object creates an mmap of the specified path, and will munmap
// when the object leaves scope.
MmapFile f(file);

/* Increase reader limit to 1G words to allow for large files. */
::capnp::ReaderOptions opts = default_large_capnp_opts();

// FlatArrayMessageReader is used to read the message from the data array
// provided by MmapFile.
::capnp::FlatArrayMessageReader reader(f.getData(), opts);

// When reading capnproto files the Reader object to use is named
// <schema name>::Reader.
//
// Initially this object is an empty VprDeltaDelayModel.
VprDeltaDelayModel::Reader model;

// The reader.getRoot performs a cast from the generic capnproto to fit
// with the specified schema.
//
// Note that capnproto does not validate that the incoming data matches the
// schema. If this property is required, some form of check would be
// required.
model = reader.getRoot<VprDeltaDelayModel>();

// ToNdMatrix is a generic function for converting a Matrix capnproto
// to a vtr::NdMatrix.
//
// The user must supply the matrix dimension (5 in this case), the source
// capnproto type (VprFloatEntry),
// target C++ type (flat), and a function to convert from the source capnproto
// type to the target C++ type (ToFloat).
//
// The second argument should be of type Matrix<X>::Reader where X is the
// capnproto element type.
ToNdMatrix<5, VprFloatEntry, float>(&delays_, model.getDelays(), ToFloat);
}

void SimpleDelayModel::write(const std::string& file) const {
// MallocMessageBuilder object generates capnproto message builder,
// using malloc for buffer allocation.
::capnp::MallocMessageBuilder builder;

// initRoot<X> returns a X::Builder object that can be used to set the
// fields in the message.
auto model = builder.initRoot<VprDeltaDelayModel>();

// FromNdMatrix is a generic function for converting a vtr::NdMatrix to a
// Matrix message. It is the mirror function of ToNdMatrix described in
// read above.
auto delay_values = model.getDelays();
FromNdMatrix<5, VprFloatEntry, float>(&delay_values, delays_, FromFloat);

// writeMessageToFile writes message to the specified file.
writeMessageToFile(file, &builder);
}

void DeltaDelayModel::read(const std::string& file) {
// MmapFile object creates an mmap of the specified path, and will munmap
// when the object leaves scope.
Expand Down
19 changes: 17 additions & 2 deletions vpr/src/place/place_delay_model.h
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,15 @@ class SimpleDelayModel : public PlaceDelayModel {
public:
SimpleDelayModel() {}

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

void read(const std::string& /*file*/) override {}
void write(const std::string& /*file*/) const override {}
void read(const std::string& /*file*/) override;
void write(const std::string& /*file*/) const override;
/**
@brief Returns a reference to the array containing the placement delay matrix.
*/
const vtr::NdMatrix<float, 5>& delays() const {
return delays_;
}

private:
/**
Expand Down

0 comments on commit 231438e

Please sign in to comment.