Skip to content

[SYCL][ABI-break] Switch to struct information descriptors #6467

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Aug 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion sycl/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ include(SYCLUtils)
set(SYCL_MAJOR_VERSION 5)
set(SYCL_MINOR_VERSION 7)
set(SYCL_PATCH_VERSION 0)
set(SYCL_DEV_ABI_VERSION 3)
set(SYCL_DEV_ABI_VERSION 4)
if (SYCL_ADD_DEV_VERSION_POSTFIX)
set(SYCL_VERSION_POSTFIX "-${SYCL_DEV_ABI_VERSION}")
endif()
Expand Down
4 changes: 2 additions & 2 deletions sycl/include/sycl/accessor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -444,9 +444,9 @@ class image_accessor
static_assert(Dimensions > 0 && Dimensions <= 3,
"Dimensions can be 1/2/3 for image accessor.");

template <info::device param>
template <typename Param>
void checkDeviceFeatureSupported(const device &Device) {
if (!Device.get_info<param>())
if (!Device.get_info<Param>())
throw feature_not_supported("Images are not supported by this device.",
PI_ERROR_INVALID_OPERATION);
}
Expand Down
6 changes: 3 additions & 3 deletions sycl/include/sycl/context.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include <sycl/detail/cl.h>
#include <sycl/detail/common.hpp>
#include <sycl/detail/export.hpp>
#include <sycl/detail/info_desc_helpers.hpp>
#include <sycl/detail/stl_type_traits.hpp>
#include <sycl/exception_list.hpp>
#include <sycl/info/info_desc.hpp>
Expand Down Expand Up @@ -159,9 +160,8 @@ class __SYCL_EXPORT context {
/// Queries this SYCL context for information.
///
/// The return type depends on information being queried.
template <info::context param>
typename info::param_traits<info::context, param>::return_type
get_info() const;
template <typename Param>
typename detail::is_context_info_desc<Param>::return_type get_info() const;

context(const context &rhs) = default;

Expand Down
114 changes: 114 additions & 0 deletions sycl/include/sycl/detail/info_desc_helpers.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
//==---- info_desc_helpers.hpp - SYCL information descriptor helpers -------==//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

#pragma once

#include <sycl/detail/pi.hpp>
#include <sycl/info/info_desc.hpp>

__SYCL_INLINE_NAMESPACE(cl) {
namespace sycl {
namespace detail {
template <typename T> struct PiInfoCode;
template <typename T> struct is_platform_info_desc : std::false_type {};
template <typename T> struct is_context_info_desc : std::false_type {};
template <typename T> struct is_device_info_desc : std::false_type {};
template <typename T> struct is_queue_info_desc : std::false_type {};
template <typename T> struct is_kernel_info_desc : std::false_type {};
template <typename T>
struct is_kernel_device_specific_info_desc : std::false_type {};
template <typename T> struct is_event_info_desc : std::false_type {};
template <typename T> struct is_event_profiling_info_desc : std::false_type {};
// Normally we would just use std::enable_if to limit valid get_info template
// arguments. However, there is a mangling mismatch of
// "std::enable_if<is*_desc::value>::type" between gcc clang (it appears that
// gcc lacks a E terminator for unresolved-qualifier-level sequence). As a
// workaround, we use return_type alias from is_*info_desc that doesn't run into
// the same problem.
// TODO remove once this gcc/clang discrepancy is resolved
#define __SYCL_PARAM_TRAITS_SPEC(DescType, Desc, ReturnT, PiCode) \
template <> struct PiInfoCode<info::DescType::Desc> { \
static constexpr pi_##DescType##_info value = PiCode; \
}; \
template <> \
struct is_##DescType##_info_desc<info::DescType::Desc> : std::true_type { \
using return_type = info::DescType::Desc::return_type; \
};
#include <sycl/info/context_traits.def>
#include <sycl/info/event_traits.def>
#include <sycl/info/kernel_traits.def>
#include <sycl/info/platform_traits.def>
#include <sycl/info/queue_traits.def>
#undef __SYCL_PARAM_TRAITS_SPEC
#define __SYCL_PARAM_TRAITS_SPEC(DescType, Desc, ReturnT, PiCode) \
template <> struct PiInfoCode<info::DescType::Desc> { \
static constexpr pi_profiling_info value = PiCode; \
}; \
template <> \
struct is_##DescType##_info_desc<info::DescType::Desc> : std::true_type { \
using return_type = info::DescType::Desc::return_type; \
};
#include <sycl/info/event_profiling_traits.def>
#undef __SYCL_PARAM_TRAITS_SPEC

template <typename Param> struct IsSubGroupInfo : std::false_type {};
template <>
struct IsSubGroupInfo<info::kernel_device_specific::max_num_sub_groups>
: std::true_type {};
template <>
struct IsSubGroupInfo<info::kernel_device_specific::compile_num_sub_groups>
: std::true_type {};
template <>
struct IsSubGroupInfo<info::kernel_device_specific::max_sub_group_size>
: std::true_type {};
template <>
struct IsSubGroupInfo<info::kernel_device_specific::compile_sub_group_size>
: std::true_type {};

#define __SYCL_PARAM_TRAITS_SPEC(DescType, Desc, ReturnT, PiCode) \
template <> struct PiInfoCode<info::DescType::Desc> { \
static constexpr \
typename std::conditional<IsSubGroupInfo<info::DescType::Desc>::value, \
pi_kernel_sub_group_info, \
pi_kernel_group_info>::type value = PiCode; \
}; \
template <> \
struct is_##DescType##_info_desc<info::DescType::Desc> : std::true_type { \
using return_type = info::DescType::Desc::return_type; \
};
#define __SYCL_PARAM_TRAITS_SPEC_WITH_INPUT(DescType, Desc, ReturnT, InputT, \
PiCode) \
template <> struct PiInfoCode<info::DescType::Desc> { \
static constexpr \
typename std::conditional<IsSubGroupInfo<info::DescType::Desc>::value, \
pi_kernel_sub_group_info, \
pi_kernel_group_info>::type value = PiCode; \
}; \
template <> \
struct is_##DescType##_info_desc<info::DescType::Desc> : std::true_type { \
using with_input_return_type = info::DescType::Desc::return_type; \
};
#include <sycl/info/kernel_device_specific_traits.def>
#undef __SYCL_PARAM_TRAITS_SPEC_WITH_INPUT
#undef __SYCL_PARAM_TRAITS_SPEC
// Need a static_cast here since piDeviceGetInfo can also accept
// pi_usm_capability_query values.
#define __SYCL_PARAM_TRAITS_SPEC(DescType, Desc, ReturnT, PiCode) \
template <> struct PiInfoCode<info::DescType::Desc> { \
static constexpr pi_device_info value = \
static_cast<pi_device_info>(PiCode); \
}; \
template <> \
struct is_##DescType##_info_desc<info::DescType::Desc> : std::true_type { \
using return_type = info::DescType::Desc::return_type; \
};
#include <sycl/info/device_traits.def>
#undef __SYCL_PARAM_TRAITS_SPEC
} // namespace detail
} // namespace sycl
} // __SYCL_INLINE_NAMESPACE(cl)
6 changes: 3 additions & 3 deletions sycl/include/sycl/device.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include <sycl/detail/cl.h>
#include <sycl/detail/common.hpp>
#include <sycl/detail/export.hpp>
#include <sycl/detail/info_desc_helpers.hpp>
#include <sycl/info/info_desc.hpp>
#include <sycl/platform.hpp>
#include <sycl/stl.hpp>
Expand Down Expand Up @@ -160,9 +161,8 @@ class __SYCL_EXPORT device {
/// type associated with the param parameter.
///
/// \return device info of type described in Table 4.20.
template <info::device param>
typename info::param_traits<info::device, param>::return_type
get_info() const;
template <typename Param>
typename detail::is_device_info_desc<Param>::return_type get_info() const;

/// Check SYCL extension support by device
///
Expand Down
9 changes: 5 additions & 4 deletions sycl/include/sycl/event.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include <sycl/detail/cl.h>
#include <sycl/detail/common.hpp>
#include <sycl/detail/export.hpp>
#include <sycl/detail/info_desc_helpers.hpp>
#include <sycl/info/info_desc.hpp>
#include <sycl/stl.hpp>

Expand Down Expand Up @@ -110,8 +111,8 @@ class __SYCL_EXPORT event {
/// Queries this SYCL event for information.
///
/// \return depends on the information being requested.
template <info::event param>
typename info::param_traits<info::event, param>::return_type get_info() const;
template <typename Param>
typename detail::is_event_info_desc<Param>::return_type get_info() const;

/// Queries this SYCL event for profiling information.
///
Expand All @@ -124,8 +125,8 @@ class __SYCL_EXPORT event {
/// exception is thrown.
///
/// \return depends on template parameter.
template <info::event_profiling param>
typename info::param_traits<info::event_profiling, param>::return_type
template <typename Param>
typename detail::is_event_profiling_info_desc<Param>::return_type
get_profiling_info() const;

/// Returns the backend associated with this platform.
Expand Down
10 changes: 5 additions & 5 deletions sycl/include/sycl/info/context_traits.def
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
__SYCL_PARAM_TRAITS_SPEC(context, reference_count, uint32_t)
__SYCL_PARAM_TRAITS_SPEC(context, platform, sycl::platform)
__SYCL_PARAM_TRAITS_SPEC(context, devices, std::vector<sycl::device>)
__SYCL_PARAM_TRAITS_SPEC(context, atomic_memory_order_capabilities, std::vector<sycl::memory_order>)
__SYCL_PARAM_TRAITS_SPEC(context, atomic_memory_scope_capabilities, std::vector<sycl::memory_scope>)
__SYCL_PARAM_TRAITS_SPEC(context, reference_count, uint32_t, PI_CONTEXT_INFO_REFERENCE_COUNT)
__SYCL_PARAM_TRAITS_SPEC(context, platform, sycl::platform, PI_CONTEXT_INFO_PLATFORM)
__SYCL_PARAM_TRAITS_SPEC(context, devices, std::vector<sycl::device>, PI_CONTEXT_INFO_DEVICES)
__SYCL_PARAM_TRAITS_SPEC(context, atomic_memory_order_capabilities, std::vector<sycl::memory_order>, PI_CONTEXT_INFO_ATOMIC_MEMORY_ORDER_CAPABILITIES)
__SYCL_PARAM_TRAITS_SPEC(context, atomic_memory_scope_capabilities, std::vector<sycl::memory_scope>, PI_CONTEXT_INFO_ATOMIC_MEMORY_SCOPE_CAPABILITIES)
Loading