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

[UR] Check for if handle when type is complete #784

Closed
wants to merge 1 commit into from
Closed
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
18 changes: 11 additions & 7 deletions scripts/templates/params.hpp.mako
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,16 @@ def findMemberType(_item):
</%def>

namespace ${x}_params {
template <typename T> struct is_handle : std::false_type {};
%for spec in specs:
%for obj in spec['objects']:
%if re.match(r"handle", obj['type']):
template <> struct is_handle<${th.make_type_name(n, tags, obj)}> : std::true_type {};
%endif
%endfor
%endfor
template <typename T>
inline constexpr bool is_handle_v = is_handle<T>::value;
template <typename T> inline void serializePtr(std::ostream &os, T *ptr);
template <typename T> inline void serializeFlag(std::ostream &os, uint32_t flag);
template <typename T> inline void serializeTagged(std::ostream &os, const void *ptr, T value, size_t size);
Expand Down Expand Up @@ -351,12 +361,6 @@ inline std::ostream &operator<<(std::ostream &os, const struct ${th.make_pfncb_p
%endfor

namespace ${x}_params {
## This is needed to avoid dereferencing forward declared handles
// https://devblogs.microsoft.com/oldnewthing/20190710-00/?p=102678
template<typename, typename = void>
constexpr bool is_type_complete_v = false;
template<typename T>
constexpr bool is_type_complete_v<T, std::void_t<decltype(sizeof(T))>> = true;

template <typename T> inline void serializePtr(std::ostream &os, T *ptr) {
if (ptr == nullptr) {
Expand All @@ -365,7 +369,7 @@ template <typename T> inline void serializePtr(std::ostream &os, T *ptr) {
os << (void *)(ptr) << " (";
serializePtr(os, *ptr);
os << ")";
} else if constexpr (std::is_void_v<T> || !is_type_complete_v<T>) {
} else if constexpr (std::is_void_v<T> || is_handle_v<T *>) {
os << (void *)ptr;
} else if constexpr (std::is_same_v<std::remove_cv_t< T >, char>) {
os << (void *)(ptr) << " (";
Expand Down
29 changes: 24 additions & 5 deletions source/common/ur_params.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,29 @@
#include <ostream>

namespace ur_params {
template <typename T> struct is_handle : std::false_type {};
template <> struct is_handle<ur_loader_config_handle_t> : std::true_type {};
template <> struct is_handle<ur_adapter_handle_t> : std::true_type {};
template <> struct is_handle<ur_platform_handle_t> : std::true_type {};
template <> struct is_handle<ur_device_handle_t> : std::true_type {};
template <> struct is_handle<ur_context_handle_t> : std::true_type {};
template <> struct is_handle<ur_event_handle_t> : std::true_type {};
template <> struct is_handle<ur_program_handle_t> : std::true_type {};
template <> struct is_handle<ur_kernel_handle_t> : std::true_type {};
template <> struct is_handle<ur_queue_handle_t> : std::true_type {};
template <> struct is_handle<ur_native_handle_t> : std::true_type {};
template <> struct is_handle<ur_sampler_handle_t> : std::true_type {};
template <> struct is_handle<ur_mem_handle_t> : std::true_type {};
template <> struct is_handle<ur_physical_mem_handle_t> : std::true_type {};
template <> struct is_handle<ur_usm_pool_handle_t> : std::true_type {};
template <> struct is_handle<ur_exp_image_handle_t> : std::true_type {};
template <> struct is_handle<ur_exp_image_mem_handle_t> : std::true_type {};
template <> struct is_handle<ur_exp_interop_mem_handle_t> : std::true_type {};
template <>
struct is_handle<ur_exp_interop_semaphore_handle_t> : std::true_type {};
template <>
struct is_handle<ur_exp_command_buffer_handle_t> : std::true_type {};
template <typename T> inline constexpr bool is_handle_v = is_handle<T>::value;
template <typename T> inline void serializePtr(std::ostream &os, T *ptr);
template <typename T>
inline void serializeFlag(std::ostream &os, uint32_t flag);
Expand Down Expand Up @@ -15129,10 +15152,6 @@ operator<<(std::ostream &os,
}

namespace ur_params {
// https://devblogs.microsoft.com/oldnewthing/20190710-00/?p=102678
template <typename, typename = void> constexpr bool is_type_complete_v = false;
template <typename T>
constexpr bool is_type_complete_v<T, std::void_t<decltype(sizeof(T))>> = true;

template <typename T> inline void serializePtr(std::ostream &os, T *ptr) {
if (ptr == nullptr) {
Expand All @@ -15141,7 +15160,7 @@ template <typename T> inline void serializePtr(std::ostream &os, T *ptr) {
os << (void *)(ptr) << " (";
serializePtr(os, *ptr);
os << ")";
} else if constexpr (std::is_void_v<T> || !is_type_complete_v<T>) {
} else if constexpr (std::is_void_v<T> || is_handle_v<T *>) {
os << (void *)ptr;
} else if constexpr (std::is_same_v<std::remove_cv_t<T>, char>) {
os << (void *)(ptr) << " (";
Expand Down
Loading