@@ -310,9 +310,11 @@ ol_impl_result_t olMemAlloc_impl(ol_device_handle_t Device,
310
310
void **AllocationOut) {
311
311
auto Alloc =
312
312
Device->Device ->dataAlloc (Size , nullptr , convertOlToPluginAllocTy (Type));
313
- if (!Alloc)
313
+ if (!Alloc) {
314
+ llvm::consumeError (Alloc.takeError ());
314
315
return {OL_ERRC_OUT_OF_RESOURCES,
315
316
formatv (" Could not create allocation on device {0}" , Device).str ()};
317
+ }
316
318
317
319
*AllocationOut = *Alloc;
318
320
allocInfoMap ().insert_or_assign (*Alloc, AllocInfo{Device, Type});
@@ -329,8 +331,10 @@ ol_impl_result_t olMemFree_impl(void *Address) {
329
331
330
332
auto Res =
331
333
Device->Device ->dataDelete (Address, convertOlToPluginAllocTy (Type));
332
- if (Res)
334
+ if (Res) {
335
+ llvm::consumeError (std::move (Res));
333
336
return {OL_ERRC_OUT_OF_RESOURCES, " Could not free allocation" };
337
+ }
334
338
335
339
allocInfoMap ().erase (Address);
336
340
@@ -342,7 +346,8 @@ ol_impl_result_t olCreateQueue_impl(ol_device_handle_t Device,
342
346
auto CreatedQueue = std::make_unique<ol_queue_impl_t >(nullptr , Device);
343
347
auto Err = Device->Device ->initAsyncInfo (&(CreatedQueue->AsyncInfo ));
344
348
if (Err)
345
- return {OL_ERRC_UNKNOWN, " Could not initialize stream resource" };
349
+ return ol_impl_result_t::fromError (std::move (Err),
350
+ " Could not initialize stream resource" );
346
351
347
352
*Queue = CreatedQueue.release ();
348
353
return OL_SUCCESS;
@@ -357,24 +362,29 @@ ol_impl_result_t olWaitQueue_impl(ol_queue_handle_t Queue) {
357
362
// on it, but we have nothing to synchronize in that situation anyway.
358
363
if (Queue->AsyncInfo ->Queue ) {
359
364
auto Err = Queue->Device ->Device ->synchronize (Queue->AsyncInfo );
360
- if (Err)
365
+ if (Err) {
366
+ llvm::consumeError (std::move (Err));
361
367
return {OL_ERRC_INVALID_QUEUE, " The queue failed to synchronize" };
368
+ }
362
369
}
363
370
364
371
// Recreate the stream resource so the queue can be reused
365
372
// TODO: Would be easier for the synchronization to (optionally) not release
366
373
// it to begin with.
367
374
auto Res = Queue->Device ->Device ->initAsyncInfo (&Queue->AsyncInfo );
368
375
if (Res)
369
- return {OL_ERRC_UNKNOWN, " Could not reinitialize the stream resource" };
376
+ return ol_impl_result_t::fromError (
377
+ std::move (Res), " Could not reinitialize the stream resource" );
370
378
371
379
return OL_SUCCESS;
372
380
}
373
381
374
382
ol_impl_result_t olWaitEvent_impl (ol_event_handle_t Event) {
375
383
auto Res = Event->Queue ->Device ->Device ->syncEvent (Event->EventInfo );
376
- if (Res)
384
+ if (Res) {
385
+ llvm::consumeError (std::move (Res));
377
386
return {OL_ERRC_INVALID_EVENT, " The event failed to synchronize" };
387
+ }
378
388
379
389
return OL_SUCCESS;
380
390
}
@@ -390,13 +400,17 @@ ol_impl_result_t olDestroyEvent_impl(ol_event_handle_t Event) {
390
400
ol_event_handle_t makeEvent (ol_queue_handle_t Queue) {
391
401
auto EventImpl = std::make_unique<ol_event_impl_t >(nullptr , Queue);
392
402
auto Res = Queue->Device ->Device ->createEvent (&EventImpl->EventInfo );
393
- if (Res)
403
+ if (Res) {
404
+ llvm::consumeError (std::move (Res));
394
405
return nullptr ;
406
+ }
395
407
396
408
Res = Queue->Device ->Device ->recordEvent (EventImpl->EventInfo ,
397
409
Queue->AsyncInfo );
398
- if (Res)
410
+ if (Res) {
411
+ llvm::consumeError (std::move (Res));
399
412
return nullptr ;
413
+ }
400
414
401
415
return EventImpl.release ();
402
416
}
@@ -422,16 +436,19 @@ ol_impl_result_t olMemcpy_impl(ol_queue_handle_t Queue, void *DstPtr,
422
436
if (DstDevice == HostDevice ()) {
423
437
auto Res = SrcDevice->Device ->dataRetrieve (DstPtr, SrcPtr, Size , QueueImpl);
424
438
if (Res)
425
- return {OL_ERRC_UNKNOWN, " The data retrieve operation failed" };
439
+ return ol_impl_result_t::fromError (std::move (Res),
440
+ " The data retrieve operation failed" );
426
441
} else if (SrcDevice == HostDevice ()) {
427
442
auto Res = DstDevice->Device ->dataSubmit (DstPtr, SrcPtr, Size , QueueImpl);
428
443
if (Res)
429
- return {OL_ERRC_UNKNOWN, " The data submit operation failed" };
444
+ return ol_impl_result_t::fromError (std::move (Res),
445
+ " The data submit operation failed" );
430
446
} else {
431
447
auto Res = SrcDevice->Device ->dataExchange (SrcPtr, *DstDevice->Device ,
432
448
DstPtr, Size , QueueImpl);
433
449
if (Res)
434
- return {OL_ERRC_UNKNOWN, " The data exchange operation failed" };
450
+ return ol_impl_result_t::fromError (std::move (Res),
451
+ " The data exchange operation failed" );
435
452
}
436
453
437
454
if (EventOut)
@@ -458,6 +475,7 @@ ol_impl_result_t olCreateProgram_impl(ol_device_handle_t Device,
458
475
auto Res =
459
476
Device->Device ->loadBinary (Device->Device ->Plugin , &Prog->DeviceImage );
460
477
if (!Res) {
478
+ llvm::consumeError (Res.takeError ());
461
479
delete Prog;
462
480
return OL_ERRC_INVALID_VALUE;
463
481
}
@@ -483,7 +501,8 @@ ol_impl_result_t olGetKernel_impl(ol_program_handle_t Program,
483
501
484
502
auto Err = KernelImpl->init (Device, *Program->Image );
485
503
if (Err)
486
- return {OL_ERRC_UNKNOWN, " Could not initialize the kernel" };
504
+ return ol_impl_result_t::fromError (std::move (Err),
505
+ " Could not initialize the kernel" );
487
506
488
507
*Kernel = &*KernelImpl;
489
508
@@ -526,7 +545,8 @@ olLaunchKernel_impl(ol_queue_handle_t Queue, ol_device_handle_t Device,
526
545
527
546
AsyncInfoWrapper.finalize (Err);
528
547
if (Err)
529
- return {OL_ERRC_UNKNOWN, " Could not finalize the AsyncInfoWrapper" };
548
+ return ol_impl_result_t::fromError (
549
+ std::move (Err), " Could not finalize the AsyncInfoWrapper" );
530
550
531
551
if (EventOut)
532
552
*EventOut = makeEvent (Queue);
0 commit comments