@@ -311,8 +311,7 @@ ol_impl_result_t olMemAlloc_impl(ol_device_handle_t Device,
311
311
auto Alloc =
312
312
Device->Device ->dataAlloc (Size , nullptr , convertOlToPluginAllocTy (Type));
313
313
if (!Alloc)
314
- return {OL_ERRC_OUT_OF_RESOURCES,
315
- formatv (" Could not create allocation on device {0}" , Device).str ()};
314
+ return ol_impl_result_t::fromError (Alloc.takeError ());
316
315
317
316
*AllocationOut = *Alloc;
318
317
allocInfoMap ().insert_or_assign (*Alloc, AllocInfo{Device, Type});
@@ -330,7 +329,7 @@ ol_impl_result_t olMemFree_impl(void *Address) {
330
329
auto Res =
331
330
Device->Device ->dataDelete (Address, convertOlToPluginAllocTy (Type));
332
331
if (Res)
333
- return {OL_ERRC_OUT_OF_RESOURCES, " Could not free allocation " } ;
332
+ return ol_impl_result_t::fromError ( std::move (Res)) ;
334
333
335
334
allocInfoMap ().erase (Address);
336
335
@@ -342,7 +341,7 @@ ol_impl_result_t olCreateQueue_impl(ol_device_handle_t Device,
342
341
auto CreatedQueue = std::make_unique<ol_queue_impl_t >(nullptr , Device);
343
342
auto Err = Device->Device ->initAsyncInfo (&(CreatedQueue->AsyncInfo ));
344
343
if (Err)
345
- return {OL_ERRC_UNKNOWN, " Could not initialize stream resource " } ;
344
+ return ol_impl_result_t::fromError ( std::move (Err)) ;
346
345
347
346
*Queue = CreatedQueue.release ();
348
347
return OL_SUCCESS;
@@ -358,23 +357,23 @@ ol_impl_result_t olWaitQueue_impl(ol_queue_handle_t Queue) {
358
357
if (Queue->AsyncInfo ->Queue ) {
359
358
auto Err = Queue->Device ->Device ->synchronize (Queue->AsyncInfo );
360
359
if (Err)
361
- return {OL_ERRC_INVALID_QUEUE, " The queue failed to synchronize " } ;
360
+ return ol_impl_result_t::fromError ( std::move (Err)) ;
362
361
}
363
362
364
363
// Recreate the stream resource so the queue can be reused
365
364
// TODO: Would be easier for the synchronization to (optionally) not release
366
365
// it to begin with.
367
366
auto Res = Queue->Device ->Device ->initAsyncInfo (&Queue->AsyncInfo );
368
367
if (Res)
369
- return {OL_ERRC_UNKNOWN, " Could not reinitialize the stream resource " } ;
368
+ return ol_impl_result_t::fromError ( std::move (Res)) ;
370
369
371
370
return OL_SUCCESS;
372
371
}
373
372
374
373
ol_impl_result_t olWaitEvent_impl (ol_event_handle_t Event) {
375
374
auto Res = Event->Queue ->Device ->Device ->syncEvent (Event->EventInfo );
376
375
if (Res)
377
- return {OL_ERRC_INVALID_EVENT, " The event failed to synchronize " } ;
376
+ return ol_impl_result_t::fromError ( std::move (Res)) ;
378
377
379
378
return OL_SUCCESS;
380
379
}
@@ -390,13 +389,17 @@ ol_impl_result_t olDestroyEvent_impl(ol_event_handle_t Event) {
390
389
ol_event_handle_t makeEvent (ol_queue_handle_t Queue) {
391
390
auto EventImpl = std::make_unique<ol_event_impl_t >(nullptr , Queue);
392
391
auto Res = Queue->Device ->Device ->createEvent (&EventImpl->EventInfo );
393
- if (Res)
392
+ if (Res) {
393
+ llvm::consumeError (std::move (Res));
394
394
return nullptr ;
395
+ }
395
396
396
397
Res = Queue->Device ->Device ->recordEvent (EventImpl->EventInfo ,
397
398
Queue->AsyncInfo );
398
- if (Res)
399
+ if (Res) {
400
+ llvm::consumeError (std::move (Res));
399
401
return nullptr ;
402
+ }
400
403
401
404
return EventImpl.release ();
402
405
}
@@ -422,16 +425,16 @@ ol_impl_result_t olMemcpy_impl(ol_queue_handle_t Queue, void *DstPtr,
422
425
if (DstDevice == HostDevice ()) {
423
426
auto Res = SrcDevice->Device ->dataRetrieve (DstPtr, SrcPtr, Size , QueueImpl);
424
427
if (Res)
425
- return {OL_ERRC_UNKNOWN, " The data retrieve operation failed " } ;
428
+ return ol_impl_result_t::fromError ( std::move (Res)) ;
426
429
} else if (SrcDevice == HostDevice ()) {
427
430
auto Res = DstDevice->Device ->dataSubmit (DstPtr, SrcPtr, Size , QueueImpl);
428
431
if (Res)
429
- return {OL_ERRC_UNKNOWN, " The data submit operation failed " } ;
432
+ return ol_impl_result_t::fromError ( std::move (Res)) ;
430
433
} else {
431
434
auto Res = SrcDevice->Device ->dataExchange (SrcPtr, *DstDevice->Device ,
432
435
DstPtr, Size , QueueImpl);
433
436
if (Res)
434
- return {OL_ERRC_UNKNOWN, " The data exchange operation failed " } ;
437
+ return ol_impl_result_t::fromError ( std::move (Res)) ;
435
438
}
436
439
437
440
if (EventOut)
@@ -459,7 +462,7 @@ ol_impl_result_t olCreateProgram_impl(ol_device_handle_t Device,
459
462
Device->Device ->loadBinary (Device->Device ->Plugin , &Prog->DeviceImage );
460
463
if (!Res) {
461
464
delete Prog;
462
- return OL_ERRC_INVALID_VALUE ;
465
+ return ol_impl_result_t::fromError (Res. takeError ()) ;
463
466
}
464
467
465
468
Prog->Image = *Res;
@@ -483,7 +486,7 @@ ol_impl_result_t olGetKernel_impl(ol_program_handle_t Program,
483
486
484
487
auto Err = KernelImpl->init (Device, *Program->Image );
485
488
if (Err)
486
- return {OL_ERRC_UNKNOWN, " Could not initialize the kernel " } ;
489
+ return ol_impl_result_t::fromError ( std::move (Err)) ;
487
490
488
491
*Kernel = &*KernelImpl;
489
492
@@ -526,7 +529,7 @@ olLaunchKernel_impl(ol_queue_handle_t Queue, ol_device_handle_t Device,
526
529
527
530
AsyncInfoWrapper.finalize (Err);
528
531
if (Err)
529
- return {OL_ERRC_UNKNOWN, " Could not finalize the AsyncInfoWrapper " } ;
532
+ return ol_impl_result_t::fromError ( std::move (Err)) ;
530
533
531
534
if (EventOut)
532
535
*EventOut = makeEvent (Queue);
0 commit comments