34
LabVIEW Programming for a Multicore Environment Stefan Kreuzer ApplicationsEngineer National Instruments

LabVIEW Programming for a Multicore Environmentdownload.ni.com/.../centraleurope/nidays_at/Kreuzer_Multicore.pdf · LabVIEW Programming for a Multicore Environment ... – Real-Time

Embed Size (px)

Citation preview

Page 1: LabVIEW Programming for a Multicore Environmentdownload.ni.com/.../centraleurope/nidays_at/Kreuzer_Multicore.pdf · LabVIEW Programming for a Multicore Environment ... – Real-Time

LabVIEW Programming for a Multicore

Environment

Stefan Kreuzer

Applications Engineer

National Instruments

Page 2: LabVIEW Programming for a Multicore Environmentdownload.ni.com/.../centraleurope/nidays_at/Kreuzer_Multicore.pdf · LabVIEW Programming for a Multicore Environment ... – Real-Time

Agenda

• Overview of LabVIEW Multithreading

• Parallel Programming Techniques

• Real-Time Considerations

Resources• Resources

Page 3: LabVIEW Programming for a Multicore Environmentdownload.ni.com/.../centraleurope/nidays_at/Kreuzer_Multicore.pdf · LabVIEW Programming for a Multicore Environment ... – Real-Time

Impact on Engineers and Scientists

Engineering and scientific applications are typically on

dedicated systems (i.e. little multitasking).

Page 4: LabVIEW Programming for a Multicore Environmentdownload.ni.com/.../centraleurope/nidays_at/Kreuzer_Multicore.pdf · LabVIEW Programming for a Multicore Environment ... – Real-Time

Creating Multithreaded Applications

Engineers and scientists must use threads to benefit

from multicore processors.

Page 5: LabVIEW Programming for a Multicore Environmentdownload.ni.com/.../centraleurope/nidays_at/Kreuzer_Multicore.pdf · LabVIEW Programming for a Multicore Environment ... – Real-Time

• LabVIEW automatically divides each application into

multiple execution threads

• LabVIEW introduced multithreading in 1998

Automatic Multithreading in LabVIEW

Page 6: LabVIEW Programming for a Multicore Environmentdownload.ni.com/.../centraleurope/nidays_at/Kreuzer_Multicore.pdf · LabVIEW Programming for a Multicore Environment ... – Real-Time

• LabVIEW automatically divides each application into

multiple execution threads

• LabVIEW introduced multithreading in 1998

Automatic Multithreading in LabVIEW

threadthread

thread

thread

Page 7: LabVIEW Programming for a Multicore Environmentdownload.ni.com/.../centraleurope/nidays_at/Kreuzer_Multicore.pdf · LabVIEW Programming for a Multicore Environment ... – Real-Time

Demo:

“Accidental Parallelism” in LabVIEW

Page 8: LabVIEW Programming for a Multicore Environmentdownload.ni.com/.../centraleurope/nidays_at/Kreuzer_Multicore.pdf · LabVIEW Programming for a Multicore Environment ... – Real-Time

• Scale # of execution system threads based on available cores

• Improved thread scheduling for LabVIEW timed loops

• Set Processor Affinity with Timed Structures

• Real-Time Features:

– Support for Real-Time targets with Symmetric Multiprocessing

NEW Multithreading Features in LabVIEW 8.5

– Support for Real-Time targets with Symmetric Multiprocessing

– Real-Time Execution Trace Toolkit 2.0

Page 9: LabVIEW Programming for a Multicore Environmentdownload.ni.com/.../centraleurope/nidays_at/Kreuzer_Multicore.pdf · LabVIEW Programming for a Multicore Environment ... – Real-Time

Eaton created a portable in-vehicle test system for

truck transmissions using LabVIEW.

• Acquired and analyzed 16 channels on single core using

DAQmx multithreaded driver

• Now acquire and analyze 80+ channels on multicore

Application Example – Eaton Corporation

• Now acquire and analyze 80+ channels on multicore

“There was no need to rewrite our application for the

new multicore processing platforms.”

Scott Sirrine

Lead Design Engineer

Eaton Truck Division

Page 10: LabVIEW Programming for a Multicore Environmentdownload.ni.com/.../centraleurope/nidays_at/Kreuzer_Multicore.pdf · LabVIEW Programming for a Multicore Environment ... – Real-Time

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

Multithreaded Software Stack Support

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

Page 11: LabVIEW Programming for a Multicore Environmentdownload.ni.com/.../centraleurope/nidays_at/Kreuzer_Multicore.pdf · LabVIEW Programming for a Multicore Environment ... – Real-Time

Key Considerations• Is the code sequential or parallel?

• How are shared resources being utilized within the application?

Conclusions

Evaluating if existing LabVIEW applications

will run faster on multicore systems

Conclusions• Code speed-up will widely vary depending on application

• Many applications will require minor modifications to fully optimize for multicore

