@@ -199,45 +199,25 @@ void OverrideDelayModel::set_base_delay_model(std::unique_ptr<DeltaDelayModel> b
199
199
base_delay_model_ = std::move (base_delay_model_obj);
200
200
}
201
201
202
- /* *
203
- * When writing capnp targetted serialization, always allow compilation when
204
- * VTR_ENABLE_CAPNPROTO=OFF. Generally this means throwing an exception instead.
205
- */
206
- #ifndef VTR_ENABLE_CAPNPROTO
207
- # define DISABLE_ERROR \
208
- " is disable because VTR_ENABLE_CAPNPROTO=OFF." \
209
- " Re-compile with CMake option VTR_ENABLE_CAPNPROTO=ON to enable."
210
-
211
- void OverrideDelayModel::read (const std::string& /* file*/ ) {
212
- VPR_THROW (VPR_ERROR_PLACE, " OverrideDelayModel::read " DISABLE_ERROR);
213
- }
214
-
215
- void OverrideDelayModel::write (const std::string& /* file*/ ) const {
216
- VPR_THROW (VPR_ERROR_PLACE, " OverrideDelayModel::write " DISABLE_ERROR);
217
- }
218
-
219
- #else /* VTR_ENABLE_CAPNPROTO */
220
-
221
- static void ToFloat (float * out, const VprFloatEntry::Reader& in) {
222
- // Getting a scalar field is always "get<field name>()".
223
- *out = in.getValue ();
224
- }
225
-
226
- static void FromFloat (VprFloatEntry::Builder* out, const float & in) {
227
- // Setting a scalar field is always "set<field name>(value)".
228
- out->setValue (in);
229
- }
230
-
231
202
void OverrideDelayModel::read (const std::string& file) {
203
+ #ifndef VTR_ENABLE_CAPNPROTO
204
+ VPR_THROW (VPR_ERROR_PLACE,
205
+ " OverrideDelayModel::read is disabled because VTR_ENABLE_CAPNPROTO=OFF. "
206
+ " Re-compile with CMake option VTR_ENABLE_CAPNPROTO=ON to enable." );
207
+ #else
232
208
MmapFile f (file);
233
209
234
210
/* Increase reader limit to 1G words to allow for large files. */
235
211
::capnp::ReaderOptions opts = default_large_capnp_opts ();
236
212
::capnp::FlatArrayMessageReader reader (f.getData (), opts);
237
213
214
+ auto toFloat = [](float * out, const VprFloatEntry::Reader& in) -> void {
215
+ *out = in.getValue ();
216
+ };
217
+
238
218
vtr::NdMatrix<float , 4 > delays;
239
219
auto model = reader.getRoot <VprOverrideDelayModel>();
240
- ToNdMatrix<4 , VprFloatEntry, float >(&delays, model.getDelays (), ToFloat );
220
+ ToNdMatrix<4 , VprFloatEntry, float >(&delays, model.getDelays (), toFloat );
241
221
242
222
base_delay_model_ = std::make_unique<DeltaDelayModel>(cross_layer_delay_, delays, is_flat_);
243
223
@@ -258,14 +238,24 @@ void OverrideDelayModel::read(const std::string& file) {
258
238
}
259
239
260
240
delay_overrides_ = vtr::make_flat_map2 (std::move (overrides_arr));
241
+ #endif
261
242
}
262
243
263
244
void OverrideDelayModel::write (const std::string& file) const {
245
+ #ifndef VTR_ENABLE_CAPNPROTO
246
+ VPR_THROW (VPR_ERROR_PLACE,
247
+ " OverrideDelayModel::write is disabled because VTR_ENABLE_CAPNPROTO=OFF. "
248
+ " Re-compile with CMake option VTR_ENABLE_CAPNPROTO=ON to enable.\" );
249
+ #else
264
250
::capnp::MallocMessageBuilder builder;
265
251
auto model = builder.initRoot<VprOverrideDelayModel>();
266
252
253
+ auto fromFloat = [](VprFloatEntry::Builder* out, const float& in) -> void {
254
+ out->setValue(in);
255
+ };
256
+
267
257
auto delays = model.getDelays();
268
- FromNdMatrix<4 , VprFloatEntry, float >(&delays, base_delay_model_->delays (), FromFloat );
258
+ FromNdMatrix<4, VprFloatEntry, float>(&delays, base_delay_model_->delays(), fromFloat );
269
259
270
260
// Non-scalar capnproto fields should be first initialized with
271
261
// init<field name>(count), and then accessed from the returned
@@ -285,6 +275,6 @@ void OverrideDelayModel::write(const std::string& file) const {
285
275
}
286
276
287
277
writeMessageToFile(file, &builder);
278
+ #endif
288
279
}
289
280
290
- #endif
0 commit comments