the numerical template toolbox or why i stopped worrying...

29
Introduction What’s NT2 Conclusion The Numerical Template Toolbox or Why I Stopped Worrying & Loved Boost::Proto Joel Falcou LRI, Equipe PARALL - Université Paris Sud XI 19 Fev. 2010 1 / 16 The Numerical Template Toolbox, or Why I Stopped Worrying & Loved Boost::Proto

Upload: others

Post on 07-Aug-2020

4 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: The Numerical Template Toolbox or Why I Stopped Worrying ...downloads.tuxfamily.org/eigen/meetings/paris2010/Joel-nt2.pdf · Use modern C++ idioms Expression Templates Policy based

Introduction What’s NT2 Conclusion

The Numerical Template Toolboxor Why I Stopped Worrying & Loved Boost::Proto

Joel Falcou

LRI, Equipe PARALL - Université Paris Sud XI

19 Fev. 2010

1 / 16The Numerical Template Toolbox, or Why I Stopped Worrying & Loved Boost::Proto

Page 2: The Numerical Template Toolbox or Why I Stopped Worrying ...downloads.tuxfamily.org/eigen/meetings/paris2010/Joel-nt2.pdf · Use modern C++ idioms Expression Templates Policy based

Introduction What’s NT2 Conclusion

Context

In Scientific Computing ...

there is Scientific ..

Applications are domain drivenUsers are often programming-agnosticHuge base of legacy code in fancy languages

and there is Computing ...

Often implies performances ...... which implies architectures support.. which require expertise

The ProblemPeople using computer to do science want to do science first and don’t careabout the needed nuts and bolts and often don’t understand them at all...

2 / 16The Numerical Template Toolbox, or Why I Stopped Worrying & Loved Boost::Proto

Page 3: The Numerical Template Toolbox or Why I Stopped Worrying ...downloads.tuxfamily.org/eigen/meetings/paris2010/Joel-nt2.pdf · Use modern C++ idioms Expression Templates Policy based

Introduction What’s NT2 Conclusion

Context

In Scientific Computing ...

there is Scientific ..

Applications are domain drivenUsers are often programming-agnosticHuge base of legacy code in fancy languages

and there is Computing ...

Often implies performances ...... which implies architectures support.. which require expertise

The ProblemPeople using computer to do science want to do science first and don’t careabout the needed nuts and bolts and often don’t understand them at all...

2 / 16The Numerical Template Toolbox, or Why I Stopped Worrying & Loved Boost::Proto

Page 4: The Numerical Template Toolbox or Why I Stopped Worrying ...downloads.tuxfamily.org/eigen/meetings/paris2010/Joel-nt2.pdf · Use modern C++ idioms Expression Templates Policy based

Introduction What’s NT2 Conclusion

Context

In Scientific Computing ...

there is Scientific ..

Applications are domain drivenUsers are often programming-agnosticHuge base of legacy code in fancy languages

and there is Computing ...

Often implies performances ...... which implies architectures support.. which require expertise

The ProblemPeople using computer to do science want to do science first and don’t careabout the needed nuts and bolts and often don’t understand them at all...

2 / 16The Numerical Template Toolbox, or Why I Stopped Worrying & Loved Boost::Proto

Page 5: The Numerical Template Toolbox or Why I Stopped Worrying ...downloads.tuxfamily.org/eigen/meetings/paris2010/Joel-nt2.pdf · Use modern C++ idioms Expression Templates Policy based

Introduction What’s NT2 Conclusion

Context

In Scientific Computing ...

there is Scientific ..

Applications are domain drivenUsers are often programming-agnosticHuge base of legacy code in fancy languages

and there is Computing ...

Often implies performances ...... which implies architectures support.. which require expertise

The ProblemPeople using computer to do science want to do science first and don’t careabout the needed nuts and bolts and often don’t understand them at all...

2 / 16The Numerical Template Toolbox, or Why I Stopped Worrying & Loved Boost::Proto

