OpenCores
URL https://opencores.org/ocsvn/artificial_neural_network/artificial_neural_network/trunk

Subversion Repositories artificial_neural_network

[/] [artificial_neural_network/] [trunk/] [ANN_kernel/] [RTL_VHDL_files/] [activation_function.vhd] - Blame information for rev 8

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 3 ojosynariz
----------------------------------------------------------------------------------
2
-- Company:
3
-- Engineer:
4
--
5
-- Create Date:    16:16:02 05/14/2014
6
-- Design Name:    Configurable ANN
7
-- Module Name:    activation_function - Structural
8
-- Project Name:
9
-- Target Devices:
10
-- Tool versions:
11
-- Description: Activation function selector. It instantiates the activation
12
--             funtion type selected with f_type parameter.
13
--
14
-- Dependencies:
15
--
16
-- Revision:
17
-- Revision 0.01 - File Created
18
-- Additional Comments:
19
--
20
----------------------------------------------------------------------------------
21
library IEEE;
22
use IEEE.STD_LOGIC_1164.ALL;
23
 
24
 
25
entity activation_function is
26
   generic
27
   (
28 8 jstefanowi
      lsbit : natural := 10;
29 3 ojosynariz
      f_type : string := "linear"; -- Activation function type
30
      Nbit   : natural := 8        -- Bit width
31
   );
32
   port
33
   (
34
      reset   : in  std_logic;
35
      clk     : in  std_logic;
36
      run_in  : in  std_logic; -- Start and input data validation
37
      inputs  : in  std_logic_vector(Nbit-1 downto 0); -- Input data
38
      run_out : out std_logic; -- Output data validation, run_in for the next layer
39
      outputs : out std_logic_vector(Nbit-1 downto 0)  -- Output data
40
   );
41
end activation_function;
42
 
43
architecture Structural of activation_function is
44
 
45 8 jstefanowi
component af_sigmoid is
46
   generic
47
   (
48
      Nbit : natural := 8
49
   );
50
   port
51
   (
52
      reset   : in  std_logic;
53
      clk     : in  std_logic;
54
      run_in  : in  std_logic; -- Start and input data validation
55
      inputs  : in  std_logic_vector(Nbit-1 downto 0); -- Input data
56
      run_out : out std_logic; -- Output data validation, run_in for the next layer
57
      outputs : out std_logic_vector(Nbit-1 downto 0) -- Output data
58
   );
59
end component;
60
 
61 3 ojosynariz
begin
62
 
63
-- Linear activation function. It is a direct assignment:
64
linear_f:
65
   if (f_type = "linear") generate
66
      outputs <= inputs;
67
      run_out <= run_in;
68
   end generate;
69
 
70
-- Example 1: sigmoid activation function implemented as a Look-Up-Table (LUT):
71
Sigmoid_f:
72
   if (f_type = "siglut") generate
73 8 jstefanowi
      siglut_inst: af_sigmoid
74 3 ojosynariz
         generic map
75
         (
76
            Nbit => Nbit
77
         )
78
         port map
79
         (
80
            reset   => reset,
81
            clk     => clk,
82
            run_in  => run_in,
83
            inputs  => inputs,
84
            run_out => run_out,
85
            outputs => outputs
86
         );
87
   end generate;
88
 
89
-- Example 2: sigmoid activation function implemented as a LUT, with a second different set of parameters:
90
Sigmoid2_f:
91
   if (f_type = "siglu2") generate
92
      siglut_inst: entity work.af_sigmoid2
93
         generic map
94
         (
95 8 jstefanowi
            Nbit => Nbit,
96
            lsbit => lsbit
97 3 ojosynariz
         )
98
         port map
99
         (
100
            reset   => reset,
101
            clk     => clk,
102
            run_in  => run_in,
103
            inputs  => inputs,
104
            run_out => run_out,
105
            outputs => outputs
106
         );
107
   end generate;
108
 
109
-- Template to instance user activation function type ("userAF"):
110
--userAF_f:
111
   --if (f_type = "userAF") generate
112
      --yourAF_inst: entity work.--palace here user module name--
113
         --generic map
114
         --(
115
         --   Nbits => Nbits
116
         --)
117
         --port map
118
         --(
119
         --   reset => reset,
120
         --   clk   => clk,
121
         --   run_in  => run_in,
122
         --   inputs  => inputs,
123
         --   run_out => run_out,
124
         --   outputs => outputs
125
         --);
126
   --end generate;
127
-- User can instantiate as many types of activation function as needed, each one of them must be tagged as a 6 character string
128
 
129
end Structural;
130
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.