@@ -37,9 +37,9 @@ void copy(buffer<DataT, 1> &Src, buffer<DataT, 1> &Dst, queue &Q) {
37
37
auto DstA = Dst.template get_access <mode::write >(CGH);
38
38
39
39
CGH.codeplay_host_task ([=](interop_handle IH) {
40
- auto NativeQ = IH.get_native_queue ();
41
- auto SrcMem = IH.get_native_mem (SrcA);
42
- auto DstMem = IH.get_native_mem (DstA);
40
+ auto NativeQ = IH.get_native_queue <backend::opencl> ();
41
+ auto SrcMem = IH.get_native_mem <backend::opencl> (SrcA);
42
+ auto DstMem = IH.get_native_mem <backend::opencl> (DstA);
43
43
cl_event Event;
44
44
45
45
int RC = clEnqueueCopyBuffer (NativeQ, SrcMem, DstMem, 0 , 0 ,
@@ -221,13 +221,65 @@ void test5() {
221
221
checkBufferValues (Buffer2, static_cast <int >(123 ));
222
222
}
223
223
224
+ // The test checks that placeholder accessors are correctly handled,
225
+ // when properly registered in the command group.
226
+ // It also checks that an exception is thrown if the placeholder accessor
227
+ // is not registered.
228
+ void test6 () {
229
+ queue Queue ([](sycl::exception_list ExceptionList) {
230
+ if (ExceptionList.size () != 1 ) {
231
+ std::cerr << " Should be one exception in exception list" << std::endl;
232
+ std::abort ();
233
+ }
234
+ std::rethrow_exception (*ExceptionList.begin ());
235
+ });
236
+
237
+ // Placeholder accessor that is properly registered in CGH.
238
+ try {
239
+ size_t size = 1 ;
240
+ buffer<int , 1 > Buf{size};
241
+ accessor<int , 1 , mode::write , target::global_buffer,
242
+ access ::placeholder::true_t >
243
+ PHAcc (Buf);
244
+ Queue.submit ([&](sycl::handler &CGH) {
245
+ CGH.require (PHAcc);
246
+ CGH.codeplay_host_task (
247
+ [=](interop_handle IH) { (void )IH.get_native_mem (PHAcc); });
248
+ });
249
+ Queue.wait_and_throw ();
250
+ } catch (sycl::exception &E) {
251
+ std::cerr << " Unexpected exception caught: " << E.what ();
252
+ assert (!" Unexpected exception caught" );
253
+ }
254
+
255
+ // Placeholder accessor that is NOT registered in CGH.
256
+ try {
257
+ size_t size = 1 ;
258
+ buffer<int , 1 > Buf{size};
259
+ accessor<int , 1 , mode::write , target::global_buffer,
260
+ access ::placeholder::true_t >
261
+ PHAcc (Buf);
262
+ Queue.submit ([&](sycl::handler &CGH) {
263
+ CGH.codeplay_host_task (
264
+ [=](interop_handle IH) { (void )IH.get_native_mem (PHAcc); });
265
+ });
266
+ Queue.wait_and_throw ();
267
+ assert (!" Expected exception was not caught" );
268
+ } catch (sycl::exception &E) {
269
+ assert (std::string (E.what ()).find (" Invalid memory object" ) !=
270
+ std::string::npos &&
271
+ " Unexpected error was caught!" );
272
+ }
273
+ }
274
+
224
275
int main () {
225
276
test1 ();
226
277
test2 ();
227
278
test2_1 ();
228
279
test3 ();
229
280
test4 ();
230
281
test5 ();
282
+ test6 ();
231
283
std::cout << " Test PASSED" << std::endl;
232
284
return 0 ;
233
285
}
0 commit comments