-
Notifications
You must be signed in to change notification settings - Fork 738
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Initial support for ext_oneapi_composite_device. #12178
Changes from all commits
abab8b3
a3bc3e6
c559036
e5d70ea
26f9669
88b1017
28652e6
83bc72b
1f458be
031d0d9
8d68661
c866676
d7dd2b2
b5bba6a
4ad0840
e0e1b68
fe7dbdc
4e78c90
8b3d6c9
ee5c8fb
fd6bdbe
27faf1c
cefad83
b25e46e
daa047c
0816f64
81a9a2c
7c06067
43dc4fa
5b39de1
a1f6b09
110b757
6ffce19
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
//==---------- composite_device.hpp - SYCL Composite Device ----------------==// | ||
// | ||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
// See https://llvm.org/LICENSE.txt for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#pragma once | ||
|
||
#include <sycl/device.hpp> | ||
|
||
#include <vector> | ||
|
||
namespace sycl { | ||
inline namespace _V1 { | ||
namespace ext::oneapi::experimental { | ||
__SYCL_EXPORT std::vector<device> get_composite_devices(); | ||
} // namespace ext::oneapi::experimental | ||
} // namespace _V1 | ||
} // namespace sycl |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
//==---------- composite_device.cpp - SYCL Composite Device ----------------==// | ||
// | ||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
// See https://llvm.org/LICENSE.txt for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#include <sycl/ext/oneapi/experimental/composite_device.hpp> | ||
#include <sycl/platform.hpp> | ||
|
||
#include <unordered_set> | ||
|
||
namespace sycl { | ||
inline namespace _V1 { | ||
namespace ext::oneapi::experimental { | ||
std::vector<device> get_composite_devices() { | ||
// We use set to filter out duplicates, and unordered because we don't need it | ||
// to be sorted, and unordered provides faster insertion. | ||
std::unordered_set<device> Composites; | ||
auto Devs = sycl::device::get_devices(); | ||
for (const auto &D : Devs) { | ||
if (D.has(sycl::aspect::ext_oneapi_is_component)) { | ||
auto Composite = D.get_info<info::device::composite_device>(); | ||
Composites.insert(Composite); | ||
} | ||
} | ||
std::vector<device> Result; | ||
std::copy_if( | ||
Composites.begin(), Composites.end(), std::back_inserter(Result), | ||
[&](const device &Composite) { | ||
auto Components = Composite.get_info<info::device::component_devices>(); | ||
// Only return composite devices if all of its component | ||
// devices are available. | ||
return std::all_of( | ||
Components.begin(), Components.end(), [&](const device &d) { | ||
return std::find(Devs.begin(), Devs.end(), d) != Devs.end(); | ||
}); | ||
}); | ||
return Result; | ||
} | ||
} // namespace ext::oneapi::experimental | ||
} // namespace _V1 | ||
} // namespace sycl |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1085,6 +1085,67 @@ struct get_device_info_impl< | |
} | ||
}; | ||
|
||
// Specialization for composite devices extension. | ||
template <> | ||
struct get_device_info_impl< | ||
std::vector<sycl::device>, | ||
ext::oneapi::experimental::info::device::component_devices> { | ||
static std::vector<sycl::device> get(const DeviceImplPtr &Dev) { | ||
if (Dev->getBackend() != backend::ext_oneapi_level_zero) | ||
return {}; | ||
size_t ResultSize = 0; | ||
// First call to get DevCount. | ||
Dev->getPlugin()->call<PiApiKind::piDeviceGetInfo>( | ||
Dev->getHandleRef(), | ||
PiInfoCode< | ||
ext::oneapi::experimental::info::device::component_devices>::value, | ||
0, nullptr, &ResultSize); | ||
size_t DevCount = ResultSize / sizeof(pi_device); | ||
// Second call to get the list. | ||
std::vector<pi_device> Devs(DevCount); | ||
Dev->getPlugin()->call<PiApiKind::piDeviceGetInfo>( | ||
Dev->getHandleRef(), | ||
PiInfoCode< | ||
ext::oneapi::experimental::info::device::component_devices>::value, | ||
ResultSize, Devs.data(), nullptr); | ||
std::vector<sycl::device> Result; | ||
const auto &Platform = Dev->getPlatformImpl(); | ||
for (const auto &d : Devs) | ||
Result.push_back(createSyclObjFromImpl<device>( | ||
Platform->getOrMakeDeviceImpl(d, Platform))); | ||
|
||
return Result; | ||
} | ||
}; | ||
template <> | ||
struct get_device_info_impl< | ||
sycl::device, ext::oneapi::experimental::info::device::composite_device> { | ||
static sycl::device get(const DeviceImplPtr &Dev) { | ||
if (Dev->getBackend() != backend::ext_oneapi_level_zero) | ||
return {}; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why not throwing an exception? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. From the extension specification:
|
||
if (!Dev->has(sycl::aspect::ext_oneapi_is_component)) | ||
throw sycl::exception(make_error_code(errc::invalid), | ||
"Only devices with aspect::ext_oneapi_is_component " | ||
"can call this function."); | ||
|
||
typename sycl_to_pi<device>::type Result; | ||
Dev->getPlugin()->call<PiApiKind::piDeviceGetInfo>( | ||
Dev->getHandleRef(), | ||
PiInfoCode< | ||
ext::oneapi::experimental::info::device::composite_device>::value, | ||
sizeof(Result), &Result, nullptr); | ||
|
||
if (Result) { | ||
const auto &Platform = Dev->getPlatformImpl(); | ||
return createSyclObjFromImpl<device>( | ||
Platform->getOrMakeDeviceImpl(Result, Platform)); | ||
} | ||
throw sycl::exception(make_error_code(errc::invalid), | ||
"A component with aspect::ext_oneapi_is_component " | ||
"must have a composite device."); | ||
} | ||
}; | ||
|
||
template <typename Param> | ||
typename Param::return_type get_device_info(const DeviceImplPtr &Dev) { | ||
static_assert(is_device_info_desc<Param>::value, | ||
|
@@ -2041,6 +2102,20 @@ inline float get_device_info_host< | |
PI_ERROR_INVALID_DEVICE); | ||
} | ||
|
||
template <> | ||
inline std::vector<sycl::device> get_device_info_host< | ||
ext::oneapi::experimental::info::device::component_devices>() { | ||
throw runtime_error("Host devices cannot be component devices.", | ||
PI_ERROR_INVALID_DEVICE); | ||
} | ||
|
||
template <> | ||
inline sycl::device get_device_info_host< | ||
ext::oneapi::experimental::info::device::composite_device>() { | ||
throw runtime_error("Host devices cannot be composite devices.", | ||
PI_ERROR_INVALID_DEVICE); | ||
} | ||
|
||
} // namespace detail | ||
} // namespace _V1 | ||
} // namespace sycl |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From what I tested during development of this patch, I'd say this is not used. It seems that we're now using the equivalent in URT repo.