Skip to content
This repository was archived by the owner on Mar 28, 2023. It is now read-only.

[SYCL] Add test for default initialized local memory #1619

Open
wants to merge 1 commit into
base: intel
Choose a base branch
from
Open
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
34 changes: 31 additions & 3 deletions SYCL/GroupLocalMemory/group_local_memory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,13 @@ struct Foo {
int Values[WgSize];
};

struct Bar {
int Value = 42;
};

class KernelA;
class KernelB;
class KernelC;

using namespace sycl;

Expand All @@ -48,7 +53,7 @@ int main() {
// Foo &Ref = *group_local_memory<Foo>(Item.get_group(), ...);
multi_ptr<Foo, access::address_space::local_space,
sycl::access::decorated::legacy>
Ptr = group_local_memory<Foo>(
Ptr = sycl::ext::oneapi::group_local_memory<Foo>(
Item.get_group(), 1,
CounterAcc[Item.get_group_linear_id()]);
Ptr->Values[Item.get_local_linear_id()] *=
Expand Down Expand Up @@ -82,8 +87,8 @@ int main() {
nd_range<1>(range<1>(Size), range<1>(WgSize)), [=](nd_item<1> Item) {
multi_ptr<int[WgSize], access::address_space::local_space,
sycl::access::decorated::legacy>
Ptr = group_local_memory_for_overwrite<int[WgSize]>(
Item.get_group());
Ptr = sycl::ext::oneapi::group_local_memory_for_overwrite<
int[WgSize]>(Item.get_group());
(*Ptr)[Item.get_local_linear_id()] = Item.get_local_linear_id();

Item.barrier();
Expand All @@ -98,4 +103,27 @@ int main() {
for (size_t I = 0; I < Size; ++I)
assert(Acc[I] == I % WgSize);
}

{
std::vector<int> Vec(Size, 0);
buffer<int, 1> Buf{Vec.data(), range<1>(Size)};

Q.submit([&](handler &Cgh) {
auto Acc = Buf.get_access<access::mode::write>(Cgh);
Cgh.parallel_for<KernelC>(
nd_range<1>(range<1>(Size), range<1>(WgSize)), [=](nd_item<1> Item) {
multi_ptr<Bar, access::address_space::local_space,
sycl::access::decorated::legacy>
Ptr = sycl::ext::oneapi::group_local_memory_for_overwrite<Bar>(
Item.get_group());
// Make sure that the value is default initialized on all items.
Acc[Item.get_global_linear_id()] = Ptr->Value;
});
});

auto Acc = Buf.get_access<access::mode::read>();
Bar RefBar;
for (size_t I = 0; I < Size; ++I)
assert(Acc[I] == RefBar.Value);
}
}