91
EECS Berkeley EE249 LabVIEW Framework Hugo A. Andrade Principal Architect LabVIEW Platform & Real Time Group

EECS Berkeley EE249 LabVIEW Frameworkee249/fa08/Lectures/EE249Fall08...EECS Berkeley EE249 LabVIEW Framework Hugo A. Andrade Principal Architect ... Math with the MathScript Node •

Embed Size (px)

Citation preview

Page 1: EECS Berkeley EE249 LabVIEW Frameworkee249/fa08/Lectures/EE249Fall08...EECS Berkeley EE249 LabVIEW Framework Hugo A. Andrade Principal Architect ... Math with the MathScript Node •

EECS Berkeley EE249LabVIEW Framework

Hugo A. AndradePrincipal Architect

LabVIEW Platform & Real Time Group

Page 2: EECS Berkeley EE249 LabVIEW Frameworkee249/fa08/Lectures/EE249Fall08...EECS Berkeley EE249 LabVIEW Framework Hugo A. Andrade Principal Architect ... Math with the MathScript Node •

Agenda

• Overview of NI Tools

• LabVIEW

– Intro

– Framework

– Parallel programming

• From multi-core to many-core

Page 3: EECS Berkeley EE249 LabVIEW Frameworkee249/fa08/Lectures/EE249Fall08...EECS Berkeley EE249 LabVIEW Framework Hugo A. Andrade Principal Architect ... Math with the MathScript Node •

National Instruments Profile

• Leaders in Computer-Based Measurement and Automation

• Strong Track Record of Growth and Profitability

• $740 MM Revenue in FY2007

• Past nine consecutive years votedFortune’s 100 Best Companies to Work For in America

• Headquartered in Austin, Texas

• More than 4,000 employees; operations in 40+ countries

Asia 21%

Europe 31%

Americas 48%

Page 4: EECS Berkeley EE249 LabVIEW Frameworkee249/fa08/Lectures/EE249Fall08...EECS Berkeley EE249 LabVIEW Framework Hugo A. Andrade Principal Architect ... Math with the MathScript Node •

Diversity of Customers

Customers are mainly domain experts, scientists and engineers

Top 100 customers ≈ 35% of revenue

More than 25,000 customers in more than 90 countries

95% of Fortune 500 manufacturing companies have adopted Virtual Instrumentation

Page 5: EECS Berkeley EE249 LabVIEW Frameworkee249/fa08/Lectures/EE249Fall08...EECS Berkeley EE249 LabVIEW Framework Hugo A. Andrade Principal Architect ... Math with the MathScript Node •

Diversity of Industries

ElectronicsSemiconductors Computers

Advanced

ResearchPetrochemical

Food

ProcessingTextiles

AutomotiveTelecom

ATE Military/Aerospace

Page 6: EECS Berkeley EE249 LabVIEW Frameworkee249/fa08/Lectures/EE249Fall08...EECS Berkeley EE249 LabVIEW Framework Hugo A. Andrade Principal Architect ... Math with the MathScript Node •

Virtual Instrumentation

Page 7: EECS Berkeley EE249 LabVIEW Frameworkee249/fa08/Lectures/EE249Fall08...EECS Berkeley EE249 LabVIEW Framework Hugo A. Andrade Principal Architect ... Math with the MathScript Node •

Hardware and

Driver Software

Virtual Instrumentation

Application

Software

Page 8: EECS Berkeley EE249 LabVIEW Frameworkee249/fa08/Lectures/EE249Fall08...EECS Berkeley EE249 LabVIEW Framework Hugo A. Andrade Principal Architect ... Math with the MathScript Node •

Virtual Instrumentation Applications• Analysis and Design

– Simulation

– Signal and Image Processing

– Embedded System Programming• (PC, DSP, FPGA, Microcontroller)

– Prototyping

– And more…

• Control

– Automatic Controls and Dynamic Systems

– Mechatronics and Robotics

– And more…

• Measurement/Test

– Circuits and Electronics

– Measurements and Instrumentation

Design Prototype Deploy

A single graphical development platform

Page 9: EECS Berkeley EE249 LabVIEW Frameworkee249/fa08/Lectures/EE249Fall08...EECS Berkeley EE249 LabVIEW Framework Hugo A. Andrade Principal Architect ... Math with the MathScript Node •

LabVIEW Graphical Development System

• Graphical Programming Environment

• Compile code for multiple OS and devices

• Useful in a broad range of applications

Page 10: EECS Berkeley EE249 LabVIEW Frameworkee249/fa08/Lectures/EE249Fall08...EECS Berkeley EE249 LabVIEW Framework Hugo A. Andrade Principal Architect ... Math with the MathScript Node •

LabVIEW

• LabVIEW Background and Intro

• Facets

