Top Banner
Telescoping MATLAB for DSP Applications PhD Thesis Defense Arun Chauhan Computer Science, Rice University PhD Thesis Defense July 10, 2003
97

Telescoping MATLAB for DSP Applicationsachauhan/Presentations/Thesis/defense.pdf · Telescoping MATLAB for DSP Applications PhD Thesis Defense ArunChauhan Computer Science, Rice University

Mar 23, 2020

Download

Documents

dariahiddleston
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Telescoping MATLAB for DSP Applicationsachauhan/Presentations/Thesis/defense.pdf · Telescoping MATLAB for DSP Applications PhD Thesis Defense ArunChauhan Computer Science, Rice University

Telescoping MATLAB for DSP Applications

PhD Thesis Defense

Arun Chauhan

Computer Science, Rice University

PhD Thesis Defense July 10, 2003

Page 2: Telescoping MATLAB for DSP Applicationsachauhan/Presentations/Thesis/defense.pdf · Telescoping MATLAB for DSP Applications PhD Thesis Defense ArunChauhan Computer Science, Rice University

Two True Stories

• the world of Digital Signal Processing

- almost everyone uses MATLAB

- a large number uses MATLAB exclusively

- almost everyone hates writing C code

- prefer coding for an hour and letting it run for 7 days, than

the other way round

- often forced to rewrite programs in C

• linear algebra through MATLAB

- ARPACK—a linear algebra package to solve eigenvalue

problems

- prototyped in MATLAB

- painfully hand translated to FORTRAN

PhD Thesis Defense: Telescoping MATLAB for DSP Applications July 10, 2003

Page 3: Telescoping MATLAB for DSP Applicationsachauhan/Presentations/Thesis/defense.pdf · Telescoping MATLAB for DSP Applications PhD Thesis Defense ArunChauhan Computer Science, Rice University

Two True Stories• the world of Digital Signal Processing

- almost everyone uses MATLAB

- a large number uses MATLAB exclusively

- almost everyone hates writing C code

- prefer coding for an hour and letting it run for 7 days, than

the other way round

- often forced to rewrite programs in C

• linear algebra through MATLAB

- ARPACK—a linear algebra package to solve eigenvalue

problems

- prototyped in MATLAB

- painfully hand translated to FORTRAN

PhD Thesis Defense: Telescoping MATLAB for DSP Applications July 10, 2003

Page 4: Telescoping MATLAB for DSP Applicationsachauhan/Presentations/Thesis/defense.pdf · Telescoping MATLAB for DSP Applications PhD Thesis Defense ArunChauhan Computer Science, Rice University

Two True Stories• the world of Digital Signal Processing

- almost everyone uses MATLAB

- a large number uses MATLAB exclusively

- almost everyone hates writing C code

- prefer coding for an hour and letting it run for 7 days, than

the other way round

- often forced to rewrite programs in C

• linear algebra through MATLAB

- ARPACK—a linear algebra package to solve eigenvalue

problems

- prototyped in MATLAB

- painfully hand translated to FORTRAN

PhD Thesis Defense: Telescoping MATLAB for DSP Applications July 10, 2003

Page 5: Telescoping MATLAB for DSP Applicationsachauhan/Presentations/Thesis/defense.pdf · Telescoping MATLAB for DSP Applications PhD Thesis Defense ArunChauhan Computer Science, Rice University

Two True Stories• the world of Digital Signal Processing

- almost everyone uses MATLAB

- a large number uses MATLAB exclusively

- almost everyone hates writing C code

- prefer coding for an hour and letting it run for 7 days, than

the other way round

- often forced to rewrite programs in C

• linear algebra through MATLAB

- ARPACK—a linear algebra package to solve eigenvalue

problems

- prototyped in MATLAB

- painfully hand translated to FORTRAN

PhD Thesis Defense: Telescoping MATLAB for DSP Applications July 10, 2003

Page 6: Telescoping MATLAB for DSP Applicationsachauhan/Presentations/Thesis/defense.pdf · Telescoping MATLAB for DSP Applications PhD Thesis Defense ArunChauhan Computer Science, Rice University

Two True Stories• the world of Digital Signal Processing

- almost everyone uses MATLAB

- a large number uses MATLAB exclusively

- almost everyone hates writing C code

- prefer coding for an hour and letting it run for 7 days, than

the other way round

- often forced to rewrite programs in C

• linear algebra through MATLAB

- ARPACK—a linear algebra package to solve eigenvalue

problems

- prototyped in MATLAB

- painfully hand translated to FORTRAN

PhD Thesis Defense: Telescoping MATLAB for DSP Applications July 10, 2003

Page 7: Telescoping MATLAB for DSP Applicationsachauhan/Presentations/Thesis/defense.pdf · Telescoping MATLAB for DSP Applications PhD Thesis Defense ArunChauhan Computer Science, Rice University

Lessons

• programming is an unavoidable fact of life to conduct

research in science and engineering

• users do not like programming in traditional

languages

• users love domain-specific high-level scripting

languages

- MATLAB has over 500,000 worldwide licenses

- Python, Perl, R, Mathematica

• performance problems limit their use

• the productivity connection

PhD Thesis Defense: Telescoping MATLAB for DSP Applications July 10, 2003

Page 8: Telescoping MATLAB for DSP Applicationsachauhan/Presentations/Thesis/defense.pdf · Telescoping MATLAB for DSP Applications PhD Thesis Defense ArunChauhan Computer Science, Rice University

Lessons• programming is an unavoidable fact of life to conduct

research in science and engineering

• users do not like programming in traditional

languages

• users love domain-specific high-level scripting

languages

- MATLAB has over 500,000 worldwide licenses

- Python, Perl, R, Mathematica

• performance problems limit their use

• the productivity connection

PhD Thesis Defense: Telescoping MATLAB for DSP Applications July 10, 2003

Page 9: Telescoping MATLAB for DSP Applicationsachauhan/Presentations/Thesis/defense.pdf · Telescoping MATLAB for DSP Applications PhD Thesis Defense ArunChauhan Computer Science, Rice University

Lessons• programming is an unavoidable fact of life to conduct

research in science and engineering

• users do not like programming in traditional

languages

• users love domain-specific high-level scripting

languages

- MATLAB has over 500,000 worldwide licenses

- Python, Perl, R, Mathematica

• performance problems limit their use

• the productivity connection

PhD Thesis Defense: Telescoping MATLAB for DSP Applications July 10, 2003

Page 10: Telescoping MATLAB for DSP Applicationsachauhan/Presentations/Thesis/defense.pdf · Telescoping MATLAB for DSP Applications PhD Thesis Defense ArunChauhan Computer Science, Rice University

Lessons• programming is an unavoidable fact of life to conduct

research in science and engineering

• users do not like programming in traditional

languages

• users love domain-specific high-level scripting

languages

- MATLAB has over 500,000 worldwide licenses

- Python, Perl, R, Mathematica

• performance problems limit their use

• the productivity connection

PhD Thesis Defense: Telescoping MATLAB for DSP Applications July 10, 2003

Page 11: Telescoping MATLAB for DSP Applicationsachauhan/Presentations/Thesis/defense.pdf · Telescoping MATLAB for DSP Applications PhD Thesis Defense ArunChauhan Computer Science, Rice University

Lessons• programming is an unavoidable fact of life to conduct

research in science and engineering

• users do not like programming in traditional

languages

• users love domain-specific high-level scripting

languages

- MATLAB has over 500,000 worldwide licenses

- Python, Perl, R, Mathematica

