changed notation, task[Index,Count]_[x,y,z] -> task[Index,Count][1,2,3]. Change launch <<< nx,ny,nz >>> into launch [nx,ny,nz] or equivalent launch [nz][ny][nx]. Programmer can pick the one the is liked the most

This commit is contained in:
Evghenii
2013-10-24 13:16:23 +02:00
parent e6c8765891
commit 43761173ec
7 changed files with 122 additions and 120 deletions

View File

@@ -59,16 +59,10 @@ mandelbrot_scanline(uniform float x0, uniform float dx,
uniform int width, uniform int height, uniform int width, uniform int height,
uniform int xspan, uniform int yspan, uniform int xspan, uniform int yspan,
uniform int maxIterations, uniform int output[]) { uniform int maxIterations, uniform int output[]) {
#if 0 const uniform int xstart = taskIndex1 * xspan;
print("taskIndex = % : % \n", taskIndex);
print("taskIndex_x= % : % \n", taskIndex_x);
print("taskIndex_y= % : % \n", taskIndex_y);
print(" --- \n");
#endif
const uniform int xstart = taskIndex_x * xspan;
const uniform int xend = min(xstart + xspan, width); const uniform int xend = min(xstart + xspan, width);
const uniform int ystart = taskIndex_y * yspan; const uniform int ystart = taskIndex2 * yspan;
const uniform int yend = min(ystart + yspan, height); const uniform int yend = min(ystart + yspan, height);
@@ -90,10 +84,15 @@ mandelbrot_ispc(uniform float x0, uniform float y0,
uniform int maxIterations, uniform int output[]) { uniform int maxIterations, uniform int output[]) {
uniform float dx = (x1 - x0) / width; uniform float dx = (x1 - x0) / width;
uniform float dy = (y1 - y0) / height; uniform float dy = (y1 - y0) / height;
const uniform int xspan = 16; const uniform int xspan = 16; /* make sure it is big enough to avoid false-sharing */
const uniform int yspan = 16; const uniform int yspan = 16;
launch <<<width/xspan, height/yspan>>>
#if 1
launch [width/xspan, height/yspan]
#else
launch [height/yspan][width/xspan]
#endif
mandelbrot_scanline(x0, dx, y0, dy, width, height, xspan, yspan, mandelbrot_scanline(x0, dx, y0, dy, width, height, xspan, yspan,
maxIterations, output); maxIterations, output);
} }

View File

