-
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 12 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
88 changes: 88 additions & 0 deletions
88
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,88 @@ | ||
| // REQUIRES: aspect-ext_oneapi_virtual_mem | ||
|
|
||
| // This test checks whether data can be correctly written to and read from | ||
| // virtual memory. | ||
|
|
||
| // RUN: %{build} -o %t.out | ||
| // RUN: %{run} %t.out | ||
|
|
||
| #include "helpers.hpp" | ||
|
|
||
| int main() { | ||
| sycl::queue Q; | ||
| sycl::context Context = Q.get_context(); | ||
| sycl::device Device = Q.get_device(); | ||
| int Failed = 0; | ||
| constexpr size_t NumberOfElements = 1000; | ||
| size_t BytesRequired = NumberOfElements * sizeof(int); | ||
|
|
||
| size_t UsedGranularity = GetLCMGranularity(Device, Context); | ||
|
|
||
| size_t AlignedByteSize = | ||
| ((BytesRequired + UsedGranularity - 1) / UsedGranularity) * | ||
| UsedGranularity; | ||
|
|
||
| syclext::physical_mem NewPhysicalMem{Device, Context, AlignedByteSize}; | ||
| uintptr_t VirtualMemoryPtr = | ||
| syclext::reserve_virtual_mem(0, AlignedByteSize, Context); | ||
|
|
||
| void *MappedPtr = | ||
| NewPhysicalMem.map(VirtualMemoryPtr, AlignedByteSize, | ||
| syclext::address_access_mode::read_write); | ||
|
|
||
| int *DataPtr = reinterpret_cast<int *>(MappedPtr); | ||
|
|
||
| std::vector<int> ResultHostData(NumberOfElements); | ||
|
|
||
| constexpr int ExpectedValueAfterFill = 1; | ||
|
|
||
| Q.fill(DataPtr, ExpectedValueAfterFill, NumberOfElements).wait_and_throw(); | ||
| { | ||
| sycl::buffer<int> CheckBuffer(ResultHostData); | ||
| Q.submit([&](sycl::handler &Handle) { | ||
| sycl::accessor A(CheckBuffer, Handle, sycl::write_only); | ||
| Handle.parallel_for(NumberOfElements, | ||
| [=](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(NumberOfElements, [=](sycl::id<1> Idx) { | ||
| DataPtr[Idx] = Idx; | ||
| }).wait_and_throw(); | ||
|
|
||
| syclext::set_access_mode(DataPtr, AlignedByteSize, | ||
| 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(NumberOfElements, | ||
| [=](sycl::id<1> Idx) { A[Idx] = DataPtr[Idx]; }); | ||
| }); | ||
| } | ||
|
|
||
| for (size_t i = 0; i < NumberOfElements; 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, AlignedByteSize, Context); | ||
| syclext::free_virtual_mem(VirtualMemoryPtr, AlignedByteSize, Context); | ||
|
|
||
| return Failed; | ||
| } | ||
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,25 @@ | ||
| #pragma once | ||
|
|
||
| #include <sycl/detail/core.hpp> | ||
| #include <sycl/ext/oneapi/virtual_mem/physical_mem.hpp> | ||
| #include <sycl/ext/oneapi/virtual_mem/virtual_mem.hpp> | ||
|
|
||
| namespace syclext = sycl::ext::oneapi::experimental; | ||
|
|
||
| // Find the least common multiple of the context and device granularities. This | ||
| // value can be used for aligning both physical memory allocations and for | ||
| // reserving virtual memory ranges. | ||
| size_t GetLCMGranularity( | ||
| const sycl::device &Dev, const sycl::context &Ctx, | ||
| syclext::granularity_mode Gm = syclext::granularity_mode::recommended) { | ||
| size_t CtxGranularity = syclext::get_mem_granularity(Ctx, Gm); | ||
| size_t DevGranularity = syclext::get_mem_granularity(Dev, Ctx, Gm); | ||
|
|
||
| size_t GCD = CtxGranularity; | ||
| size_t Rem = DevGranularity % GCD; | ||
| while (Rem != 0) { | ||
| std::swap(GCD, Rem); | ||
| Rem %= GCD; | ||
| } | ||
| return (DevGranularity / GCD) * CtxGranularity; | ||
| } |
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
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.