-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add linear layer to lstm network
- Loading branch information
Showing
14 changed files
with
258 additions
and
103 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
elasticai/creator/translatable_modules/vhdl/lstm/fp_hard_tanh.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
from elasticai.creator.hdl.code_generation.abstract_base_template import ( | ||
TemplateConfig, | ||
TemplateExpander, | ||
module_to_package, | ||
) | ||
from elasticai.creator.hdl.design_base.design import Design, Port | ||
from elasticai.creator.hdl.design_base.signal import Signal | ||
from elasticai.creator.hdl.translatable import Path | ||
from elasticai.creator.nn._two_complement_fixed_point_config import ( | ||
TwoComplementFixedPointConfig, | ||
) | ||
|
||
|
||
class FPHardTanh(Design): | ||
def __init__(self, total_bits: int, frac_bits: int): | ||
super().__init__(name="hardtanh") | ||
self._data_width = total_bits | ||
fp_config = TwoComplementFixedPointConfig( | ||
frac_bits=frac_bits, total_bits=total_bits | ||
) | ||
self._template = TemplateConfig( | ||
package=module_to_package(self.__module__), | ||
file_name="fp_hard_tanh.tpl.vhd", | ||
parameters=dict( | ||
data_width=str(self._data_width), | ||
one=str(fp_config.as_integer(1)), | ||
minus_one=str(fp_config.as_integer(-1)), | ||
), | ||
) | ||
|
||
def save_to(self, destination: "Path"): | ||
destination.as_file(".vhd").write_text(TemplateExpander(self._template).lines()) | ||
|
||
@property | ||
def port(self) -> Port: | ||
return Port( | ||
incoming=[Signal("x", self._data_width)], | ||
outgoing=[Signal("y", self._data_width)], | ||
) |
27 changes: 27 additions & 0 deletions
27
elasticai/creator/translatable_modules/vhdl/lstm/fp_hard_tanh.tpl.vhd
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
-- A LUT version of tanh | ||
library ieee; | ||
use ieee.std_logic_1164.all; | ||
use ieee.numeric_std.all; -- for type conversions | ||
|
||
entity tanh is | ||
port ( | ||
x : in signed({data_width}-1 downto 0); | ||
y : out signed({data_width}-1 downto 0) | ||
); | ||
|
||
end tanh; | ||
|
||
architecture rtl of tanh is | ||
begin | ||
|
||
tanh_process:process(x) | ||
begin | ||
if x<=-16 then | ||
y <= to_signed({minus_one}, y'length); | ||
elsif x<16 then | ||
y <= x; | ||
else | ||
y <= to_signed({one}, y'length); | ||
end if; | ||
end process; | ||
end rtl; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.