Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions projects/rocthrust/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@
Documentation for rocThrust available at
[https://rocm.docs.amd.com/projects/rocThrust/en/latest/](https://rocm.docs.amd.com/projects/rocThrust/en/latest/).

## rocThrust x.y.z for ROCm x.y

### Added

* If you are using rocThrust on the host-side only, you can now build using g++ or non-HIP-aware clang++. To configure rocThrust in this-way, set the new CMake option `ROCTHRUST_DEVICE_SYSTEM` to `CPP` (other options include `HIP`, `CUDA`, `OpenMP`, and `TBB`), and set `CXX` to g++ or clang++. Then install rocThrust via `make install`. When you compile your application, don't forget to include the rocThrust include directory (`-I /opt/rocm/include`), since this won't happen automatically like it does when building with hipcc. Note that currently, rocThrust tests and benchmarks cannot be built when configuring rocThrust for host-side-only use.

## rocThrust 4.2.0 for ROCm 7.2

### Added
Expand Down
17 changes: 16 additions & 1 deletion projects/rocthrust/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,22 @@ cmake_dependent_option(ENABLE_UPSTREAM_TESTS "Enable upstream (thrust) tests" ON
cmake_dependent_option(USE_SYSTEM_LIB "Use existing system ROCm library installation when building tests" OFF BUILD_TEST OFF)
option(EXTERNAL_DEPS_FORCE_DOWNLOAD "Force download of non-ROCm dependencies (eg. Google Test, Google Benchmark)" OFF)

check_language(HIP)
set(DEVICE_SYSTEM_OPTIONS "HIP" "CUDA" "CPP" "OpenMP" "TBB")
set(ROCTHRUST_DEVICE_SYSTEM "HIP" CACHE STRING "Set device system for thrust (options are ${DEVICE_SYSTEM_OPTIONS})")

if(NOT ${ROCTHRUST_DEVICE_SYSTEM} IN_LIST DEVICE_SYSTEM_OPTIONS)
message(FATAL_ERROR "Unrecognized ROCTHRUST_DEVICE_SYSTEM option \"${ROCTHRUST_DEVICE_SYSTEM}\". Valid options are: ${DEVICE_SYSTEM_OPTIONS}")
endif()

if((BUILD_TEST OR BUILD_BENCHMARK OR BUILD_EXAMPLE) AND
NOT (${ROCTHRUST_DEVICE_SYSTEM} STREQUAL "HIP" OR $ROCTHRUST_DEVICE_SYSTEM STREQUAL "CUDA"))
message(FATAL_ERROR "rocThrust tests, benchmarks, and examples must be built with ROCTHRUST_DEVICE_SYSTEM=HIP|CUDA since they require device acceleration.")
endif()

if(${ROCTHRUST_DEVICE_SYSTEM} STREQUAL "HIP")
check_language(HIP)
endif()

cmake_dependent_option(USE_HIPCXX "Use CMake HIP language support" OFF CMAKE_HIP_COMPILER OFF)

include(CheckCXXCompilerFlag)
Expand Down
6 changes: 4 additions & 2 deletions projects/rocthrust/cmake/Dependencies.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -236,9 +236,10 @@ function(fetch_dep method repo_name repo_path download_branch)
endif()
endfunction()

fetch_dep(ROCPRIM_FETCH_METHOD rocprim ROCPRIM_PATH ROCM_DEP_RELEASE_BRANCH)
if(${ROCTHRUST_DEVICE_SYSTEM} STREQUAL "HIP")
fetch_dep(ROCPRIM_FETCH_METHOD rocprim ROCPRIM_PATH ROCM_DEP_RELEASE_BRANCH)

if(${ROCPRIM_FETCH_METHOD} STREQUAL "DOWNLOAD" OR ${ROCPRIM_FETCH_METHOD} STREQUAL "MONOREPO")
if(${ROCPRIM_FETCH_METHOD} STREQUAL "DOWNLOAD" OR ${ROCPRIM_FETCH_METHOD} STREQUAL "MONOREPO")
# The fetch_dep call above should have downloaded/located the source. We just need to make it available.
message(STATUS "Configuring rocPRIM")
FetchContent_Declare(
Expand All @@ -258,6 +259,7 @@ if(${ROCPRIM_FETCH_METHOD} STREQUAL "DOWNLOAD" OR ${ROCPRIM_FETCH_METHOD} STREQU
add_library(roc::rocprim_hip ALIAS rocprim_hip)
endif()
endif()
endif()

# Test dependencies
if(BUILD_TEST OR BUILD_HIPSTDPAR_TEST)
Expand Down
1 change: 1 addition & 0 deletions projects/rocthrust/cmake/Summary.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ endif()
message(STATUS " USE_SYSTEM_LIB : ${USE_SYSTEM_LIB}")
message(STATUS " BUILD_ADDRESS_SANITIZER : ${BUILD_ADDRESS_SANITIZER}")
message(STATUS " EXTERNAL_DEPS_FORCE_DOWNLOAD : ${EXTERNAL_DEPS_FORCE_DOWNLOAD}")
message(STATUS " ROCTHRUST_DEVICE_SYSTEM : ${ROCTHRUST_DEVICE_SYSTEM}")
message(STATUS "")
message(STATUS "Detailed:")
message(STATUS " C++ compiler details : \n${CMAKE_CXX_COMPILER_VERBOSE_DETAILS}")
Expand Down
29 changes: 18 additions & 11 deletions projects/rocthrust/cmake/VerifyCompiler.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -20,21 +20,28 @@
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.

list(APPEND CMAKE_PREFIX_PATH /opt/rocm /opt/rocm/hip)
find_package(hip REQUIRED CONFIG PATHS /opt/rocm)
if(${ROCTHRUST_DEVICE_SYSTEM} STREQUAL "HIP")
list(APPEND CMAKE_PREFIX_PATH /opt/rocm /opt/rocm/hip)
find_package(hip REQUIRED CONFIG PATHS /opt/rocm)
endif()

if(HIP_COMPILER STREQUAL "nvcc")
message(FATAL_ERROR "rocThrust does not support the CUDA backend.")
elseif(HIP_COMPILER STREQUAL "clang")
if(USE_HIPCXX)
if(NOT (CMAKE_HIP_COMPILER MATCHES ".*hipcc$" OR CMAKE_HIP_COMPILER MATCHES ".*clang\\+\\+"))
message(FATAL_ERROR "On ROCm platform 'hipcc' or HIP-aware Clang must be used as HIP compiler.")
endif()

if(${ROCTHRUST_DEVICE_SYSTEM} STREQUAL "HIP")
# When building for HIP, make sure we have a hip-aware clang.
if(HIP_COMPILER STREQUAL "clang")
if(USE_HIPCXX)
if(NOT (CMAKE_HIP_COMPILER MATCHES ".*hipcc$" OR CMAKE_HIP_COMPILER MATCHES ".*clang\\+\\+"))
message(FATAL_ERROR "When ROCTHRUST_DEVICE_SYSTEM is set to 'HIP', then 'hipcc' or a HIP-aware Clang must be used as the C++ compiler.")
endif()
else()
if(NOT (CMAKE_CXX_COMPILER MATCHES ".*hipcc$" OR CMAKE_CXX_COMPILER MATCHES ".*clang\\+\\+"))
message(FATAL_ERROR "When ROCTHRUST_DEVICE_SYSTEM is set to 'HIP', then 'hipcc' or a HIP-aware Clang must be used as the C++ compiler.")
endif()
endif()
else()
if(NOT (CMAKE_CXX_COMPILER MATCHES ".*hipcc$" OR CMAKE_CXX_COMPILER MATCHES ".*clang\\+\\+"))
message(FATAL_ERROR "On ROCm platform 'hipcc' or HIP-aware Clang must be used as C++ compiler.")
endif()
message(FATAL_ERROR "When ROCTHRUST_DEVICE_SYSTEM is set to 'HIP', HIP_COMPILER must be `clang` (AMD ROCm platform)")
endif()
else()
message(FATAL_ERROR "HIP_COMPILER must be `clang` (AMD ROCm platform)")
endif()
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ The build options are:
* ``EXTERNAL_DEPS_FORCE_DOWNLOAD``. Set this to ``ON`` to download the non-ROCm dependencies such as Google Test even if they're already installed. Default is ``OFF``.
* ``USE_HIPCXX``. Set this to ``ON`` to build with CMake HIP language support. Setting this to ``ON`` eliminates the need to use ``CXX=hipcc``. Default is ``OFF``.
* ``ROCPRIM_FETCH_METHOD`` and ``ROCRAND_FETCH_METHOD``. Set these to the method to use to download the rocPRIM and rocRAND components, respectively. Can be set to ``PACKAGE``, ``DOWNLOAD``, or ``MONOREPO``. Set to ``MONOREPO`` if the component isn't already installed and you're building rocThrust from within a clone of the `rocm-libraries <https://github.com/ROCm/rocm-libraries/>`_ repository that includes the component. Set to ``DOWNLOAD`` if the component isn't installed and you aren't in a clone of the ``rocm-libraries`` repository that includes the component. ``DOWNLOAD`` will clone the repository using sparse checkout so that only the necessary files are downloaded. Set to ``PACKAGE`` if the component is already installed. If the component isn't installed, it'll be downloaded form the repository in the same way as using the ``DOWNLOAD`` option. The default method is ``PACKAGE``.
* ``ROCTHRUST_DEVICE_SYSTEM``. This option controls how rocThrust is linked. It may be set to one of: ``HIP``, ``CUDA``, ``TBB``, ``OpenMP``, or ``CPP``. If it's set to ``HIP`` or ``CUDA``, then the code links against device dependencies (eg. for ``HIP``, it looks for rocPRIM). If it's set to ``CPP``, then it does not link against device dependencies - it performs host-side compuation only.

.. note::

Expand Down
28 changes: 19 additions & 9 deletions projects/rocthrust/thrust/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,12 @@ target_include_directories(rocthrust
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}/>
)

target_link_libraries(rocthrust
INTERFACE
if(${ROCTHRUST_DEVICE_SYSTEM} STREQUAL "HIP")
target_link_libraries(rocthrust
INTERFACE
roc::rocprim_hip
)
)
endif()

# hipstdpar header target
add_library(hipstdpar INTERFACE)
Expand Down Expand Up @@ -57,9 +59,17 @@ rocm_install(
)

include(ROCMExportTargetsHeaderOnly)
# Export targets
rocm_export_targets_header_only(
TARGETS roc::rocthrust
DEPENDS PACKAGE rocprim
NAMESPACE roc::
)

if(${ROCTHRUST_DEVICE_SYSTEM} STREQUAL "HIP")
# Export targets
rocm_export_targets_header_only(
TARGETS roc::rocthrust
DEPENDS PACKAGE rocprim
NAMESPACE roc::
)
else()
rocm_export_targets_header_only(
TARGETS roc::rocthrust
NAMESPACE roc::
)
endif()
6 changes: 4 additions & 2 deletions projects/rocthrust/thrust/detail/alignment.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@

#if _THRUST_HAS_DEVICE_SYSTEM_STD
# include _THRUST_LIBCXX_INCLUDE(cmath)
#else
#elif _THRUST_USE_ROCPRIM
# include <rocprim/detail/various.hpp>
#endif

Expand Down Expand Up @@ -82,8 +82,10 @@ THRUST_HOST_DEVICE inline _THRUST_STD::size_t aligned_storage_size(_THRUST_STD::
{
#if _THRUST_HAS_DEVICE_SYSTEM_STD
return _THRUST_LIBCXX::ceil_div(n, align) * align;
#else
#elif _THRUST_USE_ROCPRIM
return ::rocprim::detail::ceiling_div(n, align) * align;
#else
return (n / align + (n % align > 0 ? 1 : 0)) * align;
#endif
}
} // end namespace detail
Expand Down
2 changes: 1 addition & 1 deletion projects/rocthrust/thrust/detail/config/device_system.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
#ifndef THRUST_DEVICE_SYSTEM
# if THRUST_DEVICE_COMPILER == THRUST_DEVICE_COMPILER_HIP
# define THRUST_DEVICE_SYSTEM THRUST_DEVICE_SYSTEM_HIP
# elif THRUST_DEVICE_COMPILER == THRUST_DEVICE_COMPILER_CLANG
# elif THRUST_DEVICE_COMPILER == THRUST_DEVICE_COMPILER_CLANG || THRUST_DEVICE_COMPILER == THRUST_DEVICE_COMPILER_GCC
# define THRUST_DEVICE_SYSTEM THRUST_DEVICE_SYSTEM_CPP
# else
# define THRUST_DEVICE_SYSTEM THRUST_DEVICE_SYSTEM_CUDA
Expand Down
3 changes: 3 additions & 0 deletions projects/rocthrust/thrust/detail/config/libcxx.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
# define _THRUST_HAS_DEVICE_SYSTEM_STD 1
# define _THRUST_STD_NAMESPACE_BEGIN _LIBCUDACXX_BEGIN_NAMESPACE_STD
# define _THRUST_STD_NAMESPACE_END _LIBCUDACXX_END_NAMESPACE_STD
# define _THRUST_USE_ROCPRIM 0
# endif

// Otherwise, if the '::hip::std' namespace from 'libhipcxx' is available.
Expand All @@ -71,6 +72,7 @@
# define _THRUST_HAS_DEVICE_SYSTEM_STD 1
# define _THRUST_STD_NAMESPACE_BEGIN _LIBCUDACXX_BEGIN_NAMESPACE_STD
# define _THRUST_STD_NAMESPACE_END _LIBCUDACXX_END_NAMESPACE_STD
# define _THRUST_USE_ROCPRIM 0
# endif
#endif

Expand All @@ -85,4 +87,5 @@
namespace std \
{
# define _THRUST_STD_NAMESPACE_END }
# define _THRUST_USE_ROCPRIM (THRUST_DEVICE_SYSTEM != THRUST_DEVICE_SYSTEM_CPP)
#endif
12 changes: 9 additions & 3 deletions projects/rocthrust/thrust/detail/type_traits.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@

#include _THRUST_STD_INCLUDE(type_traits)

#if !_THRUST_HAS_DEVICE_SYSTEM_STD
#if !_THRUST_HAS_DEVICE_SYSTEM_STD && _THRUST_USE_ROCPRIM
# include <rocprim/type_traits.hpp>
# include <rocprim/type_traits_functions.hpp>
#endif // !_THRUST_HAS_DEVICE_SYSTEM_STD
Expand Down Expand Up @@ -75,7 +75,11 @@ template <typename T>
using make_unsigned_t = typename ::std::make_unsigned<T>::type;

template <typename Invokable, typename InputT, typename InitT = InputT>
#if _THRUST_USE_ROCPRIM
using accumulator_t = ::rocprim::accumulator_t<Invokable, InputT, InitT>;
#else
using accumulator_t = _THRUST_STD::decay_t<_THRUST_STD::invoke_result_t<Invokable, InitT, InputT>>;
#endif
template <typename T>
// If we're not on Windows and we have libstdc++ >= 10, we can use the __decay_t
// builtin to reduce compilation time.
Expand Down Expand Up @@ -146,7 +150,7 @@ struct is_unbounded_array<T[]> : public thrust::detail::true_type
template <typename T>
struct is_bounded_array : public thrust::detail::false_type
{};
template <typename T, size_t N>
template <typename T, _THRUST_STD::size_t N>
struct is_bounded_array<T[N]> : public thrust::detail::true_type
{};

Expand Down Expand Up @@ -233,8 +237,10 @@ struct larger_type
template <class F, class... Us>
#if _THRUST_HAS_DEVICE_SYSTEM_STD
using invoke_result = _THRUST_STD::__invoke_of<F, Us...>;
#else // !_THRUST_HAS_DEVICE_SYSTEM_STD
#elif _THRUST_USE_ROCPRIM // !_THRUST_HAS_DEVICE_SYSTEM_STD
using invoke_result = ::rocprim::invoke_result<F, Us...>;
#else
using invoke_result = _THRUST_STD::invoke_result<F, Us...>;
#endif // _THRUST_HAS_DEVICE_SYSTEM_STD

template <class F, class... Us>
Expand Down
1 change: 1 addition & 0 deletions projects/rocthrust/thrust/iterator/zip_iterator.h
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ THRUST_NAMESPACE_BEGIN
* \see tuple
* \see get
*/

template <typename IteratorTuple>
class THRUST_DECLSPEC_EMPTY_BASES zip_iterator : public detail::zip_iterator_base<IteratorTuple>::type
{
Expand Down
2 changes: 1 addition & 1 deletion projects/rocthrust/thrust/pair.h
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ inline THRUST_HOST_DEVICE pair<T1, T2> make_pair(T1 x, T2 y);
* \tparam N This parameter selects the member of interest.
* \tparam T A \c pair type of interest.
*/
template <size_t N, class T>
template <_THRUST_STD::size_t N, class T>
struct tuple_element;

/*! This convenience metafunction is included for compatibility with
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ namespace sequential
template <typename DerivedPolicy, typename Pointer1, typename Pointer2>
THRUST_HOST_DEVICE void iter_swap(sequential::execution_policy<DerivedPolicy>&, Pointer1 a, Pointer2 b)
{
#if _THRUST_HAS_DEVICE_SYSTEM_STD
#if _THRUST_HAS_DEVICE_SYSTEM_STD || THRUST_DEVICE_SYSTEM == THRUST_DEVICE_SYSTEM_CPP
using _THRUST_STD::swap;
#else
using thrust::swap;
Expand Down