Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add NVRTC testing #24

Merged
merged 13 commits into from
Oct 21, 2024
58 changes: 58 additions & 0 deletions .github/workflows/cuda.yml
Original file line number Diff line number Diff line change
Expand Up @@ -75,3 +75,61 @@ jobs:
run: |
cd ../boost-root/__build__
ctest --output-on-failure --no-tests=error

nvrtc-cmake-test:
strategy:
fail-fast: false

runs-on: gpu-runner-1

steps:
- uses: Jimver/[email protected]
id: cuda-toolkit
with:
cuda: '12.5.0'
method: 'network'

- 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_CRYPT_ENABLE_NVRTC=1 -DCMAKE_CUDA_ARCHITECTURES=70 -DCUDA_TOOLKIT_ROOT_DIR=/usr/local/cuda-12.5 -DBOOST_CRYPT_NVRTC_CI_RUN=1 ..
pwd
- 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
3 changes: 2 additions & 1 deletion doc/crypt/overview.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ as well as emulated PPC64LE and STM32 using QEMU with the following compilers:
* GCC 7 and later
* Clang 6 and later
* Visual Studio 2017 and later
* Intel OneAPI DPC++
* Intel OneAPI DPC++ 2024.2 and later
* CUDA Toolkit 12.5 and later (Both NVCC and NVRTC)

Tested on https://github.com/cppalliance/decimal/actions[Github Actions] and https://drone.cpp.al/cppalliance/decimal[Drone].
Coverage can be found on https://app.codecov.io/gh/cppalliance/decimal[Codecov].
Expand Down
2 changes: 1 addition & 1 deletion include/boost/crypt/hash/md5.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
#include <boost/crypt/utility/iterator.hpp>
#include <boost/crypt/utility/file.hpp>

#ifndef BOOST_CRYPT_BUILD_MODULE
#if !defined(BOOST_CRYPT_BUILD_MODULE) && !defined(BOOST_CRYPT_HAS_CUDA)
#include <memory>
#include <string>
#include <cstdint>
Expand Down
2 changes: 1 addition & 1 deletion include/boost/crypt/hash/sha1.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
#include <boost/crypt/utility/file.hpp>
#include <boost/crypt/utility/null.hpp>

#ifndef BOOST_CRYPT_BUILD_MODULE
#if !defined(BOOST_CRYPT_BUILD_MODULE) && !defined(BOOST_CRYPT_HAS_CUDA)
#include <memory>
#include <string>
#include <cstdint>
Expand Down
4 changes: 3 additions & 1 deletion include/boost/crypt/utility/array.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#include <boost/crypt/utility/cstdint.hpp>
#include <boost/crypt/utility/cstddef.hpp>

#ifndef BOOST_CRYPT_BUILD_MODULE
#if !defined(BOOST_CRYPT_BUILD_MODULE) && !defined(BOOST_CRYPT_HAS_CUDA)
#include <array>
#endif

Expand Down Expand Up @@ -102,6 +102,7 @@ class array
*this = temp;
}

#ifndef BOOST_CRYPT_HAS_CUDA
constexpr operator std::array<T, N>() noexcept
{
std::array<T, N> new_array{};
Expand All @@ -112,6 +113,7 @@ class array

return new_array;
}
#endif
};

template <typename ForwardIter, typename T>
Expand Down
30 changes: 15 additions & 15 deletions include/boost/crypt/utility/byte.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,85 +18,85 @@ class byte
boost::crypt::uint8_t bits_;

public:
constexpr byte() noexcept : bits_ {} {}
explicit constexpr byte(boost::crypt::uint8_t bits) noexcept : bits_ {bits} {}
BOOST_CRYPT_GPU_ENABLED constexpr byte() noexcept : bits_ {} {}
BOOST_CRYPT_GPU_ENABLED explicit constexpr byte(boost::crypt::uint8_t bits) noexcept : bits_ {bits} {}

template <typename IntegerType>
constexpr auto to_integer() noexcept
BOOST_CRYPT_GPU_ENABLED constexpr auto to_integer() noexcept
BOOST_CRYPT_REQUIRES(boost::crypt::is_integral_v, IntegerType)
{
return static_cast<IntegerType>(bits_);
}

