Skip to content
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

[SYCL] Implement get_backend_info() #12906

Merged
merged 18 commits into from
Mar 29, 2024
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
7 changes: 7 additions & 0 deletions sycl/include/sycl/context.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,13 @@ class __SYCL_EXPORT context : public detail::OwnerLessBase<context> {
template <typename Param>
typename detail::is_context_info_desc<Param>::return_type get_info() const;

/// Queries this SYCL context for SYCL backend-specific information.
///
/// The return type depends on information being queried.
template <typename Param>
typename detail::is_backend_info_desc<Param>::return_type
get_backend_info() const;

context(const context &rhs) = default;

context(context &&rhs) = default;
Expand Down
11 changes: 11 additions & 0 deletions sycl/include/sycl/detail/info_desc_helpers.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ template <typename T> struct is_event_profiling_info_desc : std::false_type {};
// 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

template <typename T> struct is_backend_info_desc : std::false_type {};
// Similar approach to limit valid get_backend_info template argument

#define __SYCL_PARAM_TRAITS_SPEC(DescType, Desc, ReturnT, PiCode) \
template <> struct PiInfoCode<info::DescType::Desc> { \
static constexpr pi_##DescType##_info value = PiCode; \
Expand Down Expand Up @@ -124,6 +128,13 @@ struct IsSubGroupInfo<info::kernel_device_specific::compile_sub_group_size>
#include <sycl/info/ext_intel_device_traits.def>
#include <sycl/info/ext_oneapi_device_traits.def>
#undef __SYCL_PARAM_TRAITS_SPEC
#define __SYCL_PARAM_TRAITS_SPEC(DescType, Desc, ReturnT, PiCode) \
template <> \
struct is_backend_info_desc<info::DescType::Desc> : std::true_type { \
using return_type = info::DescType::Desc::return_type; \
};
#include <sycl/info/sycl_backend_traits.def>
#undef __SYCL_PARAM_TRAITS_SPEC

} // namespace detail
} // namespace _V1
Expand Down
7 changes: 7 additions & 0 deletions sycl/include/sycl/device.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,13 @@ class __SYCL_EXPORT device : public detail::OwnerLessBase<device> {
get_info() const;
#endif

/// Queries this SYCL device for SYCL backend-specific information.
///
/// The return type depends on information being queried.
template <typename Param>
typename detail::is_backend_info_desc<Param>::return_type
get_backend_info() const;

/// Check SYCL extension support by device
///
/// \param extension_name is a name of queried extension.
Expand Down
7 changes: 7 additions & 0 deletions sycl/include/sycl/event.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,13 @@ class __SYCL_EXPORT event : public detail::OwnerLessBase<event> {
template <typename Param>
typename detail::is_event_info_desc<Param>::return_type get_info() const;

/// Queries this SYCL event for SYCL backend-specific information.
///
/// \return depends on information being queried.
template <typename Param>
typename detail::is_backend_info_desc<Param>::return_type
get_backend_info() const;

/// Queries this SYCL event for profiling information.
///
/// If the requested info is not available when this member function is called
Expand Down
3 changes: 3 additions & 0 deletions sycl/include/sycl/info/sycl_backend_traits.def
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
__SYCL_PARAM_TRAITS_SPEC(platform, version, std::string, PI_PLATFORM_INFO_VERSION)
__SYCL_PARAM_TRAITS_SPEC(device, version, std::string, PI_DEVICE_INFO_VERSION)
__SYCL_PARAM_TRAITS_SPEC(device, backend_version, std::string, PI_DEVICE_INFO_BACKEND_VERSION)
7 changes: 7 additions & 0 deletions sycl/include/sycl/kernel.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,13 @@ class __SYCL_EXPORT kernel : public detail::OwnerLessBase<kernel> {
typename detail::is_kernel_info_desc<Param>::return_type get_info() const;
#endif

/// Queries the kernel object for SYCL backend-specific information.
///
/// The return type depends on information being queried.
template <typename Param>
typename detail::is_backend_info_desc<Param>::return_type
get_backend_info() const;

/// Query device-specific information from the kernel object using the
/// info::kernel_device_specific descriptor.
///
Expand Down
8 changes: 8 additions & 0 deletions sycl/include/sycl/platform.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,14 @@ class __SYCL_EXPORT platform : public detail::OwnerLessBase<platform> {
typename detail::is_platform_info_desc<Param>::return_type>
get_info() const;
#endif

/// Queries this SYCL platform for SYCL backend-specific info.
///
/// The return type depends on information being queried.
template <typename Param>
typename detail::is_backend_info_desc<Param>::return_type
get_backend_info() const;

/// Returns all available SYCL platforms in the system.
///
/// The resulting vector always contains a single SYCL host platform instance.
Expand Down
7 changes: 7 additions & 0 deletions sycl/include/sycl/queue.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,13 @@ class __SYCL_EXPORT queue : public detail::OwnerLessBase<queue> {
template <typename Param>
typename detail::is_queue_info_desc<Param>::return_type get_info() const;

/// Queries SYCL queue for SYCL backend-specific information.
///
/// The return type depends on information being queried.
template <typename Param>
typename detail::is_backend_info_desc<Param>::return_type
get_backend_info() const;

private:
// A shorthand for `get_device().has()' which is expected to be a bit quicker
// than the long version
Expand Down
14 changes: 14 additions & 0 deletions sycl/source/context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,20 @@ context::get_info() const {

#undef __SYCL_PARAM_TRAITS_SPEC

template <typename Param>
typename detail::is_backend_info_desc<Param>::return_type
context::get_backend_info() const {
return impl->get_backend_info<Param>();
}

#define __SYCL_PARAM_TRAITS_SPEC(DescType, Desc, ReturnT, Picode) \
template __SYCL_EXPORT ReturnT \
context::get_backend_info<info::DescType::Desc>() const;

#include <sycl/info/sycl_backend_traits.def>

#undef __SYCL_PARAM_TRAITS_SPEC

#define __SYCL_PARAM_TRAITS_SPEC(param_type) \
template <> \
__SYCL_EXPORT bool context::has_property<param_type>() const noexcept { \
Expand Down
45 changes: 45 additions & 0 deletions sycl/source/detail/context_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,51 @@ context_impl::get_info<info::context::atomic_fence_scope_capabilities>() const {
return CapabilityList;
}

template <>
typename info::platform::version::return_type
context_impl::get_backend_info<info::platform::version>() const {
if (getBackend() != backend::opencl) {
throw sycl::exception(errc::backend_mismatch,
"the info::platform::version info descriptor can "
"only be queried with an OpenCL backend");
}
return MDevices[0].get_platform().get_info<info::platform::version>();
}

device select_device(DSelectorInvocableType DeviceSelectorInvocable,
std::vector<device> &Devices);

template <>
typename info::device::version::return_type
context_impl::get_backend_info<info::device::version>() const {
if (getBackend() != backend::opencl) {
throw sycl::exception(errc::backend_mismatch,
"the info::device::version info descriptor can only "
"be queried with an OpenCL backend");
}
auto Devices = get_info<info::context::devices>();
if (Devices.empty()) {
return "No available device";
}
// Use default selector to pick a device.
return select_device(default_selector_v, Devices)
.get_info<info::device::version>();
}

template <>
typename info::device::backend_version::return_type
context_impl::get_backend_info<info::device::backend_version>() const {
if (getBackend() != backend::ext_oneapi_level_zero) {
throw sycl::exception(errc::backend_mismatch,
"the info::device::backend_version info descriptor "
"can only be queried with a Level Zero backend");
}
return "";
// Currently The Level Zero backend does not define the value of this
// information descriptor and implementations are encouraged to return the
// empty string as per specification.
}

sycl::detail::pi::PiContext &context_impl::getHandleRef() { return MContext; }
const sycl::detail::pi::PiContext &context_impl::getHandleRef() const {
return MContext;
Expand Down
6 changes: 6 additions & 0 deletions sycl/source/detail/context_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,12 @@ class context_impl {
/// The return type depends on information being queried.
template <typename Param> typename Param::return_type get_info() const;

/// Queries SYCL queue for SYCL backend-specific information.
///
/// The return type depends on information being queried.
template <typename Param>
typename Param::return_type get_backend_info() const;

/// Gets the underlying context object (if any) without reference count
/// modification.
///
Expand Down
36 changes: 36 additions & 0 deletions sycl/source/detail/device_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,42 @@ typename Param::return_type device_impl::get_info() const {
#include <sycl/info/ext_oneapi_device_traits.def>
#undef __SYCL_PARAM_TRAITS_SPEC

template <>
typename info::platform::version::return_type
device_impl::get_backend_info<info::platform::version>() const {
if (getBackend() != backend::opencl) {
throw sycl::exception(errc::backend_mismatch,
"the info::platform::version info descriptor can "
"only be queried with an OpenCL backend");
}
return get_platform().get_info<info::platform::version>();
}

template <>
typename info::device::version::return_type
device_impl::get_backend_info<info::device::version>() const {
if (getBackend() != backend::opencl) {
throw sycl::exception(errc::backend_mismatch,
"the info::device::version info descriptor can only "
"be queried with an OpenCL backend");
}
return get_info<info::device::version>();
}

template <>
typename info::device::backend_version::return_type
device_impl::get_backend_info<info::device::backend_version>() const {
if (getBackend() != backend::ext_oneapi_level_zero) {
throw sycl::exception(errc::backend_mismatch,
"the info::device::backend_version info descriptor "
"can only be queried with a Level Zero backend");
}
return "";
// Currently The Level Zero backend does not define the value of this
// information descriptor and implementations are encouraged to return the
// empty string as per specification.
}

bool device_impl::has_extension(const std::string &ExtensionName) const {
if (MIsHostDevice)
// TODO: implement extension management for host device;
Expand Down
6 changes: 6 additions & 0 deletions sycl/source/detail/device_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,12 @@ class device_impl {
/// \return device info of type described in Table 4.20.
template <typename Param> typename Param::return_type get_info() const;

/// Queries SYCL queue for SYCL backend-specific information.
///
/// The return type depends on information being queried.
template <typename Param>
typename Param::return_type get_backend_info() const;

/// Check if affinity partitioning by specified domain is supported by
/// device
///
Expand Down
55 changes: 55 additions & 0 deletions sycl/source/detail/event_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,61 @@ event_impl::get_info<info::event::command_execution_status>() {
: info::event_command_status::complete;
}

template <>
typename info::platform::version::return_type
event_impl::get_backend_info<info::platform::version>() const {
if (!MIsContextInitialized) {
return "Context not initialized, no backend info available";
}
if (MContext->getBackend() != backend::opencl) {
HPS-1 marked this conversation as resolved.
Show resolved Hide resolved
throw sycl::exception(errc::backend_mismatch,
"the info::platform::version info descriptor can "
"only be queried with an OpenCL backend");
}
if (QueueImplPtr Queue = MQueue.lock()) {
return Queue->getDeviceImplPtr()
->get_platform()
.get_info<info::platform::version>();
}
return ""; // If the queue has been released, no platform will be associated
// so return empty string
}

template <>
typename info::device::version::return_type
event_impl::get_backend_info<info::device::version>() const {
if (!MIsContextInitialized) {
return "Context not initialized, no backend info available";
}
if (MContext->getBackend() != backend::opencl) {
throw sycl::exception(errc::backend_mismatch,
"the info::device::version info descriptor can only "
"be queried with an OpenCL backend");
}
if (QueueImplPtr Queue = MQueue.lock()) {
return Queue->getDeviceImplPtr()->get_info<info::device::version>();
}
return ""; // If the queue has been released, no device will be associated so
// return empty string
}

template <>
typename info::device::backend_version::return_type
event_impl::get_backend_info<info::device::backend_version>() const {
if (!MIsContextInitialized) {
return "Context not initialized, no backend info available";
}
if (MContext->getBackend() != backend::ext_oneapi_level_zero) {
throw sycl::exception(errc::backend_mismatch,
"the info::device::backend_version info descriptor "
"can only be queried with a Level Zero backend");
}
return "";
// Currently The Level Zero backend does not define the value of this
// information descriptor and implementations are encouraged to return the
// empty string as per specification.
}

void HostProfilingInfo::start() { StartTime = getTimestamp(); }

void HostProfilingInfo::end() { EndTime = getTimestamp(); }
Expand Down
6 changes: 6 additions & 0 deletions sycl/source/detail/event_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,12 @@ class event_impl {
/// \return depends on the information being requested.
template <typename Param> typename Param::return_type get_info();

/// Queries this SYCL event for SYCL backend-specific information.
///
/// \return depends on information being queried.
template <typename Param>
typename Param::return_type get_backend_info() const;

~event_impl();

/// Waits for the event with respect to device type.
Expand Down
46 changes: 46 additions & 0 deletions sycl/source/detail/kernel_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,52 @@ void kernel_impl::checkIfValidForNumArgsInfoQuery() const {
"interoperability function or to query a device built-in kernel");
}

template <>
typename info::platform::version::return_type
kernel_impl::get_backend_info<info::platform::version>() const {
if (MContext->getBackend() != backend::opencl) {
throw sycl::exception(errc::backend_mismatch,
"the info::platform::version info descriptor can "
"only be queried with an OpenCL backend");
}
auto Devices = MKernelBundleImpl->get_devices();
return Devices[0].get_platform().get_info<info::platform::version>();
}

device select_device(DSelectorInvocableType DeviceSelectorInvocable,
std::vector<device> &Devices);

template <>
typename info::device::version::return_type
kernel_impl::get_backend_info<info::device::version>() const {
if (MContext->getBackend() != backend::opencl) {
throw sycl::exception(errc::backend_mismatch,
"the info::device::version info descriptor can only "
"be queried with an OpenCL backend");
}
auto Devices = MKernelBundleImpl->get_devices();
if (Devices.empty()) {
return "No available device";
}
// Use default selector to pick a device.
return select_device(default_selector_v, Devices)
.get_info<info::device::version>();
}

template <>
typename info::device::backend_version::return_type
kernel_impl::get_backend_info<info::device::backend_version>() const {
if (MContext->getBackend() != backend::ext_oneapi_level_zero) {
throw sycl::exception(errc::backend_mismatch,
"the info::device::backend_version info descriptor "
"can only be queried with a Level Zero backend");
}
return "";
// Currently The Level Zero backend does not define the value of this
// information descriptor and implementations are encouraged to return the
// empty string as per specification.
}

} // namespace detail
} // namespace _V1
} // namespace sycl
6 changes: 6 additions & 0 deletions sycl/source/detail/kernel_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,12 @@ class kernel_impl {
/// \return depends on information being queried.
template <typename Param> typename Param::return_type get_info() const;

/// Queries the kernel object for SYCL backend-specific information.
///
/// \return depends on information being queried.
template <typename Param>
typename Param::return_type get_backend_info() const;

/// Query device-specific information from a kernel object using the
/// info::kernel_device_specific descriptor.
///
Expand Down
Loading
Loading