Skip to content

Commit

Permalink
Merge pull request #717 from cppalliance/real_cuda
Browse files Browse the repository at this point in the history
  • Loading branch information
mborland authored Aug 12, 2024
2 parents 4bf4e48 + 266eb3f commit 8df12cd
Show file tree
Hide file tree
Showing 35 changed files with 2,566 additions and 765 deletions.
78 changes: 78 additions & 0 deletions .github/workflows/cuda.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
# Copyright 2024 Matt Borland
# Distributed under the Boost Software License, Version 1.0.
# (See accompanying file LICENSE_1_0.txt or copy at http://boost.org/LICENSE_1_0.txt)

name: GPUs
on:
push:
branches:
- master
- develop
- feature/**
pull_request:
release:
types: [published, created, edited]

concurrency:
group: ${{ github.head_ref || github.run_id }}
cancel-in-progress: true

jobs:
cuda-cmake-test:
strategy:
fail-fast: false

runs-on: gpu-runner-1

steps:
- uses: Jimver/cuda-toolkit@v0.2.16
id: cuda-toolkit
with:
cuda: '12.5.0'
method: 'network'
sub-packages: '["nvcc"]'

- name: Output CUDA information
run: |
echo "Installed cuda version is: ${{steps.cuda-toolkit.outputs.cuda}}"+
echo "Cuda install location: ${{steps.cuda-toolkit.outputs.CUDA_PATH}}"
nvcc -V
- uses: actions/checkout@v4

- name: Install Packages
run: |
sudo apt-get install -y cmake make
- name: Setup Boost
run: |
echo GITHUB_REPOSITORY: $GITHUB_REPOSITORY
LIBRARY=${GITHUB_REPOSITORY#*/}
echo LIBRARY: $LIBRARY
echo "LIBRARY=$LIBRARY" >> $GITHUB_ENV
echo GITHUB_BASE_REF: $GITHUB_BASE_REF
echo GITHUB_REF: $GITHUB_REF
REF=${GITHUB_BASE_REF:-$GITHUB_REF}
REF=${REF#refs/heads/}
echo REF: $REF
BOOST_BRANCH=develop && [ "$REF" == "master" ] && BOOST_BRANCH=master || true
echo BOOST_BRANCH: $BOOST_BRANCH
cd ..
git clone -b $BOOST_BRANCH --depth 1 https://github.com/boostorg/boost.git boost-root
cd boost-root
mkdir -p libs/$LIBRARY
cp -r $GITHUB_WORKSPACE/* libs/$LIBRARY
git submodule update --init tools/boostdep
python3 tools/boostdep/depinst/depinst.py --git_args "--jobs 3" $LIBRARY
- name: Configure
run: |
cd ../boost-root
mkdir __build__ && cd __build__
cmake -DBOOST_INCLUDE_LIBRARIES=$LIBRARY -DBUILD_TESTING=ON -DCMAKE_CUDA_COMPILER=/usr/local/cuda/bin/nvcc -DBOOST_DECIMAL_ENABLE_CUDA=1 -DCMAKE_CUDA_ARCHITECTURES=70 -DCUDA_TOOLKIT_ROOT_DIR=/usr/local/cuda-12.5 ..
- name: Build tests
run: |
cd ../boost-root/__build__
cmake --build . --target tests -j $(nproc)
- name: Run tests
run: |
cd ../boost-root/__build__
ctest --output-on-failure --no-tests=error
374 changes: 188 additions & 186 deletions include/boost/decimal/decimal32_fast.hpp

Large diffs are not rendered by default.

37 changes: 21 additions & 16 deletions include/boost/decimal/detail/add_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,12 @@
#ifndef BOOST_DECIMAL_DETAIL_ADD_IMPL_HPP
#define BOOST_DECIMAL_DETAIL_ADD_IMPL_HPP

#include <boost/decimal/detail/config.hpp>
#include <boost/decimal/detail/attributes.hpp>
#include <boost/decimal/detail/apply_sign.hpp>
#include <boost/decimal/detail/fenv_rounding.hpp>
#include <boost/decimal/detail/type_traits.hpp>
#include <boost/decimal/detail/numeric_limits.hpp>

#ifndef BOOST_DECIMAL_BUILD_MODULE
#include <cstdint>
Expand All @@ -18,9 +21,10 @@ namespace decimal {
namespace detail {

template <typename ReturnType, typename T, typename U>
BOOST_DECIMAL_FORCE_INLINE constexpr auto d32_add_impl(T lhs_sig, U lhs_exp, bool lhs_sign,
T rhs_sig, U rhs_exp, bool rhs_sign,
bool abs_lhs_bigger) noexcept -> ReturnType
BOOST_DECIMAL_GPU_ENABLED BOOST_DECIMAL_FORCE_INLINE
constexpr auto d32_add_impl(T lhs_sig, U lhs_exp, bool lhs_sign,
T rhs_sig, U rhs_exp, bool rhs_sign,
bool abs_lhs_bigger) noexcept -> ReturnType
{
using add_type = std::int_fast32_t;

Expand Down Expand Up @@ -64,7 +68,7 @@ BOOST_DECIMAL_FORCE_INLINE constexpr auto d32_add_impl(T lhs_sig, U lhs_exp, boo

if (delta_exp <= 2)
{
sig_bigger *= pow10(static_cast<std::remove_reference_t<decltype(sig_bigger)>>(delta_exp));
sig_bigger *= pow10(static_cast<BOOST_DECIMAL_TYPE_TRAITS_NAMESPACE::remove_reference_t<decltype(sig_bigger)>>(delta_exp));
exp_bigger -= delta_exp;
delta_exp = 0;
}
Expand All @@ -76,7 +80,7 @@ BOOST_DECIMAL_FORCE_INLINE constexpr auto d32_add_impl(T lhs_sig, U lhs_exp, boo

if (delta_exp > 1)
{
sig_smaller /= pow10(static_cast<std::remove_reference_t<decltype(sig_smaller)>>(delta_exp - 1));
sig_smaller /= pow10(static_cast<BOOST_DECIMAL_TYPE_TRAITS_NAMESPACE::remove_reference_t<decltype(sig_smaller)>>(delta_exp - 1));
delta_exp = 1;
}
}
Expand All @@ -103,8 +107,9 @@ BOOST_DECIMAL_FORCE_INLINE constexpr auto d32_add_impl(T lhs_sig, U lhs_exp, boo
}

template <typename ReturnType, typename T, typename U>
BOOST_DECIMAL_FORCE_INLINE constexpr auto add_impl(T lhs_sig, U lhs_exp, bool lhs_sign,
T rhs_sig, U rhs_exp, bool rhs_sign) noexcept -> ReturnType
BOOST_DECIMAL_FORCE_INLINE BOOST_DECIMAL_GPU_ENABLED
constexpr auto add_impl(T lhs_sig, U lhs_exp, bool lhs_sign,
T rhs_sig, U rhs_exp, bool rhs_sign) noexcept -> ReturnType
{
const bool sign {lhs_sign};

Expand Down Expand Up @@ -176,9 +181,9 @@ BOOST_DECIMAL_FORCE_INLINE constexpr auto add_impl(T lhs_sig, U lhs_exp, bool lh
}

template <typename ReturnType, typename T, typename U>
constexpr auto d64_add_impl(T lhs_sig, U lhs_exp, bool lhs_sign,
T rhs_sig, U rhs_exp, bool rhs_sign,
bool abs_lhs_bigger) noexcept -> ReturnType
BOOST_DECIMAL_GPU_ENABLED constexpr auto d64_add_impl(T lhs_sig, U lhs_exp, bool lhs_sign,
T rhs_sig, U rhs_exp, bool rhs_sign,
bool abs_lhs_bigger) noexcept -> ReturnType
{
using add_type = std::int_fast64_t;

Expand Down Expand Up @@ -261,8 +266,8 @@ constexpr auto d64_add_impl(T lhs_sig, U lhs_exp, bool lhs_sign,

template <typename ReturnType, BOOST_DECIMAL_INTEGRAL T1, BOOST_DECIMAL_INTEGRAL U1,
BOOST_DECIMAL_INTEGRAL T2, BOOST_DECIMAL_INTEGRAL U2>
constexpr auto d128_add_impl(T1 lhs_sig, U1 lhs_exp, bool lhs_sign,
T2 rhs_sig, U2 rhs_exp, bool rhs_sign) noexcept -> ReturnType
BOOST_DECIMAL_GPU_ENABLED constexpr auto d128_add_impl(T1 lhs_sig, U1 lhs_exp, bool lhs_sign,
T2 rhs_sig, U2 rhs_exp, bool rhs_sign) noexcept -> ReturnType
{
const bool sign {lhs_sign};

Expand All @@ -284,7 +289,7 @@ constexpr auto d128_add_impl(T1 lhs_sig, U1 lhs_exp, bool lhs_sign,
//
// e.g. 1.234567e5 + 9.876543e-2 = 1.234568e5

BOOST_DECIMAL_IF_CONSTEXPR (std::numeric_limits<T2>::digits10 > std::numeric_limits<std::uint64_t>::digits10)
BOOST_DECIMAL_IF_CONSTEXPR (boost::decimal::detail::numeric_limits<T2>::digits10 > boost::decimal::detail::numeric_limits<std::uint64_t>::digits10)
{
if (rhs_sig >= detail::uint128 {UINT64_C(0xF684DF56C3E0), UINT64_C(0x1BC6C73200000000)})
{
Expand Down Expand Up @@ -341,9 +346,9 @@ constexpr auto d128_add_impl(T1 lhs_sig, U1 lhs_exp, bool lhs_sign,
}

template <typename ReturnType, typename T, typename U>
constexpr auto d128_add_impl(T lhs_sig, U lhs_exp, bool lhs_sign,
T rhs_sig, U rhs_exp, bool rhs_sign,
bool abs_lhs_bigger) noexcept -> ReturnType
BOOST_DECIMAL_GPU_ENABLED constexpr auto d128_add_impl(T lhs_sig, U lhs_exp, bool lhs_sign,
T rhs_sig, U rhs_exp, bool rhs_sign,
bool abs_lhs_bigger) noexcept -> ReturnType
{
auto delta_exp {lhs_exp > rhs_exp ? lhs_exp - rhs_exp : rhs_exp - lhs_exp};

Expand Down
12 changes: 6 additions & 6 deletions include/boost/decimal/detail/apply_sign.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,39 +22,39 @@ namespace boost { namespace decimal { namespace detail {

template <typename Integer, typename Unsigned_Integer = detail::make_unsigned_t<Integer>,
std::enable_if_t<detail::is_signed_v<Integer>, bool> = true>
constexpr auto apply_sign(Integer val) noexcept -> Unsigned_Integer
BOOST_DECIMAL_GPU_ENABLED constexpr auto apply_sign(Integer val) noexcept -> Unsigned_Integer
{
return static_cast<Unsigned_Integer>(-(static_cast<Unsigned_Integer>(val)));
}

template <typename Unsigned_Integer, std::enable_if_t<!detail::is_signed_v<Unsigned_Integer>, bool> = true>
constexpr auto apply_sign(Unsigned_Integer val) noexcept -> Unsigned_Integer
BOOST_DECIMAL_GPU_ENABLED constexpr auto apply_sign(Unsigned_Integer val) noexcept -> Unsigned_Integer
{
return val;
}

template <typename Integer, typename Unsigned_Integer = detail::make_unsigned_t<Integer>,
std::enable_if_t<detail::is_signed_v<Integer>, bool> = true>
constexpr auto make_positive_unsigned(Integer val) noexcept -> Unsigned_Integer
BOOST_DECIMAL_GPU_ENABLED constexpr auto make_positive_unsigned(Integer val) noexcept -> Unsigned_Integer
{
return static_cast<Unsigned_Integer>(val < static_cast<Integer>(static_cast<std::int8_t>(0)) ? apply_sign(val) : static_cast<Unsigned_Integer>(val));
}

template <typename Unsigned_Integer, std::enable_if_t<!detail::is_signed_v<Unsigned_Integer>, bool> = true>
constexpr auto make_positive_unsigned(Unsigned_Integer val) noexcept -> Unsigned_Integer
BOOST_DECIMAL_GPU_ENABLED constexpr auto make_positive_unsigned(Unsigned_Integer val) noexcept -> Unsigned_Integer
{
return val;
}

template <typename Integer, std::enable_if_t<detail::is_signed_v<Integer>, bool> = true>
constexpr auto make_signed_value(Integer val, bool sign) noexcept -> Integer
BOOST_DECIMAL_GPU_ENABLED constexpr auto make_signed_value(Integer val, bool sign) noexcept -> Integer
{
return sign ? -val : val;
}

template <typename Unsigned_Integer, typename Integer = detail::make_signed_t<Unsigned_Integer>,
std::enable_if_t<!detail::is_signed_v<Unsigned_Integer>, bool> = true>
constexpr auto make_signed_value(Unsigned_Integer val, bool sign) noexcept -> Integer
BOOST_DECIMAL_GPU_ENABLED constexpr auto make_signed_value(Unsigned_Integer val, bool sign) noexcept -> Integer
{
const auto signed_val {static_cast<Integer>(val)};
return sign ? -signed_val : signed_val;
Expand Down
2 changes: 1 addition & 1 deletion include/boost/decimal/detail/cmath/abs.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ namespace boost {
namespace decimal {

BOOST_DECIMAL_EXPORT template <typename T>
constexpr auto abs BOOST_DECIMAL_PREVENT_MACRO_SUBSTITUTION (T rhs) noexcept
BOOST_DECIMAL_GPU_ENABLED constexpr auto abs BOOST_DECIMAL_PREVENT_MACRO_SUBSTITUTION (T rhs) noexcept
BOOST_DECIMAL_REQUIRES(detail::is_decimal_floating_point_v, T)
{
return signbit(rhs) ? -rhs : rhs;
Expand Down
2 changes: 1 addition & 1 deletion include/boost/decimal/detail/cmath/fpclassify.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ namespace boost {
namespace decimal {

BOOST_DECIMAL_EXPORT template <typename T>
constexpr auto fpclassify BOOST_DECIMAL_PREVENT_MACRO_SUBSTITUTION (T rhs) noexcept
BOOST_DECIMAL_GPU_ENABLED constexpr auto fpclassify BOOST_DECIMAL_PREVENT_MACRO_SUBSTITUTION (T rhs) noexcept
BOOST_DECIMAL_REQUIRES_RETURN(detail::is_decimal_floating_point_v, T, int)
{
constexpr T zero {0, 0};
Expand Down
11 changes: 6 additions & 5 deletions include/boost/decimal/detail/concepts.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#ifndef BOOST_DECIMAL_DETAIL_CONCEPTS
#define BOOST_DECIMAL_DETAIL_CONCEPTS

#include <boost/decimal/detail/config.hpp>
#include <boost/decimal/detail/promotion.hpp>
#include <boost/decimal/detail/type_traits.hpp>

Expand Down Expand Up @@ -413,23 +414,23 @@ concept execution_policy = std::is_execution_policy_v<std::remove_cvref_t<T>>;
#endif

#ifndef BOOST_DECIMAL_REQUIRES
# define BOOST_DECIMAL_REQUIRES(X, T) -> std::enable_if_t<X<T>, T>
# define BOOST_DECIMAL_REQUIRES(X, T) -> BOOST_DECIMAL_TYPE_TRAITS_NAMESPACE::enable_if_t<X<T>, T>
#endif

#ifndef BOOST_DECIMAL_REQUIRES_TWO
# define BOOST_DECIMAL_REQUIRES_TWO(X1, T1, X2, T2) -> std::enable_if_t<X1<T1> && X2<T2>, detail::promote_args_t<T1, T2>>
# define BOOST_DECIMAL_REQUIRES_TWO(X1, T1, X2, T2) -> BOOST_DECIMAL_TYPE_TRAITS_NAMESPACE::enable_if_t<X1<T1> && X2<T2>, detail::promote_args_t<T1, T2>>
#endif

#ifndef BOOST_DECIMAL_REQUIRES_TWO_RETURN
# define BOOST_DECIMAL_REQUIRES_TWO_RETURN(X1, T1, X2, T2, ReturnType) -> std::enable_if_t<X1<T1> && X2<T2>, ReturnType>
# define BOOST_DECIMAL_REQUIRES_TWO_RETURN(X1, T1, X2, T2, ReturnType) -> BOOST_DECIMAL_TYPE_TRAITS_NAMESPACE::enable_if_t<X1<T1> && X2<T2>, ReturnType>
#endif

#ifndef BOOST_DECIMAL_REQUIRES_THREE
# define BOOST_DECIMAL_REQUIRES_THREE(X1, T1, X2, T2, X3, T3) -> std::enable_if_t<X1<T1> && X2<T2> && X3<T3>, detail::promote_args_t<T1, T2, T3>>
# define BOOST_DECIMAL_REQUIRES_THREE(X1, T1, X2, T2, X3, T3) -> BOOST_DECIMAL_TYPE_TRAITS_NAMESPACE::enable_if_t<X1<T1> && X2<T2> && X3<T3>, detail::promote_args_t<T1, T2, T3>>
#endif

#ifndef BOOST_DECIMAL_REQUIRES_RETURN
# define BOOST_DECIMAL_REQUIRES_RETURN(X, T, ReturnType) -> std::enable_if_t<X<T>, ReturnType>
# define BOOST_DECIMAL_REQUIRES_RETURN(X, T, ReturnType) -> BOOST_DECIMAL_TYPE_TRAITS_NAMESPACE::enable_if_t<X<T>, ReturnType>
#endif

#endif //BOOST_DECIMAL_DETAIL_CONCEPTS
Loading

0 comments on commit 8df12cd

Please sign in to comment.