-
Notifications
You must be signed in to change notification settings - Fork 803
[SYCL] Implement device_global headers #5959
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
[SYCL] Implement device_global headers #5959
Conversation
This commit adds the device_global experimental headers. Additionally it also adds the notion of meta-names and meta-values to compile-time properties, allowing properties to define names and values that can be used with __sycl_detail__::add_ir_attributes_* attributes. Signed-off-by: Steffen Larsen <steffen.larsen@intel.com>
|
/verify with intel/llvm-test-suite#971 |
|
/verify with intel/llvm-test-suite#971 |
|
|
||
| // Type-trait for checking if a type defines the -> operator. | ||
| template <typename T, typename = void> | ||
| struct HasDerefOperator : std::false_type {}; |
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.
I think this is misleading - operator* is deref. This one is either MemberAccess or Arrow.
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.
Good point. It has been renamed.
| // Class in the device_global inheritance chain. This class will define the | ||
| // -> operator for the device_global if the underlying type T either has the |
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.
| // Class in the device_global inheritance chain. This class will define the | |
| // -> operator for the device_global if the underlying type T either has the | |
| // Class in the device_global inheritance chain. This class will define the | |
| // 'operator->' for the device_global if the underlying type T either has the |
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.
As per our offline discussion, the chain has been flattened so this comment is no more. I have done similar renaming in other places though.
| @@ -0,0 +1,106 @@ | |||
| // RUN: %clangxx -fsycl -fsycl-targets=%sycl_triple -fsyntax-only -Xclang -verify -Xclang -verify-ignore-unexpected=note,warning %s | |||
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.
What are the warnings we're ignoring here?
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.
None in particular. It is just there to avoid any rogue warnings from giving false negatives.
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.
I'd feel more confident if we didn't do that, but maybe I'm missing something.
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.
I don't mind removing it. So it has been removed.
Signed-off-by: Larsen, Steffen <steffen.larsen@intel.com>
…_variable_decorations extension Signed-off-by: Larsen, Steffen <steffen.larsen@intel.com>
|
/verify with intel/llvm-test-suite#971 |
Signed-off-by: Larsen, Steffen <steffen.larsen@intel.com>
|
/verify with intel/llvm-test-suite#971 |
mdtoguchi
left a comment
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.
OK for driver
Signed-off-by: Larsen, Steffen <steffen.larsen@intel.com>
|
/verify with intel/llvm-test-suite#971 |
| // (7.) | ||
| template <> struct PropertyMetaName<bar_key::value_t> { | ||
| static constexpr const char *value = "sycl-bar"; | ||
| }; | ||
| template <> struct PropertyMetaValue<bar_key::value_t> { | ||
| static constexpr int value = 5; | ||
| }; |
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.
What are these magic values (sycl-bar, 5)?
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.
They are just example values to show how to do it, following the guide further up.
| @@ -0,0 +1,106 @@ | |||
| // RUN: %clangxx -fsycl -fsycl-targets=%sycl_triple -fsyntax-only -Xclang -verify -Xclang -verify-ignore-unexpected=note,warning %s | |||
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.
I'd feel more confident if we didn't do that, but maybe I'm missing something.
| // Forward declaration. | ||
| template <typename T, typename PropertyListT> class device_global; |
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.
nit:
| // Forward declaration. | |
| template <typename T, typename PropertyListT> class device_global; | |
| template <typename T, typename PropertyListT> class device_global; |
C++ syntax is clear about what it is :P
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.
Force of habit! Has been removed.
Signed-off-by: Larsen, Steffen <steffen.larsen@intel.com>
|
/verify with intel/llvm-test-suite#971 |
sycl/test/extensions/device_global/device_global_properties.cpp
Outdated
Show resolved
Hide resolved
|
/verify with intel/llvm-test-suite#971 |
| template <typename T, typename PropertyListT = detail::empty_properties_t> | ||
| class | ||
| #ifdef __SYCL_DEVICE_ONLY__ | ||
| // FIXME: Temporary work-around. Remove when fixed. | ||
| [[__sycl_detail__::global_variable_allowed, __sycl_detail__::device_global]] | ||
| #endif | ||
| device_global { | ||
| // This should always fail when instantiating the unspecialized version. | ||
| static_assert(is_property_list<PropertyListT>::value, | ||
| "Property list is invalid."); | ||
| }; |
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.
I don't think we need extra specialization for this. IMO, just moving the static assert to the class below would work as good. In fact, it's already there on line 101.
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.
This is the base template and the one below is the specialization. We need to do it this way to unpack the properties inside the property list. However, we still run the risk of a user using the base-template here, e.g. as device_global<int, double> which should fail with the "Property list is invalid."
In fact, in all cases where the base template is used, the static_assert will fail, as otherwise it would have gone for the specialization below, but we cannot make it static_assert(false, ...) as it will always fail to compile, so we must make it dependent.
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.
Can we limit base case to declaration-only instead of definition? If that wouldn't be trivial, I'm fine with the current approach.
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.
We could, but I think for the sake of error reporting, having definition with a static assert helps inform the user of what is wrong, for example if they do a device_global<int, double>, they'd be told specifically there's a problem with the property list rather than just being told that there is no definition for the class. From their perspective, the is_property_list<PropertyListT>::value check is still relevant, even though we know that for this definition it won't ever be true.
| static constexpr const char *name = ""; | ||
| static constexpr std::nullptr_t value = nullptr; |
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.
Shouldn't it be empty here to cause compile time errors when used with unknown PropertyT ?
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.
We don't expect all properties to have meta-information, as not all of them will be relevant to the compiler. For example, properties with runtime values are unlikely to have any relevant information at compile-time, so by default they will just be ignored, which is the behavior of having an empty meta-name.
| template <typename T, typename PropertyListT = detail::empty_properties_t> | ||
| class | ||
| #ifdef __SYCL_DEVICE_ONLY__ | ||
| // FIXME: Temporary work-around. Remove when fixed. | ||
| [[__sycl_detail__::global_variable_allowed, __sycl_detail__::device_global]] | ||
| #endif | ||
| device_global { | ||
| // This should always fail when instantiating the unspecialized version. | ||
| static_assert(is_property_list<PropertyListT>::value, | ||
| "Property list is invalid."); | ||
| }; |
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.
Can we limit base case to declaration-only instead of definition? If that wouldn't be trivial, I'm fine with the current approach.
Co-authored-by: aelovikov-intel <andrei.elovikov@intel.com>
|
@mdtoguchi - Could you please re-approve? The driver changes should be the same as when you last approved. |
|
No code change since last verification run. Merging this. |
This commit adds the
device_globalexperimental headers. Additionally it also adds the notion of meta-names and meta-values to compile-time properties, allowing properties to define names and values that can be used with__sycl_detail__::add_ir_attributes_*attributes.This PR also enables device global processing for sycl-post-link, generating decorations for properties and the device global specific decorations.
(See sycl_ext_oneapi_device_global)