diff --git a/sycl/doc/syclcompat/README.md b/sycl/doc/syclcompat/README.md index df8d453a41d57..edaf3e48710b8 100644 --- a/sycl/doc/syclcompat/README.md +++ b/sycl/doc/syclcompat/README.md @@ -1048,6 +1048,10 @@ static inline unsigned int get_device_id(const sycl::device &dev); // Util function to get the number of available devices static inline unsigned int device_count(); +// Util function to check whether a device supports some kinds of sycl::aspect. +static inline void +has_capability_or_fail(const sycl::device &dev, + const std::initializer_list &props); } // syclcompat ``` diff --git a/sycl/include/syclcompat/device.hpp b/sycl/include/syclcompat/device.hpp index 4e227a635c44e..77d67c4097245 100644 --- a/sycl/include/syclcompat/device.hpp +++ b/sycl/include/syclcompat/device.hpp @@ -334,6 +334,51 @@ static int get_minor_version(const sycl::device &dev) { return minor; } +static inline void +has_capability_or_fail(const sycl::device &dev, + const std::initializer_list &props) { + for (const auto &it : props) { + if (dev.has(it)) + continue; + switch (it) { + case sycl::aspect::fp64: + throw sycl::exception(sycl::make_error_code(sycl::errc::runtime), + "[SYCLcompat] 'double' is not supported in '" + + dev.get_info() + + "' device"); + break; + case sycl::aspect::fp16: + throw sycl::exception(sycl::make_error_code(sycl::errc::runtime), + "[SYCLcompat] 'half' is not supported in '" + + dev.get_info() + + "' device"); + break; + default: +#define __SYCL_ASPECT(ASPECT, ID) \ + case sycl::aspect::ASPECT: \ + return #ASPECT; +#define __SYCL_ASPECT_DEPRECATED(ASPECT, ID, MESSAGE) __SYCL_ASPECT(ASPECT, ID) +#define __SYCL_ASPECT_DEPRECATED_ALIAS(ASPECT, ID, MESSAGE) + auto getAspectNameStr = [](sycl::aspect AspectNum) -> std::string { + switch (AspectNum) { +#include +#include + default: + return "unknown aspect"; + } + }; +#undef __SYCL_ASPECT_DEPRECATED_ALIAS +#undef __SYCL_ASPECT_DEPRECATED +#undef __SYCL_ASPECT + throw sycl::exception( + sycl::make_error_code(sycl::errc::runtime), + "[SYCLcompat] '" + getAspectNameStr(it) + "' is not supported in '" + + dev.get_info() + "' device"); + } + break; + } +} + /// device extension class device_ext : public sycl::device { public: @@ -613,47 +658,7 @@ Use 64 bits as memory_bus_width default value." /// sycl::aspect. void has_capability_or_fail( const std::initializer_list &props) const { - for (const auto &it : props) { - if (has(it)) - continue; - switch (it) { - case sycl::aspect::fp64: - throw sycl::exception(sycl::make_error_code(sycl::errc::runtime), - "[SYCLcompat] 'double' is not supported in '" + - get_info() + - "' device"); - break; - case sycl::aspect::fp16: - throw sycl::exception(sycl::make_error_code(sycl::errc::runtime), - "[SYCLcompat] 'half' is not supported in '" + - get_info() + - "' device"); - break; - default: -#define __SYCL_ASPECT(ASPECT, ID) \ - case sycl::aspect::ASPECT: \ - return #ASPECT; -#define __SYCL_ASPECT_DEPRECATED(ASPECT, ID, MESSAGE) __SYCL_ASPECT(ASPECT, ID) -#define __SYCL_ASPECT_DEPRECATED_ALIAS(ASPECT, ID, MESSAGE) - auto getAspectNameStr = [](sycl::aspect AspectNum) -> std::string { - switch (AspectNum) { -#include -#include - default: - return "unknown aspect"; - } - }; -#undef __SYCL_ASPECT_DEPRECATED_ALIAS -#undef __SYCL_ASPECT_DEPRECATED -#undef __SYCL_ASPECT - throw sycl::exception(sycl::make_error_code(sycl::errc::runtime), - "[SYCLcompat] '" + getAspectNameStr(it) + - "' is not supported in '" + - get_info() + - "' device"); - } - break; - } + ::syclcompat::has_capability_or_fail(*this, props); } private: