Skip to content

[SYCL] Throw an exception for unsupported aspect #6989

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
Oct 11, 2022

Conversation

KornevNikita
Copy link
Contributor

The runtime must throw an exception whenever the application attempts to submit
a kernel to a device where the kernel uses a feature that is not compatible
with the device.
Co-authored-by: @AlexeySachkov

The runtime must throw an exception whenever the application attempts to submit
a kernel to a device where the kernel uses a feature that is not compatible
with the device.
@KornevNikita
Copy link
Contributor Author

/verify with intel/llvm-test-suite#1314

__SYCL_ASPECT(usm_shared_allocations, 15, "usm_shared_allocations")
__SYCL_ASPECT(usm_restricted_shared_allocations, 16, "usm_restricted_shared_allocations")
__SYCL_ASPECT(usm_system_allocations, 17, "usm_system_allocations")
__SYCL_SPECIAL_ASPECT(usm_system_allocator __SYCL2020_DEPRECATED("use usm_system_allocations instead"), usm_system_allocations, "usm_system_allocations")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we have or a more precise definition of "special"? Also, I'd probably move deprecation message into a separate macro argument and call it

__SYCL_ASPECT_DEPRECATED(ASPECT, ID, MESSAGE)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. Added the comment to describe this macro, does it look better now?
  2. Added __SYCL_ASPECT_DEPRECATED macro & outlined these aspects into the separate file. 410f00e

#define __SYCL_ASPECT(A, B, C) \
case aspect::A: \
return C;
#define __SYCL_SPECIAL_ASPECT(A, B, C)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why the deprecated alias isn't allowed here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not allowed because it's "special", not deprecated. Since this only aspect doesn't have own token it will duplicate existing case and lead to compile fail.

continue;
ByteArray Aspects = DeviceBinaryProperty(*It).asByteArray();
// 8 because we need to skip 64-bits of size of the byte array
auto *AIt = reinterpret_cast<const std::uint32_t *>(&Aspects[8]);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why isn't this illegal type-punning?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see the same case in https://github.com/intel/llvm/blob/sycl/sycl/source/detail/program_manager/program_manager.cpp#L1241. Don't really get what you mean, could you please explain?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can do this because originally these aspects were uint32_t. Maybe @steffenlarsen can add some clarity?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In that case, I don't like how the interface is defined (i.e. we shouldn't be doing this magic here), but that would be outside this PR's scope.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have an old patch trying to amend the UB: #5537. It is a little stale now though.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have updated #5537 and added changes for this.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've uploaded an alternative approach in #7023.

@KornevNikita
Copy link
Contributor Author

/verify with intel/llvm-test-suite#1314

Comment on lines 578 to 580
auto KName = std::string_view((*It)->Name);
if (KName != "aspects")
continue;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Not used to the std::string_view best practices yet, but I'd try to write like this:

Suggested change
auto KName = std::string_view((*It)->Name);
if (KName != "aspects")
continue;
if (It->Name != "aspects"sv)
continue;

I'm also not quite sure about It->Name vs (*It)->Name, but I vaguely recall operator-> behavior would enable that. Might be wrong though.

Comment on lines +1 to +4
__SYCL_ASPECT_DEPRECATED(int64_base_atomics, 7, "use atomic64 instead")
__SYCL_ASPECT_DEPRECATED(int64_extended_atomics, 8, "use atomic64 instead")
// Special macro for aspects that don't have own token
__SYCL_ASPECT_DEPRECATED_ALIAS(usm_system_allocator, usm_system_allocations, "use usm_system_allocations instead")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: I'd personally avoid having two files, but I don't have strong argumentation.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@steffenlarsen , I'm not sure if you're "thumbing up" my "I'd avoid" or "don't have strong argumentation".

I'm approving the PR to unblock @KornevNikita but if you'd prefer to have a single file as well we can ask him to address that :) Both pre-/post-commit would work for me.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Both, really. Having a single file would be a little nicer, but I don't think it's worth sweating over. 😄

#undef __SYCL_ASPECT_DEPRECATED
#undef __SYCL_ASPECT

for (RTDeviceBinaryImage::PropertyRange::ConstIterator It : ARange) {
auto KName = std::string_view((*It)->Name);
if (KName != "aspects")
if (KName != std::string_view("aspects"))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: If done like this, this change is unnecessary.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't compile with "aspects"sv

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What I mean is that my original suggestion was to eliminate named KName by using string_view on the string literal. If you keep string_view on the LHS, there is no need to transform the string literal.

Copy link
Contributor Author

@KornevNikita KornevNikita Oct 10, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But, since (*It)->Name is char*, can't we just drop KName like:
(*It)->Name != "aspects"?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That wouldn't be the same.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, 51d9eab

@pvchupin pvchupin merged commit b1619f7 into intel:sycl Oct 11, 2022
@pvchupin
Copy link
Contributor

@KornevNikita, please follow up on post-commit issues https://github.com/intel/llvm/actions/runs/3223149961

@KornevNikita KornevNikita deleted the exception-unsupported-feature branch October 14, 2022 09:15
AlexeySachkov pushed a commit to intel/llvm-test-suite that referenced this pull request Nov 21, 2022
aelovikov-intel pushed a commit to aelovikov-intel/llvm that referenced this pull request Mar 27, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants