-
David Lanzendörfer authored20521bab
neuron.v 6.39 KiB
/*
In genereal the activation function is:
-----
\
\ (w_i*x_i)+bias
f(w_i,x_i) = /
/____
when f(w,x) > 0, then the output spikes
*/
module neuron #(
parameter NUMBER_SYNAPSES = 8,
parameter NUMBER_RNN_SYNAPSES = 8
)
(
clk,
rst,
// Turn on processing
run_inference,
inference_done,
// The layer i/o
rnn_inputs,
neuron_inputs,
neuron_output,
// Backprop
backprop_enable,
backprop_out_port,
backprop_in_port,
backprop_done,
// Data interface
read_enable,
write_enable,
read_done,
write_done,
address,
data_i,
data_o
);
parameter NUM_WEIGHTS = NUMBER_SYNAPSES+NUMBER_RNN_SYNAPSES;
input clk;
input rst;
input run_inference;
output reg inference_done;
input[NUMBER_SYNAPSES-1:0] neuron_inputs;
input[NUMBER_RNN_SYNAPSES-1:0] rnn_inputs;
output reg neuron_output;
output reg write_done;
output reg read_done;
// Data interface
input write_enable;
input read_enable;
input [$clog2(NUMBER_SYNAPSES+NUMBER_RNN_SYNAPSES+2):0] address;
input [31:0] data_i;
output reg [31:0] data_o;
// Backprop
output reg [NUMBER_SYNAPSES-1:0] backprop_out_port; // tell the other neurons that they have to better themselves
input [NUMBER_SYNAPSES-1:0] backprop_in_port; // Constructive criticism for the neuron
output reg backprop_done;
input backprop_enable;
reg backprop_running;
reg signed[NUMBER_SYNAPSES-1:0][31:0] W; // summands
reg signed[NUMBER_RNN_SYNAPSES-1:0][31:0] RNNW; // RNN summands
reg signed[31:0] bias; // summands
reg signed[31:0] dw; // weight correction