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

Modular neuron model #50

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
24 changes: 12 additions & 12 deletions pynn_spinnaker/spinnaker/runtime/common/arm_intrinsics.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ inline int64_t __smlal(int64_t acc, int32_t x, int32_t y)
//! \param[in] y second argument.
//! \return signed result.

static inline int32_t __smulbb (int32_t x, int32_t y)
inline int32_t __smulbb (int32_t x, int32_t y)
{
register int32_t r;

Expand All @@ -63,7 +63,7 @@ static inline int32_t __smulbb (int32_t x, int32_t y)
//! \param[in] y second argument.
//! \return signed result.

static inline int32_t __smulbt (int32_t x, int32_t y)
inline int32_t __smulbt (int32_t x, int32_t y)
{
register int32_t r;

Expand All @@ -78,7 +78,7 @@ static inline int32_t __smulbt (int32_t x, int32_t y)
//! \param[in] y second argument.
//! \return signed result.

static inline int32_t __smultb (int32_t x, int32_t y)
inline int32_t __smultb (int32_t x, int32_t y)
{
register int32_t r;

Expand All @@ -93,7 +93,7 @@ static inline int32_t __smultb (int32_t x, int32_t y)
//! \param[in] y second argument.
//! \return signed result.

static inline int32_t __smultt (int32_t x, int32_t y)
inline int32_t __smultt (int32_t x, int32_t y)
{
register int32_t r;

Expand All @@ -110,7 +110,7 @@ static inline int32_t __smultt (int32_t x, int32_t y)
//! \param[in] y second argument.
//! \return signed result.

static inline int32_t __smulwb (int32_t x, int32_t y)
inline int32_t __smulwb (int32_t x, int32_t y)
{
register int32_t r;

Expand All @@ -127,7 +127,7 @@ static inline int32_t __smulwb (int32_t x, int32_t y)
//! \param[in] y second argument.
//! \return signed result.

static inline int32_t __smulwt (int32_t x, int32_t y)
inline int32_t __smulwt (int32_t x, int32_t y)
{
register int32_t r;

Expand All @@ -150,7 +150,7 @@ static inline int32_t __smulwt (int32_t x, int32_t y)
//! \param[in] acc accumulation argument.
//! \return x*y+acc.

static inline int32_t __smlabb (int32_t x, int32_t y, int32_t acc)
inline int32_t __smlabb (int32_t x, int32_t y, int32_t acc)
{
register int32_t r;

Expand All @@ -171,7 +171,7 @@ static inline int32_t __smlabb (int32_t x, int32_t y, int32_t acc)
//! \param[in] acc accumulation argument.
//! \return x*y+acc.

static inline int32_t __smlabt (int32_t x, int32_t y, int32_t acc)
inline int32_t __smlabt (int32_t x, int32_t y, int32_t acc)
{
register int32_t r;

Expand All @@ -191,7 +191,7 @@ static inline int32_t __smlabt (int32_t x, int32_t y, int32_t acc)
//! \param[in] acc accumulation argument.
//! \return x*y+acc.

static inline int32_t __smlatb (int32_t x, int32_t y, int32_t acc)
inline int32_t __smlatb (int32_t x, int32_t y, int32_t acc)
{
register int32_t r;

Expand All @@ -211,7 +211,7 @@ static inline int32_t __smlatb (int32_t x, int32_t y, int32_t acc)
//! \param[in] acc accumulation argument.
//! \return x*y+acc.

static inline int32_t __smlatt (int32_t x, int32_t y, int32_t acc)
inline int32_t __smlatt (int32_t x, int32_t y, int32_t acc)
{
register int32_t r;

Expand All @@ -233,7 +233,7 @@ static inline int32_t __smlatt (int32_t x, int32_t y, int32_t acc)
//! \param[in] acc accumulation argument.
//! \return x*y+acc.

static inline int32_t __smlawb (int32_t x, int32_t y, int32_t acc)
inline int32_t __smlawb (int32_t x, int32_t y, int32_t acc)
{
register int32_t r;

Expand All @@ -254,7 +254,7 @@ static inline int32_t __smlawb (int32_t x, int32_t y, int32_t acc)
//! \param[in] acc accumulation argument.
//! \return x*y+acc.

static inline int32_t __smlawt (int32_t x, int32_t y, int32_t acc)
inline int32_t __smlawt (int32_t x, int32_t y, int32_t acc)
{
register int32_t r;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ SOURCES = ../../../common/config.cpp \
../../../common/bit_field.cpp \
../../../common/profiler.cpp \
../../neuron_processor.cpp \
../../neuron_models/if_cond.cpp \
../../neuron_dynamics_models/if.cpp \
../../neuron_input_models/cond.cpp \
../../neuron_threshold_models/constant.cpp \
../../synapse_models/exp.cpp

CFLAGS += -I $(CURDIR)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,21 @@
// Model includes
#include "../../input_buffer.h"
#include "../../intrinsic_plasticity_models/stub.h"
#include "../../neuron_models/if_cond.h"
#include "../../modular_neuron.h"
#include "../../neuron_dynamics_models/if.h"
#include "../../neuron_input_models/cond.h"
#include "../../neuron_threshold_models/constant.h"
#include "../../neuron_extra_input_models/stub.h"
#include "../../synapse_models/exp.h"

namespace NeuronProcessor
{
//-----------------------------------------------------------------------------
// Typedefines
//-----------------------------------------------------------------------------
typedef NeuronModels::IFCond Neuron;
typedef ModularNeuron<NeuronDynamicsModels::IF, NeuronInputModels::Cond,
NeuronThresholdModels::Constant,
NeuronExtraInputModels::Stub> Neuron;
typedef SynapseModels::Exp Synapse;
typedef IntrinsicPlasticityModels::Stub IntrinsicPlasticity;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ SOURCES = ../../../common/config.cpp \
../../../common/bit_field.cpp \
../../../common/profiler.cpp \
../../neuron_processor.cpp \
../../neuron_models/if_curr.cpp \
../../neuron_dynamics_models/if.cpp \
../../neuron_input_models/curr.cpp \
../../neuron_threshold_models/constant.cpp \
../../synapse_models/exp.cpp

CFLAGS += -I $(CURDIR)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,21 @@
// Model includes
#include "../../input_buffer.h"
#include "../../intrinsic_plasticity_models/stub.h"
#include "../../neuron_models/if_curr.h"
#include "../../modular_neuron.h"
#include "../../neuron_dynamics_models/if.h"
#include "../../neuron_input_models/curr.h"
#include "../../neuron_threshold_models/constant.h"
#include "../../neuron_extra_input_models/stub.h"
#include "../../synapse_models/exp.h"

namespace NeuronProcessor
{
//-----------------------------------------------------------------------------
// Typedefines
//-----------------------------------------------------------------------------
typedef NeuronModels::IFCurr Neuron;
typedef ModularNeuron<NeuronDynamicsModels::IF, NeuronInputModels::Curr,
NeuronThresholdModels::Constant,
NeuronExtraInputModels::Stub> Neuron;
typedef SynapseModels::Exp Synapse;
typedef IntrinsicPlasticityModels::Stub IntrinsicPlasticity;

Expand Down
130 changes: 130 additions & 0 deletions pynn_spinnaker/spinnaker/runtime/neuron_processor/modular_neuron.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
#pragma once

// Common includes
#include "../common/fixed_point_number.h"
#include "../common/log.h"

// Namespaces
using namespace Common::FixedPointNumber;

//-----------------------------------------------------------------------------
// NeuronProcessor::ModularNeuron
//-----------------------------------------------------------------------------
namespace NeuronProcessor
{
template<typename Dynamics, typename Input, typename Threshold, typename ExtraInput>
class ModularNeuron
{
public:
//-----------------------------------------------------------------------------
// Constants
//-----------------------------------------------------------------------------
enum RecordingChannel
{
RecordingChannelInputMax = (Dynamics::RecordingChannelMax + Input::RecordingChannelMax),
RecordingChannelThresholdMax = (RecordingChannelInputMax + Threshold::RecordingChannelMax),
RecordingChannelMax = (RecordingChannelThresholdMax + ExtraInput::RecordingChannelMax),
};

//-----------------------------------------------------------------------------
// MutableState
//-----------------------------------------------------------------------------
struct MutableState : Dynamics::MutableState, Input::MutableState,
Threshold::MutableState, ExtraInput::MutableState
{
};

//-----------------------------------------------------------------------------
// ImmutableState
//-----------------------------------------------------------------------------
struct ImmutableState : Dynamics::ImmutableState, Input::ImmutableState,
Threshold::ImmutableState, ExtraInput::ImmutableState
{
};

//-----------------------------------------------------------------------------
// Static methods
//-----------------------------------------------------------------------------
static bool Update(MutableState &mutableState, const ImmutableState &immutableState,
S1615 excInput, S1615 inhInput, S1615 extCurrent)
{
// Get membrane voltage from dynamics
const S1615 membraneVoltage = Dynamics::GetMembraneVoltage(mutableState, immutableState);

// Convert the excitatory and inhibitory inputs into a suitable input current
const S1615 synapticInputCurrent = Input::GetInputCurrent(mutableState, immutableState,
excInput, inhInput, membraneVoltage);

// Get any extra input current
const S1615 extraInputCurrent = ExtraInput::GetInputCurrent(mutableState, immutableState,
membraneVoltage);

// Add together all sources of input current
const S1615 totalInputCurrent = synapticInputCurrent + extraInputCurrent + extCurrent;

// Update membrane dynamics to get new membrane voltage
const S1615 newMembraneVoltage = Dynamics::Update(mutableState, immutableState,
totalInputCurrent);

// Has this new membrane voltage crossed the threshold?
const bool spike = Threshold::HasCrossed(mutableState, immutableState,
newMembraneVoltage);

// If a spike occurs, notify dynamics and extra input
if(spike)
{
Dynamics::SetSpiked(mutableState, immutableState);
ExtraInput::SetSpiked(mutableState, immutableState);
}

return spike;

}

static S1615 GetRecordable(unsigned int c,
const MutableState &mutableState, const ImmutableState &immutableState,
S1615 excInput, S1615 inhInput)
{
// If recording channel comes from neuron dynamics
if(c < Dynamics::RecordingChannelMax)
{
return Dynamics::GetRecordable((typename Dynamics::RecordingChannel)c,
mutableState, immutableState);
}
// Otherwise, if recording channel comes from neuron input
else if(c < RecordingChannelInputMax)
{
return Input::GetRecordable((typename Input::RecordingChannel)(c - Dynamics::RecordingChannelMax),
mutableState, immutableState,
excInput, inhInput);
}
// Otherwise, if recording channel comes from spiking threshold
else if(c < RecordingChannelThresholdMax)
{
return Threshold::GetRecordable((typename Threshold::RecordingChannel)(c - RecordingChannelInputMax),
mutableState, immutableState);
}
// Otherwise, if recording channel comes from extra input
else if(c < RecordingChannelMax)
{
return ExtraInput::GetRecordable((typename ExtraInput::RecordingChannel)(c - RecordingChannelThresholdMax),
mutableState, immutableState);
}
// Otherwise
else
{
LOG_PRINT(LOG_LEVEL_WARN, "Attempting to get data from non-existant recording channel %u", c);
return 0;
}
}

static void Print(char *stream, const MutableState &mutableState, const ImmutableState &immutableState)
{
// Print from all modules of neuron
Dynamics::Print(stream, mutableState, immutableState);
Input::Print(stream, mutableState, immutableState);
Threshold::Print(stream, mutableState, immutableState);
ExtraInput::Print(stream, mutableState, immutableState);
}
};
} // NeuronProcessor
Original file line number Diff line number Diff line change
@@ -1,22 +1,23 @@
#include "if_curr.h"
#include "if.h"

// Common includes
#include "../../common/spinnaker.h"

//-----------------------------------------------------------------------------
// NeuronProcessor::NeuronModels::IFCurr
// NeuronProcessor::NeuronDynamicsModels::IF
//-----------------------------------------------------------------------------
namespace NeuronProcessor
{
namespace NeuronModels
namespace NeuronDynamicsModels
{
void IFCurr::Print(char *stream, const MutableState &mutableState, const ImmutableState &immutableState)
void IF::Print(char *stream, const MutableState &mutableState, const ImmutableState &immutableState)
{
io_printf(stream, "Integrate-and-fire dynamics\n");
io_printf(stream, "\tMutable state:\n");
io_printf(stream, "\t\tV_Membrane = %11.4k [mV]\n", mutableState.m_V_Membrane);
io_printf(stream, "\t\tRefractoryTimer = %10d [timesteps]\n", mutableState.m_RefractoryTimer);

io_printf(stream, "\tImmutable state:\n");
io_printf(stream, "\t\tV_Threshold = %11.4k [mV]\n", immutableState.m_V_Threshold);
io_printf(stream, "\t\tV_Reset = %11.4k [mV]\n", immutableState.m_V_Reset);
io_printf(stream, "\t\tV_Rest = %11.4k [mV]\n", immutableState.m_V_Rest);
io_printf(stream, "\t\tI_Offset = %11.4k [nA]\n", immutableState.m_I_Offset);
Expand Down
Loading