sPyNNaker neural_modelling 7.4.2
Loading...
Searching...
No Matches
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
17// Check for required imports
18#ifndef _TIMING_H_
19#error "Missing timing rule definition. Make sure you define TIMING_DEPENDENCE_H in your makefile."
20#endif
21#ifndef _WEIGHT_H_
22#error "Missing weight rule definition. Make sure you define WEIGHT_DEPENDENCE_H in your makefile."
23#endif
24
28// Spinn_common includes
29#include <static-assert.h>
30
31// sPyNNaker neural modelling includes
32#include <neuron/synapses.h>
33
34// Plasticity includes
35#include "maths.h"
36#include "post_events.h"
37
40#include <debug.h>
41#include <utils.h>
43#include <stddef.h>
44
45//---------------------------------------
46// Macros
47//---------------------------------------
48// The plastic control words used by Morrison synapses store an axonal delay
49// in the upper 3 bits.
50// Assuming a maximum of 16 delay slots, this is all that is required as:
51//
52// 1) Dendritic + Axonal <= 15
53// 2) Dendritic >= Axonal
54//
55// Therefore:
56//
57// * Maximum value of dendritic delay is 15 (with axonal delay of 0)
58// - It requires 4 bits
59// * Maximum value of axonal delay is 7 (with dendritic delay of 8)
60// - It requires 3 bits
61//
62// | Axonal delay | Dendritic delay | Type | Index |
63// |---------------------------|--------------------|-------------------|--------------------|
64// | SYNAPSE_AXONAL_DELAY_BITS | SYNAPSE_DELAY_BITS | SYNAPSE_TYPE_BITS | SYNAPSE_INDEX_BITS |
65// | | | SYNAPSE_TYPE_INDEX_BITS |
66// |---------------------------|--------------------|----------------------------------------|
67#ifndef SYNAPSE_AXONAL_DELAY_BITS
68#define SYNAPSE_AXONAL_DELAY_BITS 3
69#endif
70
71#define SYNAPSE_AXONAL_DELAY_MASK \
72 ((1 << SYNAPSE_AXONAL_DELAY_BITS) - 1)
73
74//---------------------------------------
75// Structures
76//---------------------------------------
86
88typedef struct stdp_params {
92
93typedef struct fixed_stdp_synapse {
94 uint32_t delay_dendritic;
95 uint32_t delay_axonal;
96 uint32_t type;
97 uint32_t index;
98 uint32_t type_index;
99 uint32_t ring_buffer_index;
101
104
107
110
112static uint32_t plastic_saturation_count = 0;
113
114/* PRIVATE FUNCTIONS */
115
116// Mark a value as possibly unused while not using any instructions, guaranteed
117#ifndef __use
118#define __use(x) do { (void) (x); } while (0)
119#endif
120
121static inline bool synapse_dynamics_stdp_init(
122 address_t *address, stdp_params *params, uint32_t n_synapse_types,
123 uint32_t *ring_buffer_to_input_buffer_left_shifts) {
124
125 // Load parameters
126 stdp_params *sdram_params = (stdp_params *) *address;
127 spin1_memcpy(params, sdram_params, sizeof(stdp_params));
128
129 // Load timing dependence data
130 address_t weight_region_address = timing_initialise(
131 (address_t) &sdram_params[1]);
132 if (weight_region_address == NULL) {
133 return false;
134 }
135
136 // Load weight dependence data
137 address_t weight_result = weight_initialise(
138 weight_region_address, n_synapse_types,
139 ring_buffer_to_input_buffer_left_shifts);
140 if (weight_result == NULL) {
141 return false;
142 }
143
144 // Update address to after the region just read
145 *address = weight_result;
146 return true;
147}
148
149input_t synapse_dynamics_get_intrinsic_bias(
150 UNUSED uint32_t time, UNUSED index_t neuron_index) {
151 return ZERO;
152}
153
157
161
162static inline fixed_stdp_synapse synapse_dynamics_stdp_get_fixed(
163 uint32_t control_word, uint32_t time, uint32_t colour_delay) {
164 // Extract control-word components
165 // **NOTE** cunningly, control word is just the same as lower
166 // 16-bits of 32-bit fixed synapse so same functions can be used
167 uint32_t delay_dendritic = synapse_row_sparse_delay(control_word,
169 uint32_t delay_axonal = 0; //sparse_axonal_delay(control_word);
170 uint32_t type_index = synapse_row_sparse_type_index(control_word,
172 return (fixed_stdp_synapse) {
173 .delay_dendritic = delay_dendritic,
174 .delay_axonal = delay_axonal,
178 control_word, synapse_index_mask),
179 .type_index = type_index,
181 (delay_axonal + delay_dendritic + time) - colour_delay, type_index,
183 };
184}
185
186static inline void synapse_dynamics_stdp_update_ring_buffers(
187 weight_t *ring_buffers, fixed_stdp_synapse s, int32_t weight) {
188 uint32_t accumulation = ring_buffers[s.ring_buffer_index] + weight;
189
190 uint32_t sat_test = accumulation & 0xFFFF0000;
191 if (sat_test) {
192 accumulation = 0xFFFF;
194 }
195
196 ring_buffers[s.ring_buffer_index] = accumulation;
197}
198
201 uint32_t id, uint32_t delay, uint32_t type) {
202 control_t new_control =
203 (delay & ((1 << synapse_delay_bits) - 1)) << synapse_type_index_bits;
204 new_control |= (type & ((1 << synapse_type_index_bits) - 1)) << synapse_index_bits;
205 new_control |= id & ((1 << synapse_index_bits) - 1);
206 return new_control;
207}
208
uint32_t index_t
static weight_t * ring_buffers
The ring buffers to be used in the simulation.
Definition c_main.c:118
uint32_t * address_t
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
#define NULL
void spin1_memcpy(void *dst, void const *src, uint len)
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.
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_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 ...
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 index_t synapse_row_sparse_type_index(uint32_t x, uint32_t synapse_type_index_mask)
Get the type and index.
uint16_t control_t
Define the type of the control data.
The type of the fixed part of the row. The fixed-plastic part follows.
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.