Skip to content

Commit

Permalink
update scala
Browse files Browse the repository at this point in the history
  • Loading branch information
mattfel1 committed Mar 3, 2018
1 parent ccf3e7f commit 6c05f0c
Show file tree
Hide file tree
Showing 6 changed files with 86 additions and 114 deletions.
1 change: 1 addition & 0 deletions docs/site/targets.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ This section provides details on the hardware Spatial can target.
:maxdepth: 2

targets/aws
targets/scala
64 changes: 40 additions & 24 deletions docs/site/targets/scala/intro.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,43 +4,59 @@
Prerequisites
-------------

Running on EC2 FPGAs requires the following prerequisites:
Running the Scala backend requires... Scala to be installed on your machine.

- An installation of Spatial as described in the :doc:`previous tutorial <../../tutorial/starting>`
- Vivado and a license to run on the desired Amazon FPGA. We tested this tutorial both on Amazon's `FPGA Developer AMI <https://aws.amazon.com/marketplace/pp/B06VVYBLZZ#>`_ which contains all the required software tools,
as well as locally by following `these instructions <https://github.com/aws/aws-fpga/blob/master/hdk/docs/on_premise_licensing_help.md>`_.
- `Scala SBT <http://www.scala-sbt.org>`_

Spatial Compile
You must have Scala installed to compile Spatial applications, so if you can compile the app successfully then you
already have what you need to run the Scala backend.

Notes
-----

.. highlight:: bash
The Scala backend is a useful tool for debugging at the algorithm level. It has a few advantages and disadvantages, however:

Clone Amazon's `EC2 FPGA Hardware and Software Development Kit <https://github.com/aws/aws-fpga/>`_ to any location::
- Advantages
- - `println` statements in the `Accel` will actually print while the app simulates
- - Fastest way to go from source code to execution

git clone https://github.com/aws/aws-fpga.git
- Disadvantages
- - Not cycle accurate. The Scala backend will not expose bugs related to things like loop-carry dependencies in coarse-grain pipelines
or unprotected parallelized writes to memories.
- - Cannot target any devices from generated code.
- - Execution can be slow

Spatial was most recently tested with version 1.3.3 of this repository (git commit 934000f9a57c0cde8786441864d5c6e0cf42fef9).
Spatial Compile
-----

Set the ``AWS_HOME`` environment variable to point to the cloned directory.
Also source the AWS setup scripts. The HDK script is needed for simulation and synthesis, and the SDK is needed to create the host binary::
To compile the Spatial app, do the following steps:

export AWS_HOME=/path/to/aws-fpga
cd /path/to/aws-fpga/
source /path/to/aws-fpga/hdk_setup.sh
source /path/to/aws-fpga/sdk_setup.sh
cd spatial-lang/ # Navigate to Spatial base directory
bin/spatial <app name> --sim # + :doc:`other options <../../compiler>`

For example, you can add the 4 commands above to your ``.bashrc`` and source that.
The "<app name>" refers to the name of the ``object``. In our app above, for example, the app name is "HelloSpatial".
See the "Running" section below for a guide on how to test the generated app

Finally, applications targeting the F1 board (in hardware or simulation) need to set the ``target`` variable. For example,
make the following change in the very top of the ``apps/src/MatMult_outer.scala`` application::