• performance problems limit their use

• the productivity connection

PhD Thesis Defense: Telescoping MATLAB for DSP Applications July 10, 2003

Page 12: Telescoping MATLAB for DSP Applicationsachauhan/Presentations/Thesis/defense.pdf · Telescoping MATLAB for DSP Applications PhD Thesis Defense ArunChauhan Computer Science, Rice University

Lessons• programming is an unavoidable fact of life to conduct

research in science and engineering

• users do not like programming in traditional

languages

• users love domain-specific high-level scripting

languages

- MATLAB has over 500,000 worldwide licenses

- Python, Perl, R, Mathematica

• performance problems limit their use

• the productivity connection

PhD Thesis Defense: Telescoping MATLAB for DSP Applications July 10, 2003

Page 13: Telescoping MATLAB for DSP Applicationsachauhan/Presentations/Thesis/defense.pdf · Telescoping MATLAB for DSP Applications PhD Thesis Defense ArunChauhan Computer Science, Rice University

History Repeats

“It was our belief that if FORTRAN, during its first

months, were to translate any reasonable ‘scientific’

source program into an object program only half as fast

as its hand-coded counterpart, then acceptance of our

system would be in serious danger... I believe that had

we failed to produce efficient programs, the widespread

use of languages like FORTRAN would have been seri-

ously delayed.”

–John Backus

PhD Thesis Defense: Telescoping MATLAB for DSP Applications July 10, 2003

Page 14: Telescoping MATLAB for DSP Applicationsachauhan/Presentations/Thesis/defense.pdf · Telescoping MATLAB for DSP Applications PhD Thesis Defense ArunChauhan Computer Science, Rice University

Pushing the Level Again

effective compilation

efficient compilation

PhD Thesis Defense: Telescoping MATLAB for DSP Applications July 10, 2003

Page 15: Telescoping MATLAB for DSP Applicationsachauhan/Presentations/Thesis/defense.pdf · Telescoping MATLAB for DSP Applications PhD Thesis Defense ArunChauhan Computer Science, Rice University

Pushing the Level Again

effective compilation

efficient compilation

PhD Thesis Defense: Telescoping MATLAB for DSP Applications July 10, 2003

Page 16: Telescoping MATLAB for DSP Applicationsachauhan/Presentations/Thesis/defense.pdf · Telescoping MATLAB for DSP Applications PhD Thesis Defense ArunChauhan Computer Science, Rice University

Pushing the Level Again

effective compilation

efficient compilation

PhD Thesis Defense: Telescoping MATLAB for DSP Applications July 10, 2003

Page 17: Telescoping MATLAB for DSP Applicationsachauhan/Presentations/Thesis/defense.pdf · Telescoping MATLAB for DSP Applications PhD Thesis Defense ArunChauhan Computer Science, Rice University

Thesis

It is possible to efficiently compile

numerical programs written in high-

level languages to achieve perfor-

mance close to that achievable in a

lower-level language.

PhD Thesis Defense: Telescoping MATLAB for DSP Applications July 10, 2003

Page 18: Telescoping MATLAB for DSP Applicationsachauhan/Presentations/Thesis/defense.pdf · Telescoping MATLAB for DSP Applications PhD Thesis Defense ArunChauhan Computer Science, Rice University

Fundamental Observation

• libraries are the key in optimizing high-level scripting

languages

a = x * y ⇒ a = MATMULT(x, y)

• libraries define high-level languages!

- a large effort in HPC is towards writing libraries

- domain-specific libraries make scripting languages useful and

popular

- high-level operations are largely “syntactic sugar”

PhD Thesis Defense: Telescoping MATLAB for DSP Applications July 10, 2003

Page 19: Telescoping MATLAB for DSP Applicationsachauhan/Presentations/Thesis/defense.pdf · Telescoping MATLAB for DSP Applications PhD Thesis Defense ArunChauhan Computer Science, Rice University

Fundamental Observation

• libraries are the key in optimizing high-level scripting

languages

a = x * y ⇒ a = MATMULT(x, y)

• libraries define high-level languages!

- a large effort in HPC is towards writing libraries

- domain-specific libraries make scripting languages useful and

popular

- high-level operations are largely “syntactic sugar”

PhD Thesis Defense: Telescoping MATLAB for DSP Applications July 10, 2003

Page 20: Telescoping MATLAB for DSP Applicationsachauhan/Presentations/Thesis/defense.pdf · Telescoping MATLAB for DSP Applications PhD Thesis Defense ArunChauhan Computer Science, Rice University

Libraries as Black Boxes

library compilerlibrary

binaries

user

programcompiler object code

PhD Thesis Defense: Telescoping MATLAB for DSP Applications July 10, 2003

Page 21: Telescoping MATLAB for DSP Applicationsachauhan/Presentations/Thesis/defense.pdf · Telescoping MATLAB for DSP Applications PhD Thesis Defense ArunChauhan Computer Science, Rice University

Libraries as Black Boxes

library compilerlibrary

binaries

user

programcompiler object code

PhD Thesis Defense: Telescoping MATLAB for DSP Applications July 10, 2003

Page 22: Telescoping MATLAB for DSP Applicationsachauhan/Presentations/Thesis/defense.pdf · Telescoping MATLAB for DSP Applications PhD Thesis Defense ArunChauhan Computer Science, Rice University

Whole Program Compilation

user

program

library

one

library

two

one.one

one.two

compiler object code

PhD Thesis Defense: Telescoping MATLAB for DSP Applications July 10, 2003

Page 23: Telescoping MATLAB for DSP Applicationsachauhan/Presentations/Thesis/defense.pdf · Telescoping MATLAB for DSP Applications PhD Thesis Defense ArunChauhan Computer Science, Rice University

Telescoping Languages Approach

• pre-compile libraries to minimize end-user

compilation time

• annotate libraries to capture specialized knowledge of

library writers

• generate specialized variants based on interesting

contexts

• link appropriate versions into the user script

analogous to offline indexing by search engines

PhD Thesis Defense: Telescoping MATLAB for DSP Applications July 10, 2003

Page 24: Telescoping MATLAB for DSP Applicationsachauhan/Presentations/Thesis/defense.pdf · Telescoping MATLAB for DSP Applications PhD Thesis Defense ArunChauhan Computer Science, Rice University

Telescoping Languages Approach

• pre-compile libraries to minimize end-user

compilation time

• annotate libraries to capture specialized knowledge of

library writers

• generate specialized variants based on interesting

contexts

• link appropriate versions into the user script

analogous to offline indexing by search engines

PhD Thesis Defense: Telescoping MATLAB for DSP Applications July 10, 2003

Page 25: Telescoping MATLAB for DSP Applicationsachauhan/Presentations/Thesis/defense.pdf · Telescoping MATLAB for DSP Applications PhD Thesis Defense ArunChauhan Computer Science, Rice University

Telescoping Languages Approach

• pre-compile libraries to minimize end-user

compilation time

• annotate libraries to capture specialized knowledge of

library writers

• generate specialized variants based on interesting

contexts

• link appropriate versions into the user script

analogous to offline indexing by search engines

PhD Thesis Defense: Telescoping MATLAB for DSP Applications July 10, 2003

Page 26: Telescoping MATLAB for DSP Applicationsachauhan/Presentations/Thesis/defense.pdf · Telescoping MATLAB for DSP Applications PhD Thesis Defense ArunChauhan Computer Science, Rice University

Telescoping Languages Approach

• pre-compile libraries to minimize end-user

compilation time

• annotate libraries to capture specialized knowledge of

