Skip to content

Commit

Permalink
Merge pull request #753 from steffenlarsen/steffen/make_accessor_test…
Browse files Browse the repository at this point in the history
…_combinations_templated

Make accessor test cases templated on non-type arguments
  • Loading branch information
bader committed Jul 25, 2023
2 parents 22a7350 + 4c9c485 commit d6c817c
Show file tree
Hide file tree
Showing 98 changed files with 999 additions and 552 deletions.
161 changes: 135 additions & 26 deletions tests/accessor/accessor_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -219,42 +219,151 @@ void common_run_tests() {
}

/**
* @brief Factory function for getting type_pack with access modes values
* @brief Alias for a value pack containing all tested access modes.
*/
inline auto get_access_modes() {
static const auto access_modes =
value_pack<sycl::access_mode, sycl::access_mode::read,
sycl::access_mode::write,
sycl::access_mode::read_write>::generate_named();
return access_modes;
}
using access_modes_pack =
value_pack<sycl::access_mode, sycl::access_mode::read,
sycl::access_mode::write, sycl::access_mode::read_write>;

/**
* @brief Factory function for getting type_pack with dimensions values
* @brief Alias for a integer value pack containing all valid non-zero
* dimensions.
*/
inline auto get_dimensions() {
static const auto dimensions = integer_pack<1, 2, 3>::generate_unnamed();
return dimensions;
}
using dimensions_pack = integer_pack<1, 2, 3>;

/**
* @brief Factory function for getting type_pack with all (including zero)
* dimensions values
* @brief Alias for a integer value pack containing all valid dimensions.
*/
inline auto get_all_dimensions() {
static const auto dimensions = integer_pack<0, 1, 2, 3>::generate_unnamed();
return dimensions;
}
using all_dimensions_pack = integer_pack<0, 1, 2, 3>;

/**
* @brief Factory function for getting type_pack with target values
* @brief Alias for a value pack containing all tested targets.
*/
inline auto get_targets() {
static const auto targets =
value_pack<sycl::target, sycl::target::device,
sycl::target::host_task>::generate_named();
return targets;
}
using targets_pack =
value_pack<sycl::target, sycl::target::device, sycl::target::host_task>;

/**
* @brief Lightweight struct for containing tuple types with the singleton packs
* comprising a single combination to test.
*/
template <typename... Ts>
struct combinations_list {};

/**
* @brief Helper trait for concatenating two combinations_list.
*/
template <typename LCombs, typename RCombs>
struct concat_combination_lists;
template <typename... LCombTs, typename... RCombTs>
struct concat_combination_lists<combinations_list<LCombTs...>,
combinations_list<RCombTs...>> {
using type = combinations_list<LCombTs..., RCombTs...>;
};

/**
* @brief Helper trait for appending an element to a combinations_list.
*/
template <typename Comb, typename Combs>
struct append_comb;
template <typename Comb, typename... CombTs>
struct append_comb<Comb, combinations_list<CombTs...>> {
using type = combinations_list<Comb, CombTs...>;
};

/**
* @brief Helper trait for appending a type to each element in a
* combinations_list.
*/
template <typename T, typename Combs>
struct append_type_to_combs;
template <typename T, typename... ElemTs, typename... CombTs>
struct append_type_to_combs<
T, combinations_list<std::tuple<ElemTs...>, CombTs...>> {
using tail =
typename append_type_to_combs<T, combinations_list<CombTs...>>::type;
using type = typename append_comb<std::tuple<ElemTs..., T>, tail>::type;
};
template <typename T>
struct append_type_to_combs<T, combinations_list<>> {
using type = combinations_list<>;
};

/**
* @brief Helper trait for either appending a type to each element of a
* combinations_list or creating a new combination with T if the given
* combination_list is empty.
*/
template <typename T, typename Combs>
struct append_or_create_combs {
using type = typename append_type_to_combs<T, Combs>::type;
};
template <typename T>
struct append_or_create_combs<T, combinations_list<>> {
using type = combinations_list<std::tuple<T>>;
};

