diff --git a/include/alpaka/acc/AccCpuOmp2Blocks.hpp b/include/alpaka/acc/AccCpuOmp2Blocks.hpp index 532a7ce3f4a0..c495dcc933c3 100644 --- a/include/alpaka/acc/AccCpuOmp2Blocks.hpp +++ b/include/alpaka/acc/AccCpuOmp2Blocks.hpp @@ -208,6 +208,12 @@ 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 eb95dd41be0d..7188bb714671 100644 --- a/include/alpaka/acc/AccCpuOmp2Threads.hpp +++ b/include/alpaka/acc/AccCpuOmp2Threads.hpp @@ -219,6 +219,12 @@ 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 0eeaf407ae89..a5931443f3b2 100644 --- a/include/alpaka/acc/AccCpuSerial.hpp +++ b/include/alpaka/acc/AccCpuSerial.hpp @@ -33,6 +33,7 @@ #include "alpaka/acc/Tag.hpp" #include "alpaka/core/Concepts.hpp" #include "alpaka/dev/DevCpu.hpp" +#include "alpaka/mem/Visibility.hpp" #include #include @@ -202,6 +203,12 @@ 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 7a2615fc9de2..079b75786453 100644 --- a/include/alpaka/acc/AccCpuSycl.hpp +++ b/include/alpaka/acc/AccCpuSycl.hpp @@ -87,6 +87,12 @@ 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 ed5ee9b3ed30..f6acb28fa4b9 100644 --- a/include/alpaka/acc/AccCpuTbbBlocks.hpp +++ b/include/alpaka/acc/AccCpuTbbBlocks.hpp @@ -199,6 +199,12 @@ 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 fa58291c1918..a735f4a170de 100644 --- a/include/alpaka/acc/AccCpuThreads.hpp +++ b/include/alpaka/acc/AccCpuThreads.hpp @@ -227,6 +227,12 @@ 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 db4c0b94c09d..26b15a83f129 100644 --- a/include/alpaka/acc/AccFpgaSyclIntel.hpp +++ b/include/alpaka/acc/AccFpgaSyclIntel.hpp @@ -87,6 +87,12 @@ 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 012db0f33aaa..b931af9fc629 100644 --- a/include/alpaka/acc/AccGenericSycl.hpp +++ b/include/alpaka/acc/AccGenericSycl.hpp @@ -102,6 +102,12 @@ 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 5f27e519722d..30cf9ffdd456 100644 --- a/include/alpaka/acc/AccGpuCudaRt.hpp +++ b/include/alpaka/acc/AccGpuCudaRt.hpp @@ -28,6 +28,12 @@ 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 43c94ab831bc..215a4848e318 100644 --- a/include/alpaka/acc/AccGpuHipRt.hpp +++ b/include/alpaka/acc/AccGpuHipRt.hpp @@ -28,6 +28,12 @@ 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 bc60307ee17e..622b8ea0a02e 100644 --- a/include/alpaka/acc/AccGpuSyclIntel.hpp +++ b/include/alpaka/acc/AccGpuSyclIntel.hpp @@ -87,6 +87,12 @@ namespace alpaka::trait { using type = alpaka::AccGpuSyclIntel; }; + + template + struct MemVisibility> + { + using type = alpaka::MemVisibleGpuSyclIntel; + }; } // namespace alpaka::trait #endif diff --git a/include/alpaka/mem/Visibility.hpp b/include/alpaka/mem/Visibility.hpp new file mode 100644 index 000000000000..1188c459a7ad --- /dev/null +++ b/include/alpaka/mem/Visibility.hpp @@ -0,0 +1,47 @@ +/* Copyright 2023 Simeon Ehrig + * SPDX-License-Identifier: MPL-2.0 + */ + +#pragma once + +#include "alpaka/meta/TypeListOps.hpp" + +#include + +#define CREATE_MEM_VISIBILITY(mem_name) \ + struct mem_name \ + { \ + static std::string get_name() \ + { \ + return #mem_name; \ + } \ + } + +namespace alpaka +{ + CREATE_MEM_VISIBILITY(MemVisibleCPU); + CREATE_MEM_VISIBILITY(MemVisibleFpgaSyclIntel); + CREATE_MEM_VISIBILITY(MemVisibleGenericSycl); + CREATE_MEM_VISIBILITY(MemVisibleGpuCudaRt); + CREATE_MEM_VISIBILITY(MemVisibleGpuHipRt); + CREATE_MEM_VISIBILITY(MemVisibleGpuSyclIntel); + + namespace trait + { + //! Get memory visibility from a type. + //! Normally it is acc or buffer type. + //! + //! \tparam Type which implements the trait + //! \return Memory visibility type + template + struct MemVisibility; + } // namespace trait + + template + inline constexpr bool hasSameMemView() + { + return alpaka::meta::Contains< + typename alpaka::trait::MemVisibility::type, + typename alpaka::trait::MemVisibility::type>::value; + } +} // namespace alpaka diff --git a/include/alpaka/mem/buf/BufCpu.hpp b/include/alpaka/mem/buf/BufCpu.hpp index 4bfc91c73332..282ef672cfb9 100644 --- a/include/alpaka/mem/buf/BufCpu.hpp +++ b/include/alpaka/mem/buf/BufCpu.hpp @@ -11,6 +11,7 @@ #include "alpaka/core/Vectorize.hpp" #include "alpaka/dev/DevCpu.hpp" #include "alpaka/dev/Traits.hpp" +#include "alpaka/mem/Visibility.hpp" #include "alpaka/mem/alloc/AllocCpuAligned.hpp" #include "alpaka/mem/buf/Traits.hpp" #include "alpaka/mem/view/ViewAccessOps.hpp" @@ -307,6 +308,13 @@ namespace alpaka { using type = TIdx; }; + + template + struct MemVisibility> + { + using type = std::tuple; + }; + } // namespace trait } // namespace alpaka diff --git a/include/alpaka/mem/buf/BufCpuSycl.hpp b/include/alpaka/mem/buf/BufCpuSycl.hpp index d63eebf540ca..a04a94e66629 100644 --- a/include/alpaka/mem/buf/BufCpuSycl.hpp +++ b/include/alpaka/mem/buf/BufCpuSycl.hpp @@ -13,6 +13,12 @@ namespace alpaka { template using BufCpuSycl = BufGenericSycl; + + template + struct MemVisibility> + { + using type = std::tuple; + }; } // namespace alpaka #endif diff --git a/include/alpaka/mem/buf/BufCudaRt.hpp b/include/alpaka/mem/buf/BufCudaRt.hpp index a5e0020bdb62..62bc8316eb9f 100644 --- a/include/alpaka/mem/buf/BufCudaRt.hpp +++ b/include/alpaka/mem/buf/BufCudaRt.hpp @@ -13,6 +13,12 @@ namespace alpaka { template using BufCudaRt = BufUniformCudaHipRt; + + template + struct MemVisibility> + { + using type = std::tuple; + }; } // namespace alpaka #endif // ALPAKA_ACC_GPU_CUDA_ENABLED diff --git a/include/alpaka/mem/buf/BufFpgaSyclIntel.hpp b/include/alpaka/mem/buf/BufFpgaSyclIntel.hpp index 2dca26f1984f..712406fa8b0e 100644 --- a/include/alpaka/mem/buf/BufFpgaSyclIntel.hpp +++ b/include/alpaka/mem/buf/BufFpgaSyclIntel.hpp @@ -13,6 +13,12 @@ namespace alpaka { template using BufFpgaSyclIntel = BufGenericSycl; + + template + struct MemVisibility> + { + using type = std::tuple; + }; } // namespace alpaka #endif diff --git a/include/alpaka/mem/buf/BufGenericSycl.hpp b/include/alpaka/mem/buf/BufGenericSycl.hpp index b4a5fd94ed54..a0180c46a7fd 100644 --- a/include/alpaka/mem/buf/BufGenericSycl.hpp +++ b/include/alpaka/mem/buf/BufGenericSycl.hpp @@ -258,6 +258,12 @@ namespace alpaka::trait return getPtrNative(buf); } }; + + template + struct MemVisibility> + { + using type = std::tuple; + }; } // namespace alpaka::trait # include "alpaka/mem/buf/sycl/Copy.hpp" diff --git a/include/alpaka/mem/buf/BufGpuSyclIntel.hpp b/include/alpaka/mem/buf/BufGpuSyclIntel.hpp index dd20f8a39648..584e799f4e28 100644 --- a/include/alpaka/mem/buf/BufGpuSyclIntel.hpp +++ b/include/alpaka/mem/buf/BufGpuSyclIntel.hpp @@ -13,6 +13,12 @@ namespace alpaka { template using BufGpuSyclIntel = BufGenericSycl; + + template + struct MemVisibility> + { + using type = std::tuple; + }; } // namespace alpaka #endif diff --git a/include/alpaka/mem/buf/BufHipRt.hpp b/include/alpaka/mem/buf/BufHipRt.hpp index 4a59bc46e5d5..75015cbc7401 100644 --- a/include/alpaka/mem/buf/BufHipRt.hpp +++ b/include/alpaka/mem/buf/BufHipRt.hpp @@ -13,6 +13,12 @@ namespace alpaka { template using BufHipRt = BufUniformCudaHipRt; + + template + struct MemVisibility> + { + using type = std::tuple; + }; } // namespace alpaka #endif // ALPAKA_ACC_GPU_HIP_ENABLED