Page 6: The Numerical Template Toolbox or Why I Stopped Worrying ...downloads.tuxfamily.org/eigen/meetings/paris2010/Joel-nt2.pdf · Use modern C++ idioms Expression Templates Policy based

Introduction What’s NT2 Conclusion

Context

In Scientific Computing ...

there is Scientific ..

Applications are domain drivenUsers are often programming-agnosticHuge base of legacy code in fancy languages

and there is Computing ...

Often implies performances ...... which implies architectures support.. which require expertise

The ProblemPeople using computer to do science want to do science first and don’t careabout the needed nuts and bolts and often don’t understand them at all...

2 / 16The Numerical Template Toolbox, or Why I Stopped Worrying & Loved Boost::Proto

Page 7: The Numerical Template Toolbox or Why I Stopped Worrying ...downloads.tuxfamily.org/eigen/meetings/paris2010/Joel-nt2.pdf · Use modern C++ idioms Expression Templates Policy based

Introduction What’s NT2 Conclusion

Fauna and Flora in S.C.

Efficacité

Expressivité

MatlabSciLab

C++JAVA

C, FORTRAN

3 / 16The Numerical Template Toolbox, or Why I Stopped Worrying & Loved Boost::Proto

Page 8: The Numerical Template Toolbox or Why I Stopped Worrying ...downloads.tuxfamily.org/eigen/meetings/paris2010/Joel-nt2.pdf · Use modern C++ idioms Expression Templates Policy based

Introduction What’s NT2 Conclusion

What do we want to do ?

TechniquesUse modern C++ idioms

Expression Templates

Policy based classes

Meta-programming

Goals

Hides all complex C++ construct away

Provide a ”familliar” interface to users

Let ”Power-users” be able to fine tunes

4 / 16The Numerical Template Toolbox, or Why I Stopped Worrying & Loved Boost::Proto

Page 9: The Numerical Template Toolbox or Why I Stopped Worrying ...downloads.tuxfamily.org/eigen/meetings/paris2010/Joel-nt2.pdf · Use modern C++ idioms Expression Templates Policy based

Introduction What’s NT2 Conclusion

What do we want to do ?

TechniquesUse modern C++ idioms

Expression Templates

Policy based classes

Meta-programming

Goals

Hides all complex C++ construct away

Provide a ”familliar” interface to users

Let ”Power-users” be able to fine tunes

4 / 16The Numerical Template Toolbox, or Why I Stopped Worrying & Loved Boost::Proto

Page 10: The Numerical Template Toolbox or Why I Stopped Worrying ...downloads.tuxfamily.org/eigen/meetings/paris2010/Joel-nt2.pdf · Use modern C++ idioms Expression Templates Policy based

Introduction What’s NT2 Conclusion

NT2 Global Layout

boost::protonumerics

table<T,S>

algebra

Abstract System Layer

Abstract Meta-programing

Layer

polynom

image

transform

...

5 / 16The Numerical Template Toolbox, or Why I Stopped Worrying & Loved Boost::Proto

Page 11: The Numerical Template Toolbox or Why I Stopped Worrying ...downloads.tuxfamily.org/eigen/meetings/paris2010/Joel-nt2.pdf · Use modern C++ idioms Expression Templates Policy based

Introduction What’s NT2 Conclusion

NT2 Outline

The User Level

You know MATLAB, you know NT2

Support for 280+ functions on values and containers

Semantic-heavy interface

The Dev. Level

Adding features should be easy

Generic components built on themselves

Simplify house-keeping

6 / 16The Numerical Template Toolbox, or Why I Stopped Worrying & Loved Boost::Proto

Page 12: The Numerical Template Toolbox or Why I Stopped Worrying ...downloads.tuxfamily.org/eigen/meetings/paris2010/Joel-nt2.pdf · Use modern C++ idioms Expression Templates Policy based

Introduction What’s NT2 Conclusion

NT2 Outline

The User Level

You know MATLAB, you know NT2

Support for 280+ functions on values and containers

Semantic-heavy interface

