sPyNNaker neural_modelling 7.1.1
Loading...
Searching...
No Matches
Data Structures | Macros | Enumerations | Functions | Variables
spike_source_poisson.c File Reference

This file contains the main functions for a Poisson spike generator. More...

#include <common/maths-util.h>
#include <common/send_mc.h>
#include <data_specification.h>
#include <recording.h>
#include <debug.h>
#include <normal.h>
#include <simulation.h>
#include <spin1_api.h>
#include <bit_field.h>
#include <stdfix-full-iso.h>
#include <limits.h>
#include <circular_buffer.h>
#include "profile_tags.h"
#include <profiler.h>
#include <wfi.h>

Go to the source code of this file.

Data Structures

struct  spike_source_t
 data structure for Poisson sources More...
 
struct  timed_out_spikes
 data structure for recording spikes More...
 
struct  rng_seed_t
 An RNG seed of 4 words. More...
 
struct  global_parameters
 Parameters of the SpikeSourcePoisson. More...
 
struct  poisson_extension_provenance
 Structure of the provenance data. More...
 
struct  source_info
 Collection of rates to apply over time to a particular spike source. More...
 
struct  source_expand_details
 
struct  source_expand_region
 
struct  sdram_config
 A region of SDRAM used to transfer synapses. More...
 

Macros

#define END_OF_TIME   0xFFFFFFFF
 
#define NUMBER_OF_REGIONS_TO_RECORD   1
 The number of recording regions.
 
#define BYTE_TO_WORD_CONVERTER   4
 Bytes per word.
 
#define ISI_SCALE_FACTOR   1000
 A scale factor to allow the use of integers for "inter-spike intervals".
 

Enumerations

enum  region {
  SYSTEM , POISSON_PARAMS , RATES , SPIKE_HISTORY_REGION ,
  PROVENANCE_REGION , PROFILER_REGION , SDRAM_PARAMS_REGION , EXPANDER_REGION
}
 spike source array region IDs in human readable form More...
 
enum  callback_priorities { MULTICAST = -1 , SDP = 0 , DMA = 1 , TIMER = 2 }
 Priorities for interrupt handlers. More...
 

Functions

static uint32_t rng (void)
 Random number generation for the Poisson sources. This is a local version for speed of operation.
 
static uint32_t n_spikes_poisson_fast (UFRACT exp_minus_lambda)
 How many spikes to generate for a fast Poisson source.
 
static REAL n_steps_until_next (void)
 How many time steps until the next spike for a slow Poisson source.
 
static uint32_t slow_spike_source_get_time_to_spike (uint32_t mean_inter_spike_interval_in_ticks)
 Determine the time in timer ticks multiplied by ISI_SCALE_FACTOR until the next spike is to occur given the mean inter-spike interval.
 
static uint32_t fast_spike_source_get_num_spikes (UFRACT exp_minus_lambda)
 Determine how many spikes to transmit this timer tick, for a fast source.
 
static uint32_t faster_spike_source_get_num_spikes (REAL sqrt_lambda)
 Determine how many spikes to transmit this timer tick, for a faster source (where λ is large enough that a Gaussian can be used instead of a Poisson)
 
void set_spike_source_rate (uint32_t sub_id, unsigned long accum rate)
 Set the spike source rate as required.
 
static void store_provenance_data (address_t provenance_region)
 Writes the provenance data.
 
static uint32_t ms_to_ticks (unsigned long accum ms)
 
static void set_spike_source_details (uint32_t id, bool rate_changed)
 
static bit_field_t out_spikes_bitfield (uint32_t n)
 Set specific spikes for recording.
 
static void reset_spikes (void)
 Reset the spike buffer by clearing the bit field.
 
static void print_spike_source (index_t s)
 Print a spike source.
 
static void print_spike_sources (void)
 Print all spike sources.
 
static bool read_global_parameters (global_parameters *sdram_globals)
 Read the global parameters stored in Poisson parameter region.
 
static void read_next_rates (uint32_t id)
 Get the next chunk of rates read.
 
