25 #ifdef XPTI_ENABLE_INSTRUMENTATION
28 #include "xpti/xpti_trace_framework.hpp"
33 inline namespace _V1 {
38 #ifdef XPTI_ENABLE_INSTRUMENTATION
39 extern xpti::trace_event_data_t *GSYCLGraphEvent;
46 #ifdef XPTI_ENABLE_INSTRUMENTATION
50 (uint16_t)xpti::trace_point_type_t::node_create,
52 PrepareNotify.addMetadata([&](
auto TEvent) {
53 xpti::addMetadata(TEvent,
"sycl_device_name", std::string(
"Host"));
54 xpti::addMetadata(TEvent,
"sycl_device", 0);
55 xpti::addMetadata(TEvent,
"memory_size", Size);
58 PrepareNotify.notify();
60 PrepareNotify.scopedNotify(
61 (uint16_t)xpti::trace_point_type_t::mem_alloc_begin);
65 return device.has(sycl::aspect::usm_host_allocations);
68 sycl::errc::feature_not_supported,
69 "No device in this context supports USM host allocations!");
71 void *RetVal =
nullptr;
76 if (CtxImpl->is_host()) {
85 }
catch (
const std::bad_alloc &) {
91 const PluginPtr &Plugin = CtxImpl->getPlugin();
96 std::array<pi_usm_mem_properties, 3> Props;
97 auto PropsIter = Props.begin();
99 if (PropList.
has_property<sycl::ext::intel::experimental::property::usm::
102 "cl_intel_mem_alloc_buffer_location")) {
104 *PropsIter++ = PropList
107 .get_buffer_location();
110 assert(PropsIter >= Props.begin() && PropsIter < Props.end());
114 &RetVal, C, Props.data(), Size,
Alignment);
120 case alloc::unknown: {
122 Error = PI_ERROR_INVALID_VALUE;
129 if (Error != PI_SUCCESS)
132 #ifdef XPTI_ENABLE_INSTRUMENTATION
133 xpti::addMetadata(PrepareNotify.traceEvent(),
"memory_ptr",
134 reinterpret_cast<size_t>(RetVal));
143 if (Kind == alloc::device &&
144 !DevImpl->
has(sycl::aspect::usm_device_allocations)) {
146 "Device does not support USM device allocations!");
148 if (Kind == alloc::shared &&
149 !DevImpl->
has(sycl::aspect::usm_shared_allocations)) {
151 "Device does not support shared USM allocations!");
153 void *RetVal =
nullptr;
158 if (Kind == alloc::unknown) {
169 }
catch (
const std::bad_alloc &) {
177 pi_result Error = PI_ERROR_INVALID_VALUE;
181 case alloc::device: {
184 std::array<pi_usm_mem_properties, 3> Props;
185 auto PropsIter = Props.begin();
188 if (PropList.
has_property<sycl::ext::intel::experimental::property::usm::
190 DevImpl->
has_extension(
"cl_intel_mem_alloc_buffer_location")) {
192 *PropsIter++ = PropList
195 .get_buffer_location();
198 assert(PropsIter >= Props.begin() && PropsIter < Props.end());
202 &RetVal, C, Id, Props.data(), Size,
Alignment);
206 case alloc::shared: {
209 std::array<pi_usm_mem_properties, 5> Props;
210 auto PropsIter = Props.begin();
218 if (PropList.
has_property<sycl::ext::intel::experimental::property::usm::
220 DevImpl->
has_extension(
"cl_intel_mem_alloc_buffer_location")) {
222 *PropsIter++ = PropList
225 .get_buffer_location();
228 assert(PropsIter >= Props.begin() && PropsIter < Props.end());
232 &RetVal, C, Id, Props.data(), Size,
Alignment);
237 case alloc::unknown: {
239 Error = PI_ERROR_INVALID_VALUE;
246 if (Error != PI_SUCCESS)
255 #ifdef XPTI_ENABLE_INSTRUMENTATION
259 (uint16_t)xpti::trace_point_type_t::node_create,
261 PrepareNotify.addMetadata([&](
auto TEvent) {
262 xpti::addMetadata(TEvent,
"sycl_device_name",
263 Dev.
get_info<info::device::name>());
266 xpti::addMetadata(TEvent,
"memory_size", Size);
269 PrepareNotify.notify();
271 PrepareNotify.scopedNotify(
272 (uint16_t)xpti::trace_point_type_t::mem_alloc_begin);
277 #ifdef XPTI_ENABLE_INSTRUMENTATION
278 xpti::addMetadata(PrepareNotify.traceEvent(),
"memory_ptr",
279 reinterpret_cast<size_t>(RetVal));
299 #ifdef XPTI_ENABLE_INSTRUMENTATION
302 XPTIScope PrepareNotify((
void *)
free,
303 (uint16_t)xpti::trace_point_type_t::node_create,
305 PrepareNotify.addMetadata([&](
auto TEvent) {
306 xpti::addMetadata(TEvent,
"memory_ptr",
reinterpret_cast<size_t>(Ptr));
309 PrepareNotify.notify();
311 PrepareNotify.scopedNotify(
312 (uint16_t)xpti::trace_point_type_t::mem_release_begin);
321 const detail::code_location &CodeLoc) {
326 void *
malloc_device(
size_t Size,
const device &Dev,
const context &Ctxt,
327 const property_list &PropList,
328 const detail::code_location &CodeLoc) {
334 const detail::code_location &CodeLoc) {
339 void *
malloc_device(
size_t Size,
const queue &Q,
const property_list &PropList,
340 const detail::code_location &CodeLoc) {
342 alloc::device, PropList, CodeLoc);
347 const detail::code_location &CodeLoc) {
353 const context &Ctxt,
const property_list &PropList,
354 const detail::code_location &CodeLoc) {
360 const detail::code_location &CodeLoc) {
367 const property_list &PropList,
368 const detail::code_location &CodeLoc) {
370 Q.get_device(), alloc::device, PropList,
375 const detail::code_location &CodeLoc) {
379 void free(
void *ptr,
const queue &Q,
const detail::code_location &CodeLoc) {
384 const detail::code_location &CodeLoc) {
389 void *
malloc_host(
size_t Size,
const context &Ctxt,
390 const property_list &PropList,
391 const detail::code_location &CodeLoc) {
397 const detail::code_location &CodeLoc) {
402 void *
malloc_host(
size_t Size,
const queue &Q,
const property_list &PropList,
403 const detail::code_location &CodeLoc) {
409 const detail::code_location &CodeLoc) {
414 void *
malloc_shared(
size_t Size,
const device &Dev,
const context &Ctxt,
415 const property_list &PropList,
416 const detail::code_location &CodeLoc) {
422 const detail::code_location &CodeLoc) {
427 void *
malloc_shared(
size_t Size,
const queue &Q,
const property_list &PropList,
428 const detail::code_location &CodeLoc) {
430 alloc::shared, PropList, CodeLoc);
434 const detail::code_location &CodeLoc) {
440 const property_list &PropList,
441 const detail::code_location &CodeLoc) {
447 const detail::code_location &CodeLoc) {
453 const property_list &PropList,
454 const detail::code_location &CodeLoc) {
456 alloc::host, PropList, CodeLoc);
461 const detail::code_location &CodeLoc) {
467 const context &Ctxt,
const property_list &PropList,
468 const detail::code_location &CodeLoc) {
474 const detail::code_location &CodeLoc) {
481 const property_list &PropList,
482 const detail::code_location &CodeLoc) {
484 Q.get_device(), alloc::shared, PropList,
492 const detail::code_location &CodeLoc) {
493 if (Kind == alloc::host)
500 const detail::code_location &CodeLoc) {
501 if (Kind == alloc::host)
509 const detail::code_location &CodeLoc) {
510 if (Kind == alloc::host)
519 const detail::code_location &CodeLoc) {
520 if (Kind == alloc::host)
524 Kind, PropList, CodeLoc);
529 const detail::code_location &CodeLoc) {
530 if (Kind == alloc::host)
541 const detail::code_location &CodeLoc) {
542 if (Kind == alloc::host)
550 const detail::code_location &CodeLoc) {
551 if (Kind == alloc::host)
561 const detail::code_location &CodeLoc) {
562 if (Kind == alloc::host)
577 return alloc::unknown;
582 if (CtxImpl->is_host())
596 if (Err == PI_ERROR_INVALID_VALUE)
597 return alloc::unknown;
599 if (Err != PI_SUCCESS) {
600 Plugin->reportPiError(Err,
"get_pointer_type()");
606 ResultAlloc = alloc::host;
609 ResultAlloc = alloc::device;
612 ResultAlloc = alloc::shared;
615 ResultAlloc = alloc::unknown;
629 throw runtime_error(
"Ptr not a valid USM allocation!",
630 PI_ERROR_INVALID_VALUE);
635 if (CtxImpl->is_host())
640 auto Devs = CtxImpl->getDevices();
641 if (Devs.size() == 0)
642 throw runtime_error(
"No devices in passed context!",
643 PI_ERROR_INVALID_VALUE);
659 std::shared_ptr<detail::platform_impl> PltImpl = CtxImpl->getPlatformImpl();
660 std::shared_ptr<detail::device_impl> DevImpl =
661 PltImpl->getDeviceImpl(DeviceId);
663 return detail::createSyclObjFromImpl<device>(DevImpl);
664 throw runtime_error(
"Cannot find device associated with USM allocation!",
665 PI_ERROR_INVALID_OPERATION);
687 namespace ext::oneapi::experimental {
The context class represents a SYCL context on which kernel functions may be executed.
std::vector< device > get_devices() const
Gets devices associated with this SYCL context.
platform get_platform() const
Gets platform associated with this SYCL context.
static void alignedFree(void *Ptr)
Deallocates the memory referenced by Ptr.
pointer allocate(size_t Size)
const PluginPtr & getPlugin() const
bool is_host() const
Checks if this context is a host context.
sycl::detail::pi::PiContext & getHandleRef()
Gets the underlying context object (if any) without reference count modification.
bool has(aspect Aspect) const
Indicates if the SYCL device has the given feature.
sycl::detail::pi::PiDevice & getHandleRef()
Get reference to PI device.
bool has_extension(const std::string &ExtensionName) const
Check SYCL extension support by device.
Data type that manages the code_location information in TLS.
The SYCL device class encapsulates a single SYCL device on which kernels may be executed.
detail::is_device_info_desc< Param >::return_type get_info() const
Queries this SYCL device for information requested by the template parameter param.
Objects of the property_list class are containers for the SYCL properties.
bool has_property() const noexcept
PropT get_property() const
Encapsulates a single SYCL queue which schedules kernels on a SYCL device.
device get_device() const
context get_context() const
void * alignedAllocHost(size_t Alignment, size_t Bytes, const context &Ctxt, sycl::usm::alloc Kind, const code_location &CL)
void freeInternal(void *Ptr, const context_impl *CtxImpl)
void * alignedAlloc(size_t Alignment, size_t Bytes, const context &Ctxt, const device &Dev, sycl::usm::alloc Kind, const code_location &CL)
void free(void *Ptr, const context &Ctxt, const code_location &CL)
void * alignedAllocInternal(size_t Alignment, size_t Size, const context_impl *CtxImpl, const device_impl *DevImpl, alloc Kind, const property_list &PropList)
constexpr auto SYCL_MEM_ALLOC_STREAM_NAME
decltype(Obj::impl) getSyclObjImpl(const Obj &SyclObject)
std::shared_ptr< plugin > PluginPtr
constexpr buffer_location_key::value_t< N > buffer_location
void prepare_for_device_copy(const void *Ptr, size_t Size, const context &Context)
void release_from_device_copy(const void *Ptr, const context &Context)
void * aligned_alloc(size_t alignment, size_t size, const device &dev, const context &ctxt, usm::alloc kind, const detail::code_location &CodeLoc=detail::code_location::current())
void * aligned_alloc_host(size_t alignment, size_t size, const context &ctxt, const detail::code_location &CodeLoc=detail::code_location::current())
usm::alloc get_pointer_type(const void *ptr, const context &ctxt)
Query the allocation type from a USM pointer.
void * aligned_alloc_shared(size_t alignment, size_t size, const device &dev, const context &ctxt, const detail::code_location &CodeLoc=detail::code_location::current())
void * malloc_shared(size_t size, const device &dev, const context &ctxt, const detail::code_location &CodeLoc=detail::code_location::current())
static void release_from_usm_device_copy(const void *Ptr, const context &Ctxt)
device get_pointer_device(const void *ptr, const context &ctxt)
Queries the device against which the pointer was allocated Throws an invalid_object_error if ptr is a...
void * aligned_alloc_device(size_t alignment, size_t size, const device &dev, const context &ctxt, const detail::code_location &CodeLoc=detail::code_location::current())
void * malloc_device(size_t size, const device &dev, const context &ctxt, const detail::code_location &CodeLoc=detail::code_location::current())
void * malloc(size_t size, const device &dev, const context &ctxt, usm::alloc kind, const detail::code_location &CodeLoc=detail::code_location::current())
void * malloc_host(size_t size, const context &ctxt, const detail::code_location &CodeLoc=detail::code_location::current())
static void prepare_for_usm_device_copy(const void *Ptr, size_t Size, const context &Ctxt)
void free(void *ptr, const context &ctxt, const detail::code_location &CodeLoc=detail::code_location::current())
constexpr pi_usm_mem_properties PI_MEM_USM_ALLOC_BUFFER_LOCATION
pi_result piextUSMFree(pi_context context, void *ptr)
Indicates that the allocated USM memory is no longer needed on the runtime side.
constexpr pi_usm_mem_properties PI_MEM_ALLOC_FLAGS
pi_result piextUSMImport(const void *ptr, size_t size, pi_context context)
Import host system memory into USM.
pi_result piextUSMHostAlloc(void **result_ptr, pi_context context, pi_usm_mem_properties *properties, size_t size, pi_uint32 alignment)
Allocates host memory accessible by the device.
pi_result piextUSMRelease(const void *ptr, pi_context context)
Release host system memory from USM.
constexpr pi_usm_mem_properties PI_MEM_ALLOC_DEVICE_READ_ONLY
pi_result piextUSMDeviceAlloc(void **result_ptr, pi_context context, pi_device device, pi_usm_mem_properties *properties, size_t size, pi_uint32 alignment)
Allocates device memory.
pi_result piextUSMSharedAlloc(void **result_ptr, pi_context context, pi_device device, pi_usm_mem_properties *properties, size_t size, pi_uint32 alignment)
Allocates memory accessible on both host and device.
pi_result piextUSMGetMemAllocInfo(pi_context context, const void *ptr, pi_mem_alloc_info param_name, size_t param_value_size, void *param_value, size_t *param_value_size_ret)
API to query information about USM allocated pointers Valid Queries: PI_MEM_ALLOC_TYPE returns host/d...
C++ wrapper of extern "C" PI interfaces.
bool any_of(const simd_mask< _Tp, _Abi > &) noexcept