The Dev. Level

Adding features should be easy

Generic components built on themselves

Simplify house-keeping

6 / 16The Numerical Template Toolbox, or Why I Stopped Worrying & Loved Boost::Proto

Page 13: The Numerical Template Toolbox or Why I Stopped Worrying ...downloads.tuxfamily.org/eigen/meetings/paris2010/Joel-nt2.pdf · Use modern C++ idioms Expression Templates Policy based

Introduction What’s NT2 Conclusion

NT2 Main Interface

boost::protonumerics

table<T,S>

algebra

Abstract System Layer

Abstract Meta-programing

Layer

polynom

image

transform

...

7 / 16The Numerical Template Toolbox, or Why I Stopped Worrying & Loved Boost::Proto

Page 14: The Numerical Template Toolbox or Why I Stopped Worrying ...downloads.tuxfamily.org/eigen/meetings/paris2010/Joel-nt2.pdf · Use modern C++ idioms Expression Templates Policy based

Introduction What’s NT2 Conclusion

NT2 Main Interface

The table class

Models generic, multidim. MATLAB array of values

Notion of size and position as first class object

Power-user can use STL or other C++ like interface

Relation to proto

proto grammars + SFINAE simplify error messages

All containers generates a single familly of generic AST

All operations are done recursively with proto transforms

Dev. can add any number of AST transformation steps

8 / 16The Numerical Template Toolbox, or Why I Stopped Worrying & Loved Boost::Proto

Page 15: The Numerical Template Toolbox or Why I Stopped Worrying ...downloads.tuxfamily.org/eigen/meetings/paris2010/Joel-nt2.pdf · Use modern C++ idioms Expression Templates Policy based

Introduction What’s NT2 Conclusion

NT2 Main Interface

The table class

Models generic, multidim. MATLAB array of values

Notion of size and position as first class object

Power-user can use STL or other C++ like interface

Relation to proto

proto grammars + SFINAE simplify error messages

All containers generates a single familly of generic AST

All operations are done recursively with proto transforms

Dev. can add any number of AST transformation steps

8 / 16The Numerical Template Toolbox, or Why I Stopped Worrying & Loved Boost::Proto

Page 16: The Numerical Template Toolbox or Why I Stopped Worrying ...downloads.tuxfamily.org/eigen/meetings/paris2010/Joel-nt2.pdf · Use modern C++ idioms Expression Templates Policy based

Introduction What’s NT2 Conclusion

NT2 Internal Structure

boost::protonumerics

table<T,S>

algebra

Abstract System Layer

Abstract Meta-programing

Layer

polynom

image

transform

...

9 / 16The Numerical Template Toolbox, or Why I Stopped Worrying & Loved Boost::Proto

Page 17: The Numerical Template Toolbox or Why I Stopped Worrying ...downloads.tuxfamily.org/eigen/meetings/paris2010/Joel-nt2.pdf · Use modern C++ idioms Expression Templates Policy based

Introduction What’s NT2 Conclusion

NT2 Implementation

Support ILP/TLP

Functions are tag-dispatched generic P.F.O.

New architecture specific code is tagged and automatically recognized

Dev. can specialize variation point in the A.S.L.

Extending NT2

Compatible with Boost : serialization, fusion, MPL, MPI, etc ...

New subsystem can be added through a set of extensions points

Dev. can specialize variation point in the A.M.L.

10 / 16The Numerical Template Toolbox, or Why I Stopped Worrying & Loved Boost::Proto

Page 18: The Numerical Template Toolbox or Why I Stopped Worrying ...downloads.tuxfamily.org/eigen/meetings/paris2010/Joel-nt2.pdf · Use modern C++ idioms Expression Templates Policy based

Introduction What’s NT2 Conclusion

NT2 Implementation

Support ILP/TLP

Functions are tag-dispatched generic P.F.O.

New architecture specific code is tagged and automatically recognized

Dev. can specialize variation point in the A.S.L.

Extending NT2

