Skip to content

[SYCL] Default initialize group_local_memory_for_overwrite #8472

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
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions sycl/include/sycl/ext/oneapi/group_local_memory.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@ std::enable_if_t<
#ifdef __SYCL_DEVICE_ONLY__
__attribute__((opencl_local)) std::uint8_t *AllocatedMem =
__sycl_allocateLocalMemory(sizeof(T), alignof(T));
// If the type is non-trivial we need to default initialize it.
if constexpr (!std::is_trivial_v<T>) {
if (g.get_local_linear_id() == 0)
new (AllocatedMem) T; // Default initialize.
sycl::detail::workGroupBarrier();
}
return reinterpret_cast<__attribute__((opencl_local)) T *>(AllocatedMem);
#else
throw feature_not_supported(
Expand All @@ -46,19 +52,16 @@ std::enable_if_t<
sycl::detail::is_group<Group>::value,
multi_ptr<T, access::address_space::local_space, access::decorated::legacy>>
__SYCL_ALWAYS_INLINE group_local_memory(Group g, Args &&...args) {
(void)g;
#ifdef __SYCL_DEVICE_ONLY__
__attribute__((opencl_local)) std::uint8_t *AllocatedMem =
__sycl_allocateLocalMemory(sizeof(T), alignof(T));

// TODO switch to using group::get_local_linear_id here once it's implemented
id<3> Id = __spirv::initLocalInvocationId<3, id<3>>();
if (Id == id<3>(0, 0, 0))
if (g.get_local_linear_id() == 0)
new (AllocatedMem) T(std::forward<Args>(args)...);
sycl::detail::workGroupBarrier();
return reinterpret_cast<__attribute__((opencl_local)) T *>(AllocatedMem);
#else
// Silence unused variable warning
(void)g;
[&args...] {}();
throw feature_not_supported(
"sycl_ext_oneapi_local_memory extension is not supported on host device",
Expand Down