DPC++ Runtime
Runtime libraries for oneAPI Data Parallel C++
kernel_handler.hpp
Go to the documentation of this file.
1 //==------ kernel_handler.hpp -- SYCL standard header file -----*- C++ -*---==//
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 
13 #include <CL/sycl/exception.hpp>
14 
15 #include <type_traits>
16 
18 namespace sycl {
23 public:
24 #if __cplusplus > 201402L
25  template <auto &S>
26  typename std::remove_reference_t<decltype(S)>::value_type
27  get_specialization_constant() {
28 #ifdef __SYCL_DEVICE_ONLY__
29  return getSpecializationConstantOnDevice<S>();
30 #else
31  // TODO: add support of host device
32  throw cl::sycl::feature_not_supported(
33  "kernel_handler::get_specialization_constant() is not yet supported by "
34  "host device.",
36 #endif // __SYCL_DEVICE_ONLY__
37  }
38 #endif // __cplusplus > 201402L
39 
40 private:
41  void __init_specialization_constants_buffer(
42  char *SpecializationConstantsBuffer = nullptr) {
43  MSpecializationConstantsBuffer = SpecializationConstantsBuffer;
44  }
45 
46 #ifdef __SYCL_DEVICE_ONLY__
47 #if __cplusplus >= 201703L
48  template <
49  auto &S,
50  typename T = typename std::remove_reference_t<decltype(S)>::value_type,
51  std::enable_if_t<std::is_fundamental_v<T>> * = nullptr>
52  T getSpecializationConstantOnDevice() {
53  const char *SymbolicID = __builtin_sycl_unique_stable_id(S);
54  return __sycl_getScalar2020SpecConstantValue<T>(
55  SymbolicID, &S, MSpecializationConstantsBuffer);
56  }
57  template <
58  auto &S,
59  typename T = typename std::remove_reference_t<decltype(S)>::value_type,
60  std::enable_if_t<std::is_compound_v<T>> * = nullptr>
61  T getSpecializationConstantOnDevice() {
62  const char *SymbolicID = __builtin_sycl_unique_stable_id(S);
63  return __sycl_getComposite2020SpecConstantValue<T>(
64  SymbolicID, &S, MSpecializationConstantsBuffer);
65  }
66 #endif // __cplusplus >= 201703L
67 #endif // __SYCL_DEVICE_ONLY__
68 
69  char *MSpecializationConstantsBuffer = nullptr;
70 };
71 
72 } // namespace sycl
73 } // __SYCL_INLINE_NAMESPACE(cl)
PI_INVALID_OPERATION
@ PI_INVALID_OPERATION
Definition: pi.h:85
cl::sycl::detail::remove_reference_t
typename std::remove_reference< T >::type remove_reference_t
Definition: stl_type_traits.hpp:35
sycl_fe_intrins.hpp
cl
We provide new interfaces for matrix muliply in this patch:
Definition: access.hpp:13
cl::sycl::kernel_handler
Reading the value of a specialization constant.
Definition: kernel_handler.hpp:22
exception.hpp
kernel_desc.hpp
__SYCL_INLINE_NAMESPACE
#define __SYCL_INLINE_NAMESPACE(X)
Definition: defines_elementary.hpp:12