Compatible with Boost : serialization, fusion, MPL, MPI, etc ...

New subsystem can be added through a set of extensions points

Dev. can specialize variation point in the A.M.L.

10 / 16The Numerical Template Toolbox, or Why I Stopped Worrying & Loved Boost::Proto

Page 19: The Numerical Template Toolbox or Why I Stopped Worrying ...downloads.tuxfamily.org/eigen/meetings/paris2010/Joel-nt2.pdf · Use modern C++ idioms Expression Templates Policy based

Introduction What’s NT2 Conclusion

NT2 Toolboxes

boost::protonumerics

table<T,S>

algebra

Abstract System Layer

Abstract Meta-programing

Layer

polynom

image

transform

...

11 / 16The Numerical Template Toolbox, or Why I Stopped Worrying & Loved Boost::Proto

Page 20: The Numerical Template Toolbox or Why I Stopped Worrying ...downloads.tuxfamily.org/eigen/meetings/paris2010/Joel-nt2.pdf · Use modern C++ idioms Expression Templates Policy based

Introduction What’s NT2 Conclusion

NT2 Toolboxes

Objectives

Increase expressivity by specifying semantic heavy entities

Semantic is usable all around AST transforms

High-level informations grants better optimization

Examples

algebra : matrix, vector, covector

polynoms : root computing, polynom products

geometry : shape and rigid transform

12 / 16The Numerical Template Toolbox, or Why I Stopped Worrying & Loved Boost::Proto

Page 21: The Numerical Template Toolbox or Why I Stopped Worrying ...downloads.tuxfamily.org/eigen/meetings/paris2010/Joel-nt2.pdf · Use modern C++ idioms Expression Templates Policy based

Introduction What’s NT2 Conclusion

NT2 Toolboxes

Objectives

Increase expressivity by specifying semantic heavy entities

Semantic is usable all around AST transforms

High-level informations grants better optimization

Examples

algebra : matrix, vector, covector

polynoms : root computing, polynom products

geometry : shape and rigid transform

12 / 16The Numerical Template Toolbox, or Why I Stopped Worrying & Loved Boost::Proto

Page 22: The Numerical Template Toolbox or Why I Stopped Worrying ...downloads.tuxfamily.org/eigen/meetings/paris2010/Joel-nt2.pdf · Use modern C++ idioms Expression Templates Policy based

Introduction What’s NT2 Conclusion

Sample Code

MATLAB to NT2R = I(:,:,1);G = I(:,:,2);B = I(:,:,3);

Y = min(bitshift(abs(2104*R+4130*G+802*B+135168),-13),235);

U = min(bitshift(abs(-1214*R-2384*G+3598*B+1052672),-13),240);

V = min(bitshift(abs(3598*R-3013*G-585*B+1052672),-13),240);

13 / 16The Numerical Template Toolbox, or Why I Stopped Worrying & Loved Boost::Proto

Page 23: The Numerical Template Toolbox or Why I Stopped Worrying ...downloads.tuxfamily.org/eigen/meetings/paris2010/Joel-nt2.pdf · Use modern C++ idioms Expression Templates Policy based

Introduction What’s NT2 Conclusion

Sample Code

MATLAB to NT2table<> R = I(_,_,1);table<> G = I(_,_,2);table<> B = I(_,_,3);

Y = min(bitshift(abs(2104*R+4130*G+802*B+135168),-13),235);

U = min(bitshift(abs(-1214*R-2384*G+3598*B+1052672),-13),240);

V = min(bitshift(abs(3598*R-3013*G-585*B+1052672),-13),240);

13 / 16The Numerical Template Toolbox, or Why I Stopped Worrying & Loved Boost::Proto

Page 24: The Numerical Template Toolbox or Why I Stopped Worrying ...downloads.tuxfamily.org/eigen/meetings/paris2010/Joel-nt2.pdf · Use modern C++ idioms Expression Templates Policy based

Introduction What’s NT2 Conclusion

Sample Code

