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;
77 const PluginPtr &Plugin = CtxImpl->getPlugin();
82 std::array<pi_usm_mem_properties, 3> Props;
83 auto PropsIter = Props.begin();
88 "cl_intel_mem_alloc_buffer_location")) {
90 *PropsIter++ = PropList
93 .get_buffer_location();
96 assert(PropsIter >= Props.begin() && PropsIter < Props.end());
100 &RetVal, C, Props.data(), Size,
Alignment);
106 case alloc::unknown: {
108 Error = PI_ERROR_INVALID_VALUE;
115 if (Error != PI_SUCCESS)
117 #ifdef XPTI_ENABLE_INSTRUMENTATION
118 xpti::addMetadata(PrepareNotify.traceEvent(),
"memory_ptr",
119 reinterpret_cast<size_t>(RetVal));
128 if (Kind == alloc::device &&
129 !DevImpl->
has(sycl::aspect::usm_device_allocations)) {
131 "Device does not support USM device allocations!");
133 if (Kind == alloc::shared &&
134 !DevImpl->
has(sycl::aspect::usm_shared_allocations)) {
136 "Device does not support shared USM allocations!");
138 void *RetVal =
nullptr;
144 pi_result Error = PI_ERROR_INVALID_VALUE;
148 case alloc::device: {
151 std::array<pi_usm_mem_properties, 3> Props;
152 auto PropsIter = Props.begin();
157 DevImpl->
has_extension(
"cl_intel_mem_alloc_buffer_location")) {
159 *PropsIter++ = PropList
162 .get_buffer_location();
165 assert(PropsIter >= Props.begin() && PropsIter < Props.end());
169 &RetVal, C, Id, Props.data(), Size,
Alignment);
173 case alloc::shared: {
176 std::array<pi_usm_mem_properties, 5> Props;
177 auto PropsIter = Props.begin();
187 DevImpl->
has_extension(
"cl_intel_mem_alloc_buffer_location")) {
189 *PropsIter++ = PropList
192 .get_buffer_location();
195 assert(PropsIter >= Props.begin() && PropsIter < Props.end());
199 &RetVal, C, Id, Props.data(), Size,
Alignment);
204 case alloc::unknown: {
206 Error = PI_ERROR_INVALID_VALUE;
213 if (Error != PI_SUCCESS)
221 #ifdef XPTI_ENABLE_INSTRUMENTATION
225 (uint16_t)xpti::trace_point_type_t::node_create,
227 PrepareNotify.addMetadata([&](
auto TEvent) {
228 xpti::addMetadata(TEvent,
"sycl_device_name",
229 Dev.
get_info<info::device::name>());
232 xpti::addMetadata(TEvent,
"memory_size", Size);
235 PrepareNotify.notify();
237 PrepareNotify.scopedNotify(
238 (uint16_t)xpti::trace_point_type_t::mem_alloc_begin);
243 #ifdef XPTI_ENABLE_INSTRUMENTATION
244 xpti::addMetadata(PrepareNotify.traceEvent(),
"memory_ptr",
245 reinterpret_cast<size_t>(RetVal));
260 #ifdef XPTI_ENABLE_INSTRUMENTATION
263 XPTIScope PrepareNotify((
void *)
free,
264 (uint16_t)xpti::trace_point_type_t::node_create,
266 PrepareNotify.addMetadata([&](
auto TEvent) {
267 xpti::addMetadata(TEvent,
"memory_ptr",
reinterpret_cast<size_t>(Ptr));
270 PrepareNotify.notify();
272 PrepareNotify.scopedNotify(
273 (uint16_t)xpti::trace_point_type_t::mem_release_begin);
282 const detail::code_location &CodeLoc) {
287 void *
malloc_device(
size_t Size,
const device &Dev,
const context &Ctxt,
288 const property_list &PropList,
289 const detail::code_location &CodeLoc) {
295 const detail::code_location &CodeLoc) {
300 void *
malloc_device(
size_t Size,
const queue &Q,
const property_list &PropList,
301 const detail::code_location &CodeLoc) {
303 alloc::device, PropList, CodeLoc);
308 const detail::code_location &CodeLoc) {
314 const context &Ctxt,
const property_list &PropList,
315 const detail::code_location &CodeLoc) {
321 const detail::code_location &CodeLoc) {
328 const property_list &PropList,
329 const detail::code_location &CodeLoc) {
331 Q.get_device(), alloc::device, PropList,
336 const detail::code_location &CodeLoc) {
340 void free(
void *ptr,
const queue &Q,
const detail::code_location &CodeLoc) {
345 const detail::code_location &CodeLoc) {
350 void *
malloc_host(
size_t Size,
const context &Ctxt,
351 const property_list &PropList,
352 const detail::code_location &CodeLoc) {
358 const detail::code_location &CodeLoc) {
363 void *
malloc_host(
size_t Size,
const queue &Q,
const property_list &PropList,
364 const detail::code_location &CodeLoc) {
370 const detail::code_location &CodeLoc) {
375 void *
malloc_shared(
size_t Size,
const device &Dev,
const context &Ctxt,
376 const property_list &PropList,
377 const detail::code_location &CodeLoc) {
383 const detail::code_location &CodeLoc) {
388 void *
malloc_shared(
size_t Size,
const queue &Q,
const property_list &PropList,
389 const detail::code_location &CodeLoc) {
391 alloc::shared, PropList, CodeLoc);
395 const detail::code_location &CodeLoc) {
401 const property_list &PropList,
402 const detail::code_location &CodeLoc) {
408 const detail::code_location &CodeLoc) {
414 const property_list &PropList,
415 const detail::code_location &CodeLoc) {
417 alloc::host, PropList, CodeLoc);
422 const detail::code_location &CodeLoc) {
428 const context &Ctxt,
const property_list &PropList,
429 const detail::code_location &CodeLoc) {
435 const detail::code_location &CodeLoc) {
442 const property_list &PropList,
443 const detail::code_location &CodeLoc) {
445 Q.get_device(), alloc::shared, PropList,
453 const detail::code_location &CodeLoc) {
454 if (Kind == alloc::host)
461 const detail::code_location &CodeLoc) {
462 if (Kind == alloc::host)
470 const detail::code_location &CodeLoc) {
471 if (Kind == alloc::host)
480 const detail::code_location &CodeLoc) {
481 if (Kind == alloc::host)
485 Kind, PropList, CodeLoc);
490 const detail::code_location &CodeLoc) {
491 if (Kind == alloc::host)
502 const detail::code_location &CodeLoc) {
503 if (Kind == alloc::host)
511 const detail::code_location &CodeLoc) {
512 if (Kind == alloc::host)
522 const detail::code_location &CodeLoc) {
523 if (Kind == alloc::host)
538 return alloc::unknown;
553 if (Err == PI_ERROR_INVALID_VALUE)
554 return alloc::unknown;
556 if (Err != PI_SUCCESS) {
565 ResultAlloc = alloc::host;
568 ResultAlloc = alloc::device;
571 ResultAlloc = alloc::shared;
574 ResultAlloc = alloc::unknown;
589 "Ptr not a valid USM allocation!");
595 auto Devs = CtxImpl->getDevices();
596 if (Devs.size() == 0)
598 "No devices in passed context!");
614 std::shared_ptr<detail::platform_impl> PltImpl = CtxImpl->getPlatformImpl();
615 std::shared_ptr<detail::device_impl> DevImpl =
616 PltImpl->getDeviceImpl(DeviceId);
618 return detail::createSyclObjFromImpl<device>(DevImpl);
620 "Cannot find device associated with USM allocation!");
642 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.
const PluginPtr & getPlugin() const
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)
decltype(Obj::impl) const & getSyclObjImpl(const Obj &SyclObject)
constexpr auto SYCL_MEM_ALLOC_STREAM_NAME
exception set_pi_error(exception &&e, pi_int32 pi_err)
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 exception with errc::invalid err...
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())
std::error_code make_error_code(sycl::errc E) noexcept
Constructs an error code using e and sycl_category()
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