static bool read_rates (source_info *sdram_sources, bool rate_changed, uint32_t next_time)
 Read the rates of the Poisson.
 
static bool expand_rates (source_expand_region *items, source_info *sdram_sources)
 
static bool initialise_recording (data_specification_metadata_t *ds_regions)
 Initialise the recording parts of the model.
 
static void expand_spike_recording_buffer (uint32_t n_spikes)
 Expand the space for recording spikes.
 
static bool initialize (void)
 Initialise the model by reading in the regions and checking recording data.
 
static void resume_callback (void)
 Run any functions needed at resume time.
 
static void mark_spike (uint32_t neuron_id, uint32_t n_spikes)
 records spikes as needed
 
static void record_spikes (uint32_t time)
 writing spikes to SDRAM
 
static void process_fast_source (index_t s_id, spike_source_t *source)
 Handle a fast spike source.
 
static void process_slow_source (index_t s_id, spike_source_t *source)
 Handle a slow spike source.
 
static void timer_callback (uint timer_count, uint unused)
 Timer interrupt callback.
 
static void multicast_packet_callback (uint key, uint payload)
 Multicast callback used to set rate when injected in a live example.
 
void c_main (void)
 The entry point for this model.
 

Variables

 source_details
 
static uint32_t * keys
 The keys to send spikes with.
 
static global_parameters ssp_params
 The global_parameters for the sub-population.
 
static source_info ** source_data
 Array of pointers to sequences of rate data.
 
static spike_source_tsource
 The currently applied rate descriptors.
 
static uint32_t recording_flags = 0
 keeps track of which types of recording should be done to this model.
 
static uint32_t time
 
static uint32_t simulation_ticks = 0
 the number of timer ticks that this model should run for before exiting.
 
static uint32_t infinite_run
 the int that represents the bool for if the run is infinite or not.
 
static timed_out_spikesspikes = NULL
 The recorded spikes.
 
static uint32_t n_spike_buffers_allocated
 The number of recording spike buffers that have been allocated.
 
static uint32_t n_spike_buffer_words
 The number of words needed for 1 bit per source.
 
static uint32_t spike_buffer_size
 The size of each spike buffer in bytes.
 
static uint32_t timer_period
 The timer period.
 
static struct sdram_configsdram_inputs
 Where synaptic input is to be written.
 
static uint16_t * input_this_timestep
 The inputs to be sent at the end of this timestep.
 
static UREAL ts_per_second
 The timesteps per second.
 
static circular_buffer rate_change_buffer
 Buffer for rate change packets.
 
static uint32_t colour
 The colour of the current time step.
 
static uint32_t colour_mask
 The mask to apply to the time to get the colour.
 

Detailed Description

This file contains the main functions for a Poisson spike generator.

Definition in file spike_source_poisson.c.


Data Structure Documentation

◆ spike_source_t

struct spike_source_t

data structure for Poisson sources

Definition at line 50 of file spike_source_poisson.c.

Data Fields
uint32_t start_ticks When the current control regime starts, in timer ticks.
uint32_t end_ticks When the current control regime ends, in timer ticks.
uint32_t next_ticks When we should load the next control regime, in timer ticks.
uint32_t is_fast_source Flag for whether we're in fast or slow mode.
UFRACT exp_minus_lambda exp(-λ)
REAL sqrt_lambda sqrt(λ)
uint32_t mean_isi_ticks Mean interspike interval, in ticks.
uint32_t time_to_spike_ticks Planned time to spike, in ticks.

◆ timed_out_spikes

struct timed_out_spikes

data structure for recording spikes

Definition at line 71 of file spike_source_poisson.c.

Data Fields
uint32_t time Time of recording.
uint32_t n_buffers Number of spike-recording buffers.
uint32_t out_spikes[] Spike recording buffers; sort of a bit_field_t[].

◆ rng_seed_t

struct rng_seed_t

An RNG seed of 4 words.

Definition at line 112 of file spike_source_poisson.c.

Data Fields
uint32_t x
uint32_t y
uint32_t z
uint32_t c

◆ global_parameters

