sPyNNaker neural_modelling 7.1.1
Loading...
Searching...
No Matches
connection_generator_all_to_all.h
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
24#include <stdbool.h>
26
30struct all_to_all {
31 uint32_t allow_self_connections;
32};
33
41 // Allocate the data structure for parameters
42 struct all_to_all *params = spin1_malloc(sizeof(struct all_to_all));
43 struct all_to_all *params_sdram = *region;
44
45 // Copy the parameters into the data structure
46 *params = *params_sdram;
47 *region = &params_sdram[1];
48
49 log_debug("All to all connector, allow_self_connections = %u",
50 params->allow_self_connections);
51
52 return params;
53}
54
59static void connection_generator_all_to_all_free(void *generator) {
60 sark_free(generator);
61}
62
76 void *generator, uint32_t pre_lo, uint32_t pre_hi,
77 uint32_t post_lo, uint32_t post_hi, UNUSED uint32_t post_index,
78 uint32_t post_slice_start, uint32_t post_slice_count,
79 unsigned long accum weight_scale, accum timestep_per_delay,
80 param_generator_t weight_generator, param_generator_t delay_generator,
81 matrix_generator_t matrix_generator) {
82
83 // Get the actual ranges to generate within
84 uint32_t post_start = max(post_slice_start, post_lo);
85 uint32_t post_end = min(post_slice_start + post_slice_count - 1, post_hi);
86
87 struct all_to_all *obj = generator;
88 for (uint32_t pre = pre_lo; pre <= pre_hi; pre++) {
89 for (uint32_t post = post_start; post <= post_end; post++) {
90 if (obj->allow_self_connections || pre != post) {
91 uint32_t local_post = post - post_slice_start;
92 accum weight = param_generator_generate(weight_generator);
93 uint16_t delay = rescale_delay(
94 param_generator_generate(delay_generator), timestep_per_delay);
96 weight, delay, weight_scale)) {
97 log_error("Matrix not sized correctly!");
98 return false;
99 }
100 }
101 }
102 }
103 return true;
104}
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.
The parameters to be passed around for this connector.
void log_error(const char *message,...)
void log_debug(const char *message,...)
General types associated with generators.
static uint16_t rescale_delay(accum delay, accum timestep_per_delay)
Rescales a delay to account for timesteps and type-converts it.
bool matrix_generator_write_synapse(matrix_generator_t generator, uint32_t pre_index, uint16_t post_index, accum weight, uint16_t delay, unsigned long accum weight_scale)
Write a synapse with a matrix generator.
The data for a matrix generator.
accum param_generator_generate(param_generator_t generator)
Generate value with a parameter generator.
void sark_free(void *ptr)
region
spike source array region IDs in human readable form
#define min(a, b)
static stdp_params params
Configuration parameters.