URL
https://opencores.org/ocsvn/artificial_neural_network/artificial_neural_network/trunk
Subversion Repositories artificial_neural_network
Compare Revisions
- This comparison shows the changes necessary to convert path
/artificial_neural_network/trunk/ANN_kernel
- from Rev 8 to Rev 9
- ↔ Reverse comparison
Rev 8 → Rev 9
/RTL_VHDL_files/activation_function.vhd
42,22 → 42,6
|
architecture Structural of activation_function is |
|
component af_sigmoid is |
generic |
( |
Nbit : natural := 8 |
); |
port |
( |
reset : in std_logic; |
clk : in std_logic; |
run_in : in std_logic; -- Start and input data validation |
inputs : in std_logic_vector(Nbit-1 downto 0); -- Input data |
run_out : out std_logic; -- Output data validation, run_in for the next layer |
outputs : out std_logic_vector(Nbit-1 downto 0) -- Output data |
); |
end component; |
|
begin |
|
-- Linear activation function. It is a direct assignment: |
70,7 → 54,7
-- Example 1: sigmoid activation function implemented as a Look-Up-Table (LUT): |
Sigmoid_f: |
if (f_type = "siglut") generate |
siglut_inst: af_sigmoid |
siglut_inst: entity work.af_sigmoid |
generic map |
( |
Nbit => Nbit |
/RTL_VHDL_files/adder_tree.vhd
46,29 → 46,6
|
architecture Behavioral of adder_tree is |
|
|
|
component adder_tree is |
generic |
( |
NumIn : integer := 9; -- Number of inputs |
Nbit : integer := 12 -- Bit width of the input data |
); |
|
port |
( |
-- Input ports |
reset : in std_logic; |
clk : in std_logic; |
en : in std_logic; -- Enable |
inputs : in std_logic_vector((Nbit*NumIn)-1 downto 0); -- Input data |
|
-- Output ports |
en_out : out std_logic; -- Output enable (output data validation) |
output : out std_logic_vector(Nbit-1 downto 0) -- Output of the tree adder |
); |
end component; |
|
constant NumIn2 : integer := NumIn/2; -- Number of imputs of the next adder tree layer |
|
signal next_en : std_logic := '0'; -- Next adder tree layer enable |
130,7 → 107,7
recursion: |
if (NumIn > 2) generate |
|
sub_adder_tree: adder_tree |
sub_adder_tree: entity work.adder_tree |
generic map |
( |
NumIn => (NumIn2)+(NumIn mod 2), |
/RTL_VHDL_files/af_sigmoid.vhd
46,7 → 46,7
-- Definition of internal modules, constants, signals, etc... |
|
-- Sigmoid parameters: |
constant f0 : real := 1.0; -- Slope at the origin |
constant f0 : real := 2.0; -- Slope at the origin |
constant fr : real := 2.0; -- fr = fmax - fmin |
|
signal dataIn: integer range (2**Nbit-1) downto 0; -- To convert std_logic_vector input to integer index for the LUT |
53,7 → 53,7
type table_t is array(0 to (2**Nbit)-1) of std_logic_vector(Nbit-1 downto 0); -- LUT type |
|
-- Function Sigmoidal: generates the Look-Up-Table for the sigmoid activation function: |
-- margin: maximun value of x.sim:/ann_tb/ann1/layers_insts(1)/multiple_activation_functions/multiple_activation_function_insts(1)/activation_function_inst/Sigmoid_f/siglut_inst/Activation |
-- margin: maximun value of x. |
function Sigmoidal(margin:real;Nbit:natural) return table_t is |
variable scale,x,y,w,t: real; |
variable u: integer; |
63,8 → 63,8
scale := (2.0*margin)/(2.0**Nbit); -- Calculates gap between to points |
x := -margin; |
for idx in -(2**(Nbit-1)) to (2**(Nbit-1))-1 loop |
y := ( fr / (1.0+exp(((-4.0*f0)/fr)*x)) ) - (fr/2.0); |
w := y*(2.0**(Nbit-1)); -- Shifts bits to the left |
y := (fr/(1.0+exp(((-4.0*f0)/fr)*x)))-(fr/2.0); |
w := y*(2.0**(Nbit-1)); -- Shifts bits to the left |
t := round(w); |
u := integer(t); |
fbits := std_logic_vector(to_signed(u,Nbit)); |
78,7 → 78,7
begin |
|
-- Description of the activation function |
dataIn <= to_integer(unsigned(inputs)); |
dataIn <= to_integer(signed(inputs)); |
|
Activation: process(clk,reset) |
begin |
/RTL_VHDL_files/layerPS_top.vhd
125,7 → 125,7
|
signal input_aux1 : std_logic_vector((NbitIn*NumIn)-1 downto 0); |
signal input_aux2 : std_logic_vector((NbitIn*NumIn)-1 downto 0); |
signal input_aux3 : std_logic_vector((NbitIn*NumIn)-1 downto 0); |
-- signal input_aux3 : std_logic_vector((NbitIn*NumIn)-1 downto 0); |
begin |
|
layerPS_inst: entity work.layerPS |
/RTL_VHDL_files/layers_pkg.vhd
20,7 → 20,6
|
library IEEE; |
use IEEE.STD_LOGIC_1164.all; |
use IEEE.numeric_std.all; |
|
--library proc_common_v3_00_a; -- Deprecated libray from XPS tool |
--use proc_common_v3_00_a.proc_common_pkg.all; |
48,7 → 47,6
-- Return: TRUE if c is 0, 1, 2, 3, 4, 5, 6, 7, 8 or 9 |
function is_digit(c : character) return boolean; |
|
|
-- Base two logarithm for int_vector: |
-- Arguments: |
-- v : integer vector |
237,7 → 235,7
begin |
-- Calculate the maximum of the weight memory length: |
for i in 1 to n-1 loop |
addr_l := max2( addr_l, log2(NumN(i-1)+log2(NumN(i))) ); |
addr_l := max2( addr_l, log2(NumN(i-1))+log2(NumN(i)) ); |
end loop; |
addr_l := addr_l +1; -- add bias select bit |
return addr_l; |