@@ -171,8 +171,8 @@
// Signature of ispc-generated 'task' functions // Signature of ispc-generated 'task' functions
typedef void (*TaskFuncType)(void *data, int threadIndex, int threadCount, typedef void (*TaskFuncType)(void *data, int threadIndex, int threadCount,
int taskIndex, int taskCount, int taskIndex, int taskCount,
int taskIndex_x, int taskIndex_y, int taskIndex_z, int taskIndex1, int taskIndex2, int taskIndex3,
int taskCount_x, int taskCount_y, int taskCount_z); int taskCount1, int taskCount2, int taskCount3);
// Small structure used to hold the data for each task // Small structure used to hold the data for each task
struct TaskInfo { struct TaskInfo {
@@ -183,21 +183,21 @@ struct TaskInfo {
#if defined(ISPC_IS_WINDOWS) #if defined(ISPC_IS_WINDOWS)
event taskEvent; event taskEvent;
#endif #endif
int taskIndex_x() const int taskIndex1() const
{ {
return taskIndex % taskCount3d[0]; return taskIndex % taskCount3d[0];
} }
int taskIndex_y() const int taskIndex2() const
{ {
return ( taskIndex / taskCount3d[0] ) % taskCount3d[1]; return ( taskIndex / taskCount3d[0] ) % taskCount3d[1];
} }
int taskIndex_z() const int taskIndex3() const
{ {
return taskIndex / ( taskCount3d[0]*taskCount3d[1] ); return taskIndex / ( taskCount3d[0]*taskCount3d[1] );
} }
int taskCount_x() const { return taskCount3d[0]; } int taskCount1() const { return taskCount3d[0]; }
int taskCount_y() const { return taskCount3d[1]; } int taskCount2() const { return taskCount3d[1]; }
int taskCount_z() const { return taskCount3d[2]; } int taskCount3() const { return taskCount3d[2]; }
}; };
// ispc expects these functions to have C linkage / not be mangled // ispc expects these functions to have C linkage / not be mangled
@@ -537,8 +537,8 @@ lRunTask(void *ti) {
// Actually run the task // Actually run the task
taskInfo->func(taskInfo->data, threadIndex, threadCount, taskInfo->func(taskInfo->data, threadIndex, threadCount,
taskInfo->taskIndex, taskInfo->taskCount, taskInfo->taskIndex, taskInfo->taskCount,
taskInfo->taskIndex_x(), taskInfo->taskIndex_y(), taskInfo->taskIndex_z(), taskInfo->taskIndex1(), taskInfo->taskIndex2(), taskInfo->taskIndex3(),
taskInfo->taskCount_x(), taskInfo->taskCount_y(), taskInfo->taskCount_z()); taskInfo->taskCount1(), taskInfo->taskCount2(), taskInfo->taskCount3());
} }
@@ -580,8 +580,8 @@ lRunTask(LPVOID param) {
int threadIndex = 0; int threadIndex = 0;
int threadCount = 1; int threadCount = 1;
ti->func(ti->data, threadIndex, threadCount, ti->taskIndex, ti->taskCount, ti->func(ti->data, threadIndex, threadCount, ti->taskIndex, ti->taskCount,
ti->taskIndex_x(), ti->taskIndex_y(), ti->taskIndex_z(), ti->taskIndex1(), ti->taskIndex2(), ti->taskIndex3(),
ti->taskCount_x(), ti->taskCount_y(), ti->taskCount_z()); ti->taskCount1(), ti->taskCount2(), ti->taskCount3());
// Signal the event that this task is done // Signal the event that this task is done
ti->taskEvent.set(); ti->taskEvent.set();
@@ -683,8 +683,8 @@ lTaskEntry(void *arg) {
TaskInfo *myTask = tg->GetTaskInfo(taskNumber); TaskInfo *myTask = tg->GetTaskInfo(taskNumber);
myTask->func(myTask->data, threadIndex, threadCount, myTask->taskIndex, myTask->func(myTask->data, threadIndex, threadCount, myTask->taskIndex,
myTask->taskCount, myTask->taskCount,
myTask->taskIndex_x(), myTask->taskIndex_y(), myTask->taskIndex_z(), myTask->taskIndex1(), myTask->taskIndex2(), myTask->taskIndex3(),
myTask->taskCount_x(), myTask->taskCount_y(), myTask->taskCount_z()); myTask->taskCount1(), myTask->taskCount2(), myTask->taskCount3());
// //
// Decrement the "number of unfinished tasks" counter in the task // Decrement the "number of unfinished tasks" counter in the task
@@ -886,8 +886,8 @@ TaskGroup::Sync() {
// //
// FIXME: bogus values for thread index/thread count here as well.. // FIXME: bogus values for thread index/thread count here as well..
myTask->func(myTask->data, 0, 1, myTask->taskIndex, myTask->taskCount, myTask->func(myTask->data, 0, 1, myTask->taskIndex, myTask->taskCount,
myTask->taskIndex_x(), myTask->taskIndex_y(), myTask->taskIndex_z(), myTask->taskIndex1(), myTask->taskIndex2(), myTask->taskIndex3(),
myTask->taskCount_x(), myTask->taskCount_y(), myTask->taskCount_z()); myTask->taskCount1(), myTask->taskCount2(), myTask->taskCount3());
// //
// Decrement the number of unfinished tasks counter // Decrement the number of unfinished tasks counter
@@ -918,8 +918,8 @@ TaskGroup::Launch(int baseIndex, int count) {
// Actually run the task. // Actually run the task.
// Cilk does not expose the task -> thread mapping so we pretend it's 1:1 // Cilk does not expose the task -> thread mapping so we pretend it's 1:1
ti->func(ti->data, ti->taskIndex, ti->taskCount, ti->taskIndex, ti->taskCount, ti->func(ti->data, ti->taskIndex, ti->taskCount, ti->taskIndex, ti->taskCount,
ti->taskIndex_x(), ti->taskIndex_y(), ti->taskIndex_z(), ti->taskIndex1(), ti->taskIndex2(), ti->taskIndex3(),
ti->taskCount_x(), ti->taskCount_y(), ti->taskCount_z()); ti->taskCount1(), ti->taskCount2(), ti->taskCount3());
} }
} }
@@ -949,8 +949,8 @@ TaskGroup::Launch(int baseIndex, int count) {
int threadIndex = omp_get_thread_num(); int threadIndex = omp_get_thread_num();
int threadCount = omp_get_num_threads(); int threadCount = omp_get_num_threads();
ti->func(ti->data, threadIndex, threadCount, ti->taskIndex, ti->taskCount, ti->func(ti->data, threadIndex, threadCount, ti->taskIndex, ti->taskCount,
ti->taskIndex_x(), ti->taskIndex_y(), ti->taskIndex_z(), ti->taskIndex1(), ti->taskIndex2(), ti->taskIndex3(),
ti->taskCount_x(), ti->taskCount_y(), ti->taskCount_z()); ti->taskCount1(), ti->taskCount2(), ti->taskCount3());
} }
} }
@@ -982,8 +982,8 @@ TaskGroup::Launch(int baseIndex, int count) {
int threadCount = ti->taskCount; int threadCount = ti->taskCount;
ti->func(ti->data, threadIndex, threadCount, ti->taskIndex, ti->taskCount, ti->func(ti->data, threadIndex, threadCount, ti->taskIndex, ti->taskCount,
ti->taskIndex_x(), ti->taskIndex_y(), ti->taskIndex_z(), ti->taskIndex1(), ti->taskIndex2(), ti->taskIndex3(),
ti->taskCount_x(), ti->taskCount_y(), ti->taskCount_z()); ti->taskCount1(), ti->taskCount2(), ti->taskCount3());
}); });
} }
@@ -1011,8 +1011,8 @@ TaskGroup::Launch(int baseIndex, int count) {
int threadIndex = ti->taskIndex; int threadIndex = ti->taskIndex;
int threadCount = ti->taskCount; int threadCount = ti->taskCount;
ti->func(ti->data, threadIndex, threadCount, ti->taskIndex, ti->taskCount, ti->func(ti->data, threadIndex, threadCount, ti->taskIndex, ti->taskCount,
ti->taskIndex_x(), ti->taskIndex_y(), ti->taskIndex_z(), ti->taskIndex1(), ti->taskIndex2(), ti->taskIndex3(),
ti->taskCount_x(), ti->taskCount_y(), ti->taskCount_z()); ti->taskCount1(), ti->taskCount2(), ti->taskCount3());
}); });
} }
} }
@@ -1065,8 +1065,8 @@ FreeTaskGroup(TaskGroup *tg) {
/////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////
void void
ISPCLaunch(void **taskGroupPtr, void *func, void *data, int countx, int county, int countz) { ISPCLaunch(void **taskGroupPtr, void *func, void *data, int count1, int count2, int count3) {
const int count = countx*county*countz; const int count = count1*count2*count3;
TaskGroup *taskGroup; TaskGroup *taskGroup;
if (*taskGroupPtr == NULL) { if (*taskGroupPtr == NULL) {
InitTaskSystem(); InitTaskSystem();
@@ -1083,9 +1083,9 @@ ISPCLaunch(void **taskGroupPtr, void *func, void *data, int countx, int county,
ti->data = data; ti->data = data;
ti->taskIndex = i; ti->taskIndex = i;
ti->taskCount = count; ti->taskCount = count;
ti->taskCount3d[0] = countx; ti->taskCount3d[0] = count1;
ti->taskCount3d[1] = county; ti->taskCount3d[1] = count2;
ti->taskCount3d[2] = countz; ti->taskCount3d[2] = count3;
} }
taskGroup->Launch(baseIndex, count); taskGroup->Launch(baseIndex, count);
} }

View File

@@ -133,26 +133,26 @@ Function::Function(Symbol *s, Stmt *c) {
taskCountSym = m->symbolTable->LookupVariable("taskCount"); taskCountSym = m->symbolTable->LookupVariable("taskCount");
Assert(taskCountSym); Assert(taskCountSym);
taskIndexSym_x = m->symbolTable->LookupVariable("taskIndex_x"); taskIndexSym1 = m->symbolTable->LookupVariable("taskIndex1");
Assert(taskIndexSym_x); Assert(taskIndexSym1);
taskIndexSym_y = m->symbolTable->LookupVariable("taskIndex_y"); taskIndexSym2 = m->symbolTable->LookupVariable("taskIndex2");
Assert(taskIndexSym_y); Assert(taskIndexSym2);
taskIndexSym_z = m->symbolTable->LookupVariable("taskIndex_z"); taskIndexSym3 = m->symbolTable->LookupVariable("taskIndex3");
Assert(taskIndexSym_z); Assert(taskIndexSym3);
taskCountSym_x = m->symbolTable->LookupVariable("taskCount_x"); taskCountSym1 = m->symbolTable->LookupVariable("taskCount1");
Assert(taskCountSym_x); Assert(taskCountSym1);
taskCountSym_y = m->symbolTable->LookupVariable("taskCount_y"); taskCountSym2 = m->symbolTable->LookupVariable("taskCount2");
Assert(taskCountSym_y); Assert(taskCountSym2);
taskCountSym_z = m->symbolTable->LookupVariable("taskCount_z"); taskCountSym3 = m->symbolTable->LookupVariable("taskCount3");
Assert(taskCountSym_z); Assert(taskCountSym3);
} }
else else
{ {
threadIndexSym = threadCountSym = taskIndexSym = taskCountSym = NULL; threadIndexSym = threadCountSym = taskIndexSym = taskCountSym = NULL;
taskIndexSym_x = taskIndexSym_y = taskIndexSym_z = NULL; taskIndexSym1 = taskIndexSym2 = taskIndexSym3 = NULL;
taskCountSym_x = taskCountSym_y = taskCountSym_z = NULL; taskCountSym1 = taskCountSym2 = taskCountSym3 = NULL;
} }
} }
@@ -244,12 +244,12 @@ Function::emitCode(FunctionEmitContext *ctx, llvm::Function *function,
llvm::Value *threadCount = argIter++; llvm::Value *threadCount = argIter++;
llvm::Value *taskIndex = argIter++; llvm::Value *taskIndex = argIter++;
llvm::Value *taskCount = argIter++; llvm::Value *taskCount = argIter++;
llvm::Value *taskIndex_x = argIter++; llvm::Value *taskIndex1 = argIter++;
llvm::Value *taskIndex_y = argIter++; llvm::Value *taskIndex2 = argIter++;
llvm::Value *taskIndex_z = argIter++; llvm::Value *taskIndex3 = argIter++;
llvm::Value *taskCount_x = argIter++; llvm::Value *taskCount1 = argIter++;
llvm::Value *taskCount_y = argIter++; llvm::Value *taskCount2 = argIter++;
llvm::Value *taskCount_z = argIter++; llvm::Value *taskCount3 = argIter++;
// Copy the function parameter values from the structure into local // Copy the function parameter values from the structure into local
// storage // storage
@@ -282,19 +282,19 @@ Function::emitCode(FunctionEmitContext *ctx, llvm::Function *function,
taskCountSym->storagePtr = ctx->AllocaInst(LLVMTypes::Int32Type, "taskCount"); taskCountSym->storagePtr = ctx->AllocaInst(LLVMTypes::Int32Type, "taskCount");
ctx->StoreInst(taskCount, taskCountSym->storagePtr); ctx->StoreInst(taskCount, taskCountSym->storagePtr);
taskIndexSym_x->storagePtr = ctx->AllocaInst(LLVMTypes::Int32Type, "taskIndex_x"); taskIndexSym1->storagePtr = ctx->AllocaInst(LLVMTypes::Int32Type, "taskIndex1");
ctx->StoreInst(taskIndex_x, taskIndexSym_x->storagePtr); ctx->StoreInst(taskIndex1, taskIndexSym1->storagePtr);
taskIndexSym_y->storagePtr = ctx->AllocaInst(LLVMTypes::Int32Type, "taskIndex_y"); taskIndexSym2->storagePtr = ctx->AllocaInst(LLVMTypes::Int32Type, "taskIndex2");
ctx->StoreInst(taskIndex_y, taskIndexSym_y->storagePtr); ctx->StoreInst(taskIndex2, taskIndexSym2->storagePtr);
taskIndexSym_z->storagePtr = ctx->AllocaInst(LLVMTypes::Int32Type, "taskIndex_z"); taskIndexSym3->storagePtr = ctx->AllocaInst(LLVMTypes::Int32Type, "taskIndex3");
ctx->StoreInst(taskIndex_z, taskIndexSym_z->storagePtr); ctx->StoreInst(taskIndex3, taskIndexSym3->storagePtr);
taskCountSym_x->storagePtr = ctx->AllocaInst(LLVMTypes::Int32Type, "taskCount_x"); taskCountSym1->storagePtr = ctx->AllocaInst(LLVMTypes::Int32Type, "taskCount1");
ctx->StoreInst(taskCount_x, taskCountSym_x->storagePtr); ctx->StoreInst(taskCount1, taskCountSym1->storagePtr);
taskCountSym_y->storagePtr = ctx->AllocaInst(LLVMTypes::Int32Type, "taskCount_y"); taskCountSym2->storagePtr = ctx->AllocaInst(LLVMTypes::Int32Type, "taskCount2");
ctx->StoreInst(taskCount_y, taskCountSym_y->storagePtr); ctx->StoreInst(taskCount2, taskCountSym2->storagePtr);
taskCountSym_z->storagePtr = ctx->AllocaInst(LLVMTypes::Int32Type, "taskCount_z"); taskCountSym3->storagePtr = ctx->AllocaInst(LLVMTypes::Int32Type, "taskCount3");
ctx->StoreInst(taskCount_z, taskCountSym_z->storagePtr); ctx->StoreInst(taskCount3, taskCountSym3->storagePtr);
} }
else { else {
// Regular, non-task function // Regular, non-task function

6
func.h
View File

@@ -61,9 +61,9 @@ private:
Symbol *maskSymbol; Symbol *maskSymbol;
Symbol *threadIndexSym, *threadCountSym; Symbol *threadIndexSym, *threadCountSym;
Symbol *taskIndexSym, *taskCountSym; Symbol *taskIndexSym, *taskCountSym;
Symbol *taskIndexSym_x, *taskCountSym_x; Symbol *taskIndexSym1, *taskCountSym1;
Symbol *taskIndexSym_y, *taskCountSym_y; Symbol *taskIndexSym2, *taskCountSym2;
Symbol *taskIndexSym_z, *taskCountSym_z; Symbol *taskIndexSym3, *taskCountSym3;
}; };
#endif // ISPC_FUNC_H #endif // ISPC_FUNC_H

