1- // This test checks whether memory accesses to contiguous virtual memory ranges are performed correctly
1+ // This test checks whether memory accesses to contiguous virtual memory ranges
2+ // are performed correctly
23
34// RUN: %{build} -o %t.out
45// RUN: %{run} %t.out
89#include " helpers.hpp"
910
1011struct VirtualAddressRange {
11- VirtualAddressRange (uintptr_t Ptr, size_t Size) : MPtr{Ptr}, MSize{Size} {}
12+ VirtualAddressRange (uintptr_t Ptr, size_t Size) : MPtr{Ptr}, MSize{Size} {}
1213
13- uintptr_t MPtr;
14- size_t MSize;
14+ uintptr_t MPtr;
15+ size_t MSize;
1516};
1617
17- struct PhysicalMemoryMapping {
18- PhysicalMemoryMapping (syclext::physical_mem&& PhysicalMem, void * MappingPtr) : MPhysicalMem(std::move(PhysicalMem)), MMappingPtr(MappingPtr){}
19- syclext::physical_mem MPhysicalMem;
20- void * MMappingPtr;
18+ struct PhysicalMemoryMapping {
19+ PhysicalMemoryMapping (syclext::physical_mem &&PhysicalMem, void *MappingPtr)
20+ : MPhysicalMem(std::move(PhysicalMem)), MMappingPtr(MappingPtr) {}
21+ syclext::physical_mem MPhysicalMem;
22+ void *MMappingPtr;
2123};
2224
23-
24- int main (){
25+ int main () {
2526 int Failed = 0 ;
2627 sycl::queue Q;
2728 sycl::context Context = Q.get_context ();
2829 sycl::device Device = Q.get_device ();
29-
30+
3031 constexpr size_t NumberOfVirtualMemoryRanges = 5 ;
3132 constexpr size_t ElementsInRange = 100 ;
3233 constexpr int ValueSetInKernel = 999 ;
3334
34- size_t BytesRequiredPerRange = ElementsInRange* sizeof (int );
35-
35+ size_t BytesRequiredPerRange = ElementsInRange * sizeof (int );
36+
3637 size_t UsedGranularity = GetLCMGranularity (Device, Context);
37-
38- size_t AlignedByteSizePerRange = GetAlignedByteSize (BytesRequiredPerRange, UsedGranularity);
38+
39+ size_t AlignedByteSizePerRange =
40+ GetAlignedByteSize (BytesRequiredPerRange, UsedGranularity);
3941
4042 std::vector<VirtualAddressRange> VirtualMemoryRanges;
4143 std::vector<PhysicalMemoryMapping> PhysicalMemoryMappings;
42-
43- for (size_t Index =0 ; Index< NumberOfVirtualMemoryRanges; ++Index){
44+
45+ for (size_t Index = 0 ; Index < NumberOfVirtualMemoryRanges; ++Index) {
4446 uintptr_t VirtualMemoryPtr =
45- syclext::reserve_virtual_mem (AlignedByteSizePerRange, Context);
47+ syclext::reserve_virtual_mem (AlignedByteSizePerRange, Context);
4648 syclext::physical_mem PhysicalMem{Device, Context, AlignedByteSizePerRange};
47- void *MappedPtr = PhysicalMem.map (VirtualMemoryPtr, AlignedByteSizePerRange, syclext::address_access_mode::read_write);
48-
49- VirtualMemoryRanges.emplace_back (VirtualMemoryPtr, AlignedByteSizePerRange);
49+ void *MappedPtr = PhysicalMem.map (VirtualMemoryPtr, AlignedByteSizePerRange,
50+ syclext::address_access_mode::read_write);
51+
52+ VirtualMemoryRanges.emplace_back (VirtualMemoryPtr, AlignedByteSizePerRange);
5053 PhysicalMemoryMappings.emplace_back (std::move (PhysicalMem), MappedPtr);
5154 }
52-
55+
5356 std::vector<int > ResultHostData (ElementsInRange);
5457
55- for (size_t Index =0 ; Index<NumberOfVirtualMemoryRanges; ++Index){
56- int * DataRangePtr = reinterpret_cast <int *>(PhysicalMemoryMappings[Index].MMappingPtr );
58+ for (size_t Index = 0 ; Index < NumberOfVirtualMemoryRanges; ++Index) {
59+ int *DataRangePtr =
60+ reinterpret_cast <int *>(PhysicalMemoryMappings[Index].MMappingPtr );
5761
5862 Q.parallel_for (ElementsInRange, [=](sycl::id<1 > Idx) {
59- DataRangePtr[Idx] = ValueSetInKernel;
60- }).wait_and_throw ();
63+ DataRangePtr[Idx] = ValueSetInKernel;
64+ }).wait_and_throw ();
6165
6266 {
6367 sycl::buffer<int > ResultBuffer (ResultHostData);
6468
6569 Q.submit ([&](sycl::handler &Handle) {
6670 sycl::accessor A (ResultBuffer, Handle, sycl::write_only);
67- Handle.parallel_for (ElementsInRange,
68- [=](sycl::id<1 > Idx) { A[Idx] = DataRangePtr[Idx]; });
71+ Handle.parallel_for (ElementsInRange, [=](sycl::id<1 > Idx) {
72+ A[Idx] = DataRangePtr[Idx];
73+ });
6974 });
7075 }
71-
76+
7277 for (size_t i = 0 ; i < ElementsInRange; i++) {
7378 if (ResultHostData[i] != ValueSetInKernel) {
74- std::cout << " Comparison failed with virtual range " << Index+ 1 << " at index " << i<< " : "
75- << ResultHostData[i] << " != " << ValueSetInKernel
76- << std::endl;
77- ++Failed;
79+ std::cout << " Comparison failed with virtual range " << Index + 1
80+ << " at index " << i << " : " << ResultHostData[i]
81+ << " != " << ValueSetInKernel << std::endl;
82+ ++Failed;
7883 }
79- }
84+ }
8085 }
8186
82- for (auto PhysMemMap: PhysicalMemoryMappings){
83- syclext::unmap (PhysMemMap.MMappingPtr , PhysMemMap.MPhysicalMem .size (), Context);
87+ for (auto PhysMemMap : PhysicalMemoryMappings) {
88+ syclext::unmap (PhysMemMap.MMappingPtr , PhysMemMap.MPhysicalMem .size (),
89+ Context);
8490 }
85- for (auto VirtualMemRange: VirtualMemoryRanges) {
86- syclext::free_virtual_mem (VirtualMemRange.MPtr , VirtualMemRange.MSize , Context);
91+ for (auto VirtualMemRange : VirtualMemoryRanges) {
92+ syclext::free_virtual_mem (VirtualMemRange.MPtr , VirtualMemRange.MSize ,
93+ Context);
8794 }
88-
95+
8996 return Failed;
9097}
0 commit comments