//===----------------------------------------------------------------------===//
//
// Part of the CUDA Toolkit, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

#ifndef __cuda_std__
#define __cuda_std__

#ifdef __CUDACC__
    #if defined(__clang__)
        #include <cuda_fp16.h>
        #define __fp16 __half
    #endif
    #if defined(__FLT16_MANT_DIG__)
        #include <cuda_fp16.h>
        #define _Float16 __half
    #endif
#else
    #ifndef __host__
        #define __host__
    #endif
    #ifndef __device__
        #define __device__
    #endif
    #ifndef __forceinline__
        #define __forceinline__
    #endif
#endif

#ifdef _MSC_VER
    #undef __cpp_lib_transparent_operators
#endif

// request these outcomes
#define _LIBCUDACXX_NO_AUTO_LINK
#ifndef _LIBCUDACXX_NO_EXCEPTIONS
    #define _LIBCUDACXX_NO_EXCEPTIONS
#endif
#ifndef _LIBCUDACXX_NO_RTTI
    #define _LIBCUDACXX_NO_RTTI
#endif
#define _LIBCUDACXX_HAS_NO_INT128
#define _LIBCUDACXX_FREESTANDING
#define _LIBCUDACXX_HAS_NO_THREAD_CONTENTION_TABLE
#define _LIBCUDACXX_HAS_NO_PLATFORM_WAIT
#define _LIBCUDACXX_HAS_NO_MONOTONIC_CLOCK
#define _LIBCUDACXX_HAS_NO_TREE_BARRIER
#ifdef __CUDACC_RTC__
    #define __ELF__
    #define _LIBCUDACXX_DISABLE_PRAGMA_GCC_SYSTEM_HEADER
    #define _LIBCUDACXX_HAS_THREAD_API_EXTERNAL
    #define __alignof(x) alignof(x)
    #define _LIBCUDACXX_LITTLE_ENDIAN
    #define _LIBCUDACXX_DISABLE_VISIBILITY_ANNOTATIONS
    #define _LIBCUDACXX_HAS_NO_PRAGMA_PUSH_POP_MACRO
#endif
#define _LIBCUDACXX_HAS_EXTERNAL_ATOMIC_IMP
#define _LIBCUDACXX_ATOMIC_ALWAYS_LOCK_FREE(size, ptr) (size <= 8)

#define _LIBCUDACXX_SYS_CLOCK_DURATION nanoseconds

#if defined(__PGIC__) && defined(__linux__)
    #define __ELF__
#endif

#include "libcxx/include/__config"

#if defined(__CUDA_ARCH__)
    #define _LIBCUDACXX_HAS_THREAD_API_CUDA
#elif defined(_LIBCUDACXX_COMPILER_MSVC)
    #define _LIBCUDACXX_HAS_THREAD_API_WIN32
#endif

#if _GNUC_VER <= 409
    #define _LIBCUDACXX_CUDA_HAS_NO_HOST_STD_ATOMIC_INIT
#endif

// force this outcome
#undef _LIBCUDACXX_ATOMIC_FLAG_TYPE
#define _LIBCUDACXX_ATOMIC_FLAG_TYPE int
#undef _LIBCUDACXX_INLINE_VISIBILITY
#define _LIBCUDACXX_INLINE_VISIBILITY __host__ __device__
#undef _LIBCUDACXX_FUNC_VIS
#define _LIBCUDACXX_FUNC_VIS _LIBCUDACXX_INLINE_VISIBILITY
#undef _LIBCUDACXX_TYPE_VIS
#define _LIBCUDACXX_TYPE_VIS

#ifndef _LIBCUDACXX_ABI_UNSTABLE
#  define _LIBCUDACXX_ABI_UNSTABLE
#endif

#define _LIBCUDACXX_CUDA_API_VERSION 001003000

#define _LIBCUDACXX_CUDA_API_VERSION_MAJOR \
  (_LIBCUDACXX_CUDA_API_VERSION / 1000000)

