29#if ALPAKA_DEBUG >= ALPAKA_DEBUG_MINIMAL
33#ifdef ALPAKA_ACC_CPU_B_TBB_T_SEQ_ENABLED
35# include <tbb/blocked_range.h>
36# include <tbb/parallel_for.h>
37# include <tbb/task_group.h>
42 template<
typename TDim,
typename TIdx,
typename TKernelFnObj,
typename... TArgs>
43 class TaskKernelCpuTbbBlocks final :
public WorkDivMembers<TDim, TIdx>
46 template<
typename TWorkDiv>
47 ALPAKA_FN_HOST TaskKernelCpuTbbBlocks(TWorkDiv&& workDiv, TKernelFnObj
const& kernelFnObj, TArgs&&... args)
49 , m_kernelFnObj(kernelFnObj)
50 , m_args(
std::forward<TArgs>(args)...)
53 Dim<std::decay_t<TWorkDiv>>::value == TDim::value,
54 "The work division and the execution task have to be of the same dimensionality!");
62 auto const gridBlockExtent = getWorkDiv<Grid, Blocks>(*
this);
63 auto const blockThreadExtent = getWorkDiv<Block, Threads>(*
this);
64 auto const threadElemExtent = getWorkDiv<Thread, Elems>(*
this);
67 auto const blockSharedMemDynSizeBytes = std::apply(
68 [&](std::decay_t<TArgs>
const&... args)
70 return getBlockSharedMemDynSizeBytes<AccCpuTbbBlocks<TDim, TIdx>>(
78# if ALPAKA_DEBUG >= ALPAKA_DEBUG_FULL
79 std::cout << __func__ <<
" blockSharedMemDynSizeBytes: " << blockSharedMemDynSizeBytes <<
" B"
84 TIdx
const numBlocksInGrid = gridBlockExtent.prod();
86 tbb::this_task_arena::isolate(
91 core::tbb::BarrierThread<TIdx> barrier(numBlocksInGrid);
95 static_cast<TIdx
>(numBlocksInGrid),
98 AccCpuTbbBlocks<TDim, TIdx> acc(
99 *
static_cast<WorkDivMembers<TDim, TIdx> const*
>(
this),
100 blockSharedMemDynSizeBytes,
104 = mapIdx<TDim::value>(Vec<DimInt<1u>, TIdx>(
static_cast<TIdx
>(i)), gridBlockExtent);
107 [&](
auto&&... argsWithAcc) {
108 detail::checkKernelReturnType(
110 std::forward<
decltype(argsWithAcc)>(argsWithAcc)...);
112 std::tuple_cat(std::tie(acc), m_args));
113 std::apply(m_kernelFnObj, std::tuple_cat(std::tie(acc), m_args));
121 TKernelFnObj m_kernelFnObj;
122 std::tuple<std::decay_t<TArgs>...> m_args;
128 template<
typename TDim,
typename TIdx,
typename TKernelFnObj,
typename... TArgs>
129 struct AccType<TaskKernelCpuTbbBlocks<TDim, TIdx, TKernelFnObj, TArgs...>>
131 using type = AccCpuTbbBlocks<TDim, TIdx>;
135 template<
typename TDim,
typename TIdx,
typename TKernelFnObj,
typename... TArgs>
136 struct DevType<TaskKernelCpuTbbBlocks<TDim, TIdx, TKernelFnObj, TArgs...>>
142 template<
typename TDim,
typename TIdx,
typename TKernelFnObj,
typename... TArgs>
143 struct DimType<TaskKernelCpuTbbBlocks<TDim, TIdx, TKernelFnObj, TArgs...>>
149 template<
typename TDim,
typename TIdx,
typename TKernelFnObj,
typename... TArgs>
150 struct PlatformType<TaskKernelCpuTbbBlocks<TDim, TIdx, TKernelFnObj, TArgs...>>
152 using type = PlatformCpu;
156 template<
typename TDim,
typename TIdx,
typename TKernelFnObj,
typename... TArgs>
157 struct IdxType<TaskKernelCpuTbbBlocks<TDim, TIdx, TKernelFnObj, TArgs...>>
168 template<
typename TDev,
typename TDim,
typename TIdx,
typename TKernelFn,
typename... TArgs>
169 struct FunctionAttributes<AccCpuTbbBlocks<TDim, TIdx>, TDev, TKernelFn, TArgs...>
178 [[maybe_unused]] TKernelFn
const& kernelFn,
186 kernelFunctionAttributes.
maxThreadsPerBlock =
static_cast<int>(props.m_blockThreadCountMax);
189 return kernelFunctionAttributes;
194 template<
typename TDev,
typename TKernelFnObj,
typename TDim,
typename TIdx,
typename... TArgs>
195 struct MaxActiveBlocks<AccCpuTbbBlocks<TDim, TIdx>, TDev, TKernelFnObj, TDim, TIdx, TArgs...>
198 TKernelFnObj
const& ,
202 TArgs
const&... ) ->
int
204 return static_cast<int>(
205 trait::GetAccDevProps<AccCpuTbbBlocks<TDim, TIdx>>
::getAccDevProps(device).m_multiProcessorCount);
#define ALPAKA_DEBUG_MINIMAL_LOG_SCOPE
The alpaka accelerator library.
constexpr std::uint32_t BlockSharedDynMemberAllocKiB
ALPAKA_FN_HOST auto getAccDevProps(TDev const &dev) -> AccDevProps< Dim< TAcc >, Idx< TAcc > >
WorkDivMembers(alpaka::Vec< TDim, TIdx > const &gridBlockExtent, alpaka::Vec< TDim, TIdx > const &blockThreadExtent, alpaka::Vec< TDim, TIdx > const &elemExtent) -> WorkDivMembers< TDim, TIdx >
Deduction guide for the constructor which can be called without explicit template type parameters.
ALPAKA_NO_HOST_ACC_WARNING ALPAKA_FN_HOST_ACC auto getMaxActiveBlocks(TDev const &device, TKernelFnObj const &kernelFnObj, alpaka::Vec< TDim, TIdx > const &blockThreadExtent, alpaka::Vec< TDim, TIdx > const &threadElemExtent, TArgs const &... args) -> int
ALPAKA_NO_HOST_ACC_WARNING ALPAKA_FN_ACC auto freeSharedVars(TBlockSharedMemSt &blockSharedMemSt) -> void
Frees all memory used by block shared variables.
Kernel function attributes struct. Attributes are filled by calling the API of the accelerator using ...
int maxDynamicSharedSizeBytes
static ALPAKA_FN_HOST auto getFunctionAttributes(TDev const &dev, TKernelFnObj const &kernelFn, TArgs &&... args) -> alpaka::KernelFunctionAttributes