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 9

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 8 jstefanowi
            Nbit => Nbit,
80
            lsbit => lsbit
81 3 ojosynariz
         )
82
         port map
83
         (
84
            reset   => reset,
85
            clk     => clk,
86
            run_in  => run_in,
87
            inputs  => inputs,
88
            run_out => run_out,
89
            outputs => outputs
90
         );
91
   end generate;
92
 
93
-- Template to instance user activation function type ("userAF"):
94
--userAF_f:
95
   --if (f_type = "userAF") generate
96
      --yourAF_inst: entity work.--palace here user module name--
97
         --generic map
98
         --(
99
         --   Nbits => Nbits
100
         --)
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
-- User can instantiate as many types of activation function as needed, each one of them must be tagged as a 6 character string
112
 
113
end Structural;
114
 

powered by: WebSVN 2.1.0

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