– Measurement and Automation• (Instrument Control, I/O, DAQ, etc.

– General purpose computing environment for scientists and engineers

– Modeling Environment

– Framework for Domain Experts

– Embedded Development Environment

– Framework for Parallel Programming Techniques

Page 11: EECS Berkeley EE249 LabVIEW Frameworkee249/fa08/Lectures/EE249Fall08...EECS Berkeley EE249 LabVIEW Framework Hugo A. Andrade Principal Architect ... Math with the MathScript Node •

Distributed Multi-core Systems

Multiple

Programming

Models

LabVIEW 8.6

Page 12: EECS Berkeley EE249 LabVIEW Frameworkee249/fa08/Lectures/EE249Fall08...EECS Berkeley EE249 LabVIEW Framework Hugo A. Andrade Principal Architect ... Math with the MathScript Node •

Front Panel

Block Diagram

LabVIEW Virtual Instrument

Page 13: EECS Berkeley EE249 LabVIEW Frameworkee249/fa08/Lectures/EE249Fall08...EECS Berkeley EE249 LabVIEW Framework Hugo A. Andrade Principal Architect ... Math with the MathScript Node •

Introduction to LabVIEW and Dataflow

14

Page 14: EECS Berkeley EE249 LabVIEW Frameworkee249/fa08/Lectures/EE249Fall08...EECS Berkeley EE249 LabVIEW Framework Hugo A. Andrade Principal Architect ... Math with the MathScript Node •

The G (LabVIEW) Language Model

• Homogenous dataflow language – Structured case (switch, select), loops, timed specs

• “Structured dataflow”

• Turing complete• Run-time scheduling

– Inherently parallel language

• Synthesizable language– Direct compilation to software binaries on host processors– Embedded Processors (via C)– To FPGAs (via VHDL)

Page 15: EECS Berkeley EE249 LabVIEW Frameworkee249/fa08/Lectures/EE249Fall08...EECS Berkeley EE249 LabVIEW Framework Hugo A. Andrade Principal Architect ... Math with the MathScript Node •

Section Outline: LabVIEW and Dataflow

1. Introduction to the LabVIEW environment

2. Functions and hierarchy

3. Dataflow and parallelism

Page 16: EECS Berkeley EE249 LabVIEW Frameworkee249/fa08/Lectures/EE249Fall08...EECS Berkeley EE249 LabVIEW Framework Hugo A. Andrade Principal Architect ... Math with the MathScript Node •

What is LabVIEW?

• Programming language: graphical programming based on structured dataflow

• Complete development environment: project explorer, debugging tools, source code control, and more

17

Page 17: EECS Berkeley EE249 LabVIEW Frameworkee249/fa08/Lectures/EE249Fall08...EECS Berkeley EE249 LabVIEW Framework Hugo A. Andrade Principal Architect ... Math with the MathScript Node •

Parts of a LabVIEW Application

• Block diagram shows graphical source code

• Front panel contains graphical user interface (GUI) items (connected to source code)

18

Page 18: EECS Berkeley EE249 LabVIEW Frameworkee249/fa08/Lectures/EE249Fall08...EECS Berkeley EE249 LabVIEW Framework Hugo A. Andrade Principal Architect ... Math with the MathScript Node •

Block Diagram: Source Code• Block diagram can contain functions, structures, and

constants

• Analogous to functions, subroutines, flow control elements, and constants in text-based languages

• Terminals represent inputs and outputs

19

Page 19: EECS Berkeley EE249 LabVIEW Frameworkee249/fa08/Lectures/EE249Fall08...EECS Berkeley EE249 LabVIEW Framework Hugo A. Andrade Principal Architect ... Math with the MathScript Node •

3 Types of Functions (from the Functions Palette)

Express VIs: interactive VIs with configurable dialog page (blue border)

Standard VIs: modularized VIs customized by wiring (customizable)

Functions: fundamental operating elements of LabVIEW; no front panel or block diagram (yellow)

Page 20: EECS Berkeley EE249 LabVIEW Frameworkee249/fa08/Lectures/EE249Fall08...EECS Berkeley EE249 LabVIEW Framework Hugo A. Andrade Principal Architect ... Math with the MathScript Node •

What Types of Functions are Available?• Input and Output

– Signal and Data Simulation

– Acquire and Generate Real Signals with DAQ

– Instrument I/O Assistant (Serial & GPIB)

– ActiveX for communication with other programs

• Analysis – Signal Processing

– Statistics

– Advanced Math and Formulas

– Continuous Time Solver

• Storage– File I/O

Express Functions Palette

Page 21: EECS Berkeley EE249 LabVIEW Frameworkee249/fa08/Lectures/EE249Fall08...EECS Berkeley EE249 LabVIEW Framework Hugo A. Andrade Principal Architect ... Math with the MathScript Node •

Cross-Platform Graphical Programming

Graphical Source Code Compiled Code (binary)

22

Page 22: EECS Berkeley EE249 LabVIEW Frameworkee249/fa08/Lectures/EE249Fall08...EECS Berkeley EE249 LabVIEW Framework Hugo A. Andrade Principal Architect ... Math with the MathScript Node •

PC Boards

Wireless

Sensors

Embedded (FPGA)

LabVIEW Deployed

Industrial Computer (PXI)

Networked I/O

Touch Panel

Portable

Tektronix Open

Windows Oscilloscopes

Wireless

Handheld

Workstation

Smart

Cameras

23

Page 23: EECS Berkeley EE249 LabVIEW Frameworkee249/fa08/Lectures/EE249Fall08...EECS Berkeley EE249 LabVIEW Framework Hugo A. Andrade Principal Architect ... Math with the MathScript Node •

Block Diagram: Functions Palette

• Contains programming structures and functions

• Contains specialized IP, including math libraries built on Intel Math Kernel Library (MKL)

24

Page 24: EECS Berkeley EE249 LabVIEW Frameworkee249/fa08/Lectures/EE249Fall08...EECS Berkeley EE249 LabVIEW Framework Hugo A. Andrade Principal Architect ... Math with the MathScript Node •

Front Panel: Controls Palette

• Controls (inputs): menus, text entry, selectors, buttons, etc.

• Indicators (outputs): graphs, LEDs, charts, and other displays

25

Page 25: EECS Berkeley EE249 LabVIEW Frameworkee249/fa08/Lectures/EE249Fall08...EECS Berkeley EE249 LabVIEW Framework Hugo A. Andrade Principal Architect ... Math with the MathScript Node •

Hierarchy in LabVIEW

• A LabVIEW subVI is a VI that is called inside of another VI

• A subVI’s inputs and outputs (parameters) are exposed and accessed on the block diagram

• Similar to a function or subroutine in text-based programming

26

Page 26: EECS Berkeley EE249 LabVIEW Frameworkee249/fa08/Lectures/EE249Fall08...EECS Berkeley EE249 LabVIEW Framework Hugo A. Andrade Principal Architect ... Math with the MathScript Node •

Dataflow Programming

• Block diagram execution

– Dependent on the flow of

data

– Block diagram does NOT

execute left to right

• Node executes when data

is available to ALL input

terminals

• Nodes supply data to all

output terminals when done

Page 27: EECS Berkeley EE249 LabVIEW Frameworkee249/fa08/Lectures/EE249Fall08...EECS Berkeley EE249 LabVIEW Framework Hugo A. Andrade Principal Architect ... Math with the MathScript Node •

Dataflow and Parallel Execution

• Dataflow programming means inherent parallelism in your application

• Parallel code sections in a dataflow program can be easily visualized

30

Page 28: EECS Berkeley EE249 LabVIEW Frameworkee249/fa08/Lectures/EE249Fall08...EECS Berkeley EE249 LabVIEW Framework Hugo A. Andrade Principal Architect ... Math with the MathScript Node •

Dataflow and Parallel Execution • Program massively parallel hardware with

LabVIEW FPGA

• Same approach as programming CPUs, only code executes directly in hardware

31

Page 29: EECS Berkeley EE249 LabVIEW Frameworkee249/fa08/Lectures/EE249Fall08...EECS Berkeley EE249 LabVIEW Framework Hugo A. Andrade Principal Architect ... Math with the MathScript Node •

National Instruments ConfidentialNational

Instruments

Simple LabVIEW G Demo

Page 30: EECS Berkeley EE249 LabVIEW Frameworkee249/fa08/Lectures/EE249Fall08...EECS Berkeley EE249 LabVIEW Framework Hugo A. Andrade Principal Architect ... Math with the MathScript Node •

Increasing Levels of Hardware Abstraction

Ab

stra

ctio

n

System complexity

Vacuum Tubes

Transistors

Integrated Circuits (IC)

Very Large Scale ICs (VLSI)

System-on-Chip (SoC)

Page 31: EECS Berkeley EE249 LabVIEW Frameworkee249/fa08/Lectures/EE249Fall08...EECS Berkeley EE249 LabVIEW Framework Hugo A. Andrade Principal Architect ... Math with the MathScript Node •

Increasing Levels of Software Abstraction

Ab

stra

ctio

n

System complexity

Machine code

Assembly language

Procedural Lang. (C)

Object Oriented Lang. (C++)

System design platform

Page 32: EECS Berkeley EE249 LabVIEW Frameworkee249/fa08/Lectures/EE249Fall08...EECS Berkeley EE249 LabVIEW Framework Hugo A. Andrade Principal Architect ... Math with the MathScript Node •

High-Level Development Tools

Data Flow C Code Textual Math Modeling Statechart

Graphical System Design Platform

MacintoshLinux® Windows Real-Time FPGA Micro

Desktop Platform Embedded Platform

Page 33: EECS Berkeley EE249 LabVIEW Frameworkee249/fa08/Lectures/EE249Fall08...EECS Berkeley EE249 LabVIEW Framework Hugo A. Andrade Principal Architect ... Math with the MathScript Node •

LabVIEW Targets• Scalable from distributed network to sensors

Portable

FPGA

PC

Handheld

Industrial Controllers (PXI)

Sensor

Vision System

DSP/MPU

Embedded Controllers

Page 34: EECS Berkeley EE249 LabVIEW Frameworkee249/fa08/Lectures/EE249Fall08...EECS Berkeley EE249 LabVIEW Framework Hugo A. Andrade Principal Architect ... Math with the MathScript Node •

LabVIEW on cRIO - HW

Real-Time Processor Reconfigurable FPGA

Industrial I/O

Modules

•Reconfigurable FPGA for high-speed

and custom I/O timing, triggering,

control

•Real-Time Processor for

deterministic, stand-alone operation

and advanced analysis

•Industrial I/O Modules with built-in

signal conditioning for direct connection

to sensors/actuators

CompactRIO

Page 35: EECS Berkeley EE249 LabVIEW Frameworkee249/fa08/Lectures/EE249Fall08...EECS Berkeley EE249 LabVIEW Framework Hugo A. Andrade Principal Architect ... Math with the MathScript Node •

LabVIEW on cRIO – Logical Diagram

Reconfigurable

FPGA

LabVIEW

FPGA VI

Data Storage

LabVIEW Real-Time SystemWindows PC

Enterprise

User

InterfaceTime-Critical

Interface VI

Normal Priority

VI

Windows

Host VI

Network

CommunicationInter-Thread

Communication

FPGA

Interface

LabVIEW

for WindowsLabVIEW FPGALabVIEW Real-Time

Page 36: EECS Berkeley EE249 LabVIEW Frameworkee249/fa08/Lectures/EE249Fall08...EECS Berkeley EE249 LabVIEW Framework Hugo A. Andrade Principal Architect ... Math with the MathScript Node •

LabVIEW on cRIO – SW and Some Ideas

EthernetRT CPU Host CPU

SPIAI 0 Pin PCI(e)

Elemental IO DMA FIFO Network Variable

FPGA

FPGA Loop RT Loop Host Loop

Page 37: EECS Berkeley EE249 LabVIEW Frameworkee249/fa08/Lectures/EE249Fall08...EECS Berkeley EE249 LabVIEW Framework Hugo A. Andrade Principal Architect ... Math with the MathScript Node •

High-Level Development Tools

Data Flow C Code Textual Math Modeling Statechart

Graphical System Design Platform

MacintoshLinux® Windows Real-Time FPGA Micro

Desktop Platform Embedded Platform

Page 38: EECS Berkeley EE249 LabVIEW Frameworkee249/fa08/Lectures/EE249Fall08...EECS Berkeley EE249 LabVIEW Framework Hugo A. Andrade Principal Architect ... Math with the MathScript Node •

LabVIEW as a Framework

• Demo Express VI

• Demo Vision Assistant

– Metal example

• Demo Motion Assistant

Page 39: EECS Berkeley EE249 LabVIEW Frameworkee249/fa08/Lectures/EE249Fall08...EECS Berkeley EE249 LabVIEW Framework Hugo A. Andrade Principal Architect ... Math with the MathScript Node •

Textual Math in LabVIEW• Integrate existing scripts with LabVIEW for faster

development

• Interactive, easy-to-use, hands-on learning environment

• Develop algorithms, explore mathematical concepts, and

analyze results using a single environment

• Freedom to choose the most effective syntax, whether

graphical or textual within one VI

Supported Math Tools:

MathScript script node MathSoft software

Mathematica software MATLAB® software

Maple software Xmath software

MATLAB ® is a registered trademark of The MathWorks, Inc.

Page 40: EECS Berkeley EE249 LabVIEW Frameworkee249/fa08/Lectures/EE249Fall08...EECS Berkeley EE249 LabVIEW Framework Hugo A. Andrade Principal Architect ... Math with the MathScript Node •

Math with the MathScript Node• Implement equations and algorithms textually

• Input and Output variables created at the border

• Generally compatible with popular m-file script language

• Terminate statements with a semicolon to disable immediate

output

Prototype your equations in the interactive MathScript Window.

(Functions»Programming»

Structures»MathScript)

Page 41: EECS Berkeley EE249 LabVIEW Frameworkee249/fa08/Lectures/EE249Fall08...EECS Berkeley EE249 LabVIEW Framework Hugo A. Andrade Principal Architect ... Math with the MathScript Node •

The Interactive MathScript Window• Rapidly develop and test algorithms

(LabVIEW»Tools»MathScript Window)

Output

Window

Variable

Workspace

View/Modify

Variable Contents

User Commands

m-file Script

• Share Scripts and

Variables with the Node

• View /Modify Variable

content in 1D, 2D, and 3D

Page 42: EECS Berkeley EE249 LabVIEW Frameworkee249/fa08/Lectures/EE249Fall08...EECS Berkeley EE249 LabVIEW Framework Hugo A. Andrade Principal Architect ... Math with the MathScript Node •

Developing Applications with the

NI LabVIEW Statechart Module

Page 43: EECS Berkeley EE249 LabVIEW Frameworkee249/fa08/Lectures/EE249Fall08...EECS Berkeley EE249 LabVIEW Framework Hugo A. Andrade Principal Architect ... Math with the MathScript Node •

What are Statecharts?

Statecharts are visual representations of reactive

(event-based) systems.

System

Inputs Outputs

Page 44: EECS Berkeley EE249 LabVIEW Frameworkee249/fa08/Lectures/EE249Fall08...EECS Berkeley EE249 LabVIEW Framework Hugo A. Andrade Principal Architect ... Math with the MathScript Node •

Differences between Statecharts and FSMsBoth contain the same basic

concepts:

– States

– Transitions

Statechart adds additional concepts:– Hierarchy

– Concurrency

– Event-based paradigm

– Pseudostates & Connectors

Button Press

H

Based on the UML statechart diagram specification

Page 45: EECS Berkeley EE249 LabVIEW Frameworkee249/fa08/Lectures/EE249Fall08...EECS Berkeley EE249 LabVIEW Framework Hugo A. Andrade Principal Architect ... Math with the MathScript Node •

Reactive Systems

• Communication systems

• Digital protocols

• Control applications

– Sequential logic

– Batch processing

– Event response

– Non-linear control

• User-interface implementation

• System modeling for virtual prototyping (simulation)

State Machines

Page 46: EECS Berkeley EE249 LabVIEW Frameworkee249/fa08/Lectures/EE249Fall08...EECS Berkeley EE249 LabVIEW Framework Hugo A. Andrade Principal Architect ... Math with the MathScript Node •

Statechart Benefits• Abstraction

– Simple semantics to represent complex systems

– System-level view

– Self-documenting

Page 47: EECS Berkeley EE249 LabVIEW Frameworkee249/fa08/Lectures/EE249Fall08...EECS Berkeley EE249 LabVIEW Framework Hugo A. Andrade Principal Architect ... Math with the MathScript Node •

Machine & Process Control

concurrencyhierarchy

Page 48: EECS Berkeley EE249 LabVIEW Frameworkee249/fa08/Lectures/EE249Fall08...EECS Berkeley EE249 LabVIEW Framework Hugo A. Andrade Principal Architect ... Math with the MathScript Node •

FPGA Logic

hierarchy

Page 49: EECS Berkeley EE249 LabVIEW Frameworkee249/fa08/Lectures/EE249Fall08...EECS Berkeley EE249 LabVIEW Framework Hugo A. Andrade Principal Architect ... Math with the MathScript Node •

User Interfaceshistory

Page 50: EECS Berkeley EE249 LabVIEW Frameworkee249/fa08/Lectures/EE249Fall08...EECS Berkeley EE249 LabVIEW Framework Hugo A. Andrade Principal Architect ... Math with the MathScript Node •

• Abstraction

– Simple semantics to represent complex systems

– System-level view

– Self-documenting

• Scalability

– Easily extend applications

– Open software platform

• Automatic Code Generation

– LabVIEW Embedded Technology

Statechart Benefits

Page 51: EECS Berkeley EE249 LabVIEW Frameworkee249/fa08/Lectures/EE249Fall08...EECS Berkeley EE249 LabVIEW Framework Hugo A. Andrade Principal Architect ... Math with the MathScript Node •

LabVIEW Simulation Module• Develop dynamic systems such as motor controllers

and hydraulic simulators with LabVIEW

• Implement your dynamic systems with real-time I/O using built-in LabVIEW data acquisition functions

• Simulate linear, nonlinear, and discrete systems with a wide array of solvers

• Deploy dynamic systems to real-time hardware with the NI LabVIEW Real-Time Module

• Translate models from The MathWorks, Inc. Simulink® into LabVIEW with built-in utility

Page 52: EECS Berkeley EE249 LabVIEW Frameworkee249/fa08/Lectures/EE249Fall08...EECS Berkeley EE249 LabVIEW Framework Hugo A. Andrade Principal Architect ... Math with the MathScript Node •

The Design Process

1. Modeling – Identify a mathematical representation of the plant

2. Control Design – Choose a control method and design a controller

3. Simulation – Employ a point-by-point approach to simulate the system timing with a solver

4. Tuning and Verification – Introduce real-world nonlinearities, tune, and verify the control algorithm

5. Deployment – Implement the finalized control system

Page 53: EECS Berkeley EE249 LabVIEW Frameworkee249/fa08/Lectures/EE249Fall08...EECS Berkeley EE249 LabVIEW Framework Hugo A. Andrade Principal Architect ... Math with the MathScript Node •

The Simulation Loop

• Built in Differential Equation Solver allows continuous-time system

• Similar to a While Loop with a predefined time period

• Installed with Simulation Module

• Double-click Input Node to configure simulation parameters

• Create an indicator on the Output Node to display Simulation errors

Input Node Main Loop Output Node

Page 54: EECS Berkeley EE249 LabVIEW Frameworkee249/fa08/Lectures/EE249Fall08...EECS Berkeley EE249 LabVIEW Framework Hugo A. Andrade Principal Architect ... Math with the MathScript Node •

Simulation Loop Parameters• Drag left node to show current

parameters and provide inputs for run-time simulation configuration

• Double-click Input Node to configure simulation parameters

Page 55: EECS Berkeley EE249 LabVIEW Frameworkee249/fa08/Lectures/EE249Fall08...EECS Berkeley EE249 LabVIEW Framework Hugo A. Andrade Principal Architect ... Math with the MathScript Node •

High-Level Development Tools

Data Flow C Code Textual Math Modeling Statechart

Graphical System Design Platform

MacintoshLinux® Windows Real-Time FPGA Micro

Desktop Platform Embedded Platform

Page 56: EECS Berkeley EE249 LabVIEW Frameworkee249/fa08/Lectures/EE249Fall08...EECS Berkeley EE249 LabVIEW Framework Hugo A. Andrade Principal Architect ... Math with the MathScript Node •

Targets and Deployment

LabVIEW Real-time

LabVIEW FPGA

LabVIEW Microprocessor SDK

LabVIEW PDA and related

Page 57: EECS Berkeley EE249 LabVIEW Frameworkee249/fa08/Lectures/EE249Fall08...EECS Berkeley EE249 LabVIEW Framework Hugo A. Andrade Principal Architect ... Math with the MathScript Node •

Evolution of LabVIEW Backend Technologies

VHDL

OEM

Synthesis

PAR

FPGA

Intermediate Code Compiler Hardware Target

None

(Machine Code)

LabVIEW

Real-Time

Wintel

PowerPC

None

(Object Library)

LabVIEW

DSPDSP

C AnyAny 32-bit

MPU

Page 58: EECS Berkeley EE249 LabVIEW Frameworkee249/fa08/Lectures/EE249Fall08...EECS Berkeley EE249 LabVIEW Framework Hugo A. Andrade Principal Architect ... Math with the MathScript Node •

LabVIEW for Parallel Programming

• Overview of LabVIEW Multithreading

• Parallel Programming Techniques

• Real-Time Considerations

• Resources

Page 59: EECS Berkeley EE249 LabVIEW Frameworkee249/fa08/Lectures/EE249Fall08...EECS Berkeley EE249 LabVIEW Framework Hugo A. Andrade Principal Architect ... Math with the MathScript Node •

Impact on Engineers and ScientistsEngineering and scientific applications are typically run on dedicated systems (i.e. little multitasking).

Page 60: EECS Berkeley EE249 LabVIEW Frameworkee249/fa08/Lectures/EE249Fall08...EECS Berkeley EE249 LabVIEW Framework Hugo A. Andrade Principal Architect ... Math with the MathScript Node •

Creating Multithreaded ApplicationsEngineers and scientists must use threads to benefit from multicore processors.

Page 61: EECS Berkeley EE249 LabVIEW Frameworkee249/fa08/Lectures/EE249Fall08...EECS Berkeley EE249 LabVIEW Framework Hugo A. Andrade Principal Architect ... Math with the MathScript Node •

Multithreading Programs in LabVIEW

• Automatic threading

– LabVIEW clumping algorithm automatically assigns code to threads based on parallelism

– Most existing programs will run faster on a Multicore system with no alteration

• Manual threading

– Force section of code to execute in a single thread

64

Page 62: EECS Berkeley EE249 LabVIEW Frameworkee249/fa08/Lectures/EE249Fall08...EECS Berkeley EE249 LabVIEW Framework Hugo A. Andrade Principal Architect ... Math with the MathScript Node •

• LabVIEW divides a program into multiple threads (originally introduced in 1998 with LabVIEW 5.0)

• Oversimplification shown below; parallel code paths execute in separate threads to run on parallel hardware

Automatic Multithreading

thread

thread

thread

Page 63: EECS Berkeley EE249 LabVIEW Frameworkee249/fa08/Lectures/EE249Fall08...EECS Berkeley EE249 LabVIEW Framework Hugo A. Andrade Principal Architect ... Math with the MathScript Node •

LabVIEW Execution System

1. LabVIEW compiler analyzes diagram and assigns code pieces to “clumps”

thread

thread

thread

thread…

# of threads scales based on # of CPUs

21 3

2. Information about which pieces of code can run simultaneously are stored in a run queue

3. If block diagram contains enough parallelism, it will simultaneously execute in all system threads

Page 64: EECS Berkeley EE249 LabVIEW Frameworkee249/fa08/Lectures/EE249Fall08...EECS Berkeley EE249 LabVIEW Framework Hugo A. Andrade Principal Architect ... Math with the MathScript Node •

Software Stack

Development tool Support provided on the

operating system of choice; tool

facilitates correct threading and

optimization

Example: Multithreaded

nature of LabVIEW and

structures that provide

optimization

Libraries Thread-safe, re-entrant libraries Example: BLAS libraries

Device drivers Drivers designed for optimal

multithreaded performance

Example: NI-DAQmx driver

software

Operating system Operating system supports

multithreading and multitasking

and can load balance tasks

Example: Support for

Windows, Mac OS, Linux® OS,

and real-time operating

systems

Multithreaded Software Stack Support

Page 65: EECS Berkeley EE249 LabVIEW Frameworkee249/fa08/Lectures/EE249Fall08...EECS Berkeley EE249 LabVIEW Framework Hugo A. Andrade Principal Architect ... Math with the MathScript Node •

Manual Threading with Timed Structures

• Code within timed structure executes in a single thread

• Threads can be assigned a relative priority

• Set processor affinity

69

Page 66: EECS Berkeley EE249 LabVIEW Frameworkee249/fa08/Lectures/EE249Fall08...EECS Berkeley EE249 LabVIEW Framework Hugo A. Andrade Principal Architect ... Math with the MathScript Node •

Parallel Programming Techniques to Improve Performance on Multicore Systems

• Task Parallelism

• Data Parallelism

• Pipelining

Page 67: EECS Berkeley EE249 LabVIEW Frameworkee249/fa08/Lectures/EE249Fall08...EECS Berkeley EE249 LabVIEW Framework Hugo A. Andrade Principal Architect ... Math with the MathScript Node •

Task Parallelism

1) Look for tasks that can be run in parallel

