DPC++ Runtime
Runtime libraries for oneAPI DPC++
windows_pi.cpp
Go to the documentation of this file.
1 //==---------------- windows_pi.cpp ----------------------------------------==//
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 
10 
11 #include <cassert>
12 #include <string>
13 #include <windows.h>
14 #include <winreg.h>
15 
17 namespace sycl {
18 namespace detail {
19 namespace pi {
20 
21 void *loadOsLibrary(const std::string &PluginPath) {
22  // Tells the system to not display the critical-error-handler message box.
23  // Instead, the system sends the error to the calling process.
24  // This is crucial for graceful handling of plugins that couldn't be
25  // loaded, e.g. due to missing native run-times.
26  // TODO: add reporting in case of an error.
27  // NOTE: we restore the old mode to not affect user app behavior.
28  //
29  UINT SavedMode = SetErrorMode(SEM_FAILCRITICALERRORS);
30  // Exclude current directory from DLL search path
31  if (!SetDllDirectoryA("")) {
32  assert(false && "Failed to update DLL search path");
33  }
34  auto Result = (void *)LoadLibraryA(PluginPath.c_str());
35  (void)SetErrorMode(SavedMode);
36  if (!SetDllDirectoryA(nullptr)) {
37  assert(false && "Failed to restore DLL search path");
38  }
39 
40  return Result;
41 }
42 
43 int unloadOsLibrary(void *Library) {
44  return (int)FreeLibrary((HMODULE)Library);
45 }
46 
47 void *getOsLibraryFuncAddress(void *Library, const std::string &FunctionName) {
48  return reinterpret_cast<void *>(
49  GetProcAddress((HMODULE)Library, FunctionName.c_str()));
50 }
51 
52 } // namespace pi
53 } // namespace detail
54 } // namespace sycl
55 } // __SYCL_INLINE_NAMESPACE(cl)
cl::sycl::detail::pi::getOsLibraryFuncAddress
void * getOsLibraryFuncAddress(void *Library, const std::string &FunctionName)
Definition: posix_pi.cpp:34
sycl
Definition: invoke_simd.hpp:68
cl::sycl::detail::pi::unloadOsLibrary
int unloadOsLibrary(void *Library)
Definition: posix_pi.cpp:32
defines.hpp
cl
We provide new interfaces for matrix muliply in this patch:
Definition: access.hpp:13
cl::sycl::detail::pi::loadOsLibrary
void * loadOsLibrary(const std::string &Library)
Definition: posix_pi.cpp:20
__SYCL_INLINE_NAMESPACE
#define __SYCL_INLINE_NAMESPACE(X)
Definition: defines_elementary.hpp:11