This repository was archived by the owner on Mar 28, 2023. It is now read-only.
forked from llvm/llvm-test-suite
-
Notifications
You must be signed in to change notification settings - Fork 130
Add a test for SYCL_INTEL_local_memory extension #176
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
81208dd
Add a test for SYCL_INTEL_local_memory extension
sergey-semenov 38d5ea6
Add a comment on alternative ways of using the returned pointer
sergey-semenov c3619d4
Add a code owner for the new test dir
sergey-semenov 5b41d02
Merge branch 'intel' into localmemory
sergey-semenov File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
// RUN: %clangxx -fsycl -fsycl-targets=%sycl_triple %s -o %t.out | ||
// RUN: %CPU_RUN_PLACEHOLDER %t.out | ||
// RUN: %GPU_RUN_PLACEHOLDER %t.out | ||
// RUN: %ACC_RUN_PLACEHOLDER %t.out | ||
|
||
#include <CL/sycl.hpp> | ||
|
||
#include <cassert> | ||
#include <vector> | ||
|
||
constexpr size_t WgSize = 32; | ||
constexpr size_t WgCount = 4; | ||
constexpr size_t Size = WgSize * WgCount; | ||
|
||
struct Foo { | ||
Foo() = delete; | ||
Foo(int Value, int &Counter) { | ||
for (int I = 0; I < WgSize; ++I) | ||
Values[I] = Value; | ||
++Counter; | ||
} | ||
int Values[WgSize]; | ||
}; | ||
|
||
class KernelA; | ||
class KernelB; | ||
|
||
using namespace sycl; | ||
|
||
int main() { | ||
queue Q; | ||
{ | ||
std::vector<int> Vec(Size, 0); | ||
buffer<int, 1> Buf{Vec.data(), range<1>(Size)}; | ||
std::vector<int> CounterVec(WgCount, 0); | ||
buffer<int, 1> CounterBuf{CounterVec.data(), range<1>(WgCount)}; | ||
|
||
Q.submit([&](handler &Cgh) { | ||
auto Acc = Buf.get_access<access::mode::read_write>(Cgh); | ||
auto CounterAcc = CounterBuf.get_access<access::mode::read_write>(Cgh); | ||
Cgh.parallel_for<KernelA>( | ||
nd_range<1>(range<1>(Size), range<1>(WgSize)), [=](nd_item<1> Item) { | ||
// Some alternative (and functionally equivalent) ways to use this | ||
// would be: | ||
// auto Ptr = group_local_memory<Foo>(Item.get_group(), ...); | ||
// Foo &Ref = *group_local_memory<Foo>(Item.get_group(), ...); | ||
multi_ptr<Foo, access::address_space::local_space> Ptr = | ||
group_local_memory<Foo>(Item.get_group(), 1, | ||
CounterAcc[Item.get_group_linear_id()]); | ||
Ptr->Values[Item.get_local_linear_id()] *= | ||
Item.get_local_linear_id(); | ||
|
||
Item.barrier(); | ||
// Check that the memory is accessible from other work-items | ||
size_t LocalIdx = Item.get_local_linear_id() ^ 1; | ||
size_t GlobalIdx = Item.get_global_linear_id() ^ 1; | ||
Acc[GlobalIdx] = Ptr->Values[LocalIdx]; | ||
}); | ||
}); | ||
|
||
auto Acc = Buf.get_access<access::mode::read>(); | ||
for (size_t I = 0; I < Size; ++I) | ||
assert(Acc[I] == I % WgSize); | ||
|
||
// Check that the constructor has been called once per work-group | ||
auto CounterAcc = CounterBuf.get_access<access::mode::read>(); | ||
for (size_t I = 0; I < WgCount; ++I) | ||
assert(CounterAcc[I] == 1); | ||
} | ||
|
||
{ | ||
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::read_write>(Cgh); | ||
Cgh.parallel_for<KernelB>( | ||
nd_range<1>(range<1>(Size), range<1>(WgSize)), [=](nd_item<1> Item) { | ||
multi_ptr<int[WgSize], access::address_space::local_space> Ptr = | ||
group_local_memory_for_overwrite<int[WgSize]>(Item.get_group()); | ||
(*Ptr)[Item.get_local_linear_id()] = Item.get_local_linear_id(); | ||
|
||
Item.barrier(); | ||
// Check that the memory is accessible from other work-items | ||
size_t LocalIdx = Item.get_local_linear_id() ^ 1; | ||
size_t GlobalIdx = Item.get_global_linear_id() ^ 1; | ||
Acc[GlobalIdx] = (*Ptr)[LocalIdx]; | ||
}); | ||
}); | ||
|
||
auto Acc = Buf.get_access<access::mode::read>(); | ||
for (size_t I = 0; I < Size; ++I) | ||
assert(Acc[I] == I % WgSize); | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
New directory is added. Could you please set correct code owner (in .github/CODEOWNERS)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added myself as the code owner. @Pennycook Do you mind being set as the second code owner for the group local memory tests? (I this can be done as a separate PR, so that it does not block merging this one).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fine by me.