2) Architect code to reflect this parallelism

• Eliminate data dependencies

• LabVIEW automatically identifies parallel code and can split into multiple threads!

71

Page 68: EECS Berkeley EE249 LabVIEW Frameworkee249/fa08/Lectures/EE249Fall08...EECS Berkeley EE249 LabVIEW Framework Hugo A. Andrade Principal Architect ... Math with the MathScript Node •

• Multiple tasks, same data

• Multiple data-independent tasks

Task Parallelism

Page 69: EECS Berkeley EE249 LabVIEW Frameworkee249/fa08/Lectures/EE249Fall08...EECS Berkeley EE249 LabVIEW Framework Hugo A. Andrade Principal Architect ... Math with the MathScript Node •

Task Parallelism Demo

Page 70: EECS Berkeley EE249 LabVIEW Frameworkee249/fa08/Lectures/EE249Fall08...EECS Berkeley EE249 LabVIEW Framework Hugo A. Andrade Principal Architect ... Math with the MathScript Node •

1) Look for large data sets that can be processed in two or more “chunks” independently

2) Architect code:• Split the data apart• Process the data in parallel• Combine the individual results into one overall

result

Data Parallelism

Page 71: EECS Berkeley EE249 LabVIEW Frameworkee249/fa08/Lectures/EE249Fall08...EECS Berkeley EE249 LabVIEW Framework Hugo A. Andrade Principal Architect ... Math with the MathScript Node •

