November 30, 2006 1 Pseudo-dynamic C metaprogramming Using strategic term rewriting and partial evaluation 7 th Stratego User Days Wouter Caarls Quantitative.

Slides:



Advertisements
Similar presentations
1 A Simple C Program /* Take a number multiply it by 10 and display it */ #include main() { int number, result; printf("Type in a number \n"); scanf("%d",
Advertisements

Chapter Five Functions
Semantic Analysis Chapter 6. Two Flavors  Static (done during compile time) –C –Ada  Dynamic (done during run time) –LISP –Smalltalk  Optimization.
Principles of programming languages 1: Introduction (with a simple language) Isao Sasano Department of Information Science and Engineering.
Principles of programming languages 4: Parameter passing, Scope rules Department of Information Science and Engineering Isao Sasano.
Cs784(TK)1 Semantics of Procedures and Scopes. Kinds of Scope Static or Lexical scope –determined by structure of program –Scheme, C++, Java, and many.
Code Generation Mooly Sagiv html:// Chapter 4.
Telescoping Languages: A Compiler Strategy for Implementation of High-Level Domain-Specific Programming Systems Ken Kennedy Rice University.
Introduction to Code Generation Mooly Sagiv html:// Chapter 4.
Names and Scopes CS 351. Program Binding We should be familiar with this notion. A variable is bound to a method or current block e.g in C++: namespace.
Previous finals up on the web page use them as practice problems look at them early.
Encapsulation by Subprograms and Type Definitions
מבוא מורחב 1 Lecture 3 Material in the textbook Sections to
Validating High-Level Synthesis Sudipta Kundu, Sorin Lerner, Rajesh Gupta Department of Computer Science and Engineering, University of California, San.
Java An introduction. Example 1 public class Example1 { public static void main (String [] args) { System.out.println (“This is the first example”); int.
Basic Definitions Data Structures: Data Structures: A data structure is a systematic way of organizing and accessing data. Or, It’s the logical relationship.
Introduction to Code Generation Mooly Sagiv html:// Chapter 4.
1 Dan Quinlan, Markus Schordan, Qing Yi Center for Applied Scientific Computing Lawrence Livermore National Laboratory Semantic-Driven Parallelization.
Recursion and Implementation of Functions
Computer Science 209 The Strategy Pattern II: Emulating Higher-Order Functions.
October 26, 2006 Parallel Image Processing Programming and Architecture IST PhD Lunch Seminar Wouter Caarls Quantitative Imaging Group.
Exploiting Domain-Specific High-level Runtime Support for Parallel Code Generation Xiaogang Li Ruoming Jin Gagan Agrawal Department of Computer and Information.
Functional Programing Referencing material from Programming Language Pragmatics – Third Edition – by Michael L. Scott Andy Balaam (Youtube.com/user/ajbalaam)
FALL 2001ICOM Lecture 21 ICOM 4015 Advanced Programming Lecture 2 Procedural Abstraction Reading: LNN Chapter 4, 14 Prof. Bienvenido Velez.
Vermelding onderdeel organisatie April 28, Algorithmic Skeletons for Stream Programming in Embedded Hetereogeneous Parallel Image Processing Applications.
COP 4620 / 5625 Programming Language Translation / Compiler Writing Fall 2003 Lecture 10, 10/30/2003 Prof. Roy Levow.
Cs7100(Prasad)L8Proc1 Procedures. cs7100(Prasad)L8Proc2 Primitive procedures  etc User-defined procedures –Naming a sequence of operations.
Interpretation Environments and Evaluation. CS 354 Spring Translation Stages Lexical analysis (scanning) Parsing –Recognizing –Building parse tree.
Meta IFL 2007 Freiburg1 Meta - Towards a Functional-Style Interface for C++ Template Metaprograms * Ádám Sipos, Zoltán Porkoláb, Norbert Pataki, Viktória.
May 16-18, Skeletons and Asynchronous RPC for Embedded Data- and Task Parallel Image Processing IAPR Conference on Machine Vision Applications Wouter.
Compiler design Lecture 1: Compiler Overview Sulaimany University 2 Oct
Chapter 1 Introduction. Chapter 1 - Introduction 2 The Goal of Chapter 1 Introduce different forms of language translators Give a high level overview.
Introduction CPSC 388 Ellen Walker Hiram College.
David LOU – Project Manager Markus SCHANTA – Language Guru Long CHEN – System Architect Xiaolong JIANG – System Integrator Jingbo YANG – Tester & Validator.
Cs3180 (Prasad)L156HOF1 Higher-Order Functions. cs3180 (Prasad)L156HOF2 Equivalent Notations (define (f x y) (… body …)) = (define f (lambda (x y) (…
2000 Research Overview Dr. Kim Mens Programming Technology Lab Vrije Universiteit Brussel.
Overview of Compilation Prepared by Manuel E. Bermúdez, Ph.D. Associate Professor University of Florida Programming Language Principles Lecture 2.
UNIVERSITY OF SOUTH CAROLINA Department of Computer Science and Engineering CSCE 330 Programming Language Structures Operational Semantics (Slides mainly.
ECE 750 Topic 8 Meta-programming languages, systems, and applications Automatic Program Specialization for J ava – U. P. Schultz, J. L. Lawall, C. Consel.
Announcements. Practice questions, with and without solutions will be uploaded by Friday 5 th November, make sure to check them before the weekend \\netstorage\Subjects\ITCA-b\Exam.
CMPSC 16 Problem Solving with Computers I Spring 2014 Instructor: Tevfik Bultan Lecture 6: Stepwise refinement revisited, Midterm review.
Functional Programming
Chapter 14 Functions.
Names and Attributes Names are a key programming language feature
Lesson #6 Modular Programming and Functions.
A Simple Syntax-Directed Translator
Information Science and Engineering
Programming Languages Translator
Lesson #6 Modular Programming and Functions.
CSE687 - Object Oriented Design class notes Survey of the C++ Programming Language Jim Fawcett Spring 2004.
Principles of programming languages 4: Parameter passing, Scope rules
Revision Lecture
C-language Lecture By B.S.S.Tejesh, S.Neeraja Asst.Prof.
Closures and Streams cs784(Prasad) L11Clos
User-Defined Functions
Lesson #6 Modular Programming and Functions.
6.001 SICP Data abstractions
Important Concepts from Clojure
Important Concepts from Clojure
Overview of Compilation The Compiler BACK End
Recursion and Implementation of Functions
Lesson #6 Modular Programming and Functions.
Important Concepts from Clojure
Functional Programming and Haskell
Recursive Procedures and Scopes
Introduction to C Programming
CPS125.
Functions that return a value
Functional Programming and Haskell
Presentation transcript:

November 30, Pseudo-dynamic C metaprogramming Using strategic term rewriting and partial evaluation 7 th Stratego User Days Wouter Caarls Quantitative Imaging Group, Department of Imaging Science and Technology, Faculty of Applied Sciences

November 30, Motivation SIMD VLIW SS SIMD VLIW SS ? Parallel Heterogeneous Architecture independent

November 30, Sensor SIMD SS Programming Task parallelism Stream computing STREAM image, gx, g, hess, extrema; double sigma = 1; capture(image); gaussx(image, &sigma, gx); gaussy(gx, &sigma, g); hessian(image, hess); findextrema(g, extrema); filterextrema(extrema, hess, extrema); cap gx gyhess find filt

November 30, Programming Data parallelism (Algorithmic) skeletons += += SkeletonKernelOperation

November 30, Skeleton instantiation XTC target language (for SIMD) NeighbourhoodToPixelOp() erodex(in stream int i[0][-2..2], out stream int *o) { int x, val=0; for (x=-2; x <= 2; x++) if (i[0][x] < val) val = i[0][x]; *o = val; } if (task_type==ERODEX) { lmem arg0, arg1; while (ReadLine(&arg0)) { reg x; lmem val=0; for (x=-2; x <= 2; x++) (arg0[x] < val)?arg0[x]:val; arg1 = val; WriteLine(&arg1); } Program generation Pattern substitution Analysis & transformation

November 30, Skeleton instantiation language Extend C to a dynamic metaprogramming language Call library transformation functions for simple pattern substitutions Embed Stratego for more involved transformations ? Target does not support dynamic metaprogramming ! Require all metaprogramming to depend only on compile-time values, and partially evaluate

November 30, Dynamic C metaprogramming Representation code datatype Construction ` quotation $ antiquotation evaluation int x = 3; code c = `x * $x`; x = 4; printf("x * $x = >> X * $x = 12 code myint = `int`; code myx = 5; printf(“x = %d\n”, x); >> x = 5

November 30, Calling transformations The only operations defined on code are assignment (includes parameter passing) and evaluation All code manipulation is done by calling transformations int equals(code a, code b); if (equals(arguments[0].datatype, arguments[1].datatype)) … code replace(code pattern, code replacement, code term); body = replace(`*o`, `arg1`, body); body = `arg0[PH1]`, body);

November 30, Defining transformations All transformations are done using Stratego Stratego transformations can be embedded stratego int contains(code subterm, code term) { imports simple-traversal strategies main = (term) < !|[ 1 ]| + !|[ 0 ]| }

November 30, Partial evaluation by interpretation double n, x=1; int ii, iterations=3; scanf(“%lf”, &n); for (ii=0; ii < iterations; ii++) x = (x + n/x)/2; printf(“sqrt(%f) = %f\n”, n, x); double n; double x; int ii; int iterations; x = 1; iterations = 3; scanf(“%lf”, &n); ii = 0; x = (1 + n/1)/2; ii = 1; x = (x + n/x)/2; ii = 2; x = (x + n/x)/2; ii = 3; printf(“sqrt(%f) = %f\n”, n, x); doublen doublex intii intiterations Symbol table InputOutput ?1?1 ?1?3?1?3 ?103?103 ??03??03 ??13??13 ??23??23 ??33??33

November 30, Compilation flow

November 30, Implementation issues “static” code is defined by the fidelity of the partial evaluator Code fragments are dynamically scoped (use lambda library function to capture variables) Single translation unit (first preprocessed) Grammar is based on c-tools Strategies and rules in Stratego functions may clash Identifying metavariables by name is unsatisfactory

November 30, Contact details SmartCam Website

November 30, Example skeletons Pixel Neighbourhood Recursive neighbourhood Stack Filter Associative reduction

November 30, SmartCam Design Framework Skeletal App Kernels MainTrace Dissect Instan- tiate Simulate Skele- tons Skele- tons Opera- tions Opera- tions Bench- marks Bench- marks Architec- ture Perfor- mance Simulate Instan- tiate Arch. template