sPyNNaker neural_modelling 7.1.1
Loading...
Searching...
No Matches
generator_types.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2019 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
22#ifndef INCLUDED_GENERATOR_TYPES_H
23#define INCLUDED_GENERATOR_TYPES_H
24
25#include <common-typedefs.h>
26#include <spin1_api.h>
27#include "param_generator.h"
28#include "matrix_generator.h"
29
30#ifndef UNUSED
31#define UNUSED __attribute__((__unused__))
32#endif
33
38typedef uint32_t generator_hash_t;
39
46typedef void* (initialize_param_func)(void **region);
47
54typedef void* (initialize_connector_func)(void **region);
55
63typedef void* (initialize_matrix_func)(void **region, void *synaptic_matrix);
64
70typedef void (free_func)(void *data);
71
77typedef accum (generate_param_func)(void *generator);
78
90typedef bool (write_synapse_func)(void *generator,
91 uint32_t pre_index, uint16_t post_index, accum weight, uint16_t delay,
92 unsigned long accum weight_scale);
93
114 void *generator, uint32_t pre_lo, uint32_t pre_hi,
115 uint32_t post_lo, uint32_t post_hi, uint32_t post_index,
116 uint32_t post_slice_start, uint32_t post_slice_count,
117 unsigned long accum weight_scale, accum timestep_per_delay,
118 param_generator_t weight_generator, param_generator_t delay_generator,
119 matrix_generator_t matrix_generator);
120
125static inline uint16_t rescale_delay(accum delay, accum timestep_per_delay) {
126 accum ts_delay = delay * timestep_per_delay;
127 if (ts_delay < 0) {
128 ts_delay = 1;
129 }
130 uint16_t delay_int = (uint16_t) ts_delay;
131 if (ts_delay != delay_int) {
132 log_debug("Rounded delay %k to %u", delay, delay_int);
133 }
134 return delay_int;
135}
136
142static inline uint16_t rescale_weight(accum weight, unsigned long accum weight_scale) {
143 unsigned long accum uweight = 0;
144 if (weight < 0) {
145 uweight = -weight;
146 } else {
147 uweight = weight;
148 }
149 unsigned long accum weight_scaled = uweight * weight_scale;
150 unsigned long accum weight_rounded = roundulk(weight_scaled, 32);
151 uint16_t weight_int = (uint16_t) (bitsulk(weight_rounded) >> 32);
152 if (weight_scaled != weight_int) {
153 log_debug("Rounded weight %k to %u (scale is %k)",
154 weight_scaled, weight_int, weight_scale);
155 }
156 return weight_int;
157}
158
159#define max(a, b) (a > b? a: b)
160
161#endif //INCLUDED_GENERATOR_TYPES_H
void log_debug(const char *message,...)
void *() initialize_connector_func(void **region)
How to initialise the connection generator.
bool() write_synapse_func(void *generator, uint32_t pre_index, uint16_t post_index, accum weight, uint16_t delay, unsigned long accum weight_scale)
How to write a synapse to a matrix.
void *() initialize_matrix_func(void **region, void *synaptic_matrix)
How to initialise the matrix generator.
uint32_t generator_hash_t
The type of values used to indicate the subtype of generator to create. Must match the constants on t...
static uint16_t rescale_weight(accum weight, unsigned long accum weight_scale)
Rescales a weight to account for weight granularity and type-converts it.
void() free_func(void *data)
How to free any data for the generator; all generator types use the same signature of free func.
static uint16_t rescale_delay(accum delay, accum timestep_per_delay)
Rescales a delay to account for timesteps and type-converts it.
bool() generate_connection_func(void *generator, uint32_t pre_lo, uint32_t pre_hi, uint32_t post_lo, uint32_t post_hi, uint32_t post_index, uint32_t post_slice_start, uint32_t post_slice_count, unsigned long accum weight_scale, accum timestep_per_delay, param_generator_t weight_generator, param_generator_t delay_generator, matrix_generator_t matrix_generator)
How to generate connections with a connection generator.
accum() generate_param_func(void *generator)
How to generate values with a parameter generator.
void *() initialize_param_func(void **region)
How to initialise the param generator.
The data for a matrix generator.
Interface for matrix generation.
Interface for parameter generator.
region
spike source array region IDs in human readable form