Outline Notes (not in presentation)

Slides:



Advertisements
Similar presentations
Chapter 11 Introduction to Programming in C
Advertisements

The C ++ Language BY Shery khan. The C++ Language Bjarne Stroupstrup, the language’s creator C++ was designed to provide Simula’s facilities for program.
U Albany SUNY PETE code Review Xingmin Luo 6/12/2003.
Chapter 14: Overloading and Templates
Rossella Lau Lecture 5, DCO10105, Semester B, DCO10105 Object-Oriented Programming and Design  Lecture 5: Class construction  Encapsulation 
Generative Programming. Generic vs Generative Generic Programming focuses on representing families of domain concepts Generic Programming focuses on representing.
CSE 332: C++ Algorithms II From Last Time: Search with Generic Iterators Third generalization: separate iterator type parameter We arrive at the find algorithm.
1 Stacks Chapter 4 2 Introduction Consider a program to model a switching yard –Has main line and siding –Cars may be shunted, removed at any time.
A Computer Science Tapestry 1 Recursion (Tapestry 10.1, 10.3) l Recursion is an indispensable technique in a programming language ä Allows many complex.
CSE 332: C++ Type Programming: Associated Types, Typedefs and Traits A General Look at Type Programming in C++ Associated types (the idea) –Let you associate.
ADTs and C++ Classes Classes and Members Constructors The header file and the implementation file Classes and Parameters Operator Overloading.
XYZ 11/16/2015 MIT Lincoln Laboratory AltiVec Extensions to the Portable Expression Template Engine (PETE)* Edward Rutledge HPEC September,
XYZ 11/21/2015 MIT Lincoln Laboratory Monolithic Compiler Experiments Using C++ Expression Templates* Lenore R. Mullin** Edward Rutledge Robert.
C++ Programming: From Problem Analysis to Program Design, Third Edition Chapter 15: Overloading and Templates.
Programming Fundamentals. Topics to be covered Today Recursion Inline Functions Scope and Storage Class A simple class Constructor Destructor.
Copyright © 2009 – Curt Hill Standard Template Library An Introduction.
CSE 332: C++ STL iterators What is an Iterator? An iterator must be able to do 2 main things –Point to the start of a range of elements (in a container)
U Albany SUNY 1 Outline Notes (not in presentation) Intro Overview of PETE (very high level) –What pete does. –Files – say what each file does Explain.
U Albany SUNY PETE code Review Xingmin Luo 6/12/2003.
Motivation for Generic Programming in C++
Arrays.
Advanced Computer Systems
EGR 2261 Unit 11 Pointers and Dynamic Variables
Templates.
Compilers Principles, Techniques, & Tools Taught by Jing Zhang
Operator overloading Conversions friend inline
Ch. 4 – Semantic Analysis Errors can arise in syntax, static semantics, dynamic semantics Some PL features are impossible or infeasible to specify in grammar.
Student Book An Introduction
Trees.
Stacks Chapter 4.
Templates.
The dirty secrets of objects
Intermediate Code Generation
Relational Algebra 461 The slides for this text are organized into chapters. This lecture covers relational algebra, from Chapter 4. The relational calculus.
Outline Notes (not in presentation)
Object - Oriented Programming Language
Building the Support for Radar Processing Across Memory Hierarchies:
Introduction to Classes
Chapter 11 Introduction to Programming in C
OOP Paradigms There are four main aspects of Object-Orientated Programming Inheritance Polymorphism Abstraction Encapsulation We’ve seen Encapsulation.
7 Arrays.
Chapter 6 Intermediate-Code Generation
Monolithic Compiler Experiments Using C++ Expression Templates*
Chapter 11 Introduction to Programming in C
Constructors and Other Tools
Background In his classic 1972 paper on definitional interpreters, John Reynolds introduced two key techniques: Continuation-passing style - Makes.
Monolithic Compiler Experiments Using C++ Expression Templates*
Merge Sort 1/12/2019 5:31 PM Dynamic Programming Dynamic Programming.
Introduction C is a general-purpose, high-level language that was originally developed by Dennis M. Ritchie to develop the UNIX operating system at Bell.
Building the Support for Radar Processing Across Memory Hierarchies:
Building the Support for Radar Processing Across Memory Hierarchies:
Building the Support for Radar Processing Across Memory Hierarchies:
Dynamic Programming Merge Sort 1/18/ :45 AM Spring 2007
(HPEC-LB) Outline Notes
CISC/CMPE320 - Prof. McLeod
Building the Support for Radar Processing Across Memory Hierarchies:
Building the Support for Radar Processing Across Memory Hierarchies:
Trees.
CISC/CMPE320 - Prof. McLeod
Algorithms and Problem Solving
Building the Support for Radar Processing Across Memory Hierarchies:
7 Arrays.
Memory Efficient Radar Processing
<PETE> Shape Programmability
Object - Oriented Programming Language
Compiler Construction
Object - Oriented Programming Language
Building the Support for Radar Processing Across Memory Hierarchies:
Introduction to Methods and Interfaces
Presentation transcript:

