Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
4 changes: 4 additions & 0 deletions sycl/doc/syclcompat/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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<sycl::aspect> &props);
} // syclcompat
```

Expand Down
87 changes: 46 additions & 41 deletions sycl/include/syclcompat/device.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -613,47 +613,7 @@ Use 64 bits as memory_bus_width default value."
/// sycl::aspect.
void has_capability_or_fail(
const std::initializer_list<sycl::aspect> &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<sycl::info::device::name>() +
"' device");
break;
case sycl::aspect::fp16:
throw sycl::exception(sycl::make_error_code(sycl::errc::runtime),
"[SYCLcompat] 'half' is not supported in '" +
get_info<sycl::info::device::name>() +
"' 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 <sycl/info/aspects.def>
#include <sycl/info/aspects_deprecated.def>
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<sycl::info::device::name>() +
"' device");
}
break;
}
::syclcompat::has_capability_or_fail(*this, props);
}

private:
Expand Down Expand Up @@ -959,4 +919,49 @@ static inline unsigned int get_device_id(const sycl::device &dev) {
static inline unsigned int device_count() {
return detail::dev_mgr::instance().device_count();
}

static inline void
has_capability_or_fail(const sycl::device &dev,
const std::initializer_list<sycl::aspect> &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<sycl::info::device::name>() +
"' 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<sycl::info::device::name>() +
"' 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 <sycl/info/aspects.def>
#include <sycl/info/aspects_deprecated.def>
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<sycl::info::device::name>() + "' device");
}
break;
}
}
} // namespace syclcompat
Loading