sPyNNaker neural_modelling 7.3.1
Loading...
Searching...
No Matches
neuron.c
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
21#include "neuron.h"
22#include "neuron_recording.h"
26#include <debug.h>
27
29uint32_t *neuron_keys;
30
34
36uint32_t latest_send_time = 0xFFFFFFFF;
37
39uint32_t earliest_send_time = 0;
40
42uint32_t colour = 0;
43
45static uint32_t n_neurons;
46
48static uint32_t n_neurons_peak;
49
51static uint32_t n_synapse_types;
52
54static uint32_t colour_mask;
55
58
61
64
67
70 uint32_t has_key;
71 uint32_t n_neurons_to_simulate;
72 uint32_t n_neurons_peak;
73 uint32_t n_colour_bits;
74 uint32_t n_synapse_types;
75 uint32_t ring_buffer_shifts[];
76 // Following this struct in memory (as it can't be expressed in C) is:
77 // uint32_t neuron_keys[n_neurons_to_simulate];
78};
79
83static bool neuron_load_neuron_parameters(uint32_t time) {
84 address_t save_address = NULL;
85 if (time == 0) {
86 save_address = saved_initial_values_address;
87 }
89 save_address);
90 return true;
91}
92
93bool neuron_resume(uint32_t time) { // EXPORTED
95 log_error("failed to reload the neuron recording parameters");
96 return false;
97 }
98
99 // (re)load the current source parameters
101
103}
104
106 void *core_params_address, void *neuron_params_address,
107 void *current_sources_address, void *recording_address,
108 void *initial_values_address, uint32_t *n_rec_regions_used) {
109 // Read the neuron parameters
110 struct neuron_core_parameters *params = core_params_address;
111
112 // Check if there is a key to use
113 use_key = params->has_key;
114
115 // Read the neuron details
116 n_neurons = params->n_neurons_to_simulate;
117 n_neurons_peak = params->n_neurons_peak;
118 n_synapse_types = params->n_synapse_types;
119
120 // Get colour details
121 colour_mask = (1 << params->n_colour_bits) - 1;
122
123 // Set up ring buffer left shifts
124 uint32_t ring_buffer_bytes = n_synapse_types * sizeof(uint32_t);
125 ring_buffer_to_input_left_shifts = spin1_malloc(ring_buffer_bytes);
127 log_error("Not enough memory to allocate ring buffer");
128 return false;
129 }
130
131 // read in ring buffer to input left shifts
133 ring_buffer_to_input_left_shifts, params->ring_buffer_shifts,
134 ring_buffer_bytes);
135
136 // The key list comes after the ring buffer shifts
137 uint32_t *neuron_keys_sdram =
138 (uint32_t *) &params->ring_buffer_shifts[n_synapse_types];
139 uint32_t neuron_keys_size = n_neurons * sizeof(uint32_t);
140 neuron_keys = spin1_malloc(neuron_keys_size);
141 if (neuron_keys == NULL) {
142 log_error("Not enough memory to allocate neuron keys");
143 return false;
144 }
145 spin1_memcpy(neuron_keys, neuron_keys_sdram, neuron_keys_size);
146
147 // Store where the actual neuron parameters start
148 saved_neuron_params_address = neuron_params_address;
149 current_source_address = current_sources_address;
150 saved_initial_values_address = initial_values_address;
151
152 log_info("\t n_neurons = %u, peak %u, n_synapse_types %u",
154
155 // Call the neuron implementation initialise function to setup DTCM etc.
157 return false;
158 }
159
160 // load the neuron data into the allocated DTCM spaces.
162 return false;
163 }
164
165 // Initialise for current sources
166 if (!current_source_initialise(current_sources_address, n_neurons)) {
167 return false;
168 }
169
170 // load the current source data into the allocated DTCM spaces
171 if (!current_source_load_parameters(current_sources_address)) {
172 return false;
173 }
174
175 // setup recording region
177 recording_address, n_neurons, n_rec_regions_used)) {
178 return false;
179 }
180
181 return true;
182}
183
184void neuron_pause(void) { // EXPORTED
185
186 // call neuron implementation function to do the work
188}
189
190void neuron_do_timestep_update(timer_t time, uint timer_count) { // EXPORTED
191
192 // Prepare recording for the next timestep
194
196
197 // Record the recorded variables
199
200 // Update the colour
201 colour = (colour + 1) & colour_mask;
202}
203
204void neuron_transfer(weight_t *syns) { // EXPORTED
205 uint32_t synapse_index = 0;
206 uint32_t ring_buffer_index = 0;
207 for (uint32_t s_i = n_synapse_types; s_i > 0; s_i--) {
208 uint32_t rb_shift = ring_buffer_to_input_left_shifts[synapse_index];
209 uint32_t neuron_index = 0;
210 for (uint32_t n_i = n_neurons_peak; n_i > 0; n_i--) {
211 weight_t value = syns[ring_buffer_index];
212 if (value > 0) {
213 if (neuron_index > n_neurons) {
214 log_error("Neuron index %u out of range", neuron_index);
216 }
218 value, rb_shift);
219 neuron_impl_add_inputs(synapse_index, neuron_index, val_to_add);
220 }
221 syns[ring_buffer_index] = 0;
222 ring_buffer_index++;
223 neuron_index++;
224 }
225 synapse_index++;
226 }
227}
228
229#if LOG_LEVEL >= LOG_DEBUG
230void neuron_print_inputs(void) { // EXPORTED
232}
233
237
238const char *neuron_get_synapse_type_char(uint32_t synapse_type) { // EXPORTED
239 return neuron_impl_get_synapse_type_char(synapse_type);
240}
241#endif // LOG_LEVEL >= LOG_DEBUG
uint32_t time
The current timer tick value.
Definition c_main.c:94
uint32_t timer_t
uint32_t * address_t
General API of a current source implementation.
static bool current_source_initialise(address_t cs_address, uint32_t n_neurons)
Initialise the particular implementation of the data.
static bool current_source_load_parameters(address_t cs_address)
Load the data into the allocated array structures.
void log_error(const char *message,...)
void log_info(const char *message,...)
REAL input_t
The type of an input.
void neuron_pause(void)
Perform steps needed before pausing a simulation.
Definition neuron.c:184
bool neuron_initialise(void *core_params_address, void *neuron_params_address, void *current_sources_address, void *recording_address, void *initial_values_address, uint32_t *n_rec_regions_used)
translate the data stored in the NEURON_PARAMS data region in SDRAM and convert it into c based objec...
Definition neuron.c:105
const char * neuron_get_synapse_type_char(uint32_t synapse_type)
Get the synapse type description character.
Definition neuron.c:238
void neuron_print_synapse_parameters(void)
Print the neurons' synapse parameters.
Definition neuron.c:234
static void * current_source_address
The address for the current source parameters.
Definition neuron.c:63
static uint32_t colour_mask
The mask of the colour.
Definition neuron.c:54
void neuron_print_inputs(void)
Print the inputs to the neurons.
Definition neuron.c:230
uint32_t latest_send_time
Latest time in a timestep that any neuron has sent a spike.
Definition neuron.c:36
uint32_t colour
The colour of the time step to handle delayed spikes.
Definition neuron.c:42
static uint32_t n_neurons_peak
The closest power of 2 >= n_neurons.
Definition neuron.c:48
static uint32_t n_neurons
The number of neurons on the core.
Definition neuron.c:45
bool neuron_resume(uint32_t time)
Prepare to resume simulation of the neurons.
Definition neuron.c:93
void neuron_transfer(weight_t *syns)
Add inputs to the neurons.
Definition neuron.c:204
bool use_key
Whether to use key from neuron.c.
Definition neuron.c:33
static void * saved_initial_values_address
The address to save initial values to.
Definition neuron.c:66
void neuron_do_timestep_update(timer_t time, uint timer_count)
executes all the updates to neural parameters when a given timer period has occurred.
Definition neuron.c:190
uint32_t earliest_send_time
Earliest time in a timestep that any neuron has sent a spike.
Definition neuron.c:39
static uint32_t * ring_buffer_to_input_left_shifts
Amount to left shift the ring buffer by to make it an input.
Definition neuron.c:57
static uint32_t n_synapse_types
The number of synapse types.
Definition neuron.c:51
uint32_t * neuron_keys
The keys to be used by the neurons (one per neuron)
Definition neuron.c:29
static void * saved_neuron_params_address
The address where the actual neuron parameters start.
Definition neuron.c:60
static bool neuron_load_neuron_parameters(uint32_t time)
does the memory copy for the neuron parameters
Definition neuron.c:83
parameters that reside in the neuron_parameter_data_region
Definition neuron.c:69
interface for neurons
General API of a neuron implementation.
static void neuron_impl_print_synapse_parameters(uint32_t n_neurons)
Print the synapse parameters of the neurons.
static void neuron_impl_do_timestep_update(uint32_t timer_count, uint32_t time, uint32_t n_neurons)
Do the timestep update for the particular implementation.
static void neuron_impl_load_neuron_parameters(address_t address, uint32_t next, uint32_t n_neurons, address_t save_initial_state)
Load in the neuron parameters.
static void neuron_impl_add_inputs(index_t synapse_type_index, index_t neuron_index, input_t weights_this_timestep)
Add inputs to the neuron.
static const char * neuron_impl_get_synapse_type_char(uint32_t synapse_type)
Get the synapse type character for a synapse type.
static bool neuron_impl_initialise(uint32_t n_neurons)
Initialise the particular implementation of the data.
static void neuron_impl_print_inputs(uint32_t n_neurons)
Print the inputs to the neurons.
static void neuron_impl_store_neuron_parameters(address_t address, uint32_t next, uint32_t n_neurons)
Stores neuron parameters back into SDRAM.
Recording of the state of a neuron (spiking, voltage, etc.)
bool neuron_recording_reset(uint32_t n_neurons)
reads recording data from sdram on reset.
static void neuron_recording_setup_for_next_recording(void)
sets up state for next recording.
static void neuron_recording_record(uint32_t time)
does the recording process of handing over to basic recording
bool neuron_recording_initialise(void *recording_address, uint32_t n_neurons, uint32_t *n_rec_regions_used)
sets up the recording stuff
RTE_SWERR
void rt_error(uint code,...)
#define NULL
void spin1_memcpy(void *dst, void const *src, uint len)
unsigned int uint
API for synapse dynamics.
static stdp_params params
Configuration parameters.
static input_t synapse_row_convert_weight_to_input(weight_t weight, uint32_t left_shift)
Converts a weight stored in a synapse row to an input.