DPC++ Runtime
Runtime libraries for oneAPI Data Parallel C++
os_util.hpp
Go to the documentation of this file.
1 //===-- os_util.hpp - OS utilities -----------------------------*- 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 // Abstracts the operating system services.
10 
11 #pragma once
12 
15 
16 #include <cstdint>
17 #include <cstdlib>
18 #include <string>
19 #include <sys/stat.h>
20 #include <sys/types.h>
21 
22 #ifdef _WIN32
23 #define __SYCL_RT_OS_WINDOWS
24 // Windows platform
25 #ifdef _WIN64
26 // 64-bit Windows platform
27 #else
28 // 32-bit Windows platform
29 #endif // _WIN64
30 #elif __linux__
31 // Linux platform
32 #define __SYCL_RT_OS_LINUX
33 #define __SYCL_RT_OS_POSIX_SUPPORT
34 #elif defined(__APPLE__) && defined(__MACH__)
35 // Apple OSX
36 #define __SYCL_RT_OS_DARWIN
37 #define __SYCL_RT_OS_POSIX_SUPPORT
38 #else
39 #error "Unsupported compiler or OS"
40 #endif // _WIN32
41 
43 namespace sycl {
44 namespace detail {
45 
48 using OSModuleHandle = intptr_t;
49 
51 class __SYCL_EXPORT OSUtil {
52 public:
54  static OSModuleHandle getOSModuleHandle(const void *VirtAddr);
55 
57  static std::string getCurrentDSODir();
58 
60  static std::string getDirName(const char *Path);
61 
64  static constexpr OSModuleHandle ExeModuleHandle = -1;
65 
68  static constexpr OSModuleHandle DummyModuleHandle = -2;
69 
70 #ifdef __SYCL_RT_OS_WINDOWS
71  static constexpr const char *DirSep = "\\";
72 #else
73  static constexpr const char *DirSep = "/";
74 #endif
75 
77  static size_t getOSMemSize();
78 
81  static void *alignedAlloc(size_t Alignment, size_t NumBytes);
82 
84  static void alignedFree(void *Ptr);
85 
87  static int makeDir(const char *Dir);
88 
90  static inline bool isPathPresent(const std::string &Path) {
91 #ifdef __SYCL_RT_OS_WINDOWS
92  struct _stat Stat;
93  return !_stat(Path.c_str(), &Stat);
94 #else
95  struct stat Stat;
96  return !stat(Path.c_str(), &Stat);
97 #endif
98  }
99 };
100 
101 } // namespace detail
102 } // namespace sycl
103 } // __SYCL_INLINE_NAMESPACE(cl)
cl::sycl::detail::getDirName
std::string getDirName(const char *Path)
cl::sycl::detail::usm::alignedAlloc
void * alignedAlloc(size_t Alignment, size_t Bytes, const context &Ctxt, const device &Dev, cl::sycl::usm::alloc Kind)
Definition: usm_impl.cpp:74
export.hpp
cl::sycl::detail::OSUtil
Groups the OS-dependent services.
Definition: os_util.hpp:51
cl::sycl::detail::OSUtil::isPathPresent
static bool isPathPresent(const std::string &Path)
Checks if specified path is present.
Definition: os_util.hpp:90
defines.hpp
cl
We provide new interfaces for matrix muliply in this patch:
Definition: access.hpp:13
cl::sycl::detail::OSModuleHandle
intptr_t OSModuleHandle
Uniquely identifies an operating system module (executable or a dynamic library)
Definition: os_util.hpp:48
__SYCL_INLINE_NAMESPACE
#define __SYCL_INLINE_NAMESPACE(X)
Definition: defines_elementary.hpp:12