16#include <tbb/task_arena.h>
17#include <tbb/task_group.h>
18#include <oneapi/tbb/task_arena.h>
19#include <oneapi/tbb/concurrent_hash_map.h>
36 class GlobalTaskGroup :
public ::oneapi::tbb::task_group {
38 GlobalTaskGroup() : task_group() {}
55 GlobalTaskGroup globalTaskGroup;
57 #if !defined(SharedTBBExtension) and !defined(TBB_USE_TASK_GROUP_PREVIEW)
59 static ::oneapi::tbb::dynamic_task_graph taskGraph(globalTaskGroup);
114 ::tbb::task_group taskGroup;
115 for (
auto& p : tasks) {
116 taskGroup.run([&tasks, p]() ->
void {
142 Task* myTask,
const std::list<tarch::multicore::Task*>& tasksOfSameType,
int device
144 std::list<tarch::multicore::Task*> copyOfTasksOfSameType = tasksOfSameType;
145 globalTaskGroup.run([&, myTask, copyOfTasksOfSameType] {
146 bool stillExecuteLocally = myTask->
fuse(copyOfTasksOfSameType, device);
147 if (stillExecuteLocally) {
148 tarch::multicore::native::spawnTask(myTask, std::set<TaskNumber>(),
NoOutDependencies);
156void tarch::multicore::native::waitForTasks(
const std::set<TaskNumber>& inDependencies) {
157 #if !defined(SharedTBBExtension) and !defined(TBB_USE_TASK_GROUP_PREVIEW)
158 ::oneapi::tbb::task_handle* handle = new ::oneapi::tbb::task_handle(
159 globalTaskGroup.defer(
171 taskHandleRepository.addDependencies( handle, inDependencies );
173 #if !defined(SharedTBBExtension) and !defined(TBB_USE_TASK_GROUP_PREVIEW)
175 globalTaskGroup.run_and_wait( handle );
177 taskGraph.put( *handle );
178 taskGraph.wait( *handle );
185void tarch::multicore::native::waitForAllTasks() {
186 #if !defined(SharedTBBExtension) and !defined(TBB_USE_TASK_GROUP_PREVIEW)
188 taskGraph.wait_for_all();
191 globalTaskGroup.wait();
195void tarch::multicore::native::spawnTask(
197 const std::set<TaskNumber>& inDependencies,
198 const TaskNumber& taskNumber
200 #if !defined(SharedTBBExtension) and !defined(TBB_USE_TASK_GROUP_PREVIEW)
201 ::oneapi::tbb::task_handle* handle = new ::oneapi::tbb::task_handle(
202 globalTaskGroup.defer(
229 taskHandleRepository.addDependency( handle, taskNumber );
230 taskHandleRepository.addDependencies( handle, inDependencies );
232 #if !defined(SharedTBBExtension) and !defined(TBB_USE_TASK_GROUP_PREVIEW)
234 globalTaskGroup.run( handle );
236 taskGraph.put( *handle );
239 if (taskNumber==NoOutDependencies) {
243 taskHandleRepository.registerTask(handle, taskNumber);
static Core & getInstance()
void yield()
Wrapper around backend-specific yield.
Abstract super class for a job.
virtual bool fuse(const std::list< Task * > &otherTasks, int targetDevice=Host)
Fuse multiple tasks.
Simple utility class around dynamic task graphs to work with integer task numbers.
Represents one node in task graph.
void spawnAndWaitAsTaskLoop(const std::vector< tarch::multicore::Task * > &tasks)
Map onto native tasking.
void processFusedTask(Task *myTask, const std::list< tarch::multicore::Task * > &tasksOfSameType, int device)
Process a fused task.
constexpr TaskNumber NoOutDependencies