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::oneapi::experimental {
26 
28  using compile_program_error::compile_program_error;
29 };
30 
31 template <typename T, typename ID = T>
33  "Specialization constats extension is deprecated, use SYCL 2020"
34  " specialization constants instead")
35  __SYCL_TYPE(spec_constant) spec_constant {
36 public:
37  spec_constant() {}
38 
39 private:
40 #ifndef __SYCL_DEVICE_ONLY__
41  // Implementation defined constructor.
42  spec_constant(T Cst) : Val(Cst) {}
43 
44  T Val;
45 #else
46  char padding[sizeof(T)];
47 #endif // __SYCL_DEVICE_ONLY__
48 
49 public:
50  template <typename V = T>
51  typename sycl::detail::enable_if_t<std::is_arithmetic<V>::value, V>
52  get() const { // explicit access.
53 #ifdef __SYCL_DEVICE_ONLY__
54  const char *TName = __builtin_sycl_unique_stable_name(ID);
55  return __sycl_getScalarSpecConstantValue<T>(TName);
56 #else
57  return Val;
58 #endif // __SYCL_DEVICE_ONLY__
59  }
60 
61  template <typename V = T>
62  typename sycl::detail::enable_if_t<std::is_class<V>::value &&
63  std::is_pod<V>::value,
64  V>
65  get() const { // explicit access.
66 #ifdef __SYCL_DEVICE_ONLY__
67  const char *TName = __builtin_sycl_unique_stable_name(ID);
68  return __sycl_getCompositeSpecConstantValue<T>(TName);
69 #else
70  return Val;
71 #endif // __SYCL_DEVICE_ONLY__
72  }
73 
74  operator T() const { // implicit conversion.
75  return get();
76  }
77 };
78 
79 } // namespace ext::oneapi::experimental
80 
81 } // __SYCL_INLINE_VER_NAMESPACE(_V1)
82 } // namespace sycl
__SYCL_INLINE_VER_NAMESPACE
#define __SYCL_INLINE_VER_NAMESPACE(X)
Definition: defines_elementary.hpp:11
sycl
---— Error handling, matching OpenCL plugin semantics.
Definition: access.hpp:14
compile_program_error
stl_type_traits.hpp
sycl::_V1::ext::oneapi::experimental::spec_const_error
Definition: spec_constant.hpp:27
std::get
constexpr tuple_element< I, tuple< Types... > >::type & get(sycl::detail::tuple< Types... > &Arg) noexcept
Definition: tuple.hpp:199
sycl_fe_intrins.hpp
exception.hpp
__SYCL_TYPE
#define __SYCL_TYPE(x)
Definition: defines.hpp:40
sycl::_V1::ext::oneapi::experimental::matrix::use
use
Definition: matrix-unified-utils.hpp:17
sycl::_V1::ext::oneapi::instead
sycl::memory_order instead
Definition: atomic_enums.hpp:27
__SYCL2020_DEPRECATED
#define __SYCL2020_DEPRECATED(message)
Definition: defines_elementary.hpp:57