clang 23.0.0git
__clang_openmp_device_functions.h
Go to the documentation of this file.
1/*===- __clang_openmp_device_functions.h - OpenMP device function declares -===
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
10#ifndef __CLANG_OPENMP_DEVICE_FUNCTIONS_H__
11#define __CLANG_OPENMP_DEVICE_FUNCTIONS_H__
12
13#ifdef __cplusplus
14extern "C" {
15#endif
16
17#ifdef __NVPTX__
18#pragma omp begin declare variant match( \
19 device = {arch(nvptx, nvptx64)}, implementation = {extension(match_any)})
20
21#pragma push_macro("__CUDA__")
22#define __CUDA__
23#define __OPENMP_NVPTX__
24
25/// Include declarations for libdevice functions.
27
28/// Provide definitions for these functions.
30
31#undef __OPENMP_NVPTX__
32#pragma pop_macro("__CUDA__")
33
34#pragma omp end declare variant
35#endif
36
37#ifdef __AMDGCN__
38#pragma omp begin declare variant match(device = {arch(amdgcn)})
39
40// Import types which will be used by __clang_hip_libdevice_declares.h
41#ifndef __cplusplus
42#include <stdint.h>
43#endif
44
45#define __OPENMP_AMDGCN__
46#pragma push_macro("__device__")
47#define __device__
48
49/// Include declarations for libdevice functions.
51
52#pragma pop_macro("__device__")
53#undef __OPENMP_AMDGCN__
54
55#pragma omp end declare variant
56#endif
57
58#ifdef __SPIRV__
59#pragma omp begin declare variant match( \
60 device = {arch(spirv64)}, implementation = {extension(match_any)})
61
62#define __OPENMP_SPIRV__
63
64/// Include declarations for libdevice functions.
66
67#undef __OPENMP_SPIRV__
68
69#pragma omp end declare variant
70#endif
71
72#ifdef __cplusplus
73} // extern "C"
74#endif
75
76// Ensure we make `_ZdlPv`, aka. `operator delete(void*)` available without the
77// need to `include <new>` in C++ mode.
78#ifdef __cplusplus
79
80// We require malloc/free.
81#include <cstdlib>
82
83#pragma push_macro("OPENMP_NOEXCEPT")
84#if __cplusplus >= 201103L
85#define OPENMP_NOEXCEPT noexcept
86#else
87#define OPENMP_NOEXCEPT
88#endif
89
90// Device overrides for non-placement new and delete.
91inline void *operator new(__SIZE_TYPE__ size) {
92 if (size == 0)
93 size = 1;
94 return ::malloc(size);
95}
96
97inline void *operator new[](__SIZE_TYPE__ size) { return ::operator new(size); }
98
99inline void operator delete(void *ptr)OPENMP_NOEXCEPT { ::free(ptr); }
100
101inline void operator delete[](void *ptr) OPENMP_NOEXCEPT {
102 ::operator delete(ptr);
103}
104
105// Sized delete, C++14 only.
106#if __cplusplus >= 201402L
107inline void operator delete(void *ptr, __SIZE_TYPE__ size)OPENMP_NOEXCEPT {
108 ::operator delete(ptr);
109}
110inline void operator delete[](void *ptr, __SIZE_TYPE__ size) OPENMP_NOEXCEPT {
111 ::operator delete(ptr);
112}
113#endif
114
115#pragma pop_macro("OPENMP_NOEXCEPT")
116#endif
117
118#endif