@@ -405,8 +405,11 @@ void MemAllocatorTy::updateMaxAllocSize(L0DeviceTy &L0Device) {
405405void MemAllocatorTy::deinit () {
406406 std::lock_guard<std::mutex> Lock (Mtx);
407407 // Release RTL-owned memory
408- for (auto *M : MemOwned)
409- dealloc_locked (M);
408+ for (auto *M : MemOwned) {
409+ auto Err = dealloc_locked (M);
410+ if (Err)
411+ consumeError (std::move (Err));
412+ }
410413 // Release resources used in the pool
411414 Pools.clear ();
412415 ReductionPool.reset (nullptr );
@@ -436,9 +439,10 @@ void MemAllocatorTy::deinit() {
436439}
437440
438441// / Allocate memory with the specified information
439- void *MemAllocatorTy::alloc (size_t Size, size_t Align, int32_t Kind,
440- intptr_t Offset, bool UserAlloc, bool DevMalloc,
441- uint32_t MemAdvice, AllocOptionTy AllocOpt) {
442+ Expected<void *> MemAllocatorTy::alloc (size_t Size, size_t Align, int32_t Kind,
443+ intptr_t Offset, bool UserAlloc,
444+ bool DevMalloc, uint32_t MemAdvice,
445+ AllocOptionTy AllocOpt) {
442446 assert ((Kind == TARGET_ALLOC_DEVICE || Kind == TARGET_ALLOC_HOST ||
443447 Kind == TARGET_ALLOC_SHARED) &&
444448 " Unknown memory kind while allocating target memory" );
@@ -503,12 +507,13 @@ void *MemAllocatorTy::alloc(size_t Size, size_t Align, int32_t Kind,
503507}
504508
505509// / Deallocate memory
506- int32_t MemAllocatorTy::dealloc_locked (void *Ptr) {
510+ Error MemAllocatorTy::dealloc_locked (void *Ptr) {
507511 MemAllocInfoTy Info;
508512 if (!AllocInfo.remove (Ptr, &Info)) {
509- DP (" Error: Cannot find memory allocation information for " DPxMOD " \n " ,
510- DPxPTR (Ptr));
511- return OFFLOAD_FAIL;
513+ return Plugin::error (ErrorCode::BACKEND_FAILURE,
514+ " Cannot find memory allocation information for " DPxMOD
515+ " \n " ,
516+ DPxPTR (Ptr));
512517 }
513518 if (Info.InPool ) {
514519 size_t DeallocSize = 0 ;
@@ -521,24 +526,27 @@ int32_t MemAllocatorTy::dealloc_locked(void *Ptr) {
521526 if (DeallocSize == 0 )
522527 DeallocSize = CounterPool->dealloc (Info.Base );
523528 if (DeallocSize == 0 ) {
524- DP (" Error: Cannot return memory " DPxMOD " to pool\n " , DPxPTR (Ptr));
525- return OFFLOAD_FAIL;
529+ return Plugin::error (ErrorCode::BACKEND_FAILURE,
530+ " Cannot return memory " DPxMOD " to pool\n " ,
531+ DPxPTR (Ptr));
526532 }
527533 }
528534 log (0 , DeallocSize, Info.Kind , true /* Pool */ );
529- return OFFLOAD_SUCCESS ;
535+ return Plugin::success () ;
530536 }
531537 if (!Info.Base ) {
532538 DP (" Error: Cannot find base address of " DPxMOD " \n " , DPxPTR (Ptr));
533- return OFFLOAD_FAIL;
539+ return Plugin::error (ErrorCode::INVALID_ARGUMENT,
540+ " Cannot find base address of " DPxMOD " \n " ,
541+ DPxPTR (Ptr));
534542 }
535- CALL_ZE_RET_FAIL (zeMemFree, L0Context->getZeContext (), Info.Base );
543+ CALL_ZE_RET_ERROR (zeMemFree, L0Context->getZeContext (), Info.Base );
536544 log (0 , Info.Size , Info.Kind );
537545
538546 DP (" Deleted device memory " DPxMOD " (Base: " DPxMOD " , Size: %zu)\n " ,
539547 DPxPTR (Ptr), DPxPTR (Info.Base ), Info.Size );
540548
541- return OFFLOAD_SUCCESS ;
549+ return Plugin::success () ;
542550}
543551
544552int32_t MemAllocatorTy::enqueueMemCopy (void *Dst, const void *Src,
0 commit comments