Page 12: LabVIEW Programming for a Multicore Environmentdownload.ni.com/.../centraleurope/nidays_at/Kreuzer_Multicore.pdf · LabVIEW Programming for a Multicore Environment ... – Real-Time

Sequential vs. Parallel Code

Sequential Example- LabVIEW will execute VIs in order, one after another.

RESULT:

A multicore system will not improve processing speed over a

single core system, because there is no parallelism in the code.

Page 13: LabVIEW Programming for a Multicore Environmentdownload.ni.com/.../centraleurope/nidays_at/Kreuzer_Multicore.pdf · LabVIEW Programming for a Multicore Environment ... – Real-Time

Sequential vs. Parallel Code

Parallel Example - Since code has parallel branches, LabVIEW will try to compile code for parallel

execution

RESULT:

Code can now take advantage of multicore systems, i.e.

“Filter” and “Spectral Measurements” VIs will execute in parallel.

Page 14: LabVIEW Programming for a Multicore Environmentdownload.ni.com/.../centraleurope/nidays_at/Kreuzer_Multicore.pdf · LabVIEW Programming for a Multicore Environment ... – Real-Time

Potential Bottlenecks: Shared Resources

1. Data DependenciesExample: Data stored in global variables that need to be accessed by

different VIs would be a shared resource

2. Hard DiskExample: Computers can only read or write to the hard disk one item at a Example: Computers can only read or write to the hard disk one item at a

time (File I/O cannot be made into parallel operations)

3. Non-reentrant VIs

Page 15: LabVIEW Programming for a Multicore Environmentdownload.ni.com/.../centraleurope/nidays_at/Kreuzer_Multicore.pdf · LabVIEW Programming for a Multicore Environment ... – Real-Time

Non-reentrant VIs• VIs that are non-reentrant cannot be called simultaneously, one call runs and

the other call waits for the first to finish before running

To make a VI reentrant, select File»VI Properties, select the Execution

category and choose Reentrant execution.

Page 16: LabVIEW Programming for a Multicore Environmentdownload.ni.com/.../centraleurope/nidays_at/Kreuzer_Multicore.pdf · LabVIEW Programming for a Multicore Environment ... – Real-Time

Parallel Programming Techniques to Improve

Performance on Multicore Systems

• Task Parallelism

• Data Parallelism

• Pipelining

Page 17: LabVIEW Programming for a Multicore Environmentdownload.ni.com/.../centraleurope/nidays_at/Kreuzer_Multicore.pdf · LabVIEW Programming for a Multicore Environment ... – Real-Time

You can speed up processor-intensive operations

on large data sets on multicore systems.

Data Parallelism

Data Set

CPU Core

Signal Processing Result

CPU Core

CPU Core

CPU Core

CPU Core

Page 18: LabVIEW Programming for a Multicore Environmentdownload.ni.com/.../centraleurope/nidays_at/Kreuzer_Multicore.pdf · LabVIEW Programming for a Multicore Environment ... – Real-Time

You can speed up processor-intensive operations

on large data sets on multicore systems.

Signal Processing

Data Set

CPU Core

Data Parallelism

Signal Processing

Signal Processing

Signal Processing

Signal Processing

Combine

Results

CPU Core

CPU Core

CPU Core

CPU Core

Page 19: LabVIEW Programming for a Multicore Environmentdownload.ni.com/.../centraleurope/nidays_at/Kreuzer_Multicore.pdf · LabVIEW Programming for a Multicore Environment ... – Real-Time

Data Parallelism Demo

Page 20: LabVIEW Programming for a Multicore Environmentdownload.ni.com/.../centraleurope/nidays_at/Kreuzer_Multicore.pdf · LabVIEW Programming for a Multicore Environment ... – Real-Time

Application Example: High-Speed Control

• Max Planck Institute (Munich, Germany)

• Plasma control in nuclear fusion tokamak with

LabVIEW on 8 core system using data parallelism

technique

“…with LabVIEW, we obtained a 20X processing speed-up on an“…with LabVIEW, we obtained a 20X processing speed-up on an

octal-core processor machine over a single-core processor…”

Louis Giannone

Lead Project Researcher

Max Planck Institute

Page 21: LabVIEW Programming for a Multicore Environmentdownload.ni.com/.../centraleurope/nidays_at/Kreuzer_Multicore.pdf · LabVIEW Programming for a Multicore Environment ... – Real-Time

• Many applications involve sequential, multistep algorithms

• 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 22: LabVIEW Programming for a Multicore Environmentdownload.ni.com/.../centraleurope/nidays_at/Kreuzer_Multicore.pdf · LabVIEW Programming for a Multicore Environment ... – Real-Time

Acquire

Filter

CPU Core

CPU Core

Pipelining Strategy

time

Analyze

Log

t0 t1 t2

CPU Core

CPU Core

t3

