status of the development of the unified solids library
DESCRIPTION
Status of the development of the Unified Solids library. Marek Gayer, CERN PH/SFT 2 nd AIDA Annual Meeting, Frascati 2013. Motivations for a common solids library. Optimize and guarantee better long-term maintenance of ROOT and Gean4 solids libraries - PowerPoint PPT PresentationTRANSCRIPT
Status of the development of the Unified Solids library
Marek Gayer, CERN PH/SFT2nd AIDA Annual Meeting, Frascati 2013
Marek Gayer - Status of the development of the Unified Solids library
Motivations for a common solids
library• Optimize and guarantee better long-term
maintenance of ROOT and Gean4 solids librarieso A rough estimation indicates that about 70-80% of code investment for
the geometry modeler concerns solids, to guarantee the required precision and efficiency in a huge variety of combinations
• Create a single high quality library to replace solid libraries in Geant4 and ROOTo Starting from what exists today in Geant4 and Rooto Adopt a single type for each shapeo Make fast Tessellated Solid and new Multi-Union o Reach complete conformance to GDML solids schema
• Create extensive testing suite
11/04/2013
Marek Gayer - Status of the development of the Unified Solids library
Solids implemented so far
• Box• Orb• Trapezoid• Sphere (+ sphere section)• Tube (+ cylindrical section) • Cone (+ conical section) • Generic trapezoid• Tetrahedron• Arbitrary Trapezoid (ongoing)• Multi-Union• Tessellated Solid• Polycone (close to be finished)
0
500
1000
0
500
1000
200
400
600
800
1000
-10-5
05x 10
4 -5
0
5
x 104
-6
-4
-2
0
2
4
6
x 104
-4000-3000
-2000-1000
01000
20003000
4000
-4000
-3000
-2000
-1000
0
1000
2000
3000
4000-1000
0
1000
-1000
-500
0
500
1000
-1000
-500
0
500
1000-1000
-500
0
500
1000
-1000
-500
0
500
1000
-1000
-500
0
500
1000-1000
-500
0
500
1000
11/04/2013
Marek Gayer - Status of the development of the Unified Solids library
Testing Suite• Unified Solid Batch Test• Optical Escape
11/04/2013
Marek Gayer - Status of the development of the Unified Solids library
Unified Solid Batch Test• New powerful diagnosis tool for testing solids of ROOT,
Geant4 and Unified Solids library designed for transition to Unified Solids o The core part of Unified Solids testingo Testing Unified Solids together with existing Geant4 and ROOT solidso Testing methods with groups of points inside, outside and on surfaceo Compares performance and output values from different codeso Support for batch configuration and execution of testso Contains also tests from the original SBT for points and voxels
• Helps us to make sure we have similar or better performance in each method and different test cases
• Useful to detect, report and fix numerous bugs or suspect return values in Geant4, ROOT and Unified Solids
• Two phaseso Sampling phase (generation of data sets, implemented as C++ app.)o Analysis phase (data post-processing, implemented as MATLAB scripts)
11/04/2013
Marek Gayer - Status of the development of the Unified Solids library
Visualization of scalar and vector data sets
11/04/2013
Marek Gayer - Status of the development of the Unified Solids library
3D plots allowing to overview data sets
11/04/2013
Marek Gayer - Status of the development of the Unified Solids library
3D visualization of investigated shapes
-5000
0
5000
0
50000
0.2
0.4
0.6
0.8
1
1.2
1.4
1.6
1.8
2
x 104
11/04/2013
Marek Gayer - Status of the development of the Unified Solids library
Support for regions of data, focusing on sub-parts
11/04/2013
Marek Gayer - Status of the development of the Unified Solids library
Visual analysis of differences
11/04/2013
Marek Gayer - Status of the development of the Unified Solids library
Visual analysis of differences in 3D
11/04/2013
Marek Gayer - Status of the development of the Unified Solids library
Inside DistanceToOut DistanceToIn Normal SafetyFromOutside SafetyFromInside0
20
40
60
80
100
120
140
Method
Tim
e pe
r one
met
hod
call
[nan
osec
onds
]
Performance of methods at folder trap-1m-performance
Geant4ROOTUSolids
Graphs with comparison of performance
11/04/2013
Marek Gayer - Status of the development of the Unified Solids library
Visualization of scalability performance for specific
solids
3 10 100
0
500
1000
1500
2000
2500
3000
3500
4000
4500
5000
Count of solid parts
Tim
e [n
anos
econ
ds p
er o
pera
tion]
Performance of method DistanceToIn at folder log
Geant4ROOTUSolid
-1000
-500
0
500
1000
-1000
-500
0
500
10001000
1500
2000
2500
3000
-5000
0
5000
-5000
0
50000
0.2
0.4
0.6
0.8
1
1.2
1.4
1.6
1.8
2
x 104
-500005000-500005000
2
4
6
8
10
12
x 104
3 10 1000
1000
2000
3000
4000
5000
6000
7000
8000
9000
10000
Count of solid parts
Tim
e [n
anos
econ
ds p
er o
pera
tion]
Performance of method DistanceToOut at folder log
Geant4ROOTUSolid
-1000
-500
0
500
1000
-1000
-500
0
500
10001000
1500
2000
2500
3000
-5000
0
5000
-5000
0
50000
0.2
0.4
0.6
0.8
1
1.2
1.4
1.6
1.8
2
x 104
11/04/2013
Marek Gayer - Status of the development of the Unified Solids library
Inspection of values and differences of scalar and vector
data sets
11/04/2013
Marek Gayer - Status of the development of the Unified Solids library
New Multi-Union solid
11/04/2013
Marek Gayer - Status of the development of the Unified Solids library
Boolean Union solids• Existing CSG Boolean solids (ROOT and
Geant4) are represented as binary treeso To solve navigation requests, most of the solids composing a
complex one have to be checkedo Scalability is typically linear => low performance for solids
composed of many parts
Boolean Union solid: is binary tree of solids, either primitive or Boolean
[The pictures were produced by users of Wikipedia “Captain Sprite” and “Zottie” and are available under Creative Commons Attribution-Share Alike 3.0 Unported license ]
11/04/2013
Marek Gayer - Status of the development of the Unified Solids library
Multi-Union solid• We implemented a new
solid as a union of many solids using voxelization technique to optimize speed and scalabilityo 3D space partition for fast
localization of componentso Aiming for a log(n) scalability
• Useful for complex composites made of many solids
-0.8-0.6
-0.4-0.2
00.2
0.40.6
0.8
-0.8
-0.6
-0.4
-0.2
0
0.2
0.4
0.6
0.8
-0.8
-0.6
-0.4
-0.2
0
0.2
0.4
0.6
0.8
11/04/2013
Marek Gayer - Status of the development of the Unified Solids library
Scaling of Multi-Union vs. Boolean solid
0 5 10 15 20 25 30 35 40 45 50 55 60 65 70 75 80 850
2
4
6
8
10
12
14
Number of nodes
Tim
e of
exe
cutio
n [s
]
Scaling of Multi-Union inside method with boxes
Multi-UnionBoolean solid
11/04/2013
Marek Gayer - Status of the development of the Unified Solids library
Test multi-union solid for scalability measurements
Union of random boxes, orbs and trapezoids(on pictures with 5, 10, 20 solids)
11/04/2013
Marek Gayer - Status of the development of the Unified Solids library
The most performance critical methods
11/04/2013
Marek Gayer - Status of the development of the Unified Solids library
Fast Tessellated Solid
11/04/2013
Marek Gayer - Status of the development of the Unified Solids library
Fast Tessellated Solid• Made from connected triangular and
quadrangular facets forming solid• Old implementation was slow, no
spatial optimization• We use spatial division of facets into
3D grid forming voxels (i.e. we are “voxelizing”)
• Voxelizer is based on bitmasks logical and operations during initialization and on pre-calculated list of facets candidates during runtime
• We are factor thousands faster for LHCb provided foil test case (164k facets)
0510152025303540
0
20
40
60
80
100
120
140
160
180
2000
5
10
15
20
11/04/2013
Marek Gayer - Status of the development of the Unified Solids library
Fast Tessellated Solid• Voxelization resulted in a significant performance
enhancement in all performance critical methods• Also, old Tesselated Solid had several weak parts of
algorithm, used at initialization which had n2 complexity. o This sometimes caused very huge delays when loading (e.g. in case of foil with
164k faces)o Rewrote to have n ∙ log n complexityo Loading the solid is much faster. What before took minutes, now takes seconds
• Implemented also in Geant4 9.6 as G4TesselatedSolid• By improving design of classes and removing inefficiencies,
total memory save is about ~50%, o Voxelization has overhead vs. original G4TS, which reduces to a total memory save of ~25%
11/04/2013
Marek Gayer - Status of the development of the Unified Solids library
Inside Normal SafetyFromOutside SafetyFromInside DistanceToIn DistanceToOut0
5
10
15x 10
6
Method
Tim
e pe
r one
met
hod
call
[nan
osec
onds
]
Performance of methods at folder tessellatedsolid-test-t100-100k
G4TessellatedSolidNew G4TessellatedSolid
• Speedup: 894x 10.3x 1000x+ ~8.7x 412x 1183x• Speedup: 2423x 72x 1000x+ ~10.9x 1334x 1976x• Speedup: 2925x 46x 1000x+ ~9.8x 1332x 2968x
Performance – 164k/SCL5 with
10k/100k/1M voxels
11/04/2013
Marek Gayer - Status of the development of the Unified Solids library
DistanceToIn DistanceToOut Inside Normal SafetyFromInsideSafetyFromOutside0
1
2
3
4
5
6
7
8
9
10x 10
4
Method
Tim
e pe
r one
met
hod
call
[nan
osec
onds
]
Performance of methods at folder key-1.1k
G4TessellatedSolidNew G4TessellatedSolid
• Speedup: 17x 9.53 22.0x 2+ 1.8x 166+• Speedup: 22x 9.33 27.5x 20+ 2x 2000+
Performance – 1.1k/SCL 5 with 10k/1k voxels
11/04/2013
Marek Gayer - Status of the development of the Unified Solids library
Memory footprint change in comparison with old version
Voxels / Case key-1.1k.gdml foil-2.5k.gdml foil-164k.gdml1 -51% (291kB) -48% (575kB) -50% (32.8M)1000 -34% (391kB) -23% (843kb) -30% (46M)10.000 -22% (462kB) -15% (935kb) -29% (47.2M)100.000 +32% (907kB) +45% (1.6MB) -22% (51MB)1.000.000 +523%
(3.7MB)+500% (6.6MB)
+6% (70M)
11/04/2013
Marek Gayer - Status of the development of the Unified Solids library
Basic primitives – cone, tube, sphere
11/04/2013
Marek Gayer - Status of the development of the Unified Solids library
Cone performance
Inside DistanceToOut DistanceToIn Normal SafetyFromOutside SafetyFromInside0
50
100
150
200
250
300
350
400
450
Method
Tim
e pe
r one
met
hod
call
[nan
osec
onds
]
Performance of methods at folder cons-test6-p10k
Geant4ROOTUSolids
11/04/2013
Marek Gayer - Status of the development of the Unified Solids libraryInside DistanceToOut DistanceToIn Normal SafetyFromOutside SafetyFromInside
0
200
400
600
800
1000
1200
1400
Method
Tim
e pe
r one
met
hod
call
[nan
osec
onds
]
Performance of methods at folder cons-test6-p10k
Geant4ROOTUSolids
Cone with small wedge
performance
11/04/2013
Marek Gayer - Status of the development of the Unified Solids library
0 1 2 3 4 5 6 7 8 9 10
x 104
-1
-0.8
-0.6
-0.4
-0.2
0
0.2
0.4
0.6
0.8
1
All points
Folder: cons-test6-p10k ; Software: Geant4 - USolids
InsideSafetyFromInsideSafetyFromOutsideDistanceToOutDistanceToInNormal-XNormal-YNormal-Z
Cone values comparison
0 1 2 3 4 5 6 7 8 9 10
x 104
-1
-0.8
-0.6
-0.4
-0.2
0
0.2
0.4
0.6
0.8
1
All points
Folder: cons-test6-p10k ; Software: USolids - Root
InsideSafetyFromInsideSafetyFromOutsideDistanceToOutDistanceToInNormal-XNormal-YNormal-Z
11/04/2013
Marek Gayer - Status of the development of the Unified Solids library
Inside DistanceToOut DistanceToIn Normal SafetyFromOutside SafetyFromInside0
50
100
150
200
250
300
350
Method
Tim
e pe
r one
met
hod
call
[nan
osec
onds
]
Performance of methods at folder tubs-test2-p10k
Geant4ROOTUSolids
Tube performance
11/04/2013
Marek Gayer - Status of the development of the Unified Solids library
Inside DistanceToOut DistanceToIn Normal SafetyFromOutside SafetyFromInside0
500
1000
1500
2000
2500
Method
Tim
e pe
r one
met
hod
call
[nan
osec
onds
]
Performance of methods at folder sphere-test4-10k
Geant4ROOTUSolids
Spherical section performance
0
500
1000
0
500
1000-1000
-500
0
500
1000
11/04/2013
Marek Gayer - Status of the development of the Unified Solids library
Polycone
11/04/2013
Marek Gayer - Status of the development of the Unified Solids library
New polycone implementation
• Polycone is an important solid, heavily used in most experimental setups
• Optimization for constructs where coordinate of Z sections can only increase (big majority of real cases)o Careful rewrite of Polycone for these cases
• Based on composition of separate instances of cones, tubes (or their sections)o Providing brief, readable, clean and fast code
• Significant performance improvement over Geant4 & ROOT
• Could bring to visible CPU improvement in full simulation of complex setups like ATLAS
-500005000-500005000
2
4
6
8
10
12
x 104
11/04/2013
Marek Gayer - Status of the development of the Unified Solids library
Polycone Scalability
3s 10s 100s0
500
1000
1500
2000
Count of solid parts
Tim
e [n
anos
econ
ds p
er o
pera
tion]
Performance of method Inside at folder log
Geant4ROOTUSolid 3s 10s 100s
0
1000
2000
3000
4000
Count of solid parts
Tim
e [n
anos
econ
ds p
er o
pera
tion]
Performance of method DistanceToIn at folder log
Geant4ROOTUSolid
3s 10s 100s0
1000
2000
3000
4000
5000
6000
Count of solid parts
Tim
e [n
anos
econ
ds p
er o
pera
tion]
Performance of method DistanceToOut at folder log
Geant4ROOTUSolid
11/04/2013
Marek Gayer - Status of the development of the Unified Solids library
Current Polycone performance, 3 z
sections • Speedup factor 3.3x vs. Geant4, 7.6x vs. ROOT
for most performance critical methods, i.e.: Inside, DistanceToOut, DistanceToIn
Inside DistanceToOut DistanceToIn Normal SafetyFromOutside SafetyFromInside0
500
1000
1500
2000
2500
Method
Tim
e pe
r one
met
hod
call
[nan
osec
onds
]
Performance of methods at folder polycone-3s-360-perf
Geant4ROOTUSolid
11/04/2013
Marek Gayer - Status of the development of the Unified Solids library
Current Polycone performance, 10 z
sections • Speedup factor 8.3x vs. Geant4, 7.9x vs. ROOT
for most performance critical methods
Inside DistanceToOut DistanceToIn Normal SafetyFromOutside SafetyFromInside0
500
1000
1500
2000
2500
Method
Tim
e pe
r one
met
hod
call
[nan
osec
onds
]
Performance of methods at folder polycone-10s-360-perf
Geant4ROOTUSolid
11/04/2013
Marek Gayer - Status of the development of the Unified Solids library
Current Polycone performance, 100 z
sections • Speedup factor 34.3x vs. Geant4, 10.7 vs. ROOT
for most performance critical methods
Inside DistanceToOut DistanceToIn Normal SafetyFromOutside SafetyFromInside0
1000
2000
3000
4000
5000
6000
Method
Tim
e pe
r one
met
hod
call
[nan
osec
onds
]
Performance of methods at folder polycone-100s-360-perf
Geant4ROOTUSolid
11/04/2013
Marek Gayer - Status of the development of the Unified Solids library
Status of work Types and Unified Solids interface are defined Bridge classes for comparison with Geant4 and
ROOT implemented Testing suite defined and deployed Implemented 9 primitives (Box, Orb, Trapezoid,
Sphere, Tube, Cone, Generic trapezoid, Tetrahedron, Arbitrary trapezoid)
Implemented new composed solids Multi-Union, Tessellated, Polycone (close to be finished)
11/04/2013
Marek Gayer - Status of the development of the Unified Solids library
Future work plan• Marek Gayer
o Complete and eventually further optimize Polyconeo Implement Polyhedrao Hand over the tasks to Tatiana Nikitina
• Tatiana Nikitinao Give priority to the remaining most critical solids and those
where room for improvement can be easily identifiedo Systematically analyze and implement remaining solids in the
new library
11/04/2013
Thank you for your attention.
???Questions and Answers
Marek Gayer - Status of the development of the Unified Solids library 11/04/2013