sPyNNaker neural_modelling  7.4.2
synapse_row.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2015 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 
88 #ifndef _SYNAPSE_ROW_H_
89 #define _SYNAPSE_ROW_H_
90 
91 #include <common/neuron-typedefs.h>
92 
94 #ifndef SYNAPSE_WEIGHT_BITS
95 #define SYNAPSE_WEIGHT_BITS 16
96 #endif
97 
98 #ifdef SYNAPSE_WEIGHTS_SIGNED
100 typedef __int_t(SYNAPSE_WEIGHT_BITS) weight_t;
101 #else
103 typedef __uint_t(SYNAPSE_WEIGHT_BITS) weight_t;
104 #endif
106 typedef uint16_t control_t;
107 
109 #define N_SYNAPSE_ROW_HEADER_WORDS 3
110 
112 typedef struct {
113  size_t size;
114  uint32_t data[];
116 
118 typedef struct {
119  size_t num_fixed;
120  size_t num_plastic;
121  uint32_t data[];
123 
125 
129 static inline size_t synapse_row_plastic_size(const synaptic_row_t row) {
130  const synapse_row_plastic_part_t *the_row =
131  (const synapse_row_plastic_part_t *) row;
132  return the_row->size;
133 }
134 
139  synaptic_row_t row) {
141  return (synapse_row_plastic_data_t *) the_row->data;
142 }
143 
148  synaptic_row_t row) {
150  return (synapse_row_fixed_part_t *) &the_row->data[the_row->size];
151 }
152 
156 static inline size_t synapse_row_num_fixed_synapses(
157  const synapse_row_fixed_part_t *fixed) {
158  return fixed->num_fixed;
159 }
160 
164 static inline size_t synapse_row_num_plastic_controls(
165  const synapse_row_fixed_part_t *fixed) {
166  return fixed->num_plastic;
167 }
168 
173  synapse_row_fixed_part_t *fixed) {
174  return (control_t *) &fixed->data[fixed->num_fixed];
175 }
176 
180 static inline uint32_t *synapse_row_fixed_weight_controls(
181  synapse_row_fixed_part_t *fixed) {
182  return fixed->data;
183 }
184 
185 // The following are offset calculations into the ring buffers
190 static inline index_t synapse_row_sparse_index(
191  uint32_t x, uint32_t synapse_index_mask) {
192  return x & synapse_index_mask;
193 }
194 
201 static inline index_t synapse_row_sparse_type(
202  uint32_t x, uint32_t synapse_index_bits, uint32_t synapse_type_mask) {
203  return (x >> synapse_index_bits) & synapse_type_mask;
204 }
205 
211 static inline index_t synapse_row_sparse_type_index(
212  uint32_t x, uint32_t synapse_type_index_mask) {
213  return x & synapse_type_index_mask;
214 }
215 
222 static inline index_t synapse_row_sparse_delay(
223  uint32_t x, uint32_t synapse_type_index_bits, uint32_t synapse_delay_mask) {
225 }
226 
230 static inline weight_t synapse_row_sparse_weight(uint32_t x) {
231  return x >> (32 - SYNAPSE_WEIGHT_BITS);
232 }
233 
239  weight_t weight, uint32_t left_shift) {
240  union {
241  int_k_t input_type;
242  s1615 output_type;
243  } converter;
244 
245  converter.input_type = (int_k_t) (weight) << left_shift;
246 
247  return converter.output_type;
248 }
249 
259 static inline index_t synapse_row_get_ring_buffer_index(
260  uint32_t simulation_timestep, uint32_t synapse_type_index,
261  uint32_t neuron_index, uint32_t synapse_type_index_bits,
262  uint32_t synapse_index_bits, uint32_t synapse_delay_mask) {
263  return ((simulation_timestep & synapse_delay_mask) << synapse_type_index_bits)
264  | (synapse_type_index << synapse_index_bits)
265  | neuron_index;
266 }
267 
275  uint32_t synapse_type_index, uint32_t neuron_index,
276  uint32_t synapse_index_bits) {
277  return (synapse_type_index << synapse_index_bits) | neuron_index;
278 }
279 
286  uint32_t simulation_timestep, uint32_t synapse_type_index_bits,
287  int32_t synapse_delay_mask) {
288  return (simulation_timestep & synapse_delay_mask) << synapse_type_index_bits;
289 }
290 
299  uint32_t simulation_timestep,
300  uint32_t combined_synapse_neuron_index,
301  uint32_t synapse_type_index_bits, uint32_t synapse_delay_mask) {
302  return ((simulation_timestep & synapse_delay_mask) << synapse_type_index_bits)
303  | combined_synapse_neuron_index;
304 }
305 
306 #endif // SYNAPSE_ROW_H
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
uint32_t synapse_index_bits
The number of bits used by just the post-neuron index.
Definition: local_only.c:77
Data type definitions for SpiNNaker Neuron-modelling.
struct synaptic_row * synaptic_row_t
The type of a synaptic row.
REAL input_t
The type of an input.
The format of the plastic data region of a synaptic row.
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.
Definition: synapse_row.h:285
uint32_t data[]
The data, first the fixed then the plastic.
Definition: synapse_row.h:121
static size_t synapse_row_num_plastic_controls(const synapse_row_fixed_part_t *fixed)
Get the number of plastic controls in the row.
Definition: synapse_row.h:164
static uint32_t * synapse_row_fixed_weight_controls(synapse_row_fixed_part_t *fixed)
The array of fixed weights in the row.
Definition: synapse_row.h:180
static synapse_row_fixed_part_t * synapse_row_fixed_region(synaptic_row_t row)
Get the address of the non-plastic (or fixed) region.
Definition: synapse_row.h:147
size_t size
The number of plastic words in data
Definition: synapse_row.h:113
#define SYNAPSE_WEIGHT_BITS
how many bits the synapse weight will take
Definition: synapse_row.h:95
static index_t synapse_row_sparse_type(uint32_t x, uint32_t synapse_index_bits, uint32_t synapse_type_mask)
Get the type code.
Definition: synapse_row.h:201
static size_t synapse_row_num_fixed_synapses(const synapse_row_fixed_part_t *fixed)
Get the number of fixed synapses in the row.
Definition: synapse_row.h:156
static index_t synapse_row_get_ring_buffer_index_combined(uint32_t simulation_timestep, uint32_t combined_synapse_neuron_index, uint32_t synapse_type_index_bits, uint32_t synapse_delay_mask)
Get the index of the ring buffer for a given timestep and combined synapse type and neuron index (as ...
Definition: synapse_row.h:298
static index_t synapse_row_sparse_index(uint32_t x, uint32_t synapse_index_mask)
Get the index.
Definition: synapse_row.h:190
static control_t * synapse_row_plastic_controls(synapse_row_fixed_part_t *fixed)
Get the array of plastic controls in the row.
Definition: synapse_row.h:172
static index_t synapse_row_sparse_delay(uint32_t x, uint32_t synapse_type_index_bits, uint32_t synapse_delay_mask)
Get the delay from an encoded synapse descriptor.
Definition: synapse_row.h:222
size_t num_plastic
The number of plastic controls in data
Definition: synapse_row.h:120
static index_t synapse_row_sparse_type_index(uint32_t x, uint32_t synapse_type_index_mask)
Get the type and index.
Definition: synapse_row.h:211
static synapse_row_plastic_data_t * synapse_row_plastic_region(synaptic_row_t row)
Get the address of the plastic region.
Definition: synapse_row.h:138
static size_t synapse_row_plastic_size(const synaptic_row_t row)
Get the size of the plastic region.
Definition: synapse_row.h:129
size_t num_fixed
The number of fixed synapses in data
Definition: synapse_row.h:119
static index_t synapse_row_get_ring_buffer_index(uint32_t simulation_timestep, uint32_t synapse_type_index, uint32_t neuron_index, uint32_t synapse_type_index_bits, uint32_t synapse_index_bits, uint32_t synapse_delay_mask)
Get the index of the ring buffer for a given timestep, synapse type and neuron index.
Definition: synapse_row.h:259
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.
Definition: synapse_row.h:238
uint16_t control_t
Define the type of the control data.
Definition: synapse_row.h:106
static weight_t synapse_row_sparse_weight(uint32_t x)
Get the weight from an encoded synapse descriptor.
Definition: synapse_row.h:230
uint32_t data[]
The plastic words, followed by the fixed part.
Definition: synapse_row.h:114
static index_t synapse_row_get_ring_buffer_index_time_0(uint32_t synapse_type_index, uint32_t neuron_index, uint32_t synapse_index_bits)
Get the index of the ring buffer for time 0, synapse type and neuron index.
Definition: synapse_row.h:274
The type of the fixed part of the row. The fixed-plastic part follows.
Definition: synapse_row.h:118
The type of the plastic-plastic part of the row.
Definition: synapse_row.h:112
uint32_t synapse_index_mask
Mask to pick out the synapse index.
Definition: synapses.c:69
uint32_t synapse_type_index_mask
Mask to pick out the synapse type and index.
Definition: synapses.c:65
uint32_t synapse_type_mask
Mask to pick out the synapse type.
Definition: synapses.c:73