Top Banner
1 © 2014 The MathWorks, Inc. Implementing MATLAB Algorithms in FPGAs and ASICs By Alexander Schreiber Senior Application Engineer MathWorks
28

Implementing MATLAB Algorithms in FPGAs and ASICs · Implementing MATLAB Algorithms in FPGAs and ASICs By Alexander Schreiber Senior Application Engineer MathWorks . 2 ... –VHDL

Jul 28, 2018

Download

Documents

nguyennhu
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Implementing MATLAB Algorithms in FPGAs and ASICs · Implementing MATLAB Algorithms in FPGAs and ASICs By Alexander Schreiber Senior Application Engineer MathWorks . 2 ... –VHDL

1 © 2014 The MathWorks, Inc.

Implementing MATLAB Algorithms

in FPGAs and ASICs

By Alexander Schreiber

Senior Application Engineer

MathWorks

Page 2: Implementing MATLAB Algorithms in FPGAs and ASICs · Implementing MATLAB Algorithms in FPGAs and ASICs By Alexander Schreiber Senior Application Engineer MathWorks . 2 ... –VHDL

2

Traditional Implementation Workflow: Challenges

DESIGN

Algorithm

Development

MATLAB

Simulink

Stateflow

Long development cycles

Prevents short iteration cycles

Difficult to optimize the algorithm at a system level

manual

Fixed Point Conversion

manual

HDL Code Creation

Text I/O or HW based

FPGA Verification

manual

HDL Refinement

Text I/O based

HDL Verification

Text I/O based

HDL Verification

Page 3: Implementing MATLAB Algorithms in FPGAs and ASICs · Implementing MATLAB Algorithms in FPGAs and ASICs By Alexander Schreiber Senior Application Engineer MathWorks . 2 ... –VHDL

3

Solution: Model-Based Design using MATLAB

Design, simulate, and validate algorithms and system models in MATLAB and Simulink

Automatically generate and optimize HDL code

Verify the HDL/hardware implementation against the system model

Veri

fy

ASIC FPGA

HDL

HDL Coder

HDL Verifier

MATLAB® and Simulink®

Algorithm Design and System Design

Gen

era

te

Page 4: Implementing MATLAB Algorithms in FPGAs and ASICs · Implementing MATLAB Algorithms in FPGAs and ASICs By Alexander Schreiber Senior Application Engineer MathWorks . 2 ... –VHDL

4

From Algorithm to Implementation

HDL Simulation

HDL Code Generation

Conversion to Fixed Point

and Fixed-Point Verification

MATLAB® Algorithm and System Design

Model Refinement for Hardware

Iterative

Refinement

using

Fixed-Point

Advisor

Refinement and

Design

Exploration

Map

Place & Route

Synthesis

Implement Design

Page 5: Implementing MATLAB Algorithms in FPGAs and ASICs · Implementing MATLAB Algorithms in FPGAs and ASICs By Alexander Schreiber Senior Application Engineer MathWorks . 2 ... –VHDL

5

Map

Place & Route

Synthesis

Implement Design

From Algorithm to Implementation

HDL Simulation

HDL Code Generation

Conversion to Fixed Point

and Fixed-Point Verification

MATLAB® Algorithm and System Design

Model Refinement for Hardware

Map

Place & Route

Synthesis

Implement Design

HDL Simulation

HDL Code Generation

Conversion to Fixed Point

and Fixed-Point Verification

Map

Place & Route

Synthesis

Implement Design

Page 6: Implementing MATLAB Algorithms in FPGAs and ASICs · Implementing MATLAB Algorithms in FPGAs and ASICs By Alexander Schreiber Senior Application Engineer MathWorks . 2 ... –VHDL

6

MATLAB to HDL: The Big Challenges

MATLAB HDL

Floating point Fixed-Point

Procedural Concurrent + optimized

Untimed Timed with rates

Loops Streaming, Unrolling

Functions

System objects

Hardware-efficient

implementations

Algorithm land

Matrices Block RAMs

