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 {
15 inline namespace _V1 {
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,
48  sycl::detail::pi::PiEvent &InteropEvent) = 0;
49 
50  // Should be used for memory object created without use_host_ptr property.
51  virtual void *allocateHostMem() = 0;
52 
53  // Ptr must be a pointer returned by allocateMem for the same context.
54  // If Context is a device context and Ptr is a host pointer exception will be
55  // thrown. And it's undefined behaviour if Context is a host context and Ptr
56  // is a device pointer.
57  virtual void releaseMem(ContextImplPtr Context, void *Ptr) = 0;
58 
59  // Ptr must be a pointer returned by allocateHostMem.
60  virtual void releaseHostMem(void *Ptr) = 0;
61 
62  // Returns size of object in bytes
63  virtual size_t getSizeInBytes() const noexcept = 0;
64 
65  virtual bool isInterop() const = 0;
66 
67  virtual bool hasUserDataPtr() const = 0;
68 
69  virtual bool isHostPointerReadOnly() const = 0;
70 
71  virtual bool usesPinnedHostMemory() const = 0;
72 
73  // Returns the context which is passed if a memory object is created using
74  // interoperability constructor, nullptr otherwise.
75  virtual ContextImplPtr getInteropContext() const = 0;
76 
77 protected:
78  // Pointer to the record that contains the memory commands. This is managed
79  // by the scheduler.
80  // fixme replace with std::unique_ptr once it is implemented. Standard
81  // unique_ptr requires knowlege of sizeof(MemObjRecord) at compile time
82  // which is unavailable.
83  std::shared_ptr<MemObjRecord> MRecord;
84  friend class Scheduler;
85  friend class ExecCGCommand;
86 };
87 
88 } // namespace detail
89 } // namespace _V1
90 } // namespace sycl
The exec CG command enqueues execution of kernel or explicit memory operation.
Definition: commands.hpp:641
virtual bool isHostPointerReadOnly() const =0
virtual void * allocateHostMem()=0
virtual ContextImplPtr getInteropContext() const =0
virtual size_t getSizeInBytes() const noexcept=0
virtual void releaseMem(ContextImplPtr Context, void *Ptr)=0
virtual bool isInterop() const =0
virtual bool hasUserDataPtr() const =0
virtual MemObjType getType() const =0
virtual void releaseHostMem(void *Ptr)=0
std::shared_ptr< MemObjRecord > MRecord
virtual bool usesPinnedHostMemory() const =0
virtual ~SYCLMemObjI()=default
virtual void * allocateMem(ContextImplPtr Context, bool InitFromUserData, void *HostPtr, sycl::detail::pi::PiEvent &InteropEvent)=0
DPC++ graph scheduler class.
Definition: scheduler.hpp:363
std::shared_ptr< sycl::detail::context_impl > ContextImplPtr
Definition: event_impl.hpp:33
std::shared_ptr< event_impl > EventImplPtr
Definition: cg.hpp:43
Definition: access.hpp:18
C++ wrapper of extern "C" PI interfaces.
_Abi const simd< _Tp, _Abi > & noexcept
Definition: simd.hpp:1324
Memory Object Record.
Definition: scheduler.hpp:198