Data Parallelism

Result

Data Set

CPU Core Signal Processing

Page 72: EECS Berkeley EE249 LabVIEW Frameworkee249/fa08/Lectures/EE249Fall08...EECS Berkeley EE249 LabVIEW Framework Hugo A. Andrade Principal Architect ... Math with the MathScript Node •

You can speed up processor-intensive operations on large data sets on multicore systems.

Signal Processing

Signal Processing

Signal Processing

Signal Processing

CombineResults

Data Set

CPU Core

CPU Core

CPU Core

CPU Core

Data Parallelism

Page 73: EECS Berkeley EE249 LabVIEW Frameworkee249/fa08/Lectures/EE249Fall08...EECS Berkeley EE249 LabVIEW Framework Hugo A. Andrade Principal Architect ... Math with the MathScript Node •

Data Parallelism Demo

Page 74: EECS Berkeley EE249 LabVIEW Frameworkee249/fa08/Lectures/EE249Fall08...EECS Berkeley EE249 LabVIEW Framework Hugo A. Andrade Principal Architect ... Math with the MathScript Node •

• Many applications involve sequential, multistep algorithms that are executed over and over again

• Applying pipelining can increase performance

Pipelining Strategy

1

2

3

4

Acquire Filter Analyze Log

time

1

2

