3 个不稳定版本
0.2.0 | 2023年6月21日 |
---|---|
0.1.1 | 2023年4月20日 |
0.1.0 | 2023年4月19日 |
#359 in 构建工具
每月 23 次下载
270KB
6K SLoC
rust_hls
从 Rust 进行 HLS
此包使用 bambu 将 Rust 函数合成到 HDL。
此包相当实验性,可能会出错。如果您遇到问题,请打开一个问题。
工作原理
通过删除标记为 hls 的模块并创建一个只包含该模块的新(临时)crate 来执行高级综合。
然后将该模块编译为 LLVM IR。
然后将 LLVM IR 传递给 bambu,它生成 Verilog。
然后,此 crate 解析 Verilog 文件并将其转换为包含包装 HDL 的 rust-hdl 结构的 rust 模块。
然后,rust_hdl_macro crate 将模块和 use 语句插入到原始 crate 中,以便使用合成的模块。
设置
您应在 Cargo.toml 中的 [build-dependencies]
中添加此 crate,并将 rust_hls_macro
添加到您的 [dependencies]
。
在您的构建脚本中,应调用 rust_hls::Build::new().synthesize();
以合成所有标记为 hls 宏的函数 (#[hls]
)。
仿真
rust_hdl 不支持仿真嵌入式 Verilog。
要启用模拟,您需要在此crate上启用"verilator"
功能。这将集成Verilator到构建过程中以允许模拟。
依赖关系
为了合成Verilog,您需要在本地安装bambu。
如果您想使用verilator进行模拟,需要安装旧版本的verilator。对我而言,v4.108
是可行的。
特别是verilator版本相当难获取。
要获取所有依赖项,您可以使用nix包管理器。使用nix develop github:zebreus/bachelor-thesis
进入一个已安装所有依赖项的shell。这可能需要一段时间,因为bambu将从源代码编译。
示例
构建脚本
fn main() {
// Finds all modules annotated with `#[hls]` and generates synthesized versions of them
rust_hls::Build::new().synthesize();
}
#[rust_hls_macro::hls]
pub mod your_module {
#[hls]
pub extern "C" fn your_function(a: u32, b: u32) -> u32 {
// You can insert any Rust code here
// The main restriction is that the code must never panic
// You cannot access things in your crate that are outside of `your_module`
// Accessing external crates is supported
a * b
}
}
// The macro will insert `mod your_module_synthesized;` and `use your_module_synthesized::YourFunction` here.
// The `your_module_synthesized.rs` module is generated by the build script.
pub fn main() {
// The generated module is the function name in PascalCase
let mut device = YourFunction::new();
device.connect_all();
let data = generate_verilog(&device);
std::fs::write("./multiplier.v", data).unwrap();
}
HLS宏
hls宏有配置rust_flags
和hls_flags
的选项。
文档
目前除了rustdoc之外没有太多文档。如果您需要更多文档,请提交问题或PR。
贡献
我欢迎任何重大的或小的贡献。
依赖关系
~12–23MB
~367K SLoC