Page 23: LabVIEW Programming for a Multicore Environmentdownload.ni.com/.../centraleurope/nidays_at/Kreuzer_Multicore.pdf · LabVIEW Programming for a Multicore Environment ... – Real-Time

Acquire Acquire

Filter Filter

CPU Core

CPU Core

Pipelining Strategy

Analyze Analyze

Log Log

CPU Core

CPU Core

timet0 t1 t2 t3

Page 24: LabVIEW Programming for a Multicore Environmentdownload.ni.com/.../centraleurope/nidays_at/Kreuzer_Multicore.pdf · LabVIEW Programming for a Multicore Environment ... – Real-Time

Acquire Acquire Acquire Acquire

Filter Filter Filter Filter

CPU Core

CPU Core

Pipelining Strategy

Analyze Analyze Analyze Analyze

Log Log Log Log

CPU Core

CPU Core

timet0 t1 t2 t3

Page 25: LabVIEW Programming for a Multicore Environmentdownload.ni.com/.../centraleurope/nidays_at/Kreuzer_Multicore.pdf · LabVIEW Programming for a Multicore Environment ... – Real-Time

Sequential Pipelined

?

Pipelining in LabVIEW

Note: Queues may also be

used to pipeline data between

different loops

?

or

Page 26: LabVIEW Programming for a Multicore Environmentdownload.ni.com/.../centraleurope/nidays_at/Kreuzer_Multicore.pdf · LabVIEW Programming for a Multicore Environment ... – Real-Time

Pipelining Demo

Page 27: LabVIEW Programming for a Multicore Environmentdownload.ni.com/.../centraleurope/nidays_at/Kreuzer_Multicore.pdf · LabVIEW Programming for a Multicore Environment ... – Real-Time

• Consider number of Processor Cores when

determining number of pipeline stages

• Be sure to balance stages since longest stage will be

limiting factor in performance speed-up – Example:

Key Considerations for Pipelining

– Example:

Unbalanced Pipeline

Page 28: LabVIEW Programming for a Multicore Environmentdownload.ni.com/.../centraleurope/nidays_at/Kreuzer_Multicore.pdf · LabVIEW Programming for a Multicore Environment ... – Real-Time

Tips for Balancing Pipeline Stages

• Use LabVIEW benchmarking techniques

– Perform basic benchmarking with

timestamps and VI Profiler

Page 29: LabVIEW Programming for a Multicore Environmentdownload.ni.com/.../centraleurope/nidays_at/Kreuzer_Multicore.pdf · LabVIEW Programming for a Multicore Environment ... – Real-Time

LabVIEW 8.5 adds Symmetric Multiprocessing (SMP) for real-

time systems.

Deterministic Real-Time Systems

Page 30: LabVIEW Programming for a Multicore Environmentdownload.ni.com/.../centraleurope/nidays_at/Kreuzer_Multicore.pdf · LabVIEW Programming for a Multicore Environment ... – Real-Time

In LabVIEW 8.5, users can assign code to specific processor cores

using the LabVIEW Timed Loop.

Assigning Tasks to Specific Cores

Page 31: LabVIEW Programming for a Multicore Environmentdownload.ni.com/.../centraleurope/nidays_at/Kreuzer_Multicore.pdf · LabVIEW Programming for a Multicore Environment ... – Real-Time

Processor Affinity with the Timed Loop

• Recommended for

Real-Time

development

• Under special use-• Under special use-

cases it can be

used on Windows

(example: cache

optimization)

Page 32: LabVIEW Programming for a Multicore Environmentdownload.ni.com/.../centraleurope/nidays_at/Kreuzer_Multicore.pdf · LabVIEW Programming for a Multicore Environment ... – Real-Time

Execution Trace Toolkit 2.0

• 30-day evaluation

• Compatible with LabVIEW

7.1 and higher

• New Features in Version

2.02.0

• Performance improvements

• Trace activity sorting

• New debugging flags (priority

inheritance)

• Multicore support

Page 33: LabVIEW Programming for a Multicore Environmentdownload.ni.com/.../centraleurope/nidays_at/Kreuzer_Multicore.pdf · LabVIEW Programming for a Multicore Environment ... – Real-Time

Application Example: Real-Time Control

• Wind Tunnel Safety-of-Flight

system at NASA Ames

Research Center

• Benchmarks Results– Ran on PXI-8106 RT Controller– Ran on PXI-8106 RT Controller

– Time-Critical loop was reduced from

43 % CPU load to 30 % CPU load on

one CPU of the PXI-8106RT

– A core leftover for processing of non-

critical tasks. Image Source: http://windtunnels.arc.nasa.gov

Page 34: LabVIEW Programming for a Multicore Environmentdownload.ni.com/.../centraleurope/nidays_at/Kreuzer_Multicore.pdf · LabVIEW Programming for a Multicore Environment ... – Real-Time

Resources

www.ni.com/multicore