DPC++ Runtime
Runtime libraries for oneAPI DPC++
physical_mem.hpp
Go to the documentation of this file.
1 //==--- physical_mem.hpp - sycl_ext_oneapi_virtual_mem physical_mem class --==//
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/access/access.hpp>
12 #include <sycl/context.hpp>
13 #include <sycl/detail/common.hpp>
15 #include <sycl/device.hpp>
16 #include <sycl/queue.hpp>
17 
18 namespace sycl {
19 inline namespace _V1 {
20 
21 namespace detail {
22 class physical_mem_impl;
23 } // namespace detail
24 
25 namespace ext::oneapi::experimental {
26 
27 enum class address_access_mode : char { none = 0, read = 1, read_write = 2 };
28 
29 class __SYCL_EXPORT physical_mem
30  : public sycl::detail::OwnerLessBase<physical_mem> {
31 public:
32  physical_mem(const device &SyclDevice, const context &SyclContext,
33  size_t NumBytes);
34 
35  physical_mem(const queue &SyclQueue, size_t NumBytes)
36  : physical_mem(SyclQueue.get_device(), SyclQueue.get_context(),
37  NumBytes) {}
38 
39  physical_mem(const physical_mem &rhs) = default;
40  physical_mem(physical_mem &&rhs) = default;
41 
42  physical_mem &operator=(const physical_mem &rhs) = default;
43  physical_mem &operator=(physical_mem &&rhs) = default;
44 
45  ~physical_mem() noexcept(false) {};
46 
47  bool operator==(const physical_mem &rhs) const { return impl == rhs.impl; }
48  bool operator!=(const physical_mem &rhs) const { return !(*this == rhs); }
49 
50  void *map(uintptr_t Ptr, size_t NumBytes, address_access_mode Mode,
51  size_t Offset = 0) const;
52 
53  context get_context() const;
54  device get_device() const;
55 
56  size_t size() const noexcept;
57 
58 private:
59  std::shared_ptr<sycl::detail::physical_mem_impl> impl;
60 
61  template <class Obj>
62  friend const decltype(Obj::impl) &
63  sycl::detail::getSyclObjImpl(const Obj &SyclObject);
64 
65  template <class T>
66  friend T sycl::detail::createSyclObjFromImpl(decltype(T::impl) ImplObj);
67 };
68 
69 } // namespace ext::oneapi::experimental
70 } // namespace _V1
71 } // namespace sycl
72 
73 namespace std {
74 template <> struct hash<sycl::ext::oneapi::experimental::physical_mem> {
75  size_t operator()(
76  const sycl::ext::oneapi::experimental::physical_mem &PhysicalMem) const {
77  return hash<std::shared_ptr<sycl::detail::physical_mem_impl>>()(
78  sycl::detail::getSyclObjImpl(PhysicalMem));
79  }
80 };
81 } // namespace std
The context class represents a SYCL context on which kernel functions may be executed.
Definition: context.hpp:50
The SYCL device class encapsulates a single SYCL device on which kernels may be executed.
Definition: device.hpp:64
bool operator!=(const physical_mem &rhs) const
physical_mem(const queue &SyclQueue, size_t NumBytes)
physical_mem & operator=(physical_mem &&rhs)=default
physical_mem & operator=(const physical_mem &rhs)=default
physical_mem(const physical_mem &rhs)=default
bool operator==(const physical_mem &rhs) const
Encapsulates a single SYCL queue which schedules kernels on a SYCL device.
Definition: queue.hpp:110
decltype(Obj::impl) const & getSyclObjImpl(const Obj &SyclObject)
Definition: impl_utils.hpp:31
T createSyclObjFromImpl(decltype(T::impl) ImplObj)
Definition: impl_utils.hpp:40
Definition: access.hpp:18
static device_ext & get_device(unsigned int id)
Util function to get a device by id.
Definition: device.hpp:915
_Abi const simd< _Tp, _Abi > & noexcept
Definition: simd.hpp:1324
size_t operator()(const sycl::ext::oneapi::experimental::physical_mem &PhysicalMem) const