Skip to content

Commit b798677

Browse files
committed
formatting fixed
1 parent a6d9a3d commit b798677

File tree

1 file changed

+79
-67
lines changed

1 file changed

+79
-67
lines changed

sycl/test-e2e/VirtualMem/virtual_mem_usm_compatibility.cpp

Lines changed: 79 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// REQUIRES: aspect-usm_shared_allocations
22

3-
// This test checks whether a pointer produced by a virtual memory
3+
// This test checks whether a pointer produced by a virtual memory
44
// range mapping can indeed be used in various APIs accepting a USM pointer
55

66
// RUN: %{build} -o %t.out
@@ -10,109 +10,121 @@
1010

1111
#include "helpers.hpp"
1212

13-
int main(){
14-
15-
sycl::queue Queue;
16-
sycl::context Context = Queue.get_context();
17-
sycl::device Device = Queue.get_device();
13+
int main() {
1814

19-
int Failed =0;
20-
constexpr int ValueSetInKernelForCopyToUSM= 111;
21-
constexpr int ValueSetForCopyToVirtualMem= 222;
22-
constexpr int ValueSetInMemSetOperation = 333;
23-
constexpr int ValueSetInFillOperation = 444;
24-
constexpr size_t NumberOfElements = 1000;
25-
size_t BytesRequired = NumberOfElements * sizeof(int);
15+
sycl::queue Queue;
16+
sycl::context Context = Queue.get_context();
17+
sycl::device Device = Queue.get_device();
2618

27-
size_t UsedGranularity = GetLCMGranularity(Device, Context);
28-
size_t AlignedByteSize = GetAlignedByteSize(BytesRequired, UsedGranularity);
19+
int Failed = 0;
20+
constexpr int ValueSetInKernelForCopyToUSM = 111;
21+
constexpr int ValueSetForCopyToVirtualMem = 222;
22+
constexpr int ValueSetInMemSetOperation = 333;
23+
constexpr int ValueSetInFillOperation = 444;
24+
constexpr size_t NumberOfElements = 1000;
25+
size_t BytesRequired = NumberOfElements * sizeof(int);
2926

30-
syclext::physical_mem PhysicalMem{Device, Context, AlignedByteSize};
31-
uintptr_t VirtualMemoryPtr = syclext::reserve_virtual_mem(0, AlignedByteSize, Context);
27+
size_t UsedGranularity = GetLCMGranularity(Device, Context);
28+
size_t AlignedByteSize = GetAlignedByteSize(BytesRequired, UsedGranularity);
3229

33-
void *MappedPtr =
34-
PhysicalMem.map(VirtualMemoryPtr, AlignedByteSize,
35-
syclext::address_access_mode::read_write);
30+
syclext::physical_mem PhysicalMem{Device, Context, AlignedByteSize};
31+
uintptr_t VirtualMemoryPtr =
32+
syclext::reserve_virtual_mem(0, AlignedByteSize, Context);
3633

37-
int *DataPtr = reinterpret_cast<int *>(MappedPtr);
34+
void *MappedPtr = PhysicalMem.map(VirtualMemoryPtr, AlignedByteSize,
35+
syclext::address_access_mode::read_write);
3836

39-
Queue.parallel_for(NumberOfElements, [=](sycl::id<1> Idx) {
40-
DataPtr[Idx] = ValueSetInKernelForCopyToUSM;
41-
}).wait_and_throw();
37+
int *DataPtr = reinterpret_cast<int *>(MappedPtr);
4238

43-
//Check that can copy from virtual memory to a USM allocation
44-
int *CopyBack = sycl::malloc_shared<int>(NumberOfElements, Queue);
39+
Queue
40+
.parallel_for(
41+
NumberOfElements,
42+
[=](sycl::id<1> Idx) { DataPtr[Idx] = ValueSetInKernelForCopyToUSM; })
43+
.wait_and_throw();
4544

46-
Queue.parallel_for(NumberOfElements, [=](sycl::id<1> Idx) {
47-
CopyBack[Idx] = DataPtr[Idx];
48-
}).wait_and_throw();
45+
// Check that can copy from virtual memory to a USM allocation
46+
int *CopyBack = sycl::malloc_shared<int>(NumberOfElements, Queue);
4947

48+
Queue
49+
.parallel_for(NumberOfElements,
50+
[=](sycl::id<1> Idx) { CopyBack[Idx] = DataPtr[Idx]; })
51+
.wait_and_throw();
5052

51-
for (size_t i = 0; i < NumberOfElements; i++) {
52-
if (CopyBack[i] != ValueSetInKernelForCopyToUSM) {
53-
std::cout << "Comparison failed after copy from virtual memory to a USM allocation at index " << i << ": "
54-
<< CopyBack[i] << " != " << ValueSetInKernelForCopyToUSM
55-
<< std::endl;
53+
for (size_t i = 0; i < NumberOfElements; i++) {
54+
if (CopyBack[i] != ValueSetInKernelForCopyToUSM) {
55+
std::cout << "Comparison failed after copy from virtual memory to a USM "
56+
"allocation at index "
57+
<< i << ": " << CopyBack[i]
58+
<< " != " << ValueSetInKernelForCopyToUSM << std::endl;
5659
++Failed;
5760
}
5861
}
5962

60-
//Check that can copy from a USM allocation to virtual memory
63+
// Check that can copy from a USM allocation to virtual memory
6164
int *CopyFrom = sycl::malloc_shared<int>(NumberOfElements, Queue);
62-
for(size_t Idx =0; Idx<NumberOfElements; ++Idx){
63-
CopyFrom[Idx] = ValueSetForCopyToVirtualMem;
65+
for (size_t Idx = 0; Idx < NumberOfElements; ++Idx) {
66+
CopyFrom[Idx] = ValueSetForCopyToVirtualMem;
6467
}
6568

66-
Queue.parallel_for(NumberOfElements, [=](sycl::id<1> Idx) {
67-
DataPtr[Idx] = CopyFrom[Idx];
68-
}).wait_and_throw();
69+
Queue
70+
.parallel_for(NumberOfElements,
71+
[=](sycl::id<1> Idx) { DataPtr[Idx] = CopyFrom[Idx]; })
72+
.wait_and_throw();
6973

70-
Queue.parallel_for(NumberOfElements, [=](sycl::id<1> Idx) {
71-
CopyBack[Idx] = DataPtr[Idx];
72-
}).wait_and_throw();
74+
Queue
75+
.parallel_for(NumberOfElements,
76+
[=](sycl::id<1> Idx) { CopyBack[Idx] = DataPtr[Idx]; })
77+
.wait_and_throw();
7378

7479
for (size_t i = 0; i < NumberOfElements; i++) {
75-
if (CopyBack[i] != ValueSetForCopyToVirtualMem) {
76-
std::cout << "Comparison failed after copy from a USM allocation to virtual memory at index " << i << ": "
77-
<< CopyBack[i] << " != " << ValueSetForCopyToVirtualMem
78-
<< std::endl;
80+
if (CopyBack[i] != ValueSetForCopyToVirtualMem) {
81+
std::cout << "Comparison failed after copy from a USM allocation to "
82+
"virtual memory at index "
83+
<< i << ": " << CopyBack[i]
84+
<< " != " << ValueSetForCopyToVirtualMem << std::endl;
7985
++Failed;
8086
}
8187
}
8288

83-
//Check that can use memset on virtual memory
84-
Queue.memset(DataPtr, ValueSetInMemSetOperation, AlignedByteSize).wait_and_throw();
85-
86-
Queue.parallel_for(NumberOfElements, [=](sycl::id<1> Idx) {
87-
CopyBack[Idx] = DataPtr[Idx];
88-
}).wait_and_throw();
89+
// Check that can use memset on virtual memory
90+
Queue.memset(DataPtr, ValueSetInMemSetOperation, AlignedByteSize)
91+
.wait_and_throw();
92+
93+
Queue
94+
.parallel_for(NumberOfElements,
95+
[=](sycl::id<1> Idx) { CopyBack[Idx] = DataPtr[Idx]; })
96+
.wait_and_throw();
8997

9098
for (size_t i = 0; i < NumberOfElements; i++) {
91-
if (CopyBack[i] != ValueSetInMemSetOperation) {
92-
std::cout << "Comparison failed after memset operation on virtual memory at index " << i << ": "
93-
<< CopyBack[i] << " != " << ValueSetInMemSetOperation
94-
<< std::endl;
99+
if (CopyBack[i] != ValueSetInMemSetOperation) {
100+
std::cout << "Comparison failed after memset operation on virtual memory "
101+
"at index "
102+
<< i << ": " << CopyBack[i]
103+
<< " != " << ValueSetInMemSetOperation << std::endl;
95104
++Failed;
96105
}
97106
}
98107

99-
//Check that can use fill on virtual memory
108+
// Check that can use fill on virtual memory
109+
110+
Queue.fill(DataPtr, ValueSetInFillOperation, AlignedByteSize)
111+
.wait_and_throw();
100112

101-
Queue.fill(DataPtr, ValueSetInFillOperation, AlignedByteSize).wait_and_throw();
102-
103-
Queue.parallel_for(NumberOfElements, [=](sycl::id<1> Idx) {
104-
CopyBack[Idx] = DataPtr[Idx];
105-
}).wait_and_throw();
113+
Queue
114+
.parallel_for(NumberOfElements,
115+
[=](sycl::id<1> Idx) { CopyBack[Idx] = DataPtr[Idx]; })
116+
.wait_and_throw();
106117

107118
for (size_t i = 0; i < NumberOfElements; i++) {
108-
if (CopyBack[i] != ValueSetInFillOperation) {
109-
std::cout << "Comparison failed after fill operation on virtual memory at index " << i << ": "
110-
<< CopyBack[i] << " != " << ValueSetInFillOperation
119+
if (CopyBack[i] != ValueSetInFillOperation) {
120+
std::cout << "Comparison failed after fill operation on virtual memory "
121+
"at index "
122+
<< i << ": " << CopyBack[i] << " != " << ValueSetInFillOperation
111123
<< std::endl;
112124
++Failed;
113125
}
114126
}
115-
127+
116128
sycl::free(CopyFrom, Queue);
117129
sycl::free(CopyBack, Queue);
118130
syclext::unmap(MappedPtr, AlignedByteSize, Context);

0 commit comments

Comments
 (0)