Skip to content

Commit caf7e4b

Browse files
authored
Merge pull request #930 from SpiNNakerManchester/stdp-config-structs
Use structures to describe STDP config
2 parents 265b44d + 7496f21 commit caf7e4b

7 files changed

Lines changed: 115 additions & 66 deletions

File tree

neural_modelling/src/neuron/plasticity/stdp/timing_dependence/timing_recurrent_dual_fsm_impl.c

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,32 +32,41 @@ uint16_t post_exp_dist_lookup[STDP_FIXED_POINT_ONE];
3232
// Global plasticity parameter data
3333
plasticity_trace_region_data_t plasticity_trace_region_data;
3434

35+
//! How the configuration data for dual_fsm is laid out in SDRAM.
36+
typedef struct {
37+
int32_t accumulator_depression_plus_one;
38+
int32_t accumulator_potentiation_minus_one;
39+
uint16_t pre_exp_dist_lookup[STDP_FIXED_POINT_ONE];
40+
uint16_t post_exp_dist_lookup[STDP_FIXED_POINT_ONE];
41+
uint32_t following_data[];
42+
} dual_fsm_config_t;
43+
3544
//---------------------------------------
3645
// Functions
3746
//---------------------------------------
3847
uint32_t *timing_initialise(address_t address) {
3948
log_info("timing_initialise: starting");
4049
log_info("\tRecurrent dual-FSM STDP rule");
50+
dual_fsm_config_t *config = (dual_fsm_config_t *) address;
4151

4252
// Copy plasticity region data from address
4353
// **NOTE** this seems somewhat safer than relying on sizeof
4454
plasticity_trace_region_data.accumulator_depression_plus_one =
45-
(int32_t) address[0];
55+
config->accumulator_depression_plus_one;
4656
plasticity_trace_region_data.accumulator_potentiation_minus_one =
47-
(int32_t) address[1];
57+
config->accumulator_potentiation_minus_one;
4858

4959
log_info("\tAccumulator depression=%d, Accumulator potentiation=%d",
5060
plasticity_trace_region_data.accumulator_depression_plus_one - 1,
5161
plasticity_trace_region_data.accumulator_potentiation_minus_one + 1);
5262

5363
// Copy LUTs from following memory
54-
uint32_t word_size = STDP_FIXED_POINT_ONE / 2;
55-
spin1_memcpy(pre_exp_dist_lookup, &address[2],
56-
STDP_FIXED_POINT_ONE * sizeof(uint16_t));
57-
spin1_memcpy(post_exp_dist_lookup, &address[2 + word_size],
58-
STDP_FIXED_POINT_ONE * sizeof(uint16_t));
64+
spin1_memcpy(pre_exp_dist_lookup, config->pre_exp_dist_lookup,
65+
sizeof(config->pre_exp_dist_lookup));
66+
spin1_memcpy(post_exp_dist_lookup, config->post_exp_dist_lookup,
67+
sizeof(config->post_exp_dist_lookup));
5968

6069
log_info("timing_initialise: completed successfully");
6170

62-
return &address[2 + word_size + word_size];
71+
return config->following_data;
6372
}

neural_modelling/src/neuron/plasticity/stdp/timing_dependence/timing_recurrent_pre_stochastic_impl.c

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -33,33 +33,41 @@ uint16_t post_exp_dist_lookup[STDP_FIXED_POINT_ONE];
3333
//! Global plasticity parameter data
3434
plasticity_trace_region_data_t plasticity_trace_region_data;
3535

