1111// ===----------------------------------------------------------------------===//
1212
1313#include " OmptProfiler.h"
14+ #include " OpenMP/OMPT/Interface.h"
1415#include " PluginInterface.h"
1516#include " Shared/Debug.h"
1617
17- void llvm::omp::target::ompt::OmptProfilerTy::handleInit (
18- llvm::omp::target::plugin::GenericDeviceTy *Device,
19- llvm::omp::target::plugin::GenericPluginTy *Plugin) {
18+ using namespace llvm ::omp::target;
19+
20+ void ompt::OmptProfilerTy::handleInit (plugin::GenericDeviceTy *Device,
21+ plugin::GenericPluginTy *Plugin) {
2022 auto DeviceId = Device->getDeviceId ();
2123 auto DevicePtr = reinterpret_cast <ompt_device_t *>(Device);
2224 ompt::setDeviceId (DevicePtr, Plugin->getUserId (DeviceId));
@@ -32,9 +34,8 @@ void llvm::omp::target::ompt::OmptProfilerTy::handleInit(
3234 }
3335}
3436
35- void llvm::omp::target::ompt::OmptProfilerTy::handleDeinit (
36- llvm::omp::target::plugin::GenericDeviceTy *Device,
37- llvm::omp::target::plugin::GenericPluginTy *Plugin) {
37+ void ompt::OmptProfilerTy::handleDeinit (
38+ plugin::GenericDeviceTy *Device, target::plugin::GenericPluginTy *Plugin) {
3839 auto DeviceId = Device->getDeviceId ();
3940
4041 if (ompt::Initialized) {
@@ -45,50 +46,55 @@ void llvm::omp::target::ompt::OmptProfilerTy::handleDeinit(
4546 ompt::removeDeviceId (reinterpret_cast <ompt_device_t *>(Device));
4647}
4748
48- void llvm::omp::target::ompt::OmptProfilerTy::handleLoadBinary (
49- llvm::omp::target::plugin::GenericDeviceTy *Device,
50- llvm::omp::target::plugin::GenericPluginTy *Plugin,
51- const StringRef InputTgtImage) {
52- auto DeviceId = Device->getDeviceId ();
49+ void ompt::OmptProfilerTy::handleLoadBinary (plugin::GenericDeviceTy *Device,
50+ plugin::GenericPluginTy *Plugin,
51+ const StringRef InputTgtImage) {
5352
54- if (ompt::Initialized) {
55- size_t Bytes = InputTgtImage.size ();
56- performOmptCallback (
57- device_load, Plugin->getUserId (DeviceId),
58- /* FileName=*/ nullptr , /* FileOffset=*/ 0 , /* VmaInFile=*/ nullptr ,
59- /* ImgSize=*/ Bytes,
60- /* HostAddr=*/ const_cast <unsigned char *>(InputTgtImage.bytes_begin ()),
61- /* DeviceAddr=*/ nullptr , /* FIXME: ModuleId */ 0 );
62- }
53+ if (!ompt::Initialized)
54+ return ;
55+
56+ auto DeviceId = Device->getDeviceId ();
57+ size_t Bytes = InputTgtImage.size ();
58+ performOmptCallback (
59+ device_load, Plugin->getUserId (DeviceId),
60+ /* FileName=*/ nullptr , /* FileOffset=*/ 0 , /* VmaInFile=*/ nullptr ,
61+ /* ImgSize=*/ Bytes,
62+ /* HostAddr=*/ const_cast <unsigned char *>(InputTgtImage.bytes_begin ()),
63+ /* DeviceAddr=*/ nullptr , /* FIXME: ModuleId */ 0 );
6364}
6465
65- void llvm::omp::target:: ompt::OmptProfilerTy::handleDataAlloc (
66- uint64_t StartNanos, uint64_t EndNanos, void *HostPtr, uint64_t Size ,
67- void *Data) {
66+ void ompt::OmptProfilerTy::handleDataAlloc (uint64_t StartNanos,
67+ uint64_t EndNanos, void *HostPtr,
68+ uint64_t Size, void *Data) {
6869 ompt::setOmptTimestamp (StartNanos, EndNanos);
6970}
7071
71- void llvm::omp::target::ompt::OmptProfilerTy::handleDataDelete (
72- uint64_t StartNanos, uint64_t EndNanos, void *TgtPtr, void *Data) {
72+ void ompt::OmptProfilerTy::handleDataDelete (uint64_t StartNanos,
73+ uint64_t EndNanos, void *TgtPtr,
74+ void *Data) {
7375 ompt::setOmptTimestamp (StartNanos, EndNanos);
7476}
7577
76- void llvm::omp::target:: ompt::OmptProfilerTy::handlePreKernelLaunch (
77- llvm::omp::target:: plugin::GenericDeviceTy *Device, uint32_t NumBlocks[3 ],
78+ void ompt::OmptProfilerTy::handlePreKernelLaunch (
79+ plugin::GenericDeviceTy *Device, uint32_t NumBlocks[3 ],
7880 __tgt_async_info *AI) {
79- OMPT_IF_TRACING_ENABLED (
80- if (llvm::omp::target::ompt::isTracedDevice (getDeviceId (Device))) {
81- if (AI->ProfilerData != nullptr ) {
82- auto ProfilerSpecificData = reinterpret_cast <ompt::OmptEventInfoTy *>(AI->ProfilerData );
83- // Set number of granted teams for OMPT
84- setOmptGrantedNumTeams (NumBlocks[0 ]);
85- ProfilerSpecificData->NumTeams = NumBlocks[0 ];
86- }
87- });
81+ if (!ompt::isTracedDevice (getDeviceId (Device)))
82+ return ;
83+
84+ if (AI->ProfilerData == nullptr )
85+ return ;
86+
87+ auto ProfilerSpecificData =
88+ reinterpret_cast <ompt::OmptEventInfoTy *>(AI->ProfilerData );
89+ assert (ProfilerSpecificData && " Invalid ProfilerSpecificData" );
90+ // Set number of granted teams for OMPT
91+ setOmptGrantedNumTeams (NumBlocks[0 ]);
92+ ProfilerSpecificData->NumTeams = NumBlocks[0 ];
8893}
8994
90- void llvm::omp::target::ompt::OmptProfilerTy::handleKernelCompletion (
91- uint64_t StartNanos, uint64_t EndNanos, void *Data) {
95+ void ompt::OmptProfilerTy::handleKernelCompletion (uint64_t StartNanos,
96+ uint64_t EndNanos,
97+ void *Data) {
9298
9399 if (!isProfilingEnabled ())
94100 return ;
@@ -98,24 +104,24 @@ void llvm::omp::target::ompt::OmptProfilerTy::handleKernelCompletion(
98104 if (!Data)
99105 return ;
100106
101- DP (" OMPT-Async: Time kernel for asynchronous execution (Plugin) : Start %lu "
107+ DP (" OMPT-Async: Time kernel for asynchronous execution: Start %lu "
102108 " End %lu\n " ,
103109 StartNanos, EndNanos);
104110
105111 auto OmptEventInfo = reinterpret_cast <ompt::OmptEventInfoTy *>(Data);
106112 assert (OmptEventInfo && " Invalid OmptEventInfo" );
107113 assert (OmptEventInfo->TraceRecord && " Invalid TraceRecord" );
108114
109- llvm::omp::target:: ompt::RegionInterface.stopTargetSubmitTraceAsync (
110- OmptEventInfo-> TraceRecord , OmptEventInfo->NumTeams , StartNanos ,
111- EndNanos);
115+ ompt::RegionInterface.stopTargetSubmitTraceAsync (OmptEventInfo-> TraceRecord ,
116+ OmptEventInfo->NumTeams ,
117+ StartNanos, EndNanos);
112118
113119 // Done processing, our responsibility to free the memory
114120 freeProfilerDataEntry (OmptEventInfo);
115121}
116122
117- void llvm::omp::target:: ompt::OmptProfilerTy::handleDataTransfer (
118- uint64_t StartNanos, uint64_t EndNanos, void *Data) {
123+ void ompt::OmptProfilerTy::handleDataTransfer (uint64_t StartNanos,
124+ uint64_t EndNanos, void *Data) {
119125
120126 if (!isProfilingEnabled ())
121127 return ;
@@ -125,23 +131,25 @@ void llvm::omp::target::ompt::OmptProfilerTy::handleDataTransfer(
125131 if (!Data)
126132 return ;
127133
134+ DP (" OMPT-Async: Time data for asynchronous execution: Start %lu "
135+ " End %lu\n " ,
136+ StartNanos, EndNanos);
137+
128138 auto OmptEventInfo = reinterpret_cast <ompt::OmptEventInfoTy *>(Data);
129139 assert (OmptEventInfo && " Invalid OmptEventInfo" );
130140 assert (OmptEventInfo->TraceRecord && " Invalid TraceRecord" );
131141
132- llvm::omp::target:: ompt::RegionInterface.stopTargetDataMovementTraceAsync (
142+ ompt::RegionInterface.stopTargetDataMovementTraceAsync (
133143 OmptEventInfo->TraceRecord , StartNanos, EndNanos);
134144
135145 // Done processing, our responsibility to free the memory
136146 freeProfilerDataEntry (OmptEventInfo);
137147}
138148
139- bool llvm::omp::target::ompt::OmptProfilerTy::isProfilingEnabled () {
140- return llvm::omp::target::ompt::TracingActive;
141- }
149+ bool ompt::OmptProfilerTy::isProfilingEnabled () { return ompt::TracingActive; }
142150
143- void llvm::omp::target:: ompt::OmptProfilerTy::setTimeConversionFactorsImpl (
144- double Slope, double Offset) {
151+ void ompt::OmptProfilerTy::setTimeConversionFactorsImpl (double Slope,
152+ double Offset) {
145153 DP (" Using Time Slope: %f and Offset: %f \n " , Slope, Offset);
146154 setOmptHostToDeviceRate (Slope, Offset);
147155}
0 commit comments