Skip to content

Commit 920a536

Browse files
author
iclsrc
committed
Merge from 'sycl' to 'sycl-web' (3 commits)
2 parents ed5e0b6 + cd93d8f commit 920a536

File tree

13 files changed

+149
-26
lines changed

13 files changed

+149
-26
lines changed

sycl/include/sycl/detail/util.hpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,18 @@ class Sync {
3232
std::mutex GlobalLock;
3333
};
3434

35+
// TempAssignGuard is the class for a guard object that will assign some OTHER
36+
// variable to a temporary value but restore it when the guard itself goes out
37+
// of scope.
38+
template <typename T> struct TempAssignGuard {
39+
T &field;
40+
T restoreValue;
41+
TempAssignGuard(T &fld, T tempVal) : field(fld), restoreValue(fld) {
42+
field = tempVal;
43+
}
44+
~TempAssignGuard() { field = restoreValue; }
45+
};
46+
3547
// const char* key hash for STL maps
3648
struct HashCStr {
3749
size_t operator()(const char *S) const {

sycl/include/sycl/exception_list.hpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
#include <sycl/detail/defines.hpp>
1414
#include <sycl/detail/export.hpp>
15+
#include <sycl/detail/iostream_proxy.hpp>
1516
#include <sycl/stl.hpp>
1617

1718
#include <cstddef>
@@ -52,5 +53,23 @@ class __SYCL_EXPORT exception_list {
5253

5354
using async_handler = std::function<void(sycl::exception_list)>;
5455

56+
namespace detail {
57+
// Default implementation of async_handler used by queue and context when no
58+
// user-defined async_handler is specified.
59+
inline void defaultAsyncHandler(exception_list Exceptions) {
60+
std::cerr << "Default async_handler caught exceptions:";
61+
for (auto &EIt : Exceptions) {
62+
try {
63+
if (EIt) {
64+
std::rethrow_exception(EIt);
65+
}
66+
} catch (const std::exception &E) {
67+
std::cerr << "\n\t" << E.what();
68+
}
69+
}
70+
std::cerr << std::endl;
71+
std::terminate();
72+
}
73+
} // namespace detail
5574
} // __SYCL_INLINE_VER_NAMESPACE(_V1)
5675
} // namespace sycl

sycl/include/sycl/queue.hpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ class __SYCL_EXPORT queue {
9090
///
9191
/// \param PropList is a list of properties for queue construction.
9292
explicit queue(const property_list &PropList = {})
93-
: queue(default_selector(), async_handler{}, PropList) {}
93+
: queue(default_selector(), detail::defaultAsyncHandler, PropList) {}
9494

9595
/// Constructs a SYCL queue instance with an async_handler using the device
9696
/// returned by an instance of default_selector.
@@ -125,8 +125,8 @@ class __SYCL_EXPORT queue {
125125
detail::EnableIfSYCL2020DeviceSelectorInvocable<DeviceSelector>>
126126
explicit queue(const DeviceSelector &deviceSelector,
127127
const property_list &PropList = {})
128-
: queue(detail::select_device(deviceSelector), async_handler{},
129-
PropList) {}
128+
: queue(detail::select_device(deviceSelector),
129+
detail::defaultAsyncHandler, PropList) {}
130130

131131
/// Constructs a SYCL queue instance using the device identified by the
132132
/// device selector provided.
@@ -171,7 +171,8 @@ class __SYCL_EXPORT queue {
171171
"use SYCL 2020 device selectors instead.")
172172
queue(const device_selector &DeviceSelector,
173173
const property_list &PropList = {})
174-
: queue(DeviceSelector.select_device(), async_handler{}, PropList) {}
174+
: queue(DeviceSelector.select_device(), detail::defaultAsyncHandler,
175+
PropList) {}
175176

176177
/// Constructs a SYCL queue instance with an async_handler using the device
177178
/// returned by the DeviceSelector provided.
@@ -190,7 +191,7 @@ class __SYCL_EXPORT queue {
190191
/// \param SyclDevice is an instance of SYCL device.
191192
/// \param PropList is a list of properties for queue construction.
192193
explicit queue(const device &SyclDevice, const property_list &PropList = {})
193-
: queue(SyclDevice, async_handler{}, PropList) {}
194+
: queue(SyclDevice, detail::defaultAsyncHandler, PropList) {}
194195

195196
/// Constructs a SYCL queue instance with an async_handler using the device
196197
/// provided.

sycl/source/backend/level_zero.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,8 @@ __SYCL_EXPORT context make_context(const std::vector<device> &DeviceList,
5757
NativeHandle, DeviceHandles.size(), DeviceHandles.data(), !KeepOwnership,
5858
&PiContext);
5959
// Construct the SYCL context from PI context.
60-
return detail::createSyclObjFromImpl<context>(
61-
std::make_shared<context_impl>(PiContext, async_handler{}, Plugin));
60+
return detail::createSyclObjFromImpl<context>(std::make_shared<context_impl>(
61+
PiContext, detail::defaultAsyncHandler, Plugin));
6262
}
6363

6464
//----------------------------------------------------------------------------

sycl/source/backend/opencl.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@ __SYCL_EXPORT device make_device(pi_native_handle NativeHandle) {
3636
//----------------------------------------------------------------------------
3737
// Implementation of opencl::make<context>
3838
__SYCL_EXPORT context make_context(pi_native_handle NativeHandle) {
39-
return detail::make_context(NativeHandle, async_handler{}, backend::opencl);
39+
return detail::make_context(NativeHandle, detail::defaultAsyncHandler,
40+
backend::opencl);
4041
}
4142

4243
//----------------------------------------------------------------------------

sycl/source/context.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626

2727
namespace sycl {
2828
__SYCL_INLINE_VER_NAMESPACE(_V1) {
29+
2930
context::context(const property_list &PropList)
3031
: context(default_selector().select_device(), PropList) {}
3132

@@ -49,7 +50,7 @@ context::context(const platform &Platform, async_handler AsyncHandler,
4950

5051
context::context(const std::vector<device> &DeviceList,
5152
const property_list &PropList)
52-
: context(DeviceList, async_handler{}, PropList) {}
53+
: context(DeviceList, detail::defaultAsyncHandler, PropList) {}
5354

5455
context::context(const std::vector<device> &DeviceList,
5556
async_handler AsyncHandler, const property_list &PropList) {

sycl/source/detail/device_impl.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,13 @@ device_impl::device_impl(pi_native_handle InteropDeviceHandle,
5353
Plugin.call<PiApiKind::piDeviceGetInfo>(
5454
MDevice, PI_DEVICE_INFO_TYPE, sizeof(RT::PiDeviceType), &MType, nullptr);
5555

56-
// TODO catch an exception and put it to list of asynchronous exceptions
57-
Plugin.call<PiApiKind::piDeviceGetInfo>(MDevice, PI_DEVICE_INFO_PARENT_DEVICE,
58-
sizeof(RT::PiDevice), &MRootDevice,
59-
nullptr);
56+
// No need to set MRootDevice when MAlwaysRootDevice is true
57+
if ((Platform == nullptr) || !Platform->MAlwaysRootDevice) {
58+
// TODO catch an exception and put it to list of asynchronous exceptions
59+
Plugin.call<PiApiKind::piDeviceGetInfo>(
60+
MDevice, PI_DEVICE_INFO_PARENT_DEVICE, sizeof(RT::PiDevice),
61+
&MRootDevice, nullptr);
62+
}
6063

6164
if (!InteroperabilityConstructor) {
6265
// TODO catch an exception and put it to list of asynchronous exceptions

sycl/source/detail/platform_impl.cpp

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include <detail/platform_impl.hpp>
1515
#include <detail/platform_info.hpp>
1616
#include <sycl/detail/iostream_proxy.hpp>
17+
#include <sycl/detail/util.hpp>
1718
#include <sycl/device.hpp>
1819

1920
#include <algorithm>
@@ -253,13 +254,17 @@ static bool supportsPartitionProperty(const device &dev,
253254

254255
static std::vector<device> amendDeviceAndSubDevices(
255256
backend PlatformBackend, std::vector<device> &DeviceList,
256-
ods_target_list *OdsTargetList, int PlatformDeviceIndex) {
257+
ods_target_list *OdsTargetList, int PlatformDeviceIndex,
258+
PlatformImplPtr PlatformImpl) {
257259
constexpr info::partition_property partitionProperty =
258260
info::partition_property::partition_by_affinity_domain;
259261
constexpr info::partition_affinity_domain affinityDomain =
260262
info::partition_affinity_domain::next_partitionable;
261263

262264
std::vector<device> FinalResult;
265+
// (Only) when amending sub-devices for ONEAPI_DEVICE_SELECTOR, all
266+
// sub-devices are treated as root.
267+
TempAssignGuard<bool> TAG(PlatformImpl->MAlwaysRootDevice, true);
263268

264269
for (unsigned i = 0; i < DeviceList.size(); i++) {
265270
// device has already been screened. The question is whether it should be a
@@ -311,9 +316,8 @@ static std::vector<device> amendDeviceAndSubDevices(
311316
// -- Add sub sub device.
312317
if (wantSubSubDevice) {
313318

314-
auto subDevicesToPartition = dev.create_sub_devices<
315-
info::partition_property::partition_by_affinity_domain>(
316-
affinityDomain);
319+
auto subDevicesToPartition =
320+
dev.create_sub_devices<partitionProperty>(affinityDomain);
317321
if (target.SubDeviceNum) {
318322
if (subDevicesToPartition.size() >
319323
target.SubDeviceNum.value()) {
@@ -341,9 +345,9 @@ static std::vector<device> amendDeviceAndSubDevices(
341345
continue;
342346
}
343347
// Allright, lets get them sub-sub-devices.
344-
auto subSubDevices = subDev.create_sub_devices<
345-
info::partition_property::partition_by_affinity_domain>(
346-
affinityDomain);
348+
auto subSubDevices =
349+
subDev.create_sub_devices<partitionProperty>(
350+
affinityDomain);
347351
if (target.HasSubSubDeviceWildCard) {
348352
FinalResult.insert(FinalResult.end(), subSubDevices.begin(),
349353
subSubDevices.end());
@@ -476,7 +480,7 @@ platform_impl::get_devices(info::device_type DeviceType) const {
476480
// Otherwise, our last step is to revisit the devices, possibly replacing
477481
// them with subdevices (which have been ignored until now)
478482
return amendDeviceAndSubDevices(Backend, Res, OdsTargetList,
479-
PlatformDeviceIndex);
483+
PlatformDeviceIndex, PlatformImpl);
480484
}
481485

482486
bool platform_impl::has_extension(const std::string &ExtensionName) const {

sycl/source/detail/platform_impl.hpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,10 @@ class platform_impl {
188188
static std::shared_ptr<platform_impl>
189189
getPlatformFromPiDevice(RT::PiDevice PiDevice, const plugin &Plugin);
190190

191+
// when getting sub-devices for ONEAPI_DEVICE_SELECTOR we may temporarily
192+
// ensure every device is a root one.
193+
bool MAlwaysRootDevice = false;
194+
191195
private:
192196
std::shared_ptr<device_impl> getDeviceImplHelper(RT::PiDevice PiDevice);
193197

sycl/source/detail/queue_impl.hpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -230,10 +230,6 @@ class queue_impl {
230230
try {
231231
return submit_impl(CGF, Self, Self, SecondQueue, Loc, PostProcess);
232232
} catch (...) {
233-
{
234-
std::lock_guard<std::mutex> Lock(MMutex);
235-
MExceptions.PushBack(std::current_exception());
236-
}
237233
return SecondQueue->submit_impl(CGF, SecondQueue, Self, SecondQueue, Loc,
238234
PostProcess);
239235
}

0 commit comments

Comments
 (0)