Added updated task launch implementation that now tracks task groups.
Within each function that launches tasks, we now can easily track which tasks that function launched, so that the sync at the end of the function can just sync on the tasks launched by that function (not all tasks launched by all functions.) Implementing this led to a rework of the task system API that ispc generates code to call; the example task systems in examples/tasksys.cpp have been updated to conform to this API. (The updated API is also documented in the ispc user's guide.) As part of this, "launch[n]" syntax was added to launch a number of tasks in a single launch statement, rather than requiring a loop over 'n' to launch n tasks. This commit thus fixes issue #84 (enhancement to launch multiple tasks from a single launch statement) as well as issue #105 (recursive task launches were broken).
This commit is contained in:
25
module.cpp
25
module.cpp
@@ -627,6 +627,8 @@ lEmitFunctionCode(FunctionEmitContext *ctx, llvm::Function *function,
|
||||
llvm::Value *structParamPtr = argIter++;
|
||||
llvm::Value *threadIndex = argIter++;
|
||||
llvm::Value *threadCount = argIter++;
|
||||
llvm::Value *taskIndex = argIter++;
|
||||
llvm::Value *taskCount = argIter++;
|
||||
|
||||
// Copy the function parameter values from the structure into local
|
||||
// storage
|
||||
@@ -654,18 +656,17 @@ lEmitFunctionCode(FunctionEmitContext *ctx, llvm::Function *function,
|
||||
threadCountSym->storagePtr = ctx->AllocaInst(LLVMTypes::Int32Type, "threadCount");
|
||||
ctx->StoreInst(threadCount, threadCountSym->storagePtr);
|
||||
|
||||
#ifdef ISPC_IS_WINDOWS
|
||||
// On Windows, we dynamically-allocate space for the task arguments
|
||||
// (see FunctionEmitContext::LaunchInst().) Here is where we emit
|
||||
// the code to free that memory, now that we've copied the
|
||||
// parameter values out of the structure.
|
||||
ctx->EmitFree(structParamPtr);
|
||||
#else
|
||||
// We also do this for AVX... (See discussion in
|
||||
// FunctionEmitContext::LaunchInst().)
|
||||
if (g->target.isa == Target::AVX)
|
||||
ctx->EmitFree(structParamPtr);
|
||||
#endif // ISPC_IS_WINDOWS
|
||||
// Copy taskIndex and taskCount into stack-allocated storage so
|
||||
// that their symbols point to something reasonable.
|
||||
Symbol *taskIndexSym = m->symbolTable->LookupVariable("taskIndex");
|
||||
assert(taskIndexSym);
|
||||
taskIndexSym->storagePtr = ctx->AllocaInst(LLVMTypes::Int32Type, "taskIndex");
|
||||
ctx->StoreInst(taskIndex, taskIndexSym->storagePtr);
|
||||
|
||||
Symbol *taskCountSym = m->symbolTable->LookupVariable("taskCount");
|
||||
assert(taskCountSym);
|
||||
taskCountSym->storagePtr = ctx->AllocaInst(LLVMTypes::Int32Type, "taskCount");
|
||||
ctx->StoreInst(taskCount, taskCountSym->storagePtr);
|
||||
}
|
||||
else {
|
||||
// Regular, non-task function
|
||||
|
||||
Reference in New Issue
Block a user