struct global_parameters

Parameters of the SpikeSourcePoisson.

Definition at line 120 of file spike_source_poisson.c.

Data Fields
uint32_t has_key True if there is a key to transmit, False otherwise.
uint32_t set_rate_neuron_id_mask The mask to work out the neuron ID when setting the rate.
UFRACT seconds_per_tick The time between ticks in seconds for setting the rate.
UREAL ticks_per_ms The number of ticks per millisecond for setting the start and duration.
REAL slow_rate_per_tick_cutoff The border rate between slow and fast sources.
REAL fast_rate_per_tick_cutoff The border rate between fast and faster sources.
uint32_t first_source_id The ID of the first source relative to the population as a whole.
uint32_t n_spike_sources The number of sources in this sub-population.
uint32_t max_spikes_per_tick Maximum expected spikes per tick (for recording)
uint32_t n_colour_bits Number of bits to use for colour.
rng_seed_t spike_source_seed The seed for the Poisson generation process.

◆ poisson_extension_provenance

struct poisson_extension_provenance

Structure of the provenance data.

Definition at line 146 of file spike_source_poisson.c.

Data Fields
uint32_t times_tdma_fell_behind number of times the tdma fell behind its slot

◆ source_info

struct source_info

Collection of rates to apply over time to a particular spike source.

Definition at line 56 of file local_only_conv_impl.c.

Data Fields
key_info key_info Information about the key.
uint32_t source_height_per_core: 16 The source population height per core.
uint32_t source_width_per_core: 16 The source population width per core.
uint32_t source_height_last_core: 16 The source population height on the last core in a column.
uint32_t source_width_last_core: 16 The source population width on the last core on a row.
uint32_t cores_per_source_height: 16 The number cores in a height of the source.
uint32_t cores_per_source_width: 16 Number of cores in a width of the source.
div_const source_width_div Used to calculate division by the source width per core efficiently.
div_const source_width_last_div Division by last core width.
div_const cores_per_width_div Division by cores per source width.
uint32_t n_dims
source_dim source_dim[]
uint32_t n_rates The number of rates.
uint32_t index Where in the array of rate descriptors we are.
source_details details[] Array of rates.

◆ source_expand_details

struct source_expand_details

Definition at line 171 of file spike_source_poisson.c.

Data Fields
uint32_t count The number of items to expand.
source_info info The details for the given number of items.

◆ source_expand_region

struct source_expand_region

Definition at line 178 of file spike_source_poisson.c.

Data Fields
uint32_t rate_changed Determine if any rates have been changed.
uint32_t n_items
source_expand_details items[]

◆ sdram_config

struct sdram_config

A region of SDRAM used to transfer synapses.

Definition at line 87 of file c_main_neurons.c.

Data Fields
uint8_t * address The start address of the input data to be transferred.

The address of the input data to be transferred.

uint32_t size_in_bytes The size of the input data to be transferred per core.

The size of the input data to be transferred.

uint32_t n_synapse_cores The number of synapse cores feeding into here.
uint32_t * address The address of the input data to be transferred.
uint32_t time_for_transfer_overhead The time of the transfer in us.
uint32_t offset

The offset into the data to write the weights (to account for different synapse types)

uint16_t weights[] The weight to send for each active Poisson source.

Macro Definition Documentation

◆ END_OF_TIME

#define END_OF_TIME   0xFFFFFFFF

Definition at line 47 of file spike_source_poisson.c.

◆ NUMBER_OF_REGIONS_TO_RECORD

#define NUMBER_OF_REGIONS_TO_RECORD   1

The number of recording regions.

Definition at line 93 of file spike_source_poisson.c.

◆ BYTE_TO_WORD_CONVERTER

#define BYTE_TO_WORD_CONVERTER   4

Bytes per word.

Definition at line 95 of file spike_source_poisson.c.

◆ ISI_SCALE_FACTOR

#define ISI_SCALE_FACTOR   1000

A scale factor to allow the use of integers for "inter-spike intervals".

Definition at line 97 of file spike_source_poisson.c.

