@@ -308,9 +308,11 @@ ol_impl_result_t olMemAlloc_impl(ol_device_handle_t Device,
308308 void **AllocationOut) {
309309 auto Alloc =
310310 Device->Device ->dataAlloc (Size, nullptr , convertOlToPluginAllocTy (Type));
311- if (!Alloc)
311+ if (!Alloc) {
312+ llvm::consumeError (Alloc.takeError ());
312313 return {OL_ERRC_OUT_OF_RESOURCES,
313314 formatv (" Could not create allocation on device {0}" , Device).str ()};
315+ }
314316
315317 *AllocationOut = *Alloc;
316318 allocInfoMap ().insert_or_assign (*Alloc, AllocInfo{Device, Type});
@@ -327,8 +329,10 @@ ol_impl_result_t olMemFree_impl(void *Address) {
327329
328330 auto Res =
329331 Device->Device ->dataDelete (Address, convertOlToPluginAllocTy (Type));
330- if (Res)
332+ if (Res) {
333+ llvm::consumeError (std::move (Res));
331334 return {OL_ERRC_OUT_OF_RESOURCES, " Could not free allocation" };
335+ }
332336
333337 allocInfoMap ().erase (Address);
334338
@@ -340,7 +344,7 @@ ol_impl_result_t olCreateQueue_impl(ol_device_handle_t Device,
340344 auto CreatedQueue = std::make_unique<ol_queue_impl_t >(nullptr , Device);
341345 auto Err = Device->Device ->initAsyncInfo (&(CreatedQueue->AsyncInfo ));
342346 if (Err)
343- return {OL_ERRC_UNKNOWN , " Could not initialize stream resource" };
347+ return {std::move (Err) , " Could not initialize stream resource" };
344348
345349 *Queue = CreatedQueue.release ();
346350 return OL_SUCCESS;
@@ -355,24 +359,28 @@ ol_impl_result_t olWaitQueue_impl(ol_queue_handle_t Queue) {
355359 // on it, but we have nothing to synchronize in that situation anyway.
356360 if (Queue->AsyncInfo ->Queue ) {
357361 auto Err = Queue->Device ->Device ->synchronize (Queue->AsyncInfo );
358- if (Err)
362+ if (Err) {
363+ llvm::consumeError (std::move (Err));
359364 return {OL_ERRC_INVALID_QUEUE, " The queue failed to synchronize" };
365+ }
360366 }
361367
362368 // Recreate the stream resource so the queue can be reused
363369 // TODO: Would be easier for the synchronization to (optionally) not release
364370 // it to begin with.
365371 auto Res = Queue->Device ->Device ->initAsyncInfo (&Queue->AsyncInfo );
366372 if (Res)
367- return {OL_ERRC_UNKNOWN , " Could not reinitialize the stream resource" };
373+ return {std::move (Res) , " Could not reinitialize the stream resource" };
368374
369375 return OL_SUCCESS;
370376}
371377
372378ol_impl_result_t olWaitEvent_impl (ol_event_handle_t Event) {
373379 auto Res = Event->Queue ->Device ->Device ->syncEvent (Event->EventInfo );
374- if (Res)
380+ if (Res) {
381+ llvm::consumeError (std::move (Res));
375382 return {OL_ERRC_INVALID_EVENT, " The event failed to synchronize" };
383+ }
376384
377385 return OL_SUCCESS;
378386}
@@ -384,13 +392,17 @@ ol_impl_result_t olDestroyEvent_impl(ol_event_handle_t Event) {
384392ol_event_handle_t makeEvent (ol_queue_handle_t Queue) {
385393 auto EventImpl = std::make_unique<ol_event_impl_t >(nullptr , Queue);
386394 auto Res = Queue->Device ->Device ->createEvent (&EventImpl->EventInfo );
387- if (Res)
395+ if (Res) {
396+ llvm::consumeError (std::move (Res));
388397 return nullptr ;
398+ }
389399
390400 Res = Queue->Device ->Device ->recordEvent (EventImpl->EventInfo ,
391401 Queue->AsyncInfo );
392- if (Res)
402+ if (Res) {
403+ llvm::consumeError (std::move (Res));
393404 return nullptr ;
405+ }
394406
395407 return EventImpl.release ();
396408}
@@ -416,16 +428,16 @@ ol_impl_result_t olMemcpy_impl(ol_queue_handle_t Queue, void *DstPtr,
416428 if (DstDevice == HostDevice ()) {
417429 auto Res = SrcDevice->Device ->dataRetrieve (DstPtr, SrcPtr, Size, QueueImpl);
418430 if (Res)
419- return {OL_ERRC_UNKNOWN , " The data retrieve operation failed" };
431+ return {std::move (Res) , " The data retrieve operation failed" };
420432 } else if (SrcDevice == HostDevice ()) {
421433 auto Res = DstDevice->Device ->dataSubmit (DstPtr, SrcPtr, Size, QueueImpl);
422434 if (Res)
423- return {OL_ERRC_UNKNOWN , " The data submit operation failed" };
435+ return {std::move (Res) , " The data submit operation failed" };
424436 } else {
425437 auto Res = SrcDevice->Device ->dataExchange (SrcPtr, *DstDevice->Device ,
426438 DstPtr, Size, QueueImpl);
427439 if (Res)
428- return {OL_ERRC_UNKNOWN , " The data exchange operation failed" };
440+ return {std::move (Res) , " The data exchange operation failed" };
429441 }
430442
431443 if (EventOut)
@@ -452,6 +464,7 @@ ol_impl_result_t olCreateProgram_impl(ol_device_handle_t Device,
452464 auto Res =
453465 Device->Device ->loadBinary (Device->Device ->Plugin , &Prog->DeviceImage );
454466 if (!Res) {
467+ llvm::consumeError (Res.takeError ());
455468 delete Prog;
456469 return OL_ERRC_INVALID_VALUE;
457470 }
@@ -477,7 +490,7 @@ ol_impl_result_t olGetKernel_impl(ol_program_handle_t Program,
477490
478491 auto Err = KernelImpl->init (Device, *Program->Image );
479492 if (Err)
480- return {OL_ERRC_UNKNOWN , " Could not initialize the kernel" };
493+ return {std::move (Err) , " Could not initialize the kernel" };
481494
482495 *Kernel = &*KernelImpl;
483496
@@ -520,7 +533,7 @@ olLaunchKernel_impl(ol_queue_handle_t Queue, ol_device_handle_t Device,
520533
521534 AsyncInfoWrapper.finalize (Err);
522535 if (Err)
523- return {OL_ERRC_UNKNOWN , " Could not finalize the AsyncInfoWrapper" };
536+ return {std::move (Err) , " Could not finalize the AsyncInfoWrapper" };
524537
525538 if (EventOut)
526539 *EventOut = makeEvent (Queue);
0 commit comments