Presentation is loading. Please wait.

Presentation is loading. Please wait.

Timing Trials An investigation arising out of the Assignment 2012-2013 CS32310 – Nov 2013 H Holstein 1.

Similar presentations


Presentation on theme: "Timing Trials An investigation arising out of the Assignment 2012-2013 CS32310 – Nov 2013 H Holstein 1."— Presentation transcript:

1 Timing Trials An investigation arising out of the Assignment 2012-2013 CS32310 – Nov 2013 H Holstein 1

2 Abstract Transformations of the coordinates defining points in a 3D scene can be carried out using vector formulae or matrix formulae Operation counts suggest that the matrix formulae are more efficient when there are enough points to transform. MATLAB Timings showed unexpectedly high matrix speedups – Cannot be explained by complexity alone 2

3 Abstract Theoretical gains levels were observed with ‘own coded’ (slower) matrix multiply routines, This suggests that the MATLAB matrix routines make use of some form of parallel array processing. Conclude that MATLB matrix methods benefit from parallelisation – more significant than the reduced complexity, in outperforming vector methods. 3

4 Introduction Task is to compare performance of vector and matrix transformation methods For this purpose, plotting of the transformed points is not necessary Carry out a theoretical operations count analysis, – Assume operation count ∝ execution time Carry out timing experiments, using the processor clock 4

5 Methods Complexity count for a sequence of operations – Count the number of multiplications and additions required, per point transformed, – Estimate operations needed for N points Use a fairly large point set (e.g. N ≈ 1000) on which to carry out the computation of a sequence of transformations Do this for the matrix and the vector cases 5

6 Derivation of the matrix operators Use the vector formulae to transform the unit basis vectors. The result are the columns of the transformation matrix. 6 Columns of 3D transformation matrix

7 Complexity example Consider a case with – Shift – Rotation – Shift – Scaling – Perspective projection N points to be transformed 7

8 Derivation of the matrix operators Embed in a 4 x 4 matrix Include shifts and perspective transformations References: – Worksheet 3 – Homogeneous coordinates (pptx, lecture notes) 8

9 Derivation of the matrix operators Set the timer Set up the 4 x 4 transformation matrix for each operation Multiply the operators together – Obtain a single operator Multiply the positions vectors ( in homogeneous coordinates) by this operator Record the time Repeat for different sizes of data points Draw graph of times vs number of points 9

10 MATLAB timed runs Single, one-off trial set Timings very different in different trials Optimization taking place? 1.9 x 10 -3 s 2.8 x 10 -3 s 10

11 Results Timing results varied, but settled down Carried out 20 timing trials, each for 10 to 1220 points, – Ignore first 10 trials. – This way obtained repeatable results. 11

12 Matrix methods - timing MATLAB Trials 11-20 Timings settled down Optimization taking place? 1.2 x 10 -3 s 1.5 x 10 -3 s 12

13 Vector methods - timing MATLAB Trials 1-10 Timings immediately repeatable 0 s 400 x 10 -3 s 13

14 3.4 29.0 57.7 86.2 114.8 143.6 172.2 200.6 229.4 258.0 286.7 315.4 344.2 350.1 10 100 200 300 400 500 600 700 800 900 1000 1100 1200 1220 Vertices Vector Matrix Ratio 1.3458 1 / 2.5 1.3469 1.3540 1.3675 1.3676 1.3737 1.3805 1.3883 1.3979 1.3962 1.4053 1.4141 1.4222 1.4163 1 / 250 Time (milliseconds) Comparison – average of 10 trials Ratio of slopes Can simple complexity theory explain this result? 14

15 Complexity example Consider the same case with – Shift – Rotation – Shift – Scaling – Perspective projection N points to be transformed 15

16 Vector Arithmetic Complexity Notation: (multiplies, adds)  multiplies+adds 3D rotation (18,11)  29 Scaling (7,6)  13 Perspective projection (10,13)  23 Shift (0,3)  3 2 Shifts + 1 Rotation + 1 Scaling + 1 Proj  71 Cost for N points: 71 N 16

17 Matrix Arithmetic Complexity Set-up: N=3 for vector formula: 71x3=213 – Concatenation: 4 matrix multiplies (4 by 4): 4x16 x(4,3)  448 Running cost – Matrix multiply (4x4)x (4xN): 4N(4,3)  28N Post processing: 4-vectors to 3 vectors: – 3N Cost for N points: 448 + 31N 17

18 Theoretical operation counts Matrix methods superior for N>11 18

19 Operation counts Precise details depend on case and formula optimisation, but the result is typical. 19

20 Operation counts MATLAB trials indicated matrix methods outperforming vector methods by up to a factor of about 5000 in timing. Operation counts do not explain this. Repeat the experiments, using ‘own’ matrix multiply routines. 20

21 Comparison – average of 10 trials Vector formulae Matrix formulae, Own coded matrix multiply 21

22 0.0034 0.0046 0.0059 0.0146 0.0290 0.0577 0.0862 0.1148 0.1436 0.1722 0.2006 0.2294 0.2580 0.2867 0.3154 0.3442 0.3501 10 15 20 50 100 200 300 400 500 600 700 800 900 1000 1100 1200 1220 Vertices Vector Matrix 0.0035 0.0036 0.0043 0.0087 0.0158 0.0301 0.0443 0.0585 0.0728 0.0872 0.1013 0.1156 0.1300 0.1445 0.1588 0.1728 0.1757 Time (seconds) Comparison – average of 10 trials Ratio of slopes acceptably close to theory: 0.44 22

23 Comparison – average of 10 trials Equation of regression lines (best fit) Matrix: Vector Slope ratio: 23

24 Break even at N ≈ 10 Matrix methods superior for N>10 Vector formulae Matrix formulae, Own coded matrix multiply 24

25 Conclusions Transformation using matrix operators have lower operation counts per point transformed, than corresponding vector formulae Initial timing tests showed matrix methods up to about 250 times faster, with an extrapolation up to 5000 times faster. Theory can explain a speedup by about 2 Factor 2 verified by ‘own code’ matrix methods A greater speedup in matrix method can comes from parallel array processing – Appears that MATLAB uses this (via graphics card) – Feature not directly available to vector methods 25

26 END 26


Download ppt "Timing Trials An investigation arising out of the Assignment 2012-2013 CS32310 – Nov 2013 H Holstein 1."

Similar presentations


Ads by Google