brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.4 KiB · 0c3e448 Raw
53 lines · c
1//===-- Wrapper for C standard stdio.h declarations on the GPU ------------===//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-exception6//7//===----------------------------------------------------------------------===//8 9#ifndef __CLANG_LLVM_LIBC_WRAPPERS_STDIO_H__10#define __CLANG_LLVM_LIBC_WRAPPERS_STDIO_H__11 12#if !defined(_OPENMP) && !defined(__HIP__) && !defined(__CUDA__)13#error "This file is for GPU offloading compilation only"14#endif15 16#include_next <stdio.h>17 18#if defined(__HIP__) || defined(__CUDA__)19#define __LIBC_ATTRS __attribute__((device))20#else21#define __LIBC_ATTRS22#endif23 24// Some headers provide these as macros. Temporarily undefine them so they do25// not conflict with any definitions for the GPU.26 27#pragma push_macro("stdout")28#pragma push_macro("stdin")29#pragma push_macro("stderr")30 31#undef stdout32#undef stderr33#undef stdin34 35#pragma omp begin declare target36 37__LIBC_ATTRS extern FILE *stderr;38__LIBC_ATTRS extern FILE *stdin;39__LIBC_ATTRS extern FILE *stdout;40 41#pragma omp end declare target42 43// Restore the original macros when compiling on the host.44#if !defined(__NVPTX__) && !defined(__AMDGPU__)45#pragma pop_macro("stderr")46#pragma pop_macro("stdin")47#pragma pop_macro("stdout")48#endif49 50#undef __LIBC_ATTRS51 52#endif // __CLANG_LLVM_LIBC_WRAPPERS_STDIO_H__53