From e09d26060b103758cdba16ea90469eb68452e8bc Mon Sep 17 00:00:00 2001 From: amin1377 Date: Fri, 13 Dec 2024 16:20:02 -0500 Subject: [PATCH 1/5] [vpr][place] raise error when read/write of simple place delay model is called --- vpr/src/place/place_delay_model.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/vpr/src/place/place_delay_model.cpp b/vpr/src/place/place_delay_model.cpp index 4f626a5817..c1983570be 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); } From b85b8b64b5957c62bd94539462ab46856984b653 Mon Sep 17 00:00:00 2001 From: amin1377 Date: Fri, 13 Dec 2024 16:36:39 -0500 Subject: [PATCH 2/5] [vpr][place] remove empty impl for read/write simple delay model --- vpr/src/place/place_delay_model.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/vpr/src/place/place_delay_model.h b/vpr/src/place/place_delay_model.h index 0aa01385e6..a4ae0142ef 100644 --- a/vpr/src/place/place_delay_model.h +++ b/vpr/src/place/place_delay_model.h @@ -243,8 +243,8 @@ 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; private: /** From 8b9e623280d338d5d4b0d10f57c4fffb8a94f5bd Mon Sep 17 00:00:00 2001 From: amin1377 Date: Fri, 13 Dec 2024 16:39:03 -0500 Subject: [PATCH 3/5] [vpr][place] add capnproto impl for simple place delay model --- vpr/src/place/place_delay_model.cpp | 58 +++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) diff --git a/vpr/src/place/place_delay_model.cpp b/vpr/src/place/place_delay_model.cpp index c1983570be..f35e833427 100644 --- a/vpr/src/place/place_delay_model.cpp +++ b/vpr/src/place/place_delay_model.cpp @@ -206,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 use must supply the matrix dimension (2 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 is the generate 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. From 66c5c7243fea69c4cc7a17fce7bfc3b529c6c074 Mon Sep 17 00:00:00 2001 From: amin1377 Date: Fri, 13 Dec 2024 16:41:38 -0500 Subject: [PATCH 4/5] [vpr][place] add delays to simple place model --- vpr/src/place/place_delay_model.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/vpr/src/place/place_delay_model.h b/vpr/src/place/place_delay_model.h index a4ae0142ef..a1794485d9 100644 --- a/vpr/src/place/place_delay_model.h +++ b/vpr/src/place/place_delay_model.h @@ -245,6 +245,9 @@ class SimpleDelayModel : public PlaceDelayModel { void read(const std::string& /*file*/) override; void write(const std::string& /*file*/) const override; + const vtr::NdMatrix& delays() const { + return delays_; + } private: /** From 6b597f4f21e826302a32d9e37f0163b9351b1774 Mon Sep 17 00:00:00 2001 From: amin1377 Date: Mon, 16 Dec 2024 11:54:38 -0500 Subject: [PATCH 5/5] [vpr][place] apply Vaughn's comments --- vpr/src/place/place_delay_model.cpp | 4 ++-- vpr/src/place/place_delay_model.h | 12 ++++++++++++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/vpr/src/place/place_delay_model.cpp b/vpr/src/place/place_delay_model.cpp index f35e833427..4cbf5be1b6 100644 --- a/vpr/src/place/place_delay_model.cpp +++ b/vpr/src/place/place_delay_model.cpp @@ -235,7 +235,7 @@ void SimpleDelayModel::read(const std::string& file) { // ToNdMatrix is a generic function for converting a Matrix capnproto // to a vtr::NdMatrix. // - // The use must supply the matrix dimension (2 in this case), the source + // 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). @@ -246,7 +246,7 @@ void SimpleDelayModel::read(const std::string& file) { } void SimpleDelayModel::write(const std::string& file) const { - // MallocMessageBuilder object is the generate capnproto message builder, + // MallocMessageBuilder object generates capnproto message builder, // using malloc for buffer allocation. ::capnp::MallocMessageBuilder builder; diff --git a/vpr/src/place/place_delay_model.h b/vpr/src/place/place_delay_model.h index a1794485d9..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, @@ -245,6 +254,9 @@ class SimpleDelayModel : public PlaceDelayModel { 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_; }