Skip to content

Commit

Permalink
change CreateTaskKernel interface
Browse files Browse the repository at this point in the history
Use `KernelBundle` for task kernel creation.

Co-authored-by: René Widera <r.widera@hzdr.de>
  • Loading branch information
mehmetyusufoglu and psychocoderHPC committed Aug 1, 2024
1 parent 4995c5b commit 0038fa9
Show file tree
Hide file tree
Showing 18 changed files with 220 additions and 180 deletions.
17 changes: 10 additions & 7 deletions include/alpaka/acc/AccCpuOmp2Blocks.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include "alpaka/idx/bt/IdxBtZero.hpp"
#include "alpaka/idx/gb/IdxGbRef.hpp"
#include "alpaka/intrinsic/IntrinsicCpu.hpp"
#include "alpaka/kernel/KernelBundle.hpp"
#include "alpaka/math/MathStdLib.hpp"
#include "alpaka/mem/fence/MemFenceOmp2Blocks.hpp"
#include "alpaka/rand/RandDefault.hpp"
Expand Down Expand Up @@ -180,18 +181,20 @@ namespace alpaka
};

//! The CPU OpenMP 2.0 block accelerator execution task type trait specialization.
//!
//! \tparam TDim The dimensionality of the accelerator device properties.
//! \tparam TIdx The idx type of the accelerator device properties.
//! \tparam TWorkDiv The type of the work division.
//! \tparam TKernelFnObj Kernel function object type.
//! \tparam TArgs Kernel function object argument types as a parameter pack.
template<typename TDim, typename TIdx, typename TWorkDiv, typename TKernelFnObj, typename... TArgs>
struct CreateTaskKernel<AccCpuOmp2Blocks<TDim, TIdx>, TWorkDiv, TKernelFnObj, TArgs...>
struct CreateTaskKernel<AccCpuOmp2Blocks<TDim, TIdx>, TWorkDiv, KernelBundle<TKernelFnObj, TArgs...>>
{
ALPAKA_FN_HOST static auto createTaskKernel(
TWorkDiv const& workDiv,
TKernelFnObj const& kernelFnObj,
TArgs&&... args)
KernelBundle<TKernelFnObj, TArgs...> const& kernelBundle)
{
return TaskKernelCpuOmp2Blocks<TDim, TIdx, TKernelFnObj, TArgs...>(
workDiv,
kernelFnObj,
std::forward<TArgs>(args)...);
return TaskKernelCpuOmp2Blocks<TDim, TIdx, TKernelFnObj, TArgs...>(workDiv, kernelBundle);
}
};

Expand Down
17 changes: 10 additions & 7 deletions include/alpaka/acc/AccCpuOmp2Threads.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include "alpaka/idx/bt/IdxBtOmp.hpp"
#include "alpaka/idx/gb/IdxGbRef.hpp"
#include "alpaka/intrinsic/IntrinsicCpu.hpp"
#include "alpaka/kernel/KernelBundle.hpp"
#include "alpaka/math/MathStdLib.hpp"
#include "alpaka/mem/fence/MemFenceOmp2Threads.hpp"
#include "alpaka/rand/RandDefault.hpp"
Expand Down Expand Up @@ -191,18 +192,20 @@ namespace alpaka
};

//! The CPU OpenMP 2.0 thread accelerator execution task type trait specialization.
//!
//! \tparam TDim The dimensionality of the accelerator device properties.
//! \tparam TIdx The idx type of the accelerator device properties.
//! \tparam TWorkDiv The type of the work division.
//! \tparam TKernelFnObj Kernel function object type.
//! \tparam TArgs Kernel function object argument types as a parameter pack.
template<typename TDim, typename TIdx, typename TWorkDiv, typename TKernelFnObj, typename... TArgs>
struct CreateTaskKernel<AccCpuOmp2Threads<TDim, TIdx>, TWorkDiv, TKernelFnObj, TArgs...>
struct CreateTaskKernel<AccCpuOmp2Threads<TDim, TIdx>, TWorkDiv, KernelBundle<TKernelFnObj, TArgs...>>
{
ALPAKA_FN_HOST static auto createTaskKernel(
TWorkDiv const& workDiv,
TKernelFnObj const& kernelFnObj,
TArgs&&... args)
KernelBundle<TKernelFnObj, TArgs...> const& kernelBundle)
{
return TaskKernelCpuOmp2Threads<TDim, TIdx, TKernelFnObj, TArgs...>(
workDiv,
kernelFnObj,
std::forward<TArgs>(args)...);
return TaskKernelCpuOmp2Threads<TDim, TIdx, TKernelFnObj, TArgs...>(workDiv, kernelBundle);
}
};

