1 / 17

Outline Notes (not in presentation)

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

olesia
Download Presentation

Outline Notes (not in presentation)

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. 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

  2. PETE code Review Xingmin Luo 6/18/2003

  3. 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

  4. Motivation • Discover how PETE works?

  5. What is PETE Portable Expression Templates Engine Faster C++ Expression Templates Arithmetic Expressions Efficient Loops

  6. Files • PETE ( pete.h ) includes the following 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

  7. 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)

  8. 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; }

  9. 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); } template<class Expr, class FTag, class CTag> 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); } };

  10. 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; } };

  11. 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; }

  12. 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; ….. }

  13. Trace result of b=c; • Array.cpp b=c; • Array.h 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;

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

  15. 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

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

  17. 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; };

More Related