Outline Notes (not in presentation) Intro Overview of PETE (very high level) What pete does. Files – say what each file does Explain Traced Example Expression Trace Functions Conclude Handouts – trace file

PETE code Review Xingmin Luo 6/18/2003

Outline Motivation Overview of PETE Trace results of 3 kinds of expressions a = b + c + d; b = 1; c = 2; d = 3; b = c; Future Work and Conclusions

Motivation Discover how PETE works? Why? because we want to modify PETE to provide additional operations (like operations of Psi calculus.) So we must first understand how PETE is implemented. //PETE has 43 build-in operations such as Plus, Minus, times….

What is PETE Portable Expression Templates Engine Faster C++ Arithmetic Expressions Efficient Loops Pete was developed at the Los Alamos National Laboratory (Los Alamos, New Mexico). The main objective of PETE is to produce Faster C++. This means that pete combines High Performance with the high level of abstraction provided by Object Oriented Programming and Design constructs. These OOPD constructs are what make C++ more enjoyable to program, more organized, and less error prone. Expression Templates - The general expression template idea or technique was created by Todd Veldhuizen and David Vandevorde. Pete (and more generally expression templates) take arithmetic expressions and change the ordering of operations to produce efficient loops. The net effect is the reduction of temporary containers to save intermediate calculations. This saves time as well as space.

Files PETE ( pete.h ) includes the following files Our Files: #include "PETE/Scalar.h" #include "PETE/TypeComputations.h" #include "PETE/TreeNodes.h" #include "PETE/OperatorTags.h" #include "PETE/Functors.h" #include "PETE/Combiners.h" #include "PETE/ForEach.h" #include "PETE/CreateLeaf.h“ Our Files: Array.cpp Array.h This list of pete include files gives a general idea of what it entails. If a user wants to use pete, … , integrate it with his own user defined files, he needs to include the pete.h file. The pete.h file subsequently includes all of the files in the list shown here. These files provide all pete functionallity. For example, the For Each.h file defines the for each function which traverse the parse tree. Array.cpp and Array.h are our user defined classes which work with pete. That’s an excellent questions. We will get into those details,…, in a more understandable order,…, later. Do not say: It is very simple. 1. I am presenting nothing of value. 2. You are stupid if you don’t understand.

Flow of a = b + c + d; Operator=() (Array.h) forEach() (ForEach.h) LeafFunctor() (Array.h) EvalLeaf1() (Functors.h) Opcombine() (Combiners.h) PETE_EMPTY_CONSTRUCTORS() (PETE.h) Actually, this is high level description of trace result. We begin our trace from Array.cpp because there is a statement a = b + c + d; in Array.cpp. And Array.h overload the assignment operator, so we go to Array.h. Array.h call forEach() function which is defined in forEach.h; ForEach() function call leafFunctor() which is defined in Array.h; leafFunctor() call EvalLeaf1() which is defined in Functors.h; In the meanwhile, ForEach() also call Opcombine() which is defined in Combiners.h; and Opcombine() call PETE_EMPTY_CONSTRUNCTORE() which is defined in PETE.h From next slide, I will go through these code line by line.

