我试图推断VHDL二维块RAM。但详细的电路原来是寄存器和MUX的电路。对于有关RAM中的代码的主要文件是:推断2D块RAM赛灵思vivado
library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;
use work.shared_resources.all;
entity weight_ram is
port (clk : in std_logic;
write_enable : in std_logic;
row_addr : in natural range 0 to max_NR-1;
data_in : in neuron_weight_array;
data_out : out neuron_weight_array);
end weight_ram;
architecture rtl of weight_ram is
signal ram : weight_ram_array;
begin
ram_process : process (clk)
variable f : integer;
begin
if (rising_edge (clk)) then
if (write_enable = '1') then
for f in 0 to n_feature-1 loop
ram (row_addr, f) <= data_in (f);
end loop;
end if;
for f in 0 to n_feature-1 loop
data_out (f) <= ram (row_addr, f);
end loop;
end if;
end process;
end rtl;
含有使用的常量的文件是:
library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;
package shared_resources is
constant n_feature : integer := 24;
constant max_NR : integer := 10; -- maximum number of neurons allowed
constant weightw : integer := 10; -- width of the weight (1:0:9)
subtype weight_type is signed (weightw-1 downto 0);
type neuron_weight_array is array (0 to n_feature-1) of weight_type;
type weight_ram_array is array (0 to max_NR-1, 0 to n_feature-1) of weight_type;
end shared_resources;
我怎样才能确保代码被推断为一个块RAM?
更新:更新了代码以从2d数组中读取单个元素(基于morten zilmer的回答)。但它仍然不会被推断为Block RAM。
library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;
use work.shared_resources.all;
entity weight_ram is
port (clk : in std_logic;
write_enable : in std_logic;
row_addr : in natural range 0 to max_NR-1;
col_addr : in natural range 0 to n_feature-1;
data_in : in weight_type;
data_out : out weight_type);
end weight_ram;
architecture rtl of weight_ram is
signal ram : weight_ram_array;
begin
ram_process : process (clk)
variable f : integer;
begin
if (rising_edge (clk)) then
if (write_enable = '1') then
ram (row_addr, col_addr) <= data_in;
end if;
data_out <= ram (row_addr, col_addr);
end if;
end process;
end rtl;
你或许应该尝试使用一维数组。内存推断是棘手的。如果您没有完全遵守供应商模板,则合成器无法达到您想要的效果。 –