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 <CL/sycl/detail/pi.hpp>
12 #include <CL/sycl/stl.hpp>
13 
15 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 getSize() const = 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 } // namespace sycl
81 } // __SYCL_INLINE_NAMESPACE(cl)
cl::sycl::detail::Scheduler
DPC++ graph scheduler class.
Definition: scheduler.hpp:358
cl::sycl::detail::ExecCGCommand
The exec CG command enqueues execution of kernel or explicit memory operation.
Definition: commands.hpp:539
cl::sycl::detail::ContextImplPtr
std::shared_ptr< detail::context_impl > ContextImplPtr
Definition: memory_manager.hpp:31
stl.hpp
sycl
Definition: invoke_simd.hpp:68
pi.hpp
cl::sycl::detail::SYCLMemObjI::MemObjType
MemObjType
Definition: sycl_mem_obj_i.hpp:32
cl::sycl::detail::SYCLMemObjI::MRecord
std::shared_ptr< MemObjRecord > MRecord
Definition: sycl_mem_obj_i.hpp:74
cl::sycl::detail::EventImplPtr
std::shared_ptr< detail::event_impl > EventImplPtr
Definition: memory_manager.hpp:30
cl
We provide new interfaces for matrix muliply in this patch:
Definition: access.hpp:13
_pi_event
PI Event mapping to CUevent.
Definition: pi_cuda.hpp:590
cl::sycl::detail::SYCLMemObjI
Definition: sycl_mem_obj_i.hpp:28
__SYCL_INLINE_NAMESPACE
#define __SYCL_INLINE_NAMESPACE(X)
Definition: defines_elementary.hpp:12