sPyNNaker neural_modelling 7.1.1
Loading...
Searching...
No Matches
matrix_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
21#include "matrix_generator.h"
22#include <spin1_api.h>
23#include <debug.h>
24#include "generator_types.h"
25
30
32enum {
43};
44
65
70 const matrix_generator_info *type;
71 void *data;
72};
73
91
92matrix_generator_t matrix_generator_init(uint32_t hash, void **in_region,
93 void *synaptic_matrix) {
94 // Look through the known generators
95 for (uint32_t i = 0; i < N_MATRIX_GENERATORS; i++) {
97
98 // If the hash requested matches the hash of the generator, use it
99 if (hash == type->hash) {
100 // Prepare a space for the data
101 struct matrix_generator *generator =
102 spin1_malloc(sizeof(struct matrix_generator));
103 if (generator == NULL) {
104 log_error("Could not create generator");
105 return NULL;
106 }
107
108 // Store the index
109 generator->type = type;
110
111 // Initialise the generator and store the data
112 generator->data = type->initialize(in_region, synaptic_matrix);
113 return generator;
114 }
115 }
116 log_error("Matrix generator with hash %u not found", hash);
117 return NULL;
118}
119
120void matrix_generator_free(matrix_generator_t generator) {
121 generator->type->free(generator->data);
122 sark_free(generator);
123}
124
125
127 matrix_generator_t generator,
128 uint32_t pre_index, uint16_t post_index, accum weight, uint16_t delay,
129 unsigned long accum weight_scale) {
130 return generator->type->write_synapse(
131 generator->data, pre_index, post_index, weight, delay, weight_scale);
132}
void log_error(const char *message,...)
Declarations for delay extensions.
General types associated with generators.
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...
void() free_func(void *data)
How to free any data for the generator; all generator types use the same signature of free func.
matrix_generator_t matrix_generator_init(uint32_t hash, void **in_region, void *synaptic_matrix)
Initialise a specific matrix generator.
initialize_matrix_func * initialize
Initialise the generator.
static const struct matrix_generator_info matrix_generators[]
An Array of known generators.
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.
@ PLASTIC_MATRIX_GENERATOR
Generate a synaptic matrix with STDP.
@ NEUROMODULATION_MATRIX_GENERATOR
Generate a synaptic matrix for Neuromodulation.
@ N_MATRIX_GENERATORS
The number of known generators.
@ STATIC_MATRIX_GENERATOR
Generate a pure static synaptic matrix.
generator_hash_t hash
The hash of the generator.
free_func * free
Free any data for the generator.
void matrix_generator_free(matrix_generator_t generator)
Finish with a matrix generator.
write_synapse_func * write_synapse
Generate a row of a matrix with a matrix generator.
The data for a matrix generator.
A "class" for matrix generators.
Interface for matrix generation.
Neuromodulation synaptic matrix implementation.
void * matrix_generator_neuromodulation_initialize(void **region, void *synaptic_matrix)
Initialise the Neuromodulation synaptic matrix generator.
void matrix_generator_neuromodulation_free(void *generator)
Free any data for the STDP synaptic matrix generator.
Static synaptic matrix implementation.
static bool matrix_generator_static_write_synapse(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.
static void matrix_generator_static_free(void *generator)
How to free any data for the static synaptic matrix generator.
static void * matrix_generator_static_initialize(void **region, void *synaptic_matrix)
How to initialise the static synaptic matrix generator.
STDP synaptic matrix implementation.
void * matrix_generator_stdp_initialize(void **region, void *synaptic_matrix)
Initialise the STDP synaptic matrix generator.
void matrix_generator_stdp_free(void *generator)
Free any data for the STDP synaptic matrix generator.
static bool matrix_generator_stdp_write_synapse(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 sark_free(void *ptr)
#define NULL