sPyNNaker neural_modelling 7.1.1
Loading...
Searching...
No Matches
c_main.c
Go to the documentation of this file.
1/*
2 * Copyright (c) 2014 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
35#include "c_main_neuron_common.h"
36#include "c_main_synapse_common.h"
37#include "c_main_common.h"
38#include "regions.h"
39#include "profile_tags.h"
40#include "spike_processing.h"
41
52
54typedef enum callback_priorities {
55 MC = -1, DMA = 0, USER = 0, TIMER = 0, SDP = 1, BACKGROUND = 1
57
61 .provenance = PROVENANCE_DATA_REGION,
62 .profiler = PROFILER_REGION,
63 .recording = RECORDING_REGION
64};
65
68 .sdp = SDP,
69 .dma = DMA,
70 .timer = TIMER
71};
72
75 .core_params = CORE_PARAMS_REGION,
76 .neuron_params = NEURON_PARAMS_REGION,
77 .current_source_params = CURRENT_SOURCE_PARAMS_REGION,
78 .neuron_recording = NEURON_RECORDING_REGION,
79 .initial_values = INITIAL_VALUES_REGION
80};
81
84 .synapse_params = SYNAPSE_PARAMS_REGION,
85 .synaptic_matrix = SYNAPTIC_MATRIX_REGION,
86 .pop_table = POPULATION_TABLE_REGION,
87 .synapse_dynamics = SYNAPSE_DYNAMICS_REGION,
88 .structural_dynamics = STRUCTURAL_DYNAMICS_REGION,
89 .bitfield_filter = BIT_FIELD_FILTER_REGION
90};
91
93// the timer tick callback returning the same value.
94uint32_t time;
95
97static uint32_t timer_period;
98
100static uint32_t simulation_ticks = 0;
101
103static uint32_t infinite_run;
104
106static uint32_t recording_flags = 0;
107
109static uint32_t n_backgrounds_queued = 0;
110
112static uint32_t n_background_overloads = 0;
113
115static uint32_t max_backgrounds_queued = 0;
116
118static weight_t *ring_buffers;
119
122static void c_main_store_provenance_data(address_t provenance_region) {
123 struct combined_provenance *prov = (void *) provenance_region;
126 store_neuron_provenance(&prov->neuron_provenance);
127 store_synapse_provenance(&prov->synapse_provenance);
128 spike_processing_store_provenance(&prov->spike_processing_provenance);
129}
130
132void resume_callback(void) {
133
134 // Reset recording
136
137 // try resuming neuron
138 // NOTE: at reset, time is set to UINT_MAX ahead of timer_callback(...)
139 if (!neuron_resume(time + 1)) {
140 log_error("failed to resume neuron.");
142 }
143
144 // Resume synapses
145 // NOTE: at reset, time is set to UINT_MAX ahead of timer_callback(...)
147}
148
150static inline void process_ring_buffers(void) {
151 uint32_t first_index = synapse_row_get_first_ring_buffer_index(
153 neuron_transfer(&ring_buffers[first_index]);
154
155 // Print the neuron inputs.
156 #if LOG_LEVEL >= LOG_DEBUG
158 #endif // LOG_LEVEL >= LOG_DEBUG
159}
160
166 profiler_write_entry_disable_irq_fiq(PROFILER_ENTER | PROFILER_TIMER);
167
169
170 // Now do neuron time step update
172
173 profiler_write_entry_disable_irq_fiq(PROFILER_EXIT | PROFILER_TIMER);
175}
176
181void timer_callback(uint timer_count, UNUSED uint unused) {
182 // Disable interrupts to stop DMAs and MC getting in the way of this bit
183 uint32_t state = spin1_int_disable();
184
185 // Increment time step
186 time++;
187
188 // Clear any outstanding spikes
190
191 // Next bit without DMA, but with MC
192 spin1_mode_restore(state);
193 state = spin1_irq_disable();
194
195 // Process ring buffers for the inputs from last time step
197
198 /* if a fixed number of simulation ticks that were specified at startup
199 * then do reporting for finishing */
201
202 // Enter pause and resume state to avoid another tick
204
205 // Pause neuron processing
206 neuron_pause();
207
208 // Pause common functions
209 common_pause(recording_flags);
210
211 // Subtract 1 from the time so this tick gets done again on the next
212 // run
213 time--;
214
216 spin1_mode_restore(state);
217 return;
218 }
219
220 // Push the rest to the background
222 // We have failed to do this timer tick!
224 } else {
228 }
229 }
230
231 spin1_mode_restore(state);
232}
233
237static bool initialise(void) {
239 if (!initialise_common_regions(
242 COMMON_REGIONS, COMMON_PRIORITIES, &ds_regions)) {
243 return false;
244 }
245
246 // Setup neurons
247 uint32_t n_rec_regions_used;
248 if (!initialise_neuron_regions(
249 ds_regions, NEURON_REGIONS, &n_rec_regions_used)) {
250 return false;
251 }
252
253 // Setup synapses
254 uint32_t incoming_spike_buffer_size;
255 bool clear_input_buffer_of_late_packets;
256 uint32_t row_max_n_words;
257 if (!initialise_synapse_regions(
258 ds_regions, SYNAPSE_REGIONS, &ring_buffers, &row_max_n_words,
259 &incoming_spike_buffer_size,
260 &clear_input_buffer_of_late_packets, &n_rec_regions_used)) {
261 return false;
262 }
263
264 // Setup spike processing
266 row_max_n_words, MC, USER, incoming_spike_buffer_size,
267 clear_input_buffer_of_late_packets, n_rec_regions_used)) {
268 return false;
269 }
270
271 // Do bitfield configuration last to only use any unused memory
272 if (!population_table_load_bitfields(data_specification_get_region(
273 SYNAPSE_REGIONS.bitfield_filter, ds_regions))) {
274 return false;
275 }
276
277 // Set timer tick (in microseconds)
278 spin1_set_timer_tick(timer_period);
279
280 return true;
281}
282
284void c_main(void) {
285
286 // Start the time at "-1" so that the first tick will be 0
287 time = UINT32_MAX;
288
289 // initialise the model
290 if (!initialise()) {
292 }
293
295}
static void c_main_store_provenance_data(address_t provenance_region)
Callback to store provenance data (format: neuron_provenance).
Definition c_main.c:122
static uint32_t simulation_ticks
The number of timer ticks to run for before being expected to exit.
Definition c_main.c:100
void timer_callback(uint timer_count, uint unused)
Timer interrupt callback.
Definition c_main.c:181
const struct neuron_regions NEURON_REGIONS
From the regions, extract those that are neuron-specific.
Definition c_main.c:74
callback_priorities
Identify the priorities for all tasks.
Definition c_main.c:54
static void process_ring_buffers(void)
Process the ring buffers for the next time step.
Definition c_main.c:150
void resume_callback(void)
the function to call when resuming a simulation
Definition c_main.c:132
static uint32_t recording_flags
The recording flags indicating if anything is recording.
Definition c_main.c:106
static weight_t * ring_buffers
The ring buffers to be used in the simulation.
Definition c_main.c:118
static uint32_t infinite_run
Determines if this model should run for infinite time.
Definition c_main.c:103
void c_main(void)
The entry point for this model.
Definition c_main.c:284
void background_callback(uint timer_count, uint local_time)
Background activities called from timer.
Definition c_main.c:165
static uint32_t n_backgrounds_queued
The number of background tasks queued / running.
Definition c_main.c:109
const struct synapse_regions SYNAPSE_REGIONS
From the regions, extract those that are synapse-specific.
Definition c_main.c:83
const struct common_priorities COMMON_PRIORITIES
Identify the priorities of the common tasks.
Definition c_main.c:67
static bool initialise(void)
Initialises the model by reading in the regions and checking recording data.
Definition c_main.c:237
static uint32_t timer_period
timer tick period (in microseconds)
Definition c_main.c:97
const struct common_regions COMMON_REGIONS
From the regions, extract those that are common.
Definition c_main.c:59
static uint32_t max_backgrounds_queued
The maximum number of background tasks queued.
Definition c_main.c:115
uint32_t time
The current timer tick value.
Definition c_main.c:94
static uint32_t n_background_overloads
The number of times the background couldn't be added.
Definition c_main.c:112
TIMER
DMA
SDP
callback_priorities
SYSTEM_REGION
uint32_t * address_t
void log_error(const char *message,...)
@ BACKGROUND
Background processing.
USER
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
static uint32_t local_time
The local time step counter.
Definition local_only.c:68
@ PROFILER_TIMER
timer
void neuron_pause(void)
Perform steps needed before pausing a simulation.
Definition neuron.c:184
void neuron_print_inputs(void)
Print the inputs to the neurons.
Definition neuron.c:230
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
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
bool population_table_load_bitfields(filter_region_t *filter_region)
Initialise the bitfield filtering system.
void recording_reset(void)
Standard layout of DSG regions in neuron code.
RTE_SWERR
RTE_API
void rt_error(uint code,...)
void simulation_handle_pause_resume(resume_callback_t callback)
bool simulation_is_finished(void)
void simulation_ready_to_read(void)
void simulation_run(void)
bool spike_processing_initialise(size_t row_max_n_words, uint mc_packet_callback_priority, uint user_event_priority, uint incoming_spike_buffer_size, bool clear_input_buffers_of_late_packets_init, uint32_t packets_per_timestep_region)
Initialise the spike processing system.
bool spike_processing_do_rewiring(int number_of_rewires)
Set the number of times spike_processing has to attempt rewiring.
void spike_processing_clear_input_buffer(timer_t time)
clears the input buffer of packets
void spike_processing_store_provenance(struct spike_processing_provenance *prov)
Get provenance data for Spike processing.
Spike processing API.
Provenance for spike processing.
Tags for profiling of the spike source poisson.
uint spin1_schedule_callback(callback_t cback, uint arg0, uint arg1, uint priority)
uint spin1_irq_disable(void)
uint spin1_int_disable(void)
void spin1_mode_restore(uint value)
unsigned int uint
The combined provenance from synapses and neurons.
Definition c_main.c:43
uint32_t max_backgrounds_queued
Maximum backgrounds queued.
Definition c_main.c:48
uint32_t n_background_queue_overloads
Background queue overloads.
Definition c_main.c:50
The callback priorities used by all simulation cores.
uint32_t sdp
The SDP callback priority.
The identifiers of the regions used by all simulation cores.
uint32_t system
Data for general simulation setup.
The provenance information provided by neurons.
The region IDs used by the neuron processing.
uint32_t core_params
The core parameters.
The provenance information for synaptic processing.
The region IDs used by synapse processing.
uint32_t bitfield_filter
The filters to avoid DMA transfers of empty rows.
uint32_t synapse_params
The parameters of the synapse processing.
static index_t synapse_row_get_first_ring_buffer_index(uint32_t simulation_timestep, uint32_t synapse_type_index_bits, int32_t synapse_delay_mask)
Get the index of the first ring buffer for a given timestep.
void synapses_resume(timer_t time)
Resume processing of synapses after a pause.
Definition synapses.c:411
uint32_t synaptogenesis_n_updates(void)
Number of updates to do of synaptogenesis this time step.