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

Optimize computation in iaf_psc_alpha_ps model #3305

Merged
merged 7 commits into from
Sep 27, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
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
31 changes: 19 additions & 12 deletions models/iaf_psc_alpha_ps.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -268,15 +268,21 @@ nest::iaf_psc_alpha_ps::pre_run_hook()

V_.h_ms_ = Time::get_resolution().get_ms();

V_.psc_norm_ex_ = 1.0 * numerics::e / P_.tau_syn_ex_;
V_.psc_norm_in_ = 1.0 * numerics::e / P_.tau_syn_in_;
// pre-compute inverse member variables
V_.inv_c_m_ = 1.0 / P_.c_m_;
V_.inv_tau_m_ = 1.0 / P_.tau_m_;
V_.inv_tau_syn_ex_ = 1.0 / P_.tau_syn_ex_;
V_.inv_tau_syn_in_ = 1.0 / P_.tau_syn_in_;

V_.psc_norm_ex_ = 1.0 * numerics::e * V_.inv_tau_syn_ex_;
heshpdx marked this conversation as resolved.
Show resolved Hide resolved
V_.psc_norm_in_ = 1.0 * numerics::e * V_.inv_tau_syn_in_;
heshpdx marked this conversation as resolved.
Show resolved Hide resolved

// pre-compute matrix for full time step
V_.expm1_tau_m_ = numerics::expm1( -V_.h_ms_ / P_.tau_m_ );
V_.exp_tau_syn_ex_ = std::exp( -V_.h_ms_ / P_.tau_syn_ex_ );
V_.exp_tau_syn_in_ = std::exp( -V_.h_ms_ / P_.tau_syn_in_ );
V_.expm1_tau_m_ = numerics::expm1( -V_.h_ms_ * V_.inv_tau_m_ );
heshpdx marked this conversation as resolved.
Show resolved Hide resolved
V_.exp_tau_syn_ex_ = std::exp( -V_.h_ms_ * V_.inv_tau_syn_ex_ );
V_.exp_tau_syn_in_ = std::exp( -V_.h_ms_ * V_.inv_tau_syn_in_ );

V_.P30_ = -P_.tau_m_ / P_.c_m_ * V_.expm1_tau_m_;
V_.P30_ = -P_.tau_m_ * V_.inv_c_m_ * V_.expm1_tau_m_;
// these are determined according to a numeric stability criterion
propagator_ex_ = IAFPropagatorAlpha( P_.tau_syn_ex_, P_.tau_m_, P_.c_m_ );
std::tie( V_.P31_ex_, V_.P32_ex_ ) = propagator_ex_.evaluate( V_.h_ms_ );
Expand All @@ -290,6 +296,7 @@ nest::iaf_psc_alpha_ps::pre_run_hook()
V_.refractory_steps_ = Time( Time::ms( P_.t_ref_ ) ).get_steps();
// since t_ref_ >= sim step size, this can only fail in error
assert( V_.refractory_steps_ >= 1 );

heshpdx marked this conversation as resolved.
Show resolved Hide resolved
}

/* ----------------------------------------------------------------
Expand Down Expand Up @@ -500,9 +507,9 @@ nest::iaf_psc_alpha_ps::propagate_( const double dt )
// V_m_ remains unchanged at 0.0 while neuron is refractory
if ( not S_.is_refractory_ )
{
const double expm1_tau_m = numerics::expm1( -dt / P_.tau_m_ );
const double expm1_tau_m = numerics::expm1( -dt * V_.inv_tau_m_ );

const double ps_P30 = -P_.tau_m_ / P_.c_m_ * expm1_tau_m;
const double ps_P30 = -P_.tau_m_ * V_.inv_c_m_ * expm1_tau_m;

double ps_P31_ex;
double ps_P32_ex;
Expand All @@ -518,8 +525,8 @@ nest::iaf_psc_alpha_ps::propagate_( const double dt )
S_.V_m_ = ( S_.V_m_ < P_.U_min_ ? P_.U_min_ : S_.V_m_ );
}

const double ps_e_TauSyn_ex = std::exp( -dt / P_.tau_syn_ex_ );
const double ps_e_TauSyn_in = std::exp( -dt / P_.tau_syn_in_ );
const double ps_e_TauSyn_ex = std::exp( -dt * V_.inv_tau_syn_ex_ );
const double ps_e_TauSyn_in = std::exp( -dt * V_.inv_tau_syn_in_ );

// now the synaptic components
S_.I_ex_ = ps_e_TauSyn_ex * dt * S_.dI_ex_ + ps_e_TauSyn_ex * S_.I_ex_;
Expand Down Expand Up @@ -578,9 +585,9 @@ nest::iaf_psc_alpha_ps::emit_instant_spike_( Time const& origin, const long lag,
double
nest::iaf_psc_alpha_ps::threshold_distance( double t_step ) const
{
const double expm1_tau_m = numerics::expm1( -t_step / P_.tau_m_ );
const double expm1_tau_m = numerics::expm1( -t_step * V_.inv_tau_m_ );

const double ps_P30 = -P_.tau_m_ / P_.c_m_ * expm1_tau_m;
const double ps_P30 = -P_.tau_m_ * V_.inv_c_m_ * expm1_tau_m;

double ps_P31_ex;
double ps_P32_ex;
Expand Down
4 changes: 4 additions & 0 deletions models/iaf_psc_alpha_ps.h
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,10 @@ class iaf_psc_alpha_ps : public ArchivingNode
double dI_ex_before_; //!< at beginning of mini-step
double dI_in_before_; //!< at beginning of mini-step
double V_m_before_; //!< at beginning of mini-step
double inv_tau_m_; //!< 1 / tau_m
double inv_tau_syn_ex_; //!< 1 / tau_syn_ex
double inv_tau_syn_in_; //!< 1 / tau_syn_in
double inv_c_m_; //!< 1 / c_m
};

// Access functions for UniversalDataLogger -------------------------------
Expand Down
Loading