object MatMult_outer extends SpatialApp {
override val target = spatial.targets.AWS_F1 // <---- new line
...
Backend Compile
-----

The next tutorial sections describe how to generate and run applications for :doc:`simulation <sim>` and :doc:`for the FPGAs on the F1 instances<F1>`.
For the Scala backend, compiling the generated code is optional since the execution script will
call SBT, which will compile the code anyway. If you want to just compile the Scala, run the following::

Backend Compile
cd gen/<app name> # Navigate to generated directory
make sim # If you chose the Scala backend

Execute
-----

To execute the generated code, run:

# Run simulation executable if one of the first two options were chosen
bash run.sh "<arguments>"

NOTE: The "<arguments>" should be a space-separated list, fully enclosed in quotes. For example, an app that takes arguments 192 96 should be run with::

Execute
bash run.sh "192 96"
35 changes: 2 additions & 33 deletions docs/site/tutorial/helloworld.rst
Original file line number Diff line number Diff line change
Expand Up @@ -86,39 +86,8 @@ While this template is empty, you can use this same flow freely as you build you
Currently, you should edit and place apps inside of your `spatial-lang/apps/src/` directory. Copy-paste the above
template into a new file in this directory and you are ready to compile.

There are currently two backend targets that you can compile to: Scala and RTL.

The Scala backend is the fastest way to check the correctness of your application.
It does not simulate parallelization and pipelining as they would
execute in hardware so any race conditions or loop-carry dependency issues will not be caught in this backend, but
it is a very useful tool for early and rapid development.

The RTL backend can be both simulated on a cycle-accurate simulator and synthesized to generate a bitstream
for an FPGA. The RTL simulation is the most accurate way to test your design, but takes on the order of minutes
to compile.

**Compiling to Scala**

Targetting Scala is the quickest way to simulate your app and test for basic functional correctness.
You should use this backend if you are debugging things at the algorithm level.
In order to compile and simulate for the Scala backend, run::

cd spatial-lang/ # Navigate to Spatial base directory
bin/spatial <app name> --sim # + :doc:`other options <../compiler>`

The "<app name>" refers to the name of the ``object``. In our app above, for example, the app name is "HelloSpatial".
See the "Running" section below for a guide on how to test the generated app



**Compiling to RTL**

Targeting Chisel will let you compile your app down into Berkeley's Chisel language, which eventually compiles down to Verilog.
It also allows you to debug your app at the clock-cycle resolution. In order to compile with the Chisel backend, run the following::

cd spatial-lang/ # Navigate to Spatial base directory
bin/spatial <app name> --synth # + :doc:`other options <../compiler>`

For information on how to compile your app to a specific target, see the :targets:`targets <../targets>` page.
We recommend beginnig with either the Scala or VCS backends.


Synthesizing and Testing
Expand Down
1 change: 1 addition & 0 deletions docs/source/targets.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ This section provides details on the hardware Spatial can target.
:maxdepth: 2

targets/aws
targets/scala
64 changes: 40 additions & 24 deletions docs/source/targets/scala/intro.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,43 +4,59 @@
Prerequisites
-------------

Running on EC2 FPGAs requires the following prerequisites:
Running the Scala backend requires... Scala to be installed on your machine.

- An installation of Spatial as described in the :doc:`previous tutorial <../../tutorial/starting>`
- Vivado and a license to run on the desired Amazon FPGA. We tested this tutorial both on Amazon's `FPGA Developer AMI <https://aws.amazon.com/marketplace/pp/B06VVYBLZZ#>`_ which contains all the required software tools,
as well as locally by following `these instructions <https://github.com/aws/aws-fpga/blob/master/hdk/docs/on_premise_licensing_help.md>`_.
- `Scala SBT <http://www.scala-sbt.org>`_

Spatial Compile
-----
You must have Scala installed to compile Spatial applications, so if you can compile the app successfully then you
already have what you need to run the Scala backend.

.. highlight:: bash

Clone Amazon's `EC2 FPGA Hardware and Software Development Kit <https://github.com/aws/aws-fpga/>`_ to any location::
Notes
-----

git clone https://github.com/aws/aws-fpga.git
The Scala backend is a useful tool for debugging at the algorithm level. It has a few advantages and disadvantages, however:

Spatial was most recently tested with version 1.3.3 of this repository (git commit 934000f9a57c0cde8786441864d5c6e0cf42fef9).
- Advantages
- - `println` statements in the `Accel` will actually print while the app simulates
- - Fastest way to go from source code to execution

Set the ``AWS_HOME`` environment variable to point to the cloned directory.
Also source the AWS setup scripts. The HDK script is needed for simulation and synthesis, and the SDK is needed to create the host binary::
- Disadvantages
- - Not cycle accurate. The Scala backend will not expose bugs related to things like loop-carry dependencies in coarse-grain pipelines
or unprotected parallelized writes to memories.
- - Cannot target any devices from generated code.
- - Execution can be slow

export AWS_HOME=/path/to/aws-fpga
cd /path/to/aws-fpga/
source /path/to/aws-fpga/hdk_setup.sh
source /path/to/aws-fpga/sdk_setup.sh
Spatial Compile
-----

For example, you can add the 4 commands above to your ``.bashrc`` and source that.
To compile the Spatial app, do the following steps:

Finally, applications targeting the F1 board (in hardware or simulation) need to set the ``target`` variable. For example,
make the following change in the very top of the ``apps/src/MatMult_outer.scala`` application::
cd spatial-lang/ # Navigate to Spatial base directory
bin/spatial <app name> --sim # + :doc:`other options <../../compiler>`

object MatMult_outer extends SpatialApp {
override val target = spatial.targets.AWS_F1 // <---- new line
...
The "<app name>" refers to the name of the ``object``. In our app above, for example, the app name is "HelloSpatial".
See the "Running" section below for a guide on how to test the generated app

The next tutorial sections describe how to generate and run applications for :doc:`simulation <sim>` and :doc:`for the FPGAs on the F1 instances<F1>`.

Backend Compile
-----

For the Scala backend, compiling the generated code is optional since the execution script will
call SBT, which will compile the code anyway. If you want to just compile the Scala, run the following::

cd gen/<app name> # Navigate to generated directory
make sim # If you chose the Scala backend

Execute
-----

To execute the generated code, run:

# Run simulation executable if one of the first two options were chosen
bash run.sh "<arguments>"

NOTE: The "<arguments>" should be a space-separated list, fully enclosed in quotes. For example, an app that takes arguments 192 96 should be run with::

bash run.sh "192 96"
35 changes: 2 additions & 33 deletions docs/source/tutorial/helloworld.rst
Original file line number Diff line number Diff line change
Expand Up @@ -85,39 +85,8 @@ While this template is empty, you can use this same flow freely as you build you
Currently, you should edit and place apps inside of your `spatial-lang/apps/src/` directory. Copy-paste the above
template into a new file in this directory and you are ready to compile.

There are currently two backend targets that you can compile to: Scala and RTL.

The Scala backend is the fastest way to check the correctness of your application.
It does not simulate parallelization and pipelining as they would
execute in hardware so any race conditions or loop-carry dependency issues will not be caught in this backend, but
it is a very useful tool for early and rapid development.

The RTL backend can be both simulated on a cycle-accurate simulator and synthesized to generate a bitstream
for an FPGA. The RTL simulation is the most accurate way to test your design, but takes on the order of minutes
to compile.

**Compiling to Scala**

Targetting Scala is the quickest way to simulate your app and test for basic functional correctness.
You should use this backend if you are debugging things at the algorithm level.
In order to compile and simulate for the Scala backend, run::

cd spatial-lang/ # Navigate to Spatial base directory
bin/spatial <app name> --sim # + :doc:`other options <../compiler>`

The "<app name>" refers to the name of the ``object``. In our app above, for example, the app name is "HelloSpatial".
See the "Running" section below for a guide on how to test the generated app



**Compiling to RTL**

Targeting Chisel will let you compile your app down into Berkeley's Chisel language, which eventually compiles down to Verilog.
It also allows you to debug your app at the clock-cycle resolution. In order to compile with the Chisel backend, run the following::

cd spatial-lang/ # Navigate to Spatial base directory
bin/spatial <app name> --synth # + :doc:`other options <../compiler>`

For information on how to compile your app to a specific target, see the :targets:`targets <../targets>` page.
We recommend beginnig with either the Scala or VCS backends.


Synthesizing and Testing
Expand Down

0 comments on commit 6c05f0c

Please sign in to comment.