DPC++ Runtime
Runtime libraries for oneAPI DPC++
__function_pointer.hpp
Go to the documentation of this file.
1 //==----------- function_pointer.hpp --- SYCL Function pointers ------------==//
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 #ifdef __SYCL_INTERNAL_API
12 
15 #include <CL/sycl/device.hpp>
16 #include <CL/sycl/program.hpp>
17 #include <CL/sycl/stl.hpp>
18 
20 namespace sycl {
21 namespace detail {
22 __SYCL_EXPORT cl_ulong getDeviceFunctionPointerImpl(device &D, program &P,
23  const char *FuncName);
24 }
25 namespace ext {
26 namespace oneapi {
27 
28 // This is a preview extension implementation, intended to provide early
29 // access to a feature for review and community feedback.
30 //
31 // Because the interfaces defined by this header file are not final and are
32 // subject to change they are not intended to be used by shipping software
33 // products. If you are interested in using this feature in your software
34 // product, please let us know!
35 
36 using device_func_ptr_holder_t = cl_ulong;
37 
40 template <
41  class FuncType,
42  typename FuncPtrType = typename detail::add_pointer_t<FuncType>,
43  typename detail::enable_if_t<std::is_function<FuncType>::value, int> = 0>
44 inline FuncPtrType to_device_func_ptr(device_func_ptr_holder_t FptrHolder) {
45  return reinterpret_cast<FuncPtrType>(FptrHolder);
46 }
47 
48 template <class FuncType>
49 using enable_if_is_function_pointer_t = typename detail::enable_if_t<
50  std::is_pointer<FuncType>::value &&
51  std::is_function<typename std::remove_pointer<FuncType>::type>::value,
52  int>;
53 
71 template <class FuncType, enable_if_is_function_pointer_t<FuncType> = 0>
72 device_func_ptr_holder_t get_device_func_ptr(FuncType F, const char *FuncName,
73  program &P, device &D) {
74  // TODO: drop function name argument and map host function pointer directly
75  // to a device function pointer
76  if (D.is_host()) {
77  return reinterpret_cast<device_func_ptr_holder_t>(F);
78  }
79 
80  if (program_state::linked != P.get_state()) {
81  throw invalid_parameter_error(
82  "Program must be built before passing to get_device_func_ptr",
84  }
85 
86  return sycl::detail::getDeviceFunctionPointerImpl(D, P, FuncName);
87 }
88 } // namespace oneapi
89 } // namespace ext
90 
91 } // namespace sycl
92 } // __SYCL_INLINE_NAMESPACE(cl)
93 
94 #endif
PI_INVALID_OPERATION
@ PI_INVALID_OPERATION
Definition: pi.h:88
stl.hpp
device.hpp
sycl
Definition: invoke_simd.hpp:68
stl_type_traits.hpp
export.hpp
program.hpp
cl
We provide new interfaces for matrix muliply in this patch:
Definition: access.hpp:13
cl::sycl::cl_ulong
std::uint64_t cl_ulong
Definition: aliases.hpp:85
cl::sycl::detail::getDeviceFunctionPointerImpl
ext::oneapi::device_func_ptr_holder_t getDeviceFunctionPointerImpl(device &D, program &P, const char *FuncName)
Definition: function_pointer.cpp:17
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