+ All Categories
Home > Documents > nuNumerical Analysis techniques with MATLAB

nuNumerical Analysis techniques with MATLAB

Date post: 02-Jun-2018
Category:
Upload: khaleelanwar2000
View: 226 times
Download: 0 times
Share this document with a friend

of 100

Transcript
  • 8/10/2019 nuNumerical Analysis techniques with MATLAB

    1/100

    1

    2011 The MathWorks, Inc.

    2011 Technology Trend Seminar

    Speed up numerical analysis with

    MATLAB

    MathWorks: Giorgia Zucchelli TU Delft: Prof.dr.ir. Kees Vuik

    Marieke van Geffen

    Rachid Adarghal Thales Nederland: Dnis Riedijk

  • 8/10/2019 nuNumerical Analysis techniques with MATLAB

    2/100

    2

    Agenda

    14:00 Welcome and introduction

    14:10 Overview of numerical analysis techniques with MATLAB

    14:50 Break

    15:10 Speeding up the execution of your MATLAB code

    16:00 Break

    16:20 GPU computing with MATLAB

    16:30 Use of GPUs at Thales Nederland

    17:00 Discussion and wrap up

  • 8/10/2019 nuNumerical Analysis techniques with MATLAB

    3/100

    3

    Overview of numerical analysis

    techniques with MATLAB

  • 8/10/2019 nuNumerical Analysis techniques with MATLAB

    4/100

    4

    Numerical analysis tasks

    Solving linear equations

    Interpolation

    Finding zeros and roots

    Optimization and least squares Determining integrals

    Statistics and random number generation

    Fourier analysis

    Ordinary differential equations

    Partial differential equation

  • 8/10/2019 nuNumerical Analysis techniques with MATLAB

    5/100

    5

    Numerical analysis with MATLAB (and Toolboxes)

    Solving linear equations

    Interpolation

    Finding zeros and roots

    Optimization and least squaresDetermining integrals

    Statistics and random number generation

    Fourier analysis

    Ordinary differential equations

    Partial differential equation

  • 8/10/2019 nuNumerical Analysis techniques with MATLAB

    6/100

    6

    Do need to solve numerical analysis tasks?

    For standard tasks, do not re-invent the wheel:

    MATLAB and Toolboxes

    MATLAB Central

    Sources developed by others, eg. C, Fortran code

    For advanced research:

    Choose your preferred language / environment

    Develop innovation using MATLAB for testing and visualization

  • 8/10/2019 nuNumerical Analysis techniques with MATLAB

    7/1007

    Do need to solve numerical analysis tasks?

    For standard tasks, do not re-invent the wheel:

    MATLAB and Toolboxes

    MATLAB Central

    Sources developed by others, eg. C, Fortran code

    Example: curve fitting

    For advanced research:

    Choose your preferred language / environment

    Develop innovation using MATLAB for testing and visualization

    Example: import C code in MATLAB

  • 8/10/2019 nuNumerical Analysis techniques with MATLAB

    8/1008

    Example: curve fitting with MATLAB

    Two common challenges in creating an accurate curve fit:

    Cant describe the relationship

    between your variables

    Cant specify good starting points

    for your solvers

  • 8/10/2019 nuNumerical Analysis techniques with MATLAB

    9/1009

    Challenge 1

    Generat ing a Good Fit

    Without Domain Know ledge

  • 8/10/2019 nuNumerical Analysis techniques with MATLAB

    10/10010

    Regression techniques

    Require that the user specify a model

    Choice of model is based on domain knowledge

    Example - popu lat ion models

    Logistic Growth

    Exponential Growth

  • 8/10/2019 nuNumerical Analysis techniques with MATLAB

    11/10011

    What if you dont know what model to use?

  • 8/10/2019 nuNumerical Analysis techniques with MATLAB

    12/10012

    Line Quadratic Rational

    What if you dont know what model to use?

  • 8/10/2019 nuNumerical Analysis techniques with MATLAB

    13/10013

    Demo

  • 8/10/2019 nuNumerical Analysis techniques with MATLAB

    14/10014

    Summary

    Nonparametric fitting

    LOWESS: Curve Fitting Toolbox

    Cross Validation: Statistics Toolbox

  • 8/10/2019 nuNumerical Analysis techniques with MATLAB

    15/10015

    Challenge 2

    Pit fal ls Using Nonl inear Regression

  • 8/10/2019 nuNumerical Analysis techniques with MATLAB

    16/10016

    Nonlinear regression example

    ttteeeionConcentrat 654

    321

  • 8/10/2019 nuNumerical Analysis techniques with MATLAB

    17/100

    17

    Nonlinear regression example

    ttteeeionConcentrat 654

    321

  • 8/10/2019 nuNumerical Analysis techniques with MATLAB

    18/100

    18

    Practical implications:

    What does a bad R2mean?

    Bad model specification?

    Poor set of starting conditions?

  • 8/10/2019 nuNumerical Analysis techniques with MATLAB

    19/100

    19

    Demo

  • 8/10/2019 nuNumerical Analysis techniques with MATLAB

    20/100

    20

    Summary

    Use MultiStart to identify good starting conditions

    Global Optimization Toolbox

    Suitable for curve and surface fitting

  • 8/10/2019 nuNumerical Analysis techniques with MATLAB

    21/100

    21

    Challenge

    Re(use) external code in MATLAB

  • 8/10/2019 nuNumerical Analysis techniques with MATLAB

    22/100

    22

    Using (external) C code in MATLAB

    Create a MATLAB callable executable (MEX) from C,

    C++ or Fortran

    or

    Use MATLAB Coder to invoke the C code function

  • 8/10/2019 nuNumerical Analysis techniques with MATLAB

    23/100

    23

    Importing C code creating a MEX interface

    MEX wrapper

  • 8/10/2019 nuNumerical Analysis techniques with MATLAB

    24/100

    24

    Demo

  • 8/10/2019 nuNumerical Analysis techniques with MATLAB

    25/100

    25

    MEX wrapper to invoke C code in MATLAB

    Data type conversion

    Using mx library

    Dynamic memory management

    Error management and checking of the arguments

  • 8/10/2019 nuNumerical Analysis techniques with MATLAB

    26/100

    26

    Summary

    One time-only effort

    Invoke your C code in MATLAB

    Just like a MATLAB function

    Maintaining the performances

    Use MATLAB infrastructure

    Share your code with colleagues who are not C programmers

  • 8/10/2019 nuNumerical Analysis techniques with MATLAB

    27/100

    27

    Importing C code with MATLAB Coder

    MATLAB

    Coder

    MATLAB function (MEX)

  • 8/10/2019 nuNumerical Analysis techniques with MATLAB

    28/100

    28

    Demo

  • 8/10/2019 nuNumerical Analysis techniques with MATLAB

    29/100

    29

    Using MATLAB Coder to invoke C code

    coder.ceval to invoke

    the C code within a

    MATLAB function

    MATLAB Coder to generate

    source code (C code) fromthe MATLAB function

    The code is automatically

    embedded in the generated

    function

    The code is compiled as a

    MEX for rapid execution in

    MATLAB

  • 8/10/2019 nuNumerical Analysis techniques with MATLAB

    30/100

    30

    Summary

    Easy interface

    Do not require to program MEX interface

    Only a subset of MATLAB language and Toolboxes is

    supported

    Code generation MATLAB subset

    Suitable also for embedded applications

  • 8/10/2019 nuNumerical Analysis techniques with MATLAB

    31/100

    31

    Key takeaways

    For standard tasks, do not re-invent the wheel:

    MATLAB and Toolboxes

    MATLAB Central

    Sources developed by others, eg. C, Fortran code

    For advanced research:

    Choose your preferred language / environment

    Develop innovation using MATLAB for testing and visualization

  • 8/10/2019 nuNumerical Analysis techniques with MATLAB

    32/100

    32

    Speeding up the execution of your

    MATLAB code

  • 8/10/2019 nuNumerical Analysis techniques with MATLAB

    33/100

    33

    Hardware solutions

    More processing power

    Faster processors

    Dedicated hardware

    More processors

    More memory

    32 bit operating systems (4 GB of address space)

    64 bit operating systems (16,000 GB of address space)

    Multi-core Multiprocessor Cluster

    Grid,Cloud

    GPGPU,

    FPGA

    Single

    Processor

  • 8/10/2019 nuNumerical Analysis techniques with MATLAB

    34/100

    34

    Hardware & software solutions

    More processing power

    Faster processors

    Dedicated hardware

    More processors

    More memory

    32 bit operating systems (4 GB of address space)

    64 bit operating systems (16,000 GB of address space)

    GPU

    Computing

    Multithreaded Parallel

    Computing Distributed Computing

    MATLAB

  • 8/10/2019 nuNumerical Analysis techniques with MATLAB

    35/100

    35

    Slow execution? Out of memory errors?

    Know your enemy:

    Understand the constraints

    Identify bottlenecks

    Exploit data and task parallelism

    Find the best tradeoff between programming effort and

    achieving your goals

  • 8/10/2019 nuNumerical Analysis techniques with MATLAB

    36/100

    36

    MATLAB is multithreaded: new releases are faster

    No code changes required

    Enabled at MATLAB start-up

    Vector math improved

    Linear algebra operations

    Element-wise operations

    Linear Algebra Element-wise

  • 8/10/2019 nuNumerical Analysis techniques with MATLAB

    37/100

    37

    Understanding MATLAB improves efficiency

    How does MATLAB store data?

    What data types does MATLAB support?

    How much overhead is there for arrays,

    structures, and cell arrays?

    When are data copies made?

  • 8/10/2019 nuNumerical Analysis techniques with MATLAB

    38/100

    38

    What is the largest array you can create in

    MATLAB on 32 bit Windows XP?

    a) 0.5 GB

    b) 1.0 GB

    c) 1.5 GB

    d) 2.0 GB

    e) 2.5 GB

    Memory Addresses

    Operating System

    Process

  • 8/10/2019 nuNumerical Analysis techniques with MATLAB

    39/100

    39

    Contiguous memory and copy on write

    >> x = rand(100,1)

    >> y = x

    >> y(1) = 0

    Do not grow arrays within loops!

    x = rand(100,1)

    y = x

    Allocated

    y = [ 0, x(2:end)]

  • 8/10/2019 nuNumerical Analysis techniques with MATLAB

    40/100

    40

    In-place memory operations

    >> x = rand(100,1)

    >> x = 2*x+12;

    >> y = 2*x+12;

    Tradeoff readability with

    performances

    x = rand(100,1)

    x = x*2+12;

    Allocated

    y = x*2+12;

  • 8/10/2019 nuNumerical Analysis techniques with MATLAB

    41/100

    43

    Plot only what you need

    How much memory is needed to plot a 10 MB double array?

    >> y = rand(125e4,1);

    >> plot(y);

    a) 0 MB

    b) 10 MB

    b) 20 MB

    c) 30 MB

    d) 40 MB

  • 8/10/2019 nuNumerical Analysis techniques with MATLAB

    42/100

    44

    Plot only what you need

    Every plot independently stores x and y data

    >> y = rand(125e4,1); %10MB

    >> plot(y) ; %20MB for x and y data

    Integers plotted as doubles

    Strategies:

    Downsample your data prior to plotting (e.g. every 10th element)

    Divide your data into regular intervals and plot values of interest

  • 8/10/2019 nuNumerical Analysis techniques with MATLAB

    43/100

    46

    Example: fitting data

    Load data from multiple files

    Extract a specific test

    Fit a spline to the data

    Write results to Microsoft Excel

  • 8/10/2019 nuNumerical Analysis techniques with MATLAB

    44/100

    47

    Classes of bottlenecks

    File I/O

    Disk is slow compared to RAM

    When possible, use loadand save commands

    Displaying output

    Creating new figures is expensive

    Writing to command window is slow

    Computationally intensive

    Trade-off modularization, readability and performance

  • 8/10/2019 nuNumerical Analysis techniques with MATLAB

    45/100

    48

    Techniques for improving performance

    Vectorization

    Take full advantage of BLAS and LAPACK

    Brute force vectorization: cellfun, structfun, arrayfun

    Preallocation

    Minimize changing variable class

    Mexing (compiled code)

  • 8/10/2019 nuNumerical Analysis techniques with MATLAB

    46/100

    49

    Programming parallel applications

    Level of control

    Minimal

    Some

    Extensive

    Required effort

    None

    Straightforward

    Involved

  • 8/10/2019 nuNumerical Analysis techniques with MATLAB

    47/100

    50

    Programming parallel applications

    Level of control

    Minimal

    Some

    Extensive

    Required effort

    Built-in into

    Toolboxes

    Straightforward

    Involved

  • 8/10/2019 nuNumerical Analysis techniques with MATLAB

    48/100

    51

    Example: optimizing tower placement

    Determine location of cell towers

    Maximize coverage

    Minimize overlap

  • 8/10/2019 nuNumerical Analysis techniques with MATLAB

    49/100

    52

    Summary of example

    Enabled built-in support for

    Parallel Computing Toolbox

    in Optimization Toolbox

    Used a pool of MATLAB workers

    Optimized in parallel using fmincon

  • 8/10/2019 nuNumerical Analysis techniques with MATLAB

    50/100

    53

    Parallel support in Optimization Toolbox

    Functions:

    fmincon

    Finds a constrained minimum of a function of several variables

    fminimax

    Finds a minimax solution of a function of several variables fgoalattain

    Solves the multiobjective goal attainment optimization problem

    Functions can take finite differences in parallelin order to speed the estimation of gradients

  • 8/10/2019 nuNumerical Analysis techniques with MATLAB

    51/100

    54

    Toolboxes with built-in supportContain func t ions to d irect ly leverage the Parallel Computing Too lbox

    Optimization Toolbox

    Global Optimization Toolbox

    Statistics Toolbox

    SystemTest Simulink Design Optimization

    Bioinformatics Toolbox

    Model-Based Calibration Toolbox

    Communications System Toolbox

    Worker

    Worker

    Worker

    WorkerWorker

    Worker

    WorkerTOOLBOXES

    BLOCKSETS

  • 8/10/2019 nuNumerical Analysis techniques with MATLAB

    52/100

    55

    Programming parallel applications

    Level of control

    Minimal

    Some

    Extensive

    Required effort

    Built-in into

    Toolboxes

    High Level Programming

    (parfor)

    Involved

  • 8/10/2019 nuNumerical Analysis techniques with MATLAB

    53/100

    56

    Parallel tasks

    Time Time

    Task 1 Task 2 Task 3 Task 4Task 1 Task 2 Task 3 Task 4

    TOOLBOXES

    BLOCKSETS

    Worker

    Worker

    Worker

    Worker

  • 8/10/2019 nuNumerical Analysis techniques with MATLAB

    54/100

    57

    Example: parameter sweep of ODEs

    Solve a 2nd order ODE

    Simulate with different

    values for band k

    Record peak value for each run

    Plot results

    0

    ,...2,1,...2,1

    5

    xkxbxm

    0 5 10 15 20 25-0.4

    -0.2

    0

    0.2

    0.4

    0.6

    0.8

    1

    1.2

    Time (s)

    Displacement(x)

    m = 5, b = 2, k = 2

    m = 5, b = 5, k = 5

    0

    2

    4

    6 12

    34

    5

    0.5

    1

    1.5

    2

    2.5

    Stiffness (k)Damping (b)

    PeakDisplacement

    (x)

  • 8/10/2019 nuNumerical Analysis techniques with MATLAB

    55/100

    58

    Summary of example

    Mixed task-parallel and serial

    code in the same function

    Ran loops on a pool of

    MATLAB resources

    Used Code Analyzer to helpin converting existing for-loopintoparfor-loop

    0 5 10 15 20 25-0.4

    -0.2

    0

    0.2

    0.4

    0.6

    0.8

    1

    1.2

    Time (s)

    Displacement(x)

    m = 5, b = 2, k = 2

    m = 5, b = 5, k = 5

    0

    2

    4

    6 12

    34

    5

    0.5

    1

    1.5

    2

    2.5

    Stiffness (k)Damping (b)

    PeakDisplacement

    (x)

  • 8/10/2019 nuNumerical Analysis techniques with MATLAB

    56/100

    62

    Programming parallel applications

    Level of control

    Minimal

    Some

    Extensive

    Required effort

    Built-in into

    Toolboxes

    High Level Programming

    (distributed / spmd)

    Involved

  • 8/10/2019 nuNumerical Analysis techniques with MATLAB

    57/100

    63

    Parallel data distribution

    1

    1

    2

    6

    4

    11

    2

    2

    7

    4

    21

    3

    2

    8

    4

    31

    4

    2

    9

    4

    41

    5

    3

    0

    4

    51

    6

    3

    1

    4

    61

    7

    3

    2

    4

    71

    7

    3

    3

    4

    81

    9

    3

    4

    4

    92

    0

    3

    5

    5

    02136512

    2

    3

    7

    5

    2

    1

    1

    2

    6

    4

    11

    2

    2

    7

    4

    21

    3

    2

    8

    4

    31

    4

    2

    9

    4

    41

    5

    3

    0

    4

    51

    6

    3

    1

    4

    61

    7

    3

    2

    4

    71

    7

    3

    3

    4

    81

    9

    3

    4

    4

    92

    0

    3

    5

    5

    02136512

    2

    3

    7

    5

    2

    TOOLBOXES

    BLOCKSETS

  • 8/10/2019 nuNumerical Analysis techniques with MATLAB

    58/100

    65

    Programming parallel applications

    Level of control

    Minimal

    Some

    Extensive

    Required effort

    Built-in into

    Toolboxes

    High Level Programming

    (interactive vs. scheduled)

    Involved

  • 8/10/2019 nuNumerical Analysis techniques with MATLAB

    59/100

    66

    Interactive to scheduled

    Interactive

    Great for prototyping

    Immediate access to MATLAB workers

    Scheduled

    Offloads work to other MATLAB workers (local or on a cluster)

    Access to more computing resources for improved performance

    Frees up local MATLAB session

  • 8/10/2019 nuNumerical Analysis techniques with MATLAB

    60/100

    67

    Scheduling work

    TOOLBOXES

    BLOCKSETS

    Scheduler

    Work

    Result

    Worker

    Worker

    Worker

    Worker

  • 8/10/2019 nuNumerical Analysis techniques with MATLAB

    61/100

    68

    Example: schedule processing

    Offload parameter sweep

    to local workers

    Get peak value results when

    processing is complete

    Plot results in local MATLAB0 5 10 15 20 25

    -0.4

    -0.2

    0

    0.2

    0.4

    0.6

    0.8

    1

    1.2

    Time (s)

    Displacement(x)

    m = 5, b = 2, k = 2

    m = 5, b = 5, k = 5

    0

    2

    4

    6 12

    34

    5

    0.5

    1

    1.5

    2

    2.5

    Stiffness (k)Damping (b)

    PeakDisplacement

    (x)

  • 8/10/2019 nuNumerical Analysis techniques with MATLAB

    62/100

    69

    Summary of example

    Usedbatch for off-loading work

    Usedmatlabpool option to

    off-load and run in parallel

    Used loadto retrieve

    workers workspace0 5 10 15 20 25

    -0.4

    -0.2

    0

    0.2

    0.4

    0.6

    0.8

    1

    1.2

    Time (s)

    Displacement(x)

    m = 5, b = 2, k = 2

    m = 5, b = 5, k = 5

    0

    2

    4

    6 12

    34

    5

    0.5

    1

    1.5

    2

    2.5

    Stiffness (k)Damping (b)

    PeakDisplacement

    (x)

  • 8/10/2019 nuNumerical Analysis techniques with MATLAB

    63/100

    70

    Programming parallel applications

    Level of control

    Minimal

    Some

    Extensive

    Required effort

    Built-in into

    Toolboxes

    High Level Programming

    (parfor, spmd, batch)

    Low-Level

    Programming Constructs:(e.g. Jobs/Tasks, MPI-based)

  • 8/10/2019 nuNumerical Analysis techniques with MATLAB

    64/100

    71

    Task-parallel workflows

    parfor

    Multiple independent iterations

    Easy to combine serial and parallel code

    Workflow Interactive usingmatlabpool

    Scheduled usingbatch

    jobs/tasks

    Series of independent tasks; not necessarily iterations

    Workflow Always scheduled

  • 8/10/2019 nuNumerical Analysis techniques with MATLAB

    65/100

    72

    Example: scheduling independent simulations

    Offload three independentapproaches to solving our

    previous ODE example

    Retrieve simulated displacement

    as a function of time foreach simulation

    Plot comparison of results

    in local MATLAB

    0 5 10 15 20 25-0.4

    -0.2

    0

    0.2

    0.4

    0.6

    0.8

    1

    1.2

    Time (s)

    Displacement(x)

    m = 5, b = 2, k = 2

    m = 5, b = 5, k = 5

  • 8/10/2019 nuNumerical Analysis techniques with MATLAB

    66/100

    73

    Summary of example

    Used findResource to find scheduler

    Used createJob and createTask

    to set up the problem

    Used submit to off-load and

    run in parallel

    Used getAllOutputArguments

    to retrieve all task outputs 0 5 10 15 20 25-0.4-0.2

    0

    0.2

    0.4

    0.6

    0.8

    1

    1.2

    Time (s)

    Displacement(x)

    m = 5, b = 2, k = 2

    m = 5, b = 5, k = 5

  • 8/10/2019 nuNumerical Analysis techniques with MATLAB

    67/100

    74

    MPI-Based functions for higher control

    High-level abstractions of MPI functions

    labSendReceive, labBroadcast, and others

    Send, receive, and broadcast any data type in MATLAB

    Automatic bookkeeping

    Setup: communication, ranks, etc.

    Error detection: deadlocks and miscommunications

    Pluggable

    Use any MPI implementation that is binary-compatible with MPICH2

  • 8/10/2019 nuNumerical Analysis techniques with MATLAB

    68/100

    75

    Run 8 local workers on desktop

    Rapidly develop parallel

    applications on local computer

    Take full advantage ofdesktop power

    Separate computer cluster

    not required

    Desktop Computer

    Parallel Computing Toolbox

  • 8/10/2019 nuNumerical Analysis techniques with MATLAB

    69/100

    76

    Scale up to clusters, grids and clouds

    Desktop Computer

    Parallel Computing Toolbox

    Computer Cluster

    MATLAB Distributed Computing Server

    Scheduler

  • 8/10/2019 nuNumerical Analysis techniques with MATLAB

    70/100

    77

    Open API for others

    Support for schedulers

    Direct Support

    TORQUE

    http://www.univa.com/http://www.microsoft.com/hpc/en/us/default.aspx
  • 8/10/2019 nuNumerical Analysis techniques with MATLAB

    71/100

    78

    Key takeaways

    Profile MATLAB to write efficient code

    Use parallel computing to speed up execution

    Tradeoff effort with speedup requirements

    Scale up to clusters without code changes

  • 8/10/2019 nuNumerical Analysis techniques with MATLAB

    72/100

    79

    GPU computing with MATLAB

    H t l t MATLAB h d

  • 8/10/2019 nuNumerical Analysis techniques with MATLAB

    73/100

    80

    How to accelerate MATLAB on hardware

    Use DSPs for real-time execution On target automatic C code generation

    Deploy on FPGAs

    Synthesizable automatic HDL code generation

    Use multi-core PCs

    Multithreaded parallel computing

    Distribute on a cluster

    Distributed computing

    Use GP-GPUs New in R2010b

    Wh GPU ?

  • 8/10/2019 nuNumerical Analysis techniques with MATLAB

    74/100

    81

    Why GPUs now?

    GPUs are a commodity

    Massively parallel architecture that can speed up

    intensive computations

    GPU are more generically programmable

    From 3D gaming to scientific computing

    S di li ti ith GPU

  • 8/10/2019 nuNumerical Analysis techniques with MATLAB

    75/100

    82

    Speeding up applications with GPUs

    Different achievable speedups depending on: Hardware

    Type of application

    Programmer skills

    Source: NVIDIA

    A li ti th t ill f t GPU

  • 8/10/2019 nuNumerical Analysis techniques with MATLAB

    76/100

    83

    Applications that will run faster on GPUs

    Massively parallel tasks

    Computationally intensive tasks

    Tasks that have limited kernel size

    Tasks that do not necessarily require

    double accuracy

    All these requirements need to be satisfied!

    &

    P i GPU li ti

  • 8/10/2019 nuNumerical Analysis techniques with MATLAB

    77/100

    84

    Programming GPU applications

    Level of control

    Minimal

    Some

    Extensive

    Required effort

    None

    Straightforward

    Involved

    P i GPU li ti

  • 8/10/2019 nuNumerical Analysis techniques with MATLAB

    78/100

    85

    Programming GPU applications

    Level of control

    Minimal

    Some

    Extensive

    Required effort

    Built-in functions

    Straightforward

    Involved

    I k b ilt i MATLAB f ti th GPU

  • 8/10/2019 nuNumerical Analysis techniques with MATLAB

    79/100

    86

    Invoke built-in MATLAB functions on the GPU

    Accelerate standard (highly parallel) functions More than 100 MATLAB functions are already supported

    Communication System Object: ldpc.encoder, ldpc.decoder

    Out of the box:

    No additional effort for programming the GPU

    No accuracy for speed trade-off

    Double floating-point precision computations

    Invoke built in MATLAB functions on the GPU

  • 8/10/2019 nuNumerical Analysis techniques with MATLAB

    80/100

    87

    Define an array on the GPU

    A = rand(1000,1);

    B = rand(1000,1);

    A_gpu = gpuArray(A);

    B_gpu = gpuArray(B);

    Execute a built-in MATLAB function:

    Y_gpu = B_gpu\A_gpu;

    Retrieve data from the GPUresult = gather(Y_gpu);

    Invoke built-in MATLAB functions on the GPU(1) Minimal effort, minimal level of control

    Benchmarking A\b on the GPU

  • 8/10/2019 nuNumerical Analysis techniques with MATLAB

    81/100

    88

    Benchmarking A\b on the GPU

    Programming GPU applications

  • 8/10/2019 nuNumerical Analysis techniques with MATLAB

    82/100

    89

    Programming GPU applications

    Level of control

    Minimal

    Some

    Extensive

    Required effort

    Built-in functions

    Functions on array

    data

    Involved

    Run MATLAB functions on the GPU

  • 8/10/2019 nuNumerical Analysis techniques with MATLAB

    83/100

    90

    Run MATLAB functions on the GPU

    Accelerate scalar operations on large arrays Take full advantage on data parallelism

    Out of the box:

    No additional effort for programming the GPU

    No accuracy for speed trade-off Double floating-point precision computations

    Run MATLAB functions on the GPU

  • 8/10/2019 nuNumerical Analysis techniques with MATLAB

    84/100

    91

    MATLAB function that perform element-wise arithmetic

    function y = TaylorFun(x)

    y = 1 + x*(1 + x*(1 + x*(1 + ...x*(1 + x*(1 + x*(1 + x*(1 + ...

    x*(1 + ./9)./8)./7)./6)./5)./4)./3)./2); Load data on the GPU

    A = rand(1000,1);

    A_gpu = gpuArray(A);

    Execute the function as GPU kernels

    result = arrayfun(@TaylorFun, A_gpu);

    Run MATLAB functions on the GPU(2) Straightforward effort, regular level of control

    Benchmarking vector operations on the GPU

  • 8/10/2019 nuNumerical Analysis techniques with MATLAB

    85/100

    92

    Benchmarking vector operations on the GPU

    Programming GPU applications

  • 8/10/2019 nuNumerical Analysis techniques with MATLAB

    86/100

    93

    Programming GPU applications

    Level of control

    Minimal

    Some

    Extensive

    Required effort

    Built-in functions

    Functions on array

    data

    Directly invoke

    CUDA code

    Directly invoke CUDA code from MATLAB

  • 8/10/2019 nuNumerical Analysis techniques with MATLAB

    87/100

    94

    Directly invoke CUDA code from MATLAB

    Benefit from legacy code highly optimized for speed Achieve all the speed improvement that CUDA can deliver

    Use MATLAB as a test environment

    Generation of test signal

    Post-processing of results

    Suitable also for non-experts

    Invoke CUDA Code from MATLAB

  • 8/10/2019 nuNumerical Analysis techniques with MATLAB

    88/100

    95

    Compile CUDA (or PTX) code on the GPUnvcc -ptx myconv.cu

    Construct the kernelk = parallel.gpu.CUDAKernel('myconv.ptx',

    'myconv.cu');k.GridSize = [512 512];k.ThreadBlockSize = [32 32];

    Run the kernel using the MATLAB workspace

    o = feval(k, rand(100, 1), rand(100, 1));or gpu data

    i1gpu = gpuArray(rand(100, 1, 'single'));i2gpu = gpuArray(rand(100, 1, 'single'));

    ogpu = feval(k, i1gpu, i2gpu);

    Invoke CUDA Code from MATLAB(3) Involved effort, extensive level of control

    Can I use it now?

  • 8/10/2019 nuNumerical Analysis techniques with MATLAB

    89/100

    96

    Can I use it now?

    GPU support is released with R2010b Part of Parallel Computing Toolbox

    NVIDIA CUDA capable GPUs

    With CUDA version 1.3 or greater

    Key takeaways

  • 8/10/2019 nuNumerical Analysis techniques with MATLAB

    90/100

    97

    Key takeaways

    Tradeoff programming effort with level of control

    Non-experts can benefit from GPU computing

    CUDA programmers can test their code in MATLAB

  • 8/10/2019 nuNumerical Analysis techniques with MATLAB

    91/100

    98

    Use of GPUs at Thales Nederland

  • 8/10/2019 nuNumerical Analysis techniques with MATLAB

    92/100

    99

    Conclusions

    Did you know about the campus- wide license

  • 8/10/2019 nuNumerical Analysis techniques with MATLAB

    93/100

    100

    Did you know about the campus wide license

    to MATLAB & Simulink?

    Through the Delft University campus wide license you

    can access MATLAB, Simulink and many add-on

    products

    More than 50 MathWorks products

    for you available at Delft University of

    Technology

    Are you using MATLAB & Simulink?

    Visit MathWorks Web Site

  • 8/10/2019 nuNumerical Analysis techniques with MATLAB

    94/100

    101

    Learn about MathWorks products

    Discover resources for learning,

    teaching, and research

    Learn how MathWorks products are

    used in academia and industry

    www.mathworks.nl/academia

    http://www.mathworks.com/academia
  • 8/10/2019 nuNumerical Analysis techniques with MATLAB

    95/100

    102Visit www.mathworks.nl/academia

    http://www.mathworks.com/academia
  • 8/10/2019 nuNumerical Analysis techniques with MATLAB

    96/100

    103

    Supporting Innovation

    MATLAB Central

    Open exchange for theMATLAB and Simulink user community

    800,000 visits per month 50% increase over previous year

    File Exchange Free file upload/download, including

    MATLAB code, Simulink models, and

    documents

    File ratings and comments

    Over 9,000 contributed files, 400 submissions

    per month, 25,500 downloads per day

    Newsgroup and Web Forum Technical discussions about

    MATLAB and Simulink

    200 posts per day

    Blogs Read posts from key MathWorks developers

    who design and build the products

    Based on Feb-March 2009 data

  • 8/10/2019 nuNumerical Analysis techniques with MATLAB

    97/100

    104

    Learning Resources

    Interactive Video

    Tutorials Students

    learn the basics outside

    of the classroom with

    self-guided tutorialsprovided by MathWorks

    MATLAB

    Simulink

    Signal Processing

    Control Systems

    Many more

    Visit www.mathworks.com/academia/student_center/tutorials

  • 8/10/2019 nuNumerical Analysis techniques with MATLAB

    98/100

    105

  • 8/10/2019 nuNumerical Analysis techniques with MATLAB

    99/100

    106 2011 The MathWorks, Inc.

    2011 Technology Trend Seminar

    Speed up numerical analysis with

    MATLAB

    MathWorks: Giorgia Zucchelli TU Delft: Prof.dr.ir. Kees Vuik

    Marieke van Geffen

    Rachid Adarghal Thales Nederland: Dnis Riedijk

  • 8/10/2019 nuNumerical Analysis techniques with MATLAB

    100/100

    Thank you for attending

    Please fill out your evaluation form

    Stay with Us for a drink


Recommended