library writers

• generate specialized variants based on interesting

contexts

• link appropriate versions into the user script

analogous to offline indexing by search engines

PhD Thesis Defense: Telescoping MATLAB for DSP Applications July 10, 2003

Page 27: Telescoping MATLAB for DSP Applicationsachauhan/Presentations/Thesis/defense.pdf · Telescoping MATLAB for DSP Applications PhD Thesis Defense ArunChauhan Computer Science, Rice University

Telescoping Languages Approach

• pre-compile libraries to minimize end-user

compilation time

• annotate libraries to capture specialized knowledge of

library writers

• generate specialized variants based on interesting

contexts

• link appropriate versions into the user script

analogous to offline indexing by search engines

PhD Thesis Defense: Telescoping MATLAB for DSP Applications July 10, 2003

Page 28: Telescoping MATLAB for DSP Applicationsachauhan/Presentations/Thesis/defense.pdf · Telescoping MATLAB for DSP Applications PhD Thesis Defense ArunChauhan Computer Science, Rice University

Telescoping Languages Approach

• pre-compile libraries to minimize end-user

compilation time

• annotate libraries to capture specialized knowledge of

library writers

• generate specialized variants based on interesting

contexts

• link appropriate versions into the user script

analogous to offline indexing by search engines

PhD Thesis Defense: Telescoping MATLAB for DSP Applications July 10, 2003

Page 29: Telescoping MATLAB for DSP Applicationsachauhan/Presentations/Thesis/defense.pdf · Telescoping MATLAB for DSP Applications PhD Thesis Defense ArunChauhan Computer Science, Rice University

Telescoping Languages: Entities

library writer

library compiler

end user

script compiler

subroutine VMP (C, Z, ... , s)

“expect s to be mostly 1”

write libraries

write annotations

VMP step1 (C, Z, ... )specialize code

call VMP (C, Z, ... , 1)write script

call VMP step1 (C, Z, ... )choose optimized variant

PhD Thesis Defense: Telescoping MATLAB for DSP Applications July 10, 2003

Page 30: Telescoping MATLAB for DSP Applicationsachauhan/Presentations/Thesis/defense.pdf · Telescoping MATLAB for DSP Applications PhD Thesis Defense ArunChauhan Computer Science, Rice University

Telescoping Languages: Entities

library writer

library compiler

end user

script compiler

subroutine VMP (C, Z, ... , s)

“expect s to be mostly 1”

write libraries

write annotations

VMP step1 (C, Z, ... )specialize code

call VMP (C, Z, ... , 1)write script

call VMP step1 (C, Z, ... )choose optimized variant

PhD Thesis Defense: Telescoping MATLAB for DSP Applications July 10, 2003

Page 31: Telescoping MATLAB for DSP Applicationsachauhan/Presentations/Thesis/defense.pdf · Telescoping MATLAB for DSP Applications PhD Thesis Defense ArunChauhan Computer Science, Rice University

Telescoping Languages: Entities

library writer

library compiler

end user

script compiler

subroutine VMP (C, Z, ... , s)

“expect s to be mostly 1”

write libraries

write annotations

VMP step1 (C, Z, ... )specialize code

call VMP (C, Z, ... , 1)write script

call VMP step1 (C, Z, ... )choose optimized variant

PhD Thesis Defense: Telescoping MATLAB for DSP Applications July 10, 2003

Page 32: Telescoping MATLAB for DSP Applicationsachauhan/Presentations/Thesis/defense.pdf · Telescoping MATLAB for DSP Applications PhD Thesis Defense ArunChauhan Computer Science, Rice University

Telescoping Languages: Entities

library writer

library compiler

end user

script compiler

subroutine VMP (C, Z, ... , s)

“expect s to be mostly 1”

write libraries

write annotations

VMP step1 (C, Z, ... )specialize code

call VMP (C, Z, ... , 1)write script

call VMP step1 (C, Z, ... )choose optimized variant

PhD Thesis Defense: Telescoping MATLAB for DSP Applications July 10, 2003

Page 33: Telescoping MATLAB for DSP Applicationsachauhan/Presentations/Thesis/defense.pdf · Telescoping MATLAB for DSP Applications PhD Thesis Defense ArunChauhan Computer Science, Rice University

Telescoping Languages: Entities

library writer

library compiler

end user

script compiler

subroutine VMP (C, Z, ... , s)

“expect s to be mostly 1”

write libraries

write annotations

VMP step1 (C, Z, ... )specialize code

call VMP (C, Z, ... , 1)write script

call VMP step1 (C, Z, ... )choose optimized variant

PhD Thesis Defense: Telescoping MATLAB for DSP Applications July 10, 2003

Page 34: Telescoping MATLAB for DSP Applicationsachauhan/Presentations/Thesis/defense.pdf · Telescoping MATLAB for DSP Applications PhD Thesis Defense ArunChauhan Computer Science, Rice University

Telescoping Languages Approach

domain

library

language

building

compiler

scriptscript

translator

enhanced

language

compiler

optimized

object

program

PhD Thesis Defense: Telescoping MATLAB for DSP Applications July 10, 2003

Page 35: Telescoping MATLAB for DSP Applicationsachauhan/Presentations/Thesis/defense.pdf · Telescoping MATLAB for DSP Applications PhD Thesis Defense ArunChauhan Computer Science, Rice University

Challenges

• identifying specialization opportunities

- which kinds of specializations

- how many

• identifying high pay-off optimizations

- must be applicable in telescoping languages context

- should focus on these first

• enabling the library writer to express these

transformations

- guide the specialization

PhD Thesis Defense: Telescoping MATLAB for DSP Applications July 10, 2003

Page 36: Telescoping MATLAB for DSP Applicationsachauhan/Presentations/Thesis/defense.pdf · Telescoping MATLAB for DSP Applications PhD Thesis Defense ArunChauhan Computer Science, Rice University

Challenges

• identifying specialization opportunities

- which kinds of specializations

- how many

• identifying high pay-off optimizations

- must be applicable in telescoping languages context

- should focus on these first

• enabling the library writer to express these

transformations

- guide the specialization

PhD Thesis Defense: Telescoping MATLAB for DSP Applications July 10, 2003

Page 37: Telescoping MATLAB for DSP Applicationsachauhan/Presentations/Thesis/defense.pdf · Telescoping MATLAB for DSP Applications PhD Thesis Defense ArunChauhan Computer Science, Rice University

Challenges

• identifying specialization opportunities

- which kinds of specializations

- how many

• identifying high pay-off optimizations

- must be applicable in telescoping languages context

- should focus on these first

• enabling the library writer to express these

transformations

- guide the specialization

PhD Thesis Defense: Telescoping MATLAB for DSP Applications July 10, 2003

Page 38: Telescoping MATLAB for DSP Applicationsachauhan/Presentations/Thesis/defense.pdf · Telescoping MATLAB for DSP Applications PhD Thesis Defense ArunChauhan Computer Science, Rice University

Challenges

• identifying specialization opportunities

- which kinds of specializations

- how many

• identifying high pay-off optimizations

- must be applicable in telescoping languages context

- should focus on these first

• enabling the library writer to express these

transformations

- guide the specialization

PhD Thesis Defense: Telescoping MATLAB for DSP Applications July 10, 2003

Page 39: Telescoping MATLAB for DSP Applicationsachauhan/Presentations/Thesis/defense.pdf · Telescoping MATLAB for DSP Applications PhD Thesis Defense ArunChauhan Computer Science, Rice University

Developing the Compiler

