Improving the Performance of Your NI LabVIEW … · LabVIEW Desktop Execution Trace Toolkit...

Preview:

Citation preview

Improving the Performance of YourNI LabVIEW ApplicationsNI LabVIEW Applications

Improving Performance inLabVIEW

Purpose of Profiling MemoryPurpose ofOptimization

ProfilingTools

MemoryOptimization

Optimization Cycle

Optimize• Improve efficiency

Benchmark• Evaluate performance • Improve efficiency

• Improve speed• Evaluate performance•Identify problem areas

Why Should You Profile Your VIs?

• 80 percent of the execution time isspent in 20 percent of the code

The 80/20 rule of software performance

• Performance improvements are mosteffective in the 20 percent

• Guessing which 20 percent is difficult

spent in 20 percent of the code

Improving Performance inLabVIEW

Purpose of Profiling MemoryPurpose ofOptimization

ProfilingTools

MemoryOptimization

Windows Task Manager

•Gives user a rough idea ofwhether memory or CPU isthe bottleneck

•Can be helpful in•Can be helpful inidentifying memory leaks

•View»Select Columns …allows you to add additionalstats

Perfmon

•Allows you to monitor•Processors•Disk I/O•Network Tx/Rx•Memory/Paging•Memory/Paging

•Access by typing“perfmon” into theWindows Run dialog

Benchmarking Code Execution

“Timing Template (data dep)” – LabVIEW Shipping Example

Benchmarking Code Execution

Code

Calibration

Analysis

“Benchmark Project” – LabVIEW Real-Time Shipping Example

VI Profiler• Timing and memory statistics for VIs

•Tools»Profile»Performance and Memory …

Demo – VI ProfilingDemo – VI Profiling

LabVIEW Desktop Execution TraceToolkit

Threads, CPUMultiple

Sessions

• Detailedexecutiontraces

• Thread and VIinformation

Threads, CPU

and Memory

VIs

Sessions• Measurement

of executiontime

Benchmarking Summary

OS Level

• Task Manager, Perfmon

LabVIEW LevelLabVIEW Level

• VI Profiler, Benchmark VIs

VI Level

• LabVIEW Desktop Execution Trace Toolkit

Improving Performance inLabVIEW

Purpose of Profiling MemoryPurpose ofOptimization

ProfilingTools

MemoryOptimization

VI Components

• Panel

• Diagram

• Code

– Diagram compiled into machine code– Diagram compiled into machine code

• Data

– Control/indicator values

– Default data

– Block diagram constant data

VIs in Memory

• When a VI is loaded into memory

– We always load the data

– We load the code if it matches our platform(x86 Windows, x86 Linux, x86 Mac, PowerPC Mac)(x86 Windows, x86 Linux, x86 Mac, PowerPC Mac)

– We load the panel and diagram only if we need to(for instance, we need to recompile the VI)

Panel and Diagram Data• Front panel controls and indicators need their own

copy of the data to display, called “operate data”

• This VI uses about 8 KB of data if the panel is open,and about 4 KB otherwise

LabVIEW Terminology

• Panel data is called “Operate Data”

– Controls and indicators have their own copy of thedata, so that front panel editing of data does notinterfere with computations in the diagraminterfere with computations in the diagram

• Diagram data is called “Execution Data”

– Every wire represents a buffer of data

• “Transfer Data” is used to copy between them

– Avoids multithreading issues

Memory Performance

• The following features affect the impactmemory allocation has on your application:

– Wire Semantics and “In Placeness”

– Type coercion– Type coercion

– Passing values to subVIs

– Shift registers

– Front panel indicators

Wire Semantics• Every wire is a buffer

• Branches typically create copies

Optimizations by LabVIEW

The theoretical 5 copies become 1 copy operation

Copy

Output is “in place” with input

The “In Place” Algorithm

• Determines when a copy needs to be made

– Weighs arrays and clusters higher than othertypes

• Algorithm runs before execution• Algorithm runs before execution

– Does not know the size of an array or cluster

• Relies on the sequential aspects of theprogram

– Branches may require copies

Bottom Up

In-place information is propagated bottom up

Branched wire

Increments array in place

Copy becauseof increment No copies required

Showing Buffer Allocations

Allows you to explicitly modify data “in place”

The In-Place Element Structure

Types of Border Nodes

• Array index/replace element

• Array split/replace subarray

• Unbundle/bundle

• Waveform unbundle/bundle• Waveform unbundle/bundle

• Variant to/from G data

• Simple “in place” relationship

• Data value referenceread/write

Operate on each element of an array of waveforms

Example of In Place Optimization

Make the First SubVI “In Place”

changes into…

SubVI 2 Is Made “In Place”

Changes into …Changes into …

SubVI 3 Is Made “In Place”

Changes into …

Final Result: Dots Are Hidden

Type Coercion

• Changing the data type of a wire to matchthe required data type

– Dots indicate automatic coercion

– Requires a copy– Requires a copyCoercion Dot

Passing Values to SubVIs

• SubVI does not always have to make a copy

• Best when …

– Inputs are required

– Inputs and outputs are not in structures– Inputs and outputs are not in structures

– Inputs and outputs are “in place”

Passing Values to SubVIs• Parameters within structures cause

unnecessary copies

MoveMove

Shift Registers• Single left input always in place with right

output

– Even better when the body is in place

In Place

Always In Place

In Place

Building Arrays

There are a number of ways to build arraysand some are better than others

BadBad

•Reallocates array memory onevery loop iteration

•No compile time optimization

Building Arrays

There are a number of ways to build arraysand some are better than others

Better

Keep graphicsbelow the textand to the right.

Better

•Memory allocated at load time

•Values populated “in place”

Building Arrays

There are a number of ways to build arraysand some are better than others

BestBest

•Memory preallocated

•Indexing tunnel eliminatesneed for copies

Build Array Ordering

• Appending to the end of an array is muchmore efficient than prepending to themore efficient than prepending to thebeginning

• If you need to insert items at the beginning,insert at the end instead and use a singleReverse Array when finished

Demo – Effects of MemoryOptimization

Demo – Effects of MemoryOptimization

Improving Performance inLabVIEW

Purpose ofOptimization

Profiling ToolsMemory

Optimization

• Decrease memory usage, increase speed• 80/20 Rule

Improving Performance inLabVIEW

Purpose ofOptimization

Profiling ToolsMemory

Optimization

• Windows Tools (Task Manager, perfmon)• VI Profiler• Real-Time Execution Trace Toolkit

Improving Performance inLabVIEW

Purpose ofOptimization

Profiling ToolsMemory

Optimization

• Hide the dots• Take advantage of “in placeness”

Next Steps

• LabVIEW Help

In LabVIEW

• ni.com/multicore

• ni.com/devzone

On the Web

Next Steps

• Visit ni.com/training

• Identify your current expertise level anddesired level

• Register for appropriate courses• Register for appropriate courses

Recommended