DPC++ Runtime
Runtime libraries for oneAPI DPC++
bindless_images_memory.hpp
Go to the documentation of this file.
1 //==----------- bindless_images_memory.hpp --- SYCL bindless images --------==//
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/context.hpp>
12 #include <sycl/detail/export.hpp>
13 #include <sycl/device.hpp>
16 #include <sycl/image.hpp>
17 #include <sycl/range.hpp>
18 
19 #include <cstddef>
20 #include <memory>
21 #include <variant>
22 
23 namespace sycl {
24 inline namespace _V1 {
25 
26 // Forward declaration
27 class queue;
28 
29 namespace ext::oneapi::experimental {
30 
31 namespace detail {
32 
35 
36 public:
37  __SYCL_EXPORT image_mem_impl(const image_descriptor &desc,
38  const device &syclDevice,
39  const context &syclContext);
40  __SYCL_EXPORT ~image_mem_impl();
41 
42  raw_handle_type get_handle() const { return handle; }
43  const image_descriptor &get_descriptor() const { return descriptor; }
44  sycl::device get_device() const { return syclDevice; }
45  sycl::context get_context() const { return syclContext; }
46 
47 private:
48  raw_handle_type handle{0};
49  image_descriptor descriptor;
50  sycl::device syclDevice;
51  sycl::context syclContext;
52 };
53 
54 } // namespace detail
55 
57 class __SYCL_EXPORT image_mem {
59 
60 public:
61  image_mem() = default;
62  image_mem(const image_mem &) = default;
63  image_mem(image_mem &&rhs) = default;
64 
65  image_mem(const image_descriptor &desc, const device &syclDevice,
66  const context &syclContext);
67  image_mem(const image_descriptor &desc, const queue &syclQueue);
68  ~image_mem() = default;
69 
70  image_mem &operator=(const image_mem &) = default;
71  image_mem &operator=(image_mem &&) = default;
72 
73  bool operator==(const image_mem &rhs) const { return impl == rhs.impl; }
74  bool operator!=(const image_mem &rhs) const { return !(*this == rhs); }
75 
76  raw_handle_type get_handle() const { return impl->get_handle(); }
78  return impl->get_descriptor();
79  }
80  sycl::device get_device() const { return impl->get_device(); }
81  sycl::context get_context() const { return impl->get_context(); }
82 
83  sycl::range<3> get_range() const;
84  sycl::image_channel_type get_channel_type() const;
85  sycl::image_channel_order get_channel_order() const;
86  unsigned int get_num_channels() const;
87  image_type get_type() const;
88 
89  raw_handle_type get_mip_level_mem_handle(const unsigned int level) const;
90 
91 protected:
92  std::shared_ptr<detail::image_mem_impl> impl;
93 
94  template <class Obj>
95  friend const decltype(Obj::impl) &
96  sycl::detail::getSyclObjImpl(const Obj &SyclObject);
97 };
98 
101 enum image_copy_flags : unsigned int {
102  HtoD = 0,
103  DtoH = 1,
104  DtoD = 2,
105 };
106 
107 } // namespace ext::oneapi::experimental
108 } // namespace _V1
109 } // namespace sycl
110 
111 namespace std {
112 template <> struct hash<sycl::ext::oneapi::experimental::image_mem> {
113  size_t operator()(
114  const sycl::ext::oneapi::experimental::image_mem &image_mem) const {
115  return hash<std::shared_ptr<
117  sycl::detail::getSyclObjImpl(image_mem));
118  }
119 };
120 } // 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
image_mem_impl(const image_descriptor &desc, const device &syclDevice, const context &syclContext)
image_mem(const image_descriptor &desc, const device &syclDevice, const context &syclContext)
image_mem(const image_descriptor &desc, const queue &syclQueue)
std::shared_ptr< detail::image_mem_impl > impl
image_mem & operator=(const image_mem &)=default
image_mem & operator=(image_mem &&)=default
Encapsulates a single SYCL queue which schedules kernels on a SYCL device.
Definition: queue.hpp:110
Defines the iteration domain of either a single work-group in a parallel dispatch,...
Definition: range.hpp:26
decltype(Obj::impl) const & getSyclObjImpl(const Obj &SyclObject)
Definition: impl_utils.hpp:31
image_copy_flags
Direction to copy data from bindless image handle (Host -> Device) (Device -> Host) etc.
image_mem_handle get_mip_level_mem_handle(const image_mem_handle mipMem, unsigned int level, const sycl::device &syclDevice, const sycl::context &syclContext)
Retrieve the memory handle to an individual mipmap image.
image_channel_order
Definition: image.hpp:56
image_channel_type
Definition: image.hpp:74
Definition: access.hpp:18
size_t operator()(const sycl::ext::oneapi::experimental::image_mem &image_mem) const
A struct to describe the properties of an image.