DPC++ Runtime
Runtime libraries for oneAPI DPC++
usm_impl.cpp
Go to the documentation of this file.
1 //==---------------- usm_impl.cpp - USM API Utils -------------*- C++ -*---==//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 // ===--------------------------------------------------------------------=== //
8 
9 #include <detail/queue_impl.hpp>
10 #include <sycl/context.hpp>
12 #include <sycl/detail/os_util.hpp>
13 #include <sycl/detail/pi.hpp>
14 #include <sycl/device.hpp>
15 #include <sycl/usm.hpp>
16 
17 #include <array>
18 #include <cassert>
19 #include <cstdlib>
20 #include <memory>
21 
22 #ifdef XPTI_ENABLE_INSTRUMENTATION
23 // Include the headers necessary for emitting
24 // traces using the trace framework
25 #include "xpti/xpti_trace_framework.hpp"
26 
27 #define XPTI_CREATE_TRACEPOINT(CodeLoc) \
28  std::unique_ptr<xpti::framework::tracepoint_t> _TP(nullptr); \
29  if (xptiTraceEnabled()) { \
30  xpti::payload_t Payload{CodeLoc.functionName(), CodeLoc.fileName(), \
31  static_cast<int>(CodeLoc.lineNumber()), \
32  static_cast<int>(CodeLoc.columnNumber()), \
33  nullptr}; \
34  _TP = std::make_unique<xpti::framework::tracepoint_t>(&Payload); \
35  } \
36  (void)_TP;
37 #else
38 #define XPTI_CREATE_TRACEPOINT(CodeLoc)
39 #endif
40 
41 namespace sycl {
43 
45 
46 namespace detail {
47 namespace usm {
48 
49 void *alignedAllocHost(size_t Alignment, size_t Size, const context &Ctxt,
50  alloc Kind, const property_list &PropList,
51  const detail::code_location &CodeLoc) {
52  XPTI_CREATE_TRACEPOINT(CodeLoc);
53  void *RetVal = nullptr;
54  if (Size == 0)
55  return nullptr;
56 
57  std::shared_ptr<context_impl> CtxImpl = detail::getSyclObjImpl(Ctxt);
58  if (CtxImpl->is_host()) {
59  if (!Alignment) {
60  // worst case default
61  Alignment = 128;
62  }
63 
64  aligned_allocator<char> Alloc(Alignment);
65  try {
66  RetVal = Alloc.allocate(Size);
67  } catch (const std::bad_alloc &) {
68  // Conform with Specification behavior
69  RetVal = nullptr;
70  }
71  } else {
72  pi_context C = CtxImpl->getHandleRef();
73  const detail::plugin &Plugin = CtxImpl->getPlugin();
74  pi_result Error;
75 
76  switch (Kind) {
77  case alloc::host: {
78  std::array<pi_usm_mem_properties, 3> Props;
79  auto PropsIter = Props.begin();
80 
81  if (PropList.has_property<sycl::ext::intel::experimental::property::usm::
82  buffer_location>() &&
83  Ctxt.get_platform().has_extension(
84  "cl_intel_mem_alloc_buffer_location")) {
85  *PropsIter++ = PI_MEM_USM_ALLOC_BUFFER_LOCATION;
86  *PropsIter++ = PropList
89  .get_buffer_location();
90  }
91 
92  assert(PropsIter >= Props.begin() && PropsIter < Props.end());
93  *PropsIter++ = 0; // null-terminate property list
94 
96  &RetVal, C, Props.data(), Size, Alignment);
97 
98  break;
99  }
100  case alloc::device:
101  case alloc::shared:
102  case alloc::unknown: {
103  RetVal = nullptr;
104  Error = PI_ERROR_INVALID_VALUE;
105  break;
106  }
107  }
108 
109  // Error is for debugging purposes.
110  // The spec wants a nullptr returned, not an exception.
111  if (Error != PI_SUCCESS)
112  return nullptr;
113  }
114  return RetVal;
115 }
116 
117 void *alignedAlloc(size_t Alignment, size_t Size, const context &Ctxt,
118  const device &Dev, alloc Kind, const property_list &PropList,
119  const detail::code_location &CodeLoc) {
120  XPTI_CREATE_TRACEPOINT(CodeLoc);
121  void *RetVal = nullptr;
122  if (Size == 0)
123  return nullptr;
124 
125  std::shared_ptr<context_impl> CtxImpl = detail::getSyclObjImpl(Ctxt);
126  if (CtxImpl->is_host()) {
127  if (Kind == alloc::unknown) {
128  RetVal = nullptr;
129  } else {
130  if (!Alignment) {
131  // worst case default
132  Alignment = 128;
133  }
134 
135  aligned_allocator<char> Alloc(Alignment);
136  try {
137  RetVal = Alloc.allocate(Size);
138  } catch (const std::bad_alloc &) {
139  // Conform with Specification behavior
140  RetVal = nullptr;
141  }
142  }
143  } else {
144  pi_context C = CtxImpl->getHandleRef();
145  const detail::plugin &Plugin = CtxImpl->getPlugin();
146  pi_result Error;
147  pi_device Id;
148 
149  switch (Kind) {
150  case alloc::device: {
151  Id = detail::getSyclObjImpl(Dev)->getHandleRef();
152 
153  std::array<pi_usm_mem_properties, 3> Props;
154  auto PropsIter = Props.begin();
155 
156  // Buffer location is only supported on FPGA devices
157  if (PropList.has_property<sycl::ext::intel::experimental::property::usm::
158  buffer_location>() &&
159  Dev.has_extension("cl_intel_mem_alloc_buffer_location")) {
160  *PropsIter++ = PI_MEM_USM_ALLOC_BUFFER_LOCATION;
161  *PropsIter++ = PropList
164  .get_buffer_location();
165  }
166 
167  assert(PropsIter >= Props.begin() && PropsIter < Props.end());
168  *PropsIter++ = 0; // null-terminate property list
169 
171  &RetVal, C, Id, Props.data(), Size, Alignment);
172 
173  break;
174  }
175  case alloc::shared: {
176  Id = detail::getSyclObjImpl(Dev)->getHandleRef();
177 
178  std::array<pi_usm_mem_properties, 5> Props;
179  auto PropsIter = Props.begin();
180 
181  if (PropList.has_property<
182  sycl::ext::oneapi::property::usm::device_read_only>()) {
183  *PropsIter++ = PI_MEM_ALLOC_FLAGS;
184  *PropsIter++ = PI_MEM_ALLOC_DEVICE_READ_ONLY;
185  }
186 
187  if (PropList.has_property<sycl::ext::intel::experimental::property::usm::
188  buffer_location>() &&
189  Dev.has_extension("cl_intel_mem_alloc_buffer_location")) {
190  *PropsIter++ = PI_MEM_USM_ALLOC_BUFFER_LOCATION;
191  *PropsIter++ = PropList
194  .get_buffer_location();
195  }
196 
197  assert(PropsIter >= Props.begin() && PropsIter < Props.end());
198  *PropsIter++ = 0; // null-terminate property list
199 
201  &RetVal, C, Id, Props.data(), Size, Alignment);
202 
203  break;
204  }
205  case alloc::host:
206  case alloc::unknown: {
207  RetVal = nullptr;
208  Error = PI_ERROR_INVALID_VALUE;
209  break;
210  }
211  }
212 
213  // Error is for debugging purposes.
214  // The spec wants a nullptr returned, not an exception.
215  if (Error != PI_SUCCESS)
216  return nullptr;
217  }
218  return RetVal;
219 }
220 
221 void free(void *Ptr, const context &Ctxt,
222  const detail::code_location &CodeLoc) {
223  XPTI_CREATE_TRACEPOINT(CodeLoc);
224  if (Ptr == nullptr)
225  return;
226 
227  std::shared_ptr<context_impl> CtxImpl = detail::getSyclObjImpl(Ctxt);
228  if (CtxImpl->is_host()) {
229  // need to use alignedFree here for Windows
230  detail::OSUtil::alignedFree(Ptr);
231  } else {
232  pi_context C = CtxImpl->getHandleRef();
233  const detail::plugin &Plugin = CtxImpl->getPlugin();
234  Plugin.call<PiApiKind::piextUSMFree>(C, Ptr);
235  }
236 }
237 
238 } // namespace usm
239 } // namespace detail
240 
241 void *malloc_device(size_t Size, const device &Dev,
242  const context &Ctxt _CODELOCPARAMDEF(&CodeLoc)) {
243  _CODELOCARG(&CodeLoc);
244  return detail::usm::alignedAlloc(0, Size, Ctxt, Dev, alloc::device,
245  property_list{}, CodeLoc);
246 }
247 
248 void *malloc_device(size_t Size, const device &Dev, const context &Ctxt,
249  const property_list &PropList _CODELOCPARAMDEF(&CodeLoc)) {
250  _CODELOCARG(&CodeLoc);
251  return detail::usm::alignedAlloc(0, Size, Ctxt, Dev, alloc::device, PropList,
252  CodeLoc);
253 }
254 
255 void *malloc_device(size_t Size, const queue &Q _CODELOCPARAMDEF(&CodeLoc)) {
256  _CODELOCARG(&CodeLoc);
257  return detail::usm::alignedAlloc(0, Size, Q.get_context(), Q.get_device(),
258  alloc::device, property_list{}, CodeLoc);
259 }
260 
261 void *malloc_device(size_t Size, const queue &Q,
262  const property_list &PropList _CODELOCPARAMDEF(&CodeLoc)) {
263  _CODELOCARG(&CodeLoc);
264  return detail::usm::alignedAlloc(0, Size, Q.get_context(), Q.get_device(),
265  alloc::device, PropList, CodeLoc);
266 }
267 
268 void *aligned_alloc_device(size_t Alignment, size_t Size, const device &Dev,
269  const context &Ctxt _CODELOCPARAMDEF(&CodeLoc)) {
270  _CODELOCARG(&CodeLoc);
271  return detail::usm::alignedAlloc(Alignment, Size, Ctxt, Dev, alloc::device,
272  property_list{}, CodeLoc);
273 }
274 
275 void *
276 aligned_alloc_device(size_t Alignment, size_t Size, const device &Dev,
277  const context &Ctxt,
278  const property_list &PropList _CODELOCPARAMDEF(&CodeLoc)) {
279  _CODELOCARG(&CodeLoc);
280  return detail::usm::alignedAlloc(Alignment, Size, Ctxt, Dev, alloc::device,
281  PropList, CodeLoc);
282 }
283 
284 void *aligned_alloc_device(size_t Alignment, size_t Size,
285  const queue &Q _CODELOCPARAMDEF(&CodeLoc)) {
286  _CODELOCARG(&CodeLoc);
287  return detail::usm::alignedAlloc(Alignment, Size, Q.get_context(),
288  Q.get_device(), alloc::device,
289  property_list{}, CodeLoc);
290 }
291 
292 void *
293 aligned_alloc_device(size_t Alignment, size_t Size, const queue &Q,
294  const property_list &PropList _CODELOCPARAMDEF(&CodeLoc)) {
295  _CODELOCARG(&CodeLoc);
296  return detail::usm::alignedAlloc(Alignment, Size, Q.get_context(),
297  Q.get_device(), alloc::device, PropList,
298  CodeLoc);
299 }
300 
301 void free(void *ptr, const context &Ctxt _CODELOCPARAMDEF(&CodeLoc)) {
302  _CODELOCARG(&CodeLoc);
303  return detail::usm::free(ptr, Ctxt, CodeLoc);
304 }
305 
306 void free(void *ptr, const queue &Q _CODELOCPARAMDEF(&CodeLoc)) {
307  _CODELOCARG(&CodeLoc);
308  return detail::usm::free(ptr, Q.get_context(), CodeLoc);
309 }
310 
311 void *malloc_host(size_t Size, const context &Ctxt _CODELOCPARAMDEF(&CodeLoc)) {
312  _CODELOCARG(&CodeLoc);
313  return detail::usm::alignedAllocHost(0, Size, Ctxt, alloc::host,
314  property_list{}, CodeLoc);
315 }
316 
317 void *malloc_host(size_t Size, const context &Ctxt,
318  const property_list &PropList _CODELOCPARAMDEF(&CodeLoc)) {
319  _CODELOCARG(&CodeLoc);
320  return detail::usm::alignedAllocHost(0, Size, Ctxt, alloc::host, PropList,
321  CodeLoc);
322 }
323 
324 void *malloc_host(size_t Size, const queue &Q _CODELOCPARAMDEF(&CodeLoc)) {
325  _CODELOCARG(&CodeLoc);
326  return detail::usm::alignedAllocHost(0, Size, Q.get_context(), alloc::host,
327  property_list{}, CodeLoc);
328 }
329 
330 void *malloc_host(size_t Size, const queue &Q,
331  const property_list &PropList _CODELOCPARAMDEF(&CodeLoc)) {
332  _CODELOCARG(&CodeLoc);
333  return detail::usm::alignedAllocHost(0, Size, Q.get_context(), alloc::host,
334  PropList, CodeLoc);
335 }
336 
337 void *malloc_shared(size_t Size, const device &Dev,
338  const context &Ctxt _CODELOCPARAMDEF(&CodeLoc)) {
339  _CODELOCARG(&CodeLoc);
340  return detail::usm::alignedAlloc(0, Size, Ctxt, Dev, alloc::shared,
341  property_list{}, CodeLoc);
342 }
343 
344 void *malloc_shared(size_t Size, const device &Dev, const context &Ctxt,
345  const property_list &PropList _CODELOCPARAMDEF(&CodeLoc)) {
346  _CODELOCARG(&CodeLoc);
347  return detail::usm::alignedAlloc(0, Size, Ctxt, Dev, alloc::shared, PropList,
348  CodeLoc);
349 }
350 
351 void *malloc_shared(size_t Size, const queue &Q _CODELOCPARAMDEF(&CodeLoc)) {
352  _CODELOCARG(&CodeLoc);
353  return detail::usm::alignedAlloc(0, Size, Q.get_context(), Q.get_device(),
354  alloc::shared, property_list{}, CodeLoc);
355 }
356 
357 void *malloc_shared(size_t Size, const queue &Q,
358  const property_list &PropList _CODELOCPARAMDEF(&CodeLoc)) {
359  _CODELOCARG(&CodeLoc);
360  return detail::usm::alignedAlloc(0, Size, Q.get_context(), Q.get_device(),
361  alloc::shared, PropList, CodeLoc);
362 }
363 
364 void *aligned_alloc_host(size_t Alignment, size_t Size,
365  const context &Ctxt _CODELOCPARAMDEF(&CodeLoc)) {
366  _CODELOCARG(&CodeLoc);
367  return detail::usm::alignedAllocHost(Alignment, Size, Ctxt, alloc::host,
368  property_list{}, CodeLoc);
369 }
370 
371 void *
372 aligned_alloc_host(size_t Alignment, size_t Size, const context &Ctxt,
373  const property_list &PropList _CODELOCPARAMDEF(&CodeLoc)) {
374  _CODELOCARG(&CodeLoc);
375  return detail::usm::alignedAllocHost(Alignment, Size, Ctxt, alloc::host,
376  PropList, CodeLoc);
377 }
378 
379 void *aligned_alloc_host(size_t Alignment, size_t Size,
380  const queue &Q _CODELOCPARAMDEF(&CodeLoc)) {
381  _CODELOCARG(&CodeLoc);
382  return detail::usm::alignedAllocHost(Alignment, Size, Q.get_context(),
383  alloc::host, property_list{}, CodeLoc);
384 }
385 
386 void *
387 aligned_alloc_host(size_t Alignment, size_t Size, const queue &Q,
388  const property_list &PropList _CODELOCPARAMDEF(&CodeLoc)) {
389  _CODELOCARG(&CodeLoc);
390  return detail::usm::alignedAllocHost(Alignment, Size, Q.get_context(),
391  alloc::host, PropList, CodeLoc);
392 }
393 
394 void *aligned_alloc_shared(size_t Alignment, size_t Size, const device &Dev,
395  const context &Ctxt _CODELOCPARAMDEF(&CodeLoc)) {
396  _CODELOCARG(&CodeLoc);
397  return detail::usm::alignedAlloc(Alignment, Size, Ctxt, Dev, alloc::shared,
398  property_list{}, CodeLoc);
399 }
400 
401 void *
402 aligned_alloc_shared(size_t Alignment, size_t Size, const device &Dev,
403  const context &Ctxt,
404  const property_list &PropList _CODELOCPARAMDEF(&CodeLoc)) {
405  _CODELOCARG(&CodeLoc);
406  return detail::usm::alignedAlloc(Alignment, Size, Ctxt, Dev, alloc::shared,
407  PropList, CodeLoc);
408 }
409 
410 void *aligned_alloc_shared(size_t Alignment, size_t Size,
411  const queue &Q _CODELOCPARAMDEF(&CodeLoc)) {
412  _CODELOCARG(&CodeLoc);
413  return detail::usm::alignedAlloc(Alignment, Size, Q.get_context(),
414  Q.get_device(), alloc::shared,
415  property_list{}, CodeLoc);
416 }
417 
418 void *
419 aligned_alloc_shared(size_t Alignment, size_t Size, const queue &Q,
420  const property_list &PropList _CODELOCPARAMDEF(&CodeLoc)) {
421  _CODELOCARG(&CodeLoc);
422  return detail::usm::alignedAlloc(Alignment, Size, Q.get_context(),
423  Q.get_device(), alloc::shared, PropList,
424  CodeLoc);
425 }
426 
427 // single form
428 
429 void *malloc(size_t Size, const device &Dev, const context &Ctxt, alloc Kind,
430  const property_list &PropList _CODELOCPARAMDEF(&CodeLoc)) {
431  _CODELOCARG(&CodeLoc);
432  if (Kind == alloc::host)
433  return detail::usm::alignedAllocHost(0, Size, Ctxt, Kind, PropList,
434  CodeLoc);
435  return detail::usm::alignedAlloc(0, Size, Ctxt, Dev, Kind, PropList, CodeLoc);
436 }
437 
438 void *malloc(size_t Size, const device &Dev, const context &Ctxt,
439  alloc Kind _CODELOCPARAMDEF(&CodeLoc)) {
440  _CODELOCARG(&CodeLoc);
441  if (Kind == alloc::host)
442  return detail::usm::alignedAllocHost(0, Size, Ctxt, Kind, property_list{},
443  CodeLoc);
444  return detail::usm::alignedAlloc(0, Size, Ctxt, Dev, Kind, property_list{},
445  CodeLoc);
446 }
447 
448 void *malloc(size_t Size, const queue &Q,
449  alloc Kind _CODELOCPARAMDEF(&CodeLoc)) {
450  _CODELOCARG(&CodeLoc);
451  if (Kind == alloc::host)
452  return detail::usm::alignedAllocHost(0, Size, Q.get_context(), Kind,
453  property_list{}, CodeLoc);
454  return detail::usm::alignedAlloc(0, Size, Q.get_context(), Q.get_device(),
455  Kind, property_list{}, CodeLoc);
456 }
457 
458 void *malloc(size_t Size, const queue &Q, alloc Kind,
459  const property_list &PropList _CODELOCPARAMDEF(&CodeLoc)) {
460  _CODELOCARG(&CodeLoc);
461  if (Kind == alloc::host)
462  return detail::usm::alignedAllocHost(0, Size, Q.get_context(), Kind,
463  PropList, CodeLoc);
464  return detail::usm::alignedAlloc(0, Size, Q.get_context(), Q.get_device(),
465  Kind, PropList, CodeLoc);
466 }
467 
468 void *aligned_alloc(size_t Alignment, size_t Size, const device &Dev,
469  const context &Ctxt,
470  alloc Kind _CODELOCPARAMDEF(&CodeLoc)) {
471  _CODELOCARG(&CodeLoc);
472  if (Kind == alloc::host)
473  return detail::usm::alignedAllocHost(Alignment, Size, Ctxt, Kind,
474  property_list{}, CodeLoc);
475 
476  return detail::usm::alignedAlloc(Alignment, Size, Ctxt, Dev, Kind,
477  property_list{}, CodeLoc);
478 }
479 
480 void *aligned_alloc(size_t Alignment, size_t Size, const device &Dev,
481  const context &Ctxt, alloc Kind,
482  const property_list &PropList _CODELOCPARAMDEF(&CodeLoc)) {
483  _CODELOCARG(&CodeLoc);
484  if (Kind == alloc::host)
485  return detail::usm::alignedAllocHost(Alignment, Size, Ctxt, Kind, PropList,
486  CodeLoc);
487  return detail::usm::alignedAlloc(Alignment, Size, Ctxt, Dev, Kind, PropList,
488  CodeLoc);
489 }
490 
491 void *aligned_alloc(size_t Alignment, size_t Size, const queue &Q,
492  alloc Kind _CODELOCPARAMDEF(&CodeLoc)) {
493  _CODELOCARG(&CodeLoc);
494  if (Kind == alloc::host)
495  return detail::usm::alignedAllocHost(Alignment, Size, Q.get_context(), Kind,
496  property_list{}, CodeLoc);
497  return detail::usm::alignedAlloc(Alignment, Size, Q.get_context(),
498  Q.get_device(), Kind, property_list{},
499  CodeLoc);
500 }
501 
502 void *aligned_alloc(size_t Alignment, size_t Size, const queue &Q, alloc Kind,
503  const property_list &PropList _CODELOCPARAMDEF(&CodeLoc)) {
504  _CODELOCARG(&CodeLoc);
505  if (Kind == alloc::host)
506  return detail::usm::alignedAllocHost(Alignment, Size, Q.get_context(), Kind,
507  PropList, CodeLoc);
508  return detail::usm::alignedAlloc(Alignment, Size, Q.get_context(),
509  Q.get_device(), Kind, PropList, CodeLoc);
510 }
511 
512 // Pointer queries
518 alloc get_pointer_type(const void *Ptr, const context &Ctxt) {
519  if (!Ptr)
520  return alloc::unknown;
521 
522  std::shared_ptr<detail::context_impl> CtxImpl = detail::getSyclObjImpl(Ctxt);
523 
524  // Everything on a host device is just system malloc so call it host
525  if (CtxImpl->is_host())
526  return alloc::host;
527 
528  pi_context PICtx = CtxImpl->getHandleRef();
529  pi_usm_type AllocTy;
530 
531  // query type using PI function
532  const detail::plugin &Plugin = CtxImpl->getPlugin();
533  RT::PiResult Err =
535  PICtx, Ptr, PI_MEM_ALLOC_TYPE, sizeof(pi_usm_type), &AllocTy,
536  nullptr);
537 
538  // PI_ERROR_INVALID_VALUE means USM doesn't know about this ptr
539  if (Err == PI_ERROR_INVALID_VALUE)
540  return alloc::unknown;
541  // otherwise PI_SUCCESS is expected
542  if (Err != PI_SUCCESS) {
543  Plugin.reportPiError(Err, "get_pointer_type()");
544  }
545 
546  alloc ResultAlloc;
547  switch (AllocTy) {
548  case PI_MEM_TYPE_HOST:
549  ResultAlloc = alloc::host;
550  break;
551  case PI_MEM_TYPE_DEVICE:
552  ResultAlloc = alloc::device;
553  break;
554  case PI_MEM_TYPE_SHARED:
555  ResultAlloc = alloc::shared;
556  break;
557  default:
558  ResultAlloc = alloc::unknown;
559  break;
560  }
561 
562  return ResultAlloc;
563 }
564 
569 device get_pointer_device(const void *Ptr, const context &Ctxt) {
570  // Check if ptr is a valid USM pointer
571  if (get_pointer_type(Ptr, Ctxt) == alloc::unknown)
572  throw runtime_error("Ptr not a valid USM allocation!",
573  PI_ERROR_INVALID_VALUE);
574 
575  std::shared_ptr<detail::context_impl> CtxImpl = detail::getSyclObjImpl(Ctxt);
576 
577  // Just return the host device in the host context
578  if (CtxImpl->is_host())
579  return Ctxt.get_devices()[0];
580 
581  // Check if ptr is a host allocation
582  if (get_pointer_type(Ptr, Ctxt) == alloc::host) {
583  auto Devs = CtxImpl->getDevices();
584  if (Devs.size() == 0)
585  throw runtime_error("No devices in passed context!",
586  PI_ERROR_INVALID_VALUE);
587 
588  // Just return the first device in the context
589  return Devs[0];
590  }
591 
592  pi_context PICtx = CtxImpl->getHandleRef();
593  pi_device DeviceId;
594 
595  // query device using PI function
596  const detail::plugin &Plugin = CtxImpl->getPlugin();
598  PICtx, Ptr, PI_MEM_ALLOC_DEVICE, sizeof(pi_device), &DeviceId, nullptr);
599 
600  // The device is not necessarily a member of the context, it could be a
601  // member's descendant instead. Fetch the corresponding device from the cache.
602  std::shared_ptr<detail::platform_impl> PltImpl = CtxImpl->getPlatformImpl();
603  std::shared_ptr<detail::device_impl> DevImpl =
604  PltImpl->getDeviceImpl(DeviceId);
605  if (DevImpl)
606  return detail::createSyclObjFromImpl<device>(DevImpl);
607  throw runtime_error("Cannot find device associated with USM allocation!",
608  PI_ERROR_INVALID_OPERATION);
609 }
610 } // __SYCL_INLINE_VER_NAMESPACE(_V1)
611 } // namespace sycl
The context class represents a SYCL context on which kernel functions may be executed.
Definition: context.hpp:39
std::vector< device > get_devices() const
Gets devices associated with this SYCL context.
Definition: context.cpp:139
platform get_platform() const
Gets platform associated with this SYCL context.
Definition: context.cpp:135
The plugin class provides a unified interface to the underlying low-level runtimes for the device-agn...
Definition: plugin.hpp:90
void call(ArgsT... Args) const
Calls the API, traces the call, checks the result.
Definition: plugin.hpp:217
void reportPiError(RT::PiResult pi_result, const char *context) const
Definition: plugin.hpp:149
RT::PiResult call_nocheck(ArgsT... Args) const
Calls the PiApi, traces the call, and returns the result.
Definition: plugin.hpp:170
The SYCL device class encapsulates a single SYCL device on which kernels may be executed.
Definition: device.hpp:47
bool has_extension(const std::string &extension_name) const
Check SYCL extension support by device.
Definition: device.cpp:120
Objects of the property_list class are containers for the SYCL properties.
bool has_property() const noexcept
Encapsulates a single SYCL queue which schedules kernels on a SYCL device.
Definition: queue.hpp:86
device get_device() const
Definition: queue.cpp:76
context get_context() const
Definition: queue.cpp:74
#define _CODELOCARG(a)
Definition: common.hpp:112
#define _CODELOCPARAMDEF(a)
Definition: common.hpp:110
#define __SYCL_INLINE_VER_NAMESPACE(X)
::pi_result PiResult
Definition: pi.hpp:108
void * alignedAllocHost(size_t Alignment, size_t Size, const context &Ctxt, alloc Kind, const property_list &PropList, const detail::code_location &CodeLoc)
Definition: usm_impl.cpp:49
void * alignedAlloc(size_t Alignment, size_t Size, const context &Ctxt, const device &Dev, alloc Kind, const property_list &PropList, const detail::code_location &CodeLoc)
Definition: usm_impl.cpp:117
decltype(Obj::impl) getSyclObjImpl(const Obj &SyclObject)
Definition: common.hpp:240
constexpr property::buffer_location::instance< A > buffer_location
void * malloc(size_t Size, const queue &Q, alloc Kind, const property_list &PropList _CODELOCPARAMDEF(&CodeLoc))
Definition: usm_impl.cpp:458
void * aligned_alloc_shared(size_t Alignment, size_t Size, const queue &Q, const property_list &PropList _CODELOCPARAMDEF(&CodeLoc))
Definition: usm_impl.cpp:419
void free(void *ptr, const queue &Q _CODELOCPARAMDEF(&CodeLoc))
Definition: usm_impl.cpp:306
void * malloc_host(size_t Size, const queue &Q, const property_list &PropList _CODELOCPARAMDEF(&CodeLoc))
Definition: usm_impl.cpp:330
void * malloc_device(size_t Size, const queue &Q, const property_list &PropList _CODELOCPARAMDEF(&CodeLoc))
Definition: usm_impl.cpp:261
void * aligned_alloc_device(size_t Alignment, size_t Size, const queue &Q, const property_list &PropList _CODELOCPARAMDEF(&CodeLoc))
Definition: usm_impl.cpp:293
usm::alloc get_pointer_type(const void *ptr, const context &ctxt)
Query the allocation type from a USM pointer.
Definition: usm_impl.cpp:518
void * malloc_shared(size_t Size, const queue &Q, const property_list &PropList _CODELOCPARAMDEF(&CodeLoc))
Definition: usm_impl.cpp:357
void * aligned_alloc(size_t Alignment, size_t Size, const queue &Q, alloc Kind, const property_list &PropList _CODELOCPARAMDEF(&CodeLoc))
Definition: usm_impl.cpp:502
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...
Definition: usm_impl.cpp:569
void * aligned_alloc_host(size_t Alignment, size_t Size, const queue &Q, const property_list &PropList _CODELOCPARAMDEF(&CodeLoc))
Definition: usm_impl.cpp:387
sycl::usm::alloc alloc
Definition: usm_impl.cpp:44
---— Error handling, matching OpenCL plugin semantics.
Definition: access.hpp:14
_pi_result
Definition: pi.h:114
constexpr pi_usm_mem_properties PI_MEM_USM_ALLOC_BUFFER_LOCATION
Definition: pi.h:573
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
Definition: pi.h:565
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_usm_type
Definition: pi.h:1629
@ PI_MEM_TYPE_SHARED
Definition: pi.h:1633
@ PI_MEM_TYPE_DEVICE
Definition: pi.h:1632
@ PI_MEM_TYPE_HOST
Definition: pi.h:1631
_pi_device * pi_device
Definition: pi.h:904
constexpr pi_usm_mem_properties PI_MEM_ALLOC_DEVICE_READ_ONLY
Definition: pi.h:571
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_MEM_ALLOC_TYPE
Definition: pi.h:1623
@ PI_MEM_ALLOC_DEVICE
Definition: pi.h:1626
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...
_pi_usm_type pi_usm_type
Definition: pi.h:1646
C++ wrapper of extern "C" PI interfaces.
PI context mapping to a CUDA context object.
Definition: pi_cuda.hpp:160
PI device mapping to a CUdevice.
Definition: pi_cuda.hpp:83
#define XPTI_CREATE_TRACEPOINT(CodeLoc)
Definition: usm_impl.cpp:38