timing trials an investigation arising out of the assignment 2012-2013 cs32310 – nov 2013 h...

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

Upload: amberlynn-owen

Post on 29-Dec-2015

213 views

Category:

Documents


0 download

TRANSCRIPT

1

Timing TrialsAn investigation arising out of the Assignment 2012-2013

CS32310 – Nov 2013H Holstein

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

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.

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

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

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.

1

0

0

⎢ ⎢ ⎢

⎥ ⎥ ⎥,

0

1

0

⎢ ⎢ ⎢

⎥ ⎥ ⎥,

0

0

1

⎢ ⎢ ⎢

⎥ ⎥ ⎥→

a11

a21

a31

⎢ ⎢ ⎢

⎥ ⎥ ⎥,

a12

a22

a32

⎢ ⎢ ⎢

⎥ ⎥ ⎥,

a13

a23

a33

⎢ ⎢ ⎢

⎥ ⎥ ⎥

Columns of 3D transformation matrix

7

Complexity example

• Consider a case with– Shift– Rotation– Shift– Scaling– Perspective projection

• N points to be transformed

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)

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

10

MATLAB timed runs

Single, one-off trial setTimings very different in different trialsOptimization taking place?

1.9 x 10-3 s

2.8 x 10-3 s

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.

12

Matrix methods - timing

MATLAB Trials 11-20Timings settled downOptimization taking place?

1.2 x 10-3 s

1.5 x 10-3 s

13

Vector methods - timing

MATLAB Trials 1-10Timings immediately repeatable

0 s

400 x 10-3 s

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

1.4163 −1.3458

350.1− 3.4≈

1/5000

Can simple complexity theory explain this result?

15

Complexity example

• Consider the same case with– Shift– Rotation– Shift– Scaling– Perspective projection

• N points to be transformed

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) 32 Shifts + 1 Rotation + 1 Scaling + 1 Proj 71Cost for N points: 71 N

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

18

Theoretical operation counts

Matrix methods superior for N>11

19

Operation counts

• Precise details depend on case and formula optimisation, but the result is typical.

matrixvector

=448 + 31N

71N≈ 6.3/N + 0.44 →0.44 as N →∞

N =11 :448 + 31N

71N=

789

781 (break even point)

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.

21

Comparison – average of 10 trials

Vector formulae

Matrix formulae,Own coded matrixmultiply

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

0.1757 − 0.0035

0.3501− 0.0034≈

0.497

acceptably close to theory: 0.44

23

Comparison – average of 10 trials

• Equation of regression lines (best fit)

• Matrix:

• Vector

• Slope ratio:

y = 1.427 ×10−4( )x + (1.551×10−3)

y = 2.865 ×10−4( )x + (2.836 ×10−4 )

0.498

24

Break even at N ≈ 10

Matrix methods superior for N>10

Vector formulae

Matrix formulae,Own coded matrixmultiply

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

26

END