Enumeration Type Documentation

◆ region

enum region

spike source array region IDs in human readable form

Enumerator
SYSTEM 

simulation interface master control

POISSON_PARAMS 

application configuration; global_parameters

RATES 

rates to apply; source_info

SPIKE_HISTORY_REGION 

spike history recording region

PROVENANCE_REGION 

provenance region

PROFILER_REGION 

profiling region

SDRAM_PARAMS_REGION 

SDRAM transfer parameters region.

EXPANDER_REGION 

Expanding of parameters.

Definition at line 81 of file spike_source_poisson.c.

◆ callback_priorities

Priorities for interrupt handlers.

Enumerator
MULTICAST 

Multicast packet reception uses the FIQ.

SDP 

SDP handling is highest ordinary priority.

DMA 

DMA complete handling is medium priority.

TIMER 

Regular timer interrupt is lowest priority.

Definition at line 100 of file spike_source_poisson.c.

Function Documentation

◆ rng()

static uint32_t rng ( void  )
inlinestatic

Random number generation for the Poisson sources. This is a local version for speed of operation.

Returns
A random number

Definition at line 260 of file spike_source_poisson.c.

◆ n_spikes_poisson_fast()

static uint32_t n_spikes_poisson_fast ( UFRACT  exp_minus_lambda)
inlinestatic

How many spikes to generate for a fast Poisson source.

Parameters
[in]exp_minus_lambdae^(-mean_rate)
Returns
How many spikes to generate

Definition at line 276 of file spike_source_poisson.c.

◆ n_steps_until_next()

static REAL n_steps_until_next ( void  )
inlinestatic

How many time steps until the next spike for a slow Poisson source.

Returns
The number of time steps until the next spike

Definition at line 291 of file spike_source_poisson.c.

◆ slow_spike_source_get_time_to_spike()

static uint32_t slow_spike_source_get_time_to_spike ( uint32_t  mean_inter_spike_interval_in_ticks)
inlinestatic

Determine the time in timer ticks multiplied by ISI_SCALE_FACTOR until the next spike is to occur given the mean inter-spike interval.

Parameters
[in]mean_inter_spike_interval_in_ticksThe mean number of ticks before a spike is expected to occur in a slow process.
Returns
"time" in timer ticks * ISI_SCALE_FACTOR until the next spike occurs

Definition at line 318 of file spike_source_poisson.c.

◆ fast_spike_source_get_num_spikes()

static uint32_t fast_spike_source_get_num_spikes ( UFRACT  exp_minus_lambda)
inlinestatic

Determine how many spikes to transmit this timer tick, for a fast source.

Parameters
[in]exp_minus_lambdaexp(-λ), λ is amount of spikes expected to be produced this timer interval (timer tick in real time)
Returns
the number of spikes to transmit this timer tick

Definition at line 334 of file spike_source_poisson.c.

◆ faster_spike_source_get_num_spikes()

static uint32_t faster_spike_source_get_num_spikes ( REAL  sqrt_lambda)
inlinestatic

Determine how many spikes to transmit this timer tick, for a faster source (where λ is large enough that a Gaussian can be used instead of a Poisson)

Parameters
[in]sqrt_lambdaSquare root of the amount of spikes expected to be produced this timer interval (timer tick in real time)
Returns
The number of spikes to transmit this timer tick

Definition at line 350 of file spike_source_poisson.c.

◆ set_spike_source_rate()

void set_spike_source_rate ( uint32_t  sub_id,
unsigned long accum  rate 
)

Set the spike source rate as required.

Parameters
[in]idthe ID of the source to be updated
[in]ratethe rate in Hz, to be multiplied to get per-tick values

Definition at line 363 of file spike_source_poisson.c.

◆ store_provenance_data()

static void store_provenance_data ( address_t  provenance_region)
static

Writes the provenance data.

Parameters
[out]provenance_regionWhere to write the provenance

Definition at line 402 of file spike_source_poisson.c.

◆ ms_to_ticks()

static uint32_t ms_to_ticks ( unsigned long accum  ms)
inlinestatic

