23 #ifdef XPTI_ENABLE_INSTRUMENTATION
26 #include "xpti/xpti_trace_framework.hpp"
36 #ifdef XPTI_ENABLE_INSTRUMENTATION
37 extern xpti::trace_event_data_t *GSYCLGraphEvent;
44 #ifdef XPTI_ENABLE_INSTRUMENTATION
48 (uint16_t)xpti::trace_point_type_t::node_create,
50 PrepareNotify.addMetadata([&](
auto TEvent) {
51 xpti::addMetadata(TEvent,
"sycl_device_name", std::string(
"Host"));
52 xpti::addMetadata(TEvent,
"sycl_device", 0);
53 xpti::addMetadata(TEvent,
"memory_size", Size);
56 PrepareNotify.notify();
58 PrepareNotify.scopedNotify(
59 (uint16_t)xpti::trace_point_type_t::mem_alloc_begin);
61 void *RetVal =
nullptr;
66 if (CtxImpl->is_host()) {
75 }
catch (
const std::bad_alloc &) {
86 std::array<pi_usm_mem_properties, 3> Props;
87 auto PropsIter = Props.begin();
89 if (PropList.
has_property<sycl::ext::intel::experimental::property::usm::
92 "cl_intel_mem_alloc_buffer_location")) {
94 *PropsIter++ = PropList
97 .get_buffer_location();
100 assert(PropsIter >= Props.begin() && PropsIter < Props.end());
104 &RetVal, C, Props.data(), Size,
Alignment);
110 case alloc::unknown: {
112 Error = PI_ERROR_INVALID_VALUE;
119 if (Error != PI_SUCCESS)
129 void *RetVal =
nullptr;
134 if (Kind == alloc::unknown) {
145 }
catch (
const std::bad_alloc &) {
157 case alloc::device: {
160 std::array<pi_usm_mem_properties, 3> Props;
161 auto PropsIter = Props.begin();
164 if (PropList.
has_property<sycl::ext::intel::experimental::property::usm::
166 DevImpl->
has_extension(
"cl_intel_mem_alloc_buffer_location")) {
168 *PropsIter++ = PropList
171 .get_buffer_location();
174 assert(PropsIter >= Props.begin() && PropsIter < Props.end());
178 &RetVal, C, Id, Props.data(), Size,
Alignment);
182 case alloc::shared: {
185 std::array<pi_usm_mem_properties, 5> Props;
186 auto PropsIter = Props.begin();
189 sycl::ext::oneapi::property::usm::device_read_only>()) {
194 if (PropList.
has_property<sycl::ext::intel::experimental::property::usm::
196 DevImpl->
has_extension(
"cl_intel_mem_alloc_buffer_location")) {
198 *PropsIter++ = PropList
201 .get_buffer_location();
204 assert(PropsIter >= Props.begin() && PropsIter < Props.end());
208 &RetVal, C, Id, Props.data(), Size,
Alignment);
213 case alloc::unknown: {
215 Error = PI_ERROR_INVALID_VALUE;
222 if (Error != PI_SUCCESS)
231 #ifdef XPTI_ENABLE_INSTRUMENTATION
235 (uint16_t)xpti::trace_point_type_t::node_create,
237 PrepareNotify.addMetadata([&](
auto TEvent) {
238 xpti::addMetadata(TEvent,
"sycl_device_name",
239 Dev.
get_info<info::device::name>());
242 xpti::addMetadata(TEvent,
"memory_size", Size);
245 PrepareNotify.notify();
247 PrepareNotify.scopedNotify(
248 (uint16_t)xpti::trace_point_type_t::mem_alloc_begin);
259 detail::OSUtil::alignedFree(Ptr);
269 #ifdef XPTI_ENABLE_INSTRUMENTATION
272 XPTIScope PrepareNotify((
void *)
free,
273 (uint16_t)xpti::trace_point_type_t::node_create,
275 PrepareNotify.addMetadata([&](
auto TEvent) {
276 xpti::addMetadata(TEvent,
"memory_ptr",
reinterpret_cast<size_t>(Ptr));
279 PrepareNotify.notify();
281 PrepareNotify.scopedNotify(
282 (uint16_t)xpti::trace_point_type_t::mem_release_begin);
314 alloc::device, PropList, CodeLoc);
410 alloc::shared, PropList, CodeLoc);
440 alloc::host, PropList, CodeLoc);
481 if (Kind == alloc::host)
490 if (Kind == alloc::host)
500 if (Kind == alloc::host)
510 if (Kind == alloc::host)
514 Kind, PropList, CodeLoc);
521 if (Kind == alloc::host)
533 if (Kind == alloc::host)
543 if (Kind == alloc::host)
554 if (Kind == alloc::host)
569 return alloc::unknown;
574 if (CtxImpl->is_host())
588 if (Err == PI_ERROR_INVALID_VALUE)
589 return alloc::unknown;
591 if (Err != PI_SUCCESS) {
598 ResultAlloc = alloc::host;
601 ResultAlloc = alloc::device;
604 ResultAlloc = alloc::shared;
607 ResultAlloc = alloc::unknown;
621 throw runtime_error(
"Ptr not a valid USM allocation!",
622 PI_ERROR_INVALID_VALUE);
627 if (CtxImpl->is_host())
632 auto Devs = CtxImpl->getDevices();
633 if (Devs.size() == 0)
634 throw runtime_error(
"No devices in passed context!",
635 PI_ERROR_INVALID_VALUE);
651 std::shared_ptr<detail::platform_impl> PltImpl = CtxImpl->getPlatformImpl();
652 std::shared_ptr<detail::device_impl> DevImpl =
653 PltImpl->getDeviceImpl(DeviceId);
655 return detail::createSyclObjFromImpl<device>(DevImpl);
656 throw runtime_error(
"Cannot find device associated with USM allocation!",
657 PI_ERROR_INVALID_OPERATION);