Skip to content

Commit f008f72

Browse files
committed
Push hashes up into decor.
1 parent ee037fc commit f008f72

16 files changed

+86
-58
lines changed

arbor/benchmark_cell_group.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ benchmark_cell_group::benchmark_cell_group(const std::vector<cell_gid_type>& gid
4040
for (const auto& c: cells_) {
4141
cg_sources.add_cell();
4242
cg_targets.add_cell();
43-
cg_sources.add_label(c.source, {0, 1});
44-
cg_targets.add_label(c.target, {0, 1});
43+
cg_sources.add_label(internal_hash(c.source), {0, 1});
44+
cg_targets.add_label(internal_hash(c.target), {0, 1});
4545
}
4646

4747
benchmark_cell_group::reset();

arbor/cable_cell.cpp

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ struct cable_cell_impl {
8888
decor decorations;
8989

9090
// The placeable label to lid_range map
91-
dynamic_typed_map<constant_type<std::unordered_multimap<cell_tag_type, lid_range>>::type> labeled_lid_ranges;
91+
dynamic_typed_map<constant_type<std::unordered_multimap<hash_type, lid_range>>::type> labeled_lid_ranges;
9292

9393
cable_cell_impl(const arb::morphology& m, const label_dict& labels, const decor& decorations):
9494
provider(m, labels),
@@ -120,7 +120,7 @@ struct cable_cell_impl {
120120
}
121121

122122
template <typename Item>
123-
void place(const locset& ls, const Item& item, const cell_tag_type& label) {
123+
void place(const locset& ls, const Item& item, const hash_type& label) {
124124
auto& mm = get_location_map(item);
125125
cell_lid_type& lid = placed_count.get<Item>();
126126
cell_lid_type first = lid;
@@ -226,7 +226,8 @@ void cable_cell_impl::init(const decor& d) {
226226
for (const auto& p: d.placements()) {
227227
auto& where = std::get<0>(p);
228228
auto& label = std::get<2>(p);
229-
std::visit([this, &where, &label] (auto&& what) {return this->place(where, what, label);}, std::get<1>(p));
229+
std::visit([this, &where, &label] (auto&& what) {return this->place(where, what, label); },
230+
std::get<1>(p));
230231
}
231232
}
232233

@@ -280,16 +281,21 @@ const cable_cell_parameter_set& cable_cell::default_parameters() const {
280281
return impl_->decorations.defaults();
281282
}
282283

283-
const std::unordered_multimap<cell_tag_type, lid_range>& cable_cell::detector_ranges() const {
284+
const cable_cell::lid_range_map& cable_cell::detector_ranges() const {
284285
return impl_->labeled_lid_ranges.get<threshold_detector>();
285286
}
286287

287-
const std::unordered_multimap<cell_tag_type, lid_range>& cable_cell::synapse_ranges() const {
288+
const cable_cell::lid_range_map& cable_cell::synapse_ranges() const {
288289
return impl_->labeled_lid_ranges.get<synapse>();
289290
}
290291

291-
const std::unordered_multimap<cell_tag_type, lid_range>& cable_cell::junction_ranges() const {
292+
const cable_cell::lid_range_map& cable_cell::junction_ranges() const {
292293
return impl_->labeled_lid_ranges.get<junction>();
293294
}
294295

296+
cell_tag_type decor::tag_of(hash_type hash) const {
297+
if (!hashes_.count(hash)) throw arbor_internal_error{util::pprintf("Unknown hash for {}.", std::to_string(hash))};
298+
return hashes_.at(hash);
299+
}
300+
295301
} // namespace arb

arbor/cable_cell_param.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@
1010
#include <arbor/cable_cell_param.hpp>
1111
#include <arbor/s_expr.hpp>
1212

13+
#include "util/hash.hpp"
1314
#include "util/maputil.hpp"
15+
#include "util/strprintf.hpp"
1416

1517
namespace arb {
1618

@@ -120,7 +122,12 @@ decor& decor::paint(region where, paintable what) {
120122
}
121123

122124
decor& decor::place(locset where, placeable what, cell_tag_type label) {
123-
placements_.emplace_back(std::move(where), std::move(what), std::move(label));
125+
auto hash = internal_hash(label);
126+
if (hashes_.count(hash) && hashes_.at(hash) != label) {
127+
throw arbor_internal_error{util::strprintf("Hash collision {} ./. {}", label, hashes_.at(hash))};
128+
}
129+
placements_.emplace_back(std::move(where), std::move(what), hash);
130+
hashes_.emplace(hash, label);
124131
return *this;
125132
}
126133

arbor/fvm_lowered_cell_impl.hpp

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -313,16 +313,11 @@ fvm_detector_info get_detector_info(arb_size_type max,
313313
}
314314

315315
inline cell_size_type
316-
add_labels(cell_label_range& clr, const std::unordered_multimap<cell_tag_type, lid_range>& ranges) {
316+
add_labels(cell_label_range& clr, const cable_cell::lid_range_map& ranges) {
317317
clr.add_cell();
318318
cell_size_type count = 0;
319319
std::unordered_map<hash_type, cell_tag_type> hashes;
320320
for (const auto& [label, range]: ranges) {
321-
auto hash = internal_hash(label);
322-
if (hashes.count(hash) && hashes.at(hash) != label) {
323-
auto err = util::strprintf("Hash collision {} ~ {} = {}", label, hashes.at(hash), hash);
324-
throw arbor_internal_error{err};
325-
}
326321
clr.add_label(label, range);
327322
count += (range.end - range.begin);
328323
}

arbor/include/arbor/cable_cell.hpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -246,8 +246,8 @@ using cable_cell_location_map = static_typed_map<location_assignment,
246246
synapse, junction, i_clamp, threshold_detector>;
247247

248248
// High-level abstract representation of a cell.
249-
class ARB_SYMBOL_VISIBLE cable_cell {
250-
public:
249+
struct ARB_SYMBOL_VISIBLE cable_cell {
250+
using lid_range_map = std::unordered_multimap<hash_type, lid_range>;
251251
using index_type = cell_lid_type;
252252
using size_type = cell_local_size_type;
253253
using value_type = double;
@@ -311,9 +311,9 @@ class ARB_SYMBOL_VISIBLE cable_cell {
311311
const cable_cell_parameter_set& default_parameters() const;
312312

313313
// The labeled lid_ranges of sources, targets and gap_junctions on the cell;
314-
const std::unordered_multimap<cell_tag_type, lid_range>& detector_ranges() const;
315-
const std::unordered_multimap<cell_tag_type, lid_range>& synapse_ranges() const;
316-
const std::unordered_multimap<cell_tag_type, lid_range>& junction_ranges() const;
314+
const lid_range_map& detector_ranges() const;
315+
const lid_range_map& synapse_ranges() const;
316+
const lid_range_map& junction_ranges() const;
317317

318318
private:
319319
std::unique_ptr<cable_cell_impl, void (*)(cable_cell_impl*)> impl_;

arbor/include/arbor/cable_cell_param.hpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -313,8 +313,9 @@ struct ARB_ARBOR_API cable_cell_parameter_set {
313313
// are to be applied to a morphology in a cable_cell.
314314
class ARB_ARBOR_API decor {
315315
std::vector<std::pair<region, paintable>> paintings_;
316-
std::vector<std::tuple<locset, placeable, cell_tag_type>> placements_;
316+
std::vector<std::tuple<locset, placeable, hash_type>> placements_;
317317
cable_cell_parameter_set defaults_;
318+
std::unordered_map<hash_type, cell_tag_type> hashes_;
318319

319320
public:
320321
const auto& paintings() const {return paintings_; }
@@ -324,6 +325,8 @@ class ARB_ARBOR_API decor {
324325
decor& paint(region, paintable);
325326
decor& place(locset, placeable, cell_tag_type);
326327
decor& set_default(defaultable);
328+
329+
cell_tag_type tag_of(hash_type) const;
327330
};
328331

329332
ARB_ARBOR_API extern cable_cell_parameter_set neuron_parameter_defaults;

arbor/include/arbor/common_types.hpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@
1919

2020
namespace arb {
2121

22+
// Internal hashes use this 64bit id
23+
24+
using hash_type = std::uint64_t;
25+
2226
// For identifying cells globally.
2327

2428
using cell_gid_type = std::uint32_t;

arbor/include/arbor/cv_policy.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@
5959

6060
namespace arb {
6161

62-
class cable_cell;
62+
struct cable_cell;
6363

6464
struct cv_policy_base {
6565
virtual locset cv_boundary_points(const cable_cell& cell) const = 0;

arbor/label_resolution.cpp

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,21 @@ cell_label_range::cell_label_range(std::vector<cell_size_type> size_vec,
2626
arb_assert(check_invariant());
2727
};
2828

29+
cell_label_range::cell_label_range(std::vector<cell_size_type> size_vec,
30+
std::vector<hash_type> label_vec,
31+
std::vector<lid_range> range_vec):
32+
sizes(std::move(size_vec)), labels(std::move(label_vec)), ranges(std::move(range_vec))
33+
{
34+
arb_assert(check_invariant());
35+
};
36+
37+
2938
void cell_label_range::add_cell() { sizes.push_back(0); }
3039

31-
void cell_label_range::add_label(cell_tag_type label, lid_range range) {
40+
void cell_label_range::add_label(hash_type label, lid_range range) {
3241
if (sizes.empty()) throw arbor_internal_error("adding label to cell_label_range without cell");
3342
++sizes.back();
34-
labels.push_back(internal_hash(label));
43+
labels.push_back(label);
3544
ranges.push_back(std::move(range));
3645
}
3746

arbor/label_resolution.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,11 @@ struct ARB_ARBOR_API cell_label_range {
2727
cell_label_range& operator=(cell_label_range&&) = default;
2828

2929
cell_label_range(std::vector<cell_size_type> size_vec, std::vector<cell_tag_type> label_vec, std::vector<lid_range> range_vec);
30+
cell_label_range(std::vector<cell_size_type> size_vec, std::vector<hash_type> label_vec, std::vector<lid_range> range_vec);
3031

3132
void add_cell();
3233

33-
void add_label(cell_tag_type label, lid_range range);
34+
void add_label(hash_type label, lid_range range);
3435

3536
void append(cell_label_range other);
3637

0 commit comments

Comments
 (0)