24 #ifdef XPTI_ENABLE_INSTRUMENTATION
27 #include "xpti/xpti_trace_framework.hpp"
32 inline namespace _V1 {
37 #ifdef XPTI_ENABLE_INSTRUMENTATION
38 extern xpti::trace_event_data_t *GSYCLGraphEvent;
45 #ifdef XPTI_ENABLE_INSTRUMENTATION
49 (uint16_t)xpti::trace_point_type_t::node_create,
51 PrepareNotify.addMetadata([&](
auto TEvent) {
52 xpti::addMetadata(TEvent,
"sycl_device_name", std::string(
"Host"));
53 xpti::addMetadata(TEvent,
"sycl_device", 0);
54 xpti::addMetadata(TEvent,
"memory_size", Size);
57 PrepareNotify.notify();
59 PrepareNotify.scopedNotify(
60 (uint16_t)xpti::trace_point_type_t::mem_alloc_begin);
62 void *RetVal =
nullptr;
67 if (CtxImpl->is_host()) {
76 }
catch (
const std::bad_alloc &) {
82 const PluginPtr &Plugin = CtxImpl->getPlugin();
87 std::array<pi_usm_mem_properties, 3> Props;
88 auto PropsIter = Props.begin();
90 if (PropList.
has_property<sycl::ext::intel::experimental::property::usm::
93 "cl_intel_mem_alloc_buffer_location")) {
95 *PropsIter++ = PropList
98 .get_buffer_location();
101 assert(PropsIter >= Props.begin() && PropsIter < Props.end());
105 &RetVal, C, Props.data(), Size,
Alignment);
111 case alloc::unknown: {
113 Error = PI_ERROR_INVALID_VALUE;
120 if (Error != PI_SUCCESS)
123 #ifdef XPTI_ENABLE_INSTRUMENTATION
124 xpti::addMetadata(PrepareNotify.traceEvent(),
"memory_ptr",
125 reinterpret_cast<size_t>(RetVal));
134 void *RetVal =
nullptr;
139 if (Kind == alloc::unknown) {
150 }
catch (
const std::bad_alloc &) {
162 case alloc::device: {
165 std::array<pi_usm_mem_properties, 3> Props;
166 auto PropsIter = Props.begin();
169 if (PropList.
has_property<sycl::ext::intel::experimental::property::usm::
171 DevImpl->
has_extension(
"cl_intel_mem_alloc_buffer_location")) {
173 *PropsIter++ = PropList
176 .get_buffer_location();
179 assert(PropsIter >= Props.begin() && PropsIter < Props.end());
183 &RetVal, C, Id, Props.data(), Size,
Alignment);
187 case alloc::shared: {
190 std::array<pi_usm_mem_properties, 5> Props;
191 auto PropsIter = Props.begin();
199 if (PropList.
has_property<sycl::ext::intel::experimental::property::usm::
201 DevImpl->
has_extension(
"cl_intel_mem_alloc_buffer_location")) {
203 *PropsIter++ = PropList
206 .get_buffer_location();
209 assert(PropsIter >= Props.begin() && PropsIter < Props.end());
213 &RetVal, C, Id, Props.data(), Size,
Alignment);
218 case alloc::unknown: {
220 Error = PI_ERROR_INVALID_VALUE;
227 if (Error != PI_SUCCESS)
236 #ifdef XPTI_ENABLE_INSTRUMENTATION
240 (uint16_t)xpti::trace_point_type_t::node_create,
242 PrepareNotify.addMetadata([&](
auto TEvent) {
243 xpti::addMetadata(TEvent,
"sycl_device_name",
244 Dev.
get_info<info::device::name>());
247 xpti::addMetadata(TEvent,
"memory_size", Size);
250 PrepareNotify.notify();
252 PrepareNotify.scopedNotify(
253 (uint16_t)xpti::trace_point_type_t::mem_alloc_begin);
258 #ifdef XPTI_ENABLE_INSTRUMENTATION
259 xpti::addMetadata(PrepareNotify.traceEvent(),
"memory_ptr",
260 reinterpret_cast<size_t>(RetVal));
280 #ifdef XPTI_ENABLE_INSTRUMENTATION
283 XPTIScope PrepareNotify((
void *)
free,
284 (uint16_t)xpti::trace_point_type_t::node_create,
286 PrepareNotify.addMetadata([&](
auto TEvent) {
287 xpti::addMetadata(TEvent,
"memory_ptr",
reinterpret_cast<size_t>(Ptr));
290 PrepareNotify.notify();
292 PrepareNotify.scopedNotify(
293 (uint16_t)xpti::trace_point_type_t::mem_release_begin);
309 const detail::code_location &CodeLoc) {
321 const detail::code_location &CodeLoc) {
323 alloc::device, PropList, CodeLoc);
335 const detail::code_location &CodeLoc) {
349 const detail::code_location &CodeLoc) {
372 const detail::code_location &CodeLoc) {
384 const detail::code_location &CodeLoc) {
397 const detail::code_location &CodeLoc) {
409 const detail::code_location &CodeLoc) {
411 alloc::shared, PropList, CodeLoc);
422 const detail::code_location &CodeLoc) {
435 const detail::code_location &CodeLoc) {
437 alloc::host, PropList, CodeLoc);
449 const detail::code_location &CodeLoc) {
463 const detail::code_location &CodeLoc) {
474 if (Kind == alloc::host)
482 if (Kind == alloc::host)
491 if (Kind == alloc::host)
501 if (Kind == alloc::host)
505 Kind, PropList, CodeLoc);
511 if (Kind == alloc::host)
523 if (Kind == alloc::host)
532 if (Kind == alloc::host)
543 if (Kind == alloc::host)
558 return alloc::unknown;
563 if (CtxImpl->is_host())
577 if (Err == PI_ERROR_INVALID_VALUE)
578 return alloc::unknown;
580 if (Err != PI_SUCCESS) {
581 Plugin->reportPiError(Err,
"get_pointer_type()");
587 ResultAlloc = alloc::host;
590 ResultAlloc = alloc::device;
593 ResultAlloc = alloc::shared;
596 ResultAlloc = alloc::unknown;
610 throw runtime_error(
"Ptr not a valid USM allocation!",
611 PI_ERROR_INVALID_VALUE);
616 if (CtxImpl->is_host())
621 auto Devs = CtxImpl->getDevices();
622 if (Devs.size() == 0)
623 throw runtime_error(
"No devices in passed context!",
624 PI_ERROR_INVALID_VALUE);
640 std::shared_ptr<detail::platform_impl> PltImpl = CtxImpl->getPlatformImpl();
641 std::shared_ptr<detail::device_impl> DevImpl =
642 PltImpl->getDeviceImpl(DeviceId);
644 return detail::createSyclObjFromImpl<device>(DevImpl);
645 throw runtime_error(
"Cannot find device associated with USM allocation!",
646 PI_ERROR_INVALID_OPERATION);
668 namespace ext::oneapi::experimental {