MATLABlibrary

compiler

C / FORTRAN(multiple variants)

• compile MATLAB

• emit specialized output code

• implement identified high-payoff optimizations

• implement newly discovered optimizations

PhD Thesis Defense: Telescoping MATLAB for DSP Applications July 10, 2003

Page 40: Telescoping MATLAB for DSP Applicationsachauhan/Presentations/Thesis/defense.pdf · Telescoping MATLAB for DSP Applications PhD Thesis Defense ArunChauhan Computer Science, Rice University

Developing the Compiler

MATLABlibrary

compilerC / FORTRAN(multiple variants)

• compile MATLAB

• emit specialized output code

• implement identified high-payoff optimizations

• implement newly discovered optimizations

PhD Thesis Defense: Telescoping MATLAB for DSP Applications July 10, 2003

Page 41: Telescoping MATLAB for DSP Applicationsachauhan/Presentations/Thesis/defense.pdf · Telescoping MATLAB for DSP Applications PhD Thesis Defense ArunChauhan Computer Science, Rice University

Example Compilation

function mcc demo

x = 1;

y = x / 10;

z = x * 20;

r = y + z;

PhD Thesis Defense: Telescoping MATLAB for DSP Applications July 10, 2003

Page 42: Telescoping MATLAB for DSP Applicationsachauhan/Presentations/Thesis/defense.pdf · Telescoping MATLAB for DSP Applications PhD Thesis Defense ArunChauhan Computer Science, Rice University

Example Compilation

static void Mmcc demo (void) {

. . .

mxArray * r = NULL;

mxArray * z = NULL;

mxArray * y = NULL;

mxArray * x = NULL;

mlfAssign(&x, mxarray0 ); /* x = 1; */

mlfAssign(&y, mclMrdivide(mclVv(x, ”x”), mxarray1 )); /* y = x / 10; */

mlfAssign(&z, mclMtimes(mclVv(x, ”x”), mxarray2 )); /* z = x * 20; */

mlfAssign(&r, mclPlus(mclVv(y, ”y”), mclVv(z, ”z”))); /* r = y + z; */

mxDestroyArray(x);

mxDestroyArray(y);

mxDestroyArray(z);

mxDestroyArray(r);

. . .

}

PhD Thesis Defense: Telescoping MATLAB for DSP Applications July 10, 2003

Page 43: Telescoping MATLAB for DSP Applicationsachauhan/Presentations/Thesis/defense.pdf · Telescoping MATLAB for DSP Applications PhD Thesis Defense ArunChauhan Computer Science, Rice University

Example Compilation

static void Mmcc demo (void) {

. . .

double r;

double z;

double y;

double z;

mlfAssign(&x, mxarray0 ); /* x = 1; */

mlfAssign(&y, mclMrdivide(mclVv(x, ”x”), mxarray1 )); /* y = x / 10; */

mlfAssign(&z, mclMtimes(mclVv(x, ”x”), mxarray2 )); /* z = x * 20; */

mlfAssign(&r, mclPlus(mclVv(y, ”y”), mclVv(z, ”z”))); /* r = y + z; */

mxDestroyArray(x);

mxDestroyArray(y);

mxDestroyArray(z);

mxDestroyArray(r);

. . .

}

PhD Thesis Defense: Telescoping MATLAB for DSP Applications July 10, 2003

Page 44: Telescoping MATLAB for DSP Applicationsachauhan/Presentations/Thesis/defense.pdf · Telescoping MATLAB for DSP Applications PhD Thesis Defense ArunChauhan Computer Science, Rice University

Example Compilation

static void Mmcc demo (void) {

. . .

double r;

double z;

double y;

double z;

scalarAssign(&x, 1); /* x = 1; */

scalarAssign(&y, scalarDivide(x, 10)); /* y = x / 10; */

scalarAssign(&z, scalarTimes(x, 20)); /* z = x * 20; */

scalarAssign(&r, scalarPlus(y, z)); /* r = y + z; */

mxDestroyArray(x);

mxDestroyArray(y);

mxDestroyArray(z);

mxDestroyArray(r);

. . .

}

PhD Thesis Defense: Telescoping MATLAB for DSP Applications July 10, 2003

Page 45: Telescoping MATLAB for DSP Applicationsachauhan/Presentations/Thesis/defense.pdf · Telescoping MATLAB for DSP Applications PhD Thesis Defense ArunChauhan Computer Science, Rice University

Example Compilation

static void Mmcc demo (void) {

. . .

double r;

double z;

double y;

double z;

x = 1; /* x = 1; */

y = x / 10; /* y = x / 10; */

z = x * 20; /* z = x * 20; */

r = y + z; /* r = y + z; */

/* mxDestroyArray(x); */

/* mxDestroyArray(y); */

/* mxDestroyArray(z); */

/* mxDestroyArray(r); */

. . .

}

PhD Thesis Defense: Telescoping MATLAB for DSP Applications July 10, 2003

Page 46: Telescoping MATLAB for DSP Applicationsachauhan/Presentations/Thesis/defense.pdf · Telescoping MATLAB for DSP Applications PhD Thesis Defense ArunChauhan Computer Science, Rice University

Inferring Types(Joint work with Cheryl McCosh)

• type ≡ <τ , δ, σ, ψ>

- τ = intrinsic type, e.g., int, real, complex, etc.

- δ = array dimensionality, 0 for scalars

- σ = δ-tuple of positive integers

- ψ = “structure” of an array

• type inference in general

- type = “smallest” set of values that preserves meaning

PhD Thesis Defense: Telescoping MATLAB for DSP Applications July 10, 2003

Page 47: Telescoping MATLAB for DSP Applicationsachauhan/Presentations/Thesis/defense.pdf · Telescoping MATLAB for DSP Applications PhD Thesis Defense ArunChauhan Computer Science, Rice University

Inferring Types(Joint work with Cheryl McCosh)

• type ≡ <τ , δ, σ, ψ>

- τ = intrinsic type, e.g., int, real, complex, etc.

- δ = array dimensionality, 0 for scalars

- σ = δ-tuple of positive integers

- ψ = “structure” of an array

• type inference in general

- type = “smallest” set of values that preserves meaning

PhD Thesis Defense: Telescoping MATLAB for DSP Applications July 10, 2003

Page 48: Telescoping MATLAB for DSP Applicationsachauhan/Presentations/Thesis/defense.pdf · Telescoping MATLAB for DSP Applications PhD Thesis Defense ArunChauhan Computer Science, Rice University

Inferring Types(Joint work with Cheryl McCosh)

• type ≡ <τ , δ, σ, ψ>

- τ = intrinsic type, e.g., int, real, complex, etc.

- δ = array dimensionality, 0 for scalars

- σ = δ-tuple of positive integers

- ψ = “structure” of an array

• type inference in general

- type = “smallest” set of values that preserves meaning

PhD Thesis Defense: Telescoping MATLAB for DSP Applications July 10, 2003

Page 49: Telescoping MATLAB for DSP Applicationsachauhan/Presentations/Thesis/defense.pdf · Telescoping MATLAB for DSP Applications PhD Thesis Defense ArunChauhan Computer Science, Rice University

Static Type Inference(Appears in McCosh’s Masters’ Thesis)

• dimensionality constraints

x = 1

LHS dims = RHS dims

y = x / 10

(x, y scalar) OR (x, y arrays of same size)

z = x * 20

(x, z scalar) OR (x, z arrays of same size)

r = y + z

(r, y, z scalar) OR (r, y, z arrays of same size)

