40 const std::lock_guard<std::mutex> Guard(
41 GlobalHandler::instance().getPlatformMapMutex());
43 std::vector<PlatformImplPtr> &PlatformCache =
44 GlobalHandler::instance().getPlatformCache();
47 for (
const auto &PlatImpl : PlatformCache) {
53 Result = std::make_shared<platform_impl>(
PiPlatform, Plugin);
54 PlatformCache.emplace_back(Result);
65 sizeof(Plt), &Plt,
nullptr);
66 return getOrMakePlatformImpl(Plt, Plugin);
77 auto IsNVIDIAOpenCL = [](
platform Platform) {
78 if (Platform.is_host())
81 const bool HasCUDA = Platform.
get_info<info::platform::name>().find(
82 "NVIDIA CUDA") != std::string::npos;
85 const bool IsCUDAOCL = (HasCUDA && Backend == backend::opencl);
87 std::cout <<
"SYCL_PI_TRACE[all]: "
88 <<
"NVIDIA CUDA OpenCL platform found but is not compatible."
93 return IsNVIDIAOpenCL(Platform);
96 std::vector<platform> platform_impl::get_platforms() {
97 std::vector<platform> Platforms;
100 for (
plugin &Plugin : Plugins) {
109 std::vector<RT::PiPlatform> PiPlatforms(NumPlatforms);
111 NumPlatforms, PiPlatforms.data(),
nullptr) !=
PI_SUCCESS)
115 platform Platform = detail::createSyclObjFromImpl<platform>(
118 std::lock_guard<std::mutex> Guard(*Plugin.getPluginMutex());
125 Platforms.push_back(Platform);
138 GlobalHandler::registerDefaultContextReleaseHandler();
164 std::find_if(Plugins.begin(), Plugins.end(), [Platform](
plugin &Plugin) {
165 return Plugin.containsPiPlatform(Platform);
167 if (It == Plugins.end())
181 &PiDevType,
nullptr);
187 backend FilterBackend = Filter.Backend;
189 if (FilterBackend == Backend || FilterBackend ==
backend::all) {
194 if (!Filter.HasDeviceNum || DeviceNum == Filter.DeviceNum) {
195 PiDevices[InsertIDx++] = Device;
198 }
else if (FilterDevType == DeviceType) {
199 if (!Filter.HasDeviceNum || DeviceNum == Filter.DeviceNum) {
200 PiDevices[InsertIDx++] = Device;
208 PiDevices.resize(InsertIDx);
215 std::shared_ptr<device_impl> platform_impl::getOrMakeDeviceImpl(
217 const std::lock_guard<std::mutex> Guard(MDeviceMapMutex);
220 for (
const std::weak_ptr<device_impl> &DeviceWP : MDeviceCache) {
221 if (std::shared_ptr<device_impl> Device = DeviceWP.lock()) {
222 if (Device->getHandleRef() ==
PiDevice)
228 std::shared_ptr<device_impl> Result =
229 std::make_shared<device_impl>(
PiDevice, PlatformImpl);
230 MDeviceCache.emplace_back(Result);
237 std::vector<device> Res;
238 if (is_host() && (DeviceType == info::device_type::host ||
249 if (is_host() || DeviceType == info::device_type::host)
255 MPlatform, pi::cast<RT::PiDeviceType>(DeviceType), 0,
256 pi::cast<RT::PiDevice *>(
nullptr), &NumDevices);
258 if (NumDevices == 0) {
265 auto It = std::find_if(Plugins.begin(), Plugins.end(),
266 [&Platform = MPlatform](
plugin &Plugin) {
267 return Plugin.containsPiPlatform(Platform);
269 if (It != Plugins.end()) {
270 std::lock_guard<std::mutex> Guard(*(It->getPluginMutex()));
271 (*It).adjustLastDeviceId(MPlatform);
276 std::vector<RT::PiDevice> PiDevices(NumDevices);
279 pi::cast<RT::PiDeviceType>(DeviceType),
280 NumDevices, PiDevices.data(),
nullptr);
289 PlatformImplPtr PlatformImpl = getOrMakePlatformImpl(MPlatform, Plugin);
291 PiDevices.begin(), PiDevices.end(), std::back_inserter(Res),
293 return detail::createSyclObjFromImpl<device>(
294 PlatformImpl->getOrMakeDeviceImpl(PiDevice, PlatformImpl));
300 bool platform_impl::has_extension(
const std::string &ExtensionName)
const {
304 std::string AllExtensionNames =
307 return (AllExtensionNames.find(ExtensionName) != std::string::npos);
317 template <info::platform param>
319 platform_impl::get_info()
const {
321 return get_platform_info_host<param>();
329 bool platform_impl::has(
aspect Aspect)
const {
330 for (
const auto &dev : get_devices()) {
331 if (dev.has(Aspect) ==
false) {
338 #define __SYCL_PARAM_TRAITS_SPEC(param_type, param, ret_type) \
339 template ret_type platform_impl::get_info<info::param_type::param>() const;
341 #include <CL/sycl/info/platform_traits.def>
342 #undef __SYCL_PARAM_TRAITS_SPEC