Skip to content

[SYCL] Cache 'assert supported' flag for device #4505

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

Merged
merged 6 commits into from
Sep 10, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions sycl/include/CL/sycl/queue.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,10 @@ class __SYCL_EXPORT queue {
template <info::queue param>
typename info::param_traits<info::queue, param>::return_type get_info() const;

// A shorthand for `get_device().has()' which is expected to be a bit quicker
// than the long version
bool device_has(aspect Aspect) const;

public:
/// Submits a command group function object to the queue, in order to be
/// scheduled for execution on the device.
Expand All @@ -247,7 +251,7 @@ class __SYCL_EXPORT queue {
if (!is_host()) {
auto PostProcess = [this, &CodeLoc](bool IsKernel, bool KernelUsesAssert,
event &E) {
if (IsKernel && !get_device().has(aspect::ext_oneapi_native_assert) &&
if (IsKernel && !device_has(aspect::ext_oneapi_native_assert) &&
KernelUsesAssert) {
// __devicelib_assert_fail isn't supported by Device-side Runtime
// Linking against fallback impl of __devicelib_assert_fail is
Expand Down Expand Up @@ -287,7 +291,7 @@ class __SYCL_EXPORT queue {
#if __SYCL_USE_FALLBACK_ASSERT
auto PostProcess = [this, &SecondaryQueue, &CodeLoc](
bool IsKernel, bool KernelUsesAssert, event &E) {
if (IsKernel && !get_device().has(aspect::ext_oneapi_native_assert) &&
if (IsKernel && !device_has(aspect::ext_oneapi_native_assert) &&
KernelUsesAssert) {
// __devicelib_assert_fail isn't supported by Device-side Runtime
// Linking against fallback impl of __devicelib_assert_fail is performed
Expand Down
13 changes: 7 additions & 6 deletions sycl/source/detail/device_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ namespace sycl {
namespace detail {

device_impl::device_impl()
: MIsHostDevice(true), MPlatform(platform_impl::getHostPlatformImpl()) {}
: MIsHostDevice(true), MPlatform(platform_impl::getHostPlatformImpl()),
// assert is natively supported by host
MIsAssertFailSupported(true) {}

device_impl::device_impl(pi_native_handle InteropDeviceHandle,
const plugin &Plugin)
Expand Down Expand Up @@ -70,6 +72,9 @@ device_impl::device_impl(pi_native_handle InteropDeviceHandle,
Platform = platform_impl::getPlatformFromPiDevice(MDevice, Plugin);
}
MPlatform = Platform;

MIsAssertFailSupported =
has_extension(PI_DEVICE_INFO_EXTENSION_DEVICELIB_ASSERT);
}

device_impl::~device_impl() {
Expand Down Expand Up @@ -334,11 +339,7 @@ std::shared_ptr<device_impl> device_impl::getHostDeviceImpl() {
}

bool device_impl::isAssertFailSupported() const {
// assert is sort of natively supported by host
if (MIsHostDevice)
return true;

return has_extension(PI_DEVICE_INFO_EXTENSION_DEVICELIB_ASSERT);
return MIsAssertFailSupported;
}

} // namespace detail
Expand Down
1 change: 1 addition & 0 deletions sycl/source/detail/device_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,7 @@ class device_impl {
bool MIsRootDevice = false;
bool MIsHostDevice;
PlatformImplPtr MPlatform;
bool MIsAssertFailSupported = false;
}; // class device_impl

} // namespace detail
Expand Down
2 changes: 1 addition & 1 deletion sycl/source/detail/device_info.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ template <info::device param> struct get_device_info<platform, param> {
// for string return type in other specializations.
template <info::device param> struct get_device_info_string {
static std::string get(RT::PiDevice dev, const plugin &Plugin) {
size_t resultSize;
size_t resultSize = 0;
Plugin.call<PiApiKind::piDeviceGetInfo>(
dev, pi::cast<RT::PiDeviceInfo>(param), 0, nullptr, &resultSize);
if (resultSize == 0) {
Expand Down
5 changes: 5 additions & 0 deletions sycl/source/queue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -191,5 +191,10 @@ pi_native_handle queue::getNative() const { return impl->getNative(); }
buffer<detail::AssertHappened, 1> &queue::getAssertHappenedBuffer() {
return impl->getAssertHappenedBuffer();
}

bool queue::device_has(aspect Aspect) const {
// avoid creating sycl object from impl
return impl->getDeviceImplPtr()->has(Aspect);
}
} // namespace sycl
} // __SYCL_INLINE_NAMESPACE(cl)
1 change: 1 addition & 0 deletions sycl/test/abi/sycl_symbols_linux.dump
Original file line number Diff line number Diff line change
Expand Up @@ -3656,6 +3656,7 @@ _ZN2cl4sycl5eventC1Ev
_ZN2cl4sycl5eventC2EP9_cl_eventRKNS0_7contextE
_ZN2cl4sycl5eventC2ESt10shared_ptrINS0_6detail10event_implEE
_ZN2cl4sycl5eventC2Ev
_ZNK2cl4sycl5queue10device_hasENS0_6aspectE
_ZN2cl4sycl5queue10mem_adviseEPKvm14_pi_mem_advice
_ZN2cl4sycl5queue10mem_adviseEPKvmi
_ZN2cl4sycl5queue10mem_adviseEPKvmiNS0_5eventE
Expand Down
1 change: 1 addition & 0 deletions sycl/test/abi/sycl_symbols_windows.dump
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@
??$get_info@$0BAIA@@context@sycl@cl@@QEBAIXZ
??$get_info@$0BAIB@@context@sycl@cl@@QEBA?AV?$vector@Vdevice@sycl@cl@@V?$allocator@Vdevice@sycl@cl@@@std@@@std@@XZ
??$get_info@$0BAIE@@context@sycl@cl@@QEBA?AVplatform@12@XZ
?device_has@queue@sycl@cl@@QEBA_NW4aspect@23@@Z
??$get_info@$0BAJA@@queue@sycl@cl@@QEBA?AVcontext@12@XZ
??$get_info@$0BAJB@@queue@sycl@cl@@QEBA?AVdevice@12@XZ
??$get_info@$0BAJC@@queue@sycl@cl@@QEBAIXZ
Expand Down