diff --git a/sycl/include/sycl/context.hpp b/sycl/include/sycl/context.hpp index 723234c6b07c7..c3e29e81bd89a 100644 --- a/sycl/include/sycl/context.hpp +++ b/sycl/include/sycl/context.hpp @@ -175,6 +175,13 @@ class __SYCL_EXPORT context : public detail::OwnerLessBase { template typename detail::is_context_info_desc::return_type get_info() const; + /// Queries this SYCL context for SYCL backend-specific information. + /// + /// The return type depends on information being queried. + template + typename detail::is_backend_info_desc::return_type + get_backend_info() const; + context(const context &rhs) = default; context(context &&rhs) = default; diff --git a/sycl/include/sycl/detail/info_desc_helpers.hpp b/sycl/include/sycl/detail/info_desc_helpers.hpp index 6706a3c02487f..9a52fe8021e2b 100644 --- a/sycl/include/sycl/detail/info_desc_helpers.hpp +++ b/sycl/include/sycl/detail/info_desc_helpers.hpp @@ -39,6 +39,10 @@ template 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 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 { \ static constexpr pi_##DescType##_info value = PiCode; \ @@ -124,6 +128,13 @@ struct IsSubGroupInfo #include #include #undef __SYCL_PARAM_TRAITS_SPEC +#define __SYCL_PARAM_TRAITS_SPEC(DescType, Desc, ReturnT, PiCode) \ + template <> \ + struct is_backend_info_desc : std::true_type { \ + using return_type = info::DescType::Desc::return_type; \ + }; +#include +#undef __SYCL_PARAM_TRAITS_SPEC } // namespace detail } // namespace _V1 diff --git a/sycl/include/sycl/device.hpp b/sycl/include/sycl/device.hpp index 3f8dc33b5dd4f..a6968b481cd84 100644 --- a/sycl/include/sycl/device.hpp +++ b/sycl/include/sycl/device.hpp @@ -233,6 +233,13 @@ class __SYCL_EXPORT device : public detail::OwnerLessBase { get_info() const; #endif + /// Queries this SYCL device for SYCL backend-specific information. + /// + /// The return type depends on information being queried. + template + typename detail::is_backend_info_desc::return_type + get_backend_info() const; + /// Check SYCL extension support by device /// /// \param extension_name is a name of queried extension. diff --git a/sycl/include/sycl/event.hpp b/sycl/include/sycl/event.hpp index 5fd596cbc452b..8e966b5e3302e 100644 --- a/sycl/include/sycl/event.hpp +++ b/sycl/include/sycl/event.hpp @@ -115,6 +115,13 @@ class __SYCL_EXPORT event : public detail::OwnerLessBase { template typename detail::is_event_info_desc::return_type get_info() const; + /// Queries this SYCL event for SYCL backend-specific information. + /// + /// \return depends on information being queried. + template + typename detail::is_backend_info_desc::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 diff --git a/sycl/include/sycl/info/sycl_backend_traits.def b/sycl/include/sycl/info/sycl_backend_traits.def new file mode 100644 index 0000000000000..b919a26d19282 --- /dev/null +++ b/sycl/include/sycl/info/sycl_backend_traits.def @@ -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) diff --git a/sycl/include/sycl/kernel.hpp b/sycl/include/sycl/kernel.hpp index 6cc7c3c3da215..e92ca5441f9e0 100644 --- a/sycl/include/sycl/kernel.hpp +++ b/sycl/include/sycl/kernel.hpp @@ -150,6 +150,13 @@ class __SYCL_EXPORT kernel : public detail::OwnerLessBase { typename detail::is_kernel_info_desc::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 detail::is_backend_info_desc::return_type + get_backend_info() const; + /// Query device-specific information from the kernel object using the /// info::kernel_device_specific descriptor. /// diff --git a/sycl/include/sycl/platform.hpp b/sycl/include/sycl/platform.hpp index 32a93acd0a873..7e5919495dd60 100644 --- a/sycl/include/sycl/platform.hpp +++ b/sycl/include/sycl/platform.hpp @@ -201,6 +201,14 @@ class __SYCL_EXPORT platform : public detail::OwnerLessBase { typename detail::is_platform_info_desc::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 detail::is_backend_info_desc::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. diff --git a/sycl/include/sycl/queue.hpp b/sycl/include/sycl/queue.hpp index 6b9494fbc865a..adbf72271fdae 100644 --- a/sycl/include/sycl/queue.hpp +++ b/sycl/include/sycl/queue.hpp @@ -331,6 +331,13 @@ class __SYCL_EXPORT queue : public detail::OwnerLessBase { template typename detail::is_queue_info_desc::return_type get_info() const; + /// Queries SYCL queue for SYCL backend-specific information. + /// + /// The return type depends on information being queried. + template + typename detail::is_backend_info_desc::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 diff --git a/sycl/source/context.cpp b/sycl/source/context.cpp index 5ae0bba6dadcc..3273c4f3056c2 100644 --- a/sycl/source/context.cpp +++ b/sycl/source/context.cpp @@ -103,6 +103,20 @@ context::get_info() const { #undef __SYCL_PARAM_TRAITS_SPEC +template +typename detail::is_backend_info_desc::return_type +context::get_backend_info() const { + return impl->get_backend_info(); +} + +#define __SYCL_PARAM_TRAITS_SPEC(DescType, Desc, ReturnT, Picode) \ + template __SYCL_EXPORT ReturnT \ + context::get_backend_info() const; + +#include + +#undef __SYCL_PARAM_TRAITS_SPEC + #define __SYCL_PARAM_TRAITS_SPEC(param_type) \ template <> \ __SYCL_EXPORT bool context::has_property() const noexcept { \ diff --git a/sycl/source/detail/context_impl.cpp b/sycl/source/detail/context_impl.cpp index 9c58335a069c2..388c312305d4a 100644 --- a/sycl/source/detail/context_impl.cpp +++ b/sycl/source/detail/context_impl.cpp @@ -254,6 +254,51 @@ context_impl::get_info() const { return CapabilityList; } +template <> +typename info::platform::version::return_type +context_impl::get_backend_info() 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(); +} + +device select_device(DSelectorInvocableType DeviceSelectorInvocable, + std::vector &Devices); + +template <> +typename info::device::version::return_type +context_impl::get_backend_info() 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(); + if (Devices.empty()) { + return "No available device"; + } + // Use default selector to pick a device. + return select_device(default_selector_v, Devices) + .get_info(); +} + +template <> +typename info::device::backend_version::return_type +context_impl::get_backend_info() 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; diff --git a/sycl/source/detail/context_impl.hpp b/sycl/source/detail/context_impl.hpp index d3d84cce8c28b..7f07b123e1ab6 100644 --- a/sycl/source/detail/context_impl.hpp +++ b/sycl/source/detail/context_impl.hpp @@ -118,6 +118,12 @@ class context_impl { /// The return type depends on information being queried. template 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::return_type get_backend_info() const; + /// Gets the underlying context object (if any) without reference count /// modification. /// diff --git a/sycl/source/detail/device_impl.cpp b/sycl/source/detail/device_impl.cpp index b185df451d362..72f0fd1aa8cbd 100644 --- a/sycl/source/detail/device_impl.cpp +++ b/sycl/source/detail/device_impl.cpp @@ -143,6 +143,42 @@ typename Param::return_type device_impl::get_info() const { #include #undef __SYCL_PARAM_TRAITS_SPEC +template <> +typename info::platform::version::return_type +device_impl::get_backend_info() 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(); +} + +template <> +typename info::device::version::return_type +device_impl::get_backend_info() 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(); +} + +template <> +typename info::device::backend_version::return_type +device_impl::get_backend_info() 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; diff --git a/sycl/source/detail/device_impl.hpp b/sycl/source/detail/device_impl.hpp index 25d39ad9c2d12..ef2580404e1e9 100644 --- a/sycl/source/detail/device_impl.hpp +++ b/sycl/source/detail/device_impl.hpp @@ -201,6 +201,12 @@ class device_impl { /// \return device info of type described in Table 4.20. template 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::return_type get_backend_info() const; + /// Check if affinity partitioning by specified domain is supported by /// device /// diff --git a/sycl/source/detail/event_impl.cpp b/sycl/source/detail/event_impl.cpp index 2be79be727369..5208a180d2e46 100644 --- a/sycl/source/detail/event_impl.cpp +++ b/sycl/source/detail/event_impl.cpp @@ -407,6 +407,61 @@ event_impl::get_info() { : info::event_command_status::complete; } +template <> +typename info::platform::version::return_type +event_impl::get_backend_info() const { + if (!MIsContextInitialized) { + return "Context not initialized, no backend info available"; + } + 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"); + } + if (QueueImplPtr Queue = MQueue.lock()) { + return Queue->getDeviceImplPtr() + ->get_platform() + .get_info(); + } + 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() 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(); + } + 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() 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(); } diff --git a/sycl/source/detail/event_impl.hpp b/sycl/source/detail/event_impl.hpp index 2721832266218..6afefc2e3f155 100644 --- a/sycl/source/detail/event_impl.hpp +++ b/sycl/source/detail/event_impl.hpp @@ -105,6 +105,12 @@ class event_impl { /// \return depends on the information being requested. template typename Param::return_type get_info(); + /// Queries this SYCL event for SYCL backend-specific information. + /// + /// \return depends on information being queried. + template + typename Param::return_type get_backend_info() const; + ~event_impl(); /// Waits for the event with respect to device type. diff --git a/sycl/source/detail/kernel_impl.cpp b/sycl/source/detail/kernel_impl.cpp index 9bb58277dcea9..9c5a1851cd3b1 100644 --- a/sycl/source/detail/kernel_impl.cpp +++ b/sycl/source/detail/kernel_impl.cpp @@ -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() 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(); +} + +device select_device(DSelectorInvocableType DeviceSelectorInvocable, + std::vector &Devices); + +template <> +typename info::device::version::return_type +kernel_impl::get_backend_info() 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(); +} + +template <> +typename info::device::backend_version::return_type +kernel_impl::get_backend_info() 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 diff --git a/sycl/source/detail/kernel_impl.hpp b/sycl/source/detail/kernel_impl.hpp index 4a23fb4e39ef4..1e56e6da4dc53 100644 --- a/sycl/source/detail/kernel_impl.hpp +++ b/sycl/source/detail/kernel_impl.hpp @@ -125,6 +125,12 @@ class kernel_impl { /// \return depends on information being queried. template 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::return_type get_backend_info() const; + /// Query device-specific information from a kernel object using the /// info::kernel_device_specific descriptor. /// diff --git a/sycl/source/detail/platform_impl.cpp b/sycl/source/detail/platform_impl.cpp index eb28ffaf3819a..3f0e9c6cf83fc 100644 --- a/sycl/source/detail/platform_impl.cpp +++ b/sycl/source/detail/platform_impl.cpp @@ -610,6 +610,51 @@ typename Param::return_type platform_impl::get_info() const { return get_platform_info(this->getHandleRef(), getPlugin()); } +template <> +typename info::platform::version::return_type +platform_impl::get_backend_info() 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_info(); +} + +device select_device(DSelectorInvocableType DeviceSelectorInvocable, + std::vector &Devices); + +template <> +typename info::device::version::return_type +platform_impl::get_backend_info() 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_devices(); + if (Devices.empty()) { + return "No available device"; + } + // Use default selector to pick a device. + return select_device(default_selector_v, Devices) + .get_info(); +} + +template <> +typename info::device::backend_version::return_type +platform_impl::get_backend_info() 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. +} + // All devices on the platform must have the given aspect. bool platform_impl::has(aspect Aspect) const { for (const auto &dev : get_devices()) { diff --git a/sycl/source/detail/platform_impl.hpp b/sycl/source/detail/platform_impl.hpp index 2948907aa61f4..34537c7191af6 100644 --- a/sycl/source/detail/platform_impl.hpp +++ b/sycl/source/detail/platform_impl.hpp @@ -83,6 +83,12 @@ class platform_impl { /// The return type depends on information being queried. template typename Param::return_type get_info() const; + /// Queries this SYCL platform for SYCL backend-specific information. + /// + /// The return type depends on information being queried. + template + typename Param::return_type get_backend_info() const; + /// \return true if this SYCL platform is a host platform. bool is_host() const { return MHostPlatform; }; diff --git a/sycl/source/detail/queue_impl.cpp b/sycl/source/detail/queue_impl.cpp index 321cc48b29769..21dc5c4923b4a 100644 --- a/sycl/source/detail/queue_impl.cpp +++ b/sycl/source/detail/queue_impl.cpp @@ -57,6 +57,42 @@ template <> device queue_impl::get_info() const { return get_device(); } +template <> +typename info::platform::version::return_type +queue_impl::get_backend_info() const { + if (getContextImplPtr()->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_device().get_platform().get_info(); +} + +template <> +typename info::device::version::return_type +queue_impl::get_backend_info() const { + if (getContextImplPtr()->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_device().get_info(); +} + +template <> +typename info::device::backend_version::return_type +queue_impl::get_backend_info() const { + if (getContextImplPtr()->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. +} + static event prepareSYCLEventAssociatedWithQueue( const std::shared_ptr &QueueImpl) { auto EventImpl = std::make_shared(QueueImpl); diff --git a/sycl/source/detail/queue_impl.hpp b/sycl/source/detail/queue_impl.hpp index 890891644bbac..6f283e75b4856 100644 --- a/sycl/source/detail/queue_impl.hpp +++ b/sycl/source/detail/queue_impl.hpp @@ -391,6 +391,12 @@ class queue_impl { /// The return type depends on information being queried. template 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::return_type get_backend_info() const; + using SubmitPostProcessF = std::function; /// Submits a command group function object to the queue, in order to be diff --git a/sycl/source/device.cpp b/sycl/source/device.cpp index 4d9737ca0412a..d027525af8e47 100644 --- a/sycl/source/device.cpp +++ b/sycl/source/device.cpp @@ -234,6 +234,20 @@ __SYCL_EXPORT bool device::get_info() const { #include #undef __SYCL_PARAM_TRAITS_SPEC +template +typename detail::is_backend_info_desc::return_type +device::get_backend_info() const { + return impl->get_backend_info(); +} + +#define __SYCL_PARAM_TRAITS_SPEC(DescType, Desc, ReturnT, Picode) \ + template __SYCL_EXPORT ReturnT \ + device::get_backend_info() const; + +#include + +#undef __SYCL_PARAM_TRAITS_SPEC + backend device::get_backend() const noexcept { return impl->getBackend(); } pi_native_handle device::getNative() const { return impl->getNative(); } diff --git a/sycl/source/event.cpp b/sycl/source/event.cpp index 897c48ca7e890..a7bae8055c10b 100644 --- a/sycl/source/event.cpp +++ b/sycl/source/event.cpp @@ -77,6 +77,12 @@ event::get_info() const { return impl->template get_info(); } +template +typename detail::is_backend_info_desc::return_type +event::get_backend_info() const { + return impl->get_backend_info(); +} + template typename detail::is_event_profiling_info_desc::return_type event::get_profiling_info() const { @@ -100,6 +106,14 @@ event::get_profiling_info() const { #undef __SYCL_PARAM_TRAITS_SPEC +#define __SYCL_PARAM_TRAITS_SPEC(DescType, Desc, ReturnT, Picode) \ + template __SYCL_EXPORT ReturnT \ + event::get_backend_info() const; + +#include + +#undef __SYCL_PARAM_TRAITS_SPEC + #define __SYCL_PARAM_TRAITS_SPEC(DescType, Desc, ReturnT, PiCode) \ template __SYCL_EXPORT ReturnT \ event::get_profiling_info() const; diff --git a/sycl/source/kernel.cpp b/sycl/source/kernel.cpp index d981833f94958..ff81752dc1f4e 100644 --- a/sycl/source/kernel.cpp +++ b/sycl/source/kernel.cpp @@ -72,6 +72,20 @@ kernel::get_info() const { #undef __SYCL_PARAM_TRAITS_SPEC +template +typename detail::is_backend_info_desc::return_type +kernel::get_backend_info() const { + return impl->get_backend_info(); +} + +#define __SYCL_PARAM_TRAITS_SPEC(DescType, Desc, ReturnT, Picode) \ + template __SYCL_EXPORT ReturnT \ + kernel::get_backend_info() const; + +#include + +#undef __SYCL_PARAM_TRAITS_SPEC + template typename detail::is_kernel_device_specific_info_desc::return_type kernel::get_info(const device &Dev) const { diff --git a/sycl/source/platform.cpp b/sycl/source/platform.cpp index c991f27eda51b..71bff195037a0 100644 --- a/sycl/source/platform.cpp +++ b/sycl/source/platform.cpp @@ -84,6 +84,20 @@ bool platform::has(aspect Aspect) const { return impl->has(Aspect); } #include #undef __SYCL_PARAM_TRAITS_SPEC +template +typename detail::is_backend_info_desc::return_type +platform::get_backend_info() const { + return impl->get_backend_info(); +} + +#define __SYCL_PARAM_TRAITS_SPEC(DescType, Desc, ReturnT, Picode) \ + template __SYCL_EXPORT ReturnT \ + platform::get_backend_info() const; + +#include + +#undef __SYCL_PARAM_TRAITS_SPEC + context platform::ext_oneapi_get_default_context() const { if (!detail::SYCLConfig::get()) throw std::runtime_error("SYCL default contexts are not enabled"); diff --git a/sycl/source/queue.cpp b/sycl/source/queue.cpp index acaecf2696629..649ddb0629d0f 100644 --- a/sycl/source/queue.cpp +++ b/sycl/source/queue.cpp @@ -283,6 +283,20 @@ queue::get_info() const { #undef __SYCL_PARAM_TRAITS_SPEC +template +typename detail::is_backend_info_desc::return_type +queue::get_backend_info() const { + return impl->get_backend_info(); +} + +#define __SYCL_PARAM_TRAITS_SPEC(DescType, Desc, ReturnT, Picode) \ + template __SYCL_EXPORT ReturnT \ + queue::get_backend_info() const; + +#include + +#undef __SYCL_PARAM_TRAITS_SPEC + template bool queue::has_property() const noexcept { return impl->has_property(); } diff --git a/sycl/test-e2e/Basic/backend_info.cpp b/sycl/test-e2e/Basic/backend_info.cpp new file mode 100644 index 0000000000000..33e4664318c6a --- /dev/null +++ b/sycl/test-e2e/Basic/backend_info.cpp @@ -0,0 +1,96 @@ +// RUN: %{build} -o %t.out +// RUN: %{run} %t.out +// + +//==--- backend_info.cpp - SYCL backend info test---------------------------==// +// +// 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 +// +//===----------------------------------------------------------------------===// + +#include +#include + +using namespace sycl; + +int main() { + try { + // Test get_backend_info for sycl::platform + std::vector platform_list = platform::get_platforms(); + for (const auto &platform : platform_list) { + std::cout << " Backend device version: " + << platform.get_backend_info() + << std::endl; + std::cout << " Backend platform version: " + << platform.get_backend_info() + << std::endl; + } + + // Test get_backend_info for sycl::device + std::vector device_list = + device::get_devices(info::device_type::gpu); + for (const auto &device : device_list) { + std::cout << " Backend device version: " + << device.get_backend_info() + << std::endl; + std::cout << " Backend platform version: " + << device.get_backend_info() + << std::endl; + } + + // Test get_backend_info for sycl::queue + queue q; + std::cout << " Backend device version: " + << q.get_backend_info() << std::endl; + std::cout << " Backend platform version: " + << q.get_backend_info() << std::endl; + + // Test get_backend_info for sycl::context + context Ctx = q.get_context(); + std::cout << " Backend device version: " + << Ctx.get_backend_info() << std::endl; + std::cout << " Backend platform version: " + << Ctx.get_backend_info() << std::endl; + + // Test get_backend_info for sycl::event + event e = q.single_task([=]() { return; }); + std::cout << " Backend device version: " + << e.get_backend_info() << std::endl; + std::cout << " Backend platform version: " + << e.get_backend_info() << std::endl; + + // Test get_backend_info for sycl::kernel + // Trivial kernel simply for testing + buffer buf(range<1>(1)); + auto KernelID = sycl::get_kernel_id(); + auto KB = get_kernel_bundle(q.get_context(), + {KernelID}); + kernel krn = KB.get_kernel(KernelID); + q.submit([&](handler &cgh) { + auto acc = buf.get_access(cgh); + cgh.single_task(krn, [=]() { acc[0] = acc[0] + 1; }); + }); + std::cout << " Backend device version: " + << krn.get_backend_info() << std::endl; + std::cout << " Backend platform version: " + << krn.get_backend_info() << std::endl; + } catch (exception e) { + // Check if the error code is the only allowed one: errc::backend_mismatch + assert(e.code() == sycl::errc::backend_mismatch && "wrong error code"); + // If so, check if there're truly non-OpenCL backend(s) or it's an + // unexpected error + std::vector platform_list = platform::get_platforms(); + bool has_non_opencl_backend = false; + for (const auto &platform : platform_list) { + if (platform.get_backend() != backend::opencl) { + has_non_opencl_backend = true; + break; + } + } + assert(has_non_opencl_backend && "unexpected error code"); + } + std::cout << " Backend info query tests passed" << std::endl; + return 0; +} diff --git a/sycl/test/abi/sycl_symbols_linux.dump b/sycl/test/abi/sycl_symbols_linux.dump index 8a5cbaa9bbac2..2561d1ded6481 100644 --- a/sycl/test/abi/sycl_symbols_linux.dump +++ b/sycl/test/abi/sycl_symbols_linux.dump @@ -4264,6 +4264,9 @@ _ZNK4sycl3_V13ext8codeplay12experimental14fusion_wrapper17is_in_fusion_modeEv _ZNK4sycl3_V13ext8codeplay12experimental14fusion_wrapper9get_queueEv _ZNK4sycl3_V15event11get_backendEv _ZNK4sycl3_V15event15getNativeVectorEv +_ZNK4sycl3_V15event16get_backend_infoINS0_4info6device15backend_versionEEENS0_6detail20is_backend_info_descIT_E11return_typeEv +_ZNK4sycl3_V15event16get_backend_infoINS0_4info6device7versionEEENS0_6detail20is_backend_info_descIT_E11return_typeEv +_ZNK4sycl3_V15event16get_backend_infoINS0_4info8platform7versionEEENS0_6detail20is_backend_info_descIT_E11return_typeEv _ZNK4sycl3_V15event18get_profiling_infoINS0_4info15event_profiling11command_endEEENS0_6detail28is_event_profiling_info_descIT_E11return_typeEv _ZNK4sycl3_V15event18get_profiling_infoINS0_4info15event_profiling13command_startEEENS0_6detail28is_event_profiling_info_descIT_E11return_typeEv _ZNK4sycl3_V15event18get_profiling_infoINS0_4info15event_profiling14command_submitEEENS0_6detail28is_event_profiling_info_descIT_E11return_typeEv @@ -4301,6 +4304,9 @@ _ZNK4sycl3_V15queue12has_propertyINS0_8property5queue16enable_profilingEEEbv _ZNK4sycl3_V15queue12has_propertyINS0_8property5queue4cuda18use_default_streamEEEbv _ZNK4sycl3_V15queue12has_propertyINS0_8property5queue8in_orderEEEbv _ZNK4sycl3_V15queue16ext_oneapi_emptyEv +_ZNK4sycl3_V15queue16get_backend_infoINS0_4info6device15backend_versionEEENS0_6detail20is_backend_info_descIT_E11return_typeEv +_ZNK4sycl3_V15queue16get_backend_infoINS0_4info6device7versionEEENS0_6detail20is_backend_info_descIT_E11return_typeEv +_ZNK4sycl3_V15queue16get_backend_infoINS0_4info8platform7versionEEENS0_6detail20is_backend_info_descIT_E11return_typeEv _ZNK4sycl3_V15queue20ext_oneapi_get_graphEv _ZNK4sycl3_V15queue20ext_oneapi_get_stateEv _ZNK4sycl3_V15queue25ext_oneapi_get_last_eventEv @@ -4491,6 +4497,9 @@ _ZNK4sycl3_V16device11get_backendEv _ZNK4sycl3_V16device12get_platformEv _ZNK4sycl3_V16device13has_extensionERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE _ZNK4sycl3_V16device14is_acceleratorEv +_ZNK4sycl3_V16device16get_backend_infoINS0_4info6device15backend_versionEEENS0_6detail20is_backend_info_descIT_E11return_typeEv +_ZNK4sycl3_V16device16get_backend_infoINS0_4info6device7versionEEENS0_6detail20is_backend_info_descIT_E11return_typeEv +_ZNK4sycl3_V16device16get_backend_infoINS0_4info8platform7versionEEENS0_6detail20is_backend_info_descIT_E11return_typeEv _ZNK4sycl3_V16device18create_sub_devicesILNS0_4info18partition_propertyE4230EEESt6vectorIS1_SaIS1_EEm _ZNK4sycl3_V16device18create_sub_devicesILNS0_4info18partition_propertyE4231EEESt6vectorIS1_SaIS1_EERKS5_ImSaImEE _ZNK4sycl3_V16device18create_sub_devicesILNS0_4info18partition_propertyE4232EEESt6vectorIS1_SaIS1_EENS3_25partition_affinity_domainE @@ -4645,6 +4654,9 @@ _ZNK4sycl3_V16device9getNativeEv _ZNK4sycl3_V16kernel11get_backendEv _ZNK4sycl3_V16kernel11get_contextEv _ZNK4sycl3_V16kernel13getNativeImplEv +_ZNK4sycl3_V16kernel16get_backend_infoINS0_4info6device15backend_versionEEENS0_6detail20is_backend_info_descIT_E11return_typeEv +_ZNK4sycl3_V16kernel16get_backend_infoINS0_4info6device7versionEEENS0_6detail20is_backend_info_descIT_E11return_typeEv +_ZNK4sycl3_V16kernel16get_backend_infoINS0_4info8platform7versionEEENS0_6detail20is_backend_info_descIT_E11return_typeEv _ZNK4sycl3_V16kernel17get_kernel_bundleEv _ZNK4sycl3_V16kernel19ext_oneapi_get_infoINS0_3ext6oneapi12experimental4info21kernel_queue_specific23max_num_work_group_syncEEENT_11return_typeERKNS0_5queueE _ZNK4sycl3_V16kernel3getEv @@ -4743,6 +4755,9 @@ _ZNK4sycl3_V17context12has_propertyINS0_8property6noinitEEEbv _ZNK4sycl3_V17context12has_propertyINS0_8property7context4cuda19use_primary_contextEEEbv _ZNK4sycl3_V17context12has_propertyINS0_8property7no_initEEEbv _ZNK4sycl3_V17context12has_propertyINS0_8property9reduction22initialize_to_identityEEEbv +_ZNK4sycl3_V17context16get_backend_infoINS0_4info6device15backend_versionEEENS0_6detail20is_backend_info_descIT_E11return_typeEv +_ZNK4sycl3_V17context16get_backend_infoINS0_4info6device7versionEEENS0_6detail20is_backend_info_descIT_E11return_typeEv +_ZNK4sycl3_V17context16get_backend_infoINS0_4info8platform7versionEEENS0_6detail20is_backend_info_descIT_E11return_typeEv _ZNK4sycl3_V17context3getEv _ZNK4sycl3_V17context7is_hostEv _ZNK4sycl3_V17context8get_infoINS0_4info7context15reference_countEEENS0_6detail20is_context_info_descIT_E11return_typeEv @@ -4799,6 +4814,9 @@ _ZNK4sycl3_V17samplerneERKS1_ _ZNK4sycl3_V18platform11get_backendEv _ZNK4sycl3_V18platform11get_devicesENS0_4info11device_typeE _ZNK4sycl3_V18platform13has_extensionERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE +_ZNK4sycl3_V18platform16get_backend_infoINS0_4info6device15backend_versionEEENS0_6detail20is_backend_info_descIT_E11return_typeEv +_ZNK4sycl3_V18platform16get_backend_infoINS0_4info6device7versionEEENS0_6detail20is_backend_info_descIT_E11return_typeEv +_ZNK4sycl3_V18platform16get_backend_infoINS0_4info8platform7versionEEENS0_6detail20is_backend_info_descIT_E11return_typeEv _ZNK4sycl3_V18platform30ext_oneapi_get_default_contextEv _ZNK4sycl3_V18platform32ext_oneapi_get_composite_devicesEv _ZNK4sycl3_V18platform3getEv diff --git a/sycl/test/abi/sycl_symbols_windows.dump b/sycl/test/abi/sycl_symbols_windows.dump index daf42c02be9ec..d4f99aed4f713 100644 --- a/sycl/test/abi/sycl_symbols_windows.dump +++ b/sycl/test/abi/sycl_symbols_windows.dump @@ -20,6 +20,24 @@ ??$getPlugin@$04@pi@detail@_V1@sycl@@YAAEBV?$shared_ptr@Vplugin@detail@_V1@sycl@@@std@@XZ ??$getPlugin@$05@pi@detail@_V1@sycl@@YAAEBV?$shared_ptr@Vplugin@detail@_V1@sycl@@@std@@XZ ??$getPluginOpaqueData@$04@detail@_V1@sycl@@YAPEAXPEAX@Z +??$get_backend_info@Ubackend_version@device@info@_V1@sycl@@@context@_V1@sycl@@QEBA?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@XZ +??$get_backend_info@Ubackend_version@device@info@_V1@sycl@@@device@_V1@sycl@@QEBA?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@XZ +??$get_backend_info@Ubackend_version@device@info@_V1@sycl@@@event@_V1@sycl@@QEBA?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@XZ +??$get_backend_info@Ubackend_version@device@info@_V1@sycl@@@kernel@_V1@sycl@@QEBA?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@XZ +??$get_backend_info@Ubackend_version@device@info@_V1@sycl@@@platform@_V1@sycl@@QEBA?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@XZ +??$get_backend_info@Ubackend_version@device@info@_V1@sycl@@@queue@_V1@sycl@@QEBA?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@XZ +??$get_backend_info@Uversion@device@info@_V1@sycl@@@context@_V1@sycl@@QEBA?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@XZ +??$get_backend_info@Uversion@device@info@_V1@sycl@@@device@_V1@sycl@@QEBA?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@XZ +??$get_backend_info@Uversion@device@info@_V1@sycl@@@event@_V1@sycl@@QEBA?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@XZ +??$get_backend_info@Uversion@device@info@_V1@sycl@@@kernel@_V1@sycl@@QEBA?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@XZ +??$get_backend_info@Uversion@device@info@_V1@sycl@@@platform@_V1@sycl@@QEBA?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@XZ +??$get_backend_info@Uversion@device@info@_V1@sycl@@@queue@_V1@sycl@@QEBA?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@XZ +??$get_backend_info@Uversion@platform@info@_V1@sycl@@@context@_V1@sycl@@QEBA?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@XZ +??$get_backend_info@Uversion@platform@info@_V1@sycl@@@device@_V1@sycl@@QEBA?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@XZ +??$get_backend_info@Uversion@platform@info@_V1@sycl@@@event@_V1@sycl@@QEBA?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@XZ +??$get_backend_info@Uversion@platform@info@_V1@sycl@@@kernel@_V1@sycl@@QEBA?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@XZ +??$get_backend_info@Uversion@platform@info@_V1@sycl@@@platform@_V1@sycl@@QEBA?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@XZ +??$get_backend_info@Uversion@platform@info@_V1@sycl@@@queue@_V1@sycl@@QEBA?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@XZ ??$get_info@U?$max_work_groups@$00@device@info@experimental@oneapi@ext@_V1@sycl@@@device@_V1@sycl@@QEBA?AV?$id@$00@12@XZ ??$get_info@U?$max_work_groups@$00@device@info@experimental@oneapi@ext@_V1@sycl@@@device_impl@detail@_V1@sycl@@QEBA?AV?$id@$00@23@XZ ??$get_info@U?$max_work_groups@$01@device@info@experimental@oneapi@ext@_V1@sycl@@@device@_V1@sycl@@QEBA?AV?$id@$01@12@XZ