Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into perf/kikis-delivery…
Browse files Browse the repository at this point in the history
…-service
  • Loading branch information
thorstenhater committed Oct 30, 2023
2 parents a121c4e + 9312a4a commit 149af9c
Show file tree
Hide file tree
Showing 71 changed files with 925 additions and 789 deletions.
7 changes: 7 additions & 0 deletions arbor/arbexcept.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,13 @@ bad_cell_probe::bad_cell_probe(cell_kind kind, cell_gid_type gid):
kind(kind)
{}

dup_cell_probe::dup_cell_probe(cell_kind kind, cell_gid_type gid, cell_tag_type tag):
arbor_exception(pprintf("Probe tag {} duplicated for cell gid {} of kind {}.", tag, gid, kind)),
gid(gid),
kind(kind),
tag(std::move(tag))
{}

bad_cell_description::bad_cell_description(cell_kind kind, cell_gid_type gid):
arbor_exception(pprintf("recipe::get_cell_kind(gid={}) -> {} does not match the cell type provided by recipe::get_cell_description(gid={})", gid, kind, gid)),
gid(gid),
Expand Down
72 changes: 32 additions & 40 deletions arbor/cable_cell_group.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@
namespace arb {

cable_cell_group::cable_cell_group(const std::vector<cell_gid_type>& gids,
const recipe& rec,
cell_label_range& cg_sources,
cell_label_range& cg_targets,
fvm_lowered_cell_ptr lowered):
const recipe& rec,
cell_label_range& cg_sources,
cell_label_range& cg_targets,
fvm_lowered_cell_ptr lowered):
gids_(gids), lowered_(std::move(lowered))
{
// Build lookup table for gid to local index.
Expand Down Expand Up @@ -82,8 +82,7 @@ void cable_cell_group::reset() {

struct sampler_call_info {
sampler_function sampler;
cell_member_type probeset_id;
probe_tag tag;
cell_address_type probeset_id;
unsigned index;
const fvm_probe_data* pdata_ptr;

Expand All @@ -93,9 +92,9 @@ struct sampler_call_info {
};

void cable_cell_group::t_serialize(serializer& ser,
const std::string& k) const { serialize(ser, k, *this); }
const std::string& k) const { serialize(ser, k, *this); }
void cable_cell_group::t_deserialize(serializer& ser,
const std::string& k) { deserialize(ser, k, *this); }
const std::string& k) { deserialize(ser, k, *this); }

// Working space for computing and collating data for samplers.
using fvm_probe_scratch = std::tuple<std::vector<double>, std::vector<cable_sample_range>>;
Expand Down Expand Up @@ -144,7 +143,7 @@ void run_samples(
sample_records.push_back(sample_record{time_type(raw_times[i]), &raw_samples[i]});
}

sc.sampler({sc.probeset_id, sc.tag, sc.index, p.get_metadata_ptr()}, n_sample, sample_records.data());
sc.sampler({sc.probeset_id, sc.index, p.get_metadata_ptr()}, n_sample, sample_records.data());
}

void run_samples(
Expand Down Expand Up @@ -174,7 +173,7 @@ void run_samples(
sample_records.push_back(sample_record{time_type(raw_times[offset]), &ctmp[j]});
}

sc.sampler({sc.probeset_id, sc.tag, sc.index, p.get_metadata_ptr()}, n_sample, sample_records.data());
sc.sampler({sc.probeset_id, sc.index, p.get_metadata_ptr()}, n_sample, sample_records.data());
}

void run_samples(
Expand Down Expand Up @@ -204,7 +203,7 @@ void run_samples(
sample_records.push_back(sample_record{time_type(raw_times[offset]), &csample_ranges[j]});
}

sc.sampler({sc.probeset_id, sc.tag, sc.index, p.get_metadata_ptr()}, n_sample, sample_records.data());
sc.sampler({sc.probeset_id, sc.index, p.get_metadata_ptr()}, n_sample, sample_records.data());
}

void run_samples(
Expand Down Expand Up @@ -247,7 +246,7 @@ void run_samples(
sample_records.push_back(sample_record{time_type(raw_times[offset]), &csample_ranges[j]});
}

sc.sampler({sc.probeset_id, sc.tag, sc.index, p.get_metadata_ptr()}, n_sample, sample_records.data());
sc.sampler({sc.probeset_id, sc.index, p.get_metadata_ptr()}, n_sample, sample_records.data());
}