template <typename IntegerType>
constexpr auto operator<<(IntegerType shift) noexcept
BOOST_CRYPT_GPU_ENABLED constexpr auto operator<<(IntegerType shift) noexcept
BOOST_CRYPT_REQUIRES_RETURN(boost::crypt::is_integral_v, IntegerType, byte)
{
return byte{bits_ << shift};
}

template <typename IntegerType>
constexpr auto operator>>(IntegerType shift) noexcept
BOOST_CRYPT_GPU_ENABLED constexpr auto operator>>(IntegerType shift) noexcept
BOOST_CRYPT_REQUIRES_RETURN(boost::crypt::is_integral_v, IntegerType, byte)
{
return byte{bits_ >> shift};
}

constexpr auto operator|(byte rhs) const noexcept -> byte
BOOST_CRYPT_GPU_ENABLED constexpr auto operator|(byte rhs) const noexcept -> byte
{
return byte{static_cast<boost::crypt::uint8_t>(bits_ | rhs.bits_)};
}

constexpr auto operator&(byte rhs) const noexcept -> byte
BOOST_CRYPT_GPU_ENABLED constexpr auto operator&(byte rhs) const noexcept -> byte
{
return byte{static_cast<boost::crypt::uint8_t>(bits_ & rhs.bits_)};
}

constexpr auto operator^(byte rhs) const noexcept -> byte
BOOST_CRYPT_GPU_ENABLED constexpr auto operator^(byte rhs) const noexcept -> byte
{
return byte{static_cast<boost::crypt::uint8_t>(bits_ ^ rhs.bits_)};
}

constexpr auto operator~() const noexcept -> byte
BOOST_CRYPT_GPU_ENABLED constexpr auto operator~() const noexcept -> byte
{
return byte{static_cast<boost::crypt::uint8_t>(~bits_)};
}

template <typename IntegerType>
constexpr auto operator<<=(IntegerType shift) noexcept
BOOST_CRYPT_GPU_ENABLED constexpr auto operator<<=(IntegerType shift) noexcept
BOOST_CRYPT_REQUIRES_RETURN(boost::crypt::is_integral_v, IntegerType, byte&)
{
bits_ <<= shift;
return *this;
}

template <typename IntegerType>
constexpr auto operator >>=(IntegerType shift) noexcept
BOOST_CRYPT_GPU_ENABLED constexpr auto operator >>=(IntegerType shift) noexcept
BOOST_CRYPT_REQUIRES_RETURN(boost::crypt::is_integral_v, IntegerType, byte&)
{
bits_ >>= shift;
return *this;
}

constexpr auto operator|(byte rhs) noexcept -> byte&
BOOST_CRYPT_GPU_ENABLED constexpr auto operator|(byte rhs) noexcept -> byte&
{
bits_ = static_cast<boost::crypt::uint8_t>(bits_ | rhs.bits_);
return *this;
}

constexpr auto operator&(byte rhs) noexcept -> byte&
BOOST_CRYPT_GPU_ENABLED constexpr auto operator&(byte rhs) noexcept -> byte&
{
bits_ = static_cast<boost::crypt::uint8_t>(bits_ & rhs.bits_);
return *this;
}

constexpr auto operator^(byte rhs) noexcept -> byte&
BOOST_CRYPT_GPU_ENABLED constexpr auto operator^(byte rhs) noexcept -> byte&
{
bits_ = static_cast<boost::crypt::uint8_t>(bits_ ^ rhs.bits_);
return *this;
}