Trace result of a = b + c + d; (1) Array.cpp (our file) a = b + c + d; Array.h (Our file) template <class T = int> class Array { ……… template<class RHS> Array &operator=(const Expression<RHS> &rhs) { for(long i=0; i<this->size; i++) d[i] = forEach(rhs, EvalLeaf1(i), OpCombine()); return *this; //equal to: a.d[i] = b.d[i]+c.d[i]+d.d[i] } ……. private: T * d; vector <int> shape; long size; Now I am going to explain the trace result of a=b+c+d; Here, A,b,c,d are instances of Array class(a template class) which is defined in Array.h This piece of code is from array class; It overload assignment operator which take the RHS(b+c+d) as input. //Expression class wraps the contents of an expression. (is defined in Creatleaf.h) //rhs is the reference of Expression <RHS> forEach () traverses the expression tree defined by rhs(b+c+d), applies the functor EvalLeaf(i) to each leaf and combines the results together using the combiner Opcombine(). We need the for loop to calculate every elements in A,B,C,D forEach() is defined in ForEach.h file, So we will go to ForEach.h file Note small forEach()

Trace result of a = b + c + d; (2) ForEach.h template<class Expr, class FTag, class CTag> inline typename ForEach<Expr,FTag,CTag>::Type_t forEach(const Expr &e, const FTag &f, const CTag &c) { return ForEach<Expr, FTag, CTag>::apply(e, f, c); } struct ForEach typedef typename LeafFunctor<Expr, FTag>::Type_t Type_t; inline static Type_t apply(const Expr &expr, const FTag &f, const CTag &) return LeafFunctor<Expr, FTag>::apply(expr, f); }; Small forEach() call capital ForEach()::Apply(); Capital ForEach()::Apply() call LeafFunctor()::apply() which is defined in Array.h

Trace result of a = b + c + d; (3) Array.h specializes EvalLeaf1 function template<class T> struct LeafFunctor<Array <T>, EvalLeaf1> { typedef T Type_t; static Type_t apply(const Array <T> &a, const EvalLeaf1 &f) { return a[f.val1()]; } //Note: here a is b+c+d }; Functors.h (functors define here) // LeafFunctors are used by ForEach to apply operations to the leaves of the // expression tree. Typical functors are evaluators, counters, etc. struct EvalLeaf1 int i1_m; // Note: forEach(rhs, EvalLeaf1(i), OpCombine()); so i1, i1_m is i inline EvalLeaf1(int i1) : i1_m(i1) { } inline int val1() const { return i1_m; } LeafFunctor()::apply() call EvalLeaf1(); it first save the index i in i1_m, then use val1() get the value i back

Trace result of a = b + c + d; (4) Combiners.h (defines combiner tag) struct OpCombine //Actually, this Tag did nothing. { PETE_EMPTY_CONSTRUCTORS(OpCombine) }; PETE.h #define PETE_EMPTY_CONSTRUCTORS(CLASS) \ CLASS() { } \ CLASS(const CLASS &) { } \ CLASS &operator=(const CLASS &) { return *this; } Equals to: OpCombine() { } OpCombine (const OpCombine &) { } OpCombine &operator=(const OpCombine &) { return *this; } In the meanwhile, forEach() also call Opcombine() which is defined in Combiners.h; However, Opcombine() call PETE_EMPTY_CONSTRUCTORS() which is defined in PETE.h; Note that PETE_EMPTY_CONSTRUCTORS() is only a macro. So struct OpCombine is equal to three statements here. It seems that Opcombine() tag did nothing here.

Trace result of b=1;c=2;d=3; Array.cpp b=1;c=2;d=3; Array.h template <class T = int> class Array { ……… Array &operator=(T value) { for(long i=0; i<this->size; i++) d[i] = value; return *this; } private: T * d; vector <int> shape; long size; ….. Let us look at another kind of expressions: b=1;c=2;d=3. Array.h overload assignment operator taking value as input; So it will go to this piece of code run b=1;c=2;d=3. This just assign every elements of array the same value of RHS. After this, each elements in b is 1; each elements in c is 2; each elements in d is 3;

Trace result of b=c; Array.cpp Array.h b=c; Array &operator=(const Array &v) { for(long i=0; i<this->size; i++) d[i] = v.d[i]; return *this; } private: T * d; vector <int> shape; long size; Let us trace b=c;. Again Array.h overloads assignment taking Array object as input. Actually it is only a copier function; It just copy each element’s value in RHS to LHS.

Future Work Modify PETE code to support Psi operations. Extend our current implementation of the Psi calculus Build high-level Psi calculus tools

Conclusions PETE’s Expression templates provide the ability to perform compiler preprocessor-style optimizations (expression tree manipulation) The C++ template mechanism can be applied to a wide variety of problems (e.g. tree traversal ala PETE, graph traversal, list traversal) to gain run-time speedup at the expense of compile time/space

Acknowlegements Prof. Lenore Mullin Prof. Dan Rosenkrantz Prof. Harry Hunt Lawrence Bush

Defines expression tree CreateLeaf.h (defines expression tree) //Expression<T> - a class that wraps the contents of an expression template<class T> class Expression { public: typedef T Expression_t; // Type of the expression. Expression(const T& expr) : expr_m(expr) { } // Construct from an expression. const Expression_t& expression() const // Accessor that returns the expression. return expr_m; } private: // Store the expression by value since it is a temporary produced // by operator functions. T expr_m; };