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

Throw sycl::exception on invalid call to get_property() #31

Merged
merged 1 commit into from
Dec 28, 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
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
Loading