7
lex.ll
View File

@@ -76,7 +76,6 @@ static int allTokens[] = {
TOKEN_TASK, TOKEN_TRUE, TOKEN_TYPEDEF, TOKEN_UNIFORM, TOKEN_UNMASKED, TOKEN_TASK, TOKEN_TRUE, TOKEN_TYPEDEF, TOKEN_UNIFORM, TOKEN_UNMASKED,
TOKEN_UNSIGNED, TOKEN_VARYING, TOKEN_VOID, TOKEN_WHILE, TOKEN_UNSIGNED, TOKEN_VARYING, TOKEN_VOID, TOKEN_WHILE,
TOKEN_STRING_C_LITERAL, TOKEN_DOTDOTDOT, TOKEN_STRING_C_LITERAL, TOKEN_DOTDOTDOT,
TOKEN_TRIPLECHEVRON_OPEN, TOKEN_TRIPLECHEVRON_CLOSE,
TOKEN_FLOAT_CONSTANT, TOKEN_DOUBLE_CONSTANT, TOKEN_FLOAT_CONSTANT, TOKEN_DOUBLE_CONSTANT,
TOKEN_INT8_CONSTANT, TOKEN_UINT8_CONSTANT, TOKEN_INT8_CONSTANT, TOKEN_UINT8_CONSTANT,
TOKEN_INT16_CONSTANT, TOKEN_UINT16_CONSTANT, TOKEN_INT16_CONSTANT, TOKEN_UINT16_CONSTANT,
@@ -152,8 +151,6 @@ void ParserInit() {
tokenToName[TOKEN_WHILE] = "while"; tokenToName[TOKEN_WHILE] = "while";
tokenToName[TOKEN_STRING_C_LITERAL] = "\"C\""; tokenToName[TOKEN_STRING_C_LITERAL] = "\"C\"";
tokenToName[TOKEN_DOTDOTDOT] = "..."; tokenToName[TOKEN_DOTDOTDOT] = "...";
tokenToName[TOKEN_TRIPLECHEVRON_OPEN] = "<<<";
tokenToName[TOKEN_TRIPLECHEVRON_CLOSE] = ">>>";
tokenToName[TOKEN_FLOAT_CONSTANT] = "TOKEN_FLOAT_CONSTANT"; tokenToName[TOKEN_FLOAT_CONSTANT] = "TOKEN_FLOAT_CONSTANT";
tokenToName[TOKEN_DOUBLE_CONSTANT] = "TOKEN_DOUBLE_CONSTANT"; tokenToName[TOKEN_DOUBLE_CONSTANT] = "TOKEN_DOUBLE_CONSTANT";
tokenToName[TOKEN_INT8_CONSTANT] = "TOKEN_INT8_CONSTANT"; tokenToName[TOKEN_INT8_CONSTANT] = "TOKEN_INT8_CONSTANT";
@@ -269,8 +266,6 @@ void ParserInit() {
tokenNameRemap["TOKEN_WHILE"] = "\'while\'"; tokenNameRemap["TOKEN_WHILE"] = "\'while\'";
tokenNameRemap["TOKEN_STRING_C_LITERAL"] = "\"C\""; tokenNameRemap["TOKEN_STRING_C_LITERAL"] = "\"C\"";
tokenNameRemap["TOKEN_DOTDOTDOT"] = "\'...\'"; tokenNameRemap["TOKEN_DOTDOTDOT"] = "\'...\'";
tokenNameRemap["TOKEN_TRIPLECHEVRON_OPEN"] = "\'<<<\'";
tokenNameRemap["TOKEN_TRIPLECHEVRON_CLOSE"] = "\'>>>\'";
tokenNameRemap["TOKEN_FLOAT_CONSTANT"] = "float constant"; tokenNameRemap["TOKEN_FLOAT_CONSTANT"] = "float constant";
tokenNameRemap["TOKEN_DOUBLE_CONSTANT"] = "double constant"; tokenNameRemap["TOKEN_DOUBLE_CONSTANT"] = "double constant";
tokenNameRemap["TOKEN_INT8_CONSTANT"] = "int8 constant"; tokenNameRemap["TOKEN_INT8_CONSTANT"] = "int8 constant";
@@ -423,8 +418,6 @@ void { RT; return TOKEN_VOID; }
while { RT; return TOKEN_WHILE; } while { RT; return TOKEN_WHILE; }
\"C\" { RT; return TOKEN_STRING_C_LITERAL; } \"C\" { RT; return TOKEN_STRING_C_LITERAL; }
\.\.\. { RT; return TOKEN_DOTDOTDOT; } \.\.\. { RT; return TOKEN_DOTDOTDOT; }
\<\<\< { RT; return TOKEN_TRIPLECHEVRON_OPEN; }
\>\>\> { RT; return TOKEN_TRIPLECHEVRON_CLOSE; }
"operator*" { return TOKEN_IDENTIFIER; } "operator*" { return TOKEN_IDENTIFIER; }
"operator+" { return TOKEN_IDENTIFIER; } "operator+" { return TOKEN_IDENTIFIER; }

View File

@@ -204,7 +204,6 @@ struct ForeachDimension {
%token TOKEN_CASE TOKEN_DEFAULT TOKEN_IF TOKEN_ELSE TOKEN_SWITCH %token TOKEN_CASE TOKEN_DEFAULT TOKEN_IF TOKEN_ELSE TOKEN_SWITCH
%token TOKEN_WHILE TOKEN_DO TOKEN_LAUNCH TOKEN_FOREACH TOKEN_FOREACH_TILED %token TOKEN_WHILE TOKEN_DO TOKEN_LAUNCH TOKEN_FOREACH TOKEN_FOREACH_TILED
%token TOKEN_FOREACH_UNIQUE TOKEN_FOREACH_ACTIVE TOKEN_DOTDOTDOT %token TOKEN_FOREACH_UNIQUE TOKEN_FOREACH_ACTIVE TOKEN_DOTDOTDOT
%token TOKEN_TRIPLECHEVRON_OPEN TOKEN_TRIPLECHEVRON_CLOSE
%token TOKEN_FOR TOKEN_GOTO TOKEN_CONTINUE TOKEN_BREAK TOKEN_RETURN %token TOKEN_FOR TOKEN_GOTO TOKEN_CONTINUE TOKEN_BREAK TOKEN_RETURN
%token TOKEN_CIF TOKEN_CDO TOKEN_CFOR TOKEN_CWHILE %token TOKEN_CIF TOKEN_CDO TOKEN_CFOR TOKEN_CWHILE
%token TOKEN_SYNC TOKEN_PRINT TOKEN_ASSERT %token TOKEN_SYNC TOKEN_PRINT TOKEN_ASSERT
@@ -363,54 +362,65 @@ launch_expression
Expr *launchCount[3] = {oneExpr, oneExpr, oneExpr}; Expr *launchCount[3] = {oneExpr, oneExpr, oneExpr};
$$ = new FunctionCallExpr($2, new ExprList(Union(@3,@4)), Union(@2, @4), true, launchCount); $$ = new FunctionCallExpr($2, new ExprList(Union(@3,@4)), Union(@2, @4), true, launchCount);
} }
| TOKEN_LAUNCH '[' expression ']' postfix_expression '(' argument_expression_list ')'
| TOKEN_LAUNCH '[' assignment_expression ']' postfix_expression '(' argument_expression_list ')'
{ {
ConstExpr *oneExpr = new ConstExpr(AtomicType::UniformInt32, (int32_t)1, @5); ConstExpr *oneExpr = new ConstExpr(AtomicType::UniformInt32, (int32_t)1, @5);
Expr *launchCount[3] = {$3, oneExpr, oneExpr}; Expr *launchCount[3] = {$3, oneExpr, oneExpr};
$$ = new FunctionCallExpr($5, $7, Union(@5,@8), true, launchCount); $$ = new FunctionCallExpr($5, $7, Union(@5,@8), true, launchCount);
} }
| TOKEN_LAUNCH TOKEN_TRIPLECHEVRON_OPEN assignment_expression TOKEN_TRIPLECHEVRON_CLOSE postfix_expression '(' argument_expression_list ')' | TOKEN_LAUNCH '[' assignment_expression ']' postfix_expression '(' ')'
{
ConstExpr *oneExpr = new ConstExpr(AtomicType::UniformInt32, (int32_t)1, @5);
Expr *launchCount[3] = {$3, oneExpr, oneExpr};
$$ = new FunctionCallExpr($5, $7, Union(@5,@8), true, launchCount);
}
| TOKEN_LAUNCH '[' expression ']' postfix_expression '(' ')'
{
ConstExpr *oneExpr = new ConstExpr(AtomicType::UniformInt32, (int32_t)1, @5);
Expr *launchCount[3] = {$3, oneExpr, oneExpr};
$$ = new FunctionCallExpr($5, new ExprList(Union(@5,@6)), Union(@5,@7), true, launchCount);
}
| TOKEN_LAUNCH TOKEN_TRIPLECHEVRON_OPEN assignment_expression TOKEN_TRIPLECHEVRON_CLOSE postfix_expression '(' ')'
{ {
ConstExpr *oneExpr = new ConstExpr(AtomicType::UniformInt32, (int32_t)1, @5); ConstExpr *oneExpr = new ConstExpr(AtomicType::UniformInt32, (int32_t)1, @5);
Expr *launchCount[3] = {$3, oneExpr, oneExpr}; Expr *launchCount[3] = {$3, oneExpr, oneExpr};
$$ = new FunctionCallExpr($5, new ExprList(Union(@5,@6)), Union(@5,@7), true, launchCount); $$ = new FunctionCallExpr($5, new ExprList(Union(@5,@6)), Union(@5,@7), true, launchCount);
} }
| TOKEN_LAUNCH TOKEN_TRIPLECHEVRON_OPEN assignment_expression ',' assignment_expression TOKEN_TRIPLECHEVRON_CLOSE postfix_expression '(' argument_expression_list ')' | TOKEN_LAUNCH '[' assignment_expression ',' assignment_expression ']' postfix_expression '(' argument_expression_list ')'
{ {
ConstExpr *oneExpr = new ConstExpr(AtomicType::UniformInt32, (int32_t)1, @7); ConstExpr *oneExpr = new ConstExpr(AtomicType::UniformInt32, (int32_t)1, @7);
Expr *launchCount[3] = {$3, $5, oneExpr}; Expr *launchCount[3] = {$3, $5, oneExpr};
$$ = new FunctionCallExpr($7, $9, Union(@7,@10), true, launchCount); $$ = new FunctionCallExpr($7, $9, Union(@7,@10), true, launchCount);
} }
| TOKEN_LAUNCH TOKEN_TRIPLECHEVRON_OPEN assignment_expression ',' assignment_expression TOKEN_TRIPLECHEVRON_CLOSE postfix_expression '(' ')' | TOKEN_LAUNCH '[' assignment_expression ',' assignment_expression ']' postfix_expression '(' ')'
{ {
ConstExpr *oneExpr = new ConstExpr(AtomicType::UniformInt32, (int32_t)1, @7); ConstExpr *oneExpr = new ConstExpr(AtomicType::UniformInt32, (int32_t)1, @7);
Expr *launchCount[3] = {$3, $5, oneExpr}; Expr *launchCount[3] = {$3, $5, oneExpr};
$$ = new FunctionCallExpr($7, new ExprList(Union(@7,@8)), Union(@7,@9), true, launchCount); $$ = new FunctionCallExpr($7, new ExprList(Union(@7,@8)), Union(@7,@9), true, launchCount);
} }
| TOKEN_LAUNCH '[' assignment_expression ']' '[' assignment_expression ']' postfix_expression '(' argument_expression_list ')'
{
ConstExpr *oneExpr = new ConstExpr(AtomicType::UniformInt32, (int32_t)1, @8);
Expr *launchCount[3] = {$6, $3, oneExpr};
$$ = new FunctionCallExpr($8, $10, Union(@8,@11), true, launchCount);
}
| TOKEN_LAUNCH '[' assignment_expression ']' '[' assignment_expression ']' postfix_expression '(' ')'
{
ConstExpr *oneExpr = new ConstExpr(AtomicType::UniformInt32, (int32_t)1, @8);
Expr *launchCount[3] = {$6, $3, oneExpr};
$$ = new FunctionCallExpr($8, new ExprList(Union(@8,@9)), Union(@8,@10), true, launchCount);
}
| TOKEN_LAUNCH TOKEN_TRIPLECHEVRON_OPEN assignment_expression ',' assignment_expression ',' assignment_expression TOKEN_TRIPLECHEVRON_CLOSE postfix_expression '(' argument_expression_list ')' | TOKEN_LAUNCH '[' assignment_expression ',' assignment_expression ',' assignment_expression ']' postfix_expression '(' argument_expression_list ')'
{ {
Expr *launchCount[3] = {$3, $5, $7}; Expr *launchCount[3] = {$3, $5, $7};
$$ = new FunctionCallExpr($9, $11, Union(@9,@12), true, launchCount); $$ = new FunctionCallExpr($9, $11, Union(@9,@12), true, launchCount);
} }
| TOKEN_LAUNCH TOKEN_TRIPLECHEVRON_OPEN assignment_expression ',' assignment_expression ',' assignment_expression TOKEN_TRIPLECHEVRON_CLOSE postfix_expression '(' ')' | TOKEN_LAUNCH '[' assignment_expression ',' assignment_expression ',' assignment_expression ']' postfix_expression '(' ')'
{ {
Expr *launchCount[3] = {$3, $5, $7}; Expr *launchCount[3] = {$3, $5, $7};
$$ = new FunctionCallExpr($9, new ExprList(Union(@9,@10)), Union(@9,@11), true, launchCount); $$ = new FunctionCallExpr($9, new ExprList(Union(@9,@10)), Union(@9,@11), true, launchCount);
} }
| TOKEN_LAUNCH '[' assignment_expression ']' '[' assignment_expression ']' '[' assignment_expression ']' postfix_expression '(' argument_expression_list ')'
{
Expr *launchCount[3] = {$9, $6, $3};
$$ = new FunctionCallExpr($11, $13, Union(@11,@14), true, launchCount);
}
| TOKEN_LAUNCH '[' assignment_expression ']' '[' assignment_expression ']' '[' assignment_expression ']' postfix_expression '(' ')'
{
Expr *launchCount[3] = {$9, $6, $3};
$$ = new FunctionCallExpr($11, new ExprList(Union(@11,@12)), Union(@11,@13), true, launchCount);
}
| TOKEN_LAUNCH '<' postfix_expression '(' argument_expression_list ')' '>' | TOKEN_LAUNCH '<' postfix_expression '(' argument_expression_list ')' '>'
@@ -425,13 +435,13 @@ launch_expression
"around function call expression."); "around function call expression.");
$$ = NULL; $$ = NULL;
} }
| TOKEN_LAUNCH '[' expression ']' '<' postfix_expression '(' argument_expression_list ')' '>' | TOKEN_LAUNCH '[' assignment_expression ']' '<' postfix_expression '(' argument_expression_list ')' '>'
{ {
Error(Union(@5, @10), "\"launch\" expressions no longer take '<' '>' " Error(Union(@5, @10), "\"launch\" expressions no longer take '<' '>' "
"around function call expression."); "around function call expression.");
$$ = NULL; $$ = NULL;
} }
| TOKEN_LAUNCH '[' expression ']' '<' postfix_expression '(' ')' '>' | TOKEN_LAUNCH '[' assignment_expression ']' '<' postfix_expression '(' ')' '>'
{ {
Error(Union(@5, @9), "\"launch\" expressions no longer take '<' '>' " Error(Union(@5, @9), "\"launch\" expressions no longer take '<' '>' "
"around function call expression."); "around function call expression.");
@@ -2266,20 +2276,20 @@ static void lAddThreadIndexCountToSymbolTable(SourcePos pos) {
Symbol *taskCountSym = new Symbol("taskCount", pos, type); Symbol *taskCountSym = new Symbol("taskCount", pos, type);
m->symbolTable->AddVariable(taskCountSym); m->symbolTable->AddVariable(taskCountSym);
Symbol *taskIndexSym_x = new Symbol("taskIndex_x", pos, type); Symbol *taskIndexSym1 = new Symbol("taskIndex1", pos, type);
m->symbolTable->AddVariable(taskIndexSym_x); m->symbolTable->AddVariable(taskIndexSym1);
Symbol *taskIndexSym_y = new Symbol("taskIndex_y", pos, type); Symbol *taskIndexSym2 = new Symbol("taskIndex2", pos, type);
m->symbolTable->AddVariable(taskIndexSym_y); m->symbolTable->AddVariable(taskIndexSym2);
Symbol *taskIndexSym_z = new Symbol("taskIndex_z", pos, type); Symbol *taskIndexSym3 = new Symbol("taskIndex3", pos, type);
m->symbolTable->AddVariable(taskIndexSym_z); m->symbolTable->AddVariable(taskIndexSym3);
Symbol *taskCountSym_x = new Symbol("taskCount_x", pos, type); Symbol *taskCountSym1 = new Symbol("taskCount1", pos, type);
m->symbolTable->AddVariable(taskCountSym_x); m->symbolTable->AddVariable(taskCountSym1);
Symbol *taskCountSym_y = new Symbol("taskCount_y", pos, type); Symbol *taskCountSym2 = new Symbol("taskCount2", pos, type);
m->symbolTable->AddVariable(taskCountSym_y); m->symbolTable->AddVariable(taskCountSym2);
Symbol *taskCountSym_z = new Symbol("taskCount_z", pos, type); Symbol *taskCountSym3 = new Symbol("taskCount3", pos, type);
m->symbolTable->AddVariable(taskCountSym_z); m->symbolTable->AddVariable(taskCountSym3);
} }

View File

@@ -2961,12 +2961,12 @@ FunctionType::LLVMFunctionType(llvm::LLVMContext *ctx, bool removeMask) const {
callTypes.push_back(LLVMTypes::Int32Type); // threadCount callTypes.push_back(LLVMTypes::Int32Type); // threadCount
callTypes.push_back(LLVMTypes::Int32Type); // taskIndex callTypes.push_back(LLVMTypes::Int32Type); // taskIndex
callTypes.push_back(LLVMTypes::Int32Type); // taskCount callTypes.push_back(LLVMTypes::Int32Type); // taskCount
callTypes.push_back(LLVMTypes::Int32Type); // taskIndex_x callTypes.push_back(LLVMTypes::Int32Type); // taskIndex1
callTypes.push_back(LLVMTypes::Int32Type); // taskIndex_y callTypes.push_back(LLVMTypes::Int32Type); // taskIndex2
callTypes.push_back(LLVMTypes::Int32Type); // taskIndex_z callTypes.push_back(LLVMTypes::Int32Type); // taskIndex3
callTypes.push_back(LLVMTypes::Int32Type); // taskCount_x callTypes.push_back(LLVMTypes::Int32Type); // taskCount1
callTypes.push_back(LLVMTypes::Int32Type); // taskCount_y callTypes.push_back(LLVMTypes::Int32Type); // taskCount2
callTypes.push_back(LLVMTypes::Int32Type); // taskCount_z callTypes.push_back(LLVMTypes::Int32Type); // taskCount3
} }
else else
// Otherwise we already have the types of the arguments // Otherwise we already have the types of the arguments