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 
25 namespace ext {
26 namespace oneapi {
27 namespace experimental {
28 
30  using compile_program_error::compile_program_error;
31 };
32 
33 template <typename T, typename ID = T>
35  "Specialization constats extension is deprecated, use SYCL 2020"
36  " specialization constants instead")
37  __SYCL_TYPE(spec_constant) 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 
51 public:
52  template <typename V = T>
53  typename sycl::detail::enable_if_t<std::is_arithmetic<V>::value, V>
54  get() const { // explicit access.
55 #ifdef __SYCL_DEVICE_ONLY__
56  const char *TName = __builtin_sycl_unique_stable_name(ID);
57  return __sycl_getScalarSpecConstantValue<T>(TName);
58 #else
59  return Val;
60 #endif // __SYCL_DEVICE_ONLY__
61  }
62 
63  template <typename V = T>
64  typename sycl::detail::enable_if_t<std::is_class<V>::value &&
65  std::is_pod<V>::value,
66  V>
67  get() const { // explicit access.
68 #ifdef __SYCL_DEVICE_ONLY__
69  const char *TName = __builtin_sycl_unique_stable_name(ID);
70  return __sycl_getCompositeSpecConstantValue<T>(TName);
71 #else
72  return Val;
73 #endif // __SYCL_DEVICE_ONLY__
74  }
75 
76  operator T() const { // implicit conversion.
77  return get();
78  }
79 };
80 
81 } // namespace experimental
82 } // namespace oneapi
83 } // namespace ext
84 
85 } // __SYCL_INLINE_VER_NAMESPACE(_V1)
86 } // namespace sycl
#define __SYCL_TYPE(x)
Definition: defines.hpp:33
#define __SYCL_INLINE_VER_NAMESPACE(X)
#define __SYCL2020_DEPRECATED(message)
constexpr tuple_element< I, tuple< Types... > >::type & get(sycl::detail::tuple< Types... > &Arg) noexcept
Definition: tuple.hpp:199
sycl::memory_order instead
---— Error handling, matching OpenCL plugin semantics.
Definition: access.hpp:14