Skip to content

Conversation

@steffenlarsen
Copy link
Contributor

@steffenlarsen steffenlarsen commented Apr 4, 2022

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.

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)

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>
@steffenlarsen steffenlarsen requested a review from gmlueck April 4, 2022 16:22
@steffenlarsen steffenlarsen requested a review from a team as a code owner April 4, 2022 16:22
@steffenlarsen
Copy link
Contributor Author

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

@steffenlarsen
Copy link
Contributor Author

/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 {};
Copy link
Contributor

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.

Copy link
Contributor Author

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.

Comment on lines 70 to 71
// 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
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
// 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

Copy link
Contributor Author

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
Copy link
Contributor

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?

Copy link
Contributor Author

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.

Copy link
Contributor

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.

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 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>
@steffenlarsen steffenlarsen requested a review from a team as a code owner July 8, 2022 12:41
@steffenlarsen
Copy link
Contributor Author

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

Signed-off-by: Larsen, Steffen <steffen.larsen@intel.com>
@steffenlarsen
Copy link
Contributor Author

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

mdtoguchi
mdtoguchi previously approved these changes Jul 8, 2022
Copy link
Contributor

@mdtoguchi mdtoguchi left a 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>
@steffenlarsen
Copy link
Contributor Author

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

Comment on lines 80 to 86
// (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;
};
Copy link
Contributor

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)?

Copy link
Contributor Author

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
Copy link
Contributor

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.

Comment on lines 20 to 21
// Forward declaration.
template <typename T, typename PropertyListT> class device_global;
Copy link
Contributor

Choose a reason for hiding this comment

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

nit:

Suggested change
// 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

Copy link
Contributor Author

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>
@steffenlarsen
Copy link
Contributor Author

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

@steffenlarsen
Copy link
Contributor Author

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

Comment on lines +66 to +76
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.");
};
Copy link
Contributor

@aelovikov-intel aelovikov-intel Jul 25, 2022

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.

Copy link
Contributor Author

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.

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 limit base case to declaration-only instead of definition? If that wouldn't be trivial, I'm fine with the current approach.

Copy link
Contributor Author

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.

Comment on lines +193 to +194
static constexpr const char *name = "";
static constexpr std::nullptr_t value = nullptr;
Copy link
Contributor

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 ?

Copy link
Contributor Author

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.

Comment on lines +66 to +76
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.");
};
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 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>
@steffenlarsen
Copy link
Contributor Author

@mdtoguchi - Could you please re-approve? The driver changes should be the same as when you last approved.

@steffenlarsen
Copy link
Contributor Author

No code change since last verification run. Merging this.

@steffenlarsen steffenlarsen merged commit 6c66f28 into intel:sycl Jul 26, 2022
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