3

4

Acquire Filter Analyze Log

t0 t3 t4 t7

Page 75: EECS Berkeley EE249 LabVIEW Frameworkee249/fa08/Lectures/EE249Fall08...EECS Berkeley EE249 LabVIEW Framework Hugo A. Andrade Principal Architect ... Math with the MathScript Node •

time

Acquire

Filter

Analyze

Log

t0 t1 t2

CPU Core

CPU Core

CPU Core

CPU Core

t3

Pipelining Strategy

Acquire

Filter

Analyze

Log

Acquire Acquire

Filter Filter

Analyze Analyze

Log Log

Page 76: EECS Berkeley EE249 LabVIEW Frameworkee249/fa08/Lectures/EE249Fall08...EECS Berkeley EE249 LabVIEW Framework Hugo A. Andrade Principal Architect ... Math with the MathScript Node •

Note: Queues may also be used to pipeline data between different loops

Sequential Pipelined

?

Pipelining in LabVIEW

or

Page 77: EECS Berkeley EE249 LabVIEW Frameworkee249/fa08/Lectures/EE249Fall08...EECS Berkeley EE249 LabVIEW Framework Hugo A. Andrade Principal Architect ... Math with the MathScript Node •

Pipelining Demo

Page 78: EECS Berkeley EE249 LabVIEW Frameworkee249/fa08/Lectures/EE249Fall08...EECS Berkeley EE249 LabVIEW Framework Hugo A. Andrade Principal Architect ... Math with the MathScript Node •

