Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!news.glorb.com!news.alt.net From: danielgutson@googlemail.com Newsgroups: comp.std.c++ Subject: flow-control operators overloading for "statement templates" aiding a generic solution for parallel technologies a program transformations Date: Fri, 22 Nov 2013 09:05:02 CST Organization: unknown Lines: 74 Sender: std-cpp-request@vandevoorde.com Approved: stephen.clamage@oracle.com Message-ID: <9cdab995-effb-4c01-8043-ee4156e6e02e@googlegroups.com> Content-Type: text/plain; charset=ISO-8859-1 To: undisclosed-recipients:; Return-Path: X-Original-Date: Thu, 21 Nov 2013 03:24:22 -0800 (PST) X-Submission-Address: std-cpp-submit@vandevoorde.com Xref: csiph.com comp.std.c++:692 Technologies such as OpenMP [1], Cilk Plus [2], CUDA [3] and SIMD vectorization require language extensions (or compiler support). I am also aware of the work of a project [4] which addresses OpenMP by incorporating it into the language. I was looking into a possible general solution at language level to be able to both implement the technologies and use them without extensions or special compiler support. Another goal is to be technology-agnostic, that is, a solution that enables the implementation of any of those technologies as a library level. As a first proof of concept, I did an analogy of "expression templates" [5] for statements and flow control in a project here: http://statement-templates.googlecode.com. Main thing here is that statements (and flow control operators) are objects. In this project, I developed a "for" and a "parallel for" using plain C++ (with almost no C++11 features intentionally), the latter segmenting the work and launching threads to get the job done (and then passes the segments to a vectorizing transformation). By using the template facilities in the project, I was able to: - mimick overloading of the "for" statement - program pattern matching to identify the suitable optimizations (e.g. when to apply certain optimizations) - statements introspection - program transformations By using these tools, a library can be done such that: optimizes/transforms loops, parallelizes, vectorizes, calculates cyclomatic complexity, or even adds coding rules (by adding static asserts when certain patterns are found). Far from trying to implement a program transformation library, I'm trying to see what could the language offer to natively perform what I tried to evaluate with a template metaprogramming library, adhering the 2-faced language principle, so the user just provides a program with regular statements (for, while, etc.), and includes a library that overloads them to provide some optimization semantic (parallelism, vectorization, etc.); and using another library, the original program already compiles, and the optimization/transformation semantic changes. With this mail, I'm proposing to start a discussion about the required language extensions to be able to implement a transformation library (which could be any of the technologies beforementioned). As far as I could see with my experiment, I could identify flow-control operators overloading, statements pattern recognition and transformations as the needs to accomplish this goal. In the source of the project, the interested reader can find a very initial proposed syntax. My initial attempt to address the solution is to suggest that the compiler provides linked statements in the way I proposed in the project so the library can be written with template metaprogramming techniques as I was able to do. Daniel. References: References: [1] www.openmp.org [2] www.cilkplus.org [3] http://www.nvidia.com/object/cuda_home_new.html [4] http://www.open-std.org/JTC1/SC22/WG21/docs/papers/2013/n3530.pdf [5] http://web.archive.org/web/20050315091836/http://osl.iu.edu/~tveldhui/papers/Expression-Templates/exprtmpl.html -- [ comp.std.c++ is moderated. To submit articles, try posting with your ] [ newsreader. If that fails, use mailto:std-cpp-submit@vandevoorde.com ] [ --- Please see the FAQ before posting. --- ] [ FAQ: http://www.comeaucomputing.com/csc/faq.html ]