sPyNNaker neural_modelling  7.4.2
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 
31 
33 enum {
46 };
47 
51 typedef struct matrix_generator_info {
58 
61 
64 
68 
73  const matrix_generator_info *type;
74  void *data;
75 };
76 
80 static const struct matrix_generator_info matrix_generators[] = {
91  matrix_generator_neuromodulation_write_synapse,
95  matrix_generator_changer_write_synapse,
97 };
98 
99 matrix_generator_t matrix_generator_init(uint32_t hash, void **in_region,
100  void *synaptic_matrix) {
101  // Look through the known generators
102  for (uint32_t i = 0; i < N_MATRIX_GENERATORS; i++) {
103  const matrix_generator_info *type = &matrix_generators[i];
104 
105  // If the hash requested matches the hash of the generator, use it
106  if (hash == type->hash) {
107  // Prepare a space for the data
108  struct matrix_generator *generator =
109  spin1_malloc(sizeof(struct matrix_generator));
110  if (generator == NULL) {
111  log_error("Could not create generator");
112  return NULL;
113  }
114 
115  // Store the index
116  generator->type = type;
117 
118  // Initialise the generator and store the data
119  generator->data = type->initialize(in_region, synaptic_matrix);
120  return generator;
121  }
122  }
123  log_error("Matrix generator with hash %u not found", hash);
124  return NULL;
125 }
126 
127 void matrix_generator_free(matrix_generator_t generator) {
128  generator->type->free(generator->data);
129  sark_free(generator);
130 }
131 
132 
134  matrix_generator_t generator,
135  uint32_t pre_index, uint16_t post_index, accum weight, uint16_t delay,
136  unsigned long accum weight_scale) {
137  return generator->type->write_synapse(
138  generator->data, pre_index, post_index, weight, delay, weight_scale);
139 }
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.
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 *() initialize_matrix_func(void **region, void *synaptic_matrix)
How to initialise the matrix generator.
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.
@ WEIGHT_CHANGER_MATRIX_GENERATOR
Generate a synaptic matrix for weight change.
@ 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_free(void *generator)
Free any data for the STDP synaptic matrix generator.
void * matrix_generator_neuromodulation_initialize(void **region, void *synaptic_matrix)
Initialise the Neuromodulation 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.
Weight-changer synaptic matrix implementation.
void * matrix_generator_changer_initialize(void **region, void *synaptic_matrix)
Initialise the Changer synaptic matrix generator.
void matrix_generator_changer_free(void *generator)
Free any data for the matrix generator.