Multicore Challenges and Debugging

• Reentrancy and execution highlighting

• Thread synchronization

• Execution tracing

• Performance counters

• Data transfer considerations

83

Page 79: EECS Berkeley EE249 LabVIEW Frameworkee249/fa08/Lectures/EE249Fall08...EECS Berkeley EE249 LabVIEW Framework Hugo A. Andrade Principal Architect ... Math with the MathScript Node •

Reentrancy• All VIs in LabVIEW can bet set to be reentrant

• Allows for each subVI to use separate memory space

All subVIs that will be executed multiple times in parallel need to be set as reentrant

84

Page 80: EECS Berkeley EE249 LabVIEW Frameworkee249/fa08/Lectures/EE249Fall08...EECS Berkeley EE249 LabVIEW Framework Hugo A. Andrade Principal Architect ... Math with the MathScript Node •

Thread Synchronization• No guarantee that an OS will schedule threads in the

correct sequence without synchronization primitives

• Order of events may change at each execution due to the way the threads are scheduled

Thread 1

Thread 2

Thread 3

Thread 2

Thread 3

Thread 1

First execution

Second execution

Thread 3

Thread 1

Thread 2Third execution

86

Page 81: EECS Berkeley EE249 LabVIEW Frameworkee249/fa08/Lectures/EE249Fall08...EECS Berkeley EE249 LabVIEW Framework Hugo A. Andrade Principal Architect ... Math with the MathScript Node •

