View
233
Download
2
Category
Preview:
Citation preview
7/24/2019 LabVIEW Performance and Memory Management
1/40
Dev Days Performance
and Memory Management
Adam Kemp
Sta Software EngineerLabVIE !ompi"er #eam
7/24/2019 LabVIEW Performance and Memory Management
2/40
$oa"s
%nderstand t&e LabVIE E'ec(tionSystem
Learn to improve performance by) *ed(cing data copies
*ed(cing overa"" memory (sage
%nderstand VI E'ec(tion Properties
7/24/2019 LabVIEW Performance and Memory Management
3/40
#&e LabVIE E'ec(tionSystem
#&e e'ec(tion system is t&e part ofLabVIE w&ic& is responsib"e foract(a""y r(nning yo(r code
Enab"es a(tomatic para""e"ism
%ni+(e to LabVIE ,t&er "ang(ages re+(ire man(a" t&read
management
7/24/2019 LabVIEW Performance and Memory Management
4/40
#&e LabVIE E'ec(tionSystem
or-s "i-e a t&read poo" A +(e(e of .obs
A set of t&reads p(""ing .obs o t&e +(e(e
/obs 01+(e(e e"ements23 are pieces of VI code to
e'ec(te ,ne +(e(e per e'ec(tion system
%I
Standard
Instr(ment I4,
Data Ac+(isition
,t&er 5
,t&er 6
#imed "oops
7/24/2019 LabVIEW Performance and Memory Management
5/40
LabVIE E'ec(tion System
Eac& e'ec(tion system &as m("tip"et&reads
E'ception) %I &as on"y one t&read
7/24/2019 LabVIEW Performance and Memory Management
6/40
LabVIE E'ec(tion System
7/24/2019 LabVIEW Performance and Memory Management
7/40
LabVIE !"(mpingA"gorit&mClump 1
Clump 2
Clump 0 Clump 0
7/24/2019 LabVIEW Performance and Memory Management
8/40
!"(mp 6 S"eeping
!"(mp 5 S"eeping
!"(mp 7 S"eeping
LabVIE !"(mpingA"gorit&m
!omp"etion ofdiagram)Divide nodes8 disp"ayofindicators8 t&en VIe'it9
Start of diagram)*eads contro"s8 t&ensc&ed("es !"(mps 5and 6#&en s"eeps999
:ottom ;or Loop
Indicator is(pdated!"(mp 7Sc&ed("edS"eep999
#op ;or LoopIndicator is(pdated!"(mp 7Sc&ed("ed
S"eep999
Clump 1
Clump 2
Clump 0
7/24/2019 LabVIEW Performance and Memory Management
9/40
$oing to s"eep
&en a node 1goes to s"eep2 it p(ts itse"f on await +(e(e and t&en ret(rns to t&e e'ec(tionsystem E9g98
7/24/2019 LabVIEW Performance and Memory Management
10/40
Preferred E'ec(tion Systems
Some nodes m(st r(n in %I t&read
Eac& VI can specify a preferrede'ec(tion system Defa("t is 1Same as ca""er2
7/24/2019 LabVIEW Performance and Memory Management
11/40
Switc&ing E'ec(tionSystems
=appens w&en code needs to r(n in a dierente'ec(tion system t&an t&e ca""er or previo(s code
Most common wit& %I code
Switc&ing e'ec(tion systems can ca(seperformance prob"ems *e+(ires going to s"eep and t&en wa-ing (p on anot&er
e'ec(tion system t&read
Switc&ing bac- ta-es .(st as "ong
!an sometimes set Preferred E'ec(tion System toavoid e'tra switc&es
Avoid (nnecessary %I code
7/24/2019 LabVIEW Performance and Memory Management
12/40
Priorities
S(bVI priorities aect t&e priority of t&e +(e(ee"ements for t&at VI wit&in an e'ec(tionsystem
=ig&er priority +(e(e e"ements are p(""ed o>rst
#&e priority setting does not aect t&e priorityof t&e e'ec(tion system t&read itse"f#&e ,S may preempt t&e w&o"e t&read to r(n t&et&read for anot&er e'ec(tion system 0or ot&erprocess3
%se #imed Loops to contro" priority more re"iab"y
7/24/2019 LabVIEW Performance and Memory Management
13/40
S(bro(tine Priority
?ot a rea" priority
*ed(ces e'ec(tion system over&ead for verycommon"y ca""ed code
;orces t&e w&o"e VI to be in a sing"e c"(mp Prevents t&e VI from ever going to s"eep
?o ca""s w&ic& may s"eep 0"i-e +(e(e operations3
?o switc&ing e'ec(tion systems
!an on"y ca"" ot&er s(bro(tine VIs
?o para""e"ism
!an be set to 1S-ip S(bro(tine !a"" If :(sy2
%s(a""y not recommended
7/24/2019 LabVIEW Performance and Memory Management
14/40
In"ine VIs
Preferred rep"acement for S(bro(tine Priority
Entire b"oc- diagram is inserted into ca""er w&ent&e ca""er is compi"ed @ero ca"" over&ead
!an sti"" contain para""e"ism
A""ows for more compi"er optimiations
Limitations)
?o front pane" access ?ot a"" nodes a""owed
;orces ca""ers to recompi"e every time t&e S(bVI ismodi>ed
7/24/2019 LabVIEW Performance and Memory Management
15/40
ire Semantics
Every wire is a b(er :ranc&es create copies
7/24/2019 LabVIEW Performance and Memory Management
16/40
,ptimiations by LabVIE
#&e t&eoretica" B copies become 5 copyoperation9
Copy
Output is inplace with input
7/24/2019 LabVIEW Performance and Memory Management
17/40
#&e 1In P"ace2 A"gorit&m
Determines w&en a copy needs to bemade eig&ts arrays and c"(sters &ig&er t&an
ot&er types A"gorit&m r(ns before e'ec(tion
Does not -now t&e sie of an array or string
*e"ies on t&e se+(entia" aspects of t&e
program :ranc&es mig&t re+(ire copies
7/24/2019 LabVIEW Performance and Memory Management
18/40
:ottom %p
In p"ace information is propagatedbottom (p t&ro(g& t&e ca""&ierarc&y
Increments array in place
Copy because
of increment No copies required
Branched wire
7/24/2019 LabVIEW Performance and Memory Management
19/40
S&owing :(er A""ocations
7/24/2019 LabVIEW Performance and Memory Management
20/40
E'amp"e of In P"ace,ptimiation
Operate on each element of an arrayof waveforms
7/24/2019 LabVIEW Performance and Memory Management
21/40
Ma-e t&e >rst S(bVI 1inp"ace2
c&anges intoC
7/24/2019 LabVIEW Performance and Memory Management
22/40
S(bVI 6 is made 1in p"ace2
c&angesintoC
7/24/2019 LabVIEW Performance and Memory Management
23/40
S(bVI is made 1in p"ace2
c&angesintoC
7/24/2019 LabVIEW Performance and Memory Management
24/40
;ina" *es("t) Dots are=idden
7/24/2019 LabVIEW Performance and Memory Management
25/40
In P"ace E"ement Str(ct(re?odes
Seven border node types)
Array inde'4rep"ace
Array sp"it4rep"ace s(barrays
%nb(nd"e4:(nd"e c"(ster
%nb(nd"e4:(nd"e waveform Variant to4from e"ement
In P"ace In4o(t border node
Data Va"(e *eference *ead4rite
*ig&tc"ic- "eft or rig&t border to add nodes
7/24/2019 LabVIEW Performance and Memory Management
26/40
Pane" Data or ,perate:(ers
!ontro"s andindicators &avet&eir own copy of
t&e data Memory is not
needed if t&e frontpane" is not in
memory Defa("t data
increases memory
(sage
7/24/2019 LabVIEW Performance and Memory Management
27/40
#ransfer :(ers
#ransfer :(ersprotect data transferbetween ,perate and
E'ec(tion :(ers ,n"y (pdated if front
pane" is in memory
Copy
Copy
7/24/2019 LabVIEW Performance and Memory Management
28/40
Loca" and $"oba" Variab"es
Loca" variab"es (pdate t&e datatransfer b(er9
*eading a "oca" or g"oba" variab"e
a"ways ca(ses a data copy %se wires to transfer data w&en
possib"e
7/24/2019 LabVIEW Performance and Memory Management
29/40
Loca" Variab"es vs9 VI Server Property
?ode
Loca" Variab"es !an r(n in any t&read
!opies to4from transfer b(er
rites ca(se second copy into operate b(er if front pane" isin memory 0avoid t&is if possib"e3
%se w&en speed is important
Property ?odes M(st r(n in %I t&read
!opies to4from operate b(er
rites ca(se second copy into transfer b(er
;orce front pane" in memory
%se w&en sync&rono(s disp"ay is necessary
Avoid both if possible
7/24/2019 LabVIEW Performance and Memory Management
30/40
Data by *eference
Manip("ate references to t&e data insteadof t&e data itse"f
Data Copy
Data Copy
Data
Reference
Reference
Reference
Traditional dataow) branc&esmay create copies
By reference) points tomemory "ocation
7/24/2019 LabVIEW Performance and Memory Management
31/40
Data Va"(e *eferences
Act as references to data rat&er t&anf("" data itse"f
!an protect access to data
7/24/2019 LabVIEW Performance and Memory Management
32/40
Memory *ea""ocation
Prea""ocate anarray if yo()
!onditiona""yadd va"(es to
an array !an determine
an (pper "imiton t&e array
sie
7/24/2019 LabVIEW Performance and Memory Management
33/40
!onditiona" Indicators
An indicator inside a !ase str(ct(reor ;or Loop
Prevents LabVIE from re(sing datab(ers
7/24/2019 LabVIEW Performance and Memory Management
34/40
*eentrancy and Dataspaces
?onreentrant ,ne dataspace s&ared by every ca""
,n"y one ca"" can e'ec(te at a time
Lower memory (sage
!an save state 0e9g98 for LV6sty"e g"oba"s3
Standard reentrancy8 a-a 1Prea""ocate c"ones2) Every ca"" &as its own dataspace
!a""s never &ave to wait
Poo"ed reentrancy8 a-a 1S&are c"ones2 Added in LabVIE F9B
Eac& ca"" p(""s a dataspace from a s&ared poo" ?ew dataspaces are a""ocated dynamica""y if needed
!a""s never &ave to wait 0e'cept possib"y to a""ocate a new dataspace3
*e+(ired for rec(rsion
7/24/2019 LabVIEW Performance and Memory Management
35/40
LabVIE !"ean(p
LabVIE c"eans (p many referencesw&en t&e owning VI goes id"e and ot&ersw&en t&e process c"oses
Man(a""y c"ose references to avoid(ndesirab"e memory growt&8 partic("ar"yfor "ongr(nning app"ications9
7/24/2019 LabVIEW Performance and Memory Management
36/40
Memory %sage of t&e %ser Interface
Every contro" on t&e %I re+(ires memoryin order to store t&e data str(ct(re
At r(n time8 !ontro" and Indicator data is
additiona" copy of b"oc- diagram data Defa("t data for contro"s may contrib(te
to (nnecessary memory (sage
S(bVI %Is genera""y do not contrib(te tomemory (sage
7/24/2019 LabVIEW Performance and Memory Management
37/40
#ips for red(cing memory(sage
,perate on data in p"ace
Do not over(se reentrant settings
!"ose references to avoid "ea-s
Avoid operations w&ic& re+(ire t&e front pane" tobe in memory E') !ontro" references
Save t&e VI and c"ose t&e front pane" before r(nning
Avoid "arge defa("t data in arrays8 grap&s8 etc9
,n"y disp"ay information on t&e front pane" w&ennecessary
*e+(est Dea""ocation Primitive
7/24/2019 LabVIEW Performance and Memory Management
38/40
Memory ;ragmentation
59G $: 79H $:
%sedAvai"ab"e795 $: 795G $:
79H$:
795G $: 79H6 $: 79F$:
79 $:
795H $:
*eported
Act(a"
7/24/2019 LabVIEW Performance and Memory Management
39/40
$enera" :enc&mar-ing tips
Disab"e deb(gging
Save a""
!"ose a"" (nnecessary front pane"s
7/24/2019 LabVIEW Performance and Memory Management
40/40
Recommended