跳转到主要内容

用于构建硬件电路的嵌入式领域特定语言(DSL)

项目描述

Magma

Documentation Status Linux Test codecov Join the chat at https://gitter.im/Magma-HDL/community

速查表

Magma是一种嵌入Python中的硬件设计语言。

Magma的核心抽象是电路。电路是一组相互连接的功能单元。Magma电路类似于Verilog模块。因此,所有Magma程序都保证可综合。虽然将模块连接起来可能看起来很底层,但它鼓励硬件设计人员构建可重用组件,类似于程序员构建库的方式。

Python用于创建Magma电路。在硬件社区中,使用脚本语言进行硬件设计的方法被称为《生成器》。示例硬件生成器包括算术单元、线性反馈移位寄存器、华莱士树和排序网络。软件工程师将这种技术称为《元编程》。脚本语言在元编程的意义上是一种元程序,因为它是一个创建硬件程序的程序。

与Verilog相比,Python具有强大的元编程能力,如装饰器和元类。这使得创建高级领域特定语言(DSLs)成为可能。示例包括有限状态机、内存控制器、图像和信号处理,甚至处理器语言。

学习Magma的最佳方式是通过示例。magma_register_file_tutorial(教程链接)提供了一个定义和验证寄存器文件生成器的示例。magmathon(教程链接)仓库包含一系列Jupyter Notebook(教程链接),介绍了该系统。还有magma_examples(示例链接)和magma_tutorial(教程链接),其中包含一组基本电路和测试,为magma项目提供了示例模板。最后还有magma_riscv_mini(示例链接),它提供了一个简单RISCV处理器的示例。请参阅文档

Magma的设计受到了Chisel(教程链接)的极大影响,所以如果你了解Chisel,Magma应该很容易学习。Chisel教程的一些示例已经被移植到Magma中,可以在这里找到。Magma还具备FIRRTL(教程链接)后端,我们希望很快通过FIRRTL展示与Chisel的互操作性。

Magma旨在与Mantle(教程链接)一起工作,它包含了一组有用的电路;以及与Loam(教程链接)一起工作,用于表示组件和板,并用于为独立的FPGA板构建应用程序。

设置Python

magma需要使用Python 3.7+。本节将介绍几种常见的Python设置方法。第一种(推荐)方法是使用miniconda,它支持MacOS和Linux(以及Windows,但Magma对Windows的支持尚未经过测试)。我们还提供了使用MacOS和Ubuntu Linux的标准包管理器的方法。

通用

miniconda - conda的一个免费最小安装程序。Miniconda是Anaconda的一个小型引导版本,仅包括conda、Python、它们依赖的包和一些其他有用的包(包括pip、zlib等)。使用conda install命令从Continuum仓库安装720多个额外的conda包。

https://conda.io/miniconda.html下载您操作系统的安装程序。

以下说明使用最新的MacOSX版本,请根据您的操作系统替换wget命令中的链接。

$ wget https://repo.continuum.io/miniconda/Miniconda3-latest-MacOSX-x86_64.sh
$ bash Miniconda3-latest-MacOSX-x86_64.sh
# Installing dependencies like matplotlib is typically more reliable with conda than pip
$ conda install matplotlib

MacOS/Homebrew

$ brew install python3

Ubuntu

$ sudo apt-get install python3 python3-pip

Arch

$ pacman -S python python-pip

安装依赖项

Magma依赖于一些第三方库,应使用您操作系统的包管理器进行安装。

MacOS/Homebrew

$ brew install verilator gmp mpfr libmpc

Ubuntu

$ sudo apt-get install make gcc g++ verilator libgmp-dev libmpfr-dev libmpc-dev cmake

Arch

$ pacman -S verilator gmp mpfr libmpc tk

用户设置

Magma可作为pip包使用,使用以下命令安装最新版本:

pip install magma-lang

开发设置

克隆magma仓库

$ git clone https://github.com/phanrahan/magma
$ cd magma

将magma作为符号包安装

$ pip install -e .

安装测试基础设施并运行测试以验证设置

$ pip install pytest fault  # you may need to add $HOME/.local/bin to your $PATH
$ pytest tests

您应该会看到类似以下内容:

============================= test session starts ==============================
platform darwin -- Python 3.6.1, pytest-3.0.7, py-1.4.33, pluggy-0.4.0
rootdir: ..../repos/magmacore, inifile:
collected 70 items

tests/test_circuit/test_anon.py .
tests/test_circuit/test_declare.py .
tests/test_circuit/test_define.py .
tests/test_higher/test_braid.py .
tests/test_higher/test_curry.py .
tests/test_higher/test_currylut.py .
tests/test_higher/test_curryrom.py .
tests/test_higher/test_flat.py .
tests/test_higher/test_fork.py .
tests/test_higher/test_higher_compose.py .
tests/test_higher/test_join.py .
tests/test_interface/test_interface.py ....
tests/test_io/test_inout1.py .
tests/test_io/test_inout2.py .
tests/test_io/test_out1.py .
tests/test_io/test_out2.py .
tests/test_ir/test_declaretest.py .
tests/test_ir/test_ir.py .
tests/test_meta/test_class.py .
tests/test_meta/test_creg.py .
tests/test_simulator/test_counter.py .
tests/test_simulator/test_ff.py .
tests/test_simulator/test_logic.py .
tests/test_type/test_anon_type.py .
tests/test_type/test_array.py .
tests/test_type/test_array2d.py .
tests/test_type/test_arrayconstruct.py .
tests/test_type/test_arrayflip.py .
tests/test_type/test_arrayval.py .
tests/test_type/test_awire1.py .
tests/test_type/test_bit.py .
tests/test_type/test_bitflip.py .
tests/test_type/test_bitval.py .
tests/test_type/test_tuple.py .
tests/test_type/test_tupleconstruct.py .
tests/test_type/test_tupleflip.py .
tests/test_type/test_tupleval.py .
tests/test_type/test_twire1.py .
tests/test_type/test_type_errors.py ...
tests/test_type/test_vcc.py .
tests/test_type/test_whole.py .
tests/test_type/test_wire1.py .
tests/test_type/test_wire2.py .
tests/test_type/test_wire3.py .
tests/test_type/test_wire4.py .
tests/test_type/test_wire5.py .
tests/test_verilog/test_verilog.py .
tests/test_wire/test_arg1.py .
tests/test_wire/test_arg2.py .
tests/test_wire/test_array1.py .
tests/test_wire/test_array2.py .
tests/test_wire/test_array3.py .
tests/test_wire/test_call1.py .
tests/test_wire/test_call2.py .
tests/test_wire/test_compose.py .
tests/test_wire/test_const0.py .
tests/test_wire/test_const1.py .
tests/test_wire/test_errors.py ..
tests/test_wire/test_flip.py .
tests/test_wire/test_named1.py .
tests/test_wire/test_named2a.py .
tests/test_wire/test_named2b.py .
tests/test_wire/test_named2c.py .
tests/test_wire/test_pos.py .

========================== 70 passed in 1.45 seconds ===========================

项目详情


发布历史 发布通知 | RSS源

下载文件

下载适用于您的平台的文件。如果您不确定选择哪一个,请了解更多关于安装包的信息。

源分发

magma-lang-3.0.2.tar.gz (248.6 kB 查看哈希值)

上传时间

支持者