Expand Down
17 changes: 10 additions & 7 deletions include/alpaka/acc/AccCpuSerial.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include "alpaka/idx/bt/IdxBtZero.hpp"
#include "alpaka/idx/gb/IdxGbRef.hpp"
#include "alpaka/intrinsic/IntrinsicCpu.hpp"
#include "alpaka/kernel/KernelBundle.hpp"
#include "alpaka/math/MathStdLib.hpp"
#include "alpaka/mem/fence/MemFenceCpuSerial.hpp"
#include "alpaka/rand/RandDefault.hpp"
Expand Down Expand Up @@ -174,18 +175,20 @@ namespace alpaka
};

//! The CPU serial accelerator execution task type trait specialization.
//!
//! \tparam TDim The dimensionality of the accelerator device properties.
//! \tparam TIdx The idx type of the accelerator device properties.
//! \tparam TWorkDiv The type of the work division.
//! \tparam TKernelFnObj Kernel function object type.
//! \tparam TArgs Kernel function object argument types as a parameter pack.
template<typename TDim, typename TIdx, typename TWorkDiv, typename TKernelFnObj, typename... TArgs>
struct CreateTaskKernel<AccCpuSerial<TDim, TIdx>, TWorkDiv, TKernelFnObj, TArgs...>
struct CreateTaskKernel<AccCpuSerial<TDim, TIdx>, TWorkDiv, KernelBundle<TKernelFnObj, TArgs...>>
{
ALPAKA_FN_HOST static auto createTaskKernel(
TWorkDiv const& workDiv,
TKernelFnObj const& kernelFnObj,
TArgs&&... args)
KernelBundle<TKernelFnObj, TArgs...> const& kernelBundle)
{
return TaskKernelCpuSerial<TDim, TIdx, TKernelFnObj, TArgs...>(
workDiv,
kernelFnObj,
std::forward<TArgs>(args)...);
return TaskKernelCpuSerial<TDim, TIdx, TKernelFnObj, TArgs...>(workDiv, kernelBundle);
}
};

Expand Down
18 changes: 12 additions & 6 deletions include/alpaka/acc/AccCpuSycl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "alpaka/core/Sycl.hpp"
#include "alpaka/dev/DevCpuSycl.hpp"
#include "alpaka/dev/Traits.hpp"
#include "alpaka/kernel/KernelBundle.hpp"
#include "alpaka/kernel/TaskKernelCpuSycl.hpp"
#include "alpaka/kernel/Traits.hpp"
#include "alpaka/platform/PlatformCpuSycl.hpp"
Expand Down Expand Up @@ -57,15 +58,20 @@ namespace alpaka::trait
};

//! The CPU SYCL accelerator execution task type trait specialization.
//!
//! \tparam TDim The dimensionality of the accelerator device properties.
//! \tparam TIdx The idx type of the accelerator device properties.
//! \tparam TWorkDiv The type of the work division.
//! \tparam TKernelFnObj Kernel function object type.
//! \tparam TArgs Kernel function object argument types as a parameter pack.
template<typename TDim, typename TIdx, typename TWorkDiv, typename TKernelFnObj, typename... TArgs>
struct CreateTaskKernel<AccCpuSycl<TDim, TIdx>, TWorkDiv, TKernelFnObj, TArgs...>
struct CreateTaskKernel<AccCpuSycl<TDim, TIdx>, TWorkDiv, KernelBundle<TKernelFnObj, TArgs...>>
{
static auto createTaskKernel(TWorkDiv const& workDiv, TKernelFnObj const& kernelFnObj, TArgs&&... args)
ALPAKA_FN_HOST static auto createTaskKernel(
TWorkDiv const& workDiv,
KernelBundle<TKernelFnObj, TArgs...> const& kernelBundle)
{
return TaskKernelCpuSycl<TDim, TIdx, TKernelFnObj, TArgs...>{
workDiv,
kernelFnObj,
std::forward<TArgs>(args)...};
return TaskKernelCpuSycl<TDim, TIdx, TKernelFnObj, TArgs...>(workDiv, kernelBundle);
}
};

Expand Down
17 changes: 10 additions & 7 deletions include/alpaka/acc/AccCpuTbbBlocks.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include "alpaka/idx/bt/IdxBtZero.hpp"
#include "alpaka/idx/gb/IdxGbRef.hpp"
#include "alpaka/intrinsic/IntrinsicCpu.hpp"
#include "alpaka/kernel/KernelBundle.hpp"
#include "alpaka/math/MathStdLib.hpp"
#include "alpaka/mem/fence/MemFenceCpu.hpp"
#include "alpaka/rand/RandDefault.hpp"
Expand Down Expand Up @@ -172,18 +173,20 @@ namespace alpaka
};

