DPC++ Runtime
Runtime libraries for oneAPI DPC++
spec_constant.hpp
Go to the documentation of this file.
1 //==----------- spec_constant.hpp - SYCL public oneapi API 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 // Based on:
10 // https://github.com/codeplaysoftware/standards-proposals/blob/master/spec-constant/index.md
11 // TODO:
12 // 1) implement the SPIR-V interop part of the proposal
13 // 2) move to the new upcoming spec constant specification (then 1 above is not
14 // needed)
15 
16 #pragma once
17 
20 #include <sycl/exception.hpp>
21 
22 namespace sycl {
24 class program;
25 
26 namespace ext {
27 namespace oneapi {
28 namespace experimental {
29 
30 class spec_const_error : public compile_program_error {
31  using compile_program_error::compile_program_error;
32 };
33 
34 template <typename T, typename ID = T>
36  "Specialization constats extension is deprecated, use SYCL 2020"
37  " specialization constants instead") spec_constant {
38 public:
39  spec_constant() {}
40 
41 private:
42 #ifndef __SYCL_DEVICE_ONLY__
43  // Implementation defined constructor.
44  spec_constant(T Cst) : Val(Cst) {}
45 
46  T Val;
47 #else
48  char padding[sizeof(T)];
49 #endif // __SYCL_DEVICE_ONLY__
50  friend class sycl::program;
51 
52 public:
53  template <typename V = T>
54  typename sycl::detail::enable_if_t<std::is_arithmetic<V>::value, V>
55  get() const { // explicit access.
56 #ifdef __SYCL_DEVICE_ONLY__
57  const char *TName = __builtin_sycl_unique_stable_name(ID);
58  return __sycl_getScalarSpecConstantValue<T>(TName);
59 #else
60  return Val;
61 #endif // __SYCL_DEVICE_ONLY__
62  }
63 
64  template <typename V = T>
65  typename sycl::detail::enable_if_t<std::is_class<V>::value &&
66  std::is_pod<V>::value,
67  V>
68  get() const { // explicit access.
69 #ifdef __SYCL_DEVICE_ONLY__
70  const char *TName = __builtin_sycl_unique_stable_name(ID);
71  return __sycl_getCompositeSpecConstantValue<T>(TName);
72 #else
73  return Val;
74 #endif // __SYCL_DEVICE_ONLY__
75  }
76 
77  operator T() const { // implicit conversion.
78  return get();
79  }
80 };
81 
82 } // namespace experimental
83 } // namespace oneapi
84 } // namespace ext
85 
86 } // __SYCL_INLINE_VER_NAMESPACE(_V1)
87 } // namespace sycl
sycl::__SYCL_INLINE_VER_NAMESPACE
__SYCL_INLINE_VER_NAMESPACE(_V1)
Definition: access.hpp:14
sycl
We provide new interfaces for matrix muliply in this patch:
Definition: access.hpp:13
stl_type_traits.hpp
std::get
constexpr tuple_element< I, tuple< Types... > >::type & get(sycl::detail::tuple< Types... > &Arg) noexcept
Definition: tuple.hpp:199
__SYCL2020_DEPRECATED
namespace __SYCL2020_DEPRECATED("cl::sycl is deprecated, use ::sycl instead.") cl
Definition: sycl.hpp:13
sycl_fe_intrins.hpp
exception.hpp