Architecture land

Page 7: Implementing MATLAB Algorithms in FPGAs and ASICs · Implementing MATLAB Algorithms in FPGAs and ASICs By Alexander Schreiber Senior Application Engineer MathWorks . 2 ... –VHDL

7

Authoring MATLAB for Hardware

Leveraging strenght of MATLAB

– Easily creating, accessing, modifying

and manipulating vectors and

matrices

Page 8: Implementing MATLAB Algorithms in FPGAs and ASICs · Implementing MATLAB Algorithms in FPGAs and ASICs By Alexander Schreiber Senior Application Engineer MathWorks . 2 ... –VHDL

8

Authoring MATLAB for Hardware

Leveraging strenght of MATLAB

– Easily creating, accessing, modifying

and manipulating vectors and

matrices

Modeling persistence

– RAM, ROM, registers, tap delays

– Finite State Machines

Page 9: Implementing MATLAB Algorithms in FPGAs and ASICs · Implementing MATLAB Algorithms in FPGAs and ASICs By Alexander Schreiber Senior Application Engineer MathWorks . 2 ... –VHDL

9

Authoring MATLAB for Hardware

Leveraging strenght of MATLAB

– Easily creating, accessing, modifying

and manipulating vectors and

matrices

Modeling persistence

– RAM, ROM, registers, tap delays

– Finite State Machines

Using System Objects

– Modular and reusable

– Implicit state handling

– Library of predefined System Objects

– Support of User-Defined System

Objects

Page 10: Implementing MATLAB Algorithms in FPGAs and ASICs · Implementing MATLAB Algorithms in FPGAs and ASICs By Alexander Schreiber Senior Application Engineer MathWorks . 2 ... –VHDL

10

From Algorithm to Implementation

HDL Simulation

HDL Code Generation

Conversion to Fixed Point

and Fixed-Point Verification

MATLAB® Algorithm and System Design

Model Refinement for Hardware

Map

Place & Route

Synthesis

Implement Design

HDL Simulation

HDL Code Generation

MATLAB® Algorithm and System Design

Model Refinement for Hardware

Map

Place & Route

Synthesis

Implement Design

Page 11: Implementing MATLAB Algorithms in FPGAs and ASICs · Implementing MATLAB Algorithms in FPGAs and ASICs By Alexander Schreiber Senior Application Engineer MathWorks . 2 ... –VHDL

11

Fixed-Point Conversion and Verification

Dynamic Range Analysis

– Based on stimuli or derived ranges

Page 12: Implementing MATLAB Algorithms in FPGAs and ASICs · Implementing MATLAB Algorithms in FPGAs and ASICs By Alexander Schreiber Senior Application Engineer MathWorks . 2 ... –VHDL

12

Fixed-Point Conversion and Verification

Dynamic Range Analysis

– Based on stimuli or derived ranges

Autoscaling of Fixed-Point Data

Type

– Either word length or precision based

– Selectable behaviour

Integer: saturation, wrapping

Fraction: rounding method

Page 13: Implementing MATLAB Algorithms in FPGAs and ASICs · Implementing MATLAB Algorithms in FPGAs and ASICs By Alexander Schreiber Senior Application Engineer MathWorks . 2 ... –VHDL

13

Fixed-Point Conversion and Verification

Dynamic Range Analysis

– Based on stimuli or derived ranges

Autoscaling of Fixed-Point Data

Type

– Either word length or precision based

– Selectable behaviour

Integer: saturation, wrapping

Fraction: rounding method

Automatic Generation of Bit-true

Fixed-Point MATLAB Function

Page 14: Implementing MATLAB Algorithms in FPGAs and ASICs · Implementing MATLAB Algorithms in FPGAs and ASICs By Alexander Schreiber Senior Application Engineer MathWorks . 2 ... –VHDL

14

Fixed-Point Conversion and Verification

Dynamic Range Analysis

– Based on stimuli or derived ranges

Autoscaling of Fixed-Point Data

Type

– Either word length or precision based

