Skip to content

Commit

Permalink
guard for zero random variables (#2031)
Browse files Browse the repository at this point in the history
  • Loading branch information
boeschf authored Nov 8, 2022
1 parent aba5799 commit 3ff2b5e
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
11 changes: 9 additions & 2 deletions arbor/backends/gpu/rand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,17 @@ namespace gpu {

void random_numbers::instantiate(mechanism& m, std::size_t value_width_padded,
const mechanism_layout& pos_data, arb_seed_type seed) {

using util::make_span;

// bail out if there are no random variables
if (m.mech_.n_random_variables == 0) return;

// Allocate view pointers for random nubers
std::size_t num_random_numbers_per_cv = m.mech_.n_random_variables;
std::size_t random_number_storage = num_random_numbers_per_cv*cbprng::cache_size();
for (auto& v : random_numbers_) v.resize(num_random_numbers_per_cv);
for (auto& v : random_numbers_) {
v.resize(num_random_numbers_per_cv);
}

// Allocate bulk storage
std::size_t count = random_number_storage*value_width_padded;
Expand All @@ -44,6 +48,9 @@ void random_numbers::instantiate(mechanism& m, std::size_t value_width_padded,
}

void random_numbers::update(mechanism& m) {
// bail out if there are no random variables
if (!impl_) return;

// Assign new random numbers by selecting the next cache
const auto counter = random_number_update_counter_++;
const auto cache_idx = cbprng::cache_index(counter);
Expand Down
4 changes: 4 additions & 0 deletions arbor/util/pimpl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ class pimpl

pimpl() noexcept;

pimpl(T* ptr) noexcept;

template<typename... Args>
pimpl(Args&&... args);

Expand All @@ -30,6 +32,8 @@ class pimpl
const T* operator->() const noexcept;
T& operator*() noexcept;
const T& operator*() const noexcept;

operator bool() const noexcept { return (bool)m; }
};


Expand Down
5 changes: 4 additions & 1 deletion arbor/util/pimpl_src.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ pimpl<T>::~pimpl() = default;
template<typename T>
pimpl<T>::pimpl() noexcept = default;

template<typename T>
pimpl<T>::pimpl(T* ptr) noexcept : m{ptr} {}

template<typename T>
template<typename... Args>
pimpl<T>::pimpl(Args&&... args)
Expand All @@ -41,7 +44,7 @@ const T& pimpl<T>::operator*() const noexcept { return *m.get(); }

template<typename T, typename... Args>
pimpl<T> make_pimpl(Args&&... args) {
return pimpl<T>{std::forward<Args>(args)...};
return {new T{std::forward<Args>(args)...}};
}

} // namespace util
Expand Down

0 comments on commit 3ff2b5e

Please sign in to comment.