Line 44... |
Line 44... |
architecture Behavioral of af_sigmoid is
|
architecture Behavioral of af_sigmoid is
|
|
|
-- Definition of internal modules, constants, signals, etc...
|
-- Definition of internal modules, constants, signals, etc...
|
|
|
-- Sigmoid parameters:
|
-- Sigmoid parameters:
|
constant f0 : real := 2.0; -- Slope at the origin
|
constant f0 : real := 1.0; -- Slope at the origin
|
constant fr : real := 2.0; -- fr = fmax - fmin
|
constant fr : real := 2.0; -- fr = fmax - fmin
|
|
|
signal dataIn: integer range (2**Nbit-1) downto 0; -- To convert std_logic_vector input to integer index for the LUT
|
signal dataIn: integer range (2**Nbit-1) downto 0; -- To convert std_logic_vector input to integer index for the LUT
|
type table_t is array(0 to (2**Nbit)-1) of std_logic_vector(Nbit-1 downto 0); -- LUT type
|
type table_t is array(0 to (2**Nbit)-1) of std_logic_vector(Nbit-1 downto 0); -- LUT type
|
|
|
-- Function Sigmoidal: generates the Look-Up-Table for the sigmoid activation function:
|
-- Function Sigmoidal: generates the Look-Up-Table for the sigmoid activation function:
|
-- margin: maximun value of x.
|
-- margin: maximun value of x.sim:/ann_tb/ann1/layers_insts(1)/multiple_activation_functions/multiple_activation_function_insts(1)/activation_function_inst/Sigmoid_f/siglut_inst/Activation
|
function Sigmoidal(margin:real;Nbit:natural) return table_t is
|
function Sigmoidal(margin:real;Nbit:natural) return table_t is
|
variable scale,x,y,w,t: real;
|
variable scale,x,y,w,t: real;
|
variable u: integer;
|
variable u: integer;
|
variable fbits: std_logic_vector(Nbit-1 downto 0);
|
variable fbits: std_logic_vector(Nbit-1 downto 0);
|
variable table: table_t;
|
variable table: table_t;
|
Line 76... |
Line 76... |
signal Table: table_t := Sigmoidal(1.0,Nbit); -- Generation of the LUT (at synthesis time)
|
signal Table: table_t := Sigmoidal(1.0,Nbit); -- Generation of the LUT (at synthesis time)
|
|
|
begin
|
begin
|
|
|
-- Description of the activation function
|
-- Description of the activation function
|
dataIn <= to_integer(signed(inputs));
|
dataIn <= to_integer(unsigned(inputs));
|
|
|
Activation: process(clk,reset)
|
Activation: process(clk,reset)
|
begin
|
begin
|
if clk'event and clk = '1' then
|
if clk'event and clk = '1' then
|
if reset = '1' then
|
if reset = '1' then
|