Skip to content
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] Update validation of annotated_arg/annotated_ptr parameterization #10437

Open
wants to merge 1 commit into
base: sycl
Choose a base branch
from

Conversation

wangdi4
Copy link
Contributor

@wangdi4 wangdi4 commented Jul 17, 2023

Update the validation of annotated_arg/annotated_pointer type parameterization as follows. Given a parameterized annotated_arg<T, PropertyList> or annotated_arg<T, PropertyList>, validate the type from two aspects:

  1. For a given T, pointer-specific properties are not allowed if T is not pointer. E.g., buffer_location<N> is not applicable for non pointers.
  2. For annotated_arg/annotated_ptr, each of them has its specific properties. E.g. alignment<N> is only supported for anntoated_ptr, while restrict is only supported for annotated_arg. Therefore this PR each property in PropertyList must be supported for annotated_arg (or anntoated_ptr)

@wangdi4 wangdi4 requested a review from a team as a code owner July 17, 2023 21:24
@wangdi4 wangdi4 requested a review from steffenlarsen July 17, 2023 21:24
@@ -76,6 +76,9 @@ __SYCL_TYPE(annotated_arg) annotated_arg<T *, detail::properties_t<Props...>> {
public:
static_assert(is_property_list<property_list_t>::value,
"Property list is invalid.");
static_assert(
validate_annotated_type<annotated_arg<T *, property_list_t>>::value,
"The property list contains invalid property.");
Copy link
Contributor

Choose a reason for hiding this comment

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

I hope in a future update we can make this better? Which property is invalid? Why is it invalid? Not gating on 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 see better errors are bellow.

Copy link
Contributor

@tiwaria1 tiwaria1 left a comment

Choose a reason for hiding this comment

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

Make sure to add some test files.

@wangdi4 wangdi4 temporarily deployed to aws July 17, 2023 21:54 — with GitHub Actions Inactive
@wangdi4 wangdi4 temporarily deployed to aws July 17, 2023 22:33 — with GitHub Actions Inactive
Comment on lines +352 to +364
struct validate_annotated_type<
annotated_arg<T, detail::properties_t<Prop, Props...>>>
: std::conditional_t<is_valid_property<T, Prop>::value &&
is_property_value_of_annotated_arg<Prop>::value,
validate_annotated_type<
annotated_arg<T, detail::properties_t<Props...>>>,
std::false_type> {
static_assert(
is_valid_property<T, Prop>::value,
"Property is invalid for the underlying type of annotated_arg.");
static_assert(is_property_value_of_annotated_arg<Prop>::value,
"Property is not supported for annotated_arg.");
};
Copy link
Contributor

Choose a reason for hiding this comment

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

Due to the static_assert inside the body, it seems unnecessary to check them in the conditional too. It would make sense if std::conditional didn't evaluate both branches, but it does. However, I believe you can prevent further checks if you move the recursive use of validate_annotated_type to after the static_assert.

That is, I would prefer one of:

Suggested change
struct validate_annotated_type<
annotated_arg<T, detail::properties_t<Prop, Props...>>>
: std::conditional_t<is_valid_property<T, Prop>::value &&
is_property_value_of_annotated_arg<Prop>::value,
validate_annotated_type<
annotated_arg<T, detail::properties_t<Props...>>>,
std::false_type> {
static_assert(
is_valid_property<T, Prop>::value,
"Property is invalid for the underlying type of annotated_arg.");
static_assert(is_property_value_of_annotated_arg<Prop>::value,
"Property is not supported for annotated_arg.");
};
struct validate_annotated_type<
annotated_arg<T, detail::properties_t<Prop, Props...>>>
: validate_annotated_type<annotated_arg<T, detail::properties_t<Props...>>> {
static_assert(
is_valid_property<T, Prop>::value,
"Property is invalid for the underlying type of annotated_arg.");
static_assert(is_property_value_of_annotated_arg<Prop>::value,
"Property is not supported for annotated_arg.");
};

or

Suggested change
struct validate_annotated_type<
annotated_arg<T, detail::properties_t<Prop, Props...>>>
: std::conditional_t<is_valid_property<T, Prop>::value &&
is_property_value_of_annotated_arg<Prop>::value,
validate_annotated_type<
annotated_arg<T, detail::properties_t<Props...>>>,
std::false_type> {
static_assert(
is_valid_property<T, Prop>::value,
"Property is invalid for the underlying type of annotated_arg.");
static_assert(is_property_value_of_annotated_arg<Prop>::value,
"Property is not supported for annotated_arg.");
};
struct validate_annotated_type<
annotated_arg<T, detail::properties_t<Prop, Props...>>> {
static_assert(
is_valid_property<T, Prop>::value,
"Property is invalid for the underlying type of annotated_arg.");
static_assert(is_property_value_of_annotated_arg<Prop>::value,
"Property is not supported for annotated_arg.");
static constexpr bool value = validate_annotated_type<annotated_arg<T, detail::properties_t<Props...>>>::value;
};

where (to my knowledge) the latter would stop at the first invalid property.

Comment on lines 347 to +349
template <typename T, typename... Props>
struct check_property_list : std::true_type {};
struct validate_annotated_type<annotated_arg<T, detail::properties_t<Props...>>>
: std::true_type {};
Copy link
Contributor

@steffenlarsen steffenlarsen Jul 20, 2023

Choose a reason for hiding this comment

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

Isn't the detail::properties_t<> the only case that hits this? If so, we might as well make that clear in the definition:

template <typename T>
struct validate_annotated_type<annotated_arg<T, detail::properties_t<>>>
    : std::true_type {};

Copy link
Contributor

github-actions bot commented Feb 1, 2024

This pull request is stale because it has been open 180 days with no activity. Remove stale label or comment or this will be automatically closed in 30 days.

@github-actions github-actions bot added the Stale label Feb 1, 2024
@tiwaria1
Copy link
Contributor

tiwaria1 commented Feb 2, 2024

Hey @wangdi4 , I think we implemented this later in some other PR, please verify and close this one.

@github-actions github-actions bot removed the Stale label Sep 15, 2024
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.

3 participants