Skip to content

Commit 5be891c

Browse files
move #ifndef VTR_ENABLE_CAPNPROTO to inside function defs instead of defining them multiple times
1 parent 174b9a4 commit 5be891c

File tree

2 files changed

+33
-52
lines changed

2 files changed

+33
-52
lines changed

vpr/src/place/timing/delay_model/override_delay_model.cpp

Lines changed: 22 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -199,45 +199,25 @@ void OverrideDelayModel::set_base_delay_model(std::unique_ptr<DeltaDelayModel> b
199199
base_delay_model_ = std::move(base_delay_model_obj);
200200
}
201201

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-
231202
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
232208
MmapFile f(file);
233209

234210
/* Increase reader limit to 1G words to allow for large files. */
235211
::capnp::ReaderOptions opts = default_large_capnp_opts();
236212
::capnp::FlatArrayMessageReader reader(f.getData(), opts);
237213

214+
auto toFloat = [](float* out, const VprFloatEntry::Reader& in) -> void {
215+
*out = in.getValue();
216+
};
217+
238218
vtr::NdMatrix<float, 4> delays;
239219
auto model = reader.getRoot<VprOverrideDelayModel>();
240-
ToNdMatrix<4, VprFloatEntry, float>(&delays, model.getDelays(), ToFloat);
220+
ToNdMatrix<4, VprFloatEntry, float>(&delays, model.getDelays(), toFloat);
241221

242222
base_delay_model_ = std::make_unique<DeltaDelayModel>(cross_layer_delay_, delays, is_flat_);
243223

@@ -258,14 +238,24 @@ void OverrideDelayModel::read(const std::string& file) {
258238
}
259239

260240
delay_overrides_ = vtr::make_flat_map2(std::move(overrides_arr));
241+
#endif
261242
}
262243

263244
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
264250
::capnp::MallocMessageBuilder builder;
265251
auto model = builder.initRoot<VprOverrideDelayModel>();
266252
253+
auto fromFloat = [](VprFloatEntry::Builder* out, const float& in) -> void {
254+
out->setValue(in);
255+
};
256+
267257
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);
269259
270260
// Non-scalar capnproto fields should be first initialized with
271261
// init<field name>(count), and then accessed from the returned
@@ -285,6 +275,6 @@ void OverrideDelayModel::write(const std::string& file) const {
285275
}
286276
287277
writeMessageToFile(file, &builder);
278+
#endif
288279
}
289280
290-
#endif

vpr/src/place/timing/delay_model/simple_delay_model.cpp

Lines changed: 11 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -51,26 +51,12 @@ float SimpleDelayModel::delay(const t_physical_tile_loc& from_loc, int /*from_pi
5151
return delays_[from_tile_idx][from_loc.layer_num][to_loc.layer_num][delta_x][delta_y];
5252
}
5353

54-
/**
55-
* When writing capnp targetted serialization, always allow compilation when
56-
* VTR_ENABLE_CAPNPROTO=OFF. Generally this means throwing an exception instead.
57-
*/
54+
void SimpleDelayModel::read(const std::string& file) {
5855
#ifndef VTR_ENABLE_CAPNPROTO
59-
60-
# define DISABLE_ERROR \
61-
"is disable because VTR_ENABLE_CAPNPROTO=OFF." \
62-
"Re-compile with CMake option VTR_ENABLE_CAPNPROTO=ON to enable."
63-
64-
void SimpleDelayModel::read(const std::string& /*file*/) {
65-
VPR_THROW(VPR_ERROR_PLACE, "SimpleDelayModel::read " DISABLE_ERROR);
66-
}
67-
68-
void SimpleDelayModel::write(const std::string& /*file*/) const {
69-
VPR_THROW(VPR_ERROR_PLACE, "SimpleDelayModel::write " DISABLE_ERROR);
70-
}
56+
VPR_THROW(VPR_ERROR_PLACE,
57+
"SimpleDelayModel::read is disabled because VTR_ENABLE_CAPNPROTO=OFF. "
58+
"Re-compile with CMake option VTR_ENABLE_CAPNPROTO=ON to enable.\");
7159
#else
72-
73-
void SimpleDelayModel::read(const std::string& file) {
7460
// MmapFile object creates an mmap of the specified path, and will munmap
7561
// when the object leaves scope.
7662
MmapFile f(file);
@@ -111,9 +97,15 @@ void SimpleDelayModel::read(const std::string& file) {
11197
// The second argument should be of type Matrix<X>::Reader where X is the
11298
// capnproto element type.
11399
ToNdMatrix<5, VprFloatEntry, float>(&delays_, model.getDelays(), toFloat);
100+
#endif
114101
}
115102
116103
void SimpleDelayModel::write(const std::string& file) const {
104+
#ifndef VTR_ENABLE_CAPNPROTO
105+
VPR_THROW(VPR_ERROR_PLACE,
106+
"SimpleDelayModel::write is disabled because VTR_ENABLE_CAPNPROTO=OFF. "
107+
"Re-compile with CMake option VTR_ENABLE_CAPNPROTO=ON to enable.\");
108+
#else
117109
// MallocMessageBuilder object generates capnproto message builder,
118110
// using malloc for buffer allocation.
119111
::capnp::MallocMessageBuilder builder;
@@ -134,6 +126,5 @@ void SimpleDelayModel::write(const std::string& file) const {
134126
135127
// writeMessageToFile writes message to the specified file.
136128
writeMessageToFile(file, &builder);
129+
#endif
137130
}
138-
139-
#endif

0 commit comments

Comments
 (0)