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 10

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

powered by: WebSVN 2.1.0

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