Skip to content

Commit

Permalink
implement cuda::fp types
Browse files Browse the repository at this point in the history
  • Loading branch information
davebayer committed Jan 29, 2025
1 parent d5d3aa6 commit ea48870
Show file tree
Hide file tree
Showing 27 changed files with 4,691 additions and 742 deletions.
486 changes: 486 additions & 0 deletions libcudacxx/include/cuda/__floating_point/cast.h

Large diffs are not rendered by default.

526 changes: 526 additions & 0 deletions libcudacxx/include/cuda/__floating_point/config.h

Large diffs are not rendered by default.

89 changes: 89 additions & 0 deletions libcudacxx/include/cuda/__floating_point/conv_rank_order.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
//===----------------------------------------------------------------------===//
//
// Part of libcu++, the C++ Standard Library for your entire system,
// 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
// SPDX-FileCopyrightText: Copyright (c) 2025 NVIDIA CORPORATION & AFFILIATES.
//
//===----------------------------------------------------------------------===//

#ifndef _CUDA___FLOATING_POINT_CONV_RANK_ORDER_H
#define _CUDA___FLOATING_POINT_CONV_RANK_ORDER_H

#include <cuda/std/detail/__config>

#if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC)
# pragma GCC system_header
#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG)
# pragma clang system_header
#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC)
# pragma system_header
#endif // no system header

#if _CCCL_STD_VER >= 2017

_LIBCUDACXX_BEGIN_NAMESPACE_CUDA

# include <cuda/__floating_point/config.h>
# include <cuda/__floating_point/type_traits.h>
# include <cuda/std/__type_traits/is_same.h>

enum class __fp_conv_rank_order
{
__unordered,
__greater,
__equal,
__less,
};

template <class _To, class _From>
_CCCL_NODISCARD _LIBCUDACXX_HIDE_FROM_ABI constexpr __fp_conv_rank_order __fp_make_conv_rank_order()
{
using _FromConfig = __fp_make_config_from_t<_From>;
using _ToConfig = __fp_make_config_from_t<_To>;

if constexpr (!_CUDA_VSTD::is_same_v<_FromConfig, __fp_invalid_config>
&& !_CUDA_VSTD::is_same_v<_ToConfig, __fp_invalid_config>)
{
if constexpr (_ToConfig::__is_signed == _FromConfig::__is_signed)
{
if constexpr (_ToConfig::__exp_nbits == _FromConfig::__exp_nbits
&& _ToConfig::__mant_nbits == _FromConfig::__mant_nbits)
{
# if !defined(_LIBCUDACXX_HAS_NO_LONG_DOUBLE)
// If the representations are the same, long double always has the higher subrank
if constexpr (_CUDA_VSTD::is_same_v<_ToConfig, __fp_long_double_config>
&& !_CUDA_VSTD::is_same_v<_FromConfig, __fp_long_double_config>)
{
return __fp_conv_rank_order::__greater;
}
else if constexpr (!_CUDA_VSTD::is_same_v<_ToConfig, __fp_long_double_config>
&& _CUDA_VSTD::is_same_v<_FromConfig, __fp_long_double_config>)
{
return __fp_conv_rank_order::__less;
}
# endif // !_LIBCUDACXX_HAS_NO_LONG_DOUBLE
return __fp_conv_rank_order::__equal;
}
else if constexpr (_ToConfig::__exp_nbits >= _FromConfig::__exp_nbits
&& _ToConfig::__mant_nbits >= _FromConfig::__mant_nbits)
{
return __fp_conv_rank_order::__greater;
}
else if constexpr (_ToConfig::__exp_nbits <= _FromConfig::__exp_nbits
&& _ToConfig::__mant_nbits <= _FromConfig::__mant_nbits)
{
return __fp_conv_rank_order::__less;
}
}
}

return __fp_conv_rank_order::__unordered;
}

_LIBCUDACXX_END_NAMESPACE_CUDA

#endif // _CCCL_STD_VER >= 2017

#endif // _CUDA___FLOATING_POINT_CONV_RANK_ORDER_H
Loading

0 comments on commit ea48870

Please sign in to comment.