diff --git a/vpr/src/place/place_delay_model.cpp b/vpr/src/place/place_delay_model.cpp index 4f626a5817..4cbf5be1b6 100644 --- a/vpr/src/place/place_delay_model.cpp +++ b/vpr/src/place/place_delay_model.cpp @@ -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); } @@ -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 + // ::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(); + + // 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::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 returns a X::Builder object that can be used to set the + // fields in the message. + auto model = builder.initRoot(); + + // 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. diff --git a/vpr/src/place/place_delay_model.h b/vpr/src/place/place_delay_model.h index 0aa01385e6..d9df7a18e9 100644 --- a/vpr/src/place/place_delay_model.h +++ b/vpr/src/place/place_delay_model.h @@ -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, @@ -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& delays() const { + return delays_; + } private: /**