36+
//! How the configuration data for pre_stochastic is laid out in SDRAM.
37+
typedef struct {
38+
int32_t accumulator_depression_plus_one;
39+
int32_t accumulator_potentiation_minus_one;
40+
uint16_t pre_exp_dist_lookup[STDP_FIXED_POINT_ONE];
41+
uint16_t post_exp_dist_lookup[STDP_FIXED_POINT_ONE];
42+
uint32_t following_data[];
43+
} pre_stochastic_config_t;
44+
3645
//---------------------------------------
3746
// Functions
3847
//---------------------------------------
3948
address_t timing_initialise(address_t address) {
4049
log_debug("timing_initialise: starting");
4150
log_debug("\tRecurrent pre-calculated stochastic STDP rule");
51+
pre_stochastic_config_t *config = (pre_stochastic_config_t *) address;
4252

4353
// Copy plasticity region data from address
4454
// **NOTE** this seems somewhat safer than relying on sizeof
4555
plasticity_trace_region_data.accumulator_depression_plus_one =
46-
(int32_t) address[0];
56+
config->accumulator_depression_plus_one;
4757
plasticity_trace_region_data.accumulator_potentiation_minus_one =
48-
(int32_t) address[1];
58+
config->accumulator_potentiation_minus_one;
4959

5060
log_debug("\tAccumulator depression=%d, Accumulator potentiation=%d",
5161
plasticity_trace_region_data.accumulator_depression_plus_one - 1,
5262
plasticity_trace_region_data.accumulator_potentiation_minus_one + 1);
5363

5464
// Copy LUTs from following memory
55-
// Copy LUTs from following memory
56-
uint32_t word_size = STDP_FIXED_POINT_ONE / 2;
57-
spin1_memcpy(pre_exp_dist_lookup, &address[2],
58-
STDP_FIXED_POINT_ONE * sizeof(uint16_t));
59-
spin1_memcpy(post_exp_dist_lookup, &address[2 + word_size],
60-
STDP_FIXED_POINT_ONE * sizeof(uint16_t));
65+
spin1_memcpy(pre_exp_dist_lookup, config->pre_exp_dist_lookup,
66+
sizeof(config->pre_exp_dist_lookup));
67+
spin1_memcpy(post_exp_dist_lookup, config->post_exp_dist_lookup,
68+
sizeof(config->post_exp_dist_lookup));
6169

6270
log_debug("timing_initialise: completed successfully");
6371

64-
return &address[2 + word_size + word_size];
72+
return config->following_data;
6573
}

neural_modelling/src/neuron/plasticity/stdp/timing_dependence/timing_vogels_2011_impl.c

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,18 +28,25 @@ int16_lut *tau_lookup;
2828
//! Global plasticity parameter data
2929
plasticity_trace_region_data_t plasticity_trace_region_data;
3030

