alpaka
Abstraction Library for Parallel Kernel Acceleration
Loading...
Searching...
No Matches
Platform.hpp
Go to the documentation of this file.
1/* Copyright 2025 Simeon Ehrig
2 * SPDX-License-Identifier: MPL-2.0
3 */
4
5#pragma once
6
12#include "alpaka/tag.hpp"
13
14#if ALPAKA_LANG_ONEAPI
15
16namespace alpaka
17{
18 namespace detail
19 {
20 template<>
21 struct SYCLDeviceSelector<deviceKind::Cpu>
22 {
23 auto operator()(sycl::device const& dev) const -> int
24 {
25 return dev.is_cpu() ? 1 : -1;
26 }
27 };
28
29 template<>
30 struct SYCLDeviceSelector<deviceKind::IntelGpu>
31 {
32 auto operator()(sycl::device const& dev) const -> int
33 {
34 auto const& vendor = dev.get_info<sycl::info::device::vendor>();
35 auto const is_intel_gpu = dev.is_gpu() && (vendor.find("Intel(R) Corporation") != std::string::npos);
36
37 return is_intel_gpu ? 1 : -1;
38 }
39 };
40
41 template<>
42 struct SYCLDeviceSelector<deviceKind::NvidiaGpu>
43 {
44 auto operator()(sycl::device const& dev) const -> int
45 {
46 auto const& vendor = dev.get_info<sycl::info::device::vendor>();
47 auto const is_nvidia_gpu = dev.is_gpu() && (vendor.find("NVIDIA") != std::string::npos);
48
49 return is_nvidia_gpu ? 1 : -1;
50 }
51 };
52
53 template<>
54 struct SYCLDeviceSelector<deviceKind::AmdGpu>
55 {
56 auto operator()(sycl::device const& dev) const -> int
57 {
58 auto const& vendor = dev.get_info<sycl::info::device::vendor>();
59 auto const is_amd_gpu = dev.is_gpu() && (vendor.find("AMD") != std::string::npos);
60
61 return is_amd_gpu ? 1 : -1;
62 }
63 };
64
65 } // namespace detail
66
67 namespace onHost
68 {
69 namespace internal
70 {
71 template<alpaka::concepts::DeviceKind T_DeviceKind>
72 struct MakePlatform::Op<api::OneApi, T_DeviceKind>
73 {
74 auto operator()(api::OneApi const&, T_DeviceKind) const
75 {
77 }
78 };
79 } // namespace internal
80 } // namespace onHost
81
82 namespace internal
83 {
84 template<alpaka::concepts::DeviceKind T_DeviceKind>
85 struct GetApi::Op<onHost::syclGeneric::Platform<api::OneApi, T_DeviceKind>>
86 {
87 decltype(auto) operator()(auto&& platform) const
88 {
89 alpaka::unused(platform);
90 return api::OneApi{};
91 }
92 };
93
94 template<alpaka::concepts::DeviceKind T_DeviceKind>
95 struct GetDeviceType::Op<onHost::syclGeneric::Platform<api::OneApi, T_DeviceKind>>
96 {
97 decltype(auto) operator()(auto&& platform) const
98 {
99 alpaka::unused(platform);
100 return T_DeviceKind{};
101 }
102 };
103 } // namespace internal
104} // namespace alpaka
105
106namespace alpaka::onHost::internal
107{
108 template<alpaka::concepts::DeviceKind T_DeviceKind, typename T_Any>
109 struct IsDataAccessible::SecondPath<api::OneApi, T_DeviceKind, T_Any>
110 {
111 static void getPtrType(auto deviceKind, auto& sycl_data_alloc_type, auto const& view)
112 {
113 try
114 {
115 auto platform
116 = onHost::make_sharedSingleton<syclGeneric::Platform<api::OneApi, ALPAKA_TYPEOF(deviceKind)>>();
117 auto sycl_context = platform->getContext();
118 auto sycl_alloc_type = get_pointer_type(Data::data(view), sycl_context);
119
120 if(sycl_alloc_type != sycl::usm::alloc::unknown)
121 sycl_data_alloc_type = sycl_alloc_type;
122 }
123 catch(...)
124 {
125 // do to mising drivers or other issues we can not query the pointer type, in this case we assume that
126 // the memory is not accessible for the device
127 }
128 }
129
130 bool operator()(api::OneApi usedApi, T_DeviceKind deviceKind, T_Any const& view) const
131 {
132 auto deviceKindList = onHost::supportedDevices(usedApi);
133 auto sycl_data_alloc_type = sycl::usm::alloc::unknown;
135 [&sycl_data_alloc_type, &view](auto... devKind)
136 { (getPtrType(devKind, sycl_data_alloc_type, view), ...); },
137 deviceKindList);
138
139 if(deviceKind == deviceKind::cpu || deviceKind == deviceKind::numaCpu)
140 {
141 /* If the device kind is not CPU and usm alloc type is shared, we do not know if the memory is shared
142 * within the same sycl context. Therefor only know we mark only shared and host alloced memory
143 * accessible in case the device kind is CPU.
144 */
145 if(sycl_data_alloc_type == sycl::usm::alloc::shared || sycl_data_alloc_type == sycl::usm::alloc::host)
146 return true;
147 }
148 return false;
149 }
150 };
151} // namespace alpaka::onHost::internal
152
153#endif
#define ALPAKA_TYPEOF(...)
Get the type of instance.
Definition common.hpp:153
constexpr auto cpu
Definition tag.hpp:170
constexpr auto numaCpu
Definition tag.hpp:180
constexpr DeviceKind deviceKind
Definition tag.hpp:30
constexpr Api api
Definition tag.hpp:24
Functionality which is usable on the host CPU controller thread.
Definition api.hpp:40
constexpr auto supportedDevices(auto const api)
Definition trait.hpp:153
auto make_sharedSingleton(T_Args &&... args)
Definition Handle.hpp:14
main alpaka namespace.
Definition alpaka.hpp:76
ALPAKA_FN_INLINE constexpr decltype(auto) apply(T_Func &&func, T_TupleLike &&tuple)
Applies a function to the elements of a tuple-like object.
Definition apply.hpp:35