Skip to content

[SYCL] Small patch on annotated USM allocation #11801

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 2 commits into from
Nov 16, 2023

Conversation

wangdi4
Copy link
Contributor

@wangdi4 wangdi4 commented Nov 7, 2023

This PR is a small change on the implementation of aligned_alloc_annotated<T>, which is a variant of the SYCL annotated USM allocation:
https://github.com/intel/llvm/blob/sycl/sycl/doc/extensions/proposed/sycl_ext_oneapi_usm_malloc_properties.asciidoc

Right now aligned_alloc_annotated<T> is implemented by calling sycl::aligned_alloc (allocation in bytes) with a specified alignment (which is a combination (i.e. least common multiple) of the compile-time alignment<K> property and the runtime argument), and then cast the returned pointer type from void * to T*

This does not cover the case where T has a extended alignment as follows

struct alignas(256) MyStruct {
  int x;
};

in this case, both the combined alignment and alignof(T) should be considered, and the greater value of the two should be the final alignment passed to the SYCL runtime. Therefore, this PR changes the impl by directly calling the SYCL core usm API: aligned_alloc<T>.

Some e2e tests are updated with this header change: when alignof(T) is large enough, the aligned_alloc_annotated<T> is no longer expected to return null when the specified alignment is not a power of 2, because alignof(T) (always a power of 2) is the final alignment passed to the SYCL runtime. Therefore, we bump up the specified alignments in these cases to make sure they are always larger the alignof(T)

@wangdi4 wangdi4 requested a review from a team as a code owner November 7, 2023 12:46
@wangdi4 wangdi4 requested a review from dm-vodopyanov November 7, 2023 12:46
@dm-vodopyanov
Copy link
Contributor

@wangdi4 SYCL :: Annotated_usm/annotated_usm_align.cpp test failed in pre-commit.

@againull againull self-requested a review November 9, 2023 18:19
Copy link
Contributor

@againull againull left a comment

Choose a reason for hiding this comment

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

Please address CI failure.

@wangdi4
Copy link
Contributor Author

wangdi4 commented Nov 14, 2023

The e2e test of the annotated USM API has been updated to fix the CI failure

@wangdi4
Copy link
Contributor Author

wangdi4 commented Nov 14, 2023

Hi @dm-vodopyanov @againull, the PR is updated.

@againull againull merged commit 6666762 into intel:sycl Nov 16, 2023
wangdi4 added a commit to wangdi4/llvm that referenced this pull request Dec 13, 2023
This PR is a small change on the implementation of
`aligned_alloc_annotated<T>`, which is a variant of the SYCL annotated
USM allocation:

https://github.com/intel/llvm/blob/sycl/sycl/doc/extensions/proposed/sycl_ext_oneapi_usm_malloc_properties.asciidoc

Right now `aligned_alloc_annotated<T>` is implemented by calling
`sycl::aligned_alloc` (allocation in bytes) with a specified alignment
(which is a combination (i.e. least common multiple) of the compile-time
`alignment<K>` property and the runtime argument), and then cast the
returned pointer type from `void *` to `T*`

This does not cover the case where T has a extended alignment as follows
```
struct alignas(256) MyStruct {
  int x;
};
```
in this case, both the combined alignment and `alignof(T)` should be
considered, and the greater value of the two should be the final
alignment passed to the SYCL runtime. Therefore, this PR changes the
impl by directly calling the SYCL core usm API: `aligned_alloc<T>`.

Some e2e tests are updated with this header change: when `alignof(T)` is
large enough, the `aligned_alloc_annotated<T>` is no longer expected to
return null when the specified alignment is not a power of 2, because
`alignof(T)` (always a power of 2) is the final alignment passed to the
SYCL runtime. Therefore, we bump up the specified alignments in these
cases to make sure they are always larger the `alignof(T)`
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