Skip to content

[SYCL][Doc] Add indeterminate to work_group_memory #15933

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 1 commit into from
Oct 31, 2024

Conversation

gmlueck
Copy link
Contributor

@gmlueck gmlueck commented Oct 30, 2024

We decided that it was too easy to mistakenly use the default constructor like this, with the expectation that it statically allocates work-group local memory:

void device_code() {
  syclex::work_group_memory<int> mem;
}

To make this error less likely, we add a parameter to the constructor named indeterminate:

void device_code() {
  syclex::work_group_memory<int> mem{syclex::indeterminate};
}

We hope this will make it more apparent that mem is just a dummy object, and it needs to be assigned to some other work_group_memory object before it can be used.

We decided that it was too easy to mistakenly use the default
constructor like this, with the expectation that it statically
allocates work-group local memory:

```
void device_code() {
  syclex::work_group_memory<int> mem;
}
```

To make this error less likely, we add a parameter to the constructor
named `indeterminate`:

```
void device_code() {
  syclex::work_group_memory<int> mem{syclex::indeterminate};
}
```

We hope this will make it more apparent that `mem` is just a dummy
object, and it needs to be assigned to some other `work_group_memory`
object before it can be used.
Copy link
Contributor

@steffenlarsen steffenlarsen left a comment

Choose a reason for hiding this comment

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

LGTM!

Copy link
Contributor

@Pennycook Pennycook left a comment

Choose a reason for hiding this comment

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

This suggestion is out of scope for this PR, but we might want to make some time to look at other extensions and see whether there are any that could benefit from this same approach.

During discussion on #15861 we spotted that accessor already has this same behavior, and I wouldn't be surprised if we found more cases.

@gmlueck
Copy link
Contributor Author

gmlueck commented Oct 31, 2024

@intel/llvm-gatekeepers I think this is ready to merge.

@martygrant martygrant merged commit acf2ca8 into intel:sycl Oct 31, 2024
4 checks passed
@gmlueck gmlueck deleted the gmlueck/indeterminate branch October 31, 2024 12:56
martygrant pushed a commit that referenced this pull request Nov 15, 2024
…16003)

Implement the changes made to the work group memory spec in this PR:
#15933.
Essentially, the default constructor is removed from the spec and
instead a constructor that takes an indeterminate argument is made
available in order to emphasize that any operation on such a work group
memory object is undefined behavior except for assigning to it another
work group memory object. Because the frontend needs special types to
have a default constructor, we make it private instead and when its time
for the frontend to call it, simply override the access specifier
temporarily.
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