PhD Thesis Defense: Telescoping MATLAB for DSP Applications July 10, 2003

Page 50: Telescoping MATLAB for DSP Applicationsachauhan/Presentations/Thesis/defense.pdf · Telescoping MATLAB for DSP Applications PhD Thesis Defense ArunChauhan Computer Science, Rice University

Static Type Inference(Appears in McCosh’s Masters’ Thesis)

• dimensionality constraints

x = 1 LHS dims = RHS dims

y = x / 10

(x, y scalar) OR (x, y arrays of same size)

z = x * 20

(x, z scalar) OR (x, z arrays of same size)

r = y + z

(r, y, z scalar) OR (r, y, z arrays of same size)

PhD Thesis Defense: Telescoping MATLAB for DSP Applications July 10, 2003

Page 51: Telescoping MATLAB for DSP Applicationsachauhan/Presentations/Thesis/defense.pdf · Telescoping MATLAB for DSP Applications PhD Thesis Defense ArunChauhan Computer Science, Rice University

Static Type Inference(Appears in McCosh’s Masters’ Thesis)

• dimensionality constraints

x = 1 LHS dims = RHS dims

y = x / 10 (x, y scalar) OR (x, y arrays of same size)

z = x * 20

(x, z scalar) OR (x, z arrays of same size)

r = y + z

(r, y, z scalar) OR (r, y, z arrays of same size)

PhD Thesis Defense: Telescoping MATLAB for DSP Applications July 10, 2003

Page 52: Telescoping MATLAB for DSP Applicationsachauhan/Presentations/Thesis/defense.pdf · Telescoping MATLAB for DSP Applications PhD Thesis Defense ArunChauhan Computer Science, Rice University

Static Type Inference(Appears in McCosh’s Masters’ Thesis)

• dimensionality constraints

x = 1 LHS dims = RHS dims

y = x / 10 (x, y scalar) OR (x, y arrays of same size)

z = x * 20 (x, z scalar) OR (x, z arrays of same size)

r = y + z

(r, y, z scalar) OR (r, y, z arrays of same size)

PhD Thesis Defense: Telescoping MATLAB for DSP Applications July 10, 2003

Page 53: Telescoping MATLAB for DSP Applicationsachauhan/Presentations/Thesis/defense.pdf · Telescoping MATLAB for DSP Applications PhD Thesis Defense ArunChauhan Computer Science, Rice University

Static Type Inference(Appears in McCosh’s Masters’ Thesis)

• dimensionality constraints

x = 1 LHS dims = RHS dims

y = x / 10 (x, y scalar) OR (x, y arrays of same size)

z = x * 20 (x, z scalar) OR (x, z arrays of same size)

r = y + z (r, y, z scalar) OR (r, y, z arrays of same size)

PhD Thesis Defense: Telescoping MATLAB for DSP Applications July 10, 2003

Page 54: Telescoping MATLAB for DSP Applicationsachauhan/Presentations/Thesis/defense.pdf · Telescoping MATLAB for DSP Applications PhD Thesis Defense ArunChauhan Computer Science, Rice University

Static Type Inference(Appears in McCosh’s Masters’ Thesis)

• write constraints

- each operation or function call imposes certain “constraints”

- incomparable types give rise to multiple valid configurations

• the problem is hard to solve in general

- efficient solution possible under certain conditions

• reducing to the clique problem

- a constraint defines a level

- clauses in a constraint are nodes at that level

- an edge whenever two clauses are “compatible”

- a clique defines a valid type configuration

PhD Thesis Defense: Telescoping MATLAB for DSP Applications July 10, 2003

Page 55: Telescoping MATLAB for DSP Applicationsachauhan/Presentations/Thesis/defense.pdf · Telescoping MATLAB for DSP Applications PhD Thesis Defense ArunChauhan Computer Science, Rice University

Static Type Inference(Appears in McCosh’s Masters’ Thesis)

• write constraints

- each operation or function call imposes certain “constraints”

- incomparable types give rise to multiple valid configurations

• the problem is hard to solve in general

- efficient solution possible under certain conditions

• reducing to the clique problem

- a constraint defines a level

- clauses in a constraint are nodes at that level

- an edge whenever two clauses are “compatible”

- a clique defines a valid type configuration

PhD Thesis Defense: Telescoping MATLAB for DSP Applications July 10, 2003

Page 56: Telescoping MATLAB for DSP Applicationsachauhan/Presentations/Thesis/defense.pdf · Telescoping MATLAB for DSP Applications PhD Thesis Defense ArunChauhan Computer Science, Rice University

Static Type Inference(Appears in McCosh’s Masters’ Thesis)

• write constraints

- each operation or function call imposes certain “constraints”

- incomparable types give rise to multiple valid configurations

• the problem is hard to solve in general

- efficient solution possible under certain conditions

• reducing to the clique problem

- a constraint defines a level

- clauses in a constraint are nodes at that level

- an edge whenever two clauses are “compatible”

- a clique defines a valid type configuration

PhD Thesis Defense: Telescoping MATLAB for DSP Applications July 10, 2003

Page 57: Telescoping MATLAB for DSP Applicationsachauhan/Presentations/Thesis/defense.pdf · Telescoping MATLAB for DSP Applications PhD Thesis Defense ArunChauhan Computer Science, Rice University

Limitations

• control join-points may result in too many configs

• array sizes defined by indexed expressions

- assignment to a(i) can resize a

• control join-points ignored for array-sizes

• symbolic expressions may be unknown at compile

time

• array sizes changing in a loop not handled

PhD Thesis Defense: Telescoping MATLAB for DSP Applications July 10, 2003

Page 58: Telescoping MATLAB for DSP Applicationsachauhan/Presentations/Thesis/defense.pdf · Telescoping MATLAB for DSP Applications PhD Thesis Defense ArunChauhan Computer Science, Rice University

Limitations

• control join-points may result in too many configs

• array sizes defined by indexed expressions

- assignment to a(i) can resize a

• control join-points ignored for array-sizes

• symbolic expressions may be unknown at compile

time

• array sizes changing in a loop not handled

PhD Thesis Defense: Telescoping MATLAB for DSP Applications July 10, 2003

Page 59: Telescoping MATLAB for DSP Applicationsachauhan/Presentations/Thesis/defense.pdf · Telescoping MATLAB for DSP Applications PhD Thesis Defense ArunChauhan Computer Science, Rice University

Size Grows in a Loop

function [A, F] = pisar (xt, sin num)

...

mcos = [];

for n = 1:sin num

vcos = [];

for i = 1:sin num

vcos = [vcos cos(n*w est(i))];

end

mcos = [mcos; vcos]

end

...

PhD Thesis Defense: Telescoping MATLAB for DSP Applications July 10, 2003

Page 60: Telescoping MATLAB for DSP Applicationsachauhan/Presentations/Thesis/defense.pdf · Telescoping MATLAB for DSP Applications PhD Thesis Defense ArunChauhan Computer Science, Rice University

Slice-hoisting: Simple Example

A

1

= zeros(1, N);

⇒σ1A1 = <N>

y

1

= ...

A

1

(y

1

) = ...

⇒σ2A1 = max(σ1

A1, <y1>)

x

1

= ...

A

1

(x

1

) = ...

⇒σ3A1 = max(σ2

A1, <x1>)

PhD Thesis Defense: Telescoping MATLAB for DSP Applications July 10, 2003

Page 61: Telescoping MATLAB for DSP Applicationsachauhan/Presentations/Thesis/defense.pdf · Telescoping MATLAB for DSP Applications PhD Thesis Defense ArunChauhan Computer Science, Rice University

