@@ -36,19 +36,24 @@ void *alignedAllocHost(size_t Alignment, size_t Size, const sycl::context &Ctxt,
3636#ifdef XPTI_ENABLE_INSTRUMENTATION
3737 // Stash the code location information and propagate
3838 sycl::detail::tls_code_loc_t CL (CodeLoc);
39- sycl::detail::XPTIScope PrepareNotify (
40- (void *)alignedAllocHost, (uint16_t )xpti::trace_point_type_t ::node_create,
41- sycl::detail::SYCL_MEM_ALLOC_STREAM_NAME, " malloc_host" );
42- PrepareNotify.addMetadata ([&](auto TEvent) {
39+ const char *UserData = " malloc_host" ;
40+
41+ xpti::framework::tracepoint_scope_t TP (CodeLoc.fileName , CodeLoc.functionName ,
42+ CodeLoc.lineNo , CodeLoc.columnNo ,
43+ nullptr );
44+ TP.stream (detail::GMemAllocStreamID)
45+ .traceType (xpti::trace_point_type_t ::node_create)
46+ .parentEvent (detail::GSYCLGraphEvent);
47+ TP.addMetadata ([&](auto TEvent) {
4348 xpti::addMetadata (TEvent, " sycl_device_name" , std::string (" Host" ));
4449 xpti::addMetadata (TEvent, " sycl_device" , 0 );
4550 xpti::addMetadata (TEvent, " memory_size" , Size);
4651 });
47- // Notify XPTI about the memset submission
48- PrepareNotify .notify ();
52+ // Notify XPTI about the allocation submission
53+ TP .notify (UserData );
4954 // Emit a begin/end scope for this call
50- PrepareNotify .scopedNotify (
51- ( uint16_t )xpti:: trace_point_type_t ::mem_alloc_begin );
55+ TP .scopedNotify (( uint16_t )xpti:: trace_point_type_t ::mem_alloc_begin,
56+ UserData );
5257#endif
5358 const auto &devices = Ctxt.get_devices ();
5459 if (!std::any_of (devices.begin (), devices.end (), [&](const auto &device) {
@@ -91,7 +96,9 @@ void *alignedAllocHost(size_t Alignment, size_t Size, const sycl::context &Ctxt,
9196 if (Error != UR_RESULT_SUCCESS)
9297 return nullptr ;
9398#ifdef XPTI_ENABLE_INSTRUMENTATION
94- xpti::addMetadata (PrepareNotify.traceEvent (), " memory_ptr" ,
99+ // Once the allocation is complete, update metadata with the memory pointer
100+ // before the mem_alloc_end event is sent
101+ xpti::addMetadata (TP.traceEvent (), " memory_ptr" ,
95102 reinterpret_cast <size_t >(RetVal));
96103#endif
97104 return RetVal;
@@ -215,27 +222,34 @@ void *alignedAlloc(size_t Alignment, size_t Size, const context &Ctxt,
215222#ifdef XPTI_ENABLE_INSTRUMENTATION
216223 // Stash the code location information and propagate
217224 detail::tls_code_loc_t CL (CodeLoc);
218- XPTIScope PrepareNotify ((void *)alignedAlloc,
219- (uint16_t )xpti::trace_point_type_t ::node_create,
220- SYCL_MEM_ALLOC_STREAM_NAME, " usm::alignedAlloc" );
221- PrepareNotify.addMetadata ([&](auto TEvent) {
225+ const char *UserData = " usm::alignedAlloc" ;
226+
227+ xpti::framework::tracepoint_scope_t TP (CodeLoc.fileName , CodeLoc.functionName ,
228+ CodeLoc.lineNo , CodeLoc.columnNo ,
229+ nullptr );
230+ TP.stream (detail::GMemAllocStreamID)
231+ .traceType (xpti::trace_point_type_t ::node_create)
232+ .parentEvent (detail::GSYCLGraphEvent);
233+ TP.addMetadata ([&](auto TEvent) {
222234 xpti::addMetadata (TEvent, " sycl_device_name" ,
223235 Dev.get_info <info::device::name>());
224236 // Need to determine how to get the device handle reference
225237 // xpti::addMetadata(TEvent, "sycl_device", Dev.getHandleRef()));
226238 xpti::addMetadata (TEvent, " memory_size" , Size);
227239 });
228- // Notify XPTI about the memset submission
229- PrepareNotify .notify ();
240+ // Notify XPTI about the allocation submission
241+ TP .notify (UserData );
230242 // Emit a begin/end scope for this call
231- PrepareNotify .scopedNotify (
232- ( uint16_t )xpti:: trace_point_type_t ::mem_alloc_begin );
243+ TP .scopedNotify (( uint16_t )xpti:: trace_point_type_t ::mem_alloc_begin,
244+ UserData );
233245#endif
234246 void *RetVal =
235247 alignedAllocInternal (Alignment, Size, getSyclObjImpl (Ctxt).get (),
236248 getSyclObjImpl (Dev).get (), Kind, PropList);
237249#ifdef XPTI_ENABLE_INSTRUMENTATION
238- xpti::addMetadata (PrepareNotify.traceEvent (), " memory_ptr" ,
250+ // Once the allocation is complete, update metadata with the memory pointer
251+ // before the mem_alloc_end event is sent
252+ xpti::addMetadata (TP.traceEvent (), " memory_ptr" ,
239253 reinterpret_cast <size_t >(RetVal));
240254#endif
241255 return RetVal;
@@ -254,17 +268,22 @@ void free(void *Ptr, const context &Ctxt,
254268#ifdef XPTI_ENABLE_INSTRUMENTATION
255269 // Stash the code location information and propagate
256270 detail::tls_code_loc_t CL (CodeLoc);
257- XPTIScope PrepareNotify ((void *)free,
258- (uint16_t )xpti::trace_point_type_t ::node_create,
259- SYCL_MEM_ALLOC_STREAM_NAME, " usm::free" );
260- PrepareNotify.addMetadata ([&](auto TEvent) {
271+ const char *UserData = " usm::free" ;
272+
273+ xpti::framework::tracepoint_scope_t TP (CodeLoc.fileName , CodeLoc.functionName ,
274+ CodeLoc.lineNo , CodeLoc.columnNo ,
275+ nullptr );
276+ TP.stream (detail::GMemAllocStreamID)
277+ .traceType (xpti::trace_point_type_t ::node_create)
278+ .parentEvent (detail::GSYCLGraphEvent);
279+ TP.addMetadata ([&](auto TEvent) {
261280 xpti::addMetadata (TEvent, " memory_ptr" , reinterpret_cast <size_t >(Ptr));
262281 });
263282 // Notify XPTI about the memset submission
264- PrepareNotify .notify ();
283+ TP .notify (UserData );
265284 // Emit a begin/end scope for this call
266- PrepareNotify .scopedNotify (
267- ( uint16_t )xpti:: trace_point_type_t ::mem_release_begin );
285+ TP .scopedNotify (( uint16_t )xpti:: trace_point_type_t ::mem_release_begin,
286+ UserData );
268287#endif
269288 freeInternal (Ptr, detail::getSyclObjImpl (Ctxt).get ());
270289}
0 commit comments