Skip to content

Commit

Permalink
Migrate C2H library to top-level library (#2629)
Browse files Browse the repository at this point in the history
Migrate CUB's c2h (catch2 helper) testing library to top-level.
  • Loading branch information
alliepiper authored Oct 29, 2024
1 parent ae2d9d2 commit c0f20c2
Show file tree
Hide file tree
Showing 126 changed files with 1,021 additions and 993 deletions.
2 changes: 1 addition & 1 deletion c/parallel/test/test_for.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

#include <algorithm>

#include "c2h.h"
#include "test_util.h"
#include <cccl/c/for.h>

void for_each(cccl_iterator_t input, unsigned long long num_items, cccl_op_t op)
Expand Down
2 changes: 1 addition & 1 deletion c/parallel/test/test_reduce.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

#include <cuda_runtime.h>

#include "c2h.h"
#include "test_util.h"

void reduce(cccl_iterator_t input, cccl_iterator_t output, unsigned long long num_items, cccl_op_t op, cccl_value_t init)
{
Expand Down
File renamed without changes.
41 changes: 41 additions & 0 deletions c2h/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
cmake_minimum_required(VERSION 3.21)

project(C2H LANGUAGES CXX CUDA)

cccl_get_catch2()

find_package(CCCL CONFIG REQUIRED
NO_DEFAULT_PATH # Only check the explicit HINTS below:
HINTS "${CCCL_SOURCE_DIR}/lib/cmake/cccl/"
)

find_package(CUDAToolkit)

set(curand_default OFF)
if (CUDA_curand_LIBRARY)
set(curand_default ON)
endif()

option(C2H_ENABLE_CURAND "Use CUDA CURAND library in c2h." ${curand_default})

add_library(cccl.c2h STATIC
generators.cu
)
target_include_directories(cccl.c2h PUBLIC "${C2H_SOURCE_DIR}/include")
target_link_libraries(cccl.c2h PUBLIC
CCCL::CCCL
Catch2::Catch2
)

if (C2H_ENABLE_CURAND)
target_link_libraries(cccl.c2h PRIVATE CUDA::curand)
target_compile_definitions(cccl.c2h PRIVATE C2H_HAS_CURAND=1)
else()
target_compile_definitions(cccl.c2h PRIVATE C2H_HAS_CURAND=0)
endif()

add_library(cccl.c2h.main OBJECT
catch2_runner.cpp
catch2_runner_helper.cu
)
target_link_libraries(cccl.c2h.main PUBLIC cccl.c2h)
2 changes: 1 addition & 1 deletion cub/test/catch2_runner.cpp → c2h/catch2_runner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,4 @@

#define CUB_CONFIG_MAIN
#define CUB_EXCLUDE_CATCH2_HELPER_IMPL
#include "catch2_main.cuh"
#include <c2h/catch2_main.cuh>
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion cub/test/c2h/generators.cu → c2h/generators.cu
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@
#include <c2h/custom_type.cuh>
#include <c2h/device_policy.cuh>
#include <c2h/extended_types.cuh>
#include <c2h/fill_striped.cuh>
#include <c2h/generators.cuh>
#include <c2h/vector.cuh>
#include <fill_striped.cuh>

#if C2H_HAS_CURAND
# include <curand.h>
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
#include <catch2/catch.hpp>

#if defined(CUB_CONFIG_MAIN)
# include "catch2_runner_helper.h"
# include <c2h/catch2_runner_helper.cuh>

# if !defined(CUB_EXCLUDE_CATCH2_HELPER_IMPL)
# include "catch2_runner_helper.inl"
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,13 @@

#include <cub/util_compiler.cuh>

#include <cuda/std/__cccl/diagnostic.h>

#include <cstdint>
#include <cstdlib>
#include <tuple>
#include <type_traits>

#include "cuda/std/__cccl/diagnostic.h"
#include "test_util_vec.h"

#if __CUDACC_VER_MAJOR__ == 11
_CCCL_NV_DIAG_SUPPRESS(177) // catch2 may contain unused variableds
#endif // nvcc-11
Expand All @@ -46,9 +45,9 @@ _CCCL_NV_DIAG_SUPPRESS(177) // catch2 may contain unused variableds
#include <cuda/std/type_traits>
#include <cuda/std/utility>

#include "catch2_main.cuh"
#include "test_warning_suppression.cuh"
#include <c2h/catch2_main.cuh>
#include <c2h/device_policy.cuh>
#include <c2h/test_util_vec.cuh>
#include <c2h/utility.cuh>
#include <c2h/vector.cuh>

Expand Down Expand Up @@ -234,26 +233,26 @@ struct Catch::StringMaker<cudaError>
#include <c2h/custom_type.cuh>
#include <c2h/generators.cuh>

#define CUB_TEST_NAME_IMPL(NAME, PARAM) CUB_TEST_STR(NAME) "(" CUB_TEST_STR(PARAM) ")"
#define C2H_TEST_NAME_IMPL(NAME, PARAM) C2H_TEST_STR(NAME) "(" C2H_TEST_STR(PARAM) ")"

#define CUB_TEST_NAME(NAME) CUB_TEST_NAME_IMPL(NAME, VAR_IDX)
#define C2H_TEST_NAME(NAME) C2H_TEST_NAME_IMPL(NAME, VAR_IDX)

#define CUB_TEST_CONCAT(A, B) CUB_TEST_CONCAT_INNER(A, B)
#define CUB_TEST_CONCAT_INNER(A, B) A##B
#define C2H_TEST_CONCAT(A, B) C2H_TEST_CONCAT_INNER(A, B)
#define C2H_TEST_CONCAT_INNER(A, B) A##B

#define CUB_TEST_IMPL(ID, NAME, TAG, ...) \
using CUB_TEST_CONCAT(types_, ID) = c2h::cartesian_product<__VA_ARGS__>; \
TEMPLATE_LIST_TEST_CASE(CUB_TEST_NAME(NAME), TAG, CUB_TEST_CONCAT(types_, ID))
#define C2H_TEST_IMPL(ID, NAME, TAG, ...) \
using C2H_TEST_CONCAT(types_, ID) = c2h::cartesian_product<__VA_ARGS__>; \
TEMPLATE_LIST_TEST_CASE(C2H_TEST_NAME(NAME), TAG, C2H_TEST_CONCAT(types_, ID))

#define CUB_TEST(NAME, TAG, ...) CUB_TEST_IMPL(__LINE__, NAME, TAG, __VA_ARGS__)
#define C2H_TEST(NAME, TAG, ...) C2H_TEST_IMPL(__LINE__, NAME, TAG, __VA_ARGS__)

#define CUB_TEST_LIST_IMPL(ID, NAME, TAG, ...) \
using CUB_TEST_CONCAT(types_, ID) = c2h::type_list<__VA_ARGS__>; \
TEMPLATE_LIST_TEST_CASE(CUB_TEST_NAME(NAME), TAG, CUB_TEST_CONCAT(types_, ID))
#define C2H_TEST_LIST_IMPL(ID, NAME, TAG, ...) \
using C2H_TEST_CONCAT(types_, ID) = c2h::type_list<__VA_ARGS__>; \
TEMPLATE_LIST_TEST_CASE(C2H_TEST_NAME(NAME), TAG, C2H_TEST_CONCAT(types_, ID))

#define CUB_TEST_LIST(NAME, TAG, ...) CUB_TEST_LIST_IMPL(__LINE__, NAME, TAG, __VA_ARGS__)
#define C2H_TEST_LIST(NAME, TAG, ...) C2H_TEST_LIST_IMPL(__LINE__, NAME, TAG, __VA_ARGS__)

#define CUB_TEST_STR(a) #a
#define C2H_TEST_STR(a) #a

namespace detail
{
Expand All @@ -267,7 +266,7 @@ inline std::size_t adjust_seed_count(std::size_t requested)
}
} // namespace detail

#define CUB_SEED(N) \
#define C2H_SEED(N) \
c2h::seed_t \
{ \
GENERATE_COPY(take( \
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,11 @@
#ifdef TEST_HALF_T
# include <cuda_fp16.h>

# include "../half.h"
# include <c2h/half.cuh>
#endif

#ifdef TEST_BF_T
# include <cuda_bf16.h>

# include "../bfloat16.h"
# include <c2h/bfloat16.cuh>
#endif
File renamed without changes.
File renamed without changes.
File renamed without changes.
84 changes: 42 additions & 42 deletions cub/test/test_util_vec.h → c2h/include/c2h/test_util_vec.cuh
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ inline int CoutCast(signed char val)
/**
* Vector1 overloads
*/
#define CUB_VEC_OVERLOAD_1(T, BaseT) \
#define C2H_VEC_OVERLOAD_1(T, BaseT) \
/* Ostream output */ \
inline std::ostream& operator<<(std::ostream& os, const T& val) \
{ \
Expand Down Expand Up @@ -105,7 +105,7 @@ inline int CoutCast(signed char val)
/**
* Vector2 overloads
*/
#define CUB_VEC_OVERLOAD_2(T, BaseT) \
#define C2H_VEC_OVERLOAD_2(T, BaseT) \
/* Ostream output */ \
inline std::ostream& operator<<(std::ostream& os, const T& val) \
{ \
Expand Down Expand Up @@ -150,7 +150,7 @@ inline int CoutCast(signed char val)
/**
* Vector3 overloads
*/
#define CUB_VEC_OVERLOAD_3(T, BaseT) \
#define C2H_VEC_OVERLOAD_3(T, BaseT) \
/* Ostream output */ \
inline std::ostream& operator<<(std::ostream& os, const T& val) \
{ \
Expand Down Expand Up @@ -203,7 +203,7 @@ inline int CoutCast(signed char val)
/**
* Vector4 overloads
*/
#define CUB_VEC_OVERLOAD_4(T, BaseT) \
#define C2H_VEC_OVERLOAD_4(T, BaseT) \
/* Ostream output */ \
inline std::ostream& operator<<(std::ostream& os, const T& val) \
{ \
Expand Down Expand Up @@ -264,27 +264,27 @@ inline int CoutCast(signed char val)
/**
* All vector overloads
*/
#define CUB_VEC_OVERLOAD(COMPONENT_T, BaseT) \
CUB_VEC_OVERLOAD_1(COMPONENT_T##1, BaseT) \
CUB_VEC_OVERLOAD_2(COMPONENT_T##2, BaseT) \
CUB_VEC_OVERLOAD_3(COMPONENT_T##3, BaseT) \
CUB_VEC_OVERLOAD_4(COMPONENT_T##4, BaseT)
#define C2H_VEC_OVERLOAD(COMPONENT_T, BaseT) \
C2H_VEC_OVERLOAD_1(COMPONENT_T##1, BaseT) \
C2H_VEC_OVERLOAD_2(COMPONENT_T##2, BaseT) \
C2H_VEC_OVERLOAD_3(COMPONENT_T##3, BaseT) \
C2H_VEC_OVERLOAD_4(COMPONENT_T##4, BaseT)

/**
* Define for types
*/
CUB_VEC_OVERLOAD(char, char)
CUB_VEC_OVERLOAD(short, short)
CUB_VEC_OVERLOAD(int, int)
CUB_VEC_OVERLOAD(long, long)
CUB_VEC_OVERLOAD(longlong, long long)
CUB_VEC_OVERLOAD(uchar, unsigned char)
CUB_VEC_OVERLOAD(ushort, unsigned short)
CUB_VEC_OVERLOAD(uint, unsigned int)
CUB_VEC_OVERLOAD(ulong, unsigned long)
CUB_VEC_OVERLOAD(ulonglong, unsigned long long)
CUB_VEC_OVERLOAD(float, float)
CUB_VEC_OVERLOAD(double, double)
C2H_VEC_OVERLOAD(char, char)
C2H_VEC_OVERLOAD(short, short)
C2H_VEC_OVERLOAD(int, int)
C2H_VEC_OVERLOAD(long, long)
C2H_VEC_OVERLOAD(longlong, long long)
C2H_VEC_OVERLOAD(uchar, unsigned char)
C2H_VEC_OVERLOAD(ushort, unsigned short)
C2H_VEC_OVERLOAD(uint, unsigned int)
C2H_VEC_OVERLOAD(ulong, unsigned long)
C2H_VEC_OVERLOAD(ulonglong, unsigned long long)
C2H_VEC_OVERLOAD(float, float)
C2H_VEC_OVERLOAD(double, double)

/*
* The following section defines macros to overload cub::NumericTraits<T>::{Max,Lowest}() for vector
Expand All @@ -294,7 +294,7 @@ CUB_VEC_OVERLOAD(double, double)
/**
* Vector1 overloads
*/
#define CUB_VEC_1_TRAITS_OVERLOAD(T, BaseT) \
#define C2H_VEC_1_TRAITS_OVERLOAD(T, BaseT) \
CUB_NAMESPACE_BEGIN \
template <> \
struct NumericTraits<T> \
Expand All @@ -321,7 +321,7 @@ CUB_VEC_OVERLOAD(double, double)
/**
* Vector2 overloads
*/
#define CUB_VEC_2_TRAITS_OVERLOAD(T, BaseT) \
#define C2H_VEC_2_TRAITS_OVERLOAD(T, BaseT) \
CUB_NAMESPACE_BEGIN \
template <> \
struct NumericTraits<T> \
Expand All @@ -348,7 +348,7 @@ CUB_VEC_OVERLOAD(double, double)
/**
* Vector3 overloads
*/
#define CUB_VEC_3_TRAITS_OVERLOAD(T, BaseT) \
#define C2H_VEC_3_TRAITS_OVERLOAD(T, BaseT) \
CUB_NAMESPACE_BEGIN \
template <> \
struct NumericTraits<T> \
Expand All @@ -375,7 +375,7 @@ CUB_VEC_OVERLOAD(double, double)
/**
* Vector4 overloads
*/
#define CUB_VEC_4_TRAITS_OVERLOAD(T, BaseT) \
#define C2H_VEC_4_TRAITS_OVERLOAD(T, BaseT) \
CUB_NAMESPACE_BEGIN \
template <> \
struct NumericTraits<T> \
Expand Down Expand Up @@ -408,24 +408,24 @@ CUB_VEC_OVERLOAD(double, double)
/**
* All vector overloads
*/
#define CUB_VEC_TRAITS_OVERLOAD(COMPONENT_T, BaseT) \
CUB_VEC_1_TRAITS_OVERLOAD(COMPONENT_T##1, BaseT) \
CUB_VEC_2_TRAITS_OVERLOAD(COMPONENT_T##2, BaseT) \
CUB_VEC_3_TRAITS_OVERLOAD(COMPONENT_T##3, BaseT) \
CUB_VEC_4_TRAITS_OVERLOAD(COMPONENT_T##4, BaseT)
#define C2H_VEC_TRAITS_OVERLOAD(COMPONENT_T, BaseT) \
C2H_VEC_1_TRAITS_OVERLOAD(COMPONENT_T##1, BaseT) \
C2H_VEC_2_TRAITS_OVERLOAD(COMPONENT_T##2, BaseT) \
C2H_VEC_3_TRAITS_OVERLOAD(COMPONENT_T##3, BaseT) \
C2H_VEC_4_TRAITS_OVERLOAD(COMPONENT_T##4, BaseT)

/**
* Define for types
*/
CUB_VEC_TRAITS_OVERLOAD(char, signed char)
CUB_VEC_TRAITS_OVERLOAD(short, short)
CUB_VEC_TRAITS_OVERLOAD(int, int)
CUB_VEC_TRAITS_OVERLOAD(long, long)
CUB_VEC_TRAITS_OVERLOAD(longlong, long long)
CUB_VEC_TRAITS_OVERLOAD(uchar, unsigned char)
CUB_VEC_TRAITS_OVERLOAD(ushort, unsigned short)
CUB_VEC_TRAITS_OVERLOAD(uint, unsigned int)
CUB_VEC_TRAITS_OVERLOAD(ulong, unsigned long)
CUB_VEC_TRAITS_OVERLOAD(ulonglong, unsigned long long)
CUB_VEC_TRAITS_OVERLOAD(float, float)
CUB_VEC_TRAITS_OVERLOAD(double, double)
C2H_VEC_TRAITS_OVERLOAD(char, signed char)
C2H_VEC_TRAITS_OVERLOAD(short, short)
C2H_VEC_TRAITS_OVERLOAD(int, int)
C2H_VEC_TRAITS_OVERLOAD(long, long)
C2H_VEC_TRAITS_OVERLOAD(longlong, long long)
C2H_VEC_TRAITS_OVERLOAD(uchar, unsigned char)
C2H_VEC_TRAITS_OVERLOAD(ushort, unsigned short)
C2H_VEC_TRAITS_OVERLOAD(uint, unsigned int)
C2H_VEC_TRAITS_OVERLOAD(ulong, unsigned long)
C2H_VEC_TRAITS_OVERLOAD(ulonglong, unsigned long long)
C2H_VEC_TRAITS_OVERLOAD(float, float)
C2H_VEC_TRAITS_OVERLOAD(double, double)
File renamed without changes.
File renamed without changes.
5 changes: 4 additions & 1 deletion ci/inspect_changes.sh
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,19 @@ subprojects=(
cudax
python
cccl_c_parallel
c2h
)

# ...and their dependencies:
declare -A dependencies=(
[cccl]=""
[libcudacxx]="cccl"
[cub]="cccl libcudacxx thrust"
[cub]="cccl libcudacxx thrust c2h"
[thrust]="cccl libcudacxx cub"
[cudax]="cccl libcudacxx"
[python]="cccl libcudacxx cub thrust cccl_c_parallel"
[cccl_c_parallel]="cccl libcudacxx cub thrust"
[c2h]="cccl libcudacxx cub thrust"
)

declare -A project_names=(
Expand All @@ -49,6 +51,7 @@ declare -A project_names=(
[cudax]="CUDA Experimental"
[python]="python"
[cccl_c_parallel]="CCCL C Parallel Library"
[c2h]="Catch2Helper"
)

# By default, the project directory is assumed to be the same as the subproject name,
Expand Down
7 changes: 7 additions & 0 deletions cmake/CCCLGetDependencies.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@ macro(cccl_get_boost)
CPMAddPackage("gh:boostorg/boost#boost-1.83.0")
endmacro()

# The CCCL Catch2Helper library:
macro(cccl_get_c2h)
if (NOT TARGET cccl.c2h)
add_subdirectory("${CCCL_SOURCE_DIR}/c2h" "${CCCL_BINARY_DIR}/c2h")
endif()
endmacro()

macro(cccl_get_catch2)
include("${_cccl_cpm_file}")
CPMAddPackage("gh:catchorg/[email protected]")
Expand Down
9 changes: 8 additions & 1 deletion cub/examples/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# Some of the examples include the `cub/test/test_util.h` header, which
# depends on c2h:
cccl_get_c2h()

# Create meta targets that build all examples for a single configuration:
foreach(cub_target IN LISTS CUB_TARGETS)
cub_get_target_property(config_prefix ${cub_target} PREFIX)
Expand Down Expand Up @@ -30,7 +34,10 @@ function(cub_add_example target_name_var example_name example_src cub_target)
set(example_meta_target cub.all.example.${example_name})

add_executable(${example_target} "${example_src}")
target_link_libraries(${example_target} ${cub_target})
target_link_libraries(${example_target} PRIVATE
${cub_target}
cccl.c2h
)
cub_clone_target_properties(${example_target} ${cub_target})
cub_configure_cuda_target(${example_target} RDC ${CUB_FORCE_RDC})
target_include_directories(${example_target} PRIVATE "${CUB_SOURCE_DIR}/examples")
Expand Down
Loading

0 comments on commit c0f20c2

Please sign in to comment.