Slice-hoisting: Simple Example

A

1

= zeros(1, N);

σ

1

A

1

= <N>

y

1

= ...

A

1

(y

1

) = ...

σ

2

A

1

= max(σ

1

A

1

, <y

1

>)

x

1

= ...

A

1

(x

1

) = ...

σ

3

A

1

= max(σ

2

A

1

, <x

1

>)

PhD Thesis Defense: Telescoping MATLAB for DSP Applications July 10, 2003

Page 62: Telescoping MATLAB for DSP Applicationsachauhan/Presentations/Thesis/defense.pdf · Telescoping MATLAB for DSP Applications PhD Thesis Defense ArunChauhan Computer Science, Rice University

Slice-hoisting: Simple Example

A1 = zeros(1, N);

σ1A1 = <N>

y1 = ...

A1(y1) = ...

σ2A1 = max(σ1

A1, <y1>)

x1 = ...

A1(x1) = ...

σ3A1 = max(σ2

A1, <x1>)

PhD Thesis Defense: Telescoping MATLAB for DSP Applications July 10, 2003

Page 63: Telescoping MATLAB for DSP Applicationsachauhan/Presentations/Thesis/defense.pdf · Telescoping MATLAB for DSP Applications PhD Thesis Defense ArunChauhan Computer Science, Rice University

Slice-hoisting: Simple Example

A1 = zeros(1, N);

⇒σ1A1 = <N>

⇒y1 = ...

A1(y1) = ...

⇒σ2A1 = max(σ1

A1, <y1>)

⇒x1 = ...

A1(x1) = ...

⇒σ3A1 = max(σ2

A1, <x1>)

PhD Thesis Defense: Telescoping MATLAB for DSP Applications July 10, 2003

Page 64: Telescoping MATLAB for DSP Applicationsachauhan/Presentations/Thesis/defense.pdf · Telescoping MATLAB for DSP Applications PhD Thesis Defense ArunChauhan Computer Science, Rice University

Slice-hoisting: Simple Example

⇒σ1A1 = <N>

⇒y1 = ...

⇒σ2A1 = max(σ1

A1, <y1>)

⇒x1 = ...

⇒σ3A1 = max(σ2

A1, <x1)

allocate(A1, σ3A1);

A1 = zeros(1, N);

A1(y1) = ...

A1(x1) = ...

PhD Thesis Defense: Telescoping MATLAB for DSP Applications July 10, 2003

Page 65: Telescoping MATLAB for DSP Applicationsachauhan/Presentations/Thesis/defense.pdf · Telescoping MATLAB for DSP Applications PhD Thesis Defense ArunChauhan Computer Science, Rice University

Slice-hoisting: Steps

• insert σ statements

• do SSA conversion

• identify the slice involved in computing the σ values

• hoist the slice before the first use of the array

PhD Thesis Defense: Telescoping MATLAB for DSP Applications July 10, 2003

Page 66: Telescoping MATLAB for DSP Applicationsachauhan/Presentations/Thesis/defense.pdf · Telescoping MATLAB for DSP Applications PhD Thesis Defense ArunChauhan Computer Science, Rice University

Slice-hoisting: Loop

A

1

(x

1

) = ...

⇒σ1A1 = <x1>

for i

1

= 1:N

...

⇒ σ2A1 = φ(σ1

A1, σ3A1)

A

1

= [A

1

f(i

1

)];

⇒ σ3A1 = σ2

A1 + <1>

end

• add σ statements

• do SSA

• identify slice

PhD Thesis Defense: Telescoping MATLAB for DSP Applications July 10, 2003

Page 67: Telescoping MATLAB for DSP Applicationsachauhan/Presentations/Thesis/defense.pdf · Telescoping MATLAB for DSP Applications PhD Thesis Defense ArunChauhan Computer Science, Rice University

Slice-hoisting: Loop

A

1

(x

1

) = ...

σ

1

A

1

= <x

1

>

for i

1

= 1:N

...

⇒ σ2A1 = φ(σ1

A1, σ3A1)

A

1

= [A

1

f(i

1

)];

σ

3

A

1

= σ

2

A

1

+ <1>

end

• add σ statements

• do SSA

• identify slice

PhD Thesis Defense: Telescoping MATLAB for DSP Applications July 10, 2003

Page 68: Telescoping MATLAB for DSP Applicationsachauhan/Presentations/Thesis/defense.pdf · Telescoping MATLAB for DSP Applications PhD Thesis Defense ArunChauhan Computer Science, Rice University

Slice-hoisting: Loop

A1(x1) = ...

σ1A1 = <x1>

for i1 = 1:N

...

σ2A1 = φ(σ1

A1, σ3A1)

A1 = [A1 f(i1)];

σ3A1 = σ2

A1 + <1>

end

• add σ statements

• do SSA

• identify slice

PhD Thesis Defense: Telescoping MATLAB for DSP Applications July 10, 2003

Page 69: Telescoping MATLAB for DSP Applicationsachauhan/Presentations/Thesis/defense.pdf · Telescoping MATLAB for DSP Applications PhD Thesis Defense ArunChauhan Computer Science, Rice University

Slice-hoisting: Loop

A1(x1) = ...

⇒σ1A1 = <x1>

⇒for i1 = 1:N

...

⇒ σ2A1 = φ(σ1

A1, σ3A1)

A1 = [A1 f(i1)];

⇒ σ3A1 = σ2

A1 + <1>

⇒end

• add σ statements

• do SSA

• identify slice

PhD Thesis Defense: Telescoping MATLAB for DSP Applications July 10, 2003

Page 70: Telescoping MATLAB for DSP Applicationsachauhan/Presentations/Thesis/defense.pdf · Telescoping MATLAB for DSP Applications PhD Thesis Defense ArunChauhan Computer Science, Rice University

Slice-hoisting: Loop

⇒σ1A1 = <x1>

⇒for i1 = 1:N

⇒ σ2A1 = φ(σ1

A1, σ3A1)

⇒ σ3A1 = σ2

A1 + <1>

⇒end

allocate(A1, σ3A1);

A1(x1) = ...

for i1 = 1:N

...

A1 = [A1 f(i1)];

end

• add σ statements

• do SSA

• identify slice

• hoist the slice

PhD Thesis Defense: Telescoping MATLAB for DSP Applications July 10, 2003

Page 71: Telescoping MATLAB for DSP Applicationsachauhan/Presentations/Thesis/defense.pdf · Telescoping MATLAB for DSP Applications PhD Thesis Defense ArunChauhan Computer Science, Rice University

Type-based Specialization

Sun SPARC 336MHz SGI Origin Apple PowerBook G4 667MHz

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

time

(sec

onds

)

jakes: Type−specialized FORTRAN vs MATLABMATLAB 6.xMATLAB 5.3FORTRAN

PhD Thesis Defense: Telescoping MATLAB for DSP Applications July 10, 2003

Page 72: Telescoping MATLAB for DSP Applicationsachauhan/Presentations/Thesis/defense.pdf · Telescoping MATLAB for DSP Applications PhD Thesis Defense ArunChauhan Computer Science, Rice University

Precision of Static Inference

acf art. Q ffth fourier by jump huffcode0

20

40

60

80

100

120

140

160

180

200

220

240

num

ber

of c

onfig

swithout annotationswith annotations

PhD Thesis Defense: Telescoping MATLAB for DSP Applications July 10, 2003