#define _LIBCUDACXX_CUDA_API_VERSION_MINOR \
  (_LIBCUDACXX_CUDA_API_VERSION / 1000 % 1000)

#define _LIBCUDACXX_CUDA_API_VERSION_PATCH \
  (_LIBCUDACXX_CUDA_API_VERSION % 1000)

#ifndef _LIBCUDACXX_CUDA_ABI_VERSION_LATEST
#  define _LIBCUDACXX_CUDA_ABI_VERSION_LATEST 3
#endif

#ifdef _LIBCUDACXX_CUDA_ABI_VERSION
#  if _LIBCUDACXX_CUDA_ABI_VERSION != 2 && _LIBCUDACXX_CUDA_ABI_VERSION != 3
#    error Unsupported libcu++ ABI version requested. Please define _LIBCUDACXX_CUDA_ABI_VERSION to either 2 or 3.
#  endif
#else
#  define _LIBCUDACXX_CUDA_ABI_VERSION _LIBCUDACXX_CUDA_ABI_VERSION_LATEST
#endif

#ifdef _LIBCUDACXX_PIPELINE_ASSUMED_ABI_VERSION
#if _LIBCUDACXX_PIPELINE_ASSUMED_ABI_VERSION != _LIBCUDACXX_CUDA_ABI_VERSION
#error cuda_pipeline.h has assumed a different libcu++ ABI version than provided by this library. To fix this, please include a libcu++ header before including cuda_pipeline.h, or upgrade to a version of the toolkit this version of libcu++ shipped in.
#endif
#endif

#ifndef _LIBCUDACXX_CUDA_ABI_NAMESPACE
#  define _LIBCUDACXX_CUDA_ABI_NAMESPACE _LIBCUDACXX_CONCAT(__,_LIBCUDACXX_CUDA_ABI_VERSION)
#endif

#ifndef _LIBCUDACXX_BEGIN_NAMESPACE_CUDA
#  define _LIBCUDACXX_BEGIN_NAMESPACE_CUDA \
      namespace cuda { inline namespace _LIBCUDACXX_CUDA_ABI_NAMESPACE {
#endif
#ifndef _LIBCUDACXX_END_NAMESPACE_CUDA
#  define _LIBCUDACXX_END_NAMESPACE_CUDA } }
#endif

#ifndef _LIBCUDACXX_BEGIN_NAMESPACE_CUDA_DEVICE
#  define _LIBCUDACXX_BEGIN_NAMESPACE_CUDA_DEVICE \
     namespace cuda { namespace device { inline namespace _LIBCUDACXX_CUDA_ABI_NAMESPACE {
#endif
#ifndef _LIBCUDACXX_END_NAMESPACE_CUDA_DEVICE
#  define _LIBCUDACXX_END_NAMESPACE_CUDA_DEVICE } } }
#endif

// redefine namespace std::
#undef _LIBCUDACXX_BEGIN_NAMESPACE_STD
#define _LIBCUDACXX_BEGIN_NAMESPACE_STD \
   namespace cuda { namespace std { inline namespace _LIBCUDACXX_CUDA_ABI_NAMESPACE {

#undef _LIBCUDACXX_END_NAMESPACE_STD
#define _LIBCUDACXX_END_NAMESPACE_STD } } }

#undef _CUDA_VSTD
#define _CUDA_VSTD cuda::std::_LIBCUDACXX_CUDA_ABI_NAMESPACE

#undef _LIBCUDACXX_BEGIN_NAMESPACE_STD_NOVERSION
#define _LIBCUDACXX_BEGIN_NAMESPACE_STD_NOVERSION namespace cuda { namespace std {
#undef _LIBCUDACXX_END_NAMESPACE_STD_NOVERSION
#define _LIBCUDACXX_END_NAMESPACE_STD_NOVERSION } }

#endif //__cuda_std__
