clang 24.0.0git
__clang_hip_runtime_wrapper.h
Go to the documentation of this file.
1/*===---- __clang_hip_runtime_wrapper.h - HIP runtime support ---------------===
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/*
11 * WARNING: This header is intended to be directly -include'd by
12 * the compiler and is not supposed to be included by users.
13 *
14 */
15
16#ifndef __CLANG_HIP_RUNTIME_WRAPPER_H__
17#define __CLANG_HIP_RUNTIME_WRAPPER_H__
18
19#if __HIP__
20
21#define __host__ __attribute__((host))
22#define __device__ __attribute__((device))
23#define __global__ __attribute__((global))
24#define __shared__ __attribute__((shared))
25#define __constant__ __attribute__((constant))
26#define __managed__ __attribute__((managed))
27
28#define __cluster_dims__(...) __attribute__((cluster_dims(__VA_ARGS__)))
29#define __no_cluster__ __attribute__((no_cluster))
30
31#if !defined(__cplusplus) || __cplusplus < 201103L
32 #define nullptr NULL;
33#endif
34
35#if !defined(__HIPCC_RTC__)
36#if __has_include("hip/hip_version.h")
37#include "hip/hip_version.h"
38#endif // __has_include("hip/hip_version.h")
39#endif // __HIPCC_RTC__
40
41typedef __SIZE_TYPE__ __hip_size_t;
42
43#ifdef __cplusplus
44extern "C" {
45#endif //__cplusplus
46
47#if HIP_VERSION_MAJOR * 100 + HIP_VERSION_MINOR >= 405
48__device__ unsigned long long __ockl_dm_alloc(unsigned long long __size);
49__device__ void __ockl_dm_dealloc(unsigned long long __addr);
50#if __has_feature(address_sanitizer)
51__device__ unsigned long long __asan_malloc_impl(unsigned long long __size,
52 unsigned long long __pc);
53__device__ void __asan_free_impl(unsigned long long __addr,
54 unsigned long long __pc);
55__attribute__((noinline, weak)) __device__ void *malloc(__hip_size_t __size) {
56 unsigned long long __pc = (unsigned long long)__builtin_return_address(0);
57 return (void *)__asan_malloc_impl(__size, __pc);
58}
59__attribute__((noinline, weak)) __device__ void free(void *__ptr) {
60 unsigned long long __pc = (unsigned long long)__builtin_return_address(0);
61 __asan_free_impl((unsigned long long)__ptr, __pc);
62}
63#else // __has_feature(address_sanitizer)
64__attribute__((weak)) inline __device__ void *malloc(__hip_size_t __size) {
65 return (void *) __ockl_dm_alloc(__size);
66}
67__attribute__((weak)) inline __device__ void free(void *__ptr) {
68 __ockl_dm_dealloc((unsigned long long)__ptr);
69}
70#endif // __has_feature(address_sanitizer)
71#else // HIP version check
72#if __HIP_ENABLE_DEVICE_MALLOC__
73__device__ void *__hip_malloc(__hip_size_t __size);
74__device__ void *__hip_free(void *__ptr);
75__attribute__((weak)) inline __device__ void *malloc(__hip_size_t __size) {
76 return __hip_malloc(__size);
77}
78__attribute__((weak)) inline __device__ void free(void *__ptr) {
79 __hip_free(__ptr);
80}
81#else // __HIP_ENABLE_DEVICE_MALLOC__
82__attribute__((weak)) inline __device__ void *malloc(__hip_size_t __size) {
83 __builtin_trap();
84 return (void *)0;
85}
86__attribute__((weak)) inline __device__ void free(void *__ptr) {
87 __builtin_trap();
88}
89#endif // __HIP_ENABLE_DEVICE_MALLOC__
90#endif // HIP version check
91
92#ifdef __cplusplus
93} // extern "C"
94#endif //__cplusplus
95
96#if !defined(__HIPCC_RTC__)
97// We must include the forward declarations before cmath is included.
98// Otherwise `constexpr` functions in <cmath> would be implicitely __host__
99// __device__. Declaring the __device__ verison before allows us to overload
100// them with __device__ versions (this behavour is only valid for system
101// headers).
103#include <cmath>
104#include <cstdlib>
105#include <stdlib.h>
106#if __has_include("hip/hip_version.h")
107#include "hip/hip_version.h"
108#endif // __has_include("hip/hip_version.h")
109#else
110typedef __SIZE_TYPE__ size_t;
111// Define macros which are needed to declare HIP device API's without standard
112// C/C++ headers. This is for readability so that these API's can be written
113// the same way as non-hipRTC use case. These macros need to be popped so that
114// they do not pollute users' name space.
115#pragma push_macro("NULL")
116#pragma push_macro("uint32_t")
117#pragma push_macro("uint64_t")
118#pragma push_macro("CHAR_BIT")
119#pragma push_macro("INT_MAX")
120#pragma push_macro("INT_MIN")
121#define NULL (void *)0
122#define uint32_t __UINT32_TYPE__
123#define uint64_t __UINT64_TYPE__
124#define CHAR_BIT __CHAR_BIT__
125#define INT_MAX __INTMAX_MAX__
126#define INT_MIN (-__INT_MAX__ - 1)
127#endif // __HIPCC_RTC__
128
130#include <__clang_hip_math.h>
131#include <__clang_hip_stdlib.h>
132
133#if defined(__HIPCC_RTC__)
134#include <__clang_hip_cmath.h>
135#else
136#include <__clang_hip_cmath.h>
138#include <algorithm>
139#include <complex>
140#include <new>
141#endif // __HIPCC_RTC__
142
143#define __CLANG_HIP_RUNTIME_WRAPPER_INCLUDED__ 1
144#if defined(__HIPCC_RTC__)
145#pragma pop_macro("NULL")
146#pragma pop_macro("uint32_t")
147#pragma pop_macro("uint64_t")
148#pragma pop_macro("CHAR_BIT")
149#pragma pop_macro("INT_MAX")
150#pragma pop_macro("INT_MIN")
151#endif // __HIPCC_RTC__
152#endif // __HIP__
153#endif // __CLANG_HIP_RUNTIME_WRAPPER_H__
_Float16 __2f16 __attribute__((ext_vector_type(2)))
Zeroes the upper 128 bits (bits 255:128) of all YMM registers.
#define __device__
__SIZE_TYPE__ size_t
The unsigned integer type of the result of the sizeof operator.