Skip to content

Commit

Permalink
implement concept alpaka::Tag
Browse files Browse the repository at this point in the history
  • Loading branch information
SimeonEhrig committed Oct 2, 2024
1 parent 9c3df80 commit 3527b00
Show file tree
Hide file tree
Showing 40 changed files with 186 additions and 128 deletions.
2 changes: 1 addition & 1 deletion example/bufferCopy/src/bufferCopy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ struct FillBufferKernel
// Instead, a single accelerator is selected once from the active accelerators and the kernels are executed with the
// selected accelerator only. If you use the example as the starting point for your project, you can rename the
// example() function to main() and move the accelerator tag to the function body.
template<typename TAccTag>
template<alpaka::Tag TAccTag>
auto example(TAccTag const&) -> int
{
// Define the index domain
Expand Down
2 changes: 1 addition & 1 deletion example/complex/src/complex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ struct ComplexKernel
// Instead, a single accelerator is selected once from the active accelerators and the kernels are executed with the
// selected accelerator only. If you use the example as the starting point for your project, you can rename the
// example() function to main() and move the accelerator tag to the function body.
template<typename TAccTag>
template<alpaka::Tag TAccTag>
auto example(TAccTag const&) -> int
{
using Idx = std::size_t;
Expand Down
2 changes: 1 addition & 1 deletion example/conv2DWithMdspan/src/conv2DWithMdspan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ auto FuzzyEqual(float a, float b) -> bool
// Instead, a single accelerator is selected once from the active accelerators and the kernels are executed with the
// selected accelerator only. If you use the example as the starting point for your project, you can rename the
// example() function to main() and move the accelerator tag to the function body.
template<typename TAccTag>
template<alpaka::Tag TAccTag>
auto example(TAccTag const&) -> int
{
// Define the index domain
Expand Down
2 changes: 1 addition & 1 deletion example/convolution1D/src/convolution1D.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ auto FuzzyEqual(float a, float b) -> bool
// Instead, a single accelerator is selected once from the active accelerators and the kernels are executed with the
// selected accelerator only. If you use the example as the starting point for your project, you can rename the
// example() function to main() and move the accelerator tag to the function body.
template<typename TAccTag>
template<alpaka::Tag TAccTag>
auto example(TAccTag const&) -> int
{
// Size of 1D arrays to be used in convolution integral
Expand Down
2 changes: 1 addition & 1 deletion example/convolution2D/src/convolution2D.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ auto FuzzyEqual(float a, float b) -> bool
// Instead, a single accelerator is selected once from the active accelerators and the kernels are executed with the
// selected accelerator only. If you use the example as the starting point for your project, you can rename the
// example() function to main() and move the accelerator tag to the function body.
template<typename TAccTag>
template<alpaka::Tag TAccTag>
auto example(TAccTag const&) -> int
{
// Define the index domain
Expand Down
2 changes: 1 addition & 1 deletion example/counterBasedRng/src/counterBasedRng.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ class CounterBasedRngKernel
// Instead, a single accelerator is selected once from the active accelerators and the kernels are executed with the
// selected accelerator only. If you use the example as the starting point for your project, you can rename the
// example() function to main() and move the accelerator tag to the function body.
template<typename TAccTag>
template<alpaka::Tag TAccTag>
auto example(TAccTag const&) -> int
{
// Define the index domain
Expand Down
2 changes: 1 addition & 1 deletion example/heatEquation/src/heatEquation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ auto exactSolution(double const x, double const t) -> double
//! Instead, a single accelerator is selected once from the active accelerators and the kernels are executed with the
//! selected accelerator only. If you use the example as the starting point for your project, you can rename the
//! example() function to main() and move the accelerator tag to the function body.
template<typename TAccTag>
template<alpaka::Tag TAccTag>
auto example(TAccTag const&) -> int
{
// Parameters (a user is supposed to change numNodesX, numTimeSteps)
Expand Down
2 changes: 1 addition & 1 deletion example/heatEquation2D/src/heatEquation2D.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
//! Instead, a single accelerator is selected once from the active accelerators and the kernels are executed with the
//! selected accelerator only. If you use the example as the starting point for your project, you can rename the
//! example() function to main() and move the accelerator tag to the function body.
template<typename TAccTag>
template<alpaka::Tag TAccTag>
auto example(TAccTag const&) -> int
{
// Set Dim and Idx type
Expand Down
2 changes: 1 addition & 1 deletion example/helloWorld/src/helloWorld.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ struct HelloWorldKernel
// Instead, a single accelerator is selected once from the active accelerators and the kernels are executed with the
// selected accelerator only. If you use the example as the starting point for your project, you can rename the
// example() function to main() and move the accelerator tag to the function body.
template<typename TAccTag>
template<alpaka::Tag TAccTag>
auto example(TAccTag const&) -> int
{
// Define the index domain
Expand Down
2 changes: 1 addition & 1 deletion example/helloWorldLambda/src/helloWorldLambda.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ void ALPAKA_FN_ACC hiWorldFunction(TAcc const& acc, size_t const nExclamationMar
// Instead, a single accelerator is selected once from the active accelerators and the kernels are executed with the
// selected accelerator only. If you use the example as the starting point for your project, you can rename the
// example() function to main() and move the accelerator tag to the function body.
template<typename TAccTag>
template<alpaka::Tag TAccTag>
auto example(TAccTag const&) -> int
{
// It requires support for extended lambdas when using nvcc as CUDA compiler.
Expand Down
2 changes: 1 addition & 1 deletion example/kernelSpecialization/src/kernelSpecialization.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ struct Kernel
// Instead, a single accelerator is selected once from the active accelerators and the kernels are executed with the
// selected accelerator only. If you use the example as the starting point for your project, you can rename the
// example() function to main() and move the accelerator tag to the function body.
template<typename TAccTag>
template<alpaka::Tag TAccTag>
auto example(TAccTag const&) -> int
{
// Define the accelerator
Expand Down
2 changes: 1 addition & 1 deletion example/matrixMulWithMdspan/src/matrixMulMdSpan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ inline void initializeMatrx(TMdSpan& span)
// Instead, a single accelerator is selected once from the active accelerators and the kernels are executed with the
// selected accelerator only. If you use the example as the starting point for your project, you can rename the
// example() function to main() and move the accelerator tag to the function body.
template<typename TAccTag>
template<alpaka::Tag TAccTag>
auto example(TAccTag const&) -> int
{
// Set number of dimensions (i.e 2) as a type
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ struct Kernel
// Instead, a single accelerator is selected once from the active accelerators and the kernels are executed with the
// selected accelerator only. If you use the example as the starting point for your project, you can rename the
// example() function to main() and move the accelerator tag to the function body.
template<typename TAccTag>
template<alpaka::Tag TAccTag>
auto example(TAccTag const&) -> int
{
// Defines and setup.
Expand Down
2 changes: 1 addition & 1 deletion example/parallelLoopPatterns/src/parallelLoopPatterns.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,7 @@ void openMPSimdStyle(TDev& dev, TQueue& queue, TBufAcc& bufAcc)
// Instead, a single accelerator is selected once from the active accelerators and the kernels are executed with the
// selected accelerator only. If you use the example as the starting point for your project, you can rename the
// example() function to main() and move the accelerator tag to the function body.
template<typename TAccTag>
template<alpaka::Tag TAccTag>
auto example(TAccTag const&) -> int
{
// Define the index domain, this example is only for 1d
Expand Down
2 changes: 1 addition & 1 deletion example/randomCells2D/src/randomCells2D.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ struct RunTimestepKernelVector
// Instead, a single accelerator is selected once from the active accelerators and the kernels are executed with the
// selected accelerator only. If you use the example as the starting point for your project, you can rename the
// example() function to main() and move the accelerator tag to the function body.
template<typename TAccTag>
template<alpaka::Tag TAccTag>
auto example(TAccTag const&) -> int
{
using Dim = alpaka::DimInt<2>;
Expand Down
14 changes: 7 additions & 7 deletions example/randomStrategies/src/randomStrategies.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ using RandomEngine = alpaka::rand::Philox4x32x10;


/// Parameters to set up the default accelerator, queue, and buffers
template<typename TAccTag>
template<alpaka::Tag TAccTag>
struct Box
{
// accelerator, queue, and work division typedefs
Expand Down Expand Up @@ -184,7 +184,7 @@ struct FillKernel
*
* File is in TSV format. One line for each "point"; line length is the number of "rolls".
*/
template<typename TAccTag>
template<alpaka::Tag TAccTag>
void saveDataAndShowAverage(std::string filename, float const* buffer, Box<TAccTag> const& box)
{
std::ofstream output(filename);
Expand All @@ -207,7 +207,7 @@ struct Writer;
template<>
struct Writer<Strategy::seed>
{
template<typename TAccTag>
template<alpaka::Tag TAccTag>
static void save(float const* buffer, Box<TAccTag> const& box)
{
saveDataAndShowAverage("out_seed.csv", buffer, box);
Expand All @@ -217,7 +217,7 @@ struct Writer<Strategy::seed>
template<>
struct Writer<Strategy::subsequence>
{
template<typename TAccTag>
template<alpaka::Tag TAccTag>
static void save(float const* buffer, Box<TAccTag> const& box)
{
saveDataAndShowAverage("out_subsequence.csv", buffer, box);
Expand All @@ -227,14 +227,14 @@ struct Writer<Strategy::subsequence>
template<>
struct Writer<Strategy::offset>
{
template<typename TAccTag>
template<alpaka::Tag TAccTag>
static void save(float const* buffer, Box<TAccTag> const& box)
{
saveDataAndShowAverage("out_offset.csv", buffer, box);
}
};

template<Strategy TStrategy, typename TAccTag>
template<Strategy TStrategy, alpaka::Tag TAccTag>
void runStrategy(Box<TAccTag>& box)
{
// Set up the pointer to the PRNG states buffer
Expand Down Expand Up @@ -326,7 +326,7 @@ void runStrategy(Box<TAccTag>& box)
// Instead, a single accelerator is selected once from the active accelerators and the kernels are executed with the
// selected accelerator only. If you use the example as the starting point for your project, you can rename the
// example() function to main() and move the accelerator tag to the function body.
template<typename TAccTag>
template<alpaka::Tag TAccTag>
auto example(TAccTag const&) -> int
{
Box<TAccTag> box; // Initialize the box
Expand Down
4 changes: 2 additions & 2 deletions example/tagSpecialization/src/tagSpecialization.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ std::string host_function_ver1<alpaka::TagGpuCudaRt>()
}

//! Function specialization via overloading
template<typename TTag>
template<alpaka::Tag TTag>
std::string host_function_ver2(TTag)
{
return "generic host function v2";
Expand Down Expand Up @@ -80,7 +80,7 @@ struct WrapperKernel
// Instead, a single accelerator is selected once from the active accelerators and the kernels are executed with the
// selected accelerator only. If you use the example as the starting point for your project, you can rename the
// example() function to main() and move the accelerator tag to the function body.
template<typename TAccTag>
template<alpaka::Tag TAccTag>
auto example(TAccTag const&) -> int
{
// Define the accelerator
Expand Down
2 changes: 1 addition & 1 deletion example/vectorAdd/src/vectorAdd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class VectorAddKernel
// Instead, a single accelerator is selected once from the active accelerators and the kernels are executed with the
// selected accelerator only. If you use the example as the starting point for your project, you can rename the
// example() function to main() and move the accelerator tag to the function body.
template<typename TAccTag>
template<alpaka::Tag TAccTag>
auto example(TAccTag const&) -> int
{
// Define the index domain
Expand Down
30 changes: 18 additions & 12 deletions include/alpaka/acc/AccGenericSycl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,13 @@

namespace alpaka
{
template<typename TTag, typename TAcc, typename TDim, typename TIdx, typename TKernelFnObj, typename... TArgs>
template<alpaka::Tag TTag, typename TAcc, typename TDim, typename TIdx, typename TKernelFnObj, typename... TArgs>
class TaskKernelGenericSycl;

//! The SYCL accelerator.
//!
//! This accelerator allows parallel kernel execution on SYCL devices.
template<typename TTag, typename TDim, typename TIdx>
template<alpaka::Tag TTag, typename TDim, typename TIdx>
class AccGenericSycl
: public WorkDivGenericSycl<TDim, TIdx>
, public gb::IdxGbGenericSycl<TDim, TIdx>
Expand Down Expand Up @@ -103,26 +103,26 @@ namespace alpaka
namespace alpaka::trait
{
//! The SYCL accelerator type trait specialization.
template<typename TTag, typename TDim, typename TIdx>
template<alpaka::Tag TTag, typename TDim, typename TIdx>
struct AccType<AccGenericSycl<TTag, TDim, TIdx>>
{
using type = AccGenericSycl<TTag, TDim, TIdx>;
};

//! The SYCL single thread accelerator type trait specialization.
template<typename TTag, typename TDim, typename TIdx>
template<alpaka::Tag TTag, typename TDim, typename TIdx>
struct IsSingleThreadAcc<AccGenericSycl<TTag, TDim, TIdx>> : std::false_type
{
};

//! The SYCL multi thread accelerator type trait specialization.
template<typename TTag, typename TDim, typename TIdx>
template<alpaka::Tag TTag, typename TDim, typename TIdx>
struct IsMultiThreadAcc<AccGenericSycl<TTag, TDim, TIdx>> : std::true_type
{
};

//! The SYCL accelerator device properties get trait specialization.
template<typename TTag, typename TDim, typename TIdx>
template<alpaka::Tag TTag, typename TDim, typename TIdx>
struct GetAccDevProps<AccGenericSycl<TTag, TDim, TIdx>>
{
static auto getAccDevProps(DevGenericSycl<TTag> const& dev) -> AccDevProps<TDim, TIdx>
Expand Down Expand Up @@ -159,7 +159,7 @@ namespace alpaka::trait
};

//! The SYCL accelerator name trait specialization.
template<typename TTag, typename TDim, typename TIdx>
template<alpaka::Tag TTag, typename TDim, typename TIdx>
struct GetAccName<AccGenericSycl<TTag, TDim, TIdx>>
{
static auto getAccName() -> std::string
Expand All @@ -170,21 +170,27 @@ namespace alpaka::trait
};

//! The SYCL accelerator device type trait specialization.
template<typename TTag, typename TDim, typename TIdx>
template<alpaka::Tag TTag, typename TDim, typename TIdx>
struct DevType<AccGenericSycl<TTag, TDim, TIdx>>
{
using type = DevGenericSycl<TTag>;
};

//! The SYCL accelerator dimension getter trait specialization.
template<typename TTag, typename TDim, typename TIdx>
template<alpaka::Tag TTag, typename TDim, typename TIdx>
struct DimType<AccGenericSycl<TTag, TDim, TIdx>>
{
using type = TDim;
};

//! The SYCL accelerator execution task type trait specialization.
template<typename TTag, typename TDim, typename TIdx, typename TWorkDiv, typename TKernelFnObj, typename... TArgs>
template<
alpaka::Tag TTag,
typename TDim,
typename TIdx,
typename TWorkDiv,
typename TKernelFnObj,
typename... TArgs>
struct CreateTaskKernel<AccGenericSycl<TTag, TDim, TIdx>, TWorkDiv, TKernelFnObj, TArgs...>
{
static auto createTaskKernel(TWorkDiv const& workDiv, TKernelFnObj const& kernelFnObj, TArgs&&... args)
Expand All @@ -197,14 +203,14 @@ namespace alpaka::trait
};

//! The SYCL execution task platform type trait specialization.
template<typename TTag, typename TDim, typename TIdx>
template<alpaka::Tag TTag, typename TDim, typename TIdx>
struct PlatformType<AccGenericSycl<TTag, TDim, TIdx>>
{
using type = PlatformGenericSycl<TTag>;
};

//! The SYCL accelerator idx type trait specialization.
template<typename TTag, typename TDim, typename TIdx>
template<alpaka::Tag TTag, typename TDim, typename TIdx>
struct IdxType<AccGenericSycl<TTag, TDim, TIdx>>
{
using type = TIdx;
Expand Down
24 changes: 20 additions & 4 deletions include/alpaka/acc/Tag.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,18 @@
#pragma once

#include "alpaka/core/BoostPredef.hpp"
#include "alpaka/core/Concepts.hpp"

#include <iostream>
#include <type_traits>

namespace alpaka
{
struct ConceptTag;
} // namespace alpaka

#define CREATE_ACC_TAG(tag_name) \
struct tag_name \
struct tag_name : public concepts::Implements<alpaka::ConceptTag, tag_name> \
{ \
static std::string get_name() \
{ \
Expand All @@ -20,6 +26,8 @@

namespace alpaka
{
struct ConceptTag;

CREATE_ACC_TAG(TagCpuOmp2Blocks);
CREATE_ACC_TAG(TagCpuOmp2Threads);
CREATE_ACC_TAG(TagCpuSerial);
Expand All @@ -32,12 +40,20 @@ namespace alpaka
CREATE_ACC_TAG(TagGpuHipRt);
CREATE_ACC_TAG(TagGpuSyclIntel);

template<typename T>
concept Tag = requires {
{
T::get_name()
} -> std::same_as<std::string>;
requires alpaka::concepts::isImplementsConcept<alpaka::ConceptTag, T>;
};

namespace trait
{
template<typename TAcc>
struct AccToTag;

template<typename TTag, typename TDim, typename TIdx>
template<alpaka::Tag TTag, typename TDim, typename TIdx>
struct TagToAcc;
} // namespace trait

Expand All @@ -50,10 +66,10 @@ namespace alpaka
//! \tparam TTag alpaka tag type
//! \tparam TDim dimension of the mapped acc type
//! \tparam TIdx index type of the mapped acc type
template<typename TTag, typename TDim, typename TIdx>
template<alpaka::Tag TTag, typename TDim, typename TIdx>
using TagToAcc = typename trait::TagToAcc<TTag, TDim, TIdx>::type;

template<typename TAcc, typename... TTag>
template<typename TAcc, alpaka::Tag... TTag>
inline constexpr bool accMatchesTags = (std::is_same_v<alpaka::AccToTag<TAcc>, TTag> || ...);

//! list of all available tags
Expand Down
Loading

0 comments on commit 3527b00

Please sign in to comment.