//! The CPU TBB block accelerator execution task type trait specialization.
//!
//! \tparam TDim The dimensionality of the accelerator device properties.
//! \tparam TIdx The idx type of the accelerator device properties.
//! \tparam TWorkDiv The type of the work division.
//! \tparam TKernelFnObj Kernel function object type.
//! \tparam TArgs Kernel function object argument types as a parameter pack.
template<typename TDim, typename TIdx, typename TWorkDiv, typename TKernelFnObj, typename... TArgs>
struct CreateTaskKernel<AccCpuTbbBlocks<TDim, TIdx>, TWorkDiv, TKernelFnObj, TArgs...>
struct CreateTaskKernel<AccCpuTbbBlocks<TDim, TIdx>, TWorkDiv, KernelBundle<TKernelFnObj, TArgs...>>
{
ALPAKA_FN_HOST static auto createTaskKernel(
TWorkDiv const& workDiv,
TKernelFnObj const& kernelFnObj,
TArgs&&... args)
KernelBundle<TKernelFnObj, TArgs...> const& kernelBundle)
{
return TaskKernelCpuTbbBlocks<TDim, TIdx, TKernelFnObj, TArgs...>(
workDiv,
kernelFnObj,
std::forward<TArgs>(args)...);
return TaskKernelCpuTbbBlocks<TDim, TIdx, TKernelFnObj, TArgs...>(workDiv, kernelBundle);
}
};

Expand Down
19 changes: 11 additions & 8 deletions include/alpaka/acc/AccCpuThreads.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include "alpaka/idx/bt/IdxBtRefThreadIdMap.hpp"
#include "alpaka/idx/gb/IdxGbRef.hpp"
#include "alpaka/intrinsic/IntrinsicCpu.hpp"
#include "alpaka/kernel/KernelBundle.hpp"
#include "alpaka/math/MathStdLib.hpp"
#include "alpaka/mem/fence/MemFenceCpu.hpp"
#include "alpaka/rand/RandDefault.hpp"
Expand Down Expand Up @@ -198,19 +199,21 @@ namespace alpaka
using type = TDim;
};

//! The CPU threads accelerator execution task type trait specialization.
//! The CPU serial accelerator execution task type trait specialization.
//!
//! \tparam TDim The dimensionality of the accelerator device properties.
//! \tparam TIdx The idx type of the accelerator device properties.
//! \tparam TWorkDiv The type of the work division.
//! \tparam TKernelFnObj Kernel function object type.
//! \tparam TArgs Kernel function object argument types as a parameter pack.
template<typename TDim, typename TIdx, typename TWorkDiv, typename TKernelFnObj, typename... TArgs>
struct CreateTaskKernel<AccCpuThreads<TDim, TIdx>, TWorkDiv, TKernelFnObj, TArgs...>
struct CreateTaskKernel<AccCpuThreads<TDim, TIdx>, TWorkDiv, KernelBundle<TKernelFnObj, TArgs...>>
{
ALPAKA_FN_HOST static auto createTaskKernel(
TWorkDiv const& workDiv,
TKernelFnObj const& kernelFnObj,
TArgs&&... args)
KernelBundle<TKernelFnObj, TArgs...> const& kernelBundle)
{
return TaskKernelCpuThreads<TDim, TIdx, TKernelFnObj, TArgs...>(
workDiv,
kernelFnObj,
std::forward<TArgs>(args)...);
return TaskKernelCpuThreads<TDim, TIdx, TKernelFnObj, TArgs...>(workDiv, kernelBundle);
}
};

Expand Down
18 changes: 12 additions & 6 deletions include/alpaka/acc/AccFpgaSyclIntel.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "alpaka/core/Sycl.hpp"
#include "alpaka/dev/DevFpgaSyclIntel.hpp"
#include "alpaka/dev/Traits.hpp"
#include "alpaka/kernel/KernelBundle.hpp"
#include "alpaka/kernel/TaskKernelFpgaSyclIntel.hpp"
#include "alpaka/kernel/Traits.hpp"
#include "alpaka/platform/PlatformFpgaSyclIntel.hpp"
Expand Down Expand Up @@ -57,15 +58,20 @@ namespace alpaka::trait
};

