Uni20
Asynchronous tensor and runtime library.
Loading...
Searching...
No Matches
tbb_task_submission.hpp
Go to the documentation of this file.
1
6#pragma once
7
8#include <oneapi/tbb/task_arena.h>
9#include <oneapi/tbb/task_group.h>
11
12#include <exception>
13#include <string_view>
14#include <utility>
15
16namespace uni20::async::detail
17{
18
20struct TbbTaskAdmissionContext
21{
22 std::string_view scheduler;
23 int device = -1;
24};
25
26[[noreturn]] inline void tbb_task_admission_failure(TbbTaskAdmissionContext context, std::string_view reason)
27{
28 if (context.device >= 0)
29 {
30 PANIC("oneTBB scheduler admission failed", context.scheduler, context.device, reason);
31 }
32 PANIC("oneTBB scheduler admission failed", context.scheduler, reason);
33}
34
39template <typename Function>
40void enqueue_tbb_task(oneapi::tbb::task_arena& arena, oneapi::tbb::task_group& group, Function&& function,
41 TbbTaskAdmissionContext context) noexcept
42{
43 try
44 {
45 auto task = group.defer(std::forward<Function>(function));
46 arena.enqueue(std::move(task));
47 }
48 catch (std::exception const& error)
49 {
50 tbb_task_admission_failure(context, error.what());
51 }
52 catch (...)
53 {
54 tbb_task_admission_failure(context, "unknown exception");
55 }
56}
57
58} // namespace uni20::async::detail
#define PANIC(...)
Definition trace.hpp:382