/**
* @brief Helper trait for getting all combinations of the values and types in
* the specified packs.
*/
template <typename CurrentLevelCombs, typename LastLevelCombs,
typename... Packs>
struct get_combinations_helper;
template <typename CurrentLevelCombs, typename LastLevelCombs>
struct get_combinations_helper<CurrentLevelCombs, LastLevelCombs> {
using type = LastLevelCombs;
};
template <typename CurrentLevelCombs, typename LastLevelCombs, typename T, T V,
T... Vs, typename... Packs>
struct get_combinations_helper<CurrentLevelCombs, LastLevelCombs,
value_pack<T, V, Vs...>, Packs...> {
using new_combs =
typename append_or_create_combs<value_pack<T, V>, LastLevelCombs>::type;
using new_current_level_combs =
typename concat_combination_lists<CurrentLevelCombs, new_combs>::type;
using type =
typename get_combinations_helper<new_current_level_combs, LastLevelCombs,
value_pack<T, Vs...>, Packs...>::type;
};
template <typename CurrentLevelCombs, typename LastLevelCombs, typename T,
typename... Packs>
struct get_combinations_helper<CurrentLevelCombs, LastLevelCombs, value_pack<T>,
Packs...> {
using type =
typename get_combinations_helper<combinations_list<>, CurrentLevelCombs,
Packs...>::type;
};
template <typename CurrentLevelCombs, typename LastLevelCombs, typename T,
typename... Ts, typename... Packs>
struct get_combinations_helper<CurrentLevelCombs, LastLevelCombs,
type_pack<T, Ts...>, Packs...> {
using new_combs =
typename append_or_create_combs<type_pack<T>, LastLevelCombs>::type;
using new_current_level_combs =
typename concat_combination_lists<CurrentLevelCombs, new_combs>::type;
using type =
typename get_combinations_helper<new_current_level_combs, LastLevelCombs,
type_pack<Ts...>, Packs...>::type;
};
template <typename CurrentLevelCombs, typename LastLevelCombs,
typename... Packs>
struct get_combinations_helper<CurrentLevelCombs, LastLevelCombs, type_pack<>,
Packs...> {
using type =
typename get_combinations_helper<combinations_list<>, CurrentLevelCombs,
Packs...>::type;
};

/**
* @brief Trait for getting all combinations of the values and types in the
* specified packs.
*/
template <typename... Packs>
struct get_combinations {
using type =
typename get_combinations_helper<combinations_list<>, combinations_list<>,
Packs...>::type;
};

