labview improving performance
TRANSCRIPT
-
8/6/2019 Labview Improving Performance
1/46
1
Improving the Performance of Your
NI LabVIEW Applications
Dan Hedges
Senior Software EngineerLabVIEW Performance Group
-
8/6/2019 Labview Improving Performance
2/46
2
Agenda
How to find performance problems
Benchmarking
Profiling
Understanding LabVIEW under the hood
Memory usage
Execution system
-
8/6/2019 Labview Improving Performance
3/46
3
Optimization Cycle
Benchmark Evaluate Performance
Identify Problem Areas
Optimize Improve efficiency
Improve Speed
-
8/6/2019 Labview Improving Performance
4/46
4
Benchmarking Code Execution
Timing Template (data dep) LabVIEW Shipping Example
-
8/6/2019 Labview Improving Performance
5/46
5
Benchmarking Code Execution
Calibration Code
Analysis
Benchmark Project LabVIEW Real-Time Shipping Example
-
8/6/2019 Labview Improving Performance
6/46
6
Tools for Measuring Resource Usage
(Windows) Task Manager
Perfmon
-
8/6/2019 Labview Improving Performance
7/467
Windows Task ManagerGives user a rough idea ofwhether memory or CPU isthe bottleneck
Can be helpful inidentifying memory leaks
ViewSelect Columns
allows you to add additionalstats
-
8/6/2019 Labview Improving Performance
8/468
PerfmonAllows you to monitor
ProcessorsDisk I/ONetwork Tx/Rx
Memory/Paging
Access by typingperfmon into the
Windows Run dialog
-
8/6/2019 Labview Improving Performance
9/469
Why Should You Profile Your VIs?
Performance improvements are most effective in
the 20 percent Guessing which 20 percent is difficult
80 percent of the execution time is spent in
20 percent of the code
The 80/20 rule of software performance
-
8/6/2019 Labview Improving Performance
10/4610
VI Profiler
Tools >> Profile >> Performance and Memory
-
8/6/2019 Labview Improving Performance
11/4611
Demo VI Profiling
-
8/6/2019 Labview Improving Performance
12/4612
LabVIEW Desktop Execution Trace
Toolkit
Threads, CPU
and Memory
VIs
MultipleSessions
Detailed
execution
traces
Thread and VIinformation
Measurement
of execution
time
-
8/6/2019 Labview Improving Performance
13/46
13
Profiling and Benchmarking Summary
To answer this question: Use these tools:
What is my current performance? Benchmark VIs
What are my limiting resources? Task Manager, Perfmon
How much time are each of my VIs taking? VI Profiler
In what order are events occurring? LabVIEW Desktop Execution Trace Toolkit
-
8/6/2019 Labview Improving Performance
14/46
14
UnderLabVIEWs Hood
MemoryManagement ExecutionSystem
-
8/6/2019 Labview Improving Performance
15/46
15
What Is In Memory?
Panel Diagram
CompiledCode Data
-
8/6/2019 Labview Improving Performance
16/46
16
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)
We load the panel and diagram only if we need to
(for instance, we need to recompile the VI)
-
8/6/2019 Labview Improving Performance
17/46
17
Panel and Diagram Data
How many bytes of memory does this VI use?
The answer depends on:
Is the panel in memory?
Is the environment multi-threaded?
-
8/6/2019 Labview Improving Performance
18/46
18
Execute, Operate and Transfer Data
Populated byCode
4K ExecuteData
Copy for Indicator4K Operate
Data
TemporaryBuffer
4K TransferData
-
8/6/2019 Labview Improving Performance
19/46
19
Avoid Loading Panels, Save Memory
-
8/6/2019 Labview Improving Performance
20/46
20
Wire Semantics Every wire is a buffer
Branches typically create copies
-
8/6/2019 Labview Improving Performance
21/46
21
Optimizations by LabVIEW
The theoretical 5 copies become 1 copy operation
Copy
Output is in place with input
-
8/6/2019 Labview Improving Performance
22/46
22
The In Place Algorithm
Determines when a copy needs to be made
Weighs arrays and clusters higher than other types
Algorithm runs during compilation, not execution
Does not know the size of an array or cluster
Relies on the sequential aspects of the program
Branches may require copies
-
8/6/2019 Labview Improving Performance
23/46
23
Bottom Up
In-place information is propagated bottom up
Increments array in plac
Copy because
of increment No copies required
Branched wire
-
8/6/2019 Labview Improving Performance
24/46
24
Showing Buffer Allocations
-
8/6/2019 Labview Improving Performance
25/46
25
The In-Place Element Structure
Allows you to explicitly modify data in place
-
8/6/2019 Labview Improving Performance
26/46
26
Example of In Place OptimizationOperate on each element of an array of waveforms
-
8/6/2019 Labview Improving Performance
27/46
27
Make the First SubVI In Place
changes into
-
8/6/2019 Labview Improving Performance
28/46
28
SubVI 2 Is Made In Place
Changes into
-
8/6/2019 Labview Improving Performance
29/46
29
SubVI 3 Is Made In Place
Changes into
-
8/6/2019 Labview Improving Performance
30/46
30
Final Result: Dots Are Hidden
-
8/6/2019 Labview Improving Performance
31/46
31
Building Arrays
There are a number of ways to build arrays and
some are better than others
BadReallocates array memory onevery loop iteration
No compile time optimization
-
8/6/2019 Labview Improving Performance
32/46
32
Building Arrays
There are a number of ways to build arrays. Try to
minimize reallocations.
BestMemory preallocated
Indexing tunnel eliminates
need for copies
-
8/6/2019 Labview Improving Performance
33/46
33
Demo Effects of MemoryOptimization
-
8/6/2019 Labview Improving Performance
34/46
34
UnderLabVIEWs Hood
MemoryManagement ExecutionSystem
-
8/6/2019 Labview Improving Performance
35/46
35
VIs Are Compiled001110100101010100010001111110101010101000101110001011001011001100011101001010
10100010001111110101010101000101110001011001011001100011101001010101000100011111101010101010001011100010
-
8/6/2019 Labview Improving Performance
36/46
36
VIs Are Compiled: ClumpsClump 1
Clump 2
Clump 0 Clump 0
-
8/6/2019 Labview Improving Performance
37/46
37
Clump 2 Sleeping
Clump 1 Sleeping
Clump 0 Sleeping
VIs Are Compiled: Clumps
Completion of diagram:
Divide nodes, display of
indicators, then VI exit
Start of diagram:
Reads controls, then
schedules Clumps 1
and 2
Then sleeps ...
Bottom for loopindicator is updated
Clump 0 Scheduled
Sleep ...
Top for loop
indicator is updated
Clump 0 Scheduled
Sleep ...
Clump 0 Clump 1
Clump 2
Clump 0
-
8/6/2019 Labview Improving Performance
38/46
38
Single-Threaded LabVIEW
CPU Thread
User Interface
Loop
CodeExecution
Coroutines
-
8/6/2019 Labview Improving Performance
39/46
39
Exec
Thread
Multithreaded LabVIEW
CPU
UI Loop
Thread
Exec
Thread
messages
Exec
Thread
Exec
Thread
-
8/6/2019 Labview Improving Performance
40/46
40
Exec
Thread
LabVIEW on a Multicore Machine
CPU1
UI Loop
Thread
Exec
Thread
Exec
Thread
Exec
Threadmessages
CPU0
-
8/6/2019 Labview Improving Performance
41/46
41
Some Operations Require the UI
Thread
Call Library Nodes
Control/Indicator Property Nodes
Front Panel Control References
-
8/6/2019 Labview Improving Performance
42/46
42
Execution Properties
-
8/6/2019 Labview Improving Performance
43/46
43
Reentrant VIs
Reentrancy allows one subVI to be called
simultaneously from different places
Requires extra memory for each instance
Use reentrant VIs in two different cases
To allow a subVI to be called in parallel
To allow a subVI instance to maintain its own state
-
8/6/2019 Labview Improving Performance
44/46
44
LabVIEW 2010 Compiler
Generates code that runs faster, ~30%
Takes longer to run (~5x-7x)
SSEInstructions
SubVI InlinerRegister
CandidatesDead CodeElimination
Loop InvariantCode Motion
Common
SubexpressionElimination
And more
-
8/6/2019 Labview Improving Performance
45/46
45
Demo Effects of ExecutionOptimization
-
8/6/2019 Labview Improving Performance
46/46
Next Steps
LabVIEW Help
In LabVIEW
ni.com/multicore
ni.com/devzone
On the Web