Page 73: Telescoping MATLAB for DSP Applicationsachauhan/Presentations/Thesis/defense.pdf · Telescoping MATLAB for DSP Applications PhD Thesis Defense ArunChauhan Computer Science, Rice University

Inference Mechanisms

acf art. Q ffth fourier by jump huffcode0

10

20

30

40

50

60

70

80

90

100

110

120

perc

ent o

f tot

al v

aria

bles

statically inferredinferred by slice−hoistingexternally specified args

PhD Thesis Defense: Telescoping MATLAB for DSP Applications July 10, 2003

Page 74: Telescoping MATLAB for DSP Applicationsachauhan/Presentations/Thesis/defense.pdf · Telescoping MATLAB for DSP Applications PhD Thesis Defense ArunChauhan Computer Science, Rice University

Relevant Optimizations

“It is a capital mistake to theorize before one has data.

Insensibly one begins to twist facts to suit theories, in-

stead of theories to suit facts.”

–Sir Arthur Conon Doyle in a A Scandal in Bohemia

PhD Thesis Defense: Telescoping MATLAB for DSP Applications July 10, 2003

Page 75: Telescoping MATLAB for DSP Applicationsachauhan/Presentations/Thesis/defense.pdf · Telescoping MATLAB for DSP Applications PhD Thesis Defense ArunChauhan Computer Science, Rice University

Identifying and Discovering

• study of DSP applications

- real life code from the ECE department

• identified high-payoff well-known optimization

techniques

• discovered two novel optimizations

- procedure strength reduction

- procedure vectorization

PhD Thesis Defense: Telescoping MATLAB for DSP Applications July 10, 2003

Page 76: Telescoping MATLAB for DSP Applicationsachauhan/Presentations/Thesis/defense.pdf · Telescoping MATLAB for DSP Applications PhD Thesis Defense ArunChauhan Computer Science, Rice University

High-payoff Optimizations

• vectorization

- 33 times speedup in one case!

• common subexpression elimination

• beating and dragging along

• constant propagation

• library identities

- single call replaces a sequence

• value of library annotations

PhD Thesis Defense: Telescoping MATLAB for DSP Applications July 10, 2003

Page 77: Telescoping MATLAB for DSP Applicationsachauhan/Presentations/Thesis/defense.pdf · Telescoping MATLAB for DSP Applications PhD Thesis Defense ArunChauhan Computer Science, Rice University

High-payoff Optimizations

• vectorization

- 33 times speedup in one case!

• common subexpression elimination

• beating and dragging along

• constant propagation

• library identities

- single call replaces a sequence

• value of library annotations

PhD Thesis Defense: Telescoping MATLAB for DSP Applications July 10, 2003

Page 78: Telescoping MATLAB for DSP Applicationsachauhan/Presentations/Thesis/defense.pdf · Telescoping MATLAB for DSP Applications PhD Thesis Defense ArunChauhan Computer Science, Rice University

Procedure Strength Reduction

for i = 1:N

. . .

f (c1, c2, i, c3);

. . .

end

f init (c1, c2, c3);

for i = 1:N

. . .

f iter (i);

. . .

end

PhD Thesis Defense: Telescoping MATLAB for DSP Applications July 10, 2003

Page 79: Telescoping MATLAB for DSP Applicationsachauhan/Presentations/Thesis/defense.pdf · Telescoping MATLAB for DSP Applications PhD Thesis Defense ArunChauhan Computer Science, Rice University

Procedure Strength Reduction

for i = 1:N

. . .

f (c1, c2, i, c3);

. . .

end

f init (c1, c2, c3);

for i = 1:N

. . .

f iter (i);

. . .

end

PhD Thesis Defense: Telescoping MATLAB for DSP Applications July 10, 2003

Page 80: Telescoping MATLAB for DSP Applicationsachauhan/Presentations/Thesis/defense.pdf · Telescoping MATLAB for DSP Applications PhD Thesis Defense ArunChauhan Computer Science, Rice University

Procedure Strength Reduction

for i = 1:N

. . .

f (c1, c2, i, c3);

. . .

end

f init (c1, c2, c3);

for i = 1:N

. . .

f iter (i);

. . .

end

PhD Thesis Defense: Telescoping MATLAB for DSP Applications July 10, 2003

Page 81: Telescoping MATLAB for DSP Applicationsachauhan/Presentations/Thesis/defense.pdf · Telescoping MATLAB for DSP Applications PhD Thesis Defense ArunChauhan Computer Science, Rice University

Applying to ctss

jakes_mp1 newcodesig codesdhd whole program0

0.5

1

1.5

2

2.5

3

3.5

spee

dup

speedups for top−level procedures in ctss relative to unoptimized

0 5 10 15 20 25

original

optimized

total time (in thousands of seconds)

distribution of the total execution time among top−level procedures in ctss

jakes_mp1newcodesigcodesdhd

PhD Thesis Defense: Telescoping MATLAB for DSP Applications July 10, 2003

Page 82: Telescoping MATLAB for DSP Applicationsachauhan/Presentations/Thesis/defense.pdf · Telescoping MATLAB for DSP Applications PhD Thesis Defense ArunChauhan Computer Science, Rice University

Applying to sML chan est

original (per iteration) init call init (with preallocation) iterative call0

2

4

6

8

10

12

14

exec

utio

n tim

e (s

econ

ds)

PhD Thesis Defense: Telescoping MATLAB for DSP Applications July 10, 2003

Page 83: Telescoping MATLAB for DSP Applicationsachauhan/Presentations/Thesis/defense.pdf · Telescoping MATLAB for DSP Applications PhD Thesis Defense ArunChauhan Computer Science, Rice University

Effect of mcc Compilation

interpreted compiled stand−alone0

50

100

150

200

250

300

350

400

450

exec

utio

n tim

e (s

econ

ds)

originaloptimized

PhD Thesis Defense: Telescoping MATLAB for DSP Applications July 10, 2003

Page 84: Telescoping MATLAB for DSP Applicationsachauhan/Presentations/Thesis/defense.pdf · Telescoping MATLAB for DSP Applications PhD Thesis Defense ArunChauhan Computer Science, Rice University

More on Strength Reduction

• procedure strength reduction somewhat different

from operator strength reduction

- could be similar if the iter component provided

• automatic differentiation is a more powerful approach

that matches procedure strength reduction

- more work needed to utilize automatic diff. for optimizing

loops

PhD Thesis Defense: Telescoping MATLAB for DSP Applications July 10, 2003

Page 85: Telescoping MATLAB for DSP Applicationsachauhan/Presentations/Thesis/defense.pdf · Telescoping MATLAB for DSP Applications PhD Thesis Defense ArunChauhan Computer Science, Rice University

Procedure Vectorization

for i = 1:N

f (c1, c2, i, A[i]);

end

. . .

function f (a1, a2, a3, a4)

<body of f >

f vect (c1, c2, [1:N], A)

. . .

function f vect (a1, a2, a3, a4)

for i = 1:N

<body of f >

end

PhD Thesis Defense: Telescoping MATLAB for DSP Applications July 10, 2003

Page 86: Telescoping MATLAB for DSP Applicationsachauhan/Presentations/Thesis/defense.pdf · Telescoping MATLAB for DSP Applications PhD Thesis Defense ArunChauhan Computer Science, Rice University

Procedure Vectorization

for i = 1:N

f (c1, c2, i, A[i]);

end

. . .

function f (a1, a2, a3, a4)

<body of f >

f vect (c1, c2, [1:N], A)

. . .

function f vect (a1, a2, a3, a4)

