Professional Documents
Culture Documents
Bill Chou
Agenda
Motivation
Why translate MATLAB to C?
Challenges of manual translation
Use cases
Integrate algorithms using source code/libraries
Accelerate through MEX
Prototype by generating EXE
Conclusion
Integration with Simulink and Embedded Coder
Other deployment solutions
2
.c
.lib
.dll
.exe
MEX
Design
Test
Test and Verification
Elaborate
Implementation
Desktop
Embedded
.dll
.exe
VHDL/Verilog
.c,
C, .cpp
C++
Structured Text
Design
Test
Elaborate
MATLAB
MATLAB
Compiler
MATLAB
Compiler SDK
MATLAB Coder
MATLAB
Runtime
.c
.exe
Algorithm Design
in MATLAB
.lib
.dll
Re-code in
C/C++
MEX
ra
t
.c
.exe
.lib
.dll
MEX
Simple Demo
c = a*b
>> Demo
8
Agenda
Motivation
Why translate MATLAB to C?
Challenges of manual translation
Use cases
Integrate algorithms using source code/libraries
Accelerate through MEX
Prototype by generating EXE
Conclusion
Integration with Simulink and Embedded Coder
Other deployment solutions
9
Implementation Considerations
Elementbybyelement
elementmultiply
multiply
Element
Element
by element multiply
function a= foo(b,c)
a = b * c;
C
double foo(double b, double c)
{
return b*c;
}
Dotproduct
product
Dot
Dot
product
logical
integer
real
complex
Matrixmultiply
multiply
Matrix
Matrix
multiply
void foo(const double b[15],
const double c[30], double a[18])
{
int i0, i1, i2;
for (i0 = 0; i0 < 3; i0++) {
for (i1 = 0; i1 < 6; i1++) {
a[i0 + 3 * i1] = 0.0;
for (i2 = 0; i2 < 5; i2++) {
a[i0 + 3 * i1] += b[i0 + 3 * i2] * c[i2 + 5 * i1];
}
}
}
}
11
Implementation Considerations
Polymorphism
Memory allocation
Processing matrices and arrays
Fixed-point data types
7
Lines of MATLAB
105 Lines of C
12
Pre-allocate
Identify more efficient constructs
Select code generation options
>> Demo
13
visualization
variable-sized data
Java
struct
nested functions
global
complex
cell arrays
malloc
functions
numeric
System objects
fixed-point arrays
classes
persistent
graphics
sparse
14
Matrix operations
N-dimensional arrays
Subscripting
Frames
Persistent variables
Global variables
Data Types
Complex numbers
Integer math
Double/single-precision
Fixed-point arithmetic
Characters
Structures
Numeric class
Variable-sized data
MATLAB Class
System objects
Programming Constructs
Arithmetic, relational, and logical
operators
Program control
(if, for, while, switch)
Functions
MATLAB functions and subfunctions
Variable-length argument lists
Function handles
Supported algorithms
More than 1100 MATLAB operators,
functions, and System objects for:
Communications
Computer vision
Image processing
Phased Array signal processing
Signal processing
Statistics
15
Supported Functions
1200+
Aerospace Toolbox
Communications System Toolbox
Computer Vision System Toolbox
DSP System Toolbox
Image Processing Toolbox
Agenda
Motivation
Why translate MATLAB to C?
Challenges of manual translation
Use cases
Integrate algorithms using source code/libraries
Accelerate through MEX
Prototype by generating EXE
Conclusion
Integration with Simulink and Embedded Coder
Other deployment solutions
17
.lib
.dll
MEX
.exe
.c
18
MATLAB
>> Demo
20
Acceleration Strategies
Better algorithms
Matrix inversion vs. QR or SVD
Different approaches to solving the same problem
22
Optimize
MATLAB code
Parallel
computing
System
objects
Custom
code using MEX
MATLAB to C
23
Optimize
MATLAB code
System
objects
Parallel
computing
MATLAB to C
>> Demo
24
25
>> Demo
26
Agenda
Motivation
Why translate MATLAB to C?
Challenges of manual translation
Use cases
Integrate algorithms using source code/libraries
Accelerate through MEX
Prototype by generating EXE
Conclusion
Integration with Simulink and Embedded Coder
Other deployment solutions
27
28
30
32
Design
Test
Elaborate
Implementation
Desktop
Embedded
Design
.dll
.exe
VHDL/Verilog
.c, .cpp
Structured Text
Test
Elaborate
33
Standalone
Application
Excel
Add-in
MATLAB
Compiler SDK
Hadoop
C/C++
Java
.NET
MATLAB
Production
Server
.c
MATLAB Coder
Output
MATLAB support
Additional libraries
License model
Extensions
MATLAB Compiler
MATLAB Compiler SDK
Software components
Full language
Most toolboxes
Graphics
None
MATLAB Runtime
Royalty-free
Royalty-free
Embedded Coder
MATLAB Production
Server
35
More Information
36
Q&A
37