Stabilizing Numeric Programs against Platform Uncertainties Thomas Wahl Northeastern University August 28, 2017
Example: Ray Tracing int raySphere( float *r, float *s, float radiusSq) { float A = dot3(r,r); float B = -2.0 * dot3(s,r); float C = dot3(s,s) - radiusSq; float D = B*B - 4*A*C; if (D > 0.00001) { float sign = ( C > 0.00001 ) ? 1 : -1; โฎ For the input on the right: AMD GPU A8-3850: ๐ธ = โ0.000122 NVIDIA Quadro 600 GPU: ๐ธ = +0.000244
CPU: 9.0 + 0.9 + 0.09 + 0.009 + 0.0009 + 0.00009 + 0.000009 + 0.0000009 9.9 GPU: 9.0 + 0.9 + 0.09 + 0.009 + 0.0009 + 0.00009 + 0.000009 + 0.0000009 0.099 0.0000099 9.9 0.00099 9.999 0.0009999 9.9999 999
Platform Variations: Contracted Operations ๐ ๐ ๐ ๐ Fused Multiply-Add (FMA) MULT MULT ๐ ROUND ๐ ADD ADD ROUND ROUND ๐ ร ๐ โ ๐ ๐ โ ๐ โ ๐
VOLATILITY IN NUMERIC PROGRAMS
Volatile Expressions = expression whose semantics depends on the (expression) evaluation model, which determines: โข evaluation order โข availability and use of hardware features such as fused multiply-add (FMA) ๐ 1 ๐ฝ + ๐ 2 ๐ฝ + โฆ + ๐ ๐ (๐ฝ) Sums, products: Dot products: ๐ 1 ๐ฝ ร ๐ 1 ๐ฝ + โฆ + ๐ ๐ ๐ฝ ร ๐ ๐ (๐ฝ)
Quantifying Volatility Let ๐ be a floating-point expression in the program. The volatile bound of ๐ for input ๐ฝ is min ๐ ๐ ๐ฝ, ๐ , max ๐ ๐ ๐ฝ, ๐ ๐ : expression evaluation models Questions: ๏ How do we compute this, for input ๐ฝ ? ๏ Once computed, what is it good for?
Volatility in Matrix Calculations ๏ผ well-designed programs ๏ผ high degree of reproducibility
But: Ray Tracing int raySphere( float *r, float *s, float radiusSq) { float A = dot3(r,r); float B = -2.0 * dot3(s,r); float C = dot3(s,s) - radiusSq; float D = B*B - 4*A*C; if (D > 0.00001) { float sign = ( C > 0.00001 ) ? 1 : -1; โฎ For some inputs: AMD GPU A8-3850: ๐ธ = โ0.000122 NVIDIA Quadro 600 GPU: ๐ธ = +0.000244
Stabilizing Numeric Programs: Overview Goal: โข Improve reproducibility of program results Naive solution: โ determinize โ the whole program cl /fp:strict source.cpp โข implements strict evaluation: FMA disabled, expressions from left to right
Local Stabilization
Identifying Major Destabilizers int raySphere( float *r, float *s, float radiusSq) { float A = dot3(r,r); float B = -2.0 * dot3(s,r); float C = dot3(s,s) - radiusSq; float D = B*B - 4*A*C; if (D > 0.00001) { float sign = ( C > 0.00001 ) ? 1 : -1; โฎ
Stabilizing ๐ธ โs expression int raySphere( float *r, float *s, float radiusSq) { float A = dot3(r,r); float B = -2.0 * dot3(s,r); float C = dot3(s,s) - radiusSq; /* donโt optimize ... */ float D = B*B - 4*A*C; if (D > 0.00001) { float sign = ( C > 0.00001 ) ? 1 : -1; โฎ Stabilizing D = B*B โ 4*A*C : new volatile bound for ๐ธ of [ โ0.250000000, 0.125000000 ]
Stabilizing ๐ธ โs expression not enough Two causes of large volatile bounds for ๐ฌ : 1. volatility caused by ๐ธ โs defining expression 2. volatility inherited from earlier expressions, which causes bloated inputs to ๐ธ !
Provenance of ๐ธ โs Volatility = for each preceding expression (here: ๐ต, ๐ถ, ๐ท ), the contribution to (impact on) ๐ธ โs volatility [VMCAI 2017]
int raySphere( float *r, float *s, float radiusSq) { float A = dot3(r,r); /* FMA forbidden! */ float B = -2.0 * dot3(s,r); /* donโt reorder! */ float C = dot3(s,s) - radiusSq; float D = B*B - 4*A*C; if (D > 0.00001) { float sign = ( C > 0.00001 ) ? 1 : -1; โฎ ๏ Stabilizing B = 2.0 * dot3(s,r) : new bound for ๐ธ : [-0.002806663, 0.156753913] ๏ Stabilizing C = dot3(s,s) - radiusSq new bound for ๐ธ : [0.125000000, 0.156753913]
Take-Home Messages ๏ผ FPA expressions are volatile: semantics fragile against platform variations ๏ผ expose volatility , or prove robustness , on a per-input basis ๏ผ repair: make program robust against platform uncertainties Future plans: ๏ platform uncertainties in machine learning (or other big-data) ๏ prove robustness for a range of inputs ๏ trade-offs: num. stability vs. accuracy ( โ !) vs. efficiency
Acknowledgements Joint with (@ NEU): โข Yijia Gu (stud.), Computer and Information Science โข Miriam Leeser (fac.) and Mahsa Bayati (stud.), Engineering http://www.ccs.neu.edu/home/wahl/Research/ /FPA-Heterogeneous/Non-Portability Financial Support:
Recommend
More recommend