constexpr auto operator~() noexcept -> byte&
BOOST_CRYPT_GPU_ENABLED constexpr auto operator~() noexcept -> byte&
{
bits_ = static_cast<boost::crypt::uint8_t>(~bits_);
return *this;
Expand Down
23 changes: 15 additions & 8 deletions include/boost/crypt/utility/config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,18 +53,25 @@
// ---- Constexpr arrays -----

// ----- Assertions -----
#include <cassert>
#define BOOST_CRYPT_ASSERT(x) assert(x)
#define BOOST_CRYPT_ASSERT_MSG(expr, msg) assert((expr)&&(msg))
#ifndef BOOST_CRYPT_HAS_CUDA
# include <cassert>
# define BOOST_CRYPT_ASSERT(x) assert(x)
# define BOOST_CRYPT_ASSERT_MSG(expr, msg) assert((expr)&&(msg))
#else
# define BOOST_CRYPT_ASSERT(x)
# define BOOST_CRYPT_ASSERT_MSG(expr, msg)
#endif
// ----- Assertions -----

// ----- Has something -----
// C++17
#if __cplusplus >= 201703L || (defined(_MSVC_LANG) && _MSVC_LANG >= 201703L)
# if __has_include(<string_view>)
# include <string_view>
# if defined(__cpp_lib_string_view) && __cpp_lib_string_view >= 201606L
# define BOOST_CRYPT_HAS_STRING_VIEW
#ifndef BOOST_CRYPT_HAS_CUDA
# if __cplusplus >= 201703L || (defined(_MSVC_LANG) && _MSVC_LANG >= 201703L)
# if __has_include(<string_view>)
# include <string_view>
# if defined(__cpp_lib_string_view) && __cpp_lib_string_view >= 201606L
# define BOOST_CRYPT_HAS_STRING_VIEW
# endif
# endif
# endif
#endif
Expand Down
6 changes: 6 additions & 0 deletions include/boost/crypt/utility/file.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@
#define BOOST_CRYPT_UTILITY_FILE_HPP

#include <boost/crypt/utility/config.hpp>

// Can't use file streaming on a CUDA device anyway
#ifndef BOOST_CRYPT_HAS_CUDA

#include <boost/crypt/utility/cstdint.hpp>

#ifndef BOOST_CRYPT_BUILD_MODULE
Expand Down Expand Up @@ -83,4 +87,6 @@ class file_reader
} // namespace crypt
} // namespace boost

#endif // BOOST_CRYPT_HAS_CUDA

#endif //BOOST_CRYPT_UTILITY_FILE_HPP
16 changes: 16 additions & 0 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,22 @@ if(HAVE_BOOST_TEST)

boost_test_jamfile(FILE nvcc_jamfile LINK_LIBRARIES Boost::crypt ${CUDA_LIBRARIES} INCLUDE_DIRECTORIES ${CUDA_INCLUDE_DIRS} )

elseif (BOOST_CRYPT_ENABLE_NVRTC)

message(STATUS "Building boost.crypt with NVRTC")
find_package(CUDA REQUIRED)
set(CUDA_nvrtc_LIBRARY /usr/local/cuda/lib64/libnvrtc.so)

if (BOOST_CRYPT_NVRTC_CI_RUN)

boost_test_jamfile(FILE nvrtc_jamfile LINK_LIBRARIES Boost::crypt ${CUDA_nvrtc_LIBRARY} ${CUDA_LIBRARIES} ${CUDA_CUDA_LIBRARY} COMPILE_DEFINITIONS BOOST_CRYPT_NVRTC_CI_RUN=1 INCLUDE_DIRECTORIES ${CUDA_INCLUDE_DIRS})

else ()

boost_test_jamfile(FILE nvrtc_jamfile LINK_LIBRARIES Boost::crypt ${CUDA_nvrtc_LIBRARY} ${CUDA_LIBRARIES} ${CUDA_CUDA_LIBRARY} INCLUDE_DIRECTORIES ${CUDA_INCLUDE_DIRS} )

endif ()

else ()

boost_test_jamfile(FILE Jamfile LINK_LIBRARIES Boost::crypt Boost::core Boost::uuid)
Expand Down
13 changes: 13 additions & 0 deletions test/nvrtc_jamfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Copyright 2024 Matt Borland
# Distributed under the Boost Software License, Version 1.0.
# https://www.boost.org/LICENSE_1_0.txt

import testing ;
import ../../config/checks/config : requires ;

project : requirements
[ requires cxx14_decltype_auto cxx14_generic_lambdas cxx14_return_type_deduction cxx14_variable_templates cxx14_constexpr ]
;

run test_md5_nvrtc.cpp ;
run test_sha1_nvrtc.cpp ;
Loading
Loading