Skip to content

Commit 823c765

Browse files
Remove platform.def
1 parent f081eea commit 823c765

File tree

7 files changed

+68
-73
lines changed

7 files changed

+68
-73
lines changed

libsycl/include/sycl/__impl/info/platform.def

Lines changed: 0 additions & 8 deletions
This file was deleted.

libsycl/include/sycl/__impl/info/platform.hpp

Lines changed: 26 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -19,36 +19,40 @@
1919
#include <string>
2020

2121
_LIBSYCL_BEGIN_NAMESPACE_SYCL
22+
class platform;
23+
24+
namespace detail {
25+
template <typename Desc, typename DescOf> struct info_desc_tag {};
26+
template <typename Desc, typename DescOf, typename = void>
27+
struct is_info_desc : std::false_type {};
28+
template <typename Desc, typename DescOf>
29+
struct is_info_desc<
30+
Desc, DescOf,
31+
std::enable_if_t<std::is_base_of_v<info_desc_tag<Desc, DescOf>, Desc>>>
32+
: std::true_type {
33+
using return_type = typename Desc::return_type;
34+
};
35+
36+
template <typename T>
37+
using is_platform_info_desc_t = typename is_info_desc<T, platform>::return_type;
38+
} // namespace detail
2239

2340
// A.1. Platform information descriptors
2441
namespace info {
2542
namespace platform {
26-
#define __SYCL_PARAM_TRAITS_SPEC(DescType, Desc, ReturnT, OffloadCode) \
27-
struct Desc { \
28-
using return_type = ReturnT; \
29-
};
30-
3143
// 4.6.2.4. Information descriptors
32-
#include <sycl/__impl/info/platform.def>
33-
34-
#undef __SYCL_PARAM_TRAITS_SPEC
44+
struct version : detail::info_desc_tag<version, sycl::platform> {
45+
using return_type = std::string;
46+
};
47+
struct name : detail::info_desc_tag<name, sycl::platform> {
48+
using return_type = std::string;
49+
};
50+
struct vendor : detail::info_desc_tag<vendor, sycl::platform> {
51+
using return_type = std::string;
52+
};
3553
} // namespace platform
3654
} // namespace info
3755

38-
namespace detail {
39-
template <typename T> struct is_platform_info_desc : std::false_type {};
40-
41-
#define __SYCL_PARAM_TRAITS_SPEC(DescType, Desc, ReturnT, OffloadCode) \
42-
template <> \
43-
struct is_##DescType##_info_desc<info::DescType::Desc> : std::true_type { \
44-
using return_type = info::DescType::Desc::return_type; \
45-
};
46-
47-
#include <sycl/__impl/info/platform.def>
48-
49-
#undef __SYCL_PARAM_TRAITS_SPEC
50-
} // namespace detail
51-
5256
_LIBSYCL_END_NAMESPACE_SYCL
5357

5458
#endif // _LIBSYCL___IMPL_INFO_PLATFORM_HPP

libsycl/include/sycl/__impl/platform.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ class _LIBSYCL_EXPORT platform
7676
///
7777
/// The return type depends on information being queried.
7878
template <typename Param>
79-
typename detail::is_platform_info_desc<Param>::return_type get_info() const;
79+
detail::is_platform_info_desc_t<Param> get_info() const;
8080

8181
// template <typename Param>
8282
// typename detail::is_backend_info_desc<Param>::return_type

libsycl/src/detail/offload/info_code.hpp

Lines changed: 0 additions & 30 deletions
This file was deleted.

