24 uint32_t synapse_type:30;
26 uint32_t is_neuromodulation: 1;
36 uint32_t weight_shift;
77static uint32_t *nm_weight_shift;
81#define DECAY_LOOKUP_TAU_C(time) \
82 maths_lut_exponential_decay(time, tau_c_lookup)
83#define DECAY_LOOKUP_TAU_D(time) \
84 maths_lut_exponential_decay(time, tau_d_lookup)
88 accum s1615_weight = kbits(synapse.weight << nm_weight_shift[synapse_type]);
91 .weight_shift=nm_weight_shift[synapse_type],
93 synapse.eligibility_synapse, synapse_type)
100 update_state.weight = kbits(
MAX(bitsk(update_state.weight),
102 update_state.weight = kbits(
MIN(bitsk(update_state.weight),
105 .weight=(weight_t) (bitsk(update_state.weight) >> update_state.weight_shift),
107 update_state.eligibility_state)
115 .weight=final_state.weight,
117 final_state.final_state)
124 const uint32_t delayed_pre_time,
const uint32_t delayed_last_pre_time,
125 const uint32_t delay_dendritic) {
127 const uint32_t window_begin_time =
128 (delayed_last_pre_time >= delay_dendritic)
129 ? (delayed_last_pre_time - delay_dendritic) : 0;
130 const uint32_t window_end_time =
131 (delayed_pre_time >= delay_dendritic)
132 ? (delayed_pre_time - delay_dendritic) : 0;
136 log_debug(
"\t\tbegin_time:%u, end_time:%u - prev_time:%u (valid %u), num_events:%u",
137 window_begin_time, window_end_time, post_window.
prev_time,
140#if LOG_LEVEL >= LOG_DEBUG
143 window_end_time, delay_dendritic);
148static inline accum get_weight_update(int16_t decay_eligibility_trace,
149 int16_t decay_dopamine_trace, int16_t last_dopamine_trace,
150 accum eligibility_weight) {
153 decay_eligibility_trace, decay_dopamine_trace)
156 accum mul_trace =
mul_accum_fixed(eligibility_weight, last_dopamine_trace);
179 const uint32_t last_pre_time,
const pre_trace_t last_pre_trace,
180 const pre_trace_t new_pre_trace,
const uint32_t delay_dendritic,
183 log_debug(
"\tPerforming deferred synapse update at time:%u",
time);
185 const uint32_t delayed_last_pre_time = last_pre_time + delay_axonal;
186 const uint32_t delayed_pre_time =
time + delay_axonal;
191 delayed_last_pre_time, delay_dendritic);
194 uint32_t prev_corr_time = delayed_last_pre_time;
197 int16_t last_dopamine_trace = 0;
201 DECAY_LOOKUP_TAU_D(delayed_last_pre_time - post_window.
prev_time));
206 const uint32_t delayed_post_time = *post_window.
next_time + delay_dendritic;
208 log_debug(
"\t\tApplying post-synaptic event at delayed time:%u, pre:%u, prev_corr:%u",
209 delayed_post_time, delayed_last_pre_time, prev_corr_time);
212 int16_t decay_eligibility_trace = DECAY_LOOKUP_TAU_C(
213 delayed_post_time - prev_corr_time);
216 if (last_dopamine_trace != 0) {
217 int16_t decay_dopamine_trace = DECAY_LOOKUP_TAU_D(
218 delayed_post_time - prev_corr_time);
220 current_state.eligibility_state);
221 current_state.weight += get_weight_update(decay_eligibility_trace,
222 decay_dopamine_trace, last_dopamine_trace, eligibility_weight);
227 decay_eligibility_trace);
229 if (!post_events_next_is_dopamine(post_window)) {
231 delayed_post_time, post_window.
next_trace->post_trace,
232 delayed_last_pre_time, last_pre_trace, post_window.
prev_time,
233 post_window.
prev_trace.post_trace, current_state.eligibility_state);
238 last_dopamine_trace = post_window.
next_trace->dopamine_trace;
240 prev_corr_time = delayed_post_time;
248 const uint32_t delayed_last_post = post_window.
prev_time + delay_dendritic;
249 log_debug(
"\t\tApplying pre-synaptic event at time:%u last post time:%u, prev_corr=%u",
250 delayed_pre_time, delayed_last_post, prev_corr_time);
251 int32_t decay_eligibility_trace = DECAY_LOOKUP_TAU_C(
252 delayed_pre_time - prev_corr_time);
254 if (last_dopamine_trace != 0) {
255 int32_t decay_dopamine_trace = DECAY_LOOKUP_TAU_D(
256 delayed_pre_time - prev_corr_time);
258 current_state.eligibility_state);
259 current_state.weight += get_weight_update(decay_eligibility_trace,
260 decay_dopamine_trace, last_dopamine_trace, eligibility_weight);
265 decay_eligibility_trace);
268 delayed_pre_time, new_pre_trace, delayed_last_pre_time, last_pre_trace,
269 delayed_last_post, post_window.
prev_trace.post_trace,
270 current_state.eligibility_state);
273 return get_nm_final_state(current_state);
278 uint32_t *ring_buffer_to_input_buffer_left_shifts) {
281 ring_buffer_to_input_buffer_left_shifts)) {
295 address_t lut_address = (
void *) &sdram_params[1];
301 if (nm_weight_shift ==
NULL) {
302 log_error(
"Could not initialise weight region data");
306 nm_weight_shift[s] = ring_buffer_to_input_buffer_left_shifts[s];
318 uint32_t *ring_buffer_to_input_buffer_left_shifts) {
319 __use(plastic_region_data);
321 __use(ring_buffer_to_input_buffer_left_shifts);
323#if LOG_LEVEL >= LOG_DEBUG
330 log_debug(
"Plastic region %u synapses\n", plastic_synapse);
333 for (uint32_t i = 0; i < plastic_synapse; i++) {
335 uint32_t control_word = *control_words++;
341 *plastic_words++, synapse_type);
346 log_debug(
"%08x [%3d: (w: %5u (=", control_word, i, weight);
348 weight, ring_buffer_to_input_buffer_left_shifts[synapse_type]);
349 log_debug(
"nA) d: %2u, n = %3u)] - {%08x %08x}\n",
367 return (x >> synapse_delay_index_type_bits) & SYNAPSE_AXONAL_DELAY_MASK;
373 uint32_t time,
index_t neuron_index) {
374 log_debug(
"Adding post-synaptic event to trace %u at time:%u", neuron_index,
time);
382 time, last_post_time, last_post_trace.post_trace);
384 last_post_trace.dopamine_trace,
385 DECAY_LOOKUP_TAU_D(
time - last_post_time));
392 uint32_t control_word, uint32_t last_pre_time,
pre_trace_t last_pre_trace,
402 uint32_t post_delay = s.delay_dendritic;
408 time - colour_delay, last_pre_time, last_pre_trace, new_pre_trace,
409 post_delay, s.delay_axonal, current_state,
413 if (s.delay_dendritic + s.delay_axonal > colour_delay) {
414 synapse_dynamics_stdp_update_ring_buffers(
ring_buffers, s,
420 return get_nm_final_synaptic_word(final_state);
423static inline void process_neuromodulation(
426 bool reward = plastic_region_address->neuromodulation.is_reward;
431 for (; n_synapses > 0; n_synapses--) {
433 uint32_t word = *words++;
437 concentration = -concentration;
449 time, last_post_time, last_post_trace.post_trace);
451 last_post_trace.dopamine_trace,
452 DECAY_LOOKUP_TAU_D(time - last_post_time));
453 new_dopamine_trace += concentration;
456 post_events_add(time, history, new_post_trace, new_dopamine_trace,
true);
463 weight_t *
ring_buffers, uint32_t time, uint32_t colour_delay,
467 if (plastic_region_address->neuromodulation.is_neuromodulation) {
468 process_neuromodulation(plastic_region_address, fixed_region,
time);
486 log_debug(
"Adding pre-synaptic event to trace at time:%u",
time);
492 for (; n_plastic_synapses > 0; n_plastic_synapses--) {
494 uint32_t control_word = *control_words++;
496 plastic_words[0] = process_plastic_synapse(
497 control_word, last_pre_time, last_pre_trace,
499 colour_delay, plastic_words[0]);
513 uint32_t
id,
synaptic_row_t row, weight_t *weight, uint16_t *delay,
514 uint32_t *offset, uint32_t *synapse_type) {
521 for (
size_t plastic_synapse = n_plastic_synapses; plastic_synapse > 0;
522 plastic_synapse--, plastic_words++) {
526 uint32_t control_word = *control_words++;
529 plastic_words->eligibility_synapse);
530 *offset = n_plastic_synapses - plastic_synapse;
549 plastic_words[offset] = plastic_words[plastic_synapse - 1];
552 control_words[offset] = control_words[plastic_synapse - 1];
553 control_words[plastic_synapse - 1] = 0;
561 weight_t weight, uint32_t delay, uint32_t type) {
572 .eligibility_synapse = new_weight,
577 control_words[plastic_synapse] = new_control;
static weight_t * ring_buffers
The ring buffers to be used in the simulation.
uint32_t time
The current timer tick value.
void log_error(const char *message,...)
void log_debug(const char *message,...)
uint32_t synapse_delay_mask
The mask to get the synaptic delay from a "synapse".
uint32_t synapse_type_index_bits
The number of bits used by the synapse type and post-neuron index.
uint32_t synapse_index_bits
The number of bits used by just the post-neuron index.
static int16_lut * maths_copy_int16_lut(address_t *address)
Copy a Lookup Table from SDRAM to DTCM, updating the address.
#define MIN(X, Y)
Minimum. Evaluates arguments twice.
#define MAX(X, Y)
Maximum. Evaluates arguments twice.
Lookup Table of 16-bit integers.
struct synaptic_row * synaptic_row_t
The type of a synaptic row.
static uint32_t n_neurons
The number of neurons on the core.
static uint32_t n_synapse_types
The number of synapse types.
static post_event_history_t * post_events_init_buffers(uint32_t n_neurons)
Initialise an array of post-synaptic event histories.
static void print_event_history(const post_event_history_t *events)
Print a post-synaptic event history.
static post_event_window_t post_events_next(post_event_window_t window)
Advance a post-synaptic event window to the next event.
static void post_events_add(uint32_t time, post_event_history_t *events, post_trace_t trace)
Add a post-synaptic event to the history.
static post_event_window_t post_events_get_window_delayed(const post_event_history_t *events, uint32_t begin_time, uint32_t end_time)
Get the post-synaptic event window.
static void print_delayed_window_events(const post_event_history_t *post_event_history, uint32_t begin_time, uint32_t end_time, uint32_t delay_dendritic)
Print the post-synaptic event history.
uint32_t num_events
The number of events.
post_trace_t prev_trace
The previous post-synaptic event trace.
const uint32_t * next_time
The next post-synaptic event time.
uint32_t prev_time
The previous post-synaptic event time.
const post_trace_t * next_trace
The next post-synaptic event trace.
uint32_t prev_time_valid
Whether the previous post-synaptic event is valid (based on time)
Post event window description.
uint32_t count_minus_one
Number of events stored (minus one)
uint32_t times[MAX_POST_SYNAPTIC_EVENTS]
Event times.
post_trace_t traces[MAX_POST_SYNAPTIC_EVENTS]
Event traces.
Trace history of post-synaptic events.
void spin1_memcpy(void *dst, void const *src, uint len)
Basic definitions for STDP.
static accum mul_accum_fixed(accum a, int32_t stdp_fixed)
Multiply an accum by an STDP fixed point and return an accum.
#define STDP_FIXED_POINT_ONE
The number 1.0 in the fixed point math used by STDP.
#define STDP_FIXED_MUL_16X16(a, b)
Multiply two STDP fixed point numbers.
plastic_synapse_t synapses[]
The per-synapse information.
pre_event_history_t history
The pre-event history.
The format of the plastic data region of a synaptic row.
STDP core implementation.
uint32_t backprop_delay
The back-propagation delay, in basic simulation timesteps.
static control_t control_conversion(uint32_t id, uint32_t delay, uint32_t type)
packing all of the information into the required plastic control word
static stdp_params params
Configuration parameters.
pre_trace_t prev_trace
The event trace.
static post_event_history_t * post_event_history
The history data of post-events.
static uint32_t num_plastic_pre_synaptic_events
Count of pre-synaptic events relevant to plastic processing.
uint32_t prev_time
The event time.
The type of history data of pre-events.
accum max_weight
Maximum of weight after update.
bool synapse_dynamics_initialise(address_t address, uint32_t n_neurons, uint32_t n_synapse_types, uint32_t *ring_buffer_to_input_buffer_left_shifts)
Initialise the synapse dynamics.
void synapse_dynamics_process_post_synaptic_event(uint32_t time, index_t neuron_index)
Inform the synapses that the neuron fired.
bool synapse_dynamics_find_neuron(uint32_t id, synaptic_row_t row, weight_t *weight, uint16_t *delay, uint32_t *offset, uint32_t *synapse_type)
Search the synaptic row for the the connection with the specified post-synaptic ID.
static index_t sparse_axonal_delay(uint32_t x)
Get the axonal delay.
void synapse_dynamics_print_plastic_synapses(synapse_row_plastic_data_t *plastic_region_data, synapse_row_fixed_part_t *fixed_region, uint32_t *ring_buffer_to_input_buffer_left_shifts)
Print the synapse dynamics.
bool synapse_dynamics_add_neuron(uint32_t id, synaptic_row_t row, weight_t weight, uint32_t delay, uint32_t type)
Add an entry in the synaptic row.
accum weight_update_constant_component
Constant part of weight update.
static nm_final_state_t izhikevich_neuromodulation_plasticity_update_synapse(const uint32_t time, const uint32_t last_pre_time, const pre_trace_t last_pre_trace, const pre_trace_t new_pre_trace, const uint32_t delay_dendritic, const uint32_t delay_axonal, nm_update_state_t current_state, const post_event_history_t *post_event_history)
Synapse update loop core.
bool synapse_dynamics_remove_neuron(uint32_t offset, synaptic_row_t row)
Remove the entry at the specified offset in the synaptic row.
uint32_t skipped_synapses
accum min_weight
Minimum of weight after update (must be >= 0)
bool synapse_dynamics_process_plastic_synapses(synapse_row_plastic_data_t *plastic_region_address, synapse_row_fixed_part_t *fixed_region, weight_t *ring_buffers, uint32_t time, uint32_t colour_delay, bool *write_back)
Process the dynamics of the synapses.
static size_t synapse_row_num_plastic_controls(const synapse_row_fixed_part_t *fixed)
Get the number of plastic controls in the row.
static synapse_row_fixed_part_t * synapse_row_fixed_region(synaptic_row_t row)
Get the address of the non-plastic (or fixed) region.
static control_t * synapse_row_plastic_controls(synapse_row_fixed_part_t *fixed)
Get the array of plastic controls in the row.
static index_t synapse_row_sparse_type(uint32_t x, uint32_t synapse_index_bits, uint32_t synapse_type_mask)
Get the type code.
static index_t synapse_row_sparse_index(uint32_t x, uint32_t synapse_index_mask)
Get the index.
static index_t synapse_row_sparse_delay(uint32_t x, uint32_t synapse_type_index_bits, uint32_t synapse_delay_mask)
Get the delay from an encoded synapse descriptor.
static synapse_row_plastic_data_t * synapse_row_plastic_region(synaptic_row_t row)
Get the address of the plastic region.
size_t num_plastic
The number of plastic controls in data
uint16_t control_t
Define the type of the control data.
static weight_t synapse_row_sparse_weight(uint32_t x)
Get the weight from an encoded synapse descriptor.
The type of the fixed part of the row. The fixed-plastic part follows.
static plastic_synapse_t synapse_structure_get_final_synaptic_word(final_state_t final_state)
Get the final plastic synapse data from the final state.
static accum synapse_structure_get_update_weight(update_state_t state)
Get the current synaptic weight stored in the update state.
static void synapse_structure_decay_weight(update_state_t *state, uint32_t decay)
Decay the synaptic weight value stored by multiplication.
static plastic_synapse_t synapse_structure_create_synapse(weight_t weight)
Create the initial plastic synapse data.
static update_state_t synapse_structure_get_update_state(plastic_synapse_t synaptic_word, index_t synapse_type)
Get the update state from the synapse structure.
static weight_t synapse_structure_get_final_weight(final_state_t final_state)
Get the final weight from the final state.
static final_state_t synapse_structure_get_final_state(update_state_t state)
Get the final state from the update state.
static weight_t synapse_structure_get_weight(plastic_synapse_t synaptic_word)
Get the current synaptic weight from the plastic synapse data.
weight_t weight
The state.
Plastic synapse contains normal 16-bit weight and an accumulator.
uint32_t synapse_index_mask
Mask to pick out the synapse index.
uint32_t synapse_type_mask
Mask to pick out the synapse type.
static void synapses_print_weight(weight_t weight, uint32_t left_shift)
Print the weight of a synapse.
static post_trace_t timing_add_post_spike(uint32_t time, uint32_t last_time, post_trace_t last_trace)
Add a post spike to the post trace.
static post_trace_t timing_decay_post(uint32_t time, uint32_t last_time, post_trace_t last_trace)
Evolve the post trace without adding a spike.
static update_state_t timing_apply_pre_spike(uint32_t time, pre_trace_t trace, uint32_t last_pre_time, pre_trace_t last_pre_trace, uint32_t last_post_time, post_trace_t last_post_trace, update_state_t previous_state)
Apply a pre-spike timing rule state update.
static pre_trace_t timing_add_pre_spike(uint32_t time, uint32_t last_time, pre_trace_t last_trace)
Add a pre spike to the pre trace.
static update_state_t timing_apply_post_spike(uint32_t time, post_trace_t trace, uint32_t last_pre_time, pre_trace_t last_pre_trace, uint32_t last_post_time, post_trace_t last_post_trace, update_state_t previous_state)
Apply a post-spike timing rule state update.
The type of post-spike traces.
The type of pre-spike traces.