@@ -308,9 +308,11 @@ ol_impl_result_t olMemAlloc_impl(ol_device_handle_t Device,
308
308
void **AllocationOut) {
309
309
auto Alloc =
310
310
Device->Device ->dataAlloc (Size , nullptr , convertOlToPluginAllocTy (Type));
311
- if (!Alloc)
311
+ if (!Alloc) {
312
+ llvm::consumeError (Alloc.takeError ());
312
313
return {OL_ERRC_OUT_OF_RESOURCES,
313
314
formatv (" Could not create allocation on device {0}" , Device).str ()};
315
+ }
314
316
315
317
*AllocationOut = *Alloc;
316
318
allocInfoMap ().insert_or_assign (*Alloc, AllocInfo{Device, Type});
@@ -327,8 +329,10 @@ ol_impl_result_t olMemFree_impl(void *Address) {
327
329
328
330
auto Res =
329
331
Device->Device ->dataDelete (Address, convertOlToPluginAllocTy (Type));
330
- if (Res)
332
+ if (Res) {
333
+ llvm::consumeError (std::move (Res));
331
334
return {OL_ERRC_OUT_OF_RESOURCES, " Could not free allocation" };
335
+ }
332
336
333
337
allocInfoMap ().erase (Address);
334
338
@@ -340,7 +344,8 @@ ol_impl_result_t olCreateQueue_impl(ol_device_handle_t Device,
340
344
auto CreatedQueue = std::make_unique<ol_queue_impl_t >(nullptr , Device);
341
345
auto Err = Device->Device ->initAsyncInfo (&(CreatedQueue->AsyncInfo ));
342
346
if (Err)
343
- return {OL_ERRC_UNKNOWN, " Could not initialize stream resource" };
347
+ return ol_impl_result_t::fromError (std::move (Err),
348
+ " Could not initialize stream resource" );
344
349
345
350
*Queue = CreatedQueue.release ();
346
351
return OL_SUCCESS;
@@ -355,24 +360,29 @@ ol_impl_result_t olWaitQueue_impl(ol_queue_handle_t Queue) {
355
360
// on it, but we have nothing to synchronize in that situation anyway.
356
361
if (Queue->AsyncInfo ->Queue ) {
357
362
auto Err = Queue->Device ->Device ->synchronize (Queue->AsyncInfo );
358
- if (Err)
363
+ if (Err) {
364
+ llvm::consumeError (std::move (Err));
359
365
return {OL_ERRC_INVALID_QUEUE, " The queue failed to synchronize" };
366
+ }
360
367
}
361
368
362
369
// Recreate the stream resource so the queue can be reused
363
370
// TODO: Would be easier for the synchronization to (optionally) not release
364
371
// it to begin with.
365
372
auto Res = Queue->Device ->Device ->initAsyncInfo (&Queue->AsyncInfo );
366
373
if (Res)
367
- return {OL_ERRC_UNKNOWN, " Could not reinitialize the stream resource" };
374
+ return ol_impl_result_t::fromError (
375
+ std::move (Res), " Could not reinitialize the stream resource" );
368
376
369
377
return OL_SUCCESS;
370
378
}
371
379
372
380
ol_impl_result_t olWaitEvent_impl (ol_event_handle_t Event) {
373
381
auto Res = Event->Queue ->Device ->Device ->syncEvent (Event->EventInfo );
374
- if (Res)
382
+ if (Res) {
383
+ llvm::consumeError (std::move (Res));
375
384
return {OL_ERRC_INVALID_EVENT, " The event failed to synchronize" };
385
+ }
376
386
377
387
return OL_SUCCESS;
378
388
}
@@ -384,13 +394,17 @@ ol_impl_result_t olDestroyEvent_impl(ol_event_handle_t Event) {
384
394
ol_event_handle_t makeEvent (ol_queue_handle_t Queue) {
385
395
auto EventImpl = std::make_unique<ol_event_impl_t >(nullptr , Queue);
386
396
auto Res = Queue->Device ->Device ->createEvent (&EventImpl->EventInfo );
387
- if (Res)
397
+ if (Res) {
398
+ llvm::consumeError (std::move (Res));
388
399
return nullptr ;
400
+ }
389
401
390
402
Res = Queue->Device ->Device ->recordEvent (EventImpl->EventInfo ,
391
403
Queue->AsyncInfo );
392
- if (Res)
404
+ if (Res) {
405
+ llvm::consumeError (std::move (Res));
393
406
return nullptr ;
407
+ }
394
408
395
409
return EventImpl.release ();
396
410
}
@@ -416,16 +430,19 @@ ol_impl_result_t olMemcpy_impl(ol_queue_handle_t Queue, void *DstPtr,
416
430
if (DstDevice == HostDevice ()) {
417
431
auto Res = SrcDevice->Device ->dataRetrieve (DstPtr, SrcPtr, Size , QueueImpl);
418
432
if (Res)
419
- return {OL_ERRC_UNKNOWN, " The data retrieve operation failed" };
433
+ return ol_impl_result_t::fromError (std::move (Res),
434
+ " The data retrieve operation failed" );
420
435
} else if (SrcDevice == HostDevice ()) {
421
436
auto Res = DstDevice->Device ->dataSubmit (DstPtr, SrcPtr, Size , QueueImpl);
422
437
if (Res)
423
- return {OL_ERRC_UNKNOWN, " The data submit operation failed" };
438
+ return ol_impl_result_t::fromError (std::move (Res),
439
+ " The data submit operation failed" );
424
440
} else {
425
441
auto Res = SrcDevice->Device ->dataExchange (SrcPtr, *DstDevice->Device ,
426
442
DstPtr, Size , QueueImpl);
427
443
if (Res)
428
- return {OL_ERRC_UNKNOWN, " The data exchange operation failed" };
444
+ return ol_impl_result_t::fromError (std::move (Res),
445
+ " The data exchange operation failed" );
429
446
}
430
447
431
448
if (EventOut)
@@ -452,6 +469,7 @@ ol_impl_result_t olCreateProgram_impl(ol_device_handle_t Device,
452
469
auto Res =
453
470
Device->Device ->loadBinary (Device->Device ->Plugin , &Prog->DeviceImage );
454
471
if (!Res) {
472
+ llvm::consumeError (Res.takeError ());
455
473
delete Prog;
456
474
return OL_ERRC_INVALID_VALUE;
457
475
}
@@ -477,7 +495,8 @@ ol_impl_result_t olGetKernel_impl(ol_program_handle_t Program,
477
495
478
496
auto Err = KernelImpl->init (Device, *Program->Image );
479
497
if (Err)
480
- return {OL_ERRC_UNKNOWN, " Could not initialize the kernel" };
498
+ return ol_impl_result_t::fromError (std::move (Err),
499
+ " Could not initialize the kernel" );
481
500
482
501
*Kernel = &*KernelImpl;
483
502
@@ -520,7 +539,8 @@ olLaunchKernel_impl(ol_queue_handle_t Queue, ol_device_handle_t Device,
520
539
521
540
AsyncInfoWrapper.finalize (Err);
522
541
if (Err)
523
- return {OL_ERRC_UNKNOWN, " Could not finalize the AsyncInfoWrapper" };
542
+ return ol_impl_result_t::fromError (
543
+ std::move (Err), " Could not finalize the AsyncInfoWrapper" );
524
544
525
545
if (EventOut)
526
546
*EventOut = makeEvent (Queue);
0 commit comments