void run_samples(
Expand Down Expand Up @@ -294,7 +293,7 @@ void run_samples(
sample_records.push_back(sample_record{time_type(raw_times[offset]), &csample_ranges[j]});
}

sc.sampler({sc.probeset_id, sc.tag, sc.index, p.get_metadata_ptr()}, n_sample, sample_records.data());
sc.sampler({sc.probeset_id, sc.index, p.get_metadata_ptr()}, n_sample, sample_records.data());
}

void run_samples(
Expand Down Expand Up @@ -368,7 +367,7 @@ void run_samples(
sample_records.push_back(sample_record{time_type(raw_times[offset]), &csample_ranges[j]});
}

sc.sampler({sc.probeset_id, sc.tag, sc.index, p.get_metadata_ptr()}, n_sample, sample_records.data());
sc.sampler({sc.probeset_id, sc.index, p.get_metadata_ptr()}, n_sample, sample_records.data());
}

// Generic run_samples dispatches on probe info variant type.
Expand Down Expand Up @@ -453,23 +452,21 @@ void cable_cell_group::advance(epoch ep, time_type dt, const event_lane_subrange
sample_size_type n_times = sample_times.size();
if (n_times == 0) continue;
max_samples_per_call = std::max(max_samples_per_call, n_times);
for (const cell_member_type& pid: sa.probeset_ids) {
probe_tag tag = probe_map_.tag.at(pid);
for (const auto& pid: sa.probeset_ids) {
unsigned index = 0;
for (const fvm_probe_data& pdata: probe_map_.data_on(pid)) {
for (const auto& pdata: probe_map_.data_on(pid)) {
call_info.push_back({sa.sampler,
pid,
tag,
index,
&pdata,
pdata,
n_samples,
n_samples + n_times*pdata.n_raw()});
n_samples + n_times*pdata->n_raw()});
index++;
for (auto t: sample_times) {
auto it = timesteps_.find(t);
arb_assert(it != timesteps_.end());
const auto timestep_index = it - timesteps_.begin();
for (probe_handle h: pdata.raw_handle_range()) {
for (probe_handle h: pdata->raw_handle_range()) {
sample_event ev{t, {h, n_samples++}};
sample_events_[timestep_index].push_back(ev);
}
Expand Down Expand Up @@ -510,16 +507,17 @@ void cable_cell_group::advance(epoch ep, time_type dt, const event_lane_subrange
}
}

void cable_cell_group::add_sampler(sampler_association_handle h, cell_member_predicate probeset_ids,
schedule sched, sampler_function fn)
{
void cable_cell_group::add_sampler(sampler_association_handle h,
cell_member_predicate probeset_ids,
schedule sched,
sampler_function fn) {
// SAFETY? Both probe_map and sampler must be protected by this lock?!
std::lock_guard<std::mutex> guard(sampler_mex_);

std::vector<cell_member_type> probeset =
util::assign_from(util::filter(util::keys(probe_map_.tag), probeset_ids));

auto probeset = probe_map_.keys(probeset_ids);
if (!probeset.empty()) {
auto result = sampler_map_.insert({h, sampler_association{std::move(sched), std::move(fn), std::move(probeset)}});
auto result = sampler_map_.insert({h, sampler_association{std::move(sched),
std::move(fn),
std::move(probeset)}});
arb_assert(result.second);
}
}
Expand All @@ -534,23 +532,17 @@ void cable_cell_group::remove_all_samplers() {
sampler_map_.clear();
}

std::vector<probe_metadata> cable_cell_group::get_probe_metadata(cell_member_type probeset_id) const {
// Probe associations are fixed after construction, so we do not need to grab the mutex.

std::optional<probe_tag> maybe_tag = util::value_by_key(probe_map_.tag, probeset_id);
if (!maybe_tag) {
return {};
}

std::vector<probe_metadata> cable_cell_group::get_probe_metadata(const cell_address_type& probeset_id) const {
// SAFETY: Probe associations are fixed after construction, so we do not
// need to grab the mutex.
auto data = probe_map_.data_on(probeset_id);

std::vector<probe_metadata> result;
result.reserve(data.size());
unsigned index = 0;
for (const fvm_probe_data& item: data) {
result.push_back(probe_metadata{probeset_id, *maybe_tag, index++, item.get_metadata_ptr()});
for (const auto& info: data) {
result.push_back({probeset_id, index++, info->get_metadata_ptr()});
}

return result;
}
} // namespace arb
19 changes: 7 additions & 12 deletions arbor/cable_cell_group.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,9 @@

namespace arb {

class ARB_ARBOR_API cable_cell_group: public cell_group {
public:
cable_cell_group() = default;

struct ARB_ARBOR_API cable_cell_group: public cell_group {
cable_cell_group() = default;
cable_cell_group(const std::vector<cell_gid_type>& gids,
const recipe& rec,
cell_label_range& cg_sources,
Expand All @@ -40,13 +39,9 @@ class ARB_ARBOR_API cable_cell_group: public cell_group {

void advance(epoch ep, time_type dt, const event_lane_subrange& event_lanes) override;

const std::vector<spike>& spikes() const override {
return spikes_;
}
const std::vector<spike>& spikes() const override { return spikes_; }

void clear_spikes() override {
spikes_.clear();
}
void clear_spikes() override { spikes_.clear(); }

void add_sampler(sampler_association_handle h, cell_member_predicate probeset_ids,
schedule sched, sampler_function fn) override;
Expand All @@ -55,12 +50,12 @@ class ARB_ARBOR_API cable_cell_group: public cell_group {

void remove_all_samplers() override;

std::vector<probe_metadata> get_probe_metadata(cell_member_type probeset_id) const override;
std::vector<probe_metadata> get_probe_metadata(const cell_address_type&) const override;

ARB_SERDES_ENABLE(cable_cell_group, gids_, spikes_, lowered_);

virtual void t_serialize(serializer& ser, const std::string& k) const override;
virtual void t_deserialize(serializer& ser, const std::string& k) override;
void t_serialize(serializer& ser, const std::string& k) const override;
void t_deserialize(serializer& ser, const std::string& k) override;
private:
// List of the gids of the cells in the group.
std::vector<cell_gid_type> gids_;
Expand Down
4 changes: 1 addition & 3 deletions arbor/cell_group.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,7 @@ class cell_group {
// Probe metadata queries might also be called while a simulation is running, and so should
// also be thread-safe.

virtual std::vector<probe_metadata> get_probe_metadata(cell_member_type) const {
return {};
}
virtual std::vector<probe_metadata> get_probe_metadata(const cell_address_type&) const { return {}; }
// trampolines for serialization
virtual void t_serialize(serializer& s, const std::string&) const = 0;
virtual void t_deserialize(serializer& s, const std::string&) = 0;
Expand Down
44 changes: 33 additions & 11 deletions arbor/fvm_lowered_cell.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <memory>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#include <variant>
#include <vector>

Expand All @@ -23,8 +24,11 @@
#include "execution_context.hpp"
#include "sampler_map.hpp"
#include "timestep_range.hpp"
#include "util/maputil.hpp"
#include "util/meta.hpp"
#include "util/range.hpp"
#include "util/rangeutil.hpp"
#include "util/strprintf.hpp"
#include "util/transform.hpp"

namespace arb {
Expand Down Expand Up @@ -175,22 +179,40 @@ struct fvm_probe_data {
// map to multiple probe representations within the cable_cell_group.

struct probe_association_map {
// Keys are probe id.
// unique keys from multimap
std::vector<cell_address_type> keys(cell_member_predicate pred=all_probes) const {
std::vector<cell_address_type> res;
std::unordered_set<cell_address_type> seen;
for (const auto& [k, v]: data) {
if (!seen.count(k)) {
if (pred(k)) res.push_back(k);
seen.insert(k);
}
}
return res;
}

std::unordered_map<cell_member_type, probe_tag> tag;
std::unordered_multimap<cell_member_type, fvm_probe_data> data;
auto count(const cell_address_type& k) const { return data.count(k); }

std::size_t size() const {
arb_assert(tag.size()==data.size());
return data.size();
// Return range of fvm_probe_data values associated with probeset_id.
std::vector<const fvm_probe_data*> data_on(const cell_address_type& probeset_id) const {
std::vector<const fvm_probe_data*> res;
const auto& [beg, end] = data.equal_range(probeset_id);
for (auto it = beg; it != end; ++it) {
res.push_back(&it->second);
}
return res;
}

// Return range of fvm_probe_data values associated with probeset_id.
// Trailing return type added here to avoid warnings about ODR violations when building shared
// lib together with LTO - needs to be re-checked in the future
auto data_on(cell_member_type probeset_id) const -> decltype(util::transform_view(util::make_range(data.equal_range(probeset_id)), util::second)) {
return util::transform_view(util::make_range(data.equal_range(probeset_id)), util::second);
probe_association_map& insert(const cell_address_type& k, fvm_probe_data v) {
data.insert({k, std::move(v)});
return *this;
}

std::size_t size() const { return data.size(); }

private:
std::unordered_multimap<cell_address_type, fvm_probe_data> data;
};

struct fvm_initialization_data {
Expand Down
Loading

0 comments on commit 149af9c

Please sign in to comment.