diff --git a/include/alpaka/acc/AccCpuOmp2Blocks.hpp b/include/alpaka/acc/AccCpuOmp2Blocks.hpp index c495dcc933c3..532a7ce3f4a0 100644 --- a/include/alpaka/acc/AccCpuOmp2Blocks.hpp +++ b/include/alpaka/acc/AccCpuOmp2Blocks.hpp @@ -208,12 +208,6 @@ namespace alpaka { using type = alpaka::AccCpuOmp2Blocks; }; - - template - struct MemVisibility> - { - using type = alpaka::MemVisibleCPU; - }; } // namespace trait } // namespace alpaka diff --git a/include/alpaka/acc/AccCpuOmp2Threads.hpp b/include/alpaka/acc/AccCpuOmp2Threads.hpp index 7188bb714671..eb95dd41be0d 100644 --- a/include/alpaka/acc/AccCpuOmp2Threads.hpp +++ b/include/alpaka/acc/AccCpuOmp2Threads.hpp @@ -219,12 +219,6 @@ namespace alpaka { using type = alpaka::AccCpuOmp2Threads; }; - - template - struct MemVisibility> - { - using type = alpaka::MemVisibleCPU; - }; } // namespace trait } // namespace alpaka diff --git a/include/alpaka/acc/AccCpuSerial.hpp b/include/alpaka/acc/AccCpuSerial.hpp index a5931443f3b2..0eeaf407ae89 100644 --- a/include/alpaka/acc/AccCpuSerial.hpp +++ b/include/alpaka/acc/AccCpuSerial.hpp @@ -33,7 +33,6 @@ #include "alpaka/acc/Tag.hpp" #include "alpaka/core/Concepts.hpp" #include "alpaka/dev/DevCpu.hpp" -#include "alpaka/mem/Visibility.hpp" #include #include @@ -203,12 +202,6 @@ namespace alpaka { using type = alpaka::AccCpuSerial; }; - - template - struct MemVisibility> - { - using type = alpaka::MemVisibleCPU; - }; } // namespace trait } // namespace alpaka diff --git a/include/alpaka/acc/AccCpuSycl.hpp b/include/alpaka/acc/AccCpuSycl.hpp index 079b75786453..7a2615fc9de2 100644 --- a/include/alpaka/acc/AccCpuSycl.hpp +++ b/include/alpaka/acc/AccCpuSycl.hpp @@ -87,12 +87,6 @@ namespace alpaka::trait { using type = alpaka::AccCpuSycl; }; - - template - struct MemVisibility> - { - using type = alpaka::MemVisibleCPU; - }; } // namespace alpaka::trait #endif diff --git a/include/alpaka/acc/AccCpuTbbBlocks.hpp b/include/alpaka/acc/AccCpuTbbBlocks.hpp index f6acb28fa4b9..ed5ee9b3ed30 100644 --- a/include/alpaka/acc/AccCpuTbbBlocks.hpp +++ b/include/alpaka/acc/AccCpuTbbBlocks.hpp @@ -199,12 +199,6 @@ namespace alpaka { using type = alpaka::AccCpuTbbBlocks; }; - - template - struct MemVisibility> - { - using type = alpaka::MemVisibleCPU; - }; } // namespace trait } // namespace alpaka diff --git a/include/alpaka/acc/AccCpuThreads.hpp b/include/alpaka/acc/AccCpuThreads.hpp index a735f4a170de..fa58291c1918 100644 --- a/include/alpaka/acc/AccCpuThreads.hpp +++ b/include/alpaka/acc/AccCpuThreads.hpp @@ -227,12 +227,6 @@ namespace alpaka { using type = alpaka::AccCpuThreads; }; - - template - struct MemVisibility> - { - using type = alpaka::MemVisibleCPU; - }; } // namespace trait } // namespace alpaka diff --git a/include/alpaka/acc/AccFpgaSyclIntel.hpp b/include/alpaka/acc/AccFpgaSyclIntel.hpp index 26b15a83f129..db4c0b94c09d 100644 --- a/include/alpaka/acc/AccFpgaSyclIntel.hpp +++ b/include/alpaka/acc/AccFpgaSyclIntel.hpp @@ -87,12 +87,6 @@ namespace alpaka::trait { using type = alpaka::AccFpgaSyclIntel; }; - - template - struct MemVisibility> - { - using type = alpaka::MemVisibleFpgaSyclIntel; - }; } // namespace alpaka::trait #endif diff --git a/include/alpaka/acc/AccGenericSycl.hpp b/include/alpaka/acc/AccGenericSycl.hpp index b931af9fc629..012db0f33aaa 100644 --- a/include/alpaka/acc/AccGenericSycl.hpp +++ b/include/alpaka/acc/AccGenericSycl.hpp @@ -102,12 +102,6 @@ namespace alpaka::trait using type = TAcc; }; - template - struct MemVisibility> - { - using type = alpaka::MemVisibleGenericSycl; - }; - //! The SYCL accelerator device properties get trait specialization. template typename TAcc, typename TDim, typename TIdx> struct GetAccDevProps< diff --git a/include/alpaka/acc/AccGpuCudaRt.hpp b/include/alpaka/acc/AccGpuCudaRt.hpp index 30cf9ffdd456..5f27e519722d 100644 --- a/include/alpaka/acc/AccGpuCudaRt.hpp +++ b/include/alpaka/acc/AccGpuCudaRt.hpp @@ -28,12 +28,6 @@ namespace alpaka { using type = alpaka::AccGpuCudaRt; }; - - template - struct MemVisibility> - { - using type = alpaka::MemVisibleGpuCudaRt; - }; } // namespace trait } // namespace alpaka diff --git a/include/alpaka/acc/AccGpuHipRt.hpp b/include/alpaka/acc/AccGpuHipRt.hpp index 215a4848e318..43c94ab831bc 100644 --- a/include/alpaka/acc/AccGpuHipRt.hpp +++ b/include/alpaka/acc/AccGpuHipRt.hpp @@ -28,12 +28,6 @@ namespace alpaka { using type = alpaka::AccGpuHipRt; }; - - template - struct MemVisibility> - { - using type = alpaka::MemVisibleGpuHipRt; - }; } // namespace trait } // namespace alpaka diff --git a/include/alpaka/acc/AccGpuSyclIntel.hpp b/include/alpaka/acc/AccGpuSyclIntel.hpp index 622b8ea0a02e..bc60307ee17e 100644 --- a/include/alpaka/acc/AccGpuSyclIntel.hpp +++ b/include/alpaka/acc/AccGpuSyclIntel.hpp @@ -87,12 +87,6 @@ namespace alpaka::trait { using type = alpaka::AccGpuSyclIntel; }; - - template - struct MemVisibility> - { - using type = alpaka::MemVisibleGpuSyclIntel; - }; } // namespace alpaka::trait #endif diff --git a/include/alpaka/alpaka.hpp b/include/alpaka/alpaka.hpp index 99cd03754ae2..204c74fdc7f0 100644 --- a/include/alpaka/alpaka.hpp +++ b/include/alpaka/alpaka.hpp @@ -129,6 +129,7 @@ #include "alpaka/math/MathStdLib.hpp" #include "alpaka/math/MathUniformCudaHipBuiltIn.hpp" // mem +#include "alpaka/mem/Visibility.hpp" #include "alpaka/mem/alloc/AllocCpuAligned.hpp" #include "alpaka/mem/alloc/AllocCpuNew.hpp" #include "alpaka/mem/alloc/Traits.hpp" @@ -170,6 +171,7 @@ #include "alpaka/meta/Integral.hpp" #include "alpaka/meta/IsArrayOrVector.hpp" #include "alpaka/meta/IsStrictBase.hpp" +#include "alpaka/meta/IsTuple.hpp" #include "alpaka/meta/NdLoop.hpp" #include "alpaka/meta/NonZero.hpp" #include "alpaka/meta/Set.hpp" diff --git a/include/alpaka/dev/DevCpu.hpp b/include/alpaka/dev/DevCpu.hpp index e36c263072fa..ac294cab229a 100644 --- a/include/alpaka/dev/DevCpu.hpp +++ b/include/alpaka/dev/DevCpu.hpp @@ -8,6 +8,7 @@ #include "alpaka/dev/Traits.hpp" #include "alpaka/dev/common/QueueRegistry.hpp" #include "alpaka/dev/cpu/SysInfo.hpp" +#include "alpaka/mem/Visibility.hpp" #include "alpaka/mem/buf/Traits.hpp" #include "alpaka/platform/Traits.hpp" #include "alpaka/queue/Properties.hpp" @@ -185,6 +186,12 @@ namespace alpaka { using type = PlatformCpu; }; + + template<> + struct MemVisibility + { + using type = alpaka::MemVisibleCPU; + }; } // namespace trait using QueueCpuNonBlocking = QueueGenericThreadsNonBlocking; diff --git a/include/alpaka/dev/DevCpuSycl.hpp b/include/alpaka/dev/DevCpuSycl.hpp index 04b15a867558..fd58370e8931 100644 --- a/include/alpaka/dev/DevCpuSycl.hpp +++ b/include/alpaka/dev/DevCpuSycl.hpp @@ -12,6 +12,15 @@ namespace alpaka { using DevCpuSycl = DevGenericSycl; + + namespace trait + { + template<> + struct MemVisibility + { + using type = alpaka::MemVisibleCPU; + }; + } // namespace trait } // namespace alpaka #endif diff --git a/include/alpaka/dev/DevCudaRt.hpp b/include/alpaka/dev/DevCudaRt.hpp index 92dcba3a89b4..a487fa26aee1 100644 --- a/include/alpaka/dev/DevCudaRt.hpp +++ b/include/alpaka/dev/DevCudaRt.hpp @@ -13,6 +13,15 @@ namespace alpaka { //! The CUDA RT device handle. using DevCudaRt = DevUniformCudaHipRt; + + namespace trait + { + template<> + struct MemVisibility + { + using type = alpaka::MemVisibleGpuCudaRt; + }; + } // namespace trait } // namespace alpaka #endif // ALPAKA_ACC_GPU_CUDA_ENABLED diff --git a/include/alpaka/dev/DevFpgaSyclIntel.hpp b/include/alpaka/dev/DevFpgaSyclIntel.hpp index 516027db6b2a..5e4c17ad2502 100644 --- a/include/alpaka/dev/DevFpgaSyclIntel.hpp +++ b/include/alpaka/dev/DevFpgaSyclIntel.hpp @@ -12,6 +12,15 @@ namespace alpaka { using DevFpgaSyclIntel = DevGenericSycl; + + namespace trait + { + template<> + struct MemVisibility + { + using type = alpaka::MemVisibleFpgaSyclIntel; + }; + } // namespace trait } // namespace alpaka #endif diff --git a/include/alpaka/dev/DevGpuSyclIntel.hpp b/include/alpaka/dev/DevGpuSyclIntel.hpp index 9897d40ebbc5..0b8786a35eb7 100644 --- a/include/alpaka/dev/DevGpuSyclIntel.hpp +++ b/include/alpaka/dev/DevGpuSyclIntel.hpp @@ -12,6 +12,15 @@ namespace alpaka { using DevGpuSyclIntel = DevGenericSycl; + + namespace trait + { + template<> + struct MemVisibility + { + using type = alpaka::MemVisibleGpuSyclIntel; + }; + } // namespace trait } // namespace alpaka #endif diff --git a/include/alpaka/dev/DevHipRt.hpp b/include/alpaka/dev/DevHipRt.hpp index 819c2f5c4543..075fb3cf5efd 100644 --- a/include/alpaka/dev/DevHipRt.hpp +++ b/include/alpaka/dev/DevHipRt.hpp @@ -13,6 +13,15 @@ namespace alpaka { //! The HIP RT device handle. using DevHipRt = DevUniformCudaHipRt; + + namespace trait + { + template<> + struct MemVisibility + { + using type = alpaka::MemVisibleGpuHipRt; + }; + } // namespace trait } // namespace alpaka #endif // ALPAKA_ACC_GPU_HIP_ENABLED diff --git a/include/alpaka/mem/Visibility.hpp b/include/alpaka/mem/Visibility.hpp index 1188c459a7ad..3e4fea635523 100644 --- a/include/alpaka/mem/Visibility.hpp +++ b/include/alpaka/mem/Visibility.hpp @@ -4,14 +4,18 @@ #pragma once +#include "alpaka/meta/ForEachType.hpp" +#include "alpaka/meta/IsTuple.hpp" #include "alpaka/meta/TypeListOps.hpp" #include +#include +#include #define CREATE_MEM_VISIBILITY(mem_name) \ struct mem_name \ { \ - static std::string get_name() \ + static std::string name() \ { \ return #mem_name; \ } \ @@ -31,17 +35,70 @@ namespace alpaka //! Get memory visibility from a type. //! Normally it is acc or buffer type. //! - //! \tparam Type which implements the trait - //! \return Memory visibility type + //! \tparam TType which implements the trait template struct MemVisibility; } // namespace trait - template + namespace detail + { + struct AppendMemTypeName + { + template + void operator()(std::vector& vs) + { + vs.push_back(TTYPE::name()); + } + }; + } // namespace detail + + template + static std::string getMemVisiblityName() + { + using MemVisibilityType = typename alpaka::trait::MemVisibility>::type; + if constexpr(alpaka::meta::isTuple()) + { + std::vector vs; + alpaka::meta::forEachType(detail::AppendMemTypeName{}, vs); + + std::stringstream ss; + ss << "<"; + for(auto i = 0; i < vs.size(); ++i) + { + if(i == (vs.size() - 1)) + { + ss << vs[i] << ">"; + } + else + { + ss << vs[i] << ", "; + } + } + return ss.str(); + } + else + { + return MemVisibilityType::name(); + } + } + + template + static std::string getMemVisiblityName(TType) + { + return getMemVisiblityName(); + } + + template inline constexpr bool hasSameMemView() { return alpaka::meta::Contains< typename alpaka::trait::MemVisibility::type, - typename alpaka::trait::MemVisibility::type>::value; + typename alpaka::trait::MemVisibility::type>::value; + } + + template + inline constexpr bool hasSameMemView(TDev, TBuf) + { + return hasSameMemView, std::decay_t>(); } } // namespace alpaka diff --git a/include/alpaka/mem/buf/BufCudaRt.hpp b/include/alpaka/mem/buf/BufCudaRt.hpp index 62bc8316eb9f..79288b689c3c 100644 --- a/include/alpaka/mem/buf/BufCudaRt.hpp +++ b/include/alpaka/mem/buf/BufCudaRt.hpp @@ -5,8 +5,10 @@ #pragma once #include "alpaka/core/ApiCudaRt.hpp" +#include "alpaka/mem/Visibility.hpp" #include "alpaka/mem/buf/BufUniformCudaHipRt.hpp" + #ifdef ALPAKA_ACC_GPU_CUDA_ENABLED namespace alpaka @@ -14,11 +16,14 @@ namespace alpaka template using BufCudaRt = BufUniformCudaHipRt; - template - struct MemVisibility> + namespace trait { - using type = std::tuple; - }; + template + struct MemVisibility> + { + using type = std::tuple; + }; + } // namespace trait } // namespace alpaka #endif // ALPAKA_ACC_GPU_CUDA_ENABLED diff --git a/include/alpaka/meta/IsTuple.hpp b/include/alpaka/meta/IsTuple.hpp new file mode 100644 index 000000000000..ee4a920923ba --- /dev/null +++ b/include/alpaka/meta/IsTuple.hpp @@ -0,0 +1,29 @@ +/* Copyright 2024 Simeon Ehrig + * SPDX-License-Identifier: MPL-2.0 + */ + +#pragma once + +#include +#include + +// copied from https://stackoverflow.com/a/51073558/22035743 +namespace alpaka::meta +{ + template + struct IsTuple : std::false_type + { + }; + + template + struct IsTuple> : std::true_type + { + }; + + template + constexpr bool isTuple() + { + return IsTuple>::value; + } + +} // namespace alpaka::meta