– Selectable behaviour

Integer: saturation, wrapping

Fraction: rounding method

Automatic Generation of Bit-true

Fixed-Point MATLAB Function

Verification of Fixed-Point Scaling

– Comparison vs. floating-point result

– Iteration in Workflow Advisor if needed

Page 15: Implementing MATLAB Algorithms in FPGAs and ASICs · Implementing MATLAB Algorithms in FPGAs and ASICs By Alexander Schreiber Senior Application Engineer MathWorks . 2 ... –VHDL

15

From Algorithm to Implementation

HDL Simulation

HDL Code Generation

Conversion to Fixed Point

and Fixed-Point Verification

MATLAB® Algorithm and System Design

Model Refinement for Hardware

Map

Place & Route

Synthesis

Implement Design

HDL Simulation

Conversion to Fixed Point

and Fixed-Point Verification

MATLAB® Algorithm and System Design

Model Refinement for Hardware

Map

Place & Route

Synthesis

Implement Design

Page 16: Implementing MATLAB Algorithms in FPGAs and ASICs · Implementing MATLAB Algorithms in FPGAs and ASICs By Alexander Schreiber Senior Application Engineer MathWorks . 2 ... –VHDL

16

Automatic HDL Code Generation

Based on native MATLAB

– Generic, i.e. technology independent

algorithm description

– Leveraging MATLAB stengths, e.g.

vector and matrix arithmetic

Generic RTL HDL

– FPGA vendor independent

– VHDL or Verilog

Bit-true and Cycle-accurate wrt. to

Fixed-Point MATLAB Function

Page 17: Implementing MATLAB Algorithms in FPGAs and ASICs · Implementing MATLAB Algorithms in FPGAs and ASICs By Alexander Schreiber Senior Application Engineer MathWorks . 2 ... –VHDL

17

Automatic HDL Code Generation

Based on native MATLAB

– Generic, i.e. technology independent

algorithm description

– Leveraging MATLAB stengths, e.g.

vector and matrix arithmetic

Generic RTL HDL

– FPGA vendor independent

– VHDL or Verilog

Bit-true and Cycle-accurate wrt. to

Fixed-Point MATLAB Function

Traceability between HDL Code and

MATLAB Fixed-Point Function

Page 18: Implementing MATLAB Algorithms in FPGAs and ASICs · Implementing MATLAB Algorithms in FPGAs and ASICs By Alexander Schreiber Senior Application Engineer MathWorks . 2 ... –VHDL

18

Optimization: Speed

Regis

ter

Smaller

critical path

Regis

ter

Automatic pipelining

Helps you meet speed objectives

Page 19: Implementing MATLAB Algorithms in FPGAs and ASICs · Implementing MATLAB Algorithms in FPGAs and ASICs By Alexander Schreiber Senior Application Engineer MathWorks . 2 ... –VHDL

19

Optimization: Area

Page 20: Implementing MATLAB Algorithms in FPGAs and ASICs · Implementing MATLAB Algorithms in FPGAs and ASICs By Alexander Schreiber Senior Application Engineer MathWorks . 2 ... –VHDL

20

From Algorithm to Implementation

HDL Simulation

HDL Code Generation

Conversion to Fixed Point

and Fixed-Point Verification

MATLAB® Algorithm and System Design

Model Refinement for Hardware

Map

Place & Route

Synthesis

Implement Design

HDL Code Generation

Conversion to Fixed Point

and Fixed-Point Verification

MATLAB® Algorithm and System Design

Model Refinement for Hardware

Map

Place & Route

Synthesis

Implement Design

Page 21: Implementing MATLAB Algorithms in FPGAs and ASICs · Implementing MATLAB Algorithms in FPGAs and ASICs By Alexander Schreiber Senior Application Engineer MathWorks . 2 ... –VHDL

21

HDL Verification HDL Coder

Automatic Recording of input and

output streams of MATLAB

simulation

Automatic Generation of stand-

alone HDL Test Bench

– Generic, i.e. pure HDL

