2525#include " Utils/ExponentialBackoff.h"
2626
2727#include " llvm/Frontend/OpenMP/OMPConstants.h"
28+ #include " llvm/Support/Format.h"
2829
2930#include < cassert>
3031#include < cstdint>
3536#ifdef OMPT_SUPPORT
3637using namespace llvm ::omp::target::ompt;
3738#endif
39+ using namespace llvm ::omp::target::debug;
3840
3941// If offload is enabled, ensure that device DeviceID has been initialized.
4042//
@@ -49,25 +51,25 @@ using namespace llvm::omp::target::ompt;
4951// This step might be skipped if offload is disabled.
5052bool checkDevice (int64_t &DeviceID, ident_t *Loc) {
5153 if (OffloadPolicy::get (*PM).Kind == OffloadPolicy::DISABLED) {
52- DP ( " Offload is disabled\n " ) ;
54+ ODBG (ODT_Device) << " Offload is disabled" ;
5355 return true ;
5456 }
5557
5658 if (DeviceID == OFFLOAD_DEVICE_DEFAULT) {
5759 DeviceID = omp_get_default_device ();
58- DP ( " Use default device id % " PRId64 " \n " , DeviceID) ;
60+ ODBG (ODT_Device) << " Use default device id " << DeviceID;
5961 }
6062
6163 // Proposed behavior for OpenMP 5.2 in OpenMP spec github issue 2669.
6264 if (omp_get_num_devices () == 0 ) {
63- DP ( " omp_get_num_devices() == 0 but offload is manadatory\n " ) ;
65+ ODBG (ODT_Device) << " omp_get_num_devices() == 0 but offload is manadatory" ;
6466 handleTargetOutcome (false , Loc);
6567 return true ;
6668 }
6769
6870 if (DeviceID == omp_get_initial_device ()) {
69- DP ( " Device is host (% " PRId64 " ), returning as if offload is disabled \n " ,
70- DeviceID) ;
71+ ODBG (ODT_Device) << " Device is host (" << DeviceID
72+ << " ), returning as if offload is disabled " ;
7173 return true ;
7274 }
7375 return false ;
@@ -123,25 +125,25 @@ targetData(ident_t *Loc, int64_t DeviceId, int32_t ArgNum, void **ArgsBase,
123125 TIMESCOPE_WITH_DETAILS_AND_IDENT (" Runtime: Data Copy" ,
124126 " NumArgs=" + std::to_string (ArgNum), Loc);
125127
126- DP ( " Entering data %s region for device % " PRId64 " with %d mappings \n " ,
127- RegionName, DeviceId, ArgNum) ;
128+ ODBG (ODT_Interface) << " Entering data " << RegionName << " region for device "
129+ << DeviceId << " with " << ArgNum << " mappings " ;
128130
129131 if (checkDevice (DeviceId, Loc)) {
130- DP ( " Not offloading to device % " PRId64 " \n " , DeviceId) ;
132+ ODBG (ODT_Interface) << " Not offloading to device " << DeviceId;
131133 return ;
132134 }
133135
134136 if (getInfoLevel () & OMP_INFOTYPE_KERNEL_ARGS)
135137 printKernelArguments (Loc, DeviceId, ArgNum, ArgSizes, ArgTypes, ArgNames,
136138 RegionTypeMsg);
137- # ifdef OMPTARGET_DEBUG
138- for (int I = 0 ; I < ArgNum; ++I) {
139- DP ( " Entry %2d: Base= " DPxMOD " , Begin= " DPxMOD " , Size=% " PRId64
140- " , Type=0x% " PRIx64 " , Name=%s \n " ,
141- I, DPxPTR (ArgsBase [I]), DPxPTR (Args[I]), ArgSizes[I], ArgTypes[I],
142- ( ArgNames) ? getNameFromMapping (ArgNames[I]). c_str () : " unknown" );
143- }
144- # endif
139+ ODBG_OS (ODT_Kernel, [&](llvm::raw_ostream &Os) {
140+ for (int I = 0 ; I < ArgNum; ++I) {
141+ Os << " Entry " << llvm::format_decimal (I, 2 ) << " : Base= " << ArgsBase[I]
142+ << " , Begin= " << Args[I] << " , Size= " << ArgSizes[I]
143+ << " , Type= " << llvm::format_hex (ArgTypes [I], 8 ) << " , Name= "
144+ << (( ArgNames) ? getNameFromMapping (ArgNames[I]) : " unknown" ) << " \n " ;
145+ }
146+ });
145147
146148 auto DeviceOrErr = PM->getDevice (DeviceId);
147149 if (!DeviceOrErr)
@@ -274,7 +276,7 @@ static KernelArgsTy *upgradeKernelArgs(KernelArgsTy *KernelArgs,
274276 KernelArgsTy &LocalKernelArgs,
275277 int32_t NumTeams, int32_t ThreadLimit) {
276278 if (KernelArgs->Version > OMP_KERNEL_ARG_VERSION)
277- DP ( " Unexpected ABI version: %u \n " , KernelArgs->Version ) ;
279+ ODBG (ODT_Interface) << " Unexpected ABI version: " << KernelArgs->Version ;
278280
279281 uint32_t UpgradedVersion = KernelArgs->Version ;
280282 if (KernelArgs->Version < OMP_KERNEL_ARG_VERSION) {
@@ -326,12 +328,11 @@ static inline int targetKernel(ident_t *Loc, int64_t DeviceId, int32_t NumTeams,
326328 assert (PM && " Runtime not initialized" );
327329 static_assert (std::is_convertible_v<TargetAsyncInfoTy &, AsyncInfoTy &>,
328330 " Target AsyncInfoTy must be convertible to AsyncInfoTy." );
329- DP (" Entering target region for device %" PRId64 " with entry point " DPxMOD
330- " \n " ,
331- DeviceId, DPxPTR (HostPtr));
331+ ODBG (ODT_Interface) << " Entering target region for device " << DeviceId
332+ << " with entry point " << HostPtr;
332333
333334 if (checkDevice (DeviceId, Loc)) {
334- DP ( " Not offloading to device % " PRId64 " \n " , DeviceId) ;
335+ ODBG (ODT_Interface) << " Not offloading to device " << DeviceId;
335336 return OMP_TGT_FAIL;
336337 }
337338
@@ -354,17 +355,21 @@ static inline int targetKernel(ident_t *Loc, int64_t DeviceId, int32_t NumTeams,
354355 printKernelArguments (Loc, DeviceId, KernelArgs->NumArgs ,
355356 KernelArgs->ArgSizes , KernelArgs->ArgTypes ,
356357 KernelArgs->ArgNames , " Entering OpenMP kernel" );
357- #ifdef OMPTARGET_DEBUG
358- for (uint32_t I = 0 ; I < KernelArgs->NumArgs ; ++I) {
359- DP (" Entry %2d: Base=" DPxMOD " , Begin=" DPxMOD " , Size=%" PRId64
360- " , Type=0x%" PRIx64 " , Name=%s\n " ,
361- I, DPxPTR (KernelArgs->ArgBasePtrs [I]), DPxPTR (KernelArgs->ArgPtrs [I]),
362- KernelArgs->ArgSizes [I], KernelArgs->ArgTypes [I],
363- (KernelArgs->ArgNames )
364- ? getNameFromMapping (KernelArgs->ArgNames [I]).c_str ()
365- : " unknown" );
366- }
367- #endif
358+
359+ ODBG_OS (ODT_Kernel, [&](llvm::raw_ostream &Os) {
360+ for (uint32_t I = 0 ; I < KernelArgs->NumArgs ; ++I) {
361+ Os << " Entry " << llvm::format_decimal (I, 2 )
362+ << " Base=" << KernelArgs->ArgBasePtrs [I]
363+ << " , Begin=" << KernelArgs->ArgPtrs [I]
364+ << " , Size=" << KernelArgs->ArgSizes [I]
365+ << " , Type=" << llvm::format_hex (KernelArgs->ArgTypes [I], 8 )
366+ << " , Name="
367+ << (KernelArgs->ArgNames
368+ ? getNameFromMapping (KernelArgs->ArgNames [I]).c_str ()
369+ : " unknown" )
370+ << " \n " ;
371+ }
372+ });
368373
369374 auto DeviceOrErr = PM->getDevice (DeviceId);
370375 if (!DeviceOrErr)
@@ -463,7 +468,7 @@ EXTERN int __tgt_target_kernel_replay(ident_t *Loc, int64_t DeviceId,
463468 assert (PM && " Runtime not initialized" );
464469 OMPT_IF_BUILT (ReturnAddressSetterRAII RA (__builtin_return_address (0 )));
465470 if (checkDevice (DeviceId, Loc)) {
466- DP ( " Not offloading to device % " PRId64 " \n " , DeviceId) ;
471+ ODBG (ODT_Interface) << " Not offloading to device " << DeviceId;
467472 return OMP_TGT_FAIL;
468473 }
469474 auto DeviceOrErr = PM->getDevice (DeviceId);
@@ -491,20 +496,20 @@ EXTERN int __tgt_target_kernel_replay(ident_t *Loc, int64_t DeviceId,
491496EXTERN int64_t __tgt_mapper_num_components (void *RtMapperHandle) {
492497 auto *MapperComponentsPtr = (struct MapperComponentsTy *)RtMapperHandle;
493498 int64_t Size = MapperComponentsPtr->Components .size ();
494- DP ( " __tgt_mapper_num_components(Handle=" DPxMOD " ) returns % " PRId64 " \n " ,
495- DPxPTR (RtMapperHandle), Size) ;
499+ ODBG (ODT_Interface) << " __tgt_mapper_num_components(Handle=" << RtMapperHandle
500+ << " ) returns " << Size;
496501 return Size;
497502}
498503
499504// Push back one component for a user-defined mapper.
500505EXTERN void __tgt_push_mapper_component (void *RtMapperHandle, void *Base,
501506 void *Begin, int64_t Size, int64_t Type,
502507 void *Name) {
503- DP ( " __tgt_push_mapper_component(Handle=" DPxMOD
504- " ) adds an entry (Base=" DPxMOD " , Begin= " DPxMOD " , Size=% " PRId64
505- " , Type=0x% " PRIx64 " , Name=%s). \n " ,
506- DPxPTR (RtMapperHandle), DPxPTR (Base), DPxPTR (Begin), Size, Type,
507- ( Name) ? getNameFromMapping (Name). c_str () : " unknown" );
508+ ODBG (ODT_Interface) << " __tgt_push_mapper_component(Handle=" << RtMapperHandle
509+ << " ) adds an entry (Base=" << Base << " , Begin= " << Begin
510+ << " , Size= " << Size
511+ << " , Type= " << llvm::format_hex (Type, 8 ) << " , Name= "
512+ << (( Name) ? getNameFromMapping (Name) : " unknown" ) << " ) " ;
508513 auto *MapperComponentsPtr = (struct MapperComponentsTy *)RtMapperHandle;
509514 MapperComponentsPtr->Components .push_back (
510515 MapComponentInfoTy (Base, Begin, Size, Type, Name));
0 commit comments