Code Synchronization with Dataflow

• Dataflow paradigm ensures synchronization

thread

thread

Parallel code paths are synchronized and order of execution is determined by LabVIEW wires

Dataflow is a key enabler for Multicore programming

87

Page 82: EECS Berkeley EE249 LabVIEW Frameworkee249/fa08/Lectures/EE249Fall08...EECS Berkeley EE249 LabVIEW Framework Hugo A. Andrade Principal Architect ... Math with the MathScript Node •

Synchronization in LabVIEW

• When low-level synchronization is required, use synchronization mechanisms including:

• Queues

• Notifiers

• Semaphores

• Rendezvous

• Occurrences

88

Page 83: EECS Berkeley EE249 LabVIEW Frameworkee249/fa08/Lectures/EE249Fall08...EECS Berkeley EE249 LabVIEW Framework Hugo A. Andrade Principal Architect ... Math with the MathScript Node •

Execution Tracing• On real-time systems, trace debugging can show thread

activity at the OS level

• Thread activity on each core is displayed by selecting a particular CPU

89

Page 84: EECS Berkeley EE249 LabVIEW Frameworkee249/fa08/Lectures/EE249Fall08...EECS Berkeley EE249 LabVIEW Framework Hugo A. Andrade Principal Architect ... Math with the MathScript Node •

