Skip to content

Commit

Permalink
[SYCL] Use aggregate initialization for group_local_memory arrays (i…
Browse files Browse the repository at this point in the history
…ntel#10367)

Signed-off-by: Michael Aziz <michael.aziz@intel.com>
  • Loading branch information
0x12CC authored Jul 18, 2023
1 parent aaa2e13 commit b50440e
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
2 changes: 1 addition & 1 deletion sycl/include/sycl/ext/oneapi/group_local_memory.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ std::enable_if_t<
__attribute__((opencl_local)) std::uint8_t *AllocatedMem =
__sycl_allocateLocalMemory(sizeof(T), alignof(T));
if (g.get_local_linear_id() == 0)
new (AllocatedMem) T(std::forward<Args>(args)...);
new (AllocatedMem) T{std::forward<Args>(args)...};
sycl::detail::workGroupBarrier();
return reinterpret_cast<__attribute__((opencl_local)) T *>(AllocatedMem);
#else
Expand Down
23 changes: 23 additions & 0 deletions sycl/test-e2e/Basic/group_local_memory.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// RUN: %{build} -o %t.out
// RUN: %{run} %t.out

#include <CL/sycl.hpp>

constexpr int N = 5;

int main() {
sycl::queue q;
int *ptr = sycl::malloc_shared<int>(N, q);
q.parallel_for(sycl::nd_range<1>{1, 1}, [=](sycl::nd_item<1> it) {
auto g = it.get_group();
auto mem = sycl::ext::oneapi::group_local_memory<int[N]>(g, 1, 2, 3, 4, 5);
auto ref = *mem;
for (int i = 0; i < N; ++i) {
ptr[i] = ref[i];
}
}).wait();
for (int i = 0; i < N; ++i) {
assert(ptr[i] == (i + 1));
}
sycl::free(ptr, q);
}

0 comments on commit b50440e

Please sign in to comment.