Skip to content

Commit

Permalink
Throw sycl::exception on invalid call to get_property()
Browse files Browse the repository at this point in the history
Spec requires us to throw errc::invalid, instead of triggering a
SimSYCL check as we do currently.
  • Loading branch information
fknorr committed Dec 28, 2024
1 parent cba990a commit f677706
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
9 changes: 6 additions & 3 deletions include/simsycl/sycl/property.hh
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@ namespace simsycl::detail {

class property_interface;

}
// outlined into check.cc to avoid cyclic include property.hh -> exception.hh -> context.hh -> property.hh
[[noreturn]] void throw_invalid_property();

} // namespace simsycl::detail

namespace simsycl::sycl {

Expand Down Expand Up @@ -46,7 +49,7 @@ class property_list {
Property get_property() const {
const auto iter = std::find_if(m_properties.begin(), m_properties.end(),
[](const std::any &prop) { return prop.type() == typeid(Property); });
SIMSYCL_CHECK(iter != m_properties.end());
if(iter == m_properties.end()) { detail::throw_invalid_property(); }
return std::any_cast<Property>(*iter);
}

Expand Down Expand Up @@ -101,7 +104,7 @@ class property_interface {
Property get_property() const {
const auto iter = std::find_if(m_properties.begin(), m_properties.end(),
[](const std::any &prop) { return prop.type() == typeid(Property); });
SIMSYCL_CHECK(iter != m_properties.end());
if(iter == m_properties.end()) { detail::throw_invalid_property(); }
return std::any_cast<Property>(*iter);
}

Expand Down
5 changes: 5 additions & 0 deletions src/simsycl/check.cc
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "simsycl/detail/check.hh"
#include "simsycl/sycl/exception.hh"
#include "simsycl/sycl/property.hh"

// TODO: use std::format/print once widely available
#include <cassert>
Expand Down Expand Up @@ -51,4 +52,8 @@ void check(bool condition, const char *cond_string, std::source_location locatio
}
}

void throw_invalid_property() {
throw simsycl::sycl::exception(sycl::errc::invalid, "object does not hold requested property");
}

} // namespace simsycl::detail

0 comments on commit f677706

Please sign in to comment.