-
Notifications
You must be signed in to change notification settings - Fork 796
[SYCL][E2E] Add test for sycl_ext_oneapi_virtual_mem extension
#15807
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
martygrant
merged 16 commits into
intel:sycl
from
dyniols:basic_access_from_kernel_virtual_mem
Nov 4, 2024
Merged
Changes from 4 commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
7247f00
added virtual mem test for basic access from a kernel
dyniols 1297895
fixes
dyniols 0c990f9
fixed formatting
dyniols b1b23cd
formatting fixed
dyniols 34d34e7
Update sycl/test-e2e/VirtualMem/basic_access_from_kernel_virtual_mem.cpp
dyniols a9bf4c3
removed unnecessary includes and added comment explaining test purpose
dyniols 292bbe6
formatting fixed
dyniols f2a7e07
added bytes required and number of elements
dyniols ff09224
fix
dyniols 1fd26ce
fix and added some improvements for future tests
dyniols a09c57f
formatting fixed
dyniols 919a1f6
Merge branch 'sycl' into basic_access_from_kernel_virtual_mem
dyniols b143c43
Update sycl/test-e2e/VirtualMem/vector_with_virtual_mem.cpp
dyniols 7ecefbc
formatting fixed
dyniols 7a97d51
Merge remote-tracking branch 'intel/sycl' into basic_access_from_kern…
dyniols 8b47a4b
common fix because helpers header
dyniols 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
87 changes: 87 additions & 0 deletions
87
sycl/test-e2e/VirtualMem/basic_access_from_kernel_virtual_mem.cpp
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,87 @@ | ||
| // REQUIRES: aspect-ext_oneapi_virtual_mem | ||
|
|
||
| // RUN: %{build} -o %t.out | ||
| // RUN: %{run} %t.out | ||
|
|
||
| #include "sycl/handler.hpp" | ||
dyniols marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| #include <sycl/ext/oneapi/experimental/device_architecture.hpp> | ||
dyniols marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| #include <sycl/ext/oneapi/virtual_mem/physical_mem.hpp> | ||
| #include <sycl/ext/oneapi/virtual_mem/virtual_mem.hpp> | ||
|
|
||
| namespace syclext = sycl::ext::oneapi::experimental; | ||
|
|
||
| int main() { | ||
| sycl::queue Q; | ||
| sycl::context Context = Q.get_context(); | ||
| int Failed = 0; | ||
|
|
||
| size_t UsedGranularityInBytes = syclext::get_mem_granularity( | ||
| Context, syclext::granularity_mode::recommended); | ||
|
|
||
| syclext::physical_mem NewPhysicalMem{Q.get_device(), Context, | ||
| UsedGranularityInBytes}; | ||
dyniols marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| uintptr_t VirtualMemoryPtr = | ||
| syclext::reserve_virtual_mem(0, UsedGranularityInBytes, Context); | ||
|
|
||
| void *MappedPtr = | ||
| NewPhysicalMem.map(VirtualMemoryPtr, UsedGranularityInBytes, | ||
| syclext::address_access_mode::read_write); | ||
|
|
||
| int *DataPtr = reinterpret_cast<int *>(MappedPtr); | ||
|
|
||
| sycl::range NumItems{UsedGranularityInBytes / sizeof(int)}; | ||
|
|
||
| std::vector<int> ResultHostData(NumItems.size()); | ||
|
|
||
| constexpr int ExpectedValueAfterFill = 1; | ||
|
|
||
| Q.fill(DataPtr, ExpectedValueAfterFill, NumItems.size()).wait_and_throw(); | ||
| { | ||
| sycl::buffer<int> CheckBuffer(ResultHostData); | ||
| Q.submit([&](sycl::handler &Handle) { | ||
| sycl::accessor A(CheckBuffer, Handle, sycl::write_only); | ||
| Handle.parallel_for(NumItems, | ||
| [=](sycl::id<1> Idx) { A[Idx] = DataPtr[Idx]; }); | ||
| }); | ||
| } | ||
|
|
||
| for (size_t i = 0; i < ResultHostData.size(); i++) { | ||
| if (ResultHostData[i] != ExpectedValueAfterFill) { | ||
| std::cout << "Comparison failed after fill operation at index " << i | ||
| << ": " << ResultHostData[i] << " != " << ExpectedValueAfterFill | ||
| << std::endl; | ||
| ++Failed; | ||
| } | ||
| } | ||
|
|
||
| Q.parallel_for(NumItems, [=](sycl::id<1> Idx) { | ||
| DataPtr[Idx] = Idx; | ||
| }).wait_and_throw(); | ||
|
|
||
| syclext::set_access_mode(DataPtr, UsedGranularityInBytes, | ||
| syclext::address_access_mode::read, Context); | ||
|
|
||
| { | ||
| sycl::buffer<int> ResultBuffer(ResultHostData); | ||
|
|
||
| Q.submit([&](sycl::handler &Handle) { | ||
| sycl::accessor A(ResultBuffer, Handle, sycl::write_only); | ||
| Handle.parallel_for(NumItems, | ||
| [=](sycl::id<1> Idx) { A[Idx] = DataPtr[Idx]; }); | ||
| }); | ||
| } | ||
|
|
||
| for (size_t i = 0; i < NumItems.size(); i++) { | ||
| const int ExpectedValue = static_cast<int>(i); | ||
| if (ResultHostData[i] != ExpectedValue) { | ||
| std::cout << "Comparison failed at index " << i << ": " | ||
| << ResultHostData[i] << " != " << ExpectedValue << std::endl; | ||
| ++Failed; | ||
| } | ||
| } | ||
|
|
||
| syclext::unmap(MappedPtr, UsedGranularityInBytes, Context); | ||
| syclext::free_virtual_mem(VirtualMemoryPtr, UsedGranularityInBytes, Context); | ||
|
|
||
| return Failed; | ||
| } | ||
Oops, something went wrong.
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.