DPC++ Runtime
Runtime libraries for oneAPI DPC++
buffer_impl.cpp
Go to the documentation of this file.
1 //==----------------- buffer_impl.cpp - SYCL standard header file ----------==//
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 
11 #include <detail/context_impl.hpp>
14 #include <detail/xpti_registry.hpp>
15 
17 namespace sycl {
18 namespace detail {
19 #ifdef XPTI_ENABLE_INSTRUMENTATION
20 uint8_t GBufferStreamID;
21 #endif
22 void *buffer_impl::allocateMem(ContextImplPtr Context, bool InitFromUserData,
23  void *HostPtr, RT::PiEvent &OutEventToWait) {
24  bool HostPtrReadOnly = false;
25  BaseT::determineHostPtr(Context, InitFromUserData, HostPtr, HostPtrReadOnly);
26 
27  assert(!(nullptr == HostPtr && BaseT::useHostPtr() && Context->is_host()) &&
28  "Internal error. Allocating memory on the host "
29  "while having use_host_ptr property");
30  return MemoryManager::allocateMemBuffer(
31  std::move(Context), this, HostPtr, HostPtrReadOnly, BaseT::getSize(),
32  BaseT::MInteropEvent, BaseT::MInteropContext, MProps, OutEventToWait);
33 }
35  void *UserObj, const void *HostObj,
36  const void *Type, uint32_t Dim,
37  uint32_t ElemSize, size_t Range[3]) {
38  XPTIRegistry::bufferConstructorNotification(UserObj, CodeLoc, HostObj, Type,
39  Dim, ElemSize, Range);
40 }
41 // TODO: remove once ABI break is allowed
43  void *UserObj) {
44  size_t r[3] = {0, 0, 0};
45  constructorNotification(CodeLoc, UserObj, nullptr, "", 0, 0, r);
46 }
47 
48 void buffer_impl::destructorNotification(void *UserObj) {
49  XPTIRegistry::bufferDestructorNotification(UserObj);
50 }
51 
52 void buffer_impl::addInteropObject(
53  std::vector<pi_native_handle> &Handles) const {
54  if (MOpenCLInterop) {
55  if (std::find(Handles.begin(), Handles.end(),
56  pi::cast<pi_native_handle>(MInteropMemObject)) ==
57  Handles.end()) {
58  const plugin &Plugin = getPlugin();
60  pi::cast<RT::PiMem>(MInteropMemObject));
61  Handles.push_back(pi::cast<pi_native_handle>(MInteropMemObject));
62  }
63  }
64 }
65 
66 std::vector<pi_native_handle>
67 buffer_impl::getNativeVector(backend BackendName) const {
68  std::vector<pi_native_handle> Handles{};
69  if (!MRecord) {
70  addInteropObject(Handles);
71  return Handles;
72  }
73 
74  for (auto &Cmd : MRecord->MAllocaCommands) {
75  RT::PiMem NativeMem = pi::cast<RT::PiMem>(Cmd->getMemAllocation());
76  auto Ctx = Cmd->getWorkerContext();
77  auto Platform = Ctx->getPlatformImpl();
78  // If Host Shared Memory is not supported then there is alloca for host that
79  // doesn't have platform
80  if (!Platform)
81  continue;
82  auto Plugin = Platform->getPlugin();
83 
84  if (Plugin.getBackend() != BackendName)
85  continue;
86  if (Plugin.getBackend() == backend::opencl) {
87  Plugin.call<PiApiKind::piMemRetain>(NativeMem);
88  }
89 
90  pi_native_handle Handle;
91  Plugin.call<PiApiKind::piextMemGetNativeHandle>(NativeMem, &Handle);
92  Handles.push_back(Handle);
93  }
94 
95  addInteropObject(Handles);
96  return Handles;
97 }
98 } // namespace detail
99 } // namespace sycl
100 } // __SYCL_INLINE_NAMESPACE(cl)
_pi_mem
PI Mem mapping to CUDA memory allocations, both data and texture/surface.
Definition: pi_cuda.hpp:221
cl::sycl::backend
backend
Definition: backend_types.hpp:21
cl::sycl::detail::pi::getPlugin
const plugin & getPlugin()
Definition: pi.cpp:513
cl::sycl::detail::ContextImplPtr
std::shared_ptr< detail::context_impl > ContextImplPtr
Definition: memory_manager.hpp:31
context_impl.hpp
xpti_registry.hpp
sycl
Definition: invoke_simd.hpp:68
cl::sycl::detail::code_location
Definition: common.hpp:54
scheduler.hpp
cl::sycl::detail::plugin::call
void call(ArgsT... Args) const
Calls the API, traces the call, checks the result.
Definition: plugin.hpp:217
cl
We provide new interfaces for matrix muliply in this patch:
Definition: access.hpp:13
global_handler.hpp
cl::sycl::image_channel_order::r
@ r
cl::sycl::detail::plugin
The plugin class provides a unified interface to the underlying low-level runtimes for the device-agn...
Definition: plugin.hpp:90
pi_native_handle
uintptr_t pi_native_handle
Definition: pi.h:98
piextMemGetNativeHandle
pi_result piextMemGetNativeHandle(pi_mem mem, pi_native_handle *nativeHandle)
Gets the native handle of a PI mem object.
Definition: pi_esimd_emulator.cpp:1271
piMemRetain
pi_result piMemRetain(pi_mem mem)
Definition: pi_esimd_emulator.cpp:1077
_pi_event
PI Event mapping to CUevent.
Definition: pi_cuda.hpp:590
cl::sycl::detail::constructorNotification
void constructorNotification(void *BufferObj, void *AccessorObj, access::target Target, access::mode Mode, const code_location &CodeLoc)
Definition: accessor_impl.cpp:42
__SYCL_INLINE_NAMESPACE
#define __SYCL_INLINE_NAMESPACE(X)
Definition: defines_elementary.hpp:12
buffer_impl.hpp
memory_manager.hpp