DPC++ Runtime
Runtime libraries for oneAPI DPC++
defines_elementary.hpp
Go to the documentation of this file.
1 //==--- defines_elementary.hpp ---- Preprocessor directives (simplified) ---==//
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 __has_attribute
12 #define __has_attribute(x) 0
13 #endif
14 
15 #ifndef __has_builtin
16 #define __has_builtin(x) 0
17 #endif // __has_builtin
18 
19 #ifndef __SYCL_ALWAYS_INLINE
20 #if __has_attribute(always_inline)
21 #define __SYCL_ALWAYS_INLINE __attribute__((always_inline))
22 #else
23 #define __SYCL_ALWAYS_INLINE
24 #endif
25 #endif // __SYCL_ALWAYS_INLINE
26 
27 #ifdef SYCL_EXTERNAL
28 #define __DPCPP_SYCL_EXTERNAL SYCL_EXTERNAL
29 #else
30 #ifdef __SYCL_DEVICE_ONLY__
31 #define __DPCPP_SYCL_EXTERNAL __attribute__((sycl_device))
32 #else
33 #define __DPCPP_SYCL_EXTERNAL
34 #define SYCL_EXTERNAL
35 #endif
36 #endif
37 
38 // Helper for enabling empty-base optimizations on MSVC.
39 // TODO: Remove this when MSVC has this optimization enabled by default.
40 #ifdef _MSC_VER
41 #define __SYCL_EBO __declspec(empty_bases)
42 #else
43 #define __SYCL_EBO
44 #endif
45 
46 
47 #ifndef __SYCL_ID_QUERIES_FIT_IN_INT__
48 #define __SYCL_ID_QUERIES_FIT_IN_INT__ 0
49 #endif
50 
51 #ifndef __SYCL_DEPRECATED
52 #if !defined(SYCL2020_DISABLE_DEPRECATION_WARNINGS)
53 #define __SYCL_DEPRECATED(message) [[deprecated(message)]]
54 #else // SYCL_DISABLE_DEPRECATION_WARNINGS
55 #define __SYCL_DEPRECATED(message)
56 #endif // SYCL_DISABLE_DEPRECATION_WARNINGS
57 #endif // __SYCL_DEPRECATED
58 
59 #ifndef __SYCL2020_DEPRECATED
60 #if SYCL_LANGUAGE_VERSION >= 202001 && \
61  !defined(SYCL2020_DISABLE_DEPRECATION_WARNINGS)
62 #define __SYCL2020_DEPRECATED(message) __SYCL_DEPRECATED(message)
63 #else
64 #define __SYCL2020_DEPRECATED(message)
65 #endif
66 #endif // __SYCL2020_DEPRECATED
67 
68 #ifndef __SYCL_WARN_IMAGE_ASPECT
69 #if !defined(SYCL_DISABLE_IMAGE_ASPECT_WARNING) && __has_attribute(diagnose_if)
70 #define __SYCL_WARN_IMAGE_ASPECT(aspect_param) \
71  __attribute__((diagnose_if( \
72  aspect_param == aspect::image, \
73  "SYCL 2020 images are not supported on any devices. Consider using " \
74  "‘aspect::ext_intel_legacy_image’ instead. Disable this warning with " \
75  "by defining SYCL_DISABLE_IMAGE_ASPECT_WARNING.", \
76  "warning")))
77 #else
78 #define __SYCL_WARN_IMAGE_ASPECT(aspect)
79 #endif
80 #endif // __SYCL_WARN_IMAGE_ASPECT
81 
82 #ifndef __SYCL_HAS_CPP_ATTRIBUTE
83 #if defined(__cplusplus) && defined(__has_cpp_attribute)
84 #define __SYCL_HAS_CPP_ATTRIBUTE(x) __has_cpp_attribute(x)
85 #else
86 #define __SYCL_HAS_CPP_ATTRIBUTE(x) 0
87 #endif
88 #endif
89 
90 static_assert(__cplusplus >= 201703L,
91  "DPCPP does not support C++ version earlier than C++17.");
92 
93 // Helper macro to identify if fallback assert is needed
94 #if defined(SYCL_FALLBACK_ASSERT)
95 #define __SYCL_USE_FALLBACK_ASSERT SYCL_FALLBACK_ASSERT
96 #else
97 #define __SYCL_USE_FALLBACK_ASSERT 0
98 #endif
99 
100 #if defined(_WIN32) && !defined(_DLL) && !defined(__SYCL_DEVICE_ONLY__)
101 // SYCL library is designed such a way that STL objects cross DLL boundary,
102 // which is guaranteed to work properly only when the application uses the same
103 // C++ runtime that SYCL library uses.
104 // The appplications using sycl.dll must be linked with dynamic/release C++ MSVC
105 // runtime, i.e. be compiled with /MD switch. Similarly, the applications using
106 // sycld.dll must be linked with dynamic/debug C++ runtime and be compiled with
107 // /MDd switch.
108 // Compiler automatically adds /MD or /MDd when -fsycl switch is used.
109 // The options /MD and /MDd that make the code to use dynamic runtime also
110 // define the _DLL macro.
111 #if defined(_MSC_VER)
112 #pragma message( \
113  "SYCL library is designed to work safely with dynamic C++ runtime." \
114  "Please use /MD switch with sycl.dll, /MDd switch with sycld.dll, " \
115  "or -fsycl switch to set C++ runtime automatically.")
116 #else
117 #warning "SYCL library is designed to work safely with dynamic C++ runtime."\
118  "Please use /MD switch with sycl.dll, /MDd switch with sycld.dll, "\
119  "or -fsycl switch to set C++ runtime automatically."
120 #endif
121 #endif // defined(_WIN32) && !defined(_DLL) && !defined(__SYCL_DEVICE_ONLY__)