Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simple Place Delay Model Read/Write #2844

Merged
merged 8 commits into from
Dec 16, 2024
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*/) {
vaughnbetz marked this conversation as resolved.
Show resolved Hide resolved
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 {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any reasonable n why this is always a template parameter of 5 rather than a passed one n template parameter?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doxygen comment would be good.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The underlying array that stores the delay is a 5D array, and its dimension size remains constant across all instances of this class. So, I don’t think we need to pass a template parameter for it.

return delays_;
}

private:
/**
Expand Down
Loading