@@ -24,12 +24,8 @@ Error L0KernelTy::launchImpl(GenericDeviceTy &GenericDevice,
2424 AsyncInfoWrapperTy &AsyncInfoWrapper) const {
2525
2626 auto &l0Device = L0DeviceTy::makeL0Device (GenericDevice);
27- int32_t RC = runTargetTeamRegion (l0Device, KernelArgs,
28- std::move (LaunchParams), AsyncInfoWrapper);
29- if (RC == OFFLOAD_SUCCESS)
30- return Plugin::success ();
31- return Plugin::error (error::ErrorCode::UNKNOWN,
32- " Error in launch Kernel %s: %d" , getName (), RC);
27+ return runTargetTeamRegion (l0Device, KernelArgs, std::move (LaunchParams),
28+ AsyncInfoWrapper);
3329}
3430
3531Error L0KernelTy::buildKernel (L0ProgramTy &Program) {
@@ -222,7 +218,7 @@ static uint64_t computeThreadsNeeded(const llvm::ArrayRef<size_t> TripCounts,
222218 return GroupCount[0 ] * ThreadsPerWG;
223219}
224220
225- int32_t L0KernelTy::decideLoopKernelGroupArguments (
221+ Error L0KernelTy::decideLoopKernelGroupArguments (
226222 L0DeviceTy &Device, uint32_t ThreadLimit, TgtNDRangeDescTy *LoopLevels,
227223 uint32_t *GroupSizes, ze_group_count_t &GroupCounts, bool HalfNumThreads,
228224 bool &AllowCooperative) const {
@@ -282,15 +278,15 @@ int32_t L0KernelTy::decideLoopKernelGroupArguments(
282278 INFO (OMP_INFOTYPE_PLUGIN_KERNEL, DeviceId,
283279 " Invalid number of teams %zu due to large loop trip count\n " ,
284280 DistributeTripCount);
285- return OFFLOAD_FAIL ;
281+ return Plugin::success () ;
286282 }
287283 GRPCounts[DistributeDim] = DistributeTripCount;
288284 }
289285 AllowCooperative = false ;
290286 GroupCounts.groupCountX = GRPCounts[0 ];
291287 GroupCounts.groupCountY = GRPCounts[1 ];
292288 GroupCounts.groupCountZ = GRPCounts[2 ];
293- return OFFLOAD_SUCCESS ;
289+ return Plugin::success () ;
294290 }
295291
296292 if (!MaxGroupSizeForced) {
@@ -355,9 +351,10 @@ int32_t L0KernelTy::decideLoopKernelGroupArguments(
355351 GRPSizes[I] = Trip;
356352 size_t Count = (Trip + GRPSizes[I] - 1 ) / GRPSizes[I];
357353 if (Count > UINT32_MAX) {
358- INFO (OMP_INFOTYPE_PLUGIN_KERNEL, DeviceId,
359- " Invalid number of teams %zu due to large loop trip count\n " , Count);
360- return OFFLOAD_FAIL;
354+ return Plugin::error (ErrorCode::INVALID_ARGUMENT,
355+ " Invalid number of teams %zu due to large loop "
356+ " trip count\n " ,
357+ Count);
361358 }
362359 GRPCounts[I] = (uint32_t )Count;
363360 }
@@ -367,14 +364,13 @@ int32_t L0KernelTy::decideLoopKernelGroupArguments(
367364 GroupCounts.groupCountZ = GRPCounts[2 ];
368365 std::copy (GRPSizes, GRPSizes + 3 , GroupSizes);
369366
370- return OFFLOAD_SUCCESS ;
367+ return Plugin::success () ;
371368}
372369
373- int32_t L0KernelTy::getGroupsShape (L0DeviceTy &Device, int32_t NumTeams,
374- int32_t ThreadLimit, uint32_t *GroupSizes,
375- ze_group_count_t &GroupCounts,
376- void *LoopDesc,
377- bool &AllowCooperative) const {
370+ Error L0KernelTy::getGroupsShape (L0DeviceTy &Device, int32_t NumTeams,
371+ int32_t ThreadLimit, uint32_t *GroupSizes,
372+ ze_group_count_t &GroupCounts, void *LoopDesc,
373+ bool &AllowCooperative) const {
378374
379375 const auto DeviceId = Device.getDeviceId ();
380376 const auto &KernelPR = getProperties ();
@@ -443,13 +439,13 @@ int32_t L0KernelTy::getGroupsShape(L0DeviceTy &Device, int32_t NumTeams,
443439 AllowCooperative = false ;
444440 }
445441
446- return OFFLOAD_SUCCESS ;
442+ return Plugin::success () ;
447443}
448444
449- int32_t L0KernelTy::runTargetTeamRegion (L0DeviceTy &l0Device,
450- KernelArgsTy &KernelArgs,
451- KernelLaunchParamsTy LaunchParams,
452- __tgt_async_info *AsyncInfo) const {
445+ Error L0KernelTy::runTargetTeamRegion (L0DeviceTy &l0Device,
446+ KernelArgsTy &KernelArgs,
447+ KernelLaunchParamsTy LaunchParams,
448+ __tgt_async_info *AsyncInfo) const {
453449 // Libomptarget can pass negative NumTeams and ThreadLimit now after
454450 // introducing __tgt_target_kernel. This happens only when we have valid
455451 // LoopDesc and the region is not a teams region.
@@ -500,13 +496,9 @@ int32_t L0KernelTy::runTargetTeamRegion(L0DeviceTy &l0Device,
500496 GroupSizes, GroupCounts, AllowCooperative);
501497
502498 if (!GroupParamsReused) {
503- auto RC = getGroupsShape (Device, NumTeams, ThreadLimit, GroupSizes,
504- GroupCounts, LoopDesc, AllowCooperative);
505-
506- if (RC != OFFLOAD_SUCCESS) {
507- return RC;
508- }
509-
499+ if (auto Err = getGroupsShape (Device, NumTeams, ThreadLimit, GroupSizes,
500+ GroupCounts, LoopDesc, AllowCooperative))
501+ return Err;
510502 KernelPR.cacheGroupParams (static_cast <TgtNDRangeDescTy *>(LoopDesc),
511503 NumTeams, ThreadLimit, GroupSizes, GroupCounts,
512504 AllowCooperative);
@@ -522,8 +514,8 @@ int32_t L0KernelTy::runTargetTeamRegion(L0DeviceTy &l0Device,
522514 for (int32_t I = 0 ; I < NumArgs; I++) {
523515 {
524516 void *Arg = (static_cast <void **>(LaunchParams.Data ))[I];
525- CALL_ZE_RET_FAIL (zeKernelSetArgumentValue, zeKernel, I, sizeof (Arg),
526- Arg == nullptr ? nullptr : &Arg);
517+ CALL_ZE_RET_ERROR (zeKernelSetArgumentValue, zeKernel, I, sizeof (Arg),
518+ Arg == nullptr ? nullptr : &Arg);
527519 INFO (OMP_INFOTYPE_PLUGIN_KERNEL, DeviceId,
528520 " Kernel Pointer argument %" PRId32 " (value: " DPxMOD
529521 " ) was set successfully for device %s.\n " ,
@@ -540,14 +532,14 @@ int32_t L0KernelTy::runTargetTeamRegion(L0DeviceTy &l0Device,
540532 if (PrevFlags != Flags) {
541533 // Combine with common access flags
542534 const auto FinalFlags = Device.getIndirectFlags () | Flags;
543- CALL_ZE_RET_FAIL (zeKernelSetIndirectAccess, getZeKernel (), FinalFlags);
535+ CALL_ZE_RET_ERROR (zeKernelSetIndirectAccess, getZeKernel (), FinalFlags);
544536 DP (" Setting indirect access flags " DPxMOD " \n " , DPxPTR (FinalFlags));
545537 PrevFlags = Flags;
546538 }
547539
548540 if (!GroupParamsReused) {
549- CALL_ZE_RET_FAIL (zeKernelSetGroupSize, zeKernel, GroupSizes[0 ],
550- GroupSizes[1 ], GroupSizes[2 ]);
541+ CALL_ZE_RET_ERROR (zeKernelSetGroupSize, zeKernel, GroupSizes[0 ],
542+ GroupSizes[1 ], GroupSizes[2 ]);
551543 }
552544
553545 ze_command_list_handle_t CmdList = nullptr ;
@@ -580,36 +572,36 @@ int32_t L0KernelTy::runTargetTeamRegion(L0DeviceTy &l0Device,
580572 INFO (OMP_INFOTYPE_PLUGIN_KERNEL, DeviceId,
581573 " Kernel depends on %zu data copying events.\n " , NumWaitEvents);
582574 if (AllowCooperative)
583- CALL_ZE_RET_FAIL (zeCommandListAppendLaunchCooperativeKernel, CmdList,
584- zeKernel, &GroupCounts, Event, NumWaitEvents,
585- WaitEvents);
575+ CALL_ZE_RET_ERROR (zeCommandListAppendLaunchCooperativeKernel, CmdList,
576+ zeKernel, &GroupCounts, Event, NumWaitEvents,
577+ WaitEvents);
586578 else
587- CALL_ZE_RET_FAIL (zeCommandListAppendLaunchKernel, CmdList, zeKernel,
588- &GroupCounts, Event, NumWaitEvents, WaitEvents);
579+ CALL_ZE_RET_ERROR (zeCommandListAppendLaunchKernel, CmdList, zeKernel,
580+ &GroupCounts, Event, NumWaitEvents, WaitEvents);
589581 KernelLock.unlock ();
590582 if (IsAsync) {
591583 AsyncQueue->WaitEvents .push_back (Event);
592584 AsyncQueue->KernelEvent = Event;
593585 } else {
594- CALL_ZE_RET_FAIL (zeEventHostSynchronize, Event, UINT64_MAX);
586+ CALL_ZE_RET_ERROR (zeEventHostSynchronize, Event, UINT64_MAX);
595587 Device.releaseEvent (Event);
596588 }
597589 } else {
598590 ze_event_handle_t Event = nullptr ;
599591 if (AllowCooperative)
600- CALL_ZE_RET_FAIL (zeCommandListAppendLaunchCooperativeKernel, CmdList,
601- zeKernel, &GroupCounts, Event, 0 , nullptr );
592+ CALL_ZE_RET_ERROR (zeCommandListAppendLaunchCooperativeKernel, CmdList,
593+ zeKernel, &GroupCounts, Event, 0 , nullptr );
602594 else
603- CALL_ZE_RET_FAIL (zeCommandListAppendLaunchKernel, CmdList, zeKernel,
604- &GroupCounts, Event, 0 , nullptr );
595+ CALL_ZE_RET_ERROR (zeCommandListAppendLaunchKernel, CmdList, zeKernel,
596+ &GroupCounts, Event, 0 , nullptr );
605597 KernelLock.unlock ();
606- CALL_ZE_RET_FAIL (zeCommandListClose, CmdList);
607- CALL_ZE_RET_FAIL_MTX (zeCommandQueueExecuteCommandLists, Device.getMutex (),
608- CmdQueue, 1 , &CmdList, nullptr );
598+ CALL_ZE_RET_ERROR (zeCommandListClose, CmdList);
599+ CALL_ZE_RET_ERROR_MTX (zeCommandQueueExecuteCommandLists, Device.getMutex (),
600+ CmdQueue, 1 , &CmdList, nullptr );
609601 INFO (OMP_INFOTYPE_PLUGIN_KERNEL, DeviceId,
610602 " Submitted kernel " DPxMOD " to device %s\n " , DPxPTR (zeKernel), IdStr);
611- CALL_ZE_RET_FAIL (zeCommandQueueSynchronize, CmdQueue, UINT64_MAX);
612- CALL_ZE_RET_FAIL (zeCommandListReset, CmdList);
603+ CALL_ZE_RET_ERROR (zeCommandQueueSynchronize, CmdQueue, UINT64_MAX);
604+ CALL_ZE_RET_ERROR (zeCommandListReset, CmdList);
613605 if (Event) {
614606 Device.releaseEvent (Event);
615607 }
@@ -619,7 +611,7 @@ int32_t L0KernelTy::runTargetTeamRegion(L0DeviceTy &l0Device,
619611 " Executed kernel entry " DPxMOD " on device %s\n " , DPxPTR (zeKernel),
620612 IdStr);
621613
622- return OFFLOAD_SUCCESS ;
614+ return Plugin::success () ;
623615}
624616
625617} // namespace llvm::omp::target::plugin
0 commit comments