sPyNNaker neural_modelling  7.4.2
c_main_synapses.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 
35 #include "c_main_synapse_common.h"
36 #include "c_main_common.h"
37 #include "spike_processing_fast.h"
39 #include <spin1_api_params.h>
40 
42 typedef enum callback_priorities {
43  MC = -1, DMA = -2, TIMER = 0, SDP = 0
45 
48  struct synapse_provenance synapse_prov;
49  struct spike_processing_fast_provenance spike_processing_prov;
50 };
51 
53 enum regions {
54  SYSTEM_REGION,
55  PROVENANCE_DATA_REGION,
56  PROFILER_REGION,
65  KEY_REGION
66 };
67 
69 const struct common_regions COMMON_REGIONS = {
70  .system = SYSTEM_REGION,
71  .provenance = PROVENANCE_DATA_REGION,
72  .profiler = PROFILER_REGION,
73  .recording = RECORDING_REGION
74 };
75 
77 const struct common_priorities COMMON_PRIORITIES = {
78  .sdp = SDP,
79  .dma = DMA,
80  .timer = TIMER
81 };
82 
84 const struct synapse_regions SYNAPSE_REGIONS = {
86  .synaptic_matrix = SYNAPTIC_MATRIX_REGION,
87  .pop_table = POPULATION_TABLE_REGION,
88  .synapse_dynamics = SYNAPSE_DYNAMICS_REGION,
89  .structural_dynamics = STRUCTURAL_DYNAMICS_REGION,
90  .bitfield_filter = BIT_FIELD_FILTER_REGION
91 };
92 
94 // the timer tick callback returning the same value.
95 uint32_t time;
96 
98 static uint32_t timer_period;
99 
101 static uint32_t simulation_ticks = 0;
102 
104 static uint32_t infinite_run;
105 
107 static uint32_t recording_flags = 0;
108 
111 static void store_provenance_data(address_t provenance_region) {
112  struct provenance_data *prov = (void *) provenance_region;
113  store_synapse_provenance(&prov->synapse_prov);
114  spike_processing_fast_store_provenance(&prov->spike_processing_prov);
115 }
116 
118 void resume_callback(void) {
119 
120  // Reset recording
121  recording_reset();
122 
123  // Resume synapses
124  // NOTE: at reset, time is set to UINT_MAX ahead of timer_callback(...)
125  synapses_resume(time + 1);
126 }
127 
131 void timer_callback(UNUSED uint unused0, UNUSED uint unused1) {
132  time++;
133  if (simulation_is_finished()) {
134  // Enter pause and resume state to avoid another tick
135  simulation_handle_pause_resume(resume_callback);
136 
137  // Pause common functions
138  common_pause(recording_flags);
139 
140  simulation_ready_to_read();
141  return;
142  }
143 
144  uint32_t n_rewires = synaptogenesis_n_updates();
146 }
147 
151 static bool initialise(void) {
152  data_specification_metadata_t *ds_regions;
153  if (!initialise_common_regions(
156  COMMON_REGIONS, COMMON_PRIORITIES, &ds_regions)) {
157  return false;
158  }
159 
160  // Setup synapses
161  uint32_t incoming_spike_buffer_size;
162  uint32_t row_max_n_words;
163  bool clear_input_buffer_of_late_packets;
164  weight_t *ring_buffers;
165  uint32_t n_rec_regions_used = 0;
166  if (!initialise_synapse_regions(
167  ds_regions, SYNAPSE_REGIONS, &ring_buffers, &row_max_n_words,
168  &incoming_spike_buffer_size,
169  &clear_input_buffer_of_late_packets, &n_rec_regions_used)) {
170  return false;
171  }
172 
173  // Setup for writing synaptic inputs at the end of each run
174  struct sdram_config *sdram_config = data_specification_get_region(
175  SDRAM_PARAMS_REGION, ds_regions);
176  struct key_config *key_config = data_specification_get_region(
177  KEY_REGION, ds_regions);
178 
180  row_max_n_words, incoming_spike_buffer_size,
181  clear_input_buffer_of_late_packets, n_rec_regions_used, MC,
183  return false;
184  }
185 
186  // Do bitfield configuration last to only use any unused memory
187  if (!population_table_load_bitfields(data_specification_get_region(
188  SYNAPSE_REGIONS.bitfield_filter, ds_regions))) {
189  return false;
190  }
191 
192  // Set timer tick (in microseconds)
193  log_debug("setting timer tick callback for %d microseconds", timer_period);
194  spin1_set_timer_tick(timer_period);
195 
196  recording_reset();
197 
198  return true;
199 }
200 
202 void c_main(void) {
203 
204  // initialise the model
205  if (!initialise()) {
206  rt_error(RTE_API);
207  }
208 
209  simulation_run();
210 }
callback_priorities
Identify the priorities for all tasks.
Definition: c_main.c:54
static weight_t * ring_buffers
The ring buffers to be used in the simulation.
Definition: c_main.c:118
static uint32_t simulation_ticks
The number of timer ticks to run for before being expected to exit.
callback_priorities
values for the priority for each callback
static void store_provenance_data(address_t provenance_region)
Callback to store provenance data (format: neuron_provenance).
void resume_callback(void)
the function to call when resuming a simulation
static uint32_t recording_flags
The recording flags indicating if anything is recording.
static uint32_t infinite_run
Determines if this model should run for infinite time.
void c_main(void)
The entry point for this model.
const struct synapse_regions SYNAPSE_REGIONS
From the regions, select those that are used for synapse-specific things.
const struct common_priorities COMMON_PRIORITIES
Identify the priority of common tasks.
static bool initialise(void)
Initialises the model by reading in the regions and checking recording data.
static uint32_t timer_period
timer tick period (in microseconds)
const struct common_regions COMMON_REGIONS
From the regions, select those that are common.
void timer_callback(uint unused0, uint unused1)
Timer event callback.
uint32_t time
The current timer tick value.
Provenance data region layout.
@ TIMER
Call timer at 0 to keep it quick.
@ DMA
DMA is not actually used.
@ SDP
SDP handling is queued.
bool population_table_load_bitfields(filter_region_t *filter_region)
Initialise the bitfield filtering system.
@ RECORDING_REGION
general recording data; 15
Definition: regions.h:41
@ BIT_FIELD_FILTER_REGION
bitfield filter; 14
Definition: regions.h:40
@ SYNAPSE_PARAMS_REGION
synapse parameters; 4
Definition: regions.h:30
@ POPULATION_TABLE_REGION
master population table; 5
Definition: regions.h:31
@ SYNAPSE_DYNAMICS_REGION
synapse dynamics; 7
Definition: regions.h:33
@ STRUCTURAL_DYNAMICS_REGION
structural dynamics; 8
Definition: regions.h:34
@ SYNAPTIC_MATRIX_REGION
synaptic matrix; 6
Definition: regions.h:32
@ MC
Multicast message reception is FIQ.
Spike processing fast API.
void spike_processing_fast_time_step_loop(uint32_t time, uint32_t n_rewires)
The main loop of spike processing to be run once per time step. Note that this function will not retu...
void spike_processing_fast_store_provenance(struct spike_processing_fast_provenance *prov)
Store any provenance data gathered from spike processing.
bool spike_processing_fast_initialise(uint32_t row_max_n_words, uint32_t spike_buffer_size, bool discard_late_packets, uint32_t pkts_per_ts_rec_region, uint32_t multicast_priority, struct sdram_config sdram_inputs_param, struct key_config key_config_param, weight_t *ring_buffers_param)
Set up spike processing.
Provenance for spike processing.
@ SDRAM_PARAMS_REGION
SDRAM transfer parameters region.
A region of SDRAM used to transfer synapses.
The callback priorities used by all simulation cores.
Definition: c_main_common.h:46
uint32_t sdp
The SDP callback priority.
Definition: c_main_common.h:48
The identifiers of the regions used by all simulation cores.
Definition: c_main_common.h:34
uint32_t system
Data for general simulation setup.
Definition: c_main_common.h:36
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.
void synapses_resume(timer_t time)
Resume processing of synapses after a pause.
Definition: synapses.c:410
This file contains the main interface for structural plasticity.
uint32_t synaptogenesis_n_updates(void)
Number of updates to do of synaptogenesis this time step.