DPC++ Runtime
Runtime libraries for oneAPI DPC++
util.hpp
Go to the documentation of this file.
1
//===-- util.hpp - Shared SYCL runtime utilities interface -----*- 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
#pragma once
10
11
#ifndef __SYCL_DEVICE_ONLY
12
13
#include <
sycl/detail/defines.hpp
>
14
15
#include <cstring>
16
#include <mutex>
17
#include <vector>
18
19
namespace
sycl
{
20
inline
namespace
_V1 {
21
namespace
detail
{
22
24
class
Sync
{
25
public
:
28
static
std::mutex &
getGlobalLock
() {
return
getInstance().GlobalLock; }
29
30
private
:
31
static
Sync
&getInstance();
32
std::mutex GlobalLock;
33
};
34
35
// TempAssignGuard is the class for a guard object that will assign some OTHER
36
// variable to a temporary value but restore it when the guard itself goes out
37
// of scope.
38
template
<
typename
T>
struct
TempAssignGuard
{
39
T &
field
;
40
T
restoreValue
;
41
TempAssignGuard
(T &fld, T tempVal) :
field
(fld),
restoreValue
(fld) {
42
field
= tempVal;
43
}
44
~TempAssignGuard
() {
field
=
restoreValue
; }
45
};
46
47
// const char* key hash for STL maps
48
struct
HashCStr
{
49
size_t
operator()
(
const
char
*S)
const
{
50
constexpr
size_t
Prime = 31;
51
size_t
Res = 0;
52
char
Ch = 0;
53
54
for
(; (Ch = *S); S++) {
55
Res += Ch + (Prime * Res);
56
}
57
return
Res;
58
}
59
};
60
61
// const char* key comparison for STL maps
62
struct
CmpCStr
{
63
bool
operator()
(
const
char
*A,
const
char
*B)
const
{
64
return
std::strcmp(A, B) == 0;
65
}
66
};
67
68
using
SerializedObj
= std::vector<unsigned char>;
69
70
}
// namespace detail
71
}
// namespace _V1
72
}
// namespace sycl
73
74
#endif //__SYCL_DEVICE_ONLY
sycl::_V1::detail::TempAssignGuard::field
T & field
Definition:
util.hpp:39
sycl::_V1::detail::Sync::getGlobalLock
static std::mutex & getGlobalLock()
Retuns a reference to the global lock.
Definition:
util.hpp:28
sycl::_V1::detail::TempAssignGuard::~TempAssignGuard
~TempAssignGuard()
Definition:
util.hpp:44
detail
---— Error handling, matching OpenCL plugin semantics.
Definition:
common.hpp:44
sycl
Definition:
access.hpp:18
sycl::_V1::detail::TempAssignGuard
Definition:
util.hpp:38
sycl::_V1::detail::CmpCStr::operator()
bool operator()(const char *A, const char *B) const
Definition:
util.hpp:63
defines.hpp
sycl::_V1::detail::Sync
Groups and provides access to all the locks used the SYCL runtime.
Definition:
util.hpp:24
sycl::_V1::detail::HashCStr
Definition:
util.hpp:48
sycl::_V1::detail::HashCStr::operator()
size_t operator()(const char *S) const
Definition:
util.hpp:49
sycl::_V1::detail::SerializedObj
std::vector< unsigned char > SerializedObj
Definition:
util.hpp:68
sycl::_V1::detail::CmpCStr
Definition:
util.hpp:62
sycl::_V1::detail::TempAssignGuard::restoreValue
T restoreValue
Definition:
util.hpp:40
sycl::_V1::detail::TempAssignGuard::TempAssignGuard
TempAssignGuard(T &fld, T tempVal)
Definition:
util.hpp:41
include
sycl
detail
util.hpp
Generated by
1.8.17