Skip to content

Commit 200710c

Browse files
[Tests] Simplify new_kernel_name implementation in tests (#2128)
1 parent 74a536a commit 200710c

File tree

4 files changed

+52
-35
lines changed

4 files changed

+52
-35
lines changed

test/support/test_dynamic_load_utils.h

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,20 +18,13 @@
1818
#include <algorithm>
1919
#include <iostream>
2020

21+
#include "support/utils_sycl_defs.h" // for TestUtils::unique_kernel_name and etc.
22+
2123
#if TEST_DYNAMIC_SELECTION_AVAILABLE
2224

2325
class load1;
2426
class load2;
2527

26-
namespace TestUtils
27-
{
28-
template <typename Op, ::std::size_t CallNumber>
29-
struct unique_kernel_name;
30-
31-
template <typename Policy, int idx>
32-
using new_kernel_name = unique_kernel_name<std::decay_t<Policy>, idx>;
33-
} // namespace TestUtils
34-
3528
int
3629
test_dl_initialization(const std::vector<sycl::queue>& u)
3730
{

test/support/test_dynamic_selection_utils.h

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,9 @@
1515
#include <random>
1616
#include <algorithm>
1717
#include <iostream>
18-
#if TEST_DYNAMIC_SELECTION_AVAILABLE
19-
20-
namespace TestUtils
21-
{
22-
template <typename Op, ::std::size_t CallNumber>
23-
struct unique_kernel_name;
2418

25-
template <typename Policy, int idx>
26-
using new_kernel_name = unique_kernel_name<std::decay_t<Policy>, idx>;
27-
} // namespace TestUtils
19+
#if TEST_DYNAMIC_SELECTION_AVAILABLE
20+
#include "utils_sycl_defs.h"
2821

2922
static inline void
3023
build_universe(std::vector<sycl::queue>& u)

test/support/utils_invoke.h

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424

2525
#include "iterator_utils.h"
2626
#include "compile_only_checks.h"
27+
#include "utils_sycl_defs.h"
2728

2829
#ifdef ONEDPL_USE_PREDEFINED_POLICIES
2930
# define TEST_USE_PREDEFINED_POLICIES ONEDPL_USE_PREDEFINED_POLICIES
@@ -38,19 +39,6 @@ namespace TestUtils
3839
// Implemented in utils_sycl.h, required to include this file.
3940
sycl::queue get_test_queue();
4041

41-
template <sycl::usm::alloc alloc_type>
42-
constexpr ::std::size_t
43-
uniq_kernel_index()
44-
{
45-
return static_cast<::std::underlying_type_t<sycl::usm::alloc>>(alloc_type);
46-
}
47-
48-
template <typename Op, ::std::size_t CallNumber>
49-
struct unique_kernel_name;
50-
51-
template <typename Policy, int idx>
52-
using new_kernel_name = unique_kernel_name<::std::decay_t<Policy>, idx>;
53-
5442
/**
5543
* make_policy functions test wrappers
5644
* The main purpose of this function wrapper in TestUtils namespace - to cut template params from

test/support/utils_sycl_defs.h

Lines changed: 47 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,12 @@
1818
#ifndef _UTILS_SYCL_DEFS_H
1919
#define _UTILS_SYCL_DEFS_H
2020

21-
#if __has_include(<sycl/sycl.hpp>)
22-
# include <sycl/sycl.hpp>
23-
#else
24-
# include <CL/sycl.hpp>
21+
#if _ONEDPL_BACKEND_SYCL
22+
# if __has_include(<sycl/sycl.hpp>)
23+
# include <sycl/sycl.hpp>
24+
# else
25+
# include <CL/sycl.hpp>
26+
# endif
2527
#endif
2628

2729
#if ONEDPL_FPGA_DEVICE
@@ -36,4 +38,45 @@
3638
# define TEST_LIBSYCL_VERSION 0
3739
#endif
3840

41+
namespace TestUtils
42+
{
43+
#if _ONEDPL_BACKEND_SYCL
44+
template <sycl::usm::alloc alloc_type>
45+
inline constexpr std::size_t
46+
uniq_kernel_index()
47+
{
48+
return static_cast<std::underlying_type_t<sycl::usm::alloc>>(alloc_type);
49+
}
50+
#endif
51+
52+
template <typename Op, std::size_t CallNumber>
53+
struct unique_kernel_name;
54+
55+
template <typename T, typename = std::void_t<>>
56+
struct has_kernel_name : std::false_type
57+
{
58+
};
59+
60+
template <typename T>
61+
struct has_kernel_name<T, std::void_t<typename T::kernel_name>> : std::true_type
62+
{
63+
};
64+
65+
template <typename Policy, std::size_t CallNumber, typename = void>
66+
struct new_kernel_name_impl
67+
{
68+
using type = unique_kernel_name<std::decay_t<Policy>, CallNumber>;
69+
};
70+
71+
template <typename Policy, std::size_t CallNumber>
72+
struct new_kernel_name_impl<Policy, CallNumber, std::enable_if_t<has_kernel_name<std::decay_t<Policy>>::value>>
73+
{
74+
using type = unique_kernel_name<typename std::decay_t<Policy>::kernel_name, CallNumber>;
75+
};
76+
77+
template <typename Policy, std::size_t CallNumber>
78+
using new_kernel_name = typename new_kernel_name_impl<Policy, CallNumber>::type;
79+
80+
} /* namespace TestUtils */
81+
3982
#endif // _UTILS_SYCL_DEFS_H

0 commit comments

Comments
 (0)