DPC++ Runtime
Runtime libraries for oneAPI DPC++
function_pointer.cpp
Go to the documentation of this file.
1 //==----------- function_pointer.cpp --- 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 #include <detail/device_impl.hpp>
10 #include <detail/program_impl.hpp>
12 
14 namespace sycl {
15 namespace detail {
16 ext::oneapi::device_func_ptr_holder_t
17 getDeviceFunctionPointerImpl(device &D, program &P, const char *FuncName) {
18  ext::oneapi::device_func_ptr_holder_t FPtr = 0;
19 
20  const detail::plugin &Plugin = detail::getSyclObjImpl(P)->getPlugin();
21  pi_result Result = Plugin.call_nocheck<
23  detail::pi::cast<pi_device>(detail::getSyclObjImpl(D)->getHandleRef()),
24  detail::pi::cast<pi_program>(detail::getSyclObjImpl(P)->getHandleRef()),
25  FuncName, &FPtr);
26  // If extension is not supported, a fallback method is used which returns
27  // if the function exists or not. If the return address is not valid throw
28  // error.
29  if (Result != PI_SUCCESS) {
31  throw runtime_error("Function exists but address is not available",
32  Result);
33  if (Result == PI_INVALID_KERNEL_NAME)
34  throw runtime_error("Function name is not valid", Result);
35  else
36  throw runtime_error("piextGetDeviceFunctionPointer returned error when "
37  "retrieving address",
38  Result);
39  }
40 
41  return FPtr;
42 }
43 
44 } // namespace detail
45 } // namespace sycl
46 } // __SYCL_INLINE_NAMESPACE(cl)
PI_SUCCESS
@ PI_SUCCESS
Definition: pi.h:86
_pi_result
_pi_result
Definition: pi.h:85
__function_pointer.hpp
sycl
Definition: invoke_simd.hpp:68
device_impl.hpp
cl::sycl::detail::plugin::call_nocheck
RT::PiResult call_nocheck(ArgsT... Args) const
Calls the PiApi, traces the call, and returns the result.
Definition: plugin.hpp:170
program_impl.hpp
cl::sycl::device
The SYCL device class encapsulates a single SYCL device on which kernels may be executed.
Definition: device.hpp:35
cl
We provide new interfaces for matrix muliply in this patch:
Definition: access.hpp:13
PI_INVALID_KERNEL_NAME
@ PI_INVALID_KERNEL_NAME
Definition: pi.h:87
cl::sycl::detail::plugin
The plugin class provides a unified interface to the underlying low-level runtimes for the device-agn...
Definition: plugin.hpp:90
PI_FUNCTION_ADDRESS_IS_NOT_AVAILABLE
@ PI_FUNCTION_ADDRESS_IS_NOT_AVAILABLE
PI_FUNCTION_ADDRESS_IS_NOT_AVAILABLE indicates a fallback method determines the function exists but i...
Definition: pi.h:127
cl::sycl::detail::getSyclObjImpl
decltype(Obj::impl) getSyclObjImpl(const Obj &SyclObject)
Definition: common.hpp:198
cl::sycl::detail::getDeviceFunctionPointerImpl
ext::oneapi::device_func_ptr_holder_t getDeviceFunctionPointerImpl(device &D, program &P, const char *FuncName)
Definition: function_pointer.cpp:17
piextGetDeviceFunctionPointer
pi_result piextGetDeviceFunctionPointer(pi_device device, pi_program program, const char *function_name, pi_uint64 *function_pointer_ret)
Retrieves a device function pointer to a user-defined function.
Definition: pi_esimd_emulator.cpp:1835
__SYCL_INLINE_NAMESPACE
#define __SYCL_INLINE_NAMESPACE(X)
Definition: defines_elementary.hpp:12