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

Compatibility: Only use sycl::half if SYCL_CTS_ENABLE_HALF_TESTS is set #872

Open
wants to merge 1 commit into
base: SYCL-2020
Choose a base branch
from
Open
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
3 changes: 3 additions & 0 deletions tests/accessor/accessor_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -143,13 +143,16 @@ inline std::string get_section_name(const std::string& type_name,
// FIXME: re-enable when marrray is implemented in hipsycl and type_coverage is
// enabled
#ifndef SYCL_CTS_COMPILING_WITH_HIPSYCL

#if SYCL_CTS_ENABLE_HALF_TESTS
/**
* @brief Factory function for getting type_pack with fp16 type
*/
inline auto get_fp16_type() {
static const auto types = named_type_pack<sycl::half>::generate("sycl::half");
return types;
}
#endif

/**
* @brief Factory function for getting type_pack with fp64 type
Expand Down
2 changes: 2 additions & 0 deletions tests/common/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,7 @@ bool check_type_sign(bool expected_sign) {
return (std::is_signed<T>::value == expected_sign);
}

#if SYCL_CTS_ENABLE_HALF_TESTS
/**
* @brief Helper function to see if sycl::half is of the wrong sign
*/
Expand All @@ -244,6 +245,7 @@ inline bool check_type_sign<sycl::half>(bool expected_sign) {
bool is_signed = sycl::half(1) > sycl::half(-1);
return is_signed == expected_sign;
}
#endif

/**
* @brief Helper function to log a failure if a type is of the wrong size or
Expand Down
6 changes: 4 additions & 2 deletions tests/group_functions/group_functions_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include "../common/common.h"
#include "../common/get_group_range.h"
#include "../common/once_per_unit.h"
#include "../../util/type_traits.h"
#include "type_coverage.h"

#include <catch2/catch_template_test_macros.hpp>
Expand Down Expand Up @@ -133,8 +134,10 @@ struct custom_type {
template <typename T>
inline constexpr uint64_t exact_max = std::numeric_limits<T>::max();

#if SYCL_CTS_ENABLE_HALF_TESTS
template <>
inline constexpr uint64_t exact_max<sycl::half> = 1ull << 11;
#endif
template <>
inline constexpr uint64_t exact_max<float> = 1ull << 24;
template <>
Expand Down Expand Up @@ -247,8 +250,7 @@ template <typename T>
inline auto get_op_types() {
#if SYCL_CTS_ENABLE_FULL_CONFORMANCE
static const auto types = []() {
if constexpr (std::is_floating_point_v<T> ||
std::is_same_v<std::remove_cv_t<T>, sycl::half>) {
if constexpr (is_sycl_floating_point_v<T>) {
// Bitwise operations are not defined for floating point types.
return named_type_pack<sycl::plus<T>, sycl::multiplies<T>,
sycl::logical_and<T>, sycl::logical_or<T>,
Expand Down
10 changes: 8 additions & 2 deletions tests/group_functions/group_joint_reduce.cpp.in
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,15 @@ TEST_CASE(CTS_TYPE_NAME + " group and sub-group joint reduce functions",
const auto Operators = get_op_types<CTS_TYPE>();
const auto RetType = unnamed_type_pack<CTS_TYPE>();

#if SYCL_CTS_ENABLE_HALF_TESTS
if constexpr (std::is_same_v<std::remove_cv_t<CTS_TYPE>, sycl::half>) {
if (!queue.get_device().has(sycl::aspect::fp16))
SKIP(
"Device does not support half precision floating point "
"operations.");
} else if (std::is_same_v<std::remove_cv_t<CTS_TYPE>, double>) {
}
#endif
if (std::is_same_v<std::remove_cv_t<CTS_TYPE>, double>) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (std::is_same_v<std::remove_cv_t<CTS_TYPE>, double>) {
if constexpr (std::is_same_v<std::remove_cv_t<CTS_TYPE>, double>) {

if (!queue.get_device().has(sycl::aspect::fp64))
SKIP(
"Device does not support double precision floating point "
Expand All @@ -57,12 +60,15 @@ TEMPLATE_LIST_TEST_CASE(
const auto RetType = unnamed_type_pack<CTS_TYPE>();
const auto ReducedType = unnamed_type_pack<TestType>();

#if SYCL_CTS_ENABLE_HALF_TESTS
if constexpr (std::is_same_v<std::remove_cv_t<CTS_TYPE>, sycl::half>) {
if (!queue.get_device().has(sycl::aspect::fp16))
SKIP(
"Device does not support half precision floating point "
"operations.");
} else if (std::is_same_v<std::remove_cv_t<CTS_TYPE>, double>) {
}
#endif
if constexpr (std::is_same_v<std::remove_cv_t<CTS_TYPE>, double>) {
if (!queue.get_device().has(sycl::aspect::fp64))
SKIP(
"Device does not support double precision floating point "
Expand Down
10 changes: 8 additions & 2 deletions tests/group_functions/group_joint_scan.cpp.in
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,15 @@ DISABLED_FOR_TEST_CASE(hipSYCL)
#endif

auto queue = once_per_unit::get_queue();
#if SYCL_CTS_ENABLE_HALF_TESTS
if constexpr (std::is_same_v<std::remove_cv_t<CTS_TYPE>, sycl::half>) {
if (!queue.get_device().has(sycl::aspect::fp16))
SKIP(
"Device does not support half precision floating point "
"operations.");
} else if (std::is_same_v<std::remove_cv_t<CTS_TYPE>, double>) {
}
#endif
if constexpr (std::is_same_v<std::remove_cv_t<CTS_TYPE>, double>) {
if (!queue.get_device().has(sycl::aspect::fp64))
SKIP(
"Device does not support double precision floating point "
Expand Down Expand Up @@ -86,12 +89,15 @@ DISABLED_FOR_TEST_CASE(hipSYCL)
#endif

auto queue = once_per_unit::get_queue();
#if SYCL_CTS_ENABLE_HALF_TESTS
if constexpr (std::is_same_v<std::remove_cv_t<CTS_TYPE>, sycl::half>) {
if (!queue.get_device().has(sycl::aspect::fp16))
SKIP(
"Device does not support half precision floating point "
"operations.");
} else if (std::is_same_v<std::remove_cv_t<CTS_TYPE>, double>) {
}
#endif
if constexpr (std::is_same_v<std::remove_cv_t<CTS_TYPE>, double>) {
if (!queue.get_device().has(sycl::aspect::fp64))
SKIP(
"Device does not support double precision floating point "
Expand Down
10 changes: 8 additions & 2 deletions tests/group_functions/group_reduce_over_group.cpp.in
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,15 @@ TEST_CASE(CTS_TYPE_NAME + " group and sub-group reduce functions",
const auto Operators = get_op_types<CTS_TYPE>();
const auto RetType = unnamed_type_pack<CTS_TYPE>();

#if SYCL_CTS_ENABLE_HALF_TESTS
if constexpr (std::is_same_v<std::remove_cv_t<CTS_TYPE>, sycl::half>) {
if (!queue.get_device().has(sycl::aspect::fp16))
SKIP(
"Device does not support half precision floating point "
"operations.");
} else if (std::is_same_v<std::remove_cv_t<CTS_TYPE>, double>) {
}
#endif
if constexpr (std::is_same_v<std::remove_cv_t<CTS_TYPE>, double>) {
if (!queue.get_device().has(sycl::aspect::fp64))
SKIP(
"Device does not support double precision floating point "
Expand All @@ -59,12 +62,15 @@ TEMPLATE_LIST_TEST_CASE(CTS_TYPE_NAME +
const auto RetType = unnamed_type_pack<CTS_TYPE>();
const auto ReducedType = unnamed_type_pack<TestType>();

#if SYCL_CTS_ENABLE_HALF_TESTS
if constexpr (std::is_same_v<std::remove_cv_t<CTS_TYPE>, sycl::half>) {
if (!queue.get_device().has(sycl::aspect::fp16))
SKIP(
"Device does not support half precision floating point "
"operations.");
} else if (std::is_same_v<std::remove_cv_t<CTS_TYPE>, double>) {
}
#endif
if constexpr (std::is_same_v<std::remove_cv_t<CTS_TYPE>, double>) {
if (!queue.get_device().has(sycl::aspect::fp64))
SKIP(
"Device does not support double precision floating point "
Expand Down
10 changes: 8 additions & 2 deletions tests/group_functions/group_scan_over_group.cpp.in
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,15 @@ DISABLED_FOR_TEST_CASE(hipSYCL)
(CTS_TYPE_NAME + " group and sub-group scan functions",
"[group_func][type_list][dim]")({
auto queue = once_per_unit::get_queue();
#if SYCL_CTS_ENABLE_HALF_TESTS
if constexpr (std::is_same_v<std::remove_cv_t<CTS_TYPE>, sycl::half>) {
if (!queue.get_device().has(sycl::aspect::fp16))
SKIP(
"Device does not support half precision floating point "
"operations.");
} else if (std::is_same_v<std::remove_cv_t<CTS_TYPE>, double>) {
}
#endif
if constexpr (std::is_same_v<std::remove_cv_t<CTS_TYPE>, double>) {
if (!queue.get_device().has(sycl::aspect::fp64))
SKIP(
"Device does not support double precision floating point "
Expand All @@ -59,12 +62,15 @@ DISABLED_FOR_TEST_CASE(hipSYCL)
(CTS_TYPE_NAME + " group and sub-group scan functions with init",
"[group_func][type_list][dim]")({
auto queue = once_per_unit::get_queue();
#if SYCL_CTS_ENABLE_HALF_TESTS
if constexpr (std::is_same_v<std::remove_cv_t<CTS_TYPE>, sycl::half>) {
if (!queue.get_device().has(sycl::aspect::fp16))
SKIP(
"Device does not support half precision floating point "
"operations.");
} else if (std::is_same_v<std::remove_cv_t<CTS_TYPE>, double>) {
}
#endif
if constexpr (std::is_same_v<std::remove_cv_t<CTS_TYPE>, double>) {
if (!queue.get_device().has(sycl::aspect::fp64))
SKIP(
"Device does not support double precision floating point "
Expand Down
4 changes: 4 additions & 0 deletions tests/kernel_bundle/kernels.h
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,8 @@ struct kernel_atomic64_descriptor {
// fp16, fp64, atomic64 kernels without sycl::requires attribute but with
// explicit operations

#if SYCL_CTS_ENABLE_HALF_TESTS

struct kernel_fp16_no_attr : kernel_base {
void operator()(sycl::item<1> id) const {
if (id.get_linear_id() == 0) {
Expand All @@ -239,6 +241,8 @@ struct kernel_fp16_no_attr_descriptor {
}
};

#endif // SYCL_CTS_ENABLE_HALF_TESTS

struct kernel_fp64_no_attr : kernel_base {
void operator()(sycl::item<1> id) const {
if (id.get_linear_id() == 0) {
Expand Down
4 changes: 4 additions & 0 deletions tests/kernel_bundle/sycl_is_compatible.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,12 @@ TEST_CASE("Check is_compatible for kernels with no kernel attributes",
CHECK(sycl::is_compatible(builtinKernelIds, device));
}

#if SYCL_CTS_ENABLE_HALF_TESTS
SECTION("for a kernel that uses `sycl::half`") {
check_with_optional_features<kernels::kernel_fp16_no_attr_descriptor>(
device, queue, device.has(sycl::aspect::fp16));
}
#endif

SECTION("for a kernel that uses `double`") {
check_with_optional_features<kernels::kernel_fp64_no_attr_descriptor>(
Expand Down Expand Up @@ -204,10 +206,12 @@ TEST_CASE(
const sycl::device device = sycl_cts::util::get_cts_object::device();
sycl::queue queue = sycl_cts::util::get_cts_object::queue();

#if SYCL_CTS_ENABLE_HALF_TESTS
SECTION("for a kernel that uses `sycl::half`") {
check_with_optional_features<kernels::kernel_fp16_descriptor>(
device, queue, device.has(sycl::aspect::fp16));
}
#endif

SECTION("for a kernel that uses `double`") {
check_with_optional_features<kernels::kernel_fp64_descriptor>(
Expand Down
6 changes: 3 additions & 3 deletions tests/marray/marray_operators.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

#include "../common/common.h"
#include "../common/section_name_builder.h"
#include "../../util/type_traits.h"
#include "marray_common.h"
#include "marray_operator_helper.h"

Expand Down Expand Up @@ -54,9 +55,8 @@ struct operators_helper {
template <typename OpT, typename ElemT>
struct skip_result_check
: std::bool_constant<
(std::is_same_v<OpT, op_div> || std::is_same_v<OpT, op_assign_div>)&&(
std::is_same_v<ElemT, float> || std::is_same_v<ElemT, double> ||
std::is_same_v<ElemT, sycl::half>)> {};
(std::is_same_v<OpT, op_div> || std::is_same_v<OpT, op_assign_div>) &&
is_sycl_floating_point_v<ElemT>> {};

template <typename OpT, typename ElemT>
constexpr bool skip_result_check_v = skip_result_check<OpT, ElemT>::value;
Expand Down
9 changes: 6 additions & 3 deletions tests/math_builtin_api/math_builtin.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include "../../util/accuracy.h"
#include "../../util/math_reference.h"
#include "../../util/sycl_exceptions.h"
#include "../../util/type_traits.h"
#include "../common/once_per_unit.h"
#include <cfloat>
#include <limits>
Expand Down Expand Up @@ -55,10 +56,12 @@ template <>
struct base<double> {
using type = std::uint64_t;
};
#if SYCL_CTS_ENABLE_HALF_TESTS
template <>
struct base<sycl::half> {
using type = std::uint16_t;
};
#endif

template <typename T>
std::string printable(T value) {
Expand All @@ -74,19 +77,19 @@ T min_t() {
return std::numeric_limits<T>::min();
}

#if SYCL_CTS_ENABLE_HALF_TESTS
template <>
inline sycl::half min_t<sycl::half>() {
return static_cast<sycl::half>(powf(2.0f, -14.0f));
}
#endif

template <typename T>
bool verify(sycl_cts::util::logger& log, T a, T b, int accuracy,
const std::string& comment);

template <typename T>
typename std::enable_if<std::is_floating_point<T>::value ||
std::is_same<sycl::half, T>::value,
bool>::type
std::enable_if_t<is_sycl_floating_point_v<T>, bool>
verify(sycl_cts::util::logger& log, T value, sycl_cts::resultRef<T> r,
int accuracy, const std::string& comment) {
const T reference = r.res;
Expand Down
Loading
Loading