31+
//! How the configuration data for vogels_2011 is laid out in SDRAM.
32+
typedef struct {
33+
int32_t alpha;
34+
uint32_t lut_data[];
35+
} vogels_2011_config_t;
36+
3137
//---------------------------------------
3238
// Functions
3339
//---------------------------------------
3440
address_t timing_initialise(address_t address) {
3541
log_info("timing_initialise: starting");
3642
log_info("\tVogels 2011 timing rule");
43+
vogels_2011_config_t *config = (vogels_2011_config_t *) address;
3744

3845
// Copy parameters
39-
plasticity_trace_region_data.alpha = (int32_t) address[0];
46+
plasticity_trace_region_data.alpha = config->alpha;
4047

4148
// Copy LUTs from following memory
42-
address_t lut_address = &address[1];
49+
address_t lut_address = config->lut_data;
4350
tau_lookup = maths_copy_int16_lut(&lut_address);
4451

4552
log_info("timing_initialise: completed successfully");

neural_modelling/src/neuron/plasticity/stdp/weight_dependence/weight_additive_one_term_impl.c

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,15 @@
2525
//! Global plasticity parameter data
2626
plasticity_weight_region_data_t *plasticity_weight_region_data;
2727

28+
//! \brief How the configuration data for additive_one_term is laid out in
29+
//! SDRAM. The layout is an array of these.
30+
typedef struct {
31+
int32_t min_weight;
32+
int32_t max_weight;
33+
int32_t a2_plus;
34+
int32_t a2_minus;
35+
} additive_one_term_config_t;
36+
2837
//---------------------------------------
2938
// Functions
3039
//---------------------------------------
@@ -36,27 +45,26 @@ address_t weight_initialise(
3645

3746
// Copy plasticity region data from address
3847
// **NOTE** this seems somewhat safer than relying on sizeof
39-
int32_t *plasticity_word = (int32_t *) address;
40-
plasticity_weight_region_data =
48+
additive_one_term_config_t *config = (additive_one_term_config_t *) address;
49+
50+
plasticity_weight_region_data_t *dtcm_copy = plasticity_weight_region_data =
4151
spin1_malloc(sizeof(plasticity_weight_region_data_t) * n_synapse_types);
42-
if (plasticity_weight_region_data == NULL) {
52+
if (dtcm_copy == NULL) {
4353
log_error("Could not initialise weight region data");
4454
return NULL;
4555
}
46-
for (uint32_t s = 0; s < n_synapse_types; s++) {
47-
plasticity_weight_region_data[s].min_weight = *plasticity_word++;
48-
plasticity_weight_region_data[s].max_weight = *plasticity_word++;
49-
plasticity_weight_region_data[s].a2_plus = *plasticity_word++;
50-
plasticity_weight_region_data[s].a2_minus = *plasticity_word++;
56+
for (uint32_t s = 0; s < n_synapse_types; s++, config++) {
57+
dtcm_copy[s].min_weight = config->min_weight;
58+
dtcm_copy[s].max_weight = config->max_weight;
59+
dtcm_copy[s].a2_plus = config->a2_plus;
60+
dtcm_copy[s].a2_minus = config->a2_minus;
5161

5262
log_debug("\tSynapse type %u: Min weight:%d, Max weight:%d, A2+:%d, A2-:%d",
53-
s, plasticity_weight_region_data[s].min_weight,
54-
plasticity_weight_region_data[s].max_weight,
55-
plasticity_weight_region_data[s].a2_plus,
56-
plasticity_weight_region_data[s].a2_minus);
63+
s, dtcm_copy[s].min_weight, dtcm_copy[s].max_weight,
64+
dtcm_copy[s].a2_plus, dtcm_copy[s].a2_minus);
5765
}
5866
log_debug("weight_initialise: completed successfully");
5967

6068
// Return end address of region
61-
return (address_t) plasticity_word;
69+
return (address_t) config;
6270
}

neural_modelling/src/neuron/plasticity/stdp/weight_dependence/weight_additive_two_term_impl.c

Lines changed: 29 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,17 @@
2525
//! Global plasticity parameter data
2626
plasticity_weight_region_data_t *plasticity_weight_region_data;
2727

28+
//! \brief How the configuration data for additive_two_term is laid out in
29+
//! SDRAM. The layout is an array of these.
30+
typedef struct {
31+
int32_t min_weight;
32+
int32_t max_weight;
33+
int32_t a2_plus;
34+
int32_t a2_minus;
35+
int32_t a3_plus;
36+
int32_t a3_minus;
37+
} additive_two_term_config_t;
38+
2839
//---------------------------------------
2940
// Functions
3041
//---------------------------------------
@@ -36,32 +47,32 @@ address_t weight_initialise(
3647

3748
// Copy plasticity region data from address
3849
// **NOTE** this seems somewhat safer than relying on sizeof
39-
int32_t *plasticity_word = (int32_t *) address;
40-
plasticity_weight_region_data =
41-
spin1_malloc(sizeof(plasticity_weight_region_data_t) * n_synapse_types);
42-
if (plasticity_weight_region_data == NULL) {
50+
additive_two_term_config_t *config = (additive_two_term_config_t *) address;
51+
52+
struct plasticity_weight_region_data_two_term_t *dtcm_copy =
53+
plasticity_weight_region_data = spin1_malloc(
54+
sizeof(struct plasticity_weight_region_data_two_term_t) *
55+
n_synapse_types);
56+
if (dtcm_copy == NULL) {
4357
log_error("Could not initialise weight region data");
4458
return NULL;
4559
}
46-
for (uint32_t s = 0; s < n_synapse_types; s++) {
47-
plasticity_weight_region_data[s].min_weight = *plasticity_word++;
48-
plasticity_weight_region_data[s].max_weight = *plasticity_word++;
49-
plasticity_weight_region_data[s].a2_plus = *plasticity_word++;
50-
plasticity_weight_region_data[s].a2_minus = *plasticity_word++;
51-
plasticity_weight_region_data[s].a3_plus = *plasticity_word++;
52-
plasticity_weight_region_data[s].a3_minus = *plasticity_word++;
60+
for (uint32_t s = 0; s < n_synapse_types; s++, config++) {
61+
dtcm_copy[s].min_weight = config->min_weight;
62+
dtcm_copy[s].max_weight = config->max_weight;
63+
dtcm_copy[s].a2_plus = config->a2_plus;
64+
dtcm_copy[s].a2_minus = config->a2_minus;
65+
dtcm_copy[s].a3_plus = config->a3_plus;
66+
dtcm_copy[s].a3_minus = config->a3_minus;
5367

5468
log_debug("\tSynapse type %u: Min weight:%d, Max weight:%d, A2+:%d, A2-:%d,"
5569
" A3+:%d, A3-:%d",
56-
s, plasticity_weight_region_data[s].min_weight,
57-
plasticity_weight_region_data[s].max_weight,
58-
plasticity_weight_region_data[s].a2_plus,
59-
plasticity_weight_region_data[s].a2_minus,
60-
plasticity_weight_region_data[s].a3_plus,
61-
plasticity_weight_region_data[s].a3_minus);
70+
s, dtcm_copy[s].min_weight, dtcm_copy[s].max_weight,
71+
dtcm_copy[s].a2_plus, dtcm_copy[s].a2_minus,
72+
dtcm_copy[s].a3_plus, dtcm_copy[s].a3_minus);
6273
}
6374
log_debug("weight_initialise: completed successfully");
6475

6576
// Return end address of region
66-
return (address_t) plasticity_word;
77+
return (address_t) config;
6778
}

neural_modelling/src/neuron/plasticity/stdp/weight_dependence/weight_additive_two_term_impl.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
// Structures
3232
//---------------------------------------
3333
//! The configuration of the rule
34-
typedef struct {
34+
typedef struct plasticity_weight_region_data_two_term_t {
3535
int32_t min_weight; //!< Minimum weight
3636
int32_t max_weight; //!< Maximum weight
3737

neural_modelling/src/neuron/plasticity/stdp/weight_dependence/weight_multiplicative_impl.c

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,15 @@ plasticity_weight_region_data_t *plasticity_weight_region_data;
2727
//! Plasticity multiply shift array, in DTCM
2828
uint32_t *weight_multiply_right_shift;
2929

30+
//! \brief How the configuration data for multiplicative is laid out in SDRAM.
31+
//! The layout is an array of these.
32+
typedef struct {
33+
int32_t min_weight;
34+
int32_t max_weight;
35+
int32_t a2_plus;
36+
int32_t a2_minus;
37+
} multiplicative_config_t;
38+
3039
//---------------------------------------
3140
// Functions
3241
//---------------------------------------
@@ -38,9 +47,9 @@ address_t weight_initialise(
3847

3948
// Copy plasticity region data from address
4049
// **NOTE** this seems somewhat safer than relying on sizeof
41-
plasticity_weight_region_data =
50+
plasticity_weight_region_data_t *dtcm_copy = plasticity_weight_region_data =
4251
spin1_malloc(sizeof(plasticity_weight_region_data_t) * n_synapse_types);
43-
if (plasticity_weight_region_data == NULL) {
52+
if (dtcm_copy == NULL) {
4453
log_error("Could not initialise weight region data");
4554
return NULL;
4655
}
@@ -51,29 +60,26 @@ address_t weight_initialise(
5160
return NULL;
5261
}
5362

54-
int32_t *plasticity_word = (int32_t *) address;
55-
for (uint32_t s = 0; s < n_synapse_types; s++) {
63+
multiplicative_config_t *config = (multiplicative_config_t *) address;
64+
for (uint32_t s = 0; s < n_synapse_types; s++, config++) {
5665
// Copy parameters
57-
plasticity_weight_region_data[s].min_weight = *plasticity_word++;
58-
plasticity_weight_region_data[s].max_weight = *plasticity_word++;
59-
plasticity_weight_region_data[s].a2_plus = *plasticity_word++;
60-
plasticity_weight_region_data[s].a2_minus = *plasticity_word++;
66+
dtcm_copy[s].min_weight = config->min_weight;
67+
dtcm_copy[s].max_weight = config->max_weight;
68+
dtcm_copy[s].a2_plus = config->a2_plus;
69+
dtcm_copy[s].a2_minus = config->a2_minus;
6170

6271
// Calculate the right shift required to fixed-point multiply weights
63-
weight_multiply_right_shift[s] =
72+
uint32_t shift = weight_multiply_right_shift[s] =
6473
16 - (ring_buffer_to_input_buffer_left_shifts[s] + 1);
6574

6675
log_debug("\tSynapse type %u: Min weight:%d, Max weight:%d, A2+:%d, A2-:%d,"
6776
" Weight multiply right shift:%u",
68-
s, plasticity_weight_region_data[s].min_weight,
69-
plasticity_weight_region_data[s].max_weight,
70-
plasticity_weight_region_data[s].a2_plus,
71-
plasticity_weight_region_data[s].a2_minus,
72-
weight_multiply_right_shift[s]);
77+
s, dtcm_copy[s].min_weight, dtcm_copy[s].max_weight,
78+
dtcm_copy[s].a2_plus, dtcm_copy[s].a2_minus, shift);
7379
}
7480

7581
log_debug("weight_initialise: completed successfully");
7682

7783
// Return end address of region
78-
return (address_t) plasticity_word;
84+
return (address_t) config;
7985
}

0 commit comments

Comments
 (0)