sPyNNaker neural_modelling 7.1.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
34
38enum {
47};
48
63
66 const connection_generator_info *type;
67 void *data;
68};
69
101
102connection_generator_t connection_generator_init(
103 uint32_t hash, void **in_region) {
104 // Look through the known generators
105 for (uint32_t i = 0; i < N_CONNECTION_GENERATORS; i++) {
107
108 // If the hash requested matches the hash of the generator, use it
109 if (hash == type->hash) {
110 // Prepare a space for the data
111 struct connection_generator *generator =
112 spin1_malloc(sizeof(struct connection_generator));
113 if (generator == NULL) {
114 log_error("Could not create generator");
115 return NULL;
116 }
117
118 // Store the index
119 generator->type = type;
120
121 // Initialise the generator and store the data
122 generator->data = type->initialize(in_region);
123 return generator;
124 }
125 }
126 log_error("Connection generator with hash %u not found", hash);
127 return NULL;
128}
129
131 connection_generator_t generator, uint32_t pre_lo, uint32_t pre_hi,
132 uint32_t post_lo, uint32_t post_hi, uint32_t post_index,
133 uint32_t post_slice_start, uint32_t post_slice_count,
134 unsigned long accum weight_scale, accum timestep_per_delay,
135 param_generator_t weight_generator, param_generator_t delay_generator,
136 matrix_generator_t matrix_generator) {
137 return generator->type->generate(
138 generator->data, pre_lo, pre_hi, post_lo, post_hi, post_index,
139 post_slice_start, post_slice_count, weight_scale, timestep_per_delay,
140 weight_generator, delay_generator, matrix_generator);
141}
142
143void connection_generator_free(connection_generator_t generator) {
144 generator->type->free(generator->data);
145 sark_free(generator);
146}
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_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
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-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.
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