Presentation is loading. Please wait.

Presentation is loading. Please wait.

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

Similar presentations


Presentation on theme: "November 30, 2006 1 Pseudo-dynamic C metaprogramming Using strategic term rewriting and partial evaluation 7 th Stratego User Days Wouter Caarls Quantitative."— Presentation transcript:

1 November 30, 2006 1 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

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

3 November 30, 20063 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

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

5 November 30, 20065 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

6 November 30, 20066 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

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

8 November 30, 20068 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 = replace(`$@(arguments[0].id)[0][PH1]`, `arg0[PH1]`, body);

9 November 30, 20069 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 ]| }

10 November 30, 200610 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

11 November 30, 200611 Compilation flow

12 November 30, 200612 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

13 November 30, 200613 Contact details SmartCam Website http://www.qi.tnw.tudelft.nl/~wcaarls/smartcam E-mail mailto:w.caarls@tudelft.nl

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

15 November 30, 200615 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


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

Similar presentations


Ads by Google