Performance Counters• Performance counters provide detailed system information

(CPU usage, memory usage, and cache hits/misses)

• LabVIEW can call into Windows performance counters

• Example utilities:

– Windows Perfmon

– Intel’s VTune

Page 85: EECS Berkeley EE249 LabVIEW Frameworkee249/fa08/Lectures/EE249Fall08...EECS Berkeley EE249 LabVIEW Framework Hugo A. Andrade Principal Architect ... Math with the MathScript Node •

Data Transfer Considerations

• Carefully consider system memory architecture when programming for Multicore

• Avoid transferring overly large data sets between cores (relative to cache size)

• Very small memory transfers can cause repeated cache coherency updates

91

Page 86: EECS Berkeley EE249 LabVIEW Frameworkee249/fa08/Lectures/EE249Fall08...EECS Berkeley EE249 LabVIEW Framework Hugo A. Andrade Principal Architect ... Math with the MathScript Node •

Physical Processor Layout• Distance between processors and quality of

processor connections can have a large effect

• Transferring data over system bus is much slower than accessing a shared cache

Shared Cache Example: Dual-Core, Dual Processor System

Source: Tian and Shih, Software Techniques for Shared-Cache Multi-Core Systems, Intel Software Network

Core 0 Core 1 Core 2 Core 3

L2 Cache L2 Cache

System BusSystem

Memory

Page 87: EECS Berkeley EE249 LabVIEW Frameworkee249/fa08/Lectures/EE249Fall08...EECS Berkeley EE249 LabVIEW Framework Hugo A. Andrade Principal Architect ... Math with the MathScript Node •

LabVIEW 8.5 adds Symmetric Multiprocessing (SMP) for real-time systems.

Deterministic Real-Time Systems

Page 88: EECS Berkeley EE249 LabVIEW Frameworkee249/fa08/Lectures/EE249Fall08...EECS Berkeley EE249 LabVIEW Framework Hugo A. Andrade Principal Architect ... Math with the MathScript Node •

In LabVIEW 8.5, users can reserve a core and then assign time critical code to run on it

Assigning Tasks to Specific Cores

Page 89: EECS Berkeley EE249 LabVIEW Frameworkee249/fa08/Lectures/EE249Fall08...EECS Berkeley EE249 LabVIEW Framework Hugo A. Andrade Principal Architect ... Math with the MathScript Node •

Affinity, pools, threads, CPUs, etc.

System Threads Timed-Structure Threads

Up to 32 CPUs

Thread-Structure

Affinity Mask

System

Auto load balancing

CPU Pool

Pool Affinity Mask

Timed Structures

Auto load balancing

CPU Pool

Pool Affinity Mask

Page 90: EECS Berkeley EE249 LabVIEW Frameworkee249/fa08/Lectures/EE249Fall08...EECS Berkeley EE249 LabVIEW Framework Hugo A. Andrade Principal Architect ... Math with the MathScript Node •

Execution Trace Toolkit

• LabVIEW Real-Time Only

• Thread view

• VI view (function view)

• Multicore support

• Debugging flags (memory manager collisions, mutex collisions, priority inheritance, ISRs, etc.)

• Trace Activity Sorting

Page 91: EECS Berkeley EE249 LabVIEW Frameworkee249/fa08/Lectures/EE249Fall08...EECS Berkeley EE249 LabVIEW Framework Hugo A. Andrade Principal Architect ... Math with the MathScript Node •

Resources www.ni.com/multicore