Fix parsing of 'launch' so that angle brackets can be removed.

Issue #6.
This commit is contained in:
Matt Pharr
2012-03-19 11:27:32 -07:00
parent 28ac016928
commit ddfe4932ac
19 changed files with 104 additions and 48 deletions

View File

@@ -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[]...

View File

@@ -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);
}

View File

@@ -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);
}

View File

@@ -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);
}

View File

@@ -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);
}

View File

@@ -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);
}

View File

@@ -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);
}

View File

@@ -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.

View File

@@ -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);
}

View File

@@ -194,7 +194,7 @@ struct ForeachDimension {
%token TOKEN_CCONTINUE TOKEN_CRETURN TOKEN_SYNC TOKEN_PRINT TOKEN_ASSERT
%type <expr> primary_expression postfix_expression
%type <expr> unary_expression cast_expression launch_expression
%type <expr> unary_expression cast_expression funcall_expression launch_expression
%type <expr> multiplicative_expression additive_expression shift_expression
%type <expr> relational_expression equality_expression and_expression
%type <expr> 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

View File

@@ -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];
}

View File

@@ -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];
}

View File

@@ -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];
}

View File

@@ -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];
}

View File

@@ -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];
}

View File

@@ -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];
}

View File

@@ -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];
}

View File

@@ -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);
}

View File

@@ -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;
}