DPC++ Runtime
Runtime libraries for oneAPI DPC++
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 
11 #include <sycl/detail/defines.hpp> // for __SYCL_TYPE
12 #include <sycl/detail/defines_elementary.hpp> // for __SYCL_ALWAYS_INLINE
13 #include <sycl/exception.hpp> // for feature_not_supported
14 
15 #ifdef __SYCL_DEVICE_ONLY__
16 #include <CL/__spirv/spirv_ops.hpp>
17 #endif
18 
19 #include <type_traits> // for remove_reference_t
20 
21 #ifdef __SYCL_DEVICE_ONLY__
22 // Get the value of the specialization constant with given symbolic ID.
23 // `SymbolicID` is a unique string ID of a specialization constant.
24 // `DefaultValue` contains a pointer to a global variable with the initializer,
25 // which should be used as the default value of the specialization constants.
26 // `RTBuffer` is a pointer to a runtime buffer, which holds values of all
27 // specialization constant and should be used if native specialization constants
28 // are not available.
29 template <typename T>
30 __DPCPP_SYCL_EXTERNAL T __sycl_getScalar2020SpecConstantValue(
31  const char *SymbolicID, const void *DefaultValue, const void *RTBuffer);
32 
33 template <typename T>
34 __DPCPP_SYCL_EXTERNAL T __sycl_getComposite2020SpecConstantValue(
35  const char *SymbolicID, const void *DefaultValue, const void *RTBuffer);
36 #endif
37 
38 namespace sycl {
39 inline namespace _V1 {
43 class __SYCL_TYPE(kernel_handler) kernel_handler {
44 public:
45  template <auto &S>
46  __SYCL_ALWAYS_INLINE typename std::remove_reference_t<decltype(S)>::value_type
47  get_specialization_constant() {
48 #ifdef __SYCL_DEVICE_ONLY__
49  return getSpecializationConstantOnDevice<S>();
50 #else
52  "kernel_handler::get_specialization_constant() is "
53  "not supported on host.");
54 #endif // __SYCL_DEVICE_ONLY__
55  }
56 
57 private:
58  void __init_specialization_constants_buffer(
59  char *SpecializationConstantsBuffer = nullptr) {
60  MSpecializationConstantsBuffer = SpecializationConstantsBuffer;
61  }
62 
63 #ifdef __SYCL_DEVICE_ONLY__
64  template <
65  auto &S,
66  typename T = typename std::remove_reference_t<decltype(S)>::value_type,
67  std::enable_if_t<std::is_scalar_v<T>> * = nullptr>
68  __SYCL_ALWAYS_INLINE T getSpecializationConstantOnDevice() {
69  const char *SymbolicID = __builtin_sycl_unique_stable_id(S);
70  return __sycl_getScalar2020SpecConstantValue<T>(
71  SymbolicID, &S, MSpecializationConstantsBuffer);
72  }
73  template <
74  auto &S,
75  typename T = typename std::remove_reference_t<decltype(S)>::value_type,
76  std::enable_if_t<!std::is_scalar_v<T>> * = nullptr>
77  __SYCL_ALWAYS_INLINE T getSpecializationConstantOnDevice() {
78  const char *SymbolicID = __builtin_sycl_unique_stable_id(S);
79  return __sycl_getComposite2020SpecConstantValue<T>(
80  SymbolicID, &S, MSpecializationConstantsBuffer);
81  }
82 #endif // __SYCL_DEVICE_ONLY__
83 
84  char *MSpecializationConstantsBuffer = nullptr;
85 };
86 
87 } // namespace _V1
88 } // namespace sycl
#define __SYCL_ALWAYS_INLINE
#define __DPCPP_SYCL_EXTERNAL
std::error_code make_error_code(sycl::errc E) noexcept
Constructs an error code using e and sycl_category()
Definition: exception.cpp:64
const void value_type
Definition: multi_ptr.hpp:457
Definition: access.hpp:18