MATLAB to NT2table<settings(shallow)> R = I(_,_,1);table<settings(shallow)> G = I(_,_,2);table<settings(shallow)> B = I(_,_,3);

Y = min(bitshift(abs(2104*R+4130*G+802*B+135168),-13),235);

U = min(bitshift(abs(-1214*R-2384*G+3598*B+1052672),-13),240);

V = min(bitshift(abs(3598*R-3013*G-585*B+1052672),-13),240);

13 / 16The Numerical Template Toolbox, or Why I Stopped Worrying & Loved Boost::Proto

Page 25: The Numerical Template Toolbox or Why I Stopped Worrying ...downloads.tuxfamily.org/eigen/meetings/paris2010/Joel-nt2.pdf · Use modern C++ idioms Expression Templates Policy based

Introduction What’s NT2 Conclusion

Sample Code

MATLAB to NT2table<uint32_t,settings(shallow)> R = I(_,_,1);table<uint32_t,settings(shallow)> G = I(_,_,2);table<uint32_t,settings(shallow)> B = I(_,_,3);;

Y = min(bitshift(abs(2104*R+4130*G+802*B+135168),-13),235);

U = min(bitshift(abs(-1214*R-2384*G+3598*B+1052672),-13),240);

V = min(bitshift(abs(3598*R-3013*G-585*B+1052672),-13),240);

13 / 16The Numerical Template Toolbox, or Why I Stopped Worrying & Loved Boost::Proto

Page 26: The Numerical Template Toolbox or Why I Stopped Worrying ...downloads.tuxfamily.org/eigen/meetings/paris2010/Joel-nt2.pdf · Use modern C++ idioms Expression Templates Policy based

Introduction What’s NT2 Conclusion

Let’s round this up !

Computing for Scientist

Contrary to other array/algebra library, NT2 choose to lookstrange for C++ users and easy for MATLAB users.

We rely heavily on Boost as it simplify and streamline, platformsupport and modularization.

proto helps us writing our code as real EBNF and semanticactions, just using templates

Long list of existing applications running with NT2 : autonomousvehicles and drone, hand held device IP, etc...

14 / 16The Numerical Template Toolbox, or Why I Stopped Worrying & Loved Boost::Proto

Page 27: The Numerical Template Toolbox or Why I Stopped Worrying ...downloads.tuxfamily.org/eigen/meetings/paris2010/Joel-nt2.pdf · Use modern C++ idioms Expression Templates Policy based

Introduction What’s NT2 Conclusion

Current and Future Works

What’s we’re cooking at the moment

GPU support : ITOC project (CEA/LIX/LRI)

Sparse matrix support (EDF R&D)

Cell support : OMTE Digiteo project

Expected to start (soon)

Unify optimization thanks to polyhedral model

Export parts of NT2 internals as Boost library

MPI support : PhD starting in 2010

AVX prototype thanks to Intel simulator

15 / 16The Numerical Template Toolbox, or Why I Stopped Worrying & Loved Boost::Proto

Page 28: The Numerical Template Toolbox or Why I Stopped Worrying ...downloads.tuxfamily.org/eigen/meetings/paris2010/Joel-nt2.pdf · Use modern C++ idioms Expression Templates Policy based

Introduction What’s NT2 Conclusion

Current and Future Works

What’s we’re cooking at the moment

GPU support : ITOC project (CEA/LIX/LRI)

Sparse matrix support (EDF R&D)

Cell support : OMTE Digiteo project

Expected to start (soon)

Unify optimization thanks to polyhedral model

Export parts of NT2 internals as Boost library

MPI support : PhD starting in 2010

AVX prototype thanks to Intel simulator

15 / 16The Numerical Template Toolbox, or Why I Stopped Worrying & Loved Boost::Proto

Page 29: The Numerical Template Toolbox or Why I Stopped Worrying ...downloads.tuxfamily.org/eigen/meetings/paris2010/Joel-nt2.pdf · Use modern C++ idioms Expression Templates Policy based

Thanks for your attention