From 219e69a7f7fa45121fae3ba82025cb903e2986de Mon Sep 17 00:00:00 2001 From: "Skrobot, Daniel" Date: Thu, 31 Oct 2024 16:44:19 +0100 Subject: [PATCH 1/5] added extended virtual mem range test --- .../extending_virtual_memory_range.cpp | 90 +++++++++++++++++++ 1 file changed, 90 insertions(+) create mode 100644 sycl/test-e2e/VirtualMem/extending_virtual_memory_range.cpp diff --git a/sycl/test-e2e/VirtualMem/extending_virtual_memory_range.cpp b/sycl/test-e2e/VirtualMem/extending_virtual_memory_range.cpp new file mode 100644 index 000000000000..c03510880b6e --- /dev/null +++ b/sycl/test-e2e/VirtualMem/extending_virtual_memory_range.cpp @@ -0,0 +1,90 @@ +// This test checks whether memory accesses to contiguous virtual memory ranges are performed correctly + +// RUN: %{build} -o %t.out +// RUN: %{run} %t.out + +#include + +#include "helpers.hpp" + +struct VirtualAddressRange { + VirtualAddressRange(uintptr_t Ptr, size_t Size) : MPtr{Ptr}, MSize{Size} {} + + uintptr_t MPtr; + size_t MSize; +}; + +struct PhysicalMemoryMapping{ + PhysicalMemoryMapping(syclext::physical_mem&& PhysicalMem, void* MappingPtr) : MPhysicalMem(std::move(PhysicalMem)), MMappingPtr(MappingPtr){} + syclext::physical_mem MPhysicalMem; + void* MMappingPtr; +}; + + +int main(){ + int Failed = 0; + sycl::queue Q; + sycl::context Context = Q.get_context(); + sycl::device Device = Q.get_device(); + + constexpr size_t NumberOfVirtualMemoryRanges = 5; + constexpr size_t ElementsInRange = 100; + constexpr int ValueSetInKernel = 999; + + size_t BytesRequiredPerRange = ElementsInRange* sizeof(int); + + size_t UsedGranularity = GetLCMGranularity(Device, Context); + + size_t AlignedByteSizePerRange = GetAlignedByteSize(BytesRequiredPerRange, UsedGranularity); + + std::vector VirtualMemoryRanges; + std::vector PhysicalMemoryMappings; + + for(size_t Index =0; Index ResultHostData(ElementsInRange); + + for (size_t Index =0; Index(PhysicalMemoryMappings[Index].MMappingPtr); + + Q.parallel_for(ElementsInRange, [=](sycl::id<1> Idx) { + DataRangePtr[Idx] = ValueSetInKernel; + }).wait_and_throw(); + + { + sycl::buffer ResultBuffer(ResultHostData); + + Q.submit([&](sycl::handler &Handle) { + sycl::accessor A(ResultBuffer, Handle, sycl::write_only); + Handle.parallel_for(ElementsInRange, + [=](sycl::id<1> Idx) { A[Idx] = DataRangePtr[Idx]; }); + }); + } + + for (size_t i = 0; i < ElementsInRange; i++) { + if (ResultHostData[i] != ValueSetInKernel) { + std::cout << "Comparison failed with virtual range " << Index+1 << " at index " << i<<": " + << ResultHostData[i] << " != " << ValueSetInKernel + << std::endl; + ++Failed; + } + } + } + + for (auto PhysMemMap: PhysicalMemoryMappings){ + syclext::unmap(PhysMemMap.MMappingPtr, PhysMemMap.MPhysicalMem.size(), Context); + } + for (auto VirtualMemRange: VirtualMemoryRanges) { + syclext::free_virtual_mem(VirtualMemRange.MPtr, VirtualMemRange.MSize, Context); + } + + return Failed; +} \ No newline at end of file From 1701aefc45c597e06ab584f03882e26d867646a3 Mon Sep 17 00:00:00 2001 From: "Skrobot, Daniel" Date: Thu, 31 Oct 2024 17:02:11 +0100 Subject: [PATCH 2/5] formatting fixed --- .../extending_virtual_memory_range.cpp | 85 ++++++++++--------- 1 file changed, 46 insertions(+), 39 deletions(-) diff --git a/sycl/test-e2e/VirtualMem/extending_virtual_memory_range.cpp b/sycl/test-e2e/VirtualMem/extending_virtual_memory_range.cpp index c03510880b6e..d4b397b7244d 100644 --- a/sycl/test-e2e/VirtualMem/extending_virtual_memory_range.cpp +++ b/sycl/test-e2e/VirtualMem/extending_virtual_memory_range.cpp @@ -1,4 +1,5 @@ -// This test checks whether memory accesses to contiguous virtual memory ranges are performed correctly +// This test checks whether memory accesses to contiguous virtual memory ranges +// are performed correctly // RUN: %{build} -o %t.out // RUN: %{run} %t.out @@ -8,83 +9,89 @@ #include "helpers.hpp" struct VirtualAddressRange { - VirtualAddressRange(uintptr_t Ptr, size_t Size) : MPtr{Ptr}, MSize{Size} {} + VirtualAddressRange(uintptr_t Ptr, size_t Size) : MPtr{Ptr}, MSize{Size} {} - uintptr_t MPtr; - size_t MSize; + uintptr_t MPtr; + size_t MSize; }; -struct PhysicalMemoryMapping{ - PhysicalMemoryMapping(syclext::physical_mem&& PhysicalMem, void* MappingPtr) : MPhysicalMem(std::move(PhysicalMem)), MMappingPtr(MappingPtr){} - syclext::physical_mem MPhysicalMem; - void* MMappingPtr; +struct PhysicalMemoryMapping { + PhysicalMemoryMapping(syclext::physical_mem &&PhysicalMem, void *MappingPtr) + : MPhysicalMem(std::move(PhysicalMem)), MMappingPtr(MappingPtr) {} + syclext::physical_mem MPhysicalMem; + void *MMappingPtr; }; - -int main(){ +int main() { int Failed = 0; sycl::queue Q; sycl::context Context = Q.get_context(); sycl::device Device = Q.get_device(); - + constexpr size_t NumberOfVirtualMemoryRanges = 5; constexpr size_t ElementsInRange = 100; constexpr int ValueSetInKernel = 999; - size_t BytesRequiredPerRange = ElementsInRange* sizeof(int); - + size_t BytesRequiredPerRange = ElementsInRange * sizeof(int); + size_t UsedGranularity = GetLCMGranularity(Device, Context); - - size_t AlignedByteSizePerRange = GetAlignedByteSize(BytesRequiredPerRange, UsedGranularity); + + size_t AlignedByteSizePerRange = + GetAlignedByteSize(BytesRequiredPerRange, UsedGranularity); std::vector VirtualMemoryRanges; std::vector PhysicalMemoryMappings; - - for(size_t Index =0; Index ResultHostData(ElementsInRange); - for (size_t Index =0; Index(PhysicalMemoryMappings[Index].MMappingPtr); + for (size_t Index = 0; Index < NumberOfVirtualMemoryRanges; ++Index) { + int *DataRangePtr = + reinterpret_cast(PhysicalMemoryMappings[Index].MMappingPtr); Q.parallel_for(ElementsInRange, [=](sycl::id<1> Idx) { - DataRangePtr[Idx] = ValueSetInKernel; - }).wait_and_throw(); + DataRangePtr[Idx] = ValueSetInKernel; + }).wait_and_throw(); { sycl::buffer ResultBuffer(ResultHostData); Q.submit([&](sycl::handler &Handle) { sycl::accessor A(ResultBuffer, Handle, sycl::write_only); - Handle.parallel_for(ElementsInRange, - [=](sycl::id<1> Idx) { A[Idx] = DataRangePtr[Idx]; }); + Handle.parallel_for(ElementsInRange, [=](sycl::id<1> Idx) { + A[Idx] = DataRangePtr[Idx]; + }); }); } - + for (size_t i = 0; i < ElementsInRange; i++) { if (ResultHostData[i] != ValueSetInKernel) { - std::cout << "Comparison failed with virtual range " << Index+1 << " at index " << i<<": " - << ResultHostData[i] << " != " << ValueSetInKernel - << std::endl; - ++Failed; + std::cout << "Comparison failed with virtual range " << Index + 1 + << " at index " << i << ": " << ResultHostData[i] + << " != " << ValueSetInKernel << std::endl; + ++Failed; } - } + } } - for (auto PhysMemMap: PhysicalMemoryMappings){ - syclext::unmap(PhysMemMap.MMappingPtr, PhysMemMap.MPhysicalMem.size(), Context); + for (auto PhysMemMap : PhysicalMemoryMappings) { + syclext::unmap(PhysMemMap.MMappingPtr, PhysMemMap.MPhysicalMem.size(), + Context); } - for (auto VirtualMemRange: VirtualMemoryRanges) { - syclext::free_virtual_mem(VirtualMemRange.MPtr, VirtualMemRange.MSize, Context); + for (auto VirtualMemRange : VirtualMemoryRanges) { + syclext::free_virtual_mem(VirtualMemRange.MPtr, VirtualMemRange.MSize, + Context); } - + return Failed; } \ No newline at end of file From f07813e68cf2a207764edf3e244f0fa26e4678a9 Mon Sep 17 00:00:00 2001 From: "Skrobot, Daniel" Date: Thu, 31 Oct 2024 17:11:29 +0100 Subject: [PATCH 3/5] added newline at the end of file --- sycl/test-e2e/VirtualMem/extending_virtual_memory_range.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sycl/test-e2e/VirtualMem/extending_virtual_memory_range.cpp b/sycl/test-e2e/VirtualMem/extending_virtual_memory_range.cpp index d4b397b7244d..67dec551543f 100644 --- a/sycl/test-e2e/VirtualMem/extending_virtual_memory_range.cpp +++ b/sycl/test-e2e/VirtualMem/extending_virtual_memory_range.cpp @@ -94,4 +94,4 @@ int main() { } return Failed; -} \ No newline at end of file +} From e71c6b5fdc46513a94a4bb7f957d287b831a76af Mon Sep 17 00:00:00 2001 From: "Skrobot, Daniel" Date: Thu, 7 Nov 2024 20:22:32 +0100 Subject: [PATCH 4/5] triggered re-run of pre-commit tests --- sycl/test-e2e/VirtualMem/extending_virtual_memory_range.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/sycl/test-e2e/VirtualMem/extending_virtual_memory_range.cpp b/sycl/test-e2e/VirtualMem/extending_virtual_memory_range.cpp index 67dec551543f..6eb1dd6e2cfb 100644 --- a/sycl/test-e2e/VirtualMem/extending_virtual_memory_range.cpp +++ b/sycl/test-e2e/VirtualMem/extending_virtual_memory_range.cpp @@ -95,3 +95,4 @@ int main() { return Failed; } + From dc2897d49433be3be1f2c16cfd96fc412121dea3 Mon Sep 17 00:00:00 2001 From: "Skrobot, Daniel" Date: Thu, 7 Nov 2024 20:24:21 +0100 Subject: [PATCH 5/5] fix --- sycl/test-e2e/VirtualMem/extending_virtual_memory_range.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/sycl/test-e2e/VirtualMem/extending_virtual_memory_range.cpp b/sycl/test-e2e/VirtualMem/extending_virtual_memory_range.cpp index 6eb1dd6e2cfb..67dec551543f 100644 --- a/sycl/test-e2e/VirtualMem/extending_virtual_memory_range.cpp +++ b/sycl/test-e2e/VirtualMem/extending_virtual_memory_range.cpp @@ -95,4 +95,3 @@ int main() { return Failed; } -