Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimise Memory Consumption during Setup #2005

Closed
Show file tree
Hide file tree
Changes from 9 commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
c00ea33
Only accept recipes.
thorstenhater Oct 17, 2022
cacf3d1
Stop communicator update-connections from concatenating a huge vector.
thorstenhater Oct 19, 2022
16f90ee
Merge remote-tracking branch 'origin/master' into hpc/do-not-make-a-h…
thorstenhater Oct 19, 2022
12c8a2d
Merge remote-tracking branch 'origin/master' into hpc/do-not-make-a-h…
thorstenhater Oct 24, 2022
3d02e95
Merge.
thorstenhater Nov 17, 2022
c99070b
Merge.
thorstenhater Nov 20, 2022
f86c479
Merge remote-tracking branch 'origin/master' into hpc/do-not-make-a-h…
thorstenhater Jan 19, 2023
ca15a1f
Merge remote-tracking branch 'origin/master' into hpc/do-not-make-a-h…
thorstenhater Jan 27, 2023
adbec3c
Fix review commits.
thorstenhater Jan 27, 2023
6273fc0
Remove an obsolete hierarchy.
thorstenhater Jan 31, 2023
29f79e3
Add high-water-mark memory to profiling.
thorstenhater Feb 1, 2023
a90fc04
Add first-seen memory mark and iron out printing.
thorstenhater Feb 1, 2023
bf1e65c
Appease black.
thorstenhater Feb 1, 2023
285a734
Fix and refactor source labels/resolver handling.
thorstenhater Feb 2, 2023
41b6499
Revert ring.cpp.
thorstenhater Feb 13, 2023
dc84213
Nasty merge: binning, fixed-dt, and delivery.
thorstenhater Jun 13, 2023
3816910
More mergen.
thorstenhater Jun 13, 2023
0bda6f8
Make pw_zip_iterator less atrocious.
thorstenhater Jun 14, 2023
4a17c28
Implement region and locset caching.
thorstenhater Jun 15, 2023
b81674a
Add logging new, caching and early deletion for `get_sources`. Memory…
thorstenhater Jun 17, 2023
21b2ade
Add ankerl containers and try them for label resolution.
thorstenhater Jun 17, 2023
58a5f13
Shrink discretisation after building.
thorstenhater Jun 17, 2023
2064268
Make load balance waaaaay simpler at the cost of trivial permutation.
thorstenhater Jun 19, 2023
a71a3be
Modernise mechcat a bit.
thorstenhater Jun 19, 2023
35925b6
Pull out diffusion building.
thorstenhater Jun 19, 2023
a38759c
Move more, copy less.
thorstenhater Jun 19, 2023
ef14746
Get rid of an imediate vector of all GIDs.
thorstenhater Jun 19, 2023
d7802bf
Allow mechcat to return const refs.
thorstenhater Jun 20, 2023
836ef5c
Add memory logger properly.
thorstenhater Jun 20, 2023
a669ae4
Black/Flake
thorstenhater Jun 20, 2023
903d02d
Clean-up map change
thorstenhater Jun 20, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion arbor/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ set(arbor_sources
io/serialize_hex.cpp
label_resolution.cpp
lif_cell_group.cpp
mc_cell_group.cpp
cable_cell_group.cpp
mechcat.cpp
mechinfo.cpp
memory/gpu_wrappers.cpp
Expand Down
17 changes: 10 additions & 7 deletions arbor/benchmark_cell_group.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@

namespace arb {

cell_size_type ARB_ARBOR_API get_sources(cell_label_range& src, const benchmark_cell& c) {
src.add_cell();
src.add_label(c.source, {0, 1});
return 1;
}

benchmark_cell_group::benchmark_cell_group(const std::vector<cell_gid_type>& gids,
const recipe& rec,
cell_label_range& cg_sources,
Expand All @@ -29,14 +35,11 @@ benchmark_cell_group::benchmark_cell_group(const std::vector<cell_gid_type>& gid

cells_.reserve(gids_.size());
for (auto gid: gids_) {
cells_.push_back(util::any_cast<benchmark_cell>(rec.get_cell_description(gid)));
}

for (const auto& c: cells_) {
cg_sources.add_cell();
auto cell = util::any_cast<benchmark_cell>(rec.get_cell_description(gid));
cells_.push_back(cell);
cg_targets.add_cell();
cg_sources.add_label(c.source, {0, 1});
cg_targets.add_label(c.target, {0, 1});
cg_targets.add_label(cell.target, {0, 1});
get_sources(cg_sources, cell);
}

benchmark_cell_group::reset();
Expand Down
2 changes: 2 additions & 0 deletions arbor/benchmark_cell_group.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,7 @@ class benchmark_cell_group: public cell_group {
std::vector<cell_gid_type> gids_;
};

cell_size_type ARB_ARBOR_API get_sources(cell_label_range& src, const benchmark_cell& c);

} // namespace arb

30 changes: 20 additions & 10 deletions arbor/mc_cell_group.cpp → arbor/cable_cell_group.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
#include "event_binner.hpp"
#include "fvm_lowered_cell.hpp"
#include "label_resolution.hpp"
#include "mc_cell_group.hpp"
#include "cable_cell_group.hpp"
#include "profile/profiler_macro.hpp"
#include "sampler_map.hpp"
#include "util/filter.hpp"
Expand All @@ -30,15 +30,25 @@ namespace arb {
ARB_DEFINE_LEXICOGRAPHIC_ORDERING(arb::target_handle,(a.mech_id,a.mech_index,a.intdom_index),(b.mech_id,b.mech_index,b.intdom_index))
ARB_DEFINE_LEXICOGRAPHIC_ORDERING(arb::deliverable_event,(a.time,a.handle,a.weight),(b.time,b.handle,b.weight))

mc_cell_group::mc_cell_group(const std::vector<cell_gid_type>& gids,
cell_size_type ARB_ARBOR_API get_sources(cell_label_range& src, const cable_cell& c) {
src.add_cell();
cell_size_type count = 0;
for (const auto& [label, range]: c.detector_ranges()) {
src.add_label(label, range);
count += range.end - range.begin;
}
return count;
}

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):
gids_(gids), lowered_(std::move(lowered))
{
// Default to no binning of events
mc_cell_group::set_binning_policy(binning_kind::none, 0);
cable_cell_group::set_binning_policy(binning_kind::none, 0);

// Build lookup table for gid to local index.
for (auto i: util::count_along(gids_)) {
Expand Down Expand Up @@ -70,7 +80,7 @@ mc_cell_group::mc_cell_group(const std::vector<cell_gid_type>& gids,
spike_sources_.shrink_to_fit();
}

void mc_cell_group::reset() {
void cable_cell_group::reset() {
spikes_.clear();

for (auto &entry: sampler_map_) {
Expand All @@ -84,7 +94,7 @@ void mc_cell_group::reset() {
lowered_->reset();
}

void mc_cell_group::set_binning_policy(binning_kind policy, time_type bin_interval) {
void cable_cell_group::set_binning_policy(binning_kind policy, time_type bin_interval) {
binners_.clear();
binners_.resize(gids_.size(), event_binner(policy, bin_interval));
}
Expand Down Expand Up @@ -388,7 +398,7 @@ void run_samples(
std::visit([&](auto& x) {run_samples(x, sc, raw_times, raw_samples, sample_records, scratch); }, sc.pdata_ptr->info);
}

void mc_cell_group::advance(epoch ep, time_type dt, const event_lane_subrange& event_lanes) {
void cable_cell_group::advance(epoch ep, time_type dt, const event_lane_subrange& event_lanes) {
time_type tstart = lowered_->time();

// Bin and collate deliverable events from event lanes.
Expand Down Expand Up @@ -554,7 +564,7 @@ void mc_cell_group::advance(epoch ep, time_type dt, const event_lane_subrange& e
}
}

void mc_cell_group::add_sampler(sampler_association_handle h, cell_member_predicate probeset_ids,
void cable_cell_group::add_sampler(sampler_association_handle h, cell_member_predicate probeset_ids,
schedule sched, sampler_function fn, sampling_policy policy)
{
std::lock_guard<std::mutex> guard(sampler_mex_);
Expand All @@ -568,17 +578,17 @@ void mc_cell_group::add_sampler(sampler_association_handle h, cell_member_predic
}
}

void mc_cell_group::remove_sampler(sampler_association_handle h) {
void cable_cell_group::remove_sampler(sampler_association_handle h) {
std::lock_guard<std::mutex> guard(sampler_mex_);
sampler_map_.erase(h);
}

void mc_cell_group::remove_all_samplers() {
void cable_cell_group::remove_all_samplers() {
std::lock_guard<std::mutex> guard(sampler_mex_);
sampler_map_.clear();
}

std::vector<probe_metadata> mc_cell_group::get_probe_metadata(cell_member_type probeset_id) const {
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);
Expand Down
9 changes: 6 additions & 3 deletions arbor/mc_cell_group.hpp → arbor/cable_cell_group.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include <arbor/recipe.hpp>
#include <arbor/sampling.hpp>
#include <arbor/spike.hpp>
#include <arbor/cable_cell.hpp>

#include "backends/event.hpp"
#include "cell_group.hpp"
Expand All @@ -24,11 +25,11 @@

namespace arb {

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

mc_cell_group(const std::vector<cell_gid_type>& gids,
cable_cell_group(const std::vector<cell_gid_type>& gids,
const recipe& rec,
cell_label_range& cg_sources,
cell_label_range& cg_targets,
Expand Down Expand Up @@ -102,4 +103,6 @@ class ARB_ARBOR_API mc_cell_group: public cell_group {
std::vector<std::size_t> target_handle_divisions_;
};

cell_size_type ARB_ARBOR_API get_sources(cell_label_range& src, const cable_cell& c);

} // namespace arb
4 changes: 2 additions & 2 deletions arbor/cell_group_factory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#include "execution_context.hpp"
#include "fvm_lowered_cell.hpp"
#include "lif_cell_group.hpp"
#include "mc_cell_group.hpp"
#include "cable_cell_group.hpp"
#include "spike_source_cell_group.hpp"

namespace arb {
Expand All @@ -27,7 +27,7 @@ ARB_ARBOR_API cell_group_factory cell_kind_implementation(
switch (ck) {
case cell_kind::cable:
return [bk, ctx, seed](const gid_vector& gids, const recipe& rec, cell_label_range& cg_sources, cell_label_range& cg_targets) {
return make_cell_group<mc_cell_group>(gids, rec, cg_sources, cg_targets, make_fvm_lowered_cell(bk, ctx, seed));
return make_cell_group<cable_cell_group>(gids, rec, cg_sources, cg_targets, make_fvm_lowered_cell(bk, ctx, seed));
};

case cell_kind::spike_source:
Expand Down
44 changes: 40 additions & 4 deletions arbor/communication/communicator.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include <utility>
#include <vector>
#include <any>

#include <arbor/assert.hpp>
#include <arbor/common_types.hpp>
Expand All @@ -17,6 +18,10 @@
#include "util/partition.hpp"
#include "util/rangeutil.hpp"
#include "util/span.hpp"
#include "spike_source_cell_group.hpp"
#include "cable_cell_group.hpp"
#include "benchmark_cell_group.hpp"
#include "lif_cell_group.hpp"

#include "communication/communicator.hpp"

Expand All @@ -31,9 +36,31 @@ communicator::communicator(const recipe& rec,
distributed_{ctx.distributed},
thread_pool_{ctx.thread_pool} {}

void communicator::update_connections(const connectivity& rec,
// This is a bit nasty, as we basically reimplement things from all cell kinds ...
cell_label_range get_sources(cell_gid_type gid, const recipe& rec) {
auto cell = rec.get_cell_description(gid);
auto kind = rec.get_cell_kind(gid);
cell_label_range result;
if (kind == cell_kind::lif) {
get_sources(result, util::any_cast<lif_cell>(cell));
}
else if (kind == cell_kind::spike_source) {
get_sources(result, util::any_cast<spike_source_cell>(cell));
}
else if (kind == cell_kind::benchmark) {
get_sources(result, util::any_cast<benchmark_cell>(cell));
}
else if (kind == cell_kind::cable) {
get_sources(result, util::any_cast<cable_cell>(cell));
}
else {
throw arbor_internal_error("Unknown cell kind");
}
return result;
}

void communicator::update_connections(const recipe& rec,
const domain_decomposition& dom_dec,
const label_resolution_map& source_resolution_map,
const label_resolution_map& target_resolution_map) {
// Forget all lingering information
connections_.clear();
Expand Down Expand Up @@ -102,11 +129,20 @@ void communicator::update_connections(const connectivity& rec,
auto offsets = connection_part_; // Copy, as we use this as the list of current target indices to write into
auto src_domain = src_domains.begin();
auto target_resolver = resolver(&target_resolution_map);
auto source_labels = std::unordered_map<cell_gid_type, std::unique_ptr<label_resolution_map>>{};
for (const auto& cell: gid_infos) {
auto index = cell.index_on_domain;
auto source_resolver = resolver(&source_resolution_map);
auto source_resolvers = std::unordered_map<cell_gid_type, resolver>{};
for (const auto& c: cell.conns) {
auto src_lid = source_resolver.resolve(c.source);
auto sgid = c.source.gid;
if (!source_labels.count(sgid)) {
auto sources = cell_labels_and_gids{get_sources(sgid, rec), {sgid}};
source_labels.emplace(sgid, std::make_unique<label_resolution_map>(sources));
}
if (!source_resolvers.count(sgid)) {
source_resolvers.emplace(sgid, source_labels.at(sgid).get());
}
auto src_lid = source_resolvers.at(sgid).resolve(c.source);
auto tgt_lid = target_resolver.resolve({cell.gid, c.dest});
auto offset = offsets[*src_domain]++;
++src_domain;
Expand Down
3 changes: 1 addition & 2 deletions arbor/communication/communicator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,8 @@ class ARB_ARBOR_API communicator {

void reset();

void update_connections(const connectivity& rec,
void update_connections(const recipe& rec,
const domain_decomposition& dom_dec,
const label_resolution_map& source_resolution_map,
const label_resolution_map& target_resolution_map);

private:
Expand Down
11 changes: 3 additions & 8 deletions arbor/fvm_lowered_cell_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
#include "util/rangeutil.hpp"
#include "util/strprintf.hpp"
#include "util/transform.hpp"
#include "cable_cell_group.hpp"

namespace arb {

Expand Down Expand Up @@ -418,18 +419,12 @@ fvm_initialization_data fvm_lowered_cell_impl<Backend>::initialize(
auto gid = gids[i];
const auto& c = cells[i];

fvm_info.source_data.add_cell();
fvm_info.target_data.add_cell();
fvm_info.gap_junction_data.add_cell();

unsigned count = 0;
for (const auto& [label, range]: c.detector_ranges()) {
fvm_info.source_data.add_label(label, range);
count+=(range.end - range.begin);
}
fvm_info.num_sources[gid] = count;
fvm_info.num_sources[gid] = get_sources(fvm_info.source_data, c);

count = 0;
unsigned count = 0;
for (const auto& [label, range]: c.synapse_ranges()) {
fvm_info.target_data.add_label(label, range);
count+=(range.end - range.begin);
Expand Down
2 changes: 1 addition & 1 deletion arbor/include/arbor/simulation.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class ARB_ARBOR_API simulation {

static simulation_builder create(recipe const &);

void update(const connectivity& rec);
void update(const recipe& rec);

void reset();

Expand Down
1 change: 0 additions & 1 deletion arbor/label_resolution.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,6 @@ struct ARB_ARBOR_API resolver {
resolver(const label_resolution_map* label_map): label_map_(label_map) {}
cell_lid_type resolve(const cell_global_label_type& iden);

private:
using state_variant = std::variant<round_robin_state, round_robin_halt_state, assert_univalent_state>;

state_variant construct_state(lid_selection_policy pol);
Expand Down
10 changes: 9 additions & 1 deletion arbor/lif_cell_group.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,13 @@
#include "util/filter.hpp"
#include "util/maputil.hpp"

using namespace arb;
namespace arb {

cell_size_type ARB_ARBOR_API get_sources(cell_label_range& src, const lif_cell& c) {
src.add_cell();
src.add_label(c.source, {0, 1});
return 1;
}

// Constructor containing gid of first cell in a group and a container of all cells.
lif_cell_group::lif_cell_group(const std::vector<cell_gid_type>& gids,
Expand Down Expand Up @@ -246,3 +252,5 @@ std::vector<probe_metadata> lif_cell_group::get_probe_metadata(cell_member_type
return {};
}
}

} // namespace arb
2 changes: 2 additions & 0 deletions arbor/lif_cell_group.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,4 +78,6 @@ class ARB_ARBOR_API lif_cell_group: public cell_group {
std::unordered_map<cell_member_type, lif_probe_info> probes_;
};

cell_size_type ARB_ARBOR_API get_sources(cell_label_range& src, const lif_cell& c);

} // namespace arb
Loading