DPC++ Runtime
Runtime libraries for oneAPI DPC++
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
13
#include <
sycl/detail/defines.hpp
>
14
#include <
sycl/detail/export.hpp
>
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
42
namespace
sycl
{
43
__SYCL_INLINE_VER_NAMESPACE
(_V1) {
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
}
// __SYCL_INLINE_VER_NAMESPACE(_V1)
103
}
// namespace sycl
__SYCL_INLINE_VER_NAMESPACE
#define __SYCL_INLINE_VER_NAMESPACE(X)
Definition:
defines_elementary.hpp:11
sycl
---— Error handling, matching OpenCL plugin semantics.
Definition:
access.hpp:14
export.hpp
sycl::_V1::detail::OSUtil::isPathPresent
static bool isPathPresent(const std::string &Path)
Checks if specified path is present.
Definition:
os_util.hpp:90
sycl::_V1::detail::OSUtil
Groups the OS-dependent services.
Definition:
os_util.hpp:51
defines.hpp
sycl::_V1::ext::oneapi::experimental::detail::Alignment
@ Alignment
Definition:
property.hpp:189
sycl::_V1::detail::OSModuleHandle
intptr_t OSModuleHandle
Uniquely identifies an operating system module (executable or a dynamic library)
Definition:
os_util.hpp:48
sycl::_V1::detail::usm::alignedAlloc
void * alignedAlloc(size_t Alignment, size_t Bytes, const context &Ctxt, const device &Dev, sycl::usm::alloc Kind, const code_location &CL)
sycl::_V1::detail::getDirName
std::string getDirName(const char *Path)
include
sycl
detail
os_util.hpp
Generated by
1.8.17