DPC++ Runtime
Runtime libraries for oneAPI Data Parallel C++
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 
14 #include <CL/sycl/stl.hpp>
15 
16 #include <cstring>
17 #include <mutex>
18 
20 namespace sycl {
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 // const char* key hash for STL maps
36 struct HashCStr {
37  size_t operator()(const char *S) const {
38  constexpr size_t Prime = 31;
39  size_t Res = 0;
40  char Ch = 0;
41 
42  for (; (Ch = *S); S++) {
43  Res += Ch + (Prime * Res);
44  }
45  return Res;
46  }
47 };
48 
49 // const char* key comparison for STL maps
50 struct CmpCStr {
51  bool operator()(const char *A, const char *B) const {
52  return std::strcmp(A, B) == 0;
53  }
54 };
55 
56 using SerializedObj = std::vector<unsigned char>;
57 
58 } // namespace detail
59 } // namespace sycl
60 } // __SYCL_INLINE_NAMESPACE(cl)
61 
62 #endif //__SYCL_DEVICE_ONLY
cl::sycl::detail::SerializedObj
std::vector< unsigned char > SerializedObj
Definition: util.hpp:56
cl::sycl::detail::Sync::getGlobalLock
static std::mutex & getGlobalLock()
Retuns a reference to the global lock.
Definition: util.hpp:28
cl::sycl::detail::Sync
Groups and provides access to all the locks used the SYCL runtime.
Definition: util.hpp:24
cl::sycl::detail::CmpCStr::operator()
bool operator()(const char *A, const char *B) const
Definition: util.hpp:51
stl.hpp
cl::sycl::detail::HashCStr
Definition: util.hpp:36
cl::sycl::detail::CmpCStr
Definition: util.hpp:50
defines.hpp
cl
We provide new interfaces for matrix muliply in this patch:
Definition: access.hpp:13
cl::sycl::detail::HashCStr::operator()
size_t operator()(const char *S) const
Definition: util.hpp:37
__SYCL_INLINE_NAMESPACE
#define __SYCL_INLINE_NAMESPACE(X)
Definition: defines_elementary.hpp:12