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> // for context
12 #include <sycl/detail/export.hpp> // for __SYCL_EXPORT
13 #include <sycl/device.hpp> // for device
14 #include <sycl/ext/oneapi/bindless_images_descriptor.hpp> // for image_desc...
15 #include <sycl/image.hpp> // for image_chan...
16 #include <sycl/range.hpp> // for range
17 
18 #include <cstddef> // for size_t
19 #include <memory> // for shared_ptr
20 #include <variant> // for hash
21 
22 namespace sycl {
23 inline namespace _V1 {
24 
25 // Forward declaration
26 class queue;
27 
28 namespace ext::oneapi::experimental {
29 
32  using handle_type = void *;
34 };
35 
36 namespace detail {
37 
40 
41 public:
42  __SYCL_EXPORT image_mem_impl(const image_descriptor &desc,
43  const device &syclDevice,
44  const context &syclContext);
45  __SYCL_EXPORT ~image_mem_impl();
46 
47  raw_handle_type get_handle() const { return handle; }
48  const image_descriptor &get_descriptor() const { return descriptor; }
49  sycl::device get_device() const { return syclDevice; }
50  sycl::context get_context() const { return syclContext; }
51 
52 private:
53  raw_handle_type handle{nullptr};
54  image_descriptor descriptor;
55  sycl::device syclDevice;
56  sycl::context syclContext;
57 };
58 
59 } // namespace detail
60 
62 class __SYCL_EXPORT image_mem {
64 
65 public:
66  image_mem() = default;
67  image_mem(const image_mem &) = default;
68  image_mem(image_mem &&rhs) = default;
69 
70  image_mem(const image_descriptor &desc, const device &syclDevice,
71  const context &syclContext);
72  image_mem(const image_descriptor &desc, const queue &syclQueue);
73  ~image_mem() = default;
74 
75  image_mem &operator=(const image_mem &) = default;
76  image_mem &operator=(image_mem &&) = default;
77 
78  bool operator==(const image_mem &rhs) const { return impl == rhs.impl; }
79  bool operator!=(const image_mem &rhs) const { return !(*this == rhs); }
80 
81  raw_handle_type get_handle() const { return impl->get_handle(); }
83  return impl->get_descriptor();
84  }
85  sycl::device get_device() const { return impl->get_device(); }
86  sycl::context get_context() const { return impl->get_context(); }
87 
88  sycl::range<3> get_range() const;
89  sycl::image_channel_type get_channel_type() const;
90  sycl::image_channel_order get_channel_order() const;
91  unsigned int get_num_channels() const;
92  image_type get_type() const;
93 
94  raw_handle_type get_mip_level_mem_handle(const unsigned int level) const;
95 
96 protected:
97  std::shared_ptr<detail::image_mem_impl> impl;
98 
99  template <class Obj>
100  friend decltype(Obj::impl)
101  sycl::detail::getSyclObjImpl(const Obj &SyclObject);
102 };
103 
106 enum image_copy_flags : unsigned int {
107  HtoD = 0,
108  DtoH = 1,
109  DtoD = 2,
110 };
111 
112 } // namespace ext::oneapi::experimental
113 } // namespace _V1
114 } // namespace sycl
115 
116 namespace std {
117 template <> struct hash<sycl::ext::oneapi::experimental::image_mem> {
118  size_t operator()(
119  const sycl::ext::oneapi::experimental::image_mem &image_mem) const {
120  return hash<std::shared_ptr<
122  sycl::detail::getSyclObjImpl(image_mem));
123  }
124 };
125 } // 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:111
Defines the iteration domain of either a single work-group in a parallel dispatch,...
Definition: range.hpp:26
decltype(Obj::impl) getSyclObjImpl(const Obj &SyclObject)
Definition: impl_utils.hpp:30
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, const 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.