forked from KhronosGroup/SYCL-CTS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathextensions.h
119 lines (108 loc) · 2.83 KB
/
extensions.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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
/*******************************************************************************
//
// SYCL 2020 Conformance Test Suite
//
// Provide common extension verification logic
//
*******************************************************************************/
#ifndef __SYCLCTS_UTIL_EXTENSIONS_H
#define __SYCLCTS_UTIL_EXTENSIONS_H
#include <sycl/sycl.hpp>
#include "logger.h"
#include <string>
namespace sycl_cts {
namespace util {
/**
* @brief Namespace that defines extension support
* Tag members provide common extension runtime verification support
*/
namespace extensions {
/**
* @brief Tags can be used as a compile-time guards for different code paths
*/
namespace tag {
// Tag for default path
struct generic {};
// Tag for no extensions
struct core : generic {};
// Tags for extensions
struct atomic64 : generic {};
struct fp16 : generic {};
struct fp64 : generic {};
} // namespace tag
/**
* @brief Retrieve extension name by tag
*/
template <typename tagT>
inline const sycl::aspect aspect();
template <>
inline const sycl::aspect aspect<tag::atomic64>() {
return sycl::aspect::atomic64;
}
template <>
inline const sycl::aspect aspect<tag::fp16>() {
return sycl::aspect::fp16;
}
template <>
inline const sycl::aspect aspect<tag::fp64>() {
return sycl::aspect::fp64;
}
/**
* @brief Retrieve description for logs by tag
*/
template <typename tagT>
inline std::string description();
template <>
inline std::string description<tag::atomic64>() {
return "64-bit atomic operations";
}
template <>
inline std::string description<tag::fp16>() {
return "half precision floating point operations";
}
template <>
inline std::string description<tag::fp64>() {
return "double precision floating point operations";
}
/**
* @brief Provide runtime extension availability check by tag
*/
template <typename tagT>
struct availability {
/**
* @brief Verify extension availability without log messages
*/
static inline bool check(const sycl::queue& queue) {
return queue.get_device().has(aspect<tagT>());
}
/**
* @brief Verify extension availability with default log messages
*/
static inline bool check(const sycl::queue& queue,
sycl_cts::util::logger& log) {
const bool result = check(queue);
if (!result)
log.note("Device does not support " + description<tagT>());
return result;
}
};
/**
* @brief Specialization for common code support
*/
template <>
struct availability <tag::core> {
template <typename ... argsT>
static inline bool check(argsT&&...) {
return true;
}
};
/**
* @brief Explicitly cancel extension availability verification for generic
* tag to avoid possible issues with object slicing
*/
template <>
struct availability<tag::generic> {};
} //namespace extensions
} // namespace util
} // namespace sycl_cts
#endif // __SYCLCTS_UTIL_EXTENSIONS_H