sPyNNaker neural_modelling 7.1.1
Loading...
Searching...
No Matches
c_main_local_only.c
1/*
2 * Copyright (c) 2021 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#include "c_main_neuron_common.h"
18#include "c_main_common.h"
19#include "profile_tags.h"
20#include "local_only/local_only_impl.h"
21#include "local_only.h"
22#include "synapse_row.h"
23
24#define SYNAPSE_TYPE
25
34};
35
37typedef enum callback_priorities {
38 MC = -1, DMA = 0, USER = 0, TIMER = 0, SDP = 1, BACKGROUND = 1
40
42enum regions {
44 PROVENANCE_DATA_REGION,
45 PROFILER_REGION,
46 RECORDING_REGION,
47 CORE_PARAMS_REGION,
48 NEURON_PARAMS_REGION,
49 CURRENT_SOURCE_PARAMS_REGION,
50 NEURON_RECORDING_REGION,
51 LOCAL_ONLY_REGION,
52 LOCAL_ONLY_PARAMS_REGION,
53 NEURON_BUILDER_REGION,
54 INITIAL_VALUES_REGION
55};
56
58const struct common_regions COMMON_REGIONS = {
60 .provenance = PROVENANCE_DATA_REGION,
61 .profiler = PROFILER_REGION,
62 .recording = RECORDING_REGION
63};
64
67 .sdp = SDP,
68 .dma = DMA,
69 .timer = TIMER
70};
71
73const struct neuron_regions NEURON_REGIONS = {
74 .core_params = CORE_PARAMS_REGION,
75 .neuron_params = NEURON_PARAMS_REGION,
76 .current_source_params = CURRENT_SOURCE_PARAMS_REGION,
77 .neuron_recording = NEURON_RECORDING_REGION,
78 .initial_values = INITIAL_VALUES_REGION
79};
80
82// the timer tick callback returning the same value.
83uint32_t time;
84
86static uint32_t timer_period;
87
89static uint32_t simulation_ticks = 0;
90
92static uint32_t infinite_run;
93
95static uint32_t recording_flags = 0;
96
98static uint32_t n_backgrounds_queued = 0;
99
101static uint32_t n_background_overloads = 0;
102
104static uint32_t max_backgrounds_queued = 0;
105
107static uint16_t *ring_buffers;
108
109void synapse_dynamics_process_post_synaptic_event(
110 UNUSED uint32_t time, UNUSED index_t neuron_index) {
111}
112
115static void c_main_store_provenance_data(address_t provenance_region) {
116 struct combined_provenance *prov = (void *) provenance_region;
117 prov->n_background_queue_overloads = n_background_overloads;
119 store_neuron_provenance(&prov->neuron_provenance);
120 local_only_store_provenance(&prov->local_only_provenance);
121}
122
124void resume_callback(void) {
125
126 // Reset recording
128
129 // try resuming neuron
130 if (!neuron_resume(time + 1)) {
131 log_error("failed to resume neuron.");
132 rt_error(RTE_SWERR);
133 }
134}
135
137static inline void process_ring_buffers(void) {
138 uint32_t first_index = synapse_row_get_first_ring_buffer_index(
140 neuron_transfer(&ring_buffers[first_index]);
141
142 // Print the neuron inputs.
143 #if LOG_LEVEL >= LOG_DEBUG
144 log_debug("Inputs");
146 #endif // LOG_LEVEL >= LOG_DEBUG
147}
148
153void background_callback(uint timer_count, uint local_time) {
154 profiler_write_entry_disable_irq_fiq(PROFILER_ENTER | PROFILER_TIMER);
155
156 log_debug("Timer tick %u \n", local_time);
157
158 // Now do neuron time step update
160
161 profiler_write_entry_disable_irq_fiq(PROFILER_EXIT | PROFILER_TIMER);
162 n_backgrounds_queued--;
163}
164
169void timer_callback(uint timer_count, UNUSED uint unused) {
170 // Disable interrupts to stop MC getting in the way of this bit
171 uint32_t state = spin1_int_disable();
172
173 // Increment time step
174 time++;
175
176 // Clear any outstanding spikes
178
179 // Allow things to interrupt again
180 spin1_mode_restore(state);
181
182 // Process ring buffers for the inputs from last time step
183 process_ring_buffers();
184
185 /* if a fixed number of simulation ticks that were specified at startup
186 * then do reporting for finishing */
188
189 // Enter pause and resume state to avoid another tick
190 simulation_handle_pause_resume(resume_callback);
191
192 // Pause neuron processing
193 neuron_pause();
194
195 // Pause common functions
196 common_pause(recording_flags);
197
198 // Subtract 1 from the time so this tick gets done again on the next
199 // run
200 time--;
201
203 return;
204 }
205
206 // Push the rest to the background
207 if (!spin1_schedule_callback(background_callback, timer_count, time, BACKGROUND)) {
208 // We have failed to do this timer tick!
209 n_background_overloads++;
210 } else {
211 n_backgrounds_queued++;
212 if (n_backgrounds_queued > max_backgrounds_queued) {
214 }
215 }
216}
217
221static bool initialise(void) {
222 log_debug("Initialise: started");
223
225 if (!initialise_common_regions(
226 &timer_period, &simulation_ticks, &infinite_run, &time,
227 &recording_flags, c_main_store_provenance_data, timer_callback,
228 COMMON_REGIONS, COMMON_PRIORITIES, &ds_regions)) {
229 return false;
230 }
231
232 // Setup neurons
233 uint32_t n_rec_regions_used;
234 if (!initialise_neuron_regions(
235 ds_regions, NEURON_REGIONS, &n_rec_regions_used)) {
236 return false;
237 }
238
240 data_specification_get_region(LOCAL_ONLY_REGION, ds_regions),
241 data_specification_get_region(LOCAL_ONLY_PARAMS_REGION, ds_regions),
242 n_rec_regions_used, &ring_buffers)) {
243 return false;
244 }
245
246 // Set timer tick (in microseconds)
247 log_debug("setting timer tick callback for %d microseconds", timer_period);
248 spin1_set_timer_tick(timer_period);
249
250 log_debug("Initialise: finished");
251 return true;
252}
253
255void c_main(void) {
256
257 // Start the time at "-1" so that the first tick will be 0
258 time = UINT32_MAX;
259
260 // initialise the model
261 if (!initialise()) {
262 rt_error(RTE_API);
263 }
264
266}
uint32_t index_t
static void c_main_store_provenance_data(address_t provenance_region)
Callback to store provenance data (format: neuron_provenance).
Definition c_main.c:122
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
void resume_callback(void)
the function to call when resuming a simulation
Definition c_main.c:132
static weight_t * ring_buffers
The ring buffers to be used in the simulation.
Definition c_main.c:118
void background_callback(uint timer_count, uint local_time)
Background activities called from timer.
Definition c_main.c:165
const struct common_priorities COMMON_PRIORITIES
Identify the priorities of the common tasks.
Definition c_main.c:67
const struct common_regions COMMON_REGIONS
From the regions, extract those that are common.
Definition c_main.c:59
uint32_t time
The current timer tick value.
Definition c_main.c:94
TIMER
DMA
SDP
callback_priorities
SYSTEM_REGION
uint32_t * address_t
void log_error(const char *message,...)
void log_debug(const char *message,...)
@ BACKGROUND
Background processing.
static uint32_t n_backgrounds_queued
The number of background tasks queued / running.
static uint32_t timer_period
Used for configuring the timer hardware.
static uint32_t max_backgrounds_queued
The maximum number of background tasks queued.
static uint32_t n_background_overloads
The number of times the background couldn't be added.
USER
uint32_t synapse_delay_mask
The mask to get the synaptic delay from a "synapse".
Definition local_only.c:71
void local_only_clear_input(uint32_t time)
Clear the spikes for the last time step.
Definition local_only.c:218
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
void local_only_store_provenance(struct local_only_provenance *prov)
Store provenance gathered during run.
Definition local_only.c:234
bool local_only_initialise(void *local_only_addr, void *local_only_params_addr, uint32_t n_rec_regions_used, uint16_t **ring_buffers_ptr)
Set up local-only processing of spikes.
Definition local_only.c:164
Defines the "local-only" processing of spikes, that is, the processing of spikes without using transf...
@ 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
void recording_reset(void)
void c_main(void)
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)
Tags for profiling of the spike source poisson.
uint spin1_schedule_callback(callback_t cback, uint arg0, uint arg1, uint priority)
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.
implementation for handling the processing of synapse rows.
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.