-
Notifications
You must be signed in to change notification settings - Fork 181
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
examples: Add parameterized design example
This example showcases the usage of proto_to_dslx tool in DSLX design parameterization. It defines a protobuf message containing design parameters: * input width, * output width A textproto file with a variant of the design is provided. Textproto file can be converted to DSLX file which is then imported by top-level design in order to use the parameters. The design itself has 2 inputs and one output. The widths of those are controlled by parameters. Verilog file for the variant can be generated with: ``` bazel build //xls/examples/parameterized:design_verilog ``` Signed-off-by: Pawel Czarnecki <pczarnecki@antmicro.com>
- Loading branch information
Showing
4 changed files
with
94 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
load("//xls/build_rules:xls_utilities.bzl", "proto_to_dslx") | ||
load( | ||
"//xls/build_rules:xls_build_defs.bzl", | ||
"xls_dslx_ir", | ||
"xls_dslx_library", | ||
"xls_ir_opt_ir", | ||
"xls_ir_verilog", | ||
) | ||
|
||
proto_library( | ||
name = "proto_schema_lib", | ||
srcs = [":param.proto"], | ||
) | ||
|
||
proto_to_dslx( | ||
name = "parameters", | ||
proto_schema = ":proto_schema_lib", | ||
proto_name = "xls.DesignVariants", | ||
textproto = ":parameters.textproto", | ||
) | ||
|
||
xls_dslx_library( | ||
name = "parameters_lib", | ||
srcs = [":parameters"], | ||
) | ||
|
||
xls_dslx_library( | ||
name = "design_lib", | ||
srcs = [ | ||
"design.x" | ||
], | ||
deps = [":parameters_lib"], | ||
) | ||
|
||
xls_dslx_ir( | ||
name = "design_ir", | ||
dslx_top = "top", | ||
ir_file = "desing.ir", | ||
library = "design_lib", | ||
) | ||
|
||
xls_ir_opt_ir( | ||
name = "design_opt_ir", | ||
src = "desing.ir", | ||
top = "__design__top", | ||
) | ||
|
||
xls_ir_verilog( | ||
name = "design_verilog", | ||
src = ":design_opt_ir.opt.ir", | ||
codegen_args = { | ||
"module_name": "top", | ||
"delay_model": "unit", | ||
"pipeline_stages": "1", | ||
"use_system_verilog": "false", | ||
}, | ||
verilog_file = "design.v", | ||
) |
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,19 @@ | ||
import xls.examples.parameterized.parameters | ||
|
||
type DesignParameters = parameters::DesignParameters; | ||
|
||
fn add<INPUT_WIDTH: u32, OUTPUT_WIDTH: u32>(x: uN[INPUT_WIDTH], y: uN[INPUT_WIDTH]) -> uN[OUTPUT_WIDTH] { | ||
let lhs = x as uN[OUTPUT_WIDTH]; | ||
let rhs = y as uN[OUTPUT_WIDTH]; | ||
lhs + rhs | ||
} | ||
|
||
fn top(x: u64, y: u64) -> u64 { | ||
let variant: DesignParameters = parameters::parameters.variant[0]; | ||
let variant_input_width: u32 = variant.input_width; | ||
let variant_output_width: u32 = variant.output_width; | ||
let arg_x = x as uN[variant_input_width]; | ||
let arg_y = y as uN[variant_input_width]; | ||
|
||
add<variant_input_width, variant_output_width>(arg_x, arg_y) as u64 | ||
} |
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,12 @@ | ||
syntax = "proto2"; | ||
|
||
package xls; | ||
|
||
message DesignParameters { | ||
optional uint32 input_width = 1; | ||
optional uint32 output_width = 2; | ||
} | ||
|
||
message DesignVariants { | ||
repeated DesignParameters variant = 1; | ||
} |
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,5 @@ | ||
variant { | ||
input_width: 1 | ||
output_width: 2 | ||
} | ||
|