DPC++ Runtime
Runtime libraries for oneAPI DPC++
sycl_mem_obj_i.hpp
Go to the documentation of this file.
1 //==------------ sycl_mem_obj_i.hpp - 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 
9 #pragma once
10 
11 #include <sycl/detail/pi.hpp>
12 #include <sycl/stl.hpp>
13 
14 namespace sycl {
16 
17 namespace detail {
18 
19 class event_impl;
20 class context_impl;
21 struct MemObjRecord;
22 
23 using EventImplPtr = std::shared_ptr<detail::event_impl>;
24 using ContextImplPtr = std::shared_ptr<detail::context_impl>;
25 
26 // The class serves as an interface in the scheduler for all SYCL memory
27 // objects.
28 class SYCLMemObjI {
29 public:
30  virtual ~SYCLMemObjI() = default;
31 
32  enum MemObjType { Buffer = 0, Image = 1, Undefined = 2 };
33 
34  virtual MemObjType getType() const = 0;
35 
36  // The method allocates memory for the SYCL memory object. The size of
37  // allocation will be taken from the size of SYCL memory object.
38  // If the memory returned cannot be used right away InteropEvent will
39  // point to event that should be waited before using the memory.
40  // InitFromUserData indicates that the returned memory should be intialized
41  // with the data provided by user(if any). Usually it should happen on the
42  // first allocation of memory for the memory object.
43  // Non null HostPtr requires allocation to be made with USE_HOST_PTR property.
44  // Method returns a pointer to host allocation if Context is host one and
45  // cl_mem obect if not.
46  virtual void *allocateMem(ContextImplPtr Context, bool InitFromUserData,
47  void *HostPtr, RT::PiEvent &InteropEvent) = 0;
48 
49  // Should be used for memory object created without use_host_ptr property.
50  virtual void *allocateHostMem() = 0;
51 
52  // Ptr must be a pointer returned by allocateMem for the same context.
53  // If Context is a device context and Ptr is a host pointer exception will be
54  // thrown. And it's undefined behaviour if Context is a host context and Ptr
55  // is a device pointer.
56  virtual void releaseMem(ContextImplPtr Context, void *Ptr) = 0;
57 
58  // Ptr must be a pointer returned by allocateHostMem.
59  virtual void releaseHostMem(void *Ptr) = 0;
60 
61  // Returns size of object in bytes
62  virtual size_t getSizeInBytes() const noexcept = 0;
63 
64  // Returns the context which is passed if a memory object is created using
65  // interoperability constructor, nullptr otherwise.
66  virtual ContextImplPtr getInteropContext() const = 0;
67 
68 protected:
69  // Pointer to the record that contains the memory commands. This is managed
70  // by the scheduler.
71  // fixme replace with std::unique_ptr once it is implemented. Standard
72  // unique_ptr requires knowlege of sizeof(MemObjRecord) at compile time
73  // which is unavailable.
74  std::shared_ptr<MemObjRecord> MRecord;
75  friend class Scheduler;
76  friend class ExecCGCommand;
77 };
78 
79 } // namespace detail
80 } // __SYCL_INLINE_VER_NAMESPACE(_V1)
81 } // namespace sycl
sycl::_V1::detail::ContextImplPtr
std::shared_ptr< sycl::detail::context_impl > ContextImplPtr
Definition: event_impl.hpp:30
stl.hpp
__SYCL_INLINE_VER_NAMESPACE
#define __SYCL_INLINE_VER_NAMESPACE(X)
Definition: defines_elementary.hpp:11
sycl
---— Error handling, matching OpenCL plugin semantics.
Definition: access.hpp:14
pi.hpp
sycl::_V1::detail::MemObjRecord
Memory Object Record.
Definition: scheduler.hpp:198
sycl::_V1::detail::EventImplPtr
std::shared_ptr< event_impl > EventImplPtr
Definition: cg.hpp:42
sycl::_V1::detail::ExecCGCommand
The exec CG command enqueues execution of kernel or explicit memory operation.
Definition: commands.hpp:618
std
Definition: accessor.hpp:3914
sycl::_V1::detail::SYCLMemObjI
Definition: sycl_mem_obj_i.hpp:28
sycl::_V1::detail::SYCLMemObjI::MemObjType
MemObjType
Definition: sycl_mem_obj_i.hpp:32
sycl::_V1::detail::Scheduler
DPC++ graph scheduler class.
Definition: scheduler.hpp:363
sycl::_V1::detail::pi::PiEvent
::pi_event PiEvent
Definition: pi.hpp:138