//! The Intel FPGA SYCL accelerator execution task type trait specialization.
//!
//! \tparam TDim The dimensionality of the accelerator device properties.
//! \tparam TIdx The idx type of the accelerator device properties.
//! \tparam TWorkDiv The type of the work division.
//! \tparam TKernelFnObj Kernel function object type.
//! \tparam TArgs Kernel function object argument types as a parameter pack.
template<typename TDim, typename TIdx, typename TWorkDiv, typename TKernelFnObj, typename... TArgs>
struct CreateTaskKernel<AccFpgaSyclIntel<TDim, TIdx>, TWorkDiv, TKernelFnObj, TArgs...>
struct CreateTaskKernel<AccFpgaSyclIntel<TDim, TIdx>, TWorkDiv, KernelBundle<TKernelFnObj, TArgs...>>
{
static auto createTaskKernel(TWorkDiv const& workDiv, TKernelFnObj const& kernelFnObj, TArgs&&... args)
ALPAKA_FN_HOST static auto createTaskKernel(
TWorkDiv const& workDiv,
KernelBundle<TKernelFnObj, TArgs...> const& kernelBundle)
{
return TaskKernelFpgaSyclIntel<TDim, TIdx, TKernelFnObj, TArgs...>{
workDiv,
kernelFnObj,
std::forward<TArgs>(args)...};
return TaskKernelFpgaSyclIntel<TDim, TIdx, TKernelFnObj, TArgs...>(workDiv, kernelBundle);
}
};

Expand Down
18 changes: 12 additions & 6 deletions include/alpaka/acc/AccGpuSyclIntel.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "alpaka/core/Sycl.hpp"
#include "alpaka/dev/DevGpuSyclIntel.hpp"
#include "alpaka/dev/Traits.hpp"
#include "alpaka/kernel/KernelBundle.hpp"
#include "alpaka/kernel/TaskKernelGpuSyclIntel.hpp"
#include "alpaka/kernel/Traits.hpp"
#include "alpaka/platform/PlatformGpuSyclIntel.hpp"
Expand Down Expand Up @@ -57,15 +58,20 @@ namespace alpaka::trait
};

//! The Intel GPU SYCL accelerator execution task type trait specialization.
//!
//! \tparam TDim The dimensionality of the accelerator device properties.
//! \tparam TIdx The idx type of the accelerator device properties.
//! \tparam TWorkDiv The type of the work division.
//! \tparam TKernelFnObj Kernel function object type.
//! \tparam TArgs Kernel function object argument types as a parameter pack.
template<typename TDim, typename TIdx, typename TWorkDiv, typename TKernelFnObj, typename... TArgs>
struct CreateTaskKernel<AccGpuSyclIntel<TDim, TIdx>, TWorkDiv, TKernelFnObj, TArgs...>
struct CreateTaskKernel<AccCpuSyclIntel<TDim, TIdx>, TWorkDiv, KernelBundle<TKernelFnObj, TArgs...>>
{
static auto createTaskKernel(TWorkDiv const& workDiv, TKernelFnObj const& kernelFnObj, TArgs&&... args)
ALPAKA_FN_HOST static auto createTaskKernel(
TWorkDiv const& workDiv,
KernelBundle<TKernelFnObj, TArgs...> const& kernelBundle)
{
return TaskKernelGpuSyclIntel<TDim, TIdx, TKernelFnObj, TArgs...>{
workDiv,
kernelFnObj,
std::forward<TArgs>(args)...};
return TaskKernelCpuSyclIntel<TDim, TIdx, TKernelFnObj, TArgs...>(workDiv, kernelBundle);
}
};

