sPyNNaker neural_modelling 7.3.1
Loading...
Searching...
No Matches
connection_generator.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
23#include <spin1_api.h>
24#include <debug.h>
25#include "generator_types.h"
26
36
40enum {
51};
52
67
70 const connection_generator_info *type;
71 void *data;
72};
73
113
114connection_generator_t connection_generator_init(
115 uint32_t hash, void **in_region) {
116 // Look through the known generators
117 for (uint32_t i = 0; i < N_CONNECTION_GENERATORS; i++) {
119
120 // If the hash requested matches the hash of the generator, use it
121 if (hash == type->hash) {
122 // Prepare a space for the data
123 struct connection_generator *generator =
124 spin1_malloc(sizeof(struct connection_generator));
125 if (generator == NULL) {
126 log_error("Could not create generator");
127 return NULL;
128 }
129
130 // Store the index
131 generator->type = type;
132
133 // Initialise the generator and store the data
134 generator->data = type->initialize(in_region);
135 return generator;
136 }
137 }
138 log_error("Connection generator with hash %u not found", hash);
139 return NULL;
140}
141
143 connection_generator_t generator, uint32_t pre_lo, uint32_t pre_hi,
144 uint32_t post_lo, uint32_t post_hi, uint32_t post_index,
145 uint32_t post_slice_start, uint32_t post_slice_count,
146 unsigned long accum weight_scale, accum timestep_per_delay,
147 param_generator_t weight_generator, param_generator_t delay_generator,
148 matrix_generator_t matrix_generator) {
149 return generator->type->generate(
150 generator->data, pre_lo, pre_hi, post_lo, post_hi, post_index,
151 post_slice_start, post_slice_count, weight_scale, timestep_per_delay,
152 weight_generator, delay_generator, matrix_generator);
153}
154
155void connection_generator_free(connection_generator_t generator) {
156 generator->type->free(generator->data);
157 sark_free(generator);
158}
initialize_connector_func * initialize
Initialises the generator.
connection_generator_t connection_generator_init(uint32_t hash, void **in_region)
Initialise a specific connection generator.
bool connection_generator_generate(connection_generator_t 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)
Generate connections with a connection generator.
@ ALL_BUT_ME
AllButMe connection generator.
@ ALL_TO_ALL
All-to-all connection generator.
@ KERNEL
Convolution kernel connection generator.
@ FIXED_TOTAL
Fixed total connections connection generator.
@ FIXED_PROBABILITY
Fixed probability connection generator.
@ FIXED_POST
Fixed post-size connection generator.
@ FIXED_PRE
Fixed pre-size connection generator.
@ N_CONNECTION_GENERATORS
The number of known generators.
@ ONE_TO_ONE_OFFSET
One-to-one offset connection generator.
@ ONE_TO_ONE
One-to-one connection generator.
static const connection_generator_info connection_generators[]
An Array of known generators.
free_func * free
Frees any data for the generator.
void connection_generator_free(connection_generator_t generator)
Finish with a connection generator.
generate_connection_func * generate
Generate connections.
generator_hash_t hash
The hash of the generator.
The data for a connection generator.
A "class" for connection generators.
Connection Generator interface.
All But Me connection generator implementation.
static void connection_generator_all_but_me_free(void *generator)
Free the All But Me connection generator.
static void * connection_generator_all_but_me_initialise(void **region)
Initialise the all but me connection generator.
static bool connection_generator_all_but_me_generate(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)
Generate connections with the all but me connection generator.
All-to-All connection generator implementation.
static void * connection_generator_all_to_all_initialise(void **region)
Initialise the all-to-all connection generator.
static void connection_generator_all_to_all_free(void *generator)
Free the all-to-all connection generator.
static bool connection_generator_all_to_all_generate(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)
Generate connections with the all-to-all connection generator.
Fixed-Number-Post (fan-out) Connection generator implementation.
static void * connection_generator_fixed_post_initialise(void **region)
Initialise the fixed-post connection generator.
static bool connection_generator_fixed_post_generate(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)
Generate connections with the fixed-post connection generator.
static void connection_generator_fixed_post_free(void *generator)
Free the fixed-post connection generator.
Fixed-Number-Pre (fan-in) Connection generator implementation.
static void * connection_generator_fixed_pre_initialise(void **region)
Initialise the fixed-pre connection generator.
bool connection_generator_fixed_pre_generate(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)
Generate connections with the fixed-pre connection generator.
void connection_generator_fixed_pre_free(void *generator)
Free the fixed-pre connection generator.
Fixed-Probability Connection generator implementation.
static void * connection_generator_fixed_prob_initialise(void **region)
Initialise the fixed-probability connection generator.
static bool connection_generator_fixed_prob_generate(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)
Generate connections with the fixed-probability connection generator.
static void connection_generator_fixed_prob_free(void *generator)
Free the fixed-probability connection generator.
Fixed-Total-Number (Multapse) Connection generator implementation.
static void connection_generator_fixed_total_free(void *generator)
Free the fixed-total connection generator.
static void * connection_generator_fixed_total_initialise(void **region)
Draw from a binomial distribution i.e. with replacement.
static bool connection_generator_fixed_total_generate(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)
Generate connections with the fixed-total connection generator.
Kernel connection generator implementation.
static void connection_generator_kernel_free(void *generator)
Free the convolution-kernel connection generator.
static void * connection_generator_kernel_initialise(void **region)
Initialise the convolution-kernel connection generator.
static bool connection_generator_kernel_generate(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)
Generate connections with the convolution-kernel connection generator.
One-to-One Connection generator implementation.
static bool connection_generator_one_to_one_generate(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)
Generate connections with the one-to-one connection generator.
static void connection_generator_one_to_one_free(void *generator)
Free the one-to-one connection generator.
static void * connection_generator_one_to_one_initialise(void **region)
Initialise the one-to-one connection generator.
one_to_one_offset Connection generator implementation
static bool connection_generator_one_to_one_offset_generate(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)
Generate connections with the one_to_one_offset connection generator.
static void connection_generator_one_to_one_offset_free(void *generator)
Free the one_to_one_offset connection generator.
static void * connection_generator_one_to_one_offset_initialise(void **region)
Initialise the one_to_one_offset connection generator.
void log_error(const char *message,...)
General types associated with generators.
void *() initialize_connector_func(void **region)
How to initialise the connection 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...
void() free_func(void *data)
How to free any data for the generator; all generator types use the same signature of free func.
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.
The data for a matrix generator.
void sark_free(void *ptr)
#define NULL