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] - Diff between revs 9 and 10

Go to most recent revision | Only display areas with differences | Details | Blame | View Log

Rev 9 Rev 10
----------------------------------------------------------------------------------
----------------------------------------------------------------------------------
-- Company:
-- Company:
-- Engineer:
-- Engineer:
--
--
-- Create Date:    16:16:02 05/14/2014
-- Create Date:    16:16:02 05/14/2014
-- Design Name:    Configurable ANN
-- Design Name:    Configurable ANN
-- Module Name:    activation_function - Structural
-- Module Name:    activation_function - Structural
-- Project Name:
-- Project Name:
-- Target Devices:
-- Target Devices:
-- Tool versions:
-- Tool versions:
-- Description: Activation function selector. It instantiates the activation
-- Description: Activation function selector. It instantiates the activation
--             funtion type selected with f_type parameter.
--             funtion type selected with f_type parameter.
--
--
-- Dependencies:
-- Dependencies:
--
--
-- Revision:
-- Revision:
-- Revision 0.01 - File Created
-- Revision 0.01 - File Created
-- Additional Comments:
-- Additional Comments:
--
--
----------------------------------------------------------------------------------
----------------------------------------------------------------------------------
library IEEE;
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_1164.ALL;
 
 
 
 
entity activation_function is
entity activation_function is
   generic
   generic
   (
   (
      lsbit : natural := 10;
      lsbit : natural := 10;
      f_type : string := "linear"; -- Activation function type
      f_type : string := "linear"; -- Activation function type
      Nbit   : natural := 8        -- Bit width
      Nbit   : natural := 8        -- Bit width
   );
   );
   port
   port
   (
   (
      reset   : in  std_logic;
      reset   : in  std_logic;
      clk     : in  std_logic;
      clk     : in  std_logic;
      run_in  : in  std_logic; -- Start and input data validation
      run_in  : in  std_logic; -- Start and input data validation
      inputs  : in  std_logic_vector(Nbit-1 downto 0); -- Input data
      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
      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
      outputs : out std_logic_vector(Nbit-1 downto 0)  -- Output data
   );
   );
end activation_function;
end activation_function;
 
 
architecture Structural of activation_function is
architecture Structural of activation_function is
 
 
begin
begin
 
 
-- Linear activation function. It is a direct assignment:
-- Linear activation function. It is a direct assignment:
linear_f:
linear_f:
   if (f_type = "linear") generate
   if (f_type = "linear") generate
      outputs <= inputs;
      outputs <= inputs;
      run_out <= run_in;
      run_out <= run_in;
   end generate;
   end generate;
 
 
-- Example 1: sigmoid activation function implemented as a Look-Up-Table (LUT):
-- Example 1: sigmoid activation function implemented as a Look-Up-Table (LUT):
Sigmoid_f:
Sigmoid_f:
   if (f_type = "siglut") generate
   if (f_type = "siglut") generate
      siglut_inst: entity work.af_sigmoid
      siglut_inst: entity work.af_sigmoid
         generic map
         generic map
         (
         (
            Nbit => Nbit
            Nbit => Nbit
         )
         )
         port map
         port map
         (
         (
            reset   => reset,
            reset   => reset,
            clk     => clk,
            clk     => clk,
            run_in  => run_in,
            run_in  => run_in,
            inputs  => inputs,
            inputs  => inputs,
            run_out => run_out,
            run_out => run_out,
            outputs => outputs
            outputs => outputs
         );
         );
   end generate;
   end generate;
 
 
-- Example 2: sigmoid activation function implemented as a LUT, with a second different set of parameters:
-- Example 2: sigmoid activation function implemented as a LUT, with a second different set of parameters:
Sigmoid2_f:
Sigmoid2_f:
   if (f_type = "siglu2") generate
   if (f_type = "siglu2") generate
      siglut_inst: entity work.af_sigmoid2
      siglut_inst: entity work.af_sigmoid2
         generic map
         generic map
         (
         (
 
            Nbit => Nbit
 
         )
 
         port map
 
         (
 
            reset   => reset,
 
            clk     => clk,
 
            run_in  => run_in,
 
            inputs  => inputs,
 
            run_out => run_out,
 
            outputs => outputs
 
         );
 
   end generate;
 
 
 
-- Example 3: sigmoid activation function implemented as a LUT, with a second different set of parameters:
 
sigmoid_mat:
 
   if (f_type = "sigmat") generate
 
      siglut_inst: entity work.af_sigmoid_mat
 
         generic map
 
         (
            Nbit => Nbit,
            Nbit => Nbit,
            lsbit => lsbit
            lsbit => lsbit
         )
         )
         port map
         port map
         (
         (
            reset   => reset,
            reset   => reset,
            clk     => clk,
            clk     => clk,
            run_in  => run_in,
            run_in  => run_in,
            inputs  => inputs,
            inputs  => inputs,
            run_out => run_out,
            run_out => run_out,
            outputs => outputs
            outputs => outputs
         );
         );
   end generate;
   end generate;
 
 
-- Template to instance user activation function type ("userAF"):
-- Template to instance user activation function type ("userAF"):
--userAF_f:
--userAF_f:
   --if (f_type = "userAF") generate
   --if (f_type = "userAF") generate
      --yourAF_inst: entity work.--palace here user module name--
      --yourAF_inst: entity work.--palace here user module name--
         --generic map
         --generic map
         --(
         --(
         --   Nbits => Nbits
         --   Nbits => Nbits
         --)
         --)
         --port map
         --port map
         --(
         --(
         --   reset => reset,
         --   reset => reset,
         --   clk   => clk,
         --   clk   => clk,
         --   run_in  => run_in,
         --   run_in  => run_in,
         --   inputs  => inputs,
         --   inputs  => inputs,
         --   run_out => run_out,
         --   run_out => run_out,
         --   outputs => outputs
         --   outputs => outputs
         --);
         --);
   --end generate;
   --end generate;
-- User can instantiate as many types of activation function as needed, each one of them must be tagged as a 6 character string
-- User can instantiate as many types of activation function as needed, each one of them must be tagged as a 6 character string
 
 
end Structural;
end Structural;
 
 
 
 

powered by: WebSVN 2.1.0

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