for i = 1:N

<body of f >

end

PhD Thesis Defense: Telescoping MATLAB for DSP Applications July 10, 2003

Page 87: Telescoping MATLAB for DSP Applicationsachauhan/Presentations/Thesis/defense.pdf · Telescoping MATLAB for DSP Applications PhD Thesis Defense ArunChauhan Computer Science, Rice University

Procedure Vectorization

for i = 1:N

f (c1, c2, i, A[i]);

end

. . .

function f (a1, a2, a3, a4)

<body of f >

f vect (c1, c2, [1:N], A)

. . .

function f vect (a1, a2, a3, a4)

for i = 1:N

<body of f >

end

PhD Thesis Defense: Telescoping MATLAB for DSP Applications July 10, 2003

Page 88: Telescoping MATLAB for DSP Applicationsachauhan/Presentations/Thesis/defense.pdf · Telescoping MATLAB for DSP Applications PhD Thesis Defense ArunChauhan Computer Science, Rice University

Applying to jakes

0

0.2

0.4

0.6

0.8

1

1.2

1.4

1.6

1.8

2

spee

dup

(for

100

iter

atio

ns)

normalized originaloptimized

PhD Thesis Defense: Telescoping MATLAB for DSP Applications July 10, 2003

Page 89: Telescoping MATLAB for DSP Applicationsachauhan/Presentations/Thesis/defense.pdf · Telescoping MATLAB for DSP Applications PhD Thesis Defense ArunChauhan Computer Science, Rice University

Overall Architecture

Parser

and

Front-

End

Type

Infer.

Engine

Spl’n

Engine

Code

Gen.

Annot.

Lib.

Opt. Specs

C

PhD Thesis Defense: Telescoping MATLAB for DSP Applications July 10, 2003

Page 90: Telescoping MATLAB for DSP Applicationsachauhan/Presentations/Thesis/defense.pdf · Telescoping MATLAB for DSP Applications PhD Thesis Defense ArunChauhan Computer Science, Rice University

Contributions

• validation of the telescoping languages strategy

- the library compiler component

• type-based specialization

- NP-completeness of type-inference for straight line code

- a new way to infer types

- slice-hoisting as a new approach to do dynamic size-inference

• identification of relevant optimizations

• discovery of two new optimizations

- procedure strength reduction and procedure vectorization

• infrastructure development

- a novel compiler architecture

PhD Thesis Defense: Telescoping MATLAB for DSP Applications July 10, 2003

Page 91: Telescoping MATLAB for DSP Applicationsachauhan/Presentations/Thesis/defense.pdf · Telescoping MATLAB for DSP Applications PhD Thesis Defense ArunChauhan Computer Science, Rice University

Contributions• validation of the telescoping languages strategy

- the library compiler component

• type-based specialization

- NP-completeness of type-inference for straight line code

- a new way to infer types

- slice-hoisting as a new approach to do dynamic size-inference

• identification of relevant optimizations

• discovery of two new optimizations

- procedure strength reduction and procedure vectorization

• infrastructure development

- a novel compiler architecture

PhD Thesis Defense: Telescoping MATLAB for DSP Applications July 10, 2003

Page 92: Telescoping MATLAB for DSP Applicationsachauhan/Presentations/Thesis/defense.pdf · Telescoping MATLAB for DSP Applications PhD Thesis Defense ArunChauhan Computer Science, Rice University

Contributions• validation of the telescoping languages strategy

- the library compiler component

• type-based specialization

- NP-completeness of type-inference for straight line code

- a new way to infer types

- slice-hoisting as a new approach to do dynamic size-inference

• identification of relevant optimizations

• discovery of two new optimizations

- procedure strength reduction and procedure vectorization

• infrastructure development

- a novel compiler architecture

PhD Thesis Defense: Telescoping MATLAB for DSP Applications July 10, 2003

Page 93: Telescoping MATLAB for DSP Applicationsachauhan/Presentations/Thesis/defense.pdf · Telescoping MATLAB for DSP Applications PhD Thesis Defense ArunChauhan Computer Science, Rice University

Contributions• validation of the telescoping languages strategy

- the library compiler component

• type-based specialization

- NP-completeness of type-inference for straight line code

- a new way to infer types

- slice-hoisting as a new approach to do dynamic size-inference

• identification of relevant optimizations

• discovery of two new optimizations

- procedure strength reduction and procedure vectorization

• infrastructure development

- a novel compiler architecture

PhD Thesis Defense: Telescoping MATLAB for DSP Applications July 10, 2003

Page 94: Telescoping MATLAB for DSP Applicationsachauhan/Presentations/Thesis/defense.pdf · Telescoping MATLAB for DSP Applications PhD Thesis Defense ArunChauhan Computer Science, Rice University

Contributions• validation of the telescoping languages strategy

- the library compiler component

• type-based specialization

- NP-completeness of type-inference for straight line code

- a new way to infer types

- slice-hoisting as a new approach to do dynamic size-inference

• identification of relevant optimizations

• discovery of two new optimizations

- procedure strength reduction and procedure vectorization

• infrastructure development

- a novel compiler architecture

PhD Thesis Defense: Telescoping MATLAB for DSP Applications July 10, 2003

Page 95: Telescoping MATLAB for DSP Applicationsachauhan/Presentations/Thesis/defense.pdf · Telescoping MATLAB for DSP Applications PhD Thesis Defense ArunChauhan Computer Science, Rice University

Contributions• validation of the telescoping languages strategy

- the library compiler component

• type-based specialization

- NP-completeness of type-inference for straight line code

- a new way to infer types

- slice-hoisting as a new approach to do dynamic size-inference

• identification of relevant optimizations

• discovery of two new optimizations

- procedure strength reduction and procedure vectorization

• infrastructure development

- a novel compiler architecture

PhD Thesis Defense: Telescoping MATLAB for DSP Applications July 10, 2003

Page 96: Telescoping MATLAB for DSP Applicationsachauhan/Presentations/Thesis/defense.pdf · Telescoping MATLAB for DSP Applications PhD Thesis Defense ArunChauhan Computer Science, Rice University

Contributions: Publications• Arun Chauhan and Ken Kennedy. Procedure strength reduction and

procedure vectorization: Optimization strategies for telescoping languages.

In Proceedings of ACM-SIGARCH International Conference on

Supercomputing, June 2001. Also available as Reducing and vectorizing

procedures for telescoping languages. International Journal of Parallel

Programming, 30(4):289–313, August 2002.

• Arun Chauhan, Cheryl McCosh, Ken Kennedy, and Richard Hanson.

Automatic type-driven library generation for telescoping languages. To

appear in the Proceedings of SC: High Performance Networking and

Computing Conference, 2003.

• Arun Chauhan and Ken Kennedy. Slice-hoisting for dynamic size-inference

in MATLAB. In writing.

• Cheryl McCosh, Arun Chauhan, and Ken Kennedy. Computing type

jump-functions for MATLAB libraries. In writing.

PhD Thesis Defense: Telescoping MATLAB for DSP Applications July 10, 2003

Page 97: Telescoping MATLAB for DSP Applicationsachauhan/Presentations/Thesis/defense.pdf · Telescoping MATLAB for DSP Applications PhD Thesis Defense ArunChauhan Computer Science, Rice University

Future Directions

• high-level reasoning

• time-bound compilation and AI techniques

• dynamic compilation and the grid

• automatic parallelization

• automatic differentiation

• other domains

PhD Thesis Defense: Telescoping MATLAB for DSP Applications July 10, 2003