– Can be simulated in any HDL

simulator

– Self-testing, i.e. uses recorded input

and output streams

Drawback

– MATLAB visualization and analysis

capabilities cannot be leveraged

Stimulus Reference

Results

Automatically Generated HDL Test Bench

Stimulus Actual

Results HDL Design

MATLAB Test Bench

MATLAB Function

targeted to Hardware

Page 22: Implementing MATLAB Algorithms in FPGAs and ASICs · Implementing MATLAB Algorithms in FPGAs and ASICs By Alexander Schreiber Senior Application Engineer MathWorks . 2 ... –VHDL

22

HDL Co-Simulation

Re-use MATLAB test bench

Leverage visualization capabilities

in time and spectrum domain

Combined analysis in HDL

Simulator and MATLAB/Simulink

HDL Verifier

Connects HDL simulation with the

MATLAB environment!

HDL

Entity

In

Ou

t

HDL Simulator

MATLAB Functions

Stimulus Response

Input

stimuli Output

response

Page 23: Implementing MATLAB Algorithms in FPGAs and ASICs · Implementing MATLAB Algorithms in FPGAs and ASICs By Alexander Schreiber Senior Application Engineer MathWorks . 2 ... –VHDL

23

FPGA-in-the-Loop Verification HDL Verifier

Re-use the MATLAB test bench

Leverage visualization capabilities

in time and spectrum domain

Accelerate verification with FPGA

hardware

HDL Verifier

Connects FPGA HW with the MATLAB

environment!

MATLAB Functions

Input

stimuli

Output

response

Response Stimulus

Page 24: Implementing MATLAB Algorithms in FPGAs and ASICs · Implementing MATLAB Algorithms in FPGAs and ASICs By Alexander Schreiber Senior Application Engineer MathWorks . 2 ... –VHDL

24

From Algorithm to Implementation

HDL Simulation

HDL Code Generation

Conversion to Fixed Point

and Fixed-Point Verification

MATLAB® Algorithm and System Design

Model Refinement for Hardware

Map

Place & Route

Synthesis

Implement Design

HDL Simulation

HDL Code Generation

Conversion to Fixed Point

and Fixed-Point Verification

MATLAB® Algorithm and System Design

Model Refinement for Hardware

Page 25: Implementing MATLAB Algorithms in FPGAs and ASICs · Implementing MATLAB Algorithms in FPGAs and ASICs By Alexander Schreiber Senior Application Engineer MathWorks . 2 ... –VHDL

25

Automated Workflow for FPGA Implementation

Integration with Xilinx ISE and

Altera Quartus II

– Project creation

– Synthesis

– Place and Route

– Reporting

Resource utilization

Timing analysis

Rapid exploration of

implementation options through

quick iteration

Page 26: Implementing MATLAB Algorithms in FPGAs and ASICs · Implementing MATLAB Algorithms in FPGAs and ASICs By Alexander Schreiber Senior Application Engineer MathWorks . 2 ... –VHDL

26

Model-Based Design for FPGA Implementation

DESIGN

Algorithm

Development

MATLAB

Simulink

Stateflow

Shorter development cycles

Short iteration cycles

Optimization of algorithm at a system level

automated/assisted

Fixed Point Conversion

automatic

HDL Code Generation

integrated

FPGA Verification

System-level

HDL Refinement

integrated

HDL Verification

integrated

HDL Verification

Page 27: Implementing MATLAB Algorithms in FPGAs and ASICs · Implementing MATLAB Algorithms in FPGAs and ASICs By Alexander Schreiber Senior Application Engineer MathWorks . 2 ... –VHDL

27

Solution: Model-Based Design using MATLAB

Design, simulate, and validate algorithms and system models in MATLAB and Simulink

Automatically generate and optimize HDL code

Verify the HDL/hardware implementation against the system model

Veri

fy

ASIC FPGA

HDL

HDL Coder

HDL Verifier

MATLAB® and Simulink®

Algorithm Design and System Design

Gen

era

te