DPC++ Runtime
Runtime libraries for oneAPI Data Parallel C++
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 <CL/sycl/exception.hpp>
21 
23 namespace sycl {
24 class program;
25 
26 namespace ext {
27 namespace oneapi {
28 namespace experimental {
29 
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 cl::sycl::program;
51 
52 public:
53  template <typename V = T>
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>
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 } // namespace sycl
87 } // __SYCL_INLINE_NAMESPACE(cl)
cl::sycl::memory_order
memory_order
Definition: memory_enums.hpp:16
__SYCL2020_DEPRECATED
#define __SYCL2020_DEPRECATED(message)
Definition: defines_elementary.hpp:56
compile_program_error
stl_type_traits.hpp
sycl_fe_intrins.hpp
cl
We provide new interfaces for matrix muliply in this patch:
Definition: access.hpp:13
std::get
constexpr tuple_element< I, tuple< Types... > >::type & get(cl::sycl::detail::tuple< Types... > &Arg) noexcept
Definition: tuple.hpp:199
exception.hpp
cl::sycl::ext::oneapi::experimental::spec_const_error
Definition: spec_constant.hpp:30
cl::sycl::detail::enable_if_t
typename std::enable_if< B, T >::type enable_if_t
Definition: stl_type_traits.hpp:24
__SYCL_INLINE_NAMESPACE
#define __SYCL_INLINE_NAMESPACE(X)
Definition: defines_elementary.hpp:12