From ddfe4932ac440ad2153abadb0583e88fc6676b71 Mon Sep 17 00:00:00 2001 From: Matt Pharr Date: Mon, 19 Mar 2012 11:27:32 -0700 Subject: [PATCH] Fix parsing of 'launch' so that angle brackets can be removed. Issue #6. --- docs/ispc.rst | 8 +-- examples/aobench/ao.ispc | 2 +- examples/aobench_instrumented/ao.ispc | 2 +- examples/deferred/kernels.ispc | 6 +- examples/mandelbrot_tasks/mandelbrot.ispc | 4 +- examples/options/options.ispc | 4 +- examples/rt/rt.ispc | 6 +- examples/stencil/stencil.ispc | 8 +-- examples/volume_rendering/volume.ispc | 4 +- parse.yy | 61 +++++++++++++++----- tests/launch-1.ispc | 2 +- tests/launch-2.ispc | 2 +- tests/launch-3.ispc | 2 +- tests/launch-4.ispc | 2 +- tests/launch-5.ispc | 2 +- tests/launch-6.ispc | 4 +- tests/launch-7.ispc | 4 +- tests_errors/func-call-through-variable.ispc | 2 +- tests_errors/old-launch-syntax.ispc | 27 +++++++++ 19 files changed, 104 insertions(+), 48 deletions(-) create mode 100644 tests_errors/old-launch-syntax.ispc diff --git a/docs/ispc.rst b/docs/ispc.rst index 61f4a21a..4be80a18 100644 --- a/docs/ispc.rst +++ b/docs/ispc.rst @@ -2666,9 +2666,9 @@ of the overall computation it's responsible for: :: for (uniform int i = 0; i < 100; ++i) - launch < func(a, i) >; + launch func(a, i); -Note the ``launch`` keyword and the brackets around the function call. +Note the ``launch`` keyword before the function call expression. This code launches 100 tasks, each of which presumably does some computation that is keyed off of given the value ``i``. In general, one should launch many more tasks than there are processors in the system to @@ -2681,7 +2681,7 @@ statement. We might instead write the above example with a single :: - launch[100] < func2(a) >; + launch[100] func2(a); Where an integer value (not necessarily a compile-time constant) is provided to the ``launch`` keyword in square brackets; this number of tasks @@ -2707,7 +2707,7 @@ statement to wait for all launched tasks to finish: :: - launch[100] < func2(a) >; + launch[100] func2(a); sync; // now safe to use computed values in a[]... diff --git a/examples/aobench/ao.ispc b/examples/aobench/ao.ispc index 556e4cde..692dc367 100644 --- a/examples/aobench/ao.ispc +++ b/examples/aobench/ao.ispc @@ -268,5 +268,5 @@ static void task ao_task(uniform int width, uniform int height, export void ao_ispc_tasks(uniform int w, uniform int h, uniform int nsubsamples, uniform float image[]) { - launch[h] < ao_task(w, h, nsubsamples, image) >; + launch[h] ao_task(w, h, nsubsamples, image); } diff --git a/examples/aobench_instrumented/ao.ispc b/examples/aobench_instrumented/ao.ispc index 3deaa340..06d9b505 100644 --- a/examples/aobench_instrumented/ao.ispc +++ b/examples/aobench_instrumented/ao.ispc @@ -329,5 +329,5 @@ static void task ao_task(uniform int width, uniform int height, export void ao_ispc_tasks(uniform int w, uniform int h, uniform int nsubsamples, uniform float image[]) { - launch[h] < ao_task(w, h, nsubsamples, image) >; + launch[h] ao_task(w, h, nsubsamples, image); } diff --git a/examples/deferred/kernels.ispc b/examples/deferred/kernels.ispc index 6a20d45e..a2ca1111 100644 --- a/examples/deferred/kernels.ispc +++ b/examples/deferred/kernels.ispc @@ -514,9 +514,9 @@ RenderStatic(uniform InputHeader &inputHeader, // Launch a task to render each tile, each of which is MIN_TILE_WIDTH // by MIN_TILE_HEIGHT pixels. - launch[num_groups] < RenderTile(num_groups_x, num_groups_y, - inputHeader, inputData, visualizeLightCount, - framebuffer_r, framebuffer_g, framebuffer_b) >; + launch[num_groups] RenderTile(num_groups_x, num_groups_y, + inputHeader, inputData, visualizeLightCount, + framebuffer_r, framebuffer_g, framebuffer_b); } diff --git a/examples/mandelbrot_tasks/mandelbrot.ispc b/examples/mandelbrot_tasks/mandelbrot.ispc index 786e49f1..ef99dd72 100644 --- a/examples/mandelbrot_tasks/mandelbrot.ispc +++ b/examples/mandelbrot_tasks/mandelbrot.ispc @@ -79,6 +79,6 @@ mandelbrot_ispc(uniform float x0, uniform float y0, uniform float dy = (y1 - y0) / height; uniform int span = 4; - launch[height/span] < mandelbrot_scanline(x0, dx, y0, dy, width, height, span, - maxIterations, output) >; + launch[height/span] mandelbrot_scanline(x0, dx, y0, dy, width, height, span, + maxIterations, output); } diff --git a/examples/options/options.ispc b/examples/options/options.ispc index 00f5b602..8cf69cf5 100644 --- a/examples/options/options.ispc +++ b/examples/options/options.ispc @@ -77,7 +77,7 @@ black_scholes_ispc_tasks(uniform float Sa[], uniform float Xa[], uniform float T uniform float ra[], uniform float va[], uniform float result[], uniform int count) { uniform int nTasks = max((int)64, (int)count/16384); - launch[nTasks] < bs_task(Sa, Xa, Ta, ra, va, result, count) >; + launch[nTasks] bs_task(Sa, Xa, Ta, ra, va, result, count); } @@ -150,5 +150,5 @@ binomial_put_ispc_tasks(uniform float Sa[], uniform float Xa[], uniform float va[], uniform float result[], uniform int count) { uniform int nTasks = max((int)64, (int)count/16384); - launch[nTasks] < binomial_task(Sa, Xa, Ta, ra, va, result, count) >; + launch[nTasks] binomial_task(Sa, Xa, Ta, ra, va, result, count); } diff --git a/examples/rt/rt.ispc b/examples/rt/rt.ispc index 490dc5c1..dcba73ba 100644 --- a/examples/rt/rt.ispc +++ b/examples/rt/rt.ispc @@ -304,8 +304,8 @@ export void raytrace_ispc_tasks(uniform int width, uniform int height, uniform int xBuckets = (width + (dx-1)) / dx; uniform int yBuckets = (height + (dy-1)) / dy; uniform int nTasks = xBuckets * yBuckets; - launch[nTasks] < raytrace_tile_task(width, height, baseWidth, baseHeight, - raster2camera, camera2world, - image, id, nodes, triangles) >; + launch[nTasks] raytrace_tile_task(width, height, baseWidth, baseHeight, + raster2camera, camera2world, + image, id, nodes, triangles); } diff --git a/examples/stencil/stencil.ispc b/examples/stencil/stencil.ispc index 0d3c2435..0892989d 100644 --- a/examples/stencil/stencil.ispc +++ b/examples/stencil/stencil.ispc @@ -88,11 +88,11 @@ loop_stencil_ispc_tasks(uniform int t0, uniform int t1, // Parallelize across cores as well: each task will work on a slice // of 1 in the z extent of the volume. if ((t & 1) == 0) - launch[z1-z0] < stencil_step_task(x0, x1, y0, y1, z0, Nx, Ny, Nz, - coef, vsq, Aeven, Aodd) >; + launch[z1-z0] stencil_step_task(x0, x1, y0, y1, z0, Nx, Ny, Nz, + coef, vsq, Aeven, Aodd); else - launch[z1-z0] < stencil_step_task(x0, x1, y0, y1, z0, Nx, Ny, Nz, - coef, vsq, Aodd, Aeven) >; + launch[z1-z0] stencil_step_task(x0, x1, y0, y1, z0, Nx, Ny, Nz, + coef, vsq, Aodd, Aeven); // We need to wait for all of the launched tasks to finish before // starting the next iteration. diff --git a/examples/volume_rendering/volume.ispc b/examples/volume_rendering/volume.ispc index 7402976a..a60c6a42 100644 --- a/examples/volume_rendering/volume.ispc +++ b/examples/volume_rendering/volume.ispc @@ -336,6 +336,6 @@ volume_ispc_tasks(uniform float density[], uniform int nVoxels[3], // Launch tasks to work on (dx,dy)-sized tiles of the image uniform int dx = 8, dy = 8; uniform int nTasks = ((width+(dx-1))/dx) * ((height+(dy-1))/dy); - launch[nTasks] < volume_task(density, nVoxels, raster2camera, camera2world, - width, height, image) >; + launch[nTasks] volume_task(density, nVoxels, raster2camera, camera2world, + width, height, image); } diff --git a/parse.yy b/parse.yy index 73d2b11f..981f3fd8 100644 --- a/parse.yy +++ b/parse.yy @@ -194,7 +194,7 @@ struct ForeachDimension { %token TOKEN_CCONTINUE TOKEN_CRETURN TOKEN_SYNC TOKEN_PRINT TOKEN_ASSERT %type primary_expression postfix_expression -%type unary_expression cast_expression launch_expression +%type unary_expression cast_expression funcall_expression launch_expression %type multiplicative_expression additive_expression shift_expression %type relational_expression equality_expression and_expression %type exclusive_or_expression inclusive_or_expression @@ -302,20 +302,45 @@ primary_expression ; launch_expression - : TOKEN_LAUNCH '<' postfix_expression '(' argument_expression_list ')' '>' + : TOKEN_LAUNCH postfix_expression '(' argument_expression_list ')' { - ConstExpr *oneExpr = new ConstExpr(AtomicType::UniformInt32, (int32_t)1, @3); - $$ = new FunctionCallExpr($3, $5, Union(@3, @6), true, oneExpr); + ConstExpr *oneExpr = new ConstExpr(AtomicType::UniformInt32, (int32_t)1, @2); + $$ = new FunctionCallExpr($2, $4, Union(@2, @5), true, oneExpr); } - | TOKEN_LAUNCH '<' postfix_expression '(' ')' '>' + | TOKEN_LAUNCH postfix_expression '(' ')' { - ConstExpr *oneExpr = new ConstExpr(AtomicType::UniformInt32, (int32_t)1, @3); - $$ = new FunctionCallExpr($3, new ExprList(Union(@4,@5)), Union(@3, @5), true, oneExpr); + ConstExpr *oneExpr = new ConstExpr(AtomicType::UniformInt32, (int32_t)1, @2); + $$ = new FunctionCallExpr($2, new ExprList(Union(@3,@4)), Union(@2, @4), true, oneExpr); + } + | TOKEN_LAUNCH '[' expression ']' postfix_expression '(' argument_expression_list ')' + { $$ = new FunctionCallExpr($5, $7, Union(@5,@8), true, $3); } + | TOKEN_LAUNCH '[' expression ']' postfix_expression '(' ')' + { $$ = new FunctionCallExpr($5, new ExprList(Union(@5,@6)), Union(@5,@7), true, $3); } + + | TOKEN_LAUNCH '<' postfix_expression '(' argument_expression_list ')' '>' + { + Error(Union(@2, @7), "\"launch\" expressions no longer take '<' '>' " + "around function call expression."); + $$ = NULL; + } + | TOKEN_LAUNCH '<' postfix_expression '(' ')' '>' + { + Error(Union(@2, @6), "\"launch\" expressions no longer take '<' '>' " + "around function call expression."); + $$ = NULL; } | TOKEN_LAUNCH '[' expression ']' '<' postfix_expression '(' argument_expression_list ')' '>' - { $$ = new FunctionCallExpr($6, $8, Union(@6,@9), true, $3); } + { + Error(Union(@5, @10), "\"launch\" expressions no longer take '<' '>' " + "around function call expression."); + $$ = NULL; + } | TOKEN_LAUNCH '[' expression ']' '<' postfix_expression '(' ')' '>' - { $$ = new FunctionCallExpr($6, new ExprList(Union(@6,@7)), Union(@6,@8), true, $3); } + { + Error(Union(@5, @9), "\"launch\" expressions no longer take '<' '>' " + "around function call expression."); + $$ = NULL; + } ; postfix_expression @@ -324,12 +349,6 @@ postfix_expression { $$ = new IndexExpr($1, $3, Union(@1,@4)); } | postfix_expression '[' error ']' { $$ = NULL; } - | postfix_expression '(' ')' - { $$ = new FunctionCallExpr($1, new ExprList(Union(@1,@2)), Union(@1,@3)); } - | postfix_expression '(' argument_expression_list ')' - { $$ = new FunctionCallExpr($1, $3, Union(@1,@4)); } - | postfix_expression '(' error ')' - { $$ = NULL; } | launch_expression | postfix_expression '.' TOKEN_IDENTIFIER { $$ = MemberExpr::create($1, yytext, Union(@1,@3), @3, false); } @@ -341,6 +360,16 @@ postfix_expression { $$ = new UnaryExpr(UnaryExpr::PostDec, $1, Union(@1,@2)); } ; +funcall_expression + : postfix_expression + | postfix_expression '(' ')' + { $$ = new FunctionCallExpr($1, new ExprList(Union(@1,@2)), Union(@1,@3)); } + | postfix_expression '(' argument_expression_list ')' + { $$ = new FunctionCallExpr($1, $3, Union(@1,@4)); } + | postfix_expression '(' error ')' + { $$ = NULL; } + ; + argument_expression_list : assignment_expression { $$ = new ExprList($1, @1); } | argument_expression_list ',' assignment_expression @@ -357,7 +386,7 @@ argument_expression_list ; unary_expression - : postfix_expression + : funcall_expression | TOKEN_INC_OP unary_expression { $$ = new UnaryExpr(UnaryExpr::PreInc, $2, Union(@1, @2)); } | TOKEN_DEC_OP unary_expression diff --git a/tests/launch-1.ispc b/tests/launch-1.ispc index c8ca0207..5c5f9966 100644 --- a/tests/launch-1.ispc +++ b/tests/launch-1.ispc @@ -15,7 +15,7 @@ task void x(float f) { } export void f_f(uniform float RET[], uniform float fFOO[]) { float f = fFOO[programIndex]; - launch[10000] < x(f) >; + launch[10000] x(f); sync; RET[programIndex] = array[9999]; } diff --git a/tests/launch-2.ispc b/tests/launch-2.ispc index 4f24f2b2..4e6e2969 100644 --- a/tests/launch-2.ispc +++ b/tests/launch-2.ispc @@ -15,7 +15,7 @@ export void f_f(uniform float RET[], uniform float fFOO[]) { float f = fFOO[programIndex]; uniform int i; cfor (i = 0; i < 10000; ++i) - launch < x(i, f) >; + launch x(i, f); sync; RET[programIndex] = array[9999]; } diff --git a/tests/launch-3.ispc b/tests/launch-3.ispc index 3b6d73e9..87624221 100644 --- a/tests/launch-3.ispc +++ b/tests/launch-3.ispc @@ -8,7 +8,7 @@ task void x(uniform int i, float f) { } export void f_fu(uniform float RET[], uniform float fFOO[], uniform float fu) { float f = fFOO[programIndex]; - launch < x(fu, f) >; + launch x(fu, f); sync; RET[programIndex] = array[5]; } diff --git a/tests/launch-4.ispc b/tests/launch-4.ispc index 65231b5e..7af64315 100644 --- a/tests/launch-4.ispc +++ b/tests/launch-4.ispc @@ -8,7 +8,7 @@ task void x(uniform int i, float f) { } export void f_fu(uniform float RET[], uniform float fFOO[], uniform float fu) { float f = fFOO[programIndex]; - launch[1] < x(fu, f) >; + launch[1] x(fu, f); sync; RET[programIndex] = array[5]; } diff --git a/tests/launch-5.ispc b/tests/launch-5.ispc index cea927da..c64af0bb 100644 --- a/tests/launch-5.ispc +++ b/tests/launch-5.ispc @@ -15,7 +15,7 @@ export void f_f(uniform float RET[], uniform float fFOO[]) { float f = fFOO[programIndex]; uniform int i; for (i = 0; i < 10000; ++i) - launch < x(i, f) >; + launch x(i, f); sync; RET[programIndex] = array[9999]; } diff --git a/tests/launch-6.ispc b/tests/launch-6.ispc index d3b95468..8e73d093 100644 --- a/tests/launch-6.ispc +++ b/tests/launch-6.ispc @@ -6,8 +6,8 @@ static uniform float array[10]; task void foo(uniform float f) { array[0] = f; } task void foo(uniform float f, uniform int i) { array[i] = f; } export void f_v(uniform float RET[]) { - launch < foo(12.) >; - launch < foo(-1., 1) >; + launch foo(12.); + launch foo(-1., 1); sync; RET[programIndex] = array[0] + array[1]; } diff --git a/tests/launch-7.ispc b/tests/launch-7.ispc index 08a01432..7c2cfc00 100644 --- a/tests/launch-7.ispc +++ b/tests/launch-7.ispc @@ -7,8 +7,8 @@ task void foo(uniform float f) { array[0] = f; } task void foo(uniform float f, uniform int i) { array[i] = f; } export void f_v(uniform float RET[]) { - launch[1] < foo(12.) >; - launch[1] < foo(-1., 1) >; + launch[1] foo(12.); + launch[1] foo(-1., 1); sync; RET[programIndex] = array[0] + array[1]; } diff --git a/tests_errors/func-call-through-variable.ispc b/tests_errors/func-call-through-variable.ispc index 3a857e79..5b3b7323 100644 --- a/tests_errors/func-call-through-variable.ispc +++ b/tests_errors/func-call-through-variable.ispc @@ -43,5 +43,5 @@ uniform float result[]) uniform int span = N / 8; // 8 tasks -launch[N/span] < saxpy_ispc_task(N, span, scale, X, Y, result) >; +launch[N/span] saxpy_ispc_task(N, span, scale, X, Y, result); } diff --git a/tests_errors/old-launch-syntax.ispc b/tests_errors/old-launch-syntax.ispc new file mode 100644 index 00000000..d39c066a --- /dev/null +++ b/tests_errors/old-launch-syntax.ispc @@ -0,0 +1,27 @@ +// "launch" expressions no longer take '<' '>' around function call expression. + +export uniform int width() { return programCount; } + + +static uniform float array[10000]; + +task void x(float f) { + uniform int j; + uniform int i = taskIndex; + array[i] = i / 10000.; + cfor (j = 0; j < 10000; ++j) + array[i] = sin(array[i]); + if (array[i] < .02) + array[i] = i; +} +export void f_f(uniform float RET[], uniform float fFOO[]) { + float f = fFOO[programIndex]; + launch[10000] < x(f) >; + sync; + RET[programIndex] = array[9999]; +} + + +export void result(uniform float RET[]) { + RET[programIndex] = 9999.000000; +}