/**
* @brief Function helps to generate type_pack with sycl::vec of all supported
Expand Down
20 changes: 16 additions & 4 deletions tests/accessor/accessor_default_values.h
Original file line number Diff line number Diff line change
Expand Up @@ -193,21 +193,33 @@ class test_for_generic_acc_placeholder_val_verification {
}
};

using test_combinations =
typename get_combinations<access_modes_pack, all_dimensions_pack,
targets_pack>::type;

/**
* @brief Struct with functor that will be used in type coverage to call all
* verification functions.
* @tparam T Current data type
* @tparam ArgCombination A tuple containing the packs representing the current
* test configuration. The packs appear in the following order:
* access_mode, dimension, target
* @param type_name Current data type string representation
*/
template <typename T>
template <typename T, typename ArgCombination>
class run_tests {
public:
void operator()(const std::string& type_name) {
// Get the packs from the test combination type.
using AccessModePack = std::tuple_element_t<0, ArgCombination>;
using DimensionsPack = std::tuple_element_t<1, ArgCombination>;
using TargetsPack = std::tuple_element_t<2, ArgCombination>;

// Type packs instances have to be const, otherwise for_all_combination
// will not compile
const auto access_modes = get_access_modes();
const auto dimensions = get_all_dimensions();
const auto targets = get_targets();
const auto access_modes = AccessModePack::generate_named();
const auto dimensions = DimensionsPack::generate_unnamed();
const auto targets = TargetsPack::generate_named();

// Run test with non const data type
// Run test for local_accessor
Expand Down
6 changes: 3 additions & 3 deletions tests/accessor/accessor_default_values_core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ using namespace accessor_tests_common;
namespace accessor_default_values_test_core {
using namespace sycl_cts;

DISABLED_FOR_TEST_CASE(hipSYCL, ComputeCpp)
("Accessors constructor default values test core types.",
"[accessor]")({ common_run_tests<run_tests>(); });
DISABLED_FOR_TEMPLATE_LIST_TEST_CASE(hipSYCL, ComputeCpp)
("Accessors constructor default values test core types.", "[accessor]",
test_combinations)({ common_run_tests<run_tests, TestType>(); });

} // namespace accessor_default_values_test_core
9 changes: 5 additions & 4 deletions tests/accessor/accessor_default_values_fp16.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,9 @@ using namespace accessor_tests_common;
namespace accessor_exceptions_test_fp16 {
using namespace sycl_cts;

DISABLED_FOR_TEST_CASE(hipSYCL, ComputeCpp)
("Accessors constructor default values test fp16 types.", "[accessor]")({
DISABLED_FOR_TEMPLATE_LIST_TEST_CASE(hipSYCL, ComputeCpp)
("Accessors constructor default values test fp16 types.", "[accessor]",
test_combinations)({
auto queue = sycl_cts::util::get_cts_object::queue();
if (!queue.get_device().has(sycl::aspect::fp16)) {
WARN(
Expand All @@ -35,9 +36,9 @@ DISABLED_FOR_TEST_CASE(hipSYCL, ComputeCpp)
}

#if SYCL_CTS_ENABLE_FULL_CONFORMANCE
for_type_vectors_marray<run_tests, sycl::half>("sycl::half");
for_type_vectors_marray<run_tests, sycl::half, TestType>("sycl::half");
#else
run_tests<sycl::half>{}("sycl::half");
run_tests<sycl::half, TestType>{}("sycl::half");
#endif // SYCL_CTS_ENABLE_FULL_CONFORMANCE
});

Expand Down
9 changes: 5 additions & 4 deletions tests/accessor/accessor_default_values_fp64.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,9 @@ using namespace accessor_tests_common;
namespace accessor_default_values_test_fp64 {
using namespace sycl_cts;

DISABLED_FOR_TEST_CASE(hipSYCL, ComputeCpp)
("Accessors constructor default values test fp64 types.", "[accessor]")({
DISABLED_FOR_TEMPLATE_LIST_TEST_CASE(hipSYCL, ComputeCpp)
("Accessors constructor default values test fp64 types.", "[accessor]",
test_combinations)({
auto queue = sycl_cts::util::get_cts_object::queue();
if (!queue.get_device().has(sycl::aspect::fp64)) {
WARN(
Expand All @@ -35,9 +36,9 @@ DISABLED_FOR_TEST_CASE(hipSYCL, ComputeCpp)
}

#if SYCL_CTS_ENABLE_FULL_CONFORMANCE
for_type_vectors_marray<run_tests, double>("double");
for_type_vectors_marray<run_tests, double, TestType>("double");
#else
run_tests<double>{}("double");
run_tests<double, TestType>{}("double");
#endif // SYCL_CTS_ENABLE_FULL_CONFORMANCE
});

Expand Down
15 changes: 11 additions & 4 deletions tests/accessor/accessor_exceptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,9 @@ class test_exception_for_generic_acc {
}
};

using test_combinations =
typename get_combinations<access_modes_pack, dimensions_pack>::type;

/**
* @brief Struct that runs test with different input parameters types
* @tparam AccT Current type of the accessor: generic_accessor,
Expand All @@ -358,14 +361,18 @@ class test_exception_for_generic_acc {
* @param access_mode_name Current access mode string representation
* @param target_name Current target string representation
*/
template <typename T, typename AccT>
template <typename T, typename AccT, typename ArgCombination>
class run_tests_with_types {
public:
void operator()(const std::string& type_name) {
// Get the packs from the test combination type.
using AccessModePack = std::tuple_element_t<0, ArgCombination>;
using DimensionsPack = std::tuple_element_t<1, ArgCombination>;

// Type packs instances have to be const, otherwise for_all_combination
// will not compile
const auto access_modes = get_access_modes();
const auto dimensions = get_dimensions();
const auto access_modes = AccessModePack::generate_named();
const auto dimensions = DimensionsPack::generate_unnamed();

// To handle cases when class was called from functions
// like for_all_types_vectors_marray or for_all_device_copyable_std_containers.
Expand All @@ -376,7 +383,7 @@ class run_tests_with_types {
constexpr accessor_tests_common::accessor_type acc_type = AccT::value;
if constexpr (acc_type ==
accessor_tests_common::accessor_type::generic_accessor) {
const auto targets = get_targets();
const auto targets = targets_pack::generate_named();
for_all_combinations<test_exception_for_generic_acc, AccT, T>(
access_modes, dimensions, targets, actual_type_name);
} else if constexpr (acc_type ==
Expand Down
26 changes: 16 additions & 10 deletions tests/accessor/accessor_exceptions_core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,22 @@ using namespace accessor_tests_common;
namespace accessor_exceptions_test_core {
using namespace sycl_cts;

DISABLED_FOR_TEST_CASE(hipSYCL, ComputeCpp)
DISABLED_FOR_TEMPLATE_LIST_TEST_CASE(hipSYCL, ComputeCpp)
("Generic sycl::accessor constructor exceptions test. Core types.",
"[accessor]")({ common_run_tests<run_tests_with_types, generic_accessor>(); });

DISABLED_FOR_TEST_CASE(hipSYCL, ComputeCpp)
("sycl::local_accessor constructor exceptions test. Core types.",
"[accessor]")({ common_run_tests<run_tests_with_types, local_accessor>(); });

DISABLED_FOR_TEST_CASE(hipSYCL, ComputeCpp)
("sycl::host_accessor constructor exceptions test. Core types.",
"[accessor]")({ common_run_tests<run_tests_with_types, host_accessor>(); });
"[accessor]", test_combinations)({
common_run_tests<run_tests_with_types, generic_accessor, TestType>();
});

DISABLED_FOR_TEMPLATE_LIST_TEST_CASE(hipSYCL, ComputeCpp)
("sycl::local_accessor constructor exceptions test. Core types.", "[accessor]",
test_combinations)({
common_run_tests<run_tests_with_types, local_accessor, TestType>();
});

DISABLED_FOR_TEMPLATE_LIST_TEST_CASE(hipSYCL, ComputeCpp)
("sycl::host_accessor constructor exceptions test. Core types.", "[accessor]",
test_combinations)({
common_run_tests<run_tests_with_types, host_accessor, TestType>();
});

} // namespace accessor_exceptions_test_core
Loading

0 comments on commit d6c817c

Please sign in to comment.