sPyNNaker neural_modelling  7.4.2
synapse_dynamics_stdp_common.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2017 The University of Manchester
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * https://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
20 // Spinn_common includes
21 #include <static-assert.h>
22 
23 // sPyNNaker neural modelling includes
24 #include <neuron/synapses.h>
25 
26 // Plasticity includes
27 #include "maths.h"
28 #include "post_events.h"
29 
32 #include <debug.h>
33 #include <utils.h>
35 #include <stddef.h>
36 
37 //---------------------------------------
38 // Macros
39 //---------------------------------------
40 // The plastic control words used by Morrison synapses store an axonal delay
41 // in the upper 3 bits.
42 // Assuming a maximum of 16 delay slots, this is all that is required as:
43 //
44 // 1) Dendritic + Axonal <= 15
45 // 2) Dendritic >= Axonal
46 //
47 // Therefore:
48 //
49 // * Maximum value of dendritic delay is 15 (with axonal delay of 0)
50 // - It requires 4 bits
51 // * Maximum value of axonal delay is 7 (with dendritic delay of 8)
52 // - It requires 3 bits
53 //
54 // | Axonal delay | Dendritic delay | Type | Index |
55 // |---------------------------|--------------------|-------------------|--------------------|
56 // | SYNAPSE_AXONAL_DELAY_BITS | SYNAPSE_DELAY_BITS | SYNAPSE_TYPE_BITS | SYNAPSE_INDEX_BITS |
57 // | | | SYNAPSE_TYPE_INDEX_BITS |
58 // |---------------------------|--------------------|----------------------------------------|
59 #ifndef SYNAPSE_AXONAL_DELAY_BITS
60 #define SYNAPSE_AXONAL_DELAY_BITS 3
61 #endif
62 
63 #define SYNAPSE_AXONAL_DELAY_MASK \
64  ((1 << SYNAPSE_AXONAL_DELAY_BITS) - 1)
65 
66 //---------------------------------------
67 // Structures
68 //---------------------------------------
72 typedef struct {
74  uint32_t prev_time;
78 
80 typedef struct stdp_params {
82  uint32_t backprop_delay;
83 } stdp_params;
84 
85 typedef struct fixed_stdp_synapse {
86  uint32_t delay_dendritic;
87  uint32_t delay_axonal;
88  uint32_t type;
89  uint32_t index;
90  uint32_t type_index;
91  uint32_t ring_buffer_index;
93 
96 
99 
102 
104 static uint32_t plastic_saturation_count = 0;
105 
106 /* PRIVATE FUNCTIONS */
107 
108 // Mark a value as possibly unused while not using any instructions, guaranteed
109 #ifndef __use
110 #define __use(x) do { (void) (x); } while (0)
111 #endif
112 
113 static inline bool synapse_dynamics_stdp_init(
114  address_t *address, stdp_params *params, uint32_t n_synapse_types,
115  uint32_t *ring_buffer_to_input_buffer_left_shifts) {
116 
117  // Load parameters
118  stdp_params *sdram_params = (stdp_params *) *address;
119  spin1_memcpy(params, sdram_params, sizeof(stdp_params));
120 
121  // Load timing dependence data
122  address_t weight_region_address = timing_initialise(
123  (address_t) &sdram_params[1]);
124  if (weight_region_address == NULL) {
125  return false;
126  }
127 
128  // Load weight dependence data
129  address_t weight_result = weight_initialise(
130  weight_region_address, n_synapse_types,
131  ring_buffer_to_input_buffer_left_shifts);
132  if (weight_result == NULL) {
133  return false;
134  }
135 
136  // Update address to after the region just read
137  *address = weight_result;
138  return true;
139 }
140 
141 input_t synapse_dynamics_get_intrinsic_bias(
142  UNUSED uint32_t time, UNUSED index_t neuron_index) {
143  return ZERO;
144 }
145 
148 }
149 
152 }
153 
154 static inline fixed_stdp_synapse synapse_dynamics_stdp_get_fixed(
155  uint32_t control_word, uint32_t time, uint32_t colour_delay) {
156  // Extract control-word components
157  // **NOTE** cunningly, control word is just the same as lower
158  // 16-bits of 32-bit fixed synapse so same functions can be used
159  uint32_t delay_dendritic = synapse_row_sparse_delay(control_word,
161  uint32_t delay_axonal = 0; //sparse_axonal_delay(control_word);
162  uint32_t type_index = synapse_row_sparse_type_index(control_word,
164  return (fixed_stdp_synapse) {
165  .delay_dendritic = delay_dendritic,
166  .delay_axonal = delay_axonal,
167  .type = synapse_row_sparse_type(
168  control_word, synapse_index_bits, synapse_type_mask),
169  .index = synapse_row_sparse_index(
170  control_word, synapse_index_mask),
171  .type_index = type_index,
172  .ring_buffer_index = synapse_row_get_ring_buffer_index_combined(
173  (delay_axonal + delay_dendritic + time) - colour_delay, type_index,
175  };
176 }
177 
178 static inline void synapse_dynamics_stdp_update_ring_buffers(
179  weight_t *ring_buffers, fixed_stdp_synapse s, int32_t weight) {
180  uint32_t accumulation = ring_buffers[s.ring_buffer_index] + weight;
181 
182  uint32_t sat_test = accumulation & 0xFFFF0000;
183  if (sat_test) {
184  accumulation = 0xFFFF;
186  }
187 
188  ring_buffers[s.ring_buffer_index] = accumulation;
189 }
190 
193  uint32_t id, uint32_t delay, uint32_t type) {
194  control_t new_control =
195  (delay & ((1 << synapse_delay_bits) - 1)) << synapse_type_index_bits;
196  new_control |= (type & ((1 << synapse_type_index_bits) - 1)) << synapse_index_bits;
197  new_control |= id & ((1 << synapse_index_bits) - 1);
198  return new_control;
199 }
200 
202  return synapse_row_num_plastic_controls(fixed);
203 }
static weight_t * ring_buffers
The ring buffers to be used in the simulation.
Definition: c_main.c:118
static uint32_t time
Simulation time.
uint32_t synapse_delay_mask
The mask to get the synaptic delay from a "synapse".
Definition: local_only.c:71
uint32_t synapse_type_index_bits
The number of bits used by the synapse type and post-neuron index.
Definition: local_only.c:74
uint32_t synapse_index_bits
The number of bits used by just the post-neuron index.
Definition: local_only.c:77
#define ZERO
A REAL 0.0.
Definition: maths-util.h:123
Support functions for STDP.
REAL input_t
The type of an input.
static uint32_t n_synapse_types
The number of synapse types.
Definition: neuron.c:51
Post-synaptic events.
Trace history of post-synaptic events.
Definition: post_events.h:39
API for synapse dynamics.
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.
uint32_t synapse_dynamics_get_plastic_pre_synaptic_events(void)
Get the counters for plastic pre synaptic events based on (if the model was compiled with SYNAPSE_BEN...
pre_trace_t prev_trace
The event trace.
uint32_t synapse_dynamics_get_plastic_saturation_count(void)
Get the number of ring buffer saturation events due to adding plastic weights.
static uint32_t plastic_saturation_count
Count of times that the plastic math became saturated.
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 synapse_dynamics_n_connections_in_row(synapse_row_fixed_part_t *fixed)
Get the number of connections in the given row.
uint32_t prev_time
The event time.
The type of history data of pre-events.
The type of configuration parameters in SDRAM (written by host)
static size_t synapse_row_num_plastic_controls(const synapse_row_fixed_part_t *fixed)
Get the number of plastic controls in the row.
Definition: synapse_row.h:164
static index_t synapse_row_sparse_type(uint32_t x, uint32_t synapse_index_bits, uint32_t synapse_type_mask)
Get the type code.
Definition: synapse_row.h:201
static index_t synapse_row_get_ring_buffer_index_combined(uint32_t simulation_timestep, uint32_t combined_synapse_neuron_index, uint32_t synapse_type_index_bits, uint32_t synapse_delay_mask)
Get the index of the ring buffer for a given timestep and combined synapse type and neuron index (as ...
Definition: synapse_row.h:298
static index_t synapse_row_sparse_index(uint32_t x, uint32_t synapse_index_mask)
Get the index.
Definition: synapse_row.h:190
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.
Definition: synapse_row.h:222
static index_t synapse_row_sparse_type_index(uint32_t x, uint32_t synapse_type_index_mask)
Get the type and index.
Definition: synapse_row.h:211
uint16_t control_t
Define the type of the control data.
Definition: synapse_row.h:106
The type of the fixed part of the row. The fixed-plastic part follows.
Definition: synapse_row.h:118
uint32_t synapse_index_mask
Mask to pick out the synapse index.
Definition: synapses.c:69
uint32_t synapse_delay_bits
Number of bits in the delay.
Definition: synapses.c:75
uint32_t synapse_type_index_mask
Mask to pick out the synapse type and index.
Definition: synapses.c:65
uint32_t synapse_type_mask
Mask to pick out the synapse type.
Definition: synapses.c:73
Operations on synapses.
API for timing rules.
address_t timing_initialise(address_t address)
Initialise the timing dependence state (global) from SDRAM.
The type of pre-spike traces.
interface for different weight implementations for the weight half of a STDP rule.
address_t weight_initialise(address_t address, uint32_t n_synapse_types, uint32_t *ring_buffer_to_input_buffer_left_shifts)
Initialises the weight aspect of an STDP rule.