Expand Down
19 changes: 15 additions & 4 deletions include/alpaka/acc/AccGpuUniformCudaHipRt.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include "alpaka/idx/bt/IdxBtUniformCudaHipBuiltIn.hpp"
#include "alpaka/idx/gb/IdxGbUniformCudaHipBuiltIn.hpp"
#include "alpaka/intrinsic/IntrinsicUniformCudaHipBuiltIn.hpp"
#include "alpaka/kernel/KernelBundle.hpp"
#include "alpaka/math/MathUniformCudaHipBuiltIn.hpp"
#include "alpaka/mem/fence/MemFenceUniformCudaHipBuiltIn.hpp"
#include "alpaka/rand/RandDefault.hpp"
Expand Down Expand Up @@ -264,27 +265,37 @@ namespace alpaka
namespace trait
{
//! The GPU CUDA accelerator execution task type trait specialization.
//!
//! \tparam TApi The type the API of the GPU accelerator backend. Currently Cuda or Hip.
//! \tparam TDim The dimensionality of the accelerator device properties.
//! \tparam TIdx The idx type of the accelerator device properties.
//! \tparam TWorkDiv The type of the work division.
//! \tparam TKernelFnObj Kernel function object type.
//! \tparam TArgs Kernel function object argument types as a parameter pack.
template<
typename TApi,
typename TDim,
typename TIdx,
typename TWorkDiv,
typename TKernelFnObj,
typename... TArgs>
struct CreateTaskKernel<AccGpuUniformCudaHipRt<TApi, TDim, TIdx>, TWorkDiv, TKernelFnObj, TArgs...>
struct CreateTaskKernel<
AccGpuUniformCudaHipRt<TApi, TDim, TIdx>,
TWorkDiv,
KernelBundle<TKernelFnObj, TArgs...>>
{
ALPAKA_FN_HOST static auto createTaskKernel(
TWorkDiv const& workDiv,
TKernelFnObj const& kernelFnObj,
TArgs&&... args)

KernelBundle<TKernelFnObj, TArgs...> const& kernelBundle)
{
return TaskKernelGpuUniformCudaHipRt<
TApi,
AccGpuUniformCudaHipRt<TApi, TDim, TIdx>,
TDim,
TIdx,
TKernelFnObj,
TArgs...>(workDiv, kernelFnObj, std::forward<TArgs>(args)...);
TArgs...>(workDiv, kernelBundle);
}
};

Expand Down
1 change: 0 additions & 1 deletion include/alpaka/kernel/KernelBundle.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ namespace alpaka
{
}

private:
KernelFn m_kernelFn;
ArgTuple m_args; // Store the argument types without const and reference
};
Expand Down
8 changes: 5 additions & 3 deletions include/alpaka/kernel/TaskKernelCpuOmp2Blocks.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -789,10 +789,12 @@ namespace alpaka
{
public:
template<typename TWorkDiv>
ALPAKA_FN_HOST TaskKernelCpuOmp2Blocks(TWorkDiv&& workDiv, TKernelFnObj const& kernelFnObj, TArgs&&... args)
ALPAKA_FN_HOST TaskKernelCpuOmp2Blocks(
TWorkDiv&& workDiv,
KernelBundle<TKernelFnObj, TArgs...> const& KernelBundle)
: WorkDivMembers<TDim, TIdx>(std::forward<TWorkDiv>(workDiv))
, m_kernelFnObj(kernelFnObj)
, m_args(std::forward<TArgs>(args)...)
, m_kernelFnObj(KernelBundle.m_kernelFn)
, m_args(KernelBundle.m_args)
{
static_assert(
Dim<std::decay_t<TWorkDiv>>::value == TDim::value,
Expand Down
8 changes: 5 additions & 3 deletions include/alpaka/kernel/TaskKernelCpuOmp2Threads.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,12 @@ namespace alpaka
{
public:
template<typename TWorkDiv>
ALPAKA_FN_HOST TaskKernelCpuOmp2Threads(TWorkDiv&& workDiv, TKernelFnObj const& kernelFnObj, TArgs&&... args)
ALPAKA_FN_HOST TaskKernelCpuOmp2Threads(
TWorkDiv&& workDiv,
KernelBundle<TKernelFnObj, TArgs...> const& KernelBundle)
: WorkDivMembers<TDim, TIdx>(std::forward<TWorkDiv>(workDiv))
, m_kernelFnObj(kernelFnObj)
, m_args(std::forward<TArgs>(args)...)
, m_kernelFnObj(KernelBundle.m_kernelFn)
, m_args(KernelBundle.m_args)
{
static_assert(
Dim<std::decay_t<TWorkDiv>>::value == TDim::value,
Expand Down
8 changes: 5 additions & 3 deletions include/alpaka/kernel/TaskKernelCpuSerial.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,12 @@ namespace alpaka
{
public:
template<typename TWorkDiv>
ALPAKA_FN_HOST TaskKernelCpuSerial(TWorkDiv&& workDiv, TKernelFnObj kernelFnObj, TArgs&&... args)
ALPAKA_FN_HOST TaskKernelCpuSerial(
TWorkDiv&& workDiv,
KernelBundle<TKernelFnObj, TArgs...> const& KernelBundle)
: WorkDivMembers<TDim, TIdx>(std::forward<TWorkDiv>(workDiv))
, m_kernelFnObj(std::move(kernelFnObj))
, m_args(std::forward<TArgs>(args)...)
, m_kernelFnObj(KernelBundle.m_kernelFn)
, m_args(KernelBundle.m_args)
{
static_assert(
Dim<std::decay_t<TWorkDiv>>::value == TDim::value,
Expand Down
Loading

0 comments on commit 0038fa9

Please sign in to comment.