-
Notifications
You must be signed in to change notification settings - Fork 808
[WIP] [DO NOT MERGE] add std::span support #3509
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
Closed
Closed
Changes from 1 commit
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
556b15d
[SYCL] Uplift SYCL runtime standard to C++17
vladimirlaz c34b3d9
checkpoint - stdlib version issues
cperkinsintel 96418c0
Merge branch 'vlazarev-uplift' into cperkins-std-span-support
cperkinsintel 67ecd43
working. Needs tests and decisions on file mgmt
cperkinsintel 7f79fa4
clean up and comments
cperkinsintel 6a51484
more comment removal
cperkinsintel bd9646f
adding unit tests and changing namespace. Still requires cleanup
cperkinsintel f0dea36
review feedback, and more test changes due to C++17 requirement
cperkinsintel 84e1278
resolved merge conflicts
cperkinsintel 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,104 @@ | ||
| // 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 <numeric> | ||
|
|
||
| using namespace cl::sycl; | ||
|
|
||
|
|
||
| void testSpanCapture() { | ||
| // This test creates spans that are backed by USM. | ||
| // ensures they can be captured by device lambda | ||
| // and that read and write operations function correctly | ||
| // across capture. | ||
| queue Q; | ||
|
|
||
| constexpr long numReadTests = 2; | ||
| const range<1> NumberOfReadTestsRange(numReadTests); | ||
| buffer<int, 1> SpanRead(NumberOfReadTestsRange); | ||
|
|
||
| // span from a vector | ||
| // We will create a vector, backed by a USM allocator. And a span from that. | ||
| typedef usm_allocator<int, usm::alloc::shared> vec_alloc; | ||
| // Create allocator for device associated with q | ||
| vec_alloc myAlloc(Q); | ||
| // Create std vector with the allocator | ||
| std::vector<int, vec_alloc> vecUSM(4, myAlloc); | ||
| std::iota(vecUSM.begin(), vecUSM.end(), 1); | ||
| sycl::span<int> vecUSM_span{vecUSM}; | ||
| vecUSM_span[0] += 100; // 101 modify first value using span affordance. | ||
|
|
||
| // span from USM memory | ||
| int* usm_data = malloc_shared<int>(4, Q); | ||
| sycl::span<int> usm_span(usm_data, 4); | ||
| std::iota(usm_span.begin(), usm_span.end(), 1); | ||
| usm_span[0] += 100; // 101 modify first value using span affordance. | ||
|
|
||
| event E = Q.submit([&](handler &cgh){ | ||
| auto span_read_acc = SpanRead.get_access<access::mode::write>(cgh); | ||
| cgh.single_task<class hi>([=] () { | ||
| // read from the spans. | ||
| span_read_acc[0] = vecUSM_span[0]; | ||
| span_read_acc[1] = usm_span[0]; | ||
|
|
||
| // write to the spans | ||
| vecUSM_span[1] += 1000; | ||
| usm_span[1] += 1000; | ||
| }); | ||
| }); | ||
| E.wait(); | ||
|
|
||
| //check out the read operations, should have gotten 101 from each | ||
| auto span_read_acc = SpanRead.get_access<access::mode::read>(); | ||
| for(int i=0; i < numReadTests; i++){ | ||
| assert(span_read_acc[i] == 101 && "read check should have gotten 100"); | ||
| } | ||
|
|
||
| //were the spans successfully modified via write? | ||
| assert(vecUSM_span[1] == 1002 && "vecUSM_span write check should have gotten 1001"); | ||
| assert(usm_span[1] == 1002 && "usm_span write check should have gotten 1001"); | ||
|
|
||
| } | ||
|
|
||
| void set_all_span_values(sycl::span<int> container, int v){ | ||
| for(auto &e : container) | ||
| e = v; | ||
| } | ||
|
|
||
| void testSpanOnDevice(){ | ||
| // this test creates a simple span on device, | ||
| // passes it to a function that operates on it | ||
| // and ensures it worked correctly | ||
| queue Q; | ||
| constexpr long numReadTests = 4; | ||
| const range<1> NumberOfReadTestsRange(numReadTests); | ||
| buffer<int, 1> SpanRead(NumberOfReadTestsRange); | ||
|
|
||
| event E = Q.submit([&](handler &cgh){ | ||
| auto span_read_acc = SpanRead.get_access<access::mode::write>(cgh); | ||
| cgh.single_task<class ha>([=] () { | ||
| // create a span on device, pass it to function that modifies it | ||
| // read values back out. | ||
| int a[]{1, 2, 3, 4}; | ||
| sycl::span<int> a_span{a}; | ||
| set_all_span_values(a_span, 10); | ||
| for(int i=0; i < numReadTests; i++) | ||
| span_read_acc[i] = a_span[i]; | ||
| }); | ||
| }); | ||
| E.wait(); | ||
|
|
||
| //check out the read operations, should have gotten 10 from each | ||
| auto span_read_acc = SpanRead.get_access<access::mode::read>(); | ||
| for(int i=0; i < numReadTests; i++){ | ||
| assert(span_read_acc[i] == 10 && "read check should have gotten 10"); | ||
| } | ||
| } | ||
|
|
||
| int main(){ | ||
| testSpanCapture(); | ||
| testSpanOnDevice(); | ||
| } | ||
cperkinsintel marked this conversation as resolved.
Show resolved
Hide resolved
|
||
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.
Uh oh!
There was an error while loading. Please reload this page.