在Verilog/SystemVerilog中实例化处理元素网格的最佳方法?
我有一个ProcessingElement.sv模块,我想实例化一个可配置的数组,所以我想创建一个生成块,如下所示:在Verilog/SystemVerilog中实例化处理元素网格的最佳方法?,verilog,system-verilog,fpga,Verilog,System Verilog,Fpga,我有一个ProcessingElement.sv模块,我想实例化一个可配置的数组,所以我想创建一个生成块,如下所示: module ProcessingArray #(parameter Y=14, X=14, W=16) ( input GlobalClk, input [3:0] OpCode, input [W-1:0] DataIn, output logic [W-
module ProcessingArray #(parameter Y=14, X=14, W=16) (
input GlobalClk,
input [3:0] OpCode,
input [W-1:0] DataIn,
output logic [W-1:0] DataOut
);
genvar x, y;
generate
for (y=0; y<=Y; y++) begin
for (x=0; x<X; x++) begin
ProcessingElement #(.W(16)) PE(
.Clk(GlobalClk),
.OpCode(OpCode),
.Input(DataIn),
.Output(DataOut)
);
end
end
endgenerate
endmodule
您可以做的是创建一个二维导线阵列,并在generate循环内建立条件连接。下面是一个完整的示例:
module ProcessingArray #(parameter Y=14, X=14, W=16) (
input GlobalClk,
input [3:0] OpCode,
input [W-1:0] DataIn,
output logic [W-1:0] DataOut
);
// internal connections
wire [W-1:0] ConnIn[Y][X];
wire [W-1:0] ConnOut[Y][X];
// entry and exit connections
assign ConnIn[0][0] = DataIn;
assign DataOut = ConnOut[Y-1][X-1];
for (genvar y=0; y<Y; y++) begin : row
for (genvar x=0; x<X; x++) begin :col
ProcessingElement #(.W(16)) PE(
.Clk(GlobalClk),
.OpCode(OpCode),
.Input(ConnIn[y][x]),
.Output(ConnOut[y][x])
);
if (y<=x && x>0) assign ConnIn[y][x] = ConnOut[y][x-1]; // horizontal
if (x<=y && y>0) assign ConnIn[y][x] = ConnOut[y-1][x]; // vertical
end
end
endmodule
module ProcessingElement #(int W) (
input Clk,
input [3:0] OpCode,
input [W-1:0] Input,
output logic [W-1:0] Output
);
assign Output=Input+1; // trace connectivity
initial #1 $display("PE %m %d",Input);
endmodule
module tb;
logic [15:0] in,out;
logic [3:0] op;
ProcessingArray PE(clk,op,in,out);
initial begin
in = 1;
#1 $display(out);
end
endmodule
模块处理阵列#(参数Y=14,X=14,W=16)(
输入GlobalClk,
输入[3:0]操作码,
输入[W-1:0]数据输入,
输出逻辑[W-1:0]数据输出
);
//内部连接
导线[W-1:0]康宁[Y][X];
导线[W-1:0]连接[Y][X];
//出入口连接
分配ConnIn[0][0]=DataIn;
分配数据输出=连接输出[Y-1][X-1];
对于(genvar y=0;yy您可以使用begin:myname
)命名循环实例,但这对您没有帮助。您可能需要声明可以索引到的内部信号数组。但是,您的连接图显示了具有不同连接数目的PE。您需要解释循环展开示例的情况。如果可能,我将喜欢以独立方式引用任何生成的ProcessingElement(即,在其中任何一个元素上分配输入,我选择的任何线路)
module ProcessingArray #(parameter Y=14, X=14, W=16) (
input GlobalClk,
input [3:0] OpCode,
input [W-1:0] DataIn,
output logic [W-1:0] DataOut
);
// internal connections
wire [W-1:0] ConnIn[Y][X];
wire [W-1:0] ConnOut[Y][X];
// entry and exit connections
assign ConnIn[0][0] = DataIn;
assign DataOut = ConnOut[Y-1][X-1];
for (genvar y=0; y<Y; y++) begin : row
for (genvar x=0; x<X; x++) begin :col
ProcessingElement #(.W(16)) PE(
.Clk(GlobalClk),
.OpCode(OpCode),
.Input(ConnIn[y][x]),
.Output(ConnOut[y][x])
);
if (y<=x && x>0) assign ConnIn[y][x] = ConnOut[y][x-1]; // horizontal
if (x<=y && y>0) assign ConnIn[y][x] = ConnOut[y-1][x]; // vertical
end
end
endmodule
module ProcessingElement #(int W) (
input Clk,
input [3:0] OpCode,
input [W-1:0] Input,
output logic [W-1:0] Output
);
assign Output=Input+1; // trace connectivity
initial #1 $display("PE %m %d",Input);
endmodule
module tb;
logic [15:0] in,out;
logic [3:0] op;
ProcessingArray PE(clk,op,in,out);
initial begin
in = 1;
#1 $display(out);
end
endmodule