@@ -22,211 +22,6 @@ using namespace sycl;
22
22
23
23
int main () {
24
24
bool Failed = false ;
25
- {
26
- sycl::context Ctx;
27
- cl_context OCLCtx = Ctx.get ();
28
-
29
- cl_int Error = CL_SUCCESS;
30
- cl_mem OCLBuf =
31
- clCreateBuffer (OCLCtx, CL_MEM_READ_WRITE, sizeof (int ), nullptr , &Error);
32
- assert (Error == CL_SUCCESS);
33
- Error = clReleaseContext (OCLCtx);
34
- assert (Error == CL_SUCCESS);
35
-
36
- sycl::buffer<int , 1 > Buf{OCLBuf, Ctx};
37
-
38
- sycl::queue Q;
39
-
40
- if (Ctx == Q.get_context ()) {
41
- std::cerr << " Expected different contexts" << std::endl;
42
- Failed = true ;
43
- }
44
-
45
- Q.submit ([&](sycl::handler &CGH) {
46
- auto Acc = Buf.get_access <access::mode::write>(CGH);
47
- CGH.single_task <class BufferInterop_DifferentContext >(
48
- [=]() { Acc[0 ] = 42 ; });
49
- });
50
-
51
- auto Acc = Buf.get_access <sycl::access::mode::read>();
52
- if (Acc[0 ] != 42 ) {
53
- std::cerr << " Result is incorrect" << std::endl;
54
- Failed = true ;
55
- }
56
- }
57
- {
58
- constexpr size_t Size = 32 ;
59
- int Init[Size] = {5 };
60
- cl_int Error = CL_SUCCESS;
61
- sycl::range<1 > InteropRange{Size};
62
- size_t InteropSize = Size * sizeof (int );
63
-
64
- queue MyQueue;
65
-
66
- cl_context OCLCtx = MyQueue.get_context ().get ();
67
-
68
- cl_mem OpenCLBuffer =
69
- clCreateBuffer (OCLCtx, CL_MEM_READ_WRITE | CL_MEM_COPY_HOST_PTR,
70
- Size * sizeof (int ), Init, &Error);
71
- assert (Error == CL_SUCCESS);
72
- buffer<int , 1 > Buffer{OpenCLBuffer, MyQueue.get_context ()};
73
-
74
- if (Buffer.get_range () != InteropRange) {
75
- assert (false );
76
- Failed = true ;
77
- }
78
- if (Buffer.get_size () != InteropSize) {
79
- assert (false );
80
- Failed = true ;
81
- }
82
- if (Buffer.get_count () != Size) {
83
- assert (false );
84
- Failed = true ;
85
- }
86
-
87
- MyQueue.submit ([&](handler &CGH) {
88
- auto B = Buffer.get_access <access::mode::write>(CGH);
89
- CGH.parallel_for <class BufferInterop >(
90
- range<1 >{Size}, [=](id<1 > Index) { B[Index] = 10 ; });
91
- });
92
-
93
- int Data[Size] = {10 };
94
- std::vector<int > Result (Size, 0 );
95
- {
96
- buffer<int , 1 > BufferData{
97
- Data, range<1 >{Size}, {property::buffer::use_host_ptr ()}};
98
- BufferData.set_final_data (Result.begin ());
99
- MyQueue.submit ([&](handler &CGH) {
100
- auto Data = BufferData.get_access <access::mode::write>(CGH);
101
- auto CLData = Buffer.get_access <access::mode::read>(CGH);
102
- CGH.parallel_for <class UseMemContent >(range<1 >{Size}, [=](id<1 > Index) {
103
- Data[Index] = 2 * CLData[Index];
104
- });
105
- });
106
- }
107
-
108
- Error = clReleaseMemObject (OpenCLBuffer);
109
- assert (Error == CL_SUCCESS);
110
-
111
- for (size_t i = 0 ; i < Size; ++i) {
112
- if (Result[i] != 20 ) {
113
- std::cout << " array[" << i << " ] is " << Result[i] << " expected "
114
- << 20 << std::endl;
115
- assert (false );
116
- Failed = true ;
117
- }
118
- }
119
- Error = clReleaseContext (OCLCtx);
120
- assert (Error == CL_SUCCESS);
121
- }
122
- // Check set_final_data
123
- {
124
- constexpr size_t Size = 32 ;
125
- int Init[Size] = {5 };
126
- int Result[Size] = {5 };
127
- cl_int Error = CL_SUCCESS;
128
-
129
- queue MyQueue;
130
- cl_context OCLCtx = MyQueue.get_context ().get ();
131
-
132
- cl_mem OpenCLBuffer =
133
- clCreateBuffer (OCLCtx, CL_MEM_READ_WRITE | CL_MEM_COPY_HOST_PTR,
134
- Size * sizeof (int ), Init, &Error);
135
- assert (Error == CL_SUCCESS);
136
- {
137
- buffer<int , 1 > Buffer{OpenCLBuffer, MyQueue.get_context ()};
138
- Buffer.set_final_data (Result);
139
-
140
- MyQueue.submit ([&](handler &CGH) {
141
- auto B = Buffer.get_access <access::mode::write>(CGH);
142
- CGH.parallel_for <class FinalData >(range<1 >{Size},
143
- [=](id<1 > Index) { B[Index] = 10 ; });
144
- });
145
- }
146
- Error = clReleaseMemObject (OpenCLBuffer);
147
- assert (Error == CL_SUCCESS);
148
- for (size_t i = 0 ; i < Size; ++i) {
149
- if (Result[i] != 10 ) {
150
- std::cout << " array[" << i << " ] is " << Result[i] << " expected "
151
- << 10 << std::endl;
152
- assert (false );
153
- Failed = true ;
154
- }
155
- }
156
- Error = clReleaseContext (OCLCtx);
157
- assert (Error == CL_SUCCESS);
158
- }
159
- // Check host accessor
160
- {
161
- constexpr size_t Size = 32 ;
162
- int Init[Size] = {5 };
163
- cl_int Error = CL_SUCCESS;
164
-
165
- queue MyQueue;
166
- cl_context OCLCtx = MyQueue.get_context ().get ();
167
-
168
- cl_mem OpenCLBuffer =
169
- clCreateBuffer (OCLCtx, CL_MEM_READ_WRITE | CL_MEM_COPY_HOST_PTR,
170
- Size * sizeof (int ), Init, &Error);
171
- assert (Error == CL_SUCCESS);
172
- buffer<int , 1 > Buffer{OpenCLBuffer, MyQueue.get_context ()};
173
-
174
- MyQueue.submit ([&](handler &CGH) {
175
- auto B = Buffer.get_access <access::mode::write>(CGH);
176
- CGH.parallel_for <class HostAccess >(range<1 >{Size},
177
- [=](id<1 > Index) { B[Index] = 10 ; });
178
- });
179
- auto Acc = Buffer.get_access <sycl::access::mode::read>();
180
- for (size_t i = 0 ; i < Size; ++i) {
181
- if (Acc[i] != 10 ) {
182
- std::cout << " array[" << i << " ] is " << Acc[i] << " expected " << 10
183
- << std::endl;
184
- assert (false );
185
- Failed = true ;
186
- }
187
- }
188
- Error = clReleaseMemObject (OpenCLBuffer);
189
- assert (Error == CL_SUCCESS);
190
- Error = clReleaseContext (OCLCtx);
191
- assert (Error == CL_SUCCESS);
192
- }
193
- // Check interop constructor event
194
- {
195
- // Checks that the cl_event is not deleted on memory object destruction
196
- queue MyQueue;
197
- cl_context OpenCLContext = MyQueue.get_context ().get ();
198
-
199
- int Val;
200
- cl_int Error = CL_SUCCESS;
201
- cl_mem OpenCLBuffer =
202
- clCreateBuffer (OpenCLContext, CL_MEM_READ_WRITE | CL_MEM_COPY_HOST_PTR,
203
- sizeof (int ), &Val, &Error);
204
- assert (Error == CL_SUCCESS);
205
- cl_event OpenCLEvent = clCreateUserEvent (OpenCLContext, &Error);
206
- assert (Error == CL_SUCCESS);
207
- assert (clSetUserEventStatus (OpenCLEvent, CL_COMPLETE) == CL_SUCCESS);
208
-
209
- {
210
- event Event (OpenCLEvent, OpenCLContext);
211
- buffer<int , 1 > Buffer{OpenCLBuffer, MyQueue.get_context (), Event};
212
-
213
- MyQueue.submit ([&](handler &Cgh) {
214
- auto Acc = Buffer.get_access <access::mode::write>(Cgh);
215
- Cgh.single_task <class TestEvent >([=]() { Acc[0 ] = 42 ; });
216
- });
217
-
218
- auto Acc = Buffer.get_access <access::mode::read>();
219
- if (42 != Acc[0 ]) {
220
- assert (false );
221
- Failed = true ;
222
- }
223
- }
224
-
225
- assert (clReleaseMemObject (OpenCLBuffer) == CL_SUCCESS);
226
- assert (clReleaseContext (OpenCLContext) == CL_SUCCESS);
227
- assert (clReleaseEvent (OpenCLEvent) == CL_SUCCESS);
228
- }
229
-
230
25
{
231
26
queue Queue;
232
27
if (!Queue.is_host ()) {
0 commit comments