Definition at line 411 of file spike_source_poisson.c.

◆ set_spike_source_details()

static void set_spike_source_details ( uint32_t  id,
bool  rate_changed 
)
inlinestatic

Definition at line 415 of file spike_source_poisson.c.

◆ out_spikes_bitfield()

static bit_field_t out_spikes_bitfield ( uint32_t  n)
inlinestatic

Set specific spikes for recording.

Parameters
[in]nthe spike array index
Returns
bit field at the location n

Definition at line 447 of file spike_source_poisson.c.

◆ reset_spikes()

static void reset_spikes ( void  )
inlinestatic

Reset the spike buffer by clearing the bit field.

Definition at line 452 of file spike_source_poisson.c.

◆ print_spike_source()

static void print_spike_source ( index_t  s)
static

Print a spike source.

Parameters
[in]sThe spike source ID

Definition at line 463 of file spike_source_poisson.c.

◆ print_spike_sources()

static void print_spike_sources ( void  )
static

Print all spike sources.

Definition at line 477 of file spike_source_poisson.c.

◆ read_global_parameters()

static bool read_global_parameters ( global_parameters sdram_globals)
static

Read the global parameters stored in Poisson parameter region.

Parameters
[in]sdram_globalsthe absolute SDRAM memory address to which the Poisson parameter region starts.
Returns
Whether the parameters were read successfully.

Definition at line 488 of file spike_source_poisson.c.

◆ read_next_rates()

static void read_next_rates ( uint32_t  id)
inlinestatic

Get the next chunk of rates read.

Parameters
[in]idThe spike source ID

Definition at line 531 of file spike_source_poisson.c.

◆ read_rates()

static bool read_rates ( source_info sdram_sources,
bool  rate_changed,
uint32_t  next_time 
)
static

Read the rates of the Poisson.

Parameters
[in]sdram_sourcesthe configuration in SDRAM
[in]rate_changedwhether any rates have actually changed
[in]next_timethe time which will be the next timestep to run
Returns
Whether the rates were read successfully.

Definition at line 543 of file spike_source_poisson.c.

◆ expand_rates()

static bool expand_rates ( source_expand_region items,
source_info sdram_sources 
)
static

Definition at line 591 of file spike_source_poisson.c.

◆ initialise_recording()

static bool initialise_recording ( data_specification_metadata_t ds_regions)
static

Initialise the recording parts of the model.

Parameters
[in]ds_regionsData specification master descriptor
Returns
Whether recording initialisation is successful

Definition at line 640 of file spike_source_poisson.c.

◆ expand_spike_recording_buffer()

static void expand_spike_recording_buffer ( uint32_t  n_spikes)
inlinestatic

Expand the space for recording spikes.

Parameters
[in]n_spikesNew number of spikes to hold

Definition at line 653 of file spike_source_poisson.c.

◆ initialize()

static bool initialize ( void  )
static

Initialise the model by reading in the regions and checking recording data.

Returns
Whether it successfully read all the regions and set up all its internal data structures.

Definition at line 682 of file spike_source_poisson.c.

◆ resume_callback()

static void resume_callback ( void  )
static

Run any functions needed at resume time.

Definition at line 783 of file spike_source_poisson.c.

◆ mark_spike()

static void mark_spike ( uint32_t  neuron_id,
uint32_t  n_spikes 
)
inlinestatic

records spikes as needed

Parameters
[in]neuron_idthe neurons to store spikes from
[in]n_spikesthe number of times this neuron has spiked

Definition at line 822 of file spike_source_poisson.c.

◆ record_spikes()

static void record_spikes ( uint32_t  time)
inlinestatic

writing spikes to SDRAM

Parameters
[in]timethe time to which these spikes are being recorded

Definition at line 838 of file spike_source_poisson.c.

◆ process_fast_source()

static void process_fast_source ( index_t  s_id,
spike_source_t source 
)
static

Handle a fast spike source.

Parameters
s_idSource ID
sourceSource descriptor

Definition at line 849 of file spike_source_poisson.c.