libsycl/src/detail/offload/offload_utils.hpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,27 @@ void call_and_throw(FunctionType &Function, ArgsT &&...Args) {
5252

5353
backend convertBackend(ol_platform_backend_t Backend);
5454

55+
/// Helper to map SYCL information descriptors to OL_<HANDLE>_INFO_<SMTH>. To be
56+
/// used like this:
57+
///
58+
/// using Map = info_ol_mapping<ol_foo_info_t>;
59+
/// constexpr auto olInfo = map_info_desc<FromDesc, ol_foo_info_t>(
60+
/// Map::M<DescVal0>{OL_FOO_INFO_VAL0},
61+
/// Map::M<DescVal1>{OL_FOO_INFO_VAL1},
62+
/// ...)
63+
template <typename To> struct info_ol_mapping {
64+
template <typename From> struct M {
65+
To value;
66+
constexpr M(To value) : value(value) {}
67+
};
68+
};
69+
template <typename From, typename To, typename... Ts>
70+
constexpr To map_info_desc(typename info_ol_mapping<To>::template M<Ts>... ms) {
71+
return std::get<typename info_ol_mapping<To>::template M<From>>(
72+
std::tuple{ms...})
73+
.value;
74+
}
75+
5576
} // namespace detail
5677

5778
_LIBSYCL_END_NAMESPACE_SYCL

libsycl/src/detail/platform_impl.hpp

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
#include <sycl/__impl/platform.hpp>
1515

1616
#include <detail/common.hpp>
17-
#include <detail/offload/info_code.hpp>
1817
#include <detail/offload/offload_utils.hpp>
1918

2019
#include <OffloadAPI.h>
@@ -76,15 +75,22 @@ class platform_impl {
7675
///
7776
/// The return type depends on information being queried.
7877
template <typename Param> typename Param::return_type get_info() const {
78+
using namespace info::platform;
79+
using Map = info_ol_mapping<ol_platform_info_t>;
80+
81+
constexpr ol_platform_info_t olInfo =
82+
map_info_desc<Param, ol_platform_info_t>(
83+
Map::M<version>{OL_PLATFORM_INFO_VERSION},
84+
Map::M<name>{OL_PLATFORM_INFO_NAME},
85+
Map::M<vendor>{OL_PLATFORM_INFO_VENDOR_NAME});
7986
// for now we have only std::string properties
8087
static_assert(std::is_same_v<typename Param::return_type, std::string>);
8188
size_t ExpectedSize = 0;
82-
call_and_throw(olGetPlatformInfoSize, MOffloadPlatform,
83-
detail::OffloadInfoCode<Param>::value, &ExpectedSize);
89+
call_and_throw(olGetPlatformInfoSize, MOffloadPlatform, olInfo,
90+
&ExpectedSize);
8491
std::string Result;
8592
Result.resize(ExpectedSize - 1);
86-
call_and_throw(olGetPlatformInfo, MOffloadPlatform,
87-
detail::OffloadInfoCode<Param>::value, ExpectedSize,
93+
call_and_throw(olGetPlatformInfo, MOffloadPlatform, olInfo, ExpectedSize,
8894
Result.data());
8995
return Result;
9096
}

libsycl/src/platform.cpp

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,17 @@ std::vector<platform> platform::get_platforms() {
2929
}
3030

3131
template <typename Param>
32-
typename detail::is_platform_info_desc<Param>::return_type
33-
platform::get_info() const {
32+
detail::is_platform_info_desc_t<Param> platform::get_info() const {
3433
return impl.get_info<Param>();
3534
}
3635

37-
#define __SYCL_PARAM_TRAITS_SPEC(DescType, Desc, ReturnT, PiCode) \
38-
template _LIBSYCL_EXPORT ReturnT platform::get_info<info::platform::Desc>() \
39-
const;
40-
#include <sycl/__impl/info/platform.def>
41-
#undef __SYCL_PARAM_TRAITS_SPEC
36+
#define __SYCL_EXPORT_GET_INFO(Desc) \
37+
template _LIBSYCL_EXPORT \
38+
detail::is_platform_info_desc_t<info::platform::Desc> \
39+
platform::get_info<info::platform::Desc>() const;
40+
__SYCL_EXPORT_GET_INFO(version)
41+
__SYCL_EXPORT_GET_INFO(name)
42+
__SYCL_EXPORT_GET_INFO(vendor)
43+
#undef __SYCL_EXPORT_GET_INFO
4244

4345
_LIBSYCL_END_NAMESPACE_SYCL

0 commit comments

Comments
 (0)