Download presentation
Presentation is loading. Please wait.
Published byHoratio Horn Modified over 9 years ago
1
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 Traced Example –Expression –Trace –Functions Conclude Handouts – trace file
2
U Albany SUNY PETE code Review Xingmin Luo 7/2/2003
3
U Albany SUNY 3 Outline Motivation
4
U Albany SUNY 4 Overview of PETE Program expressions a = 1; a = b; a = b + c; a = b + c + d; Future Work and Conclusions
5
U Albany SUNY 5 Motivation Discover how PETE works? Modify PETE to support Psi calculus. Ensure Changes do not degrade performance.
6
U Albany SUNY 6 What is PETE Portable Expression Template Engine Faster C++ Expression Templates Arithmetic Expressions Efficient Loops
7
U Albany SUNY 7 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
8
U Albany SUNY 8 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)
9
U Albany SUNY 9 Trace result of a = b + c + d; (1) Array.cpp (our file) a = b + c + d; Array.h (Our file) template class Array { ……… template Array &operator=(const Expression &rhs) { for(long i=0; i 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 shape; long size; }
10
U Albany SUNY 10 Trace result of a = b + c + d; (2) ForEach.h template inline typename ForEach ::Type_t forEach(const Expr &e, const FTag &f, const CTag &c) { return ForEach ::apply(e, f, c); } template struct ForEach { typedef typename LeafFunctor ::Type_t Type_t; inline static Type_t apply(const Expr &expr, const FTag &f, const CTag &) { return LeafFunctor ::apply(expr, f); } };
11
U Albany SUNY 11 Trace result of a = b + c + d; (3) Array.h specializes EvalLeaf1 function template struct LeafFunctor, EvalLeaf1> { typedef T Type_t; static Type_t apply(const Array &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; } };
12
U Albany SUNY 12 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; }
13
U Albany SUNY 13 Future Work Modify PETE code to support Psi operations. Extend our current implementation of the Psi calculus Build high-level Psi calculus tools
14
U Albany SUNY 14 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
15
U Albany SUNY 15 Acknowlegements Prof. Lenore Mullin Prof. Dan Rosenkrantz Prof. Harry Hunt Lawrence Bush
16
U Albany SUNY 16 Defines expression tree CreateLeaf.h (defines expression tree) //Expression - a class that wraps the contents of an expression template 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; };
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.