1 #ifndef HeterogeneousCore_AlpakaInterface_interface_HostOnlyTask_h 2 #define HeterogeneousCore_AlpakaInterface_interface_HostOnlyTask_h 7 #include <fmt/format.h> 9 #include <alpaka/alpaka.hpp> 24 std::function<void(std::exception_ptr)>
task_;
29 #ifdef ALPAKA_ACC_GPU_CUDA_ENABLED 33 using TApi = ApiCudaRt;
36 std::unique_ptr<HostOnlyTask> pTask(static_cast<HostOnlyTask*>(
arg));
37 if (
status == cudaSuccess) {
42 throw std::runtime_error(
fmt::format(
"CUDA error: callback of stream {} received error {}: {}.",
45 cudaGetErrorString(
status)));
48 (*pTask)(std::current_exception());
55 ALPAKA_UNIFORM_CUDA_HIP_RT_CHECK(
56 cudaStreamAddCallback(alpaka::getNativeHandle(
queue),
callback, static_cast<void*>(pTask.release()), 0u));
59 #endif // ALPAKA_ACC_GPU_CUDA_ENABLED 61 #ifdef ALPAKA_ACC_GPU_HIP_ENABLED 65 using TApi = ApiHipRt;
68 std::unique_ptr<HostOnlyTask> pTask(static_cast<HostOnlyTask*>(
arg));
69 if (
status == hipSuccess) {
74 throw std::runtime_error(
fmt::format(
"HIP error: callback of stream {} received error {}: {}.",
77 hipGetErrorString(
status)));
80 (*pTask)(std::current_exception());
87 ALPAKA_UNIFORM_CUDA_HIP_RT_CHECK(
88 hipStreamAddCallback(alpaka::getNativeHandle(
queue),
callback, static_cast<void*>(pTask.release()), 0u));
91 #endif // ALPAKA_ACC_GPU_HIP_ENABLED 97 #endif // HeterogeneousCore_AlpakaInterface_interface_HostOnlyTask_h HostOnlyTask(std::function< void(std::exception_ptr)> task)
std::function< void(std::exception_ptr)> task_
void operator()(std::exception_ptr eptr) const