Boost.勉強会#4 Boost.Proto
Upcoming SlideShare
Loading in...5
×
 

Boost.勉強会#4 Boost.Proto

on

  • 3,203 views

http://atnd.org/events/11551

http://atnd.org/events/11551

Statistics

Views

Total Views
3,203
Views on SlideShare
2,496
Embed Views
707

Actions

Likes
2
Downloads
16
Comments
0

5 Embeds 707

http://d.hatena.ne.jp 692
http://paper.li 11
http://webcache.googleusercontent.com 2
http://twitter.com 1
http://translate.googleusercontent.com 1

Accessibility

Categories

Upload Details

Uploaded via as Adobe PDF

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

Boost.勉強会#4 Boost.Proto Boost.勉強会#4 Boost.Proto Presentation Transcript

  • Boost.ProtoBoost. #4 2011/02/26 /@fjnli id:fjnl1
  • Twitter ( ) ... 2
  • http://atnd.org/events/11551 3
  • http://atnd.org/events/11551Proto 3
  • http://atnd.org/events/11551 ProtoLambda, Spirit, uBLAS Proto 3
  • Boost.Proto4
  • Boost. #4 Proto ( ) Proto 5
  • Agenda•• Boost.Proto•• + 6
  • Agenda•• Boost.Proto•• + 6
  • Agenda• 15• Boost.Proto 5•• + 6
  • Agenda• Boost.Proto • Boost.Proto • Expression Template (ET) • Boost.Proto 7
  • Agenda• • Boost.Proto • Boost.uBLAS • General Purpose computing on GPU (GPGPU) • ET → 8
  • • ( )• @fjnli, id:fjnl• → ( )• Ariel Networks• : GPU 9
  • • ( )• @fjnli, id:fjnl• → Hatena ID i ( )• Ariel Networks• : GPU 9
  • • ( )• @fjnli, id:fjnl• → Hatena ID ※ i ( )• Ariel Networks• : GPU 9
  • • ( )• @fjnli, id:fjnl• → ( )• Ariel Networks• : GPU 10
  • .begin(); 11
  • Proto• Expression Template (ET) • a + b * c → plus<A, multiply<B, C>>• Boost 1.37• Headers only 12
  • Proto• Boost.Proto• Boost Boost.Proto : • Boost.Spirit (Qi, Karma, Lex) • Boost.Phoenix v3 (in the future) • Boost.MSM.eUML (experimental, 1.44) • Boost.Xpressive 13
  • ET• • • ´ ω • Qi Proto 14
  • usingnamespace proto = boost::proto;using namespace boost::proto;using boost::proto::argsns_::list2,using boost::proto::exprns_::expr;using boost::proto::exprns_::term; 15
  • a[b] + (c * d) (Syntax Tree) : 16
  • a[b] + (c * d) (Syntax Tree) : (+) ([]) (*)a b c d 16
  • a[b] + (c * d)expr<tag::plus, list2< expr<tag::subscript, list2<, expr<tag::terminal, term<int>, 0>&, expr<tag::terminal, term<int>, 0>& >, 2 > const&, expr<tag::multiplies, list2< expr<tag::terminal, term<int> 0>&, expr<tag::terminal, term<int> 0>& >, 2 > const& >, 2> const 17
  • a[b] + (c * d)expr<tag::plus, list2< expr<tag::subscript, expr exprns_:: list2<, expr<tag::terminal, term<int>, 0>&, expr<tag::terminal, term<int>, 0>& >, 2 > const&, expr<tag::multiplies, list2< expr<tag::terminal, term<int> 0>&, expr<tag::terminal, term<int> 0>& >, 2 > const& >, 2> const 18
  • a[b] + (c * d)expr<tag::plus, list2< plus → + expr<tag::subscript, multiplies → * list2<, expr<tag::terminal, subscript → [] term<int>, 0>&, expr<tag::terminal, term<int>, 0>& … >, 2 > const&, expr<tag::multiplies, list2< expr<tag::terminal, term<int> 0>&, expr<tag::terminal, term<int> 0>& >, 2 > const& >, 2> const 19
  • a[b] + (c * d)expr<tag::plus, list2< expr<tag::subscript, list2<, argsns_::listN expr<tag::terminal, term<int>, 0>&, expr<tag::terminal, term<int>, 0>& >, 2 > const&, expr<tag::multiplies, list2< expr<tag::terminal, term<int> 0>&, expr<tag::terminal, term<int> 0>& >, 2 > const& >, 2> const 20
  • a[b] + (c * d)expr<tag::plus, list2< expr<tag::subscript, exprns_::term list2<, expr<tag::terminal, term<int>, 0>&, expr<tag::terminal, term<int>, 0>& >, 2 > const&, expr<tag::multiplies, list2< expr<tag::terminal, term<int> 0>&, expr<tag::terminal, term<int> 0>& >, 2 > const& >, 2> const 21
  • a[b] + (c * d)expr<tag::plus, list2< expr<tag::subscript, list2<, expr<tag::terminal, term<int>, 0>&, expr<tag::terminal, term<int>, 0>& >, 2 > const&, expr<tag::multiplies, list2< expr<tag::terminal, term<int> 0>&, expr<tag::terminal, term<int> 0>& >, 2 > const& >, 2> const 22
  • :default_context const ctx;std::cout << eval(lit(1) + 2 + 3, ctx) << std::endl; :6 23
  • :default_context const ctx;std::cout << eval(lit(1) + 2 + 3, ctx) << std::endl; 24
  • default_context → C++null_context → 25
  • + -•x + y x-y • int + •→ 26
  • + -struct my_context { template < class Expr, class Enable = void > struct eval;};evalmy_context::eval<Expr>()(expr, ctx) 27
  • + -struct my_context { template < class Expr, class Enable = void > struct eval; SFINAE};evalmy_context::eval<Expr>()(expr, ctx) 27
  • SFINAE• SFINAE ( ?) • Substitution Failure Is Not An Error •• boost::enable_if •template <class T> typename enable_if<is_const<T>>::type foo();• SFINAE eval 28
  • + -template <class Expr>struct eval< Expr, typename boost::enable_if< matches<Expr, terminal<int>> >::type> { typedef int result_type; result_type operator ()(Expr& e, my_context const&) const { return value(e); }} 29
  • + -template <class Expr>struct eval< Expr, typename boost::enable_if< matches<Expr, terminal<int>> >::type> { proto : typedef int result_type; Expr terminal<int> result_type true operator ()(Expr& e, my_context const&) const { return value(e); }} 30
  • + -template <class Expr>struct eval< Expr, typename boost::enable_if< matches<Expr, terminal<int>> >::type> { typedef int result_type; result_type operator ()(Expr& e, C++0x my_context const&) decltype const { return value(e); }} 31
  • + -template <class Expr>struct eval< Expr, typename boost::enable_if< matches<Expr, terminal<int>> >::type> { typedef int result_type; result_type operator ()(Expr& e, my_context const&) const { return value(e); }} 32
  • + -template <class Expr>struct eval< Expr, typename boost::enable_if< matches<Expr, terminal<int>> >::type> { typedef int result_type; result_type operator ()(Expr& e, my_context const&) const { return value(e); }} 33
  • + -template <class Expr>struct eval< Expr, typename boost::enable_if< matches<Expr, plus<_, _>> >::type> { typedef int result_type; result_type operator ()(Expr& e, my_context const& ctx) const { return proto::eval(left(e), ctx) - proto::eval(right(e), ctx); }} 34
  • + -template <class Expr>struct eval< Expr, typename boost::enable_if< matches<Expr, plus<_, _>> >::type> { _ typedef int result_type; (wildcard) result_type operator ()(Expr& e, my_context const& ctx) const { return proto::eval(left(e), ctx) - proto::eval(right(e), ctx); }} 35
  • + -template <class Expr>struct eval< Expr, typename boost::enable_if< matches<Expr, plus<_, _>> >::type> { typedef int result_type; left: 1 result_type right: 2 operator ()(Expr& e, my_context const& ctx) const { return proto::eval(left(e), ctx) - proto::eval(right(e), ctx); }} 36
  • + -template <class Expr>struct eval< Expr, typename boost::enable_if< matches<Expr, plus<_, _>> >::type> { typedef int result_type; result_type operator ()(Expr& e, my_context const& ctx) const { return proto::eval(left(e), ctx) - proto::eval(right(e), ctx); }} 37
  • + -template <class Expr>struct eval< Expr, typename boost::enable_if< matches<Expr, plus<_, _>> >::type> { typedef int result_type; result_type operator ()(Expr& e, my_context const& ctx) const { return proto::eval(left(e), ctx) - proto::eval(right(e), ctx); }} 38
  • 2 :my_context const ctx;std::cout << eval(lit(1) + 2 + 3, ctx) << std::endl; :-4 39
  • /• : • proto::left, proto::right• : • proto::result_of::left, proto::result_of::right • C++0x 40
  • • Context •• Domain •• Extends •• Grammer • 41
  • :1.User’s Guide http://www.boost.org/doc/libs/1_46_0/doc/html/proto/ users_guide.html2. (C++ Advent Calender JP 2010; 16 ) http://d.hatena.ne.jp/fjnl/20101222/ 42
  • .end();.begin(); 43
  • Proto• ET • • • (+ )•( ) • Basic Linear Algebra Subprograms (BLAS) 44
  • Boost.uBLAS• Boost.uBLAS• Boost.uBLAS• Boost.uBLAS 45
  • Boost.uBLAS• CPU, GPU • →• CPU GPU • : • • CPU: , ATLAS, GotoBLAS, OpenCL • GPU: , CUBLAS, OpenCL 46
  • ET → Backend::scalar a; Backend::vector b, x, y; y = a * x + b;Backend::eval< multiply, scalar, vector>()(y, a, x);Backend::eval< plus, vector, vector>()(y, y, b); 47
  • (Cell, GPU ) [a * x + y]plus<multiply<scalar, vector>, vector>axpy<scalar, vector, vector> 48
  • 49