-
Notifications
You must be signed in to change notification settings - Fork 87
/
Copy pathrange_index_space_id.h
97 lines (86 loc) · 3.18 KB
/
range_index_space_id.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
/*******************************************************************************
//
// SYCL 2020 Conformance Test Suite
//
// Copyright (c) 2017-2022 Codeplay Software LTD. All Rights Reserved.
// Copyright (c) 2022-2023 The Khronos Group Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
*******************************************************************************/
#ifndef SYCL_CTS_COMPILING_WITH_ADAPTIVECPP
#include "../common/type_coverage.h"
#endif
namespace range_index_space_id {
enum class check_codes : size_t {
dimensions_type = 0,
dimensions_value = 1,
code_count = 2,
};
constexpr size_t check_count = to_integral(check_codes::code_count);
static const std::array<std::string, check_count> error_strings{
"Wrong type of member T<Dim>::dimensions",
"Wrong value of member T<Dim>::dimensions",
};
template <check_codes Code, typename ResultArray>
void set_success_operation(ResultArray& result) {
int index = to_integral(Code);
result[index] = true;
}
inline std::string get_error_string(int code, const std::string& type_name) {
return error_strings[code] + " for type T '" + type_name + "'";
}
template <typename T, int Dim, typename ResultArray>
void check_members(ResultArray& result) {
if (std::is_same_v<const int, decltype(T::dimensions)>) {
set_success_operation<check_codes::dimensions_type>(result);
}
if (Dim == T::dimensions) {
set_success_operation<check_codes::dimensions_value>(result);
}
}
template <typename T, int Dim>
class kernel_range_id;
template <typename T, int Dim>
void check_members_test(const std::string& type_name) {
auto queue = once_per_unit::get_queue();
std::string section_name = std::string("Checking for type '") + type_name +
"' and dim = " + std::to_string(Dim) +
" in kernel function";
bool result[check_count];
std::fill(result, result + check_count, false);
SECTION(section_name) {
{
sycl::buffer<bool, 1> res_buf(result, sycl::range(check_count));
queue.submit([&](sycl::handler& cgh) {
sycl::accessor res_acc(res_buf, cgh);
cgh.single_task<kernel_range_id<T, Dim>>(
[=] { check_members<T, Dim>(res_acc); });
});
}
for (size_t i = 0; i < check_count; ++i) {
INFO(get_error_string(i, type_name));
CHECK(result[i]);
}
}
section_name = std::string("Checking for type '") + type_name +
"' and dim = " + std::to_string(Dim) + " on host";
SECTION(section_name) {
check_members<T, Dim>(result);
for (size_t i = 0; i < check_count; ++i) {
INFO(get_error_string(i, type_name));
CHECK(result[i]);
}
}
}
} // namespace range_index_space_id