Skip to content

Commit ba9ecbc

Browse files
committed
[NFC] Use built-in Catch2 functionality for enums printing
Documentation: [link](https://github.com/catchorg/Catch2/blob/5b3b22860344193bfd51e4c3c7429e94d8a5996f/docs/tostring.md#enums)
1 parent 60c299e commit ba9ecbc

File tree

2 files changed

+43
-189
lines changed

2 files changed

+43
-189
lines changed

tests/common/string_makers.h

Lines changed: 0 additions & 180 deletions
Original file line numberDiff line numberDiff line change
@@ -15,29 +15,6 @@
1515
#include <sycl/sycl.hpp>
1616

1717
namespace Catch {
18-
template <>
19-
struct StringMaker<sycl::access_mode> {
20-
using type = sycl::access_mode;
21-
static std::string convert(type value) {
22-
switch (value) {
23-
case type::read:
24-
return "access_mode::read";
25-
case type::write:
26-
return "access_mode::write";
27-
case type::read_write:
28-
return "access_mode::read_write";
29-
case type::discard_write:
30-
return "access_mode::discard_write (deprecated)";
31-
case type::discard_read_write:
32-
return "access_mode::discard_read_write (deprecated)";
33-
case type::atomic:
34-
return "access_mode::atomic (deprecated)";
35-
default:
36-
return "unknown access mode";
37-
}
38-
}
39-
};
40-
4118
template <int Dimensions>
4219
struct StringMaker<sycl::id<Dimensions>> {
4320
static std::string convert(const sycl::id<Dimensions>& id) {
@@ -53,163 +30,6 @@ struct StringMaker<sycl::id<Dimensions>> {
5330
return ss.str();
5431
}
5532
};
56-
57-
template <>
58-
struct StringMaker<sycl::target> {
59-
using type = sycl::target;
60-
static std::string convert(type value) {
61-
switch (value) {
62-
case type::device:
63-
return "target::device";
64-
// FIXME: re-enable when target::host_task is implemented
65-
#if !SYCL_CTS_COMPILING_WITH_ADAPTIVECPP
66-
case type::host_task:
67-
return "target::host_task";
68-
#endif
69-
70-
case type::constant_buffer:
71-
return "target::constant_buffer (deprecated)";
72-
case type::local:
73-
return "target::local (deprecated)";
74-
case type::host_buffer:
75-
return "target::host_buffer (deprecated)";
76-
default:
77-
return "unknown target";
78-
}
79-
}
80-
};
81-
82-
template <>
83-
struct StringMaker<sycl::aspect> {
84-
using type = sycl::aspect;
85-
static std::string convert(type value) {
86-
switch (value) {
87-
case type::cpu:
88-
return "aspect::cpu";
89-
case type::gpu:
90-
return "aspect::gpu";
91-
case type::accelerator:
92-
return "aspect::accelerator";
93-
case type::custom:
94-
return "aspect::custom";
95-
case type::emulated:
96-
return "aspect::emulated";
97-
case type::host_debuggable:
98-
return "aspect::host_debuggable";
99-
case type::fp16:
100-
return "aspect::fp16";
101-
case type::fp64:
102-
return "aspect::fp64";
103-
case type::atomic64:
104-
return "aspect::atomic64";
105-
case type::image:
106-
return "aspect::image";
107-
case type::online_compiler:
108-
return "aspect::online_compiler";
109-
case type::online_linker:
110-
return "aspect::online_linker";
111-
case type::queue_profiling:
112-
return "aspect::queue_profiling";
113-
case type::usm_device_allocations:
114-
return "aspect::usm_device_allocations";
115-
case type::usm_host_allocations:
116-
return "aspect::usm_host_allocations";
117-
case type::usm_atomic_host_allocations:
118-
return "aspect::usm_atomic_host_allocations";
119-
case type::usm_shared_allocations:
120-
return "aspect::usm_shared_allocations";
121-
case type::usm_atomic_shared_allocations:
122-
return "aspect::usm_atomic_shared_allocations";
123-
case type::usm_system_allocations:
124-
return "aspect::usm_system_allocations";
125-
default:
126-
return "unknown aspect";
127-
}
128-
}
129-
};
130-
131-
template <>
132-
struct StringMaker<sycl::memory_order> {
133-
using type = sycl::memory_order;
134-
static std::string convert(const type& order) {
135-
switch (order) {
136-
case type::relaxed:
137-
return "memory_order::relaxed";
138-
case type::acq_rel:
139-
return "memory_order::acq_rel";
140-
case type::seq_cst:
141-
return "memory_order::seq_cst";
142-
case type::acquire:
143-
return "memory_order::acquire";
144-
case type::release:
145-
return "memory_order::release";
146-
default:
147-
return "unknown memory_order";
148-
}
149-
}
150-
};
151-
152-
template <>
153-
struct StringMaker<sycl::memory_scope> {
154-
using type = sycl::memory_scope;
155-
static std::string convert(const type& scope) {
156-
switch (scope) {
157-
case type::work_item:
158-
return "memory_scope::work_item";
159-
case type::sub_group:
160-
return "memory_scope::sub_group";
161-
case type::work_group:
162-
return "memory_scope::work_group";
163-
case type::device:
164-
return "memory_scope::device";
165-
case type::system:
166-
return "memory_scope::system";
167-
default:
168-
return "unknown memory_scope";
169-
}
170-
}
171-
};
172-
173-
template <>
174-
struct StringMaker<sycl::access::address_space> {
175-
using type = sycl::access::address_space;
176-
static std::string convert(const type& addr_space) {
177-
switch (addr_space) {
178-
case type::global_space:
179-
return "address_space::global_space";
180-
case type::local_space:
181-
return "address_space::local_space";
182-
case type::generic_space:
183-
return "address_space::generic_space";
184-
case type::private_space:
185-
return "address_space::private_space";
186-
default:
187-
// no stringification for deprecated ones
188-
return "unknown or deprecated address_space";
189-
}
190-
}
191-
};
192-
193-
// FIXME: re-enable when sycl::access::decorated is implemented in adaptivecpp
194-
#if !SYCL_CTS_COMPILING_WITH_ADAPTIVECPP
195-
template <>
196-
struct StringMaker<sycl::access::decorated> {
197-
using type = sycl::access::decorated;
198-
static std::string convert(type value) {
199-
switch (value) {
200-
case type::yes:
201-
return "access::decorated::yes";
202-
case type::no:
203-
return "access::decorated::no";
204-
case type::legacy:
205-
return "access::decorated::legacy";
206-
default:
207-
return "unknown";
208-
}
209-
}
210-
};
211-
#endif
212-
21333
} // namespace Catch
21434

21535
#endif // __SYCLCTS_TESTS_COMMON_STRING_MAKERS_H

util/sycl_enums.h

Lines changed: 43 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,6 @@
1212
#include <catch2/catch_tostring.hpp>
1313
#include <sycl/sycl.hpp>
1414

15-
// TODO: Remove when all implementations support the sycl::errc enum
16-
#if SYCL_CTS_COMPILING_WITH_ADAPTIVECPP
17-
#define SYCL_CTS_SUPPORT_HAS_ERRC_ENUM 0
18-
#else
19-
#define SYCL_CTS_SUPPORT_HAS_ERRC_ENUM 1
20-
#endif
21-
22-
#if SYCL_CTS_SUPPORT_HAS_ERRC_ENUM == 1
2315
CATCH_REGISTER_ENUM(sycl::errc, sycl::errc::success, sycl::errc::runtime,
2416
sycl::errc::kernel, sycl::errc::accessor,
2517
sycl::errc::nd_range, sycl::errc::event,
@@ -29,6 +21,48 @@ CATCH_REGISTER_ENUM(sycl::errc, sycl::errc::success, sycl::errc::runtime,
2921
sycl::errc::feature_not_supported,
3022
sycl::errc::kernel_not_supported,
3123
sycl::errc::backend_mismatch);
32-
#endif
24+
25+
CATCH_REGISTER_ENUM(sycl::access::decorated, sycl::access::decorated::yes,
26+
sycl::access::decorated::no,
27+
sycl::access::decorated::legacy)
28+
29+
CATCH_REGISTER_ENUM(sycl::access::address_space,
30+
sycl::access::address_space::global_space,
31+
sycl::access::address_space::local_space,
32+
sycl::access::address_space::generic_space,
33+
sycl::access::address_space::private_space)
34+
35+
CATCH_REGISTER_ENUM(sycl::memory_scope, sycl::memory_scope::work_item,
36+
sycl::memory_scope::sub_group,
37+
sycl::memory_scope::work_group, sycl::memory_scope::device,
38+
sycl::memory_scope::system)
39+
40+
CATCH_REGISTER_ENUM(sycl::memory_order, sycl::memory_order::relaxed,
41+
sycl::memory_order::acq_rel, sycl::memory_order::seq_cst,
42+
sycl::memory_order::acquire, sycl::memory_order::release)
43+
44+
CATCH_REGISTER_ENUM(sycl::target, sycl::target::device,
45+
sycl::target::constant_buffer, sycl::target::local,
46+
sycl::target::host_buffer, sycl::target::host_task)
47+
48+
CATCH_REGISTER_ENUM(sycl::access_mode, sycl::access_mode::read,
49+
sycl::access_mode::write, sycl::access_mode::read_write,
50+
sycl::access_mode::discard_write,
51+
sycl::access_mode::discard_read_write,
52+
sycl::access_mode::atomic)
53+
54+
CATCH_REGISTER_ENUM(sycl::aspect, sycl::aspect::cpu, sycl::aspect::gpu,
55+
sycl::aspect::accelerator, sycl::aspect::custom,
56+
sycl::aspect::emulated, sycl::aspect::host_debuggable,
57+
sycl::aspect::fp16, sycl::aspect::fp64,
58+
sycl::aspect::atomic64, sycl::aspect::image,
59+
sycl::aspect::online_compiler, sycl::aspect::online_linker,
60+
sycl::aspect::queue_profiling,
61+
sycl::aspect::usm_device_allocations,
62+
sycl::aspect::usm_host_allocations,
63+
sycl::aspect::usm_atomic_host_allocations,
64+
sycl::aspect::usm_shared_allocations,
65+
sycl::aspect::usm_atomic_shared_allocations,
66+
sycl::aspect::usm_system_allocations)
3367

3468
#endif // __SYCLCTS_UTIL_SYCL_ENUMS_H

0 commit comments

Comments
 (0)