general merchandisers sector analysis

46
1 Improving the Performance of Your NI LabVIEW Applications Dan Hedges Senior Software Engineer LabVIEW Performance Group

Upload: others

Post on 03-Feb-2022

1 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: General Merchandisers Sector Analysis

1

Improving the Performance of Your

NI LabVIEW Applications

Dan Hedges

Senior Software Engineer

LabVIEW Performance Group

Page 2: General Merchandisers Sector Analysis

2

Agenda

• How to find performance problems

Benchmarking

Profiling

• Understanding LabVIEW under the hood

Memory usage

Execution system

Page 3: General Merchandisers Sector Analysis

3

Optimization Cycle

Benchmark

• Evaluate Performance

• Identify Problem Areas

Optimize

• Improve efficiency

• Improve Speed

Page 4: General Merchandisers Sector Analysis

4

Benchmarking Code Execution

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

Page 5: General Merchandisers Sector Analysis

5

Benchmarking Code Execution

Calibration Code

Analysis

“Benchmark Project” – LabVIEW Real-Time Shipping Example

Page 6: General Merchandisers Sector Analysis

6

Tools for Measuring Resource Usage

(Windows)

• Task Manager

• Perfmon

Page 7: General Merchandisers Sector Analysis

7

Windows Task Manager •Gives user a rough idea of

whether memory or CPU is

the bottleneck

•Can be helpful in

identifying memory leaks

•View»Select Columns …

allows you to add additional

stats

Page 8: General Merchandisers Sector Analysis

8

Perfmon •Allows you to monitor

•Processors

•Disk I/O

•Network Tx/Rx

•Memory/Paging

•Access by typing

“perfmon” into the

Windows Run dialog

Page 9: General Merchandisers Sector Analysis

9

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

Page 10: General Merchandisers Sector Analysis

10

VI Profiler

• Tools >> Profile >> Performance and Memory…

Page 11: General Merchandisers Sector Analysis

11

Demo – VI Profiling

Page 12: General Merchandisers Sector Analysis

12

LabVIEW Desktop Execution Trace

Toolkit

Threads, CPU

and Memory

VIs

Multiple

Sessions

• Detailed

execution

traces

• Thread and VI

information

• Measurement

of execution

time

Page 13: General Merchandisers Sector Analysis

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

Page 14: General Merchandisers Sector Analysis

14

Under LabVIEW’s Hood

Memory Management

Execution System

Page 15: General Merchandisers Sector Analysis

15

What Is In Memory?

Panel Diagram

Compiled Code

Data

Page 16: General Merchandisers Sector Analysis

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)

Page 17: General Merchandisers Sector Analysis

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?

Page 18: General Merchandisers Sector Analysis

18

Execute, Operate and Transfer Data

• Populated by Code

4K Execute Data

• Copy for Indicator 4K Operate

Data

• Temporary Buffer

4K Transfer Data

Page 19: General Merchandisers Sector Analysis

19

Avoid Loading Panels, Save Memory

Page 20: General Merchandisers Sector Analysis

20

Wire Semantics • Every wire is a buffer

• Branches typically create copies

Page 21: General Merchandisers Sector Analysis

21

Optimizations by LabVIEW

The theoretical 5 copies become 1 copy operation

Copy

Output is “in place” with input

Page 22: General Merchandisers Sector Analysis

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

Page 23: General Merchandisers Sector Analysis

23

Bottom Up

In-place information is propagated bottom up

Increments array in place

Copy because

of increment No copies required

Branched wire

Page 24: General Merchandisers Sector Analysis

24

Showing Buffer Allocations

Page 25: General Merchandisers Sector Analysis

25

The In-Place Element Structure

Allows you to explicitly modify data “in place”

Page 26: General Merchandisers Sector Analysis

26

Example of In Place Optimization Operate on each element of an array of waveforms

Page 27: General Merchandisers Sector Analysis

27

Make the First SubVI “In Place”

changes into…

Page 28: General Merchandisers Sector Analysis

28

SubVI 2 Is Made “In Place”

Changes into …

Page 29: General Merchandisers Sector Analysis

29

SubVI 3 Is Made “In Place”

Changes into …

Page 30: General Merchandisers Sector Analysis

30

Final Result: Dots Are Hidden

Page 31: General Merchandisers Sector Analysis

31

Building Arrays

There are a number of ways to build arrays and

some are better than others

Bad

•Reallocates array memory on

every loop iteration

•No compile time optimization

Page 32: General Merchandisers Sector Analysis

32

Building Arrays

There are a number of ways to build arrays. Try to

minimize reallocations.

Best

•Memory preallocated

•Indexing tunnel eliminates

need for copies

Page 33: General Merchandisers Sector Analysis

33

Demo – Effects of Memory

Optimization

Page 34: General Merchandisers Sector Analysis

34

Under LabVIEW’s Hood

Memory Management

Execution System

Page 35: General Merchandisers Sector Analysis

35

VIs Are Compiled 0011101001010

1010001000111

1110101010101

0001011100010

1100101100110

0011101001010

1010001000111

1110101010101

0001011100010

1100101100110

0011101001010

1010001000111

1110101010101

0001011100010

Page 36: General Merchandisers Sector Analysis

36

VIs Are Compiled: “Clumps” Clump 1

Clump 2

Clump 0 Clump 0

Page 37: General Merchandisers Sector Analysis

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 loop

indicator is updated

Clump 0 Scheduled

Sleep ...

Top for loop

indicator is updated

Clump 0 Scheduled

Sleep ...

Clump 0 Clump 1

Clump 2

Clump 0

Page 38: General Merchandisers Sector Analysis

38

Single-Threaded LabVIEW

CPU Thread

User Interface

Loop

Code

Execution

Coroutines

Page 39: General Merchandisers Sector Analysis

39

Exec

Thread

Multithreaded LabVIEW

CPU

UI Loop

Thread

Exec

Thread

messages

Exec

Thread

Exec

Thread

Page 40: General Merchandisers Sector Analysis

40

Exec

Thread

LabVIEW on a Multicore Machine

CPU1

UI Loop

Thread

Exec

Thread

Exec

Thread

Exec

Thread messages

CPU0

Page 41: General Merchandisers Sector Analysis

41

Some Operations Require the UI

Thread

Call Library Nodes

Control/Indicator Property Nodes

Front Panel Control References

Page 42: General Merchandisers Sector Analysis

42

Execution Properties

Page 43: General Merchandisers Sector Analysis

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

Page 44: General Merchandisers Sector Analysis

44

LabVIEW 2010 Compiler

• Generates code that runs faster, ~30%

• Takes longer to run (~5x-7x)

SSE Instructions

SubVI Inliner Register

Candidates Dead Code Elimination

Loop Invariant Code Motion

Common Subexpression

Elimination And more

Page 45: General Merchandisers Sector Analysis

45

Demo – Effects of Execution

Optimization

Page 46: General Merchandisers Sector Analysis

46

Next Steps

• LabVIEW Help

In LabVIEW

• ni.com/multicore

• ni.com/devzone

On the Web