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 11

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
entity activation_function is
25
   generic
26
   (
27 8 jstefanowi
      lsbit : natural := 10;
28 3 ojosynariz
      f_type : string := "linear"; -- Activation function type
29
      Nbit   : natural := 8        -- Bit width
30
   );
31
   port
32
   (
33
      reset   : in  std_logic;
34
      clk     : in  std_logic;
35
      run_in  : in  std_logic; -- Start and input data validation
36
      inputs  : in  std_logic_vector(Nbit-1 downto 0); -- Input data
37
      run_out : out std_logic; -- Output data validation, run_in for the next layer
38
      outputs : out std_logic_vector(Nbit-1 downto 0)  -- Output data
39
   );
40
end activation_function;
41
 
42
architecture Structural of activation_function is
43
 
44
begin
45
 
46
-- Linear activation function. It is a direct assignment:
47
linear_f:
48
   if (f_type = "linear") generate
49
      outputs <= inputs;
50
      run_out <= run_in;
51
   end generate;
52
 
53
-- Example 1: sigmoid activation function implemented as a Look-Up-Table (LUT):
54
Sigmoid_f:
55
   if (f_type = "siglut") generate
56 9 jstefanowi
      siglut_inst: entity work.af_sigmoid
57 3 ojosynariz
         generic map
58
         (
59
            Nbit => Nbit
60
         )
61
         port map
62
         (
63
            reset   => reset,
64
            clk     => clk,
65
            run_in  => run_in,
66
            inputs  => inputs,
67
            run_out => run_out,
68
            outputs => outputs
69
         );
70
   end generate;
71
 
72
-- Example 2: sigmoid activation function implemented as a LUT, with a second different set of parameters:
73
Sigmoid2_f:
74
   if (f_type = "siglu2") generate
75
      siglut_inst: entity work.af_sigmoid2
76
         generic map
77
         (
78 10 jstefanowi
            Nbit => Nbit
79
         )
80
         port map
81
         (
82
            reset   => reset,
83
            clk     => clk,
84
            run_in  => run_in,
85
            inputs  => inputs,
86
            run_out => run_out,
87
            outputs => outputs
88
         );
89
   end generate;
90
 
91
-- Example 3: sigmoid activation function implemented as a LUT, with a second different set of parameters:
92
sigmoid_mat:
93
   if (f_type = "sigmat") generate
94
      siglut_inst: entity work.af_sigmoid_mat
95
         generic map
96
         (
97
            Nbit  => Nbit,
98 8 jstefanowi
            lsbit => lsbit
99 3 ojosynariz
         )
100
         port map
101
         (
102
            reset   => reset,
103
            clk     => clk,
104
            run_in  => run_in,
105
            inputs  => inputs,
106
            run_out => run_out,
107
            outputs => outputs
108
         );
109
   end generate;
110
 
111
-- Template to instance user activation function type ("userAF"):
112
--userAF_f:
113
   --if (f_type = "userAF") generate
114
      --yourAF_inst: entity work.--palace here user module name--
115
         --generic map
116
         --(
117
         --   Nbits => Nbits
118
         --)
119
         --port map
120
         --(
121
         --   reset => reset,
122
         --   clk   => clk,
123
         --   run_in  => run_in,
124
         --   inputs  => inputs,
125
         --   run_out => run_out,
126
         --   outputs => outputs
127
         --);
128
   --end generate;
129
-- User can instantiate as many types of activation function as needed, each one of them must be tagged as a 6 character string
130
 
131
end Structural;
132
 

powered by: WebSVN 2.1.0

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