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 
13 namespace sycl {
14 inline namespace _V1 {
15 
16 namespace detail {
17 
18 class event_impl;
19 class context_impl;
20 struct MemObjRecord;
21 
22 using EventImplPtr = std::shared_ptr<detail::event_impl>;
23 using ContextImplPtr = std::shared_ptr<detail::context_impl>;
24 
25 // The class serves as an interface in the scheduler for all SYCL memory
26 // objects.
27 class SYCLMemObjI {
28 public:
29  virtual ~SYCLMemObjI() = default;
30 
31  enum MemObjType { Buffer = 0, Image = 1, Undefined = 2 };
32 
33  virtual MemObjType getType() const = 0;
34 
35  // The method allocates memory for the SYCL memory object. The size of
36  // allocation will be taken from the size of SYCL memory object.
37  // If the memory returned cannot be used right away InteropEvent will
38  // point to event that should be waited before using the memory.
39  // InitFromUserData indicates that the returned memory should be intialized
40  // with the data provided by user(if any). Usually it should happen on the
41  // first allocation of memory for the memory object.
42  // Non null HostPtr requires allocation to be made with USE_HOST_PTR property.
43  // Method returns a pointer to host allocation if Context is host one and
44  // cl_mem obect if not.
45  virtual void *allocateMem(ContextImplPtr Context, bool InitFromUserData,
46  void *HostPtr,
47  sycl::detail::pi::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  virtual bool isInterop() const = 0;
65 
66  virtual bool hasUserDataPtr() const = 0;
67 
68  virtual bool isHostPointerReadOnly() const = 0;
69 
70  virtual bool usesPinnedHostMemory() const = 0;
71 
72  // Returns the context which is passed if a memory object is created using
73  // interoperability constructor, nullptr otherwise.
74  virtual ContextImplPtr getInteropContext() const = 0;
75 
76 protected:
77  // Pointer to the record that contains the memory commands. This is managed
78  // by the scheduler.
79  // fixme replace with std::unique_ptr once it is implemented. Standard
80  // unique_ptr requires knowlege of sizeof(MemObjRecord) at compile time
81  // which is unavailable.
82  std::shared_ptr<MemObjRecord> MRecord;
83  friend class Scheduler;
84  friend class ExecCGCommand;
85 };
86 
87 } // namespace detail
88 } // namespace _V1
89 } // namespace sycl
The exec CG command enqueues execution of kernel or explicit memory operation.
Definition: commands.hpp:647
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:367
std::shared_ptr< sycl::detail::context_impl > ContextImplPtr
Definition: event_impl.hpp:32
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:202