DPC++ Runtime
Runtime libraries for oneAPI DPC++
fpga_mem.hpp
Go to the documentation of this file.
1 //==----------- fpga_mem.hpp - SYCL fpga_mem extension -----------==//
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> // for address_space
12 #include <sycl/exception.hpp> // for make_error_code
14 #include <sycl/ext/oneapi/properties/properties.hpp> // for properties_t
15 
16 #include <cstddef> // for ptrdiff_t
17 #include <type_traits> // for enable_if_t
18 #include <utility> // for declval
19 
20 namespace sycl {
21 inline namespace _V1 {
22 namespace ext::intel::experimental {
23 
24 // Primary template should never be deduced. Needed to establish which
25 // parameters fpga_mem can be templated on
26 template <typename T, typename PropertyListT =
28 class fpga_mem {
29 
30  static_assert(
32  "Property list is invalid.");
33 };
34 
35 // Template specialization that all calls should use. Separates Props from
36 // properties_t which allows the class to apply Props as attributes.
37 template <typename T, typename... Props>
38 class
39 #ifdef __SYCL_DEVICE_ONLY__
40  [[__sycl_detail__::add_ir_attributes_global_variable(
41  "sycl-resource",
43  "DEFAULT",
45 #endif
47 
48 protected:
49  T val
50 #ifdef __SYCL_DEVICE_ONLY__
51  // In addition to annotating all the user specified properties, also add
52  // {"sycl-resource", ""} hinting to the optimizer that this object
53  // should be implemented in memory outside the datapath.
54  [[__sycl_detail__::add_ir_annotations_member(
55  "sycl-resource",
57  "DEFAULT",
59  Props>::value...)]]
60 #endif
61  ;
62 
63 public:
64  using element_type = std::remove_extent_t<T>;
65 
66  // All the initialization
67  // constexpr is used as a hint to the compiler to try and evaluate the
68  // constructor at compile-time
69  template <typename... S> constexpr fpga_mem(S... args) : val{args...} {}
70 
71  fpga_mem() = default;
72 
73  fpga_mem(const fpga_mem &) = default;
74  fpga_mem(fpga_mem &&) = default;
75  fpga_mem &operator=(const fpga_mem &) = default;
76  fpga_mem &operator=(fpga_mem &&) = default;
77 
78  T &get() noexcept { return val; }
79 
80  constexpr const T &get() const noexcept { return val; }
81 
82  // Allows for implicit conversion from this to T
83  operator T &() noexcept { return get(); }
84 
85  // Allows for implicit conversion from this to T
86  constexpr operator const T &() const noexcept { return get(); }
87 
88  fpga_mem &operator=(const T &newValue) noexcept {
89  val = newValue;
90  return *this;
91  }
92 
93  // Note that there is no need for "fpga_mem" to define member functions
94  // for operators like "++", "[]", "->", comparison, etc. Instead, the type
95  // "T" need only define these operators as non-member functions. Because
96  // there is an implicit conversion from "fpga_mem" to "T&".
97 
98  template <typename propertyT> static constexpr bool has_property() {
100  Props...>::template has_property<propertyT>();
101  }
102 
103  template <typename propertyT> static constexpr auto get_property() {
105  Props...>::template get_property<propertyT>();
106  }
107 };
108 
109 } // namespace ext::intel::experimental
110 } // namespace _V1
111 } // namespace sycl
decltype(properties{}) empty_properties_t
Definition: properties.hpp:190
pointer get() const
Definition: multi_ptr.hpp:544
Definition: access.hpp:18
_Abi const simd< _Tp, _Abi > & noexcept
Definition: simd.hpp:1324