◆ process_slow_source()

static void process_slow_source ( index_t  s_id,
spike_source_t source 
)
static

Handle a slow spike source.

Parameters
s_idSource ID
sourceSource descriptor

Definition at line 896 of file spike_source_poisson.c.

◆ timer_callback()

static void timer_callback ( uint  timer_count,
uint  unused 
)
static

Timer interrupt callback.

Parameters
[in]timer_countthe number of times this call back has been executed since start of simulation
[in]unusedfor consistency sake of the API always returning two parameters, this parameter has no semantics currently and thus is set to 0

Definition at line 939 of file spike_source_poisson.c.

◆ multicast_packet_callback()

static void multicast_packet_callback ( uint  key,
uint  payload 
)
static

Multicast callback used to set rate when injected in a live example.

Parameters
[in]keyReceived multicast key
[in]payloadReceived multicast payload

Definition at line 1030 of file spike_source_poisson.c.

◆ c_main()

void c_main ( void  )

The entry point for this model.

Definition at line 1043 of file spike_source_poisson.c.

Variable Documentation

◆ source_details

source_details

Definition at line 156 of file spike_source_poisson.c.

◆ keys

uint32_t* keys
static

The keys to send spikes with.

Definition at line 159 of file spike_source_poisson.c.

◆ ssp_params

global_parameters ssp_params
static

The global_parameters for the sub-population.

Definition at line 203 of file spike_source_poisson.c.

◆ source_data

source_info** source_data
static

Array of pointers to sequences of rate data.

Definition at line 206 of file spike_source_poisson.c.

◆ source

spike_source_t* source
static

The currently applied rate descriptors.

Definition at line 209 of file spike_source_poisson.c.

◆ recording_flags

uint32_t recording_flags = 0
static

keeps track of which types of recording should be done to this model.

Definition at line 212 of file spike_source_poisson.c.

◆ time

uint32_t time
static

the time interval parameter TODO this variable could be removed and use the timer tick callback timer value.

Definition at line 216 of file spike_source_poisson.c.

◆ simulation_ticks

uint32_t simulation_ticks = 0
static

the number of timer ticks that this model should run for before exiting.

Definition at line 219 of file spike_source_poisson.c.

◆ infinite_run

uint32_t infinite_run
static

the int that represents the bool for if the run is infinite or not.

Definition at line 222 of file spike_source_poisson.c.

◆ spikes

timed_out_spikes* spikes = NULL
static

The recorded spikes.

Definition at line 225 of file spike_source_poisson.c.

◆ n_spike_buffers_allocated

uint32_t n_spike_buffers_allocated
static

The number of recording spike buffers that have been allocated.

Definition at line 228 of file spike_source_poisson.c.

◆ n_spike_buffer_words

uint32_t n_spike_buffer_words
static

The number of words needed for 1 bit per source.

Definition at line 231 of file spike_source_poisson.c.

◆ spike_buffer_size

uint32_t spike_buffer_size
static

The size of each spike buffer in bytes.

Definition at line 234 of file spike_source_poisson.c.

◆ timer_period

uint32_t timer_period
static

The timer period.

Definition at line 237 of file spike_source_poisson.c.

◆ sdram_inputs

struct sdram_config* sdram_inputs
static

Where synaptic input is to be written.

Definition at line 240 of file spike_source_poisson.c.

◆ input_this_timestep

uint16_t* input_this_timestep
static

The inputs to be sent at the end of this timestep.

Definition at line 243 of file spike_source_poisson.c.

◆ ts_per_second

UREAL ts_per_second
static

The timesteps per second.

Definition at line 246 of file spike_source_poisson.c.

◆ rate_change_buffer

circular_buffer rate_change_buffer
static

Buffer for rate change packets.

Definition at line 249 of file spike_source_poisson.c.

◆ colour

uint32_t colour
static

The colour of the current time step.

Definition at line 252 of file spike_source_poisson.c.

◆ colour_mask

uint32_t colour_mask
static

The mask to apply to the time to get the colour.

Definition at line 255 of file spike_source_poisson.c.