From 2cf935ed6070b8a34566acb29567cac550126682 Mon Sep 17 00:00:00 2001 From: Andrei Elovikov Date: Fri, 15 Nov 2024 14:43:21 -0800 Subject: [PATCH 1/2] [NFCI][SYCL] Remove most uses of `ContainsProperty` First, `properties` itself has an interface that does exactly that. Second, this trait uses `std::tuple` which is relatively expensive to instantiate and that happens *on top* of the normal `properties` instantation that doesn't use `std::tuple` anymore. Remaining uses are related to `ConflictingProperties` which is ugly enough to be addressed in a separate PR. --- .../fpga_annotated_properties.hpp | 25 ++++++------- .../annotated_arg/annotated_arg.hpp | 8 ++--- .../annotated_ptr/annotated_ptr.hpp | 32 ++++++++--------- .../annotated_ptr_properties.hpp | 36 ++++++++++--------- .../experimental/annotated_usm/alloc_util.hpp | 8 ++--- 5 files changed, 51 insertions(+), 58 deletions(-) diff --git a/sycl/include/sycl/ext/intel/experimental/fpga_annotated_properties.hpp b/sycl/include/sycl/ext/intel/experimental/fpga_annotated_properties.hpp index ea9f531c764b9..0b12e063ebde2 100644 --- a/sycl/include/sycl/ext/intel/experimental/fpga_annotated_properties.hpp +++ b/sycl/include/sycl/ext/intel/experimental/fpga_annotated_properties.hpp @@ -319,28 +319,25 @@ struct propagateToPtrAnnotation : std::true_type {}; //===----------------------------------------------------------------------===// // namespace detail { -template struct checkValidFPGAPropertySet { - using list = std::tuple; - static constexpr bool has_BufferLocation = - ContainsProperty::value; +template struct checkValidFPGAPropertySet { + template + static constexpr bool has_one_of = + ((property_list_t::template has_property() || ...)); + + static constexpr bool has_BufferLocation = has_one_of; static constexpr bool has_InterfaceConfig = - ContainsProperty::value || - ContainsProperty::value || - ContainsProperty::value || - ContainsProperty::value || - ContainsProperty::value || - ContainsProperty::value; + has_one_of; static constexpr bool value = !(!has_BufferLocation && has_InterfaceConfig); }; -template struct checkHasConduitAndRegisterMap { - using list = std::tuple; +template struct checkHasConduitAndRegisterMap { static constexpr bool has_Conduit = - ContainsProperty::value; + property_list_t::template has_property(); static constexpr bool has_RegisterMap = - ContainsProperty::value; + property_list_t::template has_property(); static constexpr bool value = !(has_Conduit && has_RegisterMap); }; } // namespace detail diff --git a/sycl/include/sycl/ext/oneapi/experimental/annotated_arg/annotated_arg.hpp b/sycl/include/sycl/ext/oneapi/experimental/annotated_arg/annotated_arg.hpp index 91baca3e14e3f..851497b7ead3b 100644 --- a/sycl/include/sycl/ext/oneapi/experimental/annotated_arg/annotated_arg.hpp +++ b/sycl/include/sycl/ext/oneapi/experimental/annotated_arg/annotated_arg.hpp @@ -214,13 +214,13 @@ __SYCL_TYPE(annotated_arg) annotated_arg> { "The property list contains invalid property."); // check the set if FPGA specificed properties are used static constexpr bool hasValidFPGAProperties = - detail::checkValidFPGAPropertySet::value; + detail::checkValidFPGAPropertySet::value; static_assert(hasValidFPGAProperties, "FPGA Interface properties (i.e. awidth, dwidth, etc.) " "can only be set with BufferLocation together."); // check if conduit and register_map properties are specified together static constexpr bool hasConduitAndRegisterMapProperties = - detail::checkHasConduitAndRegisterMap::value; + detail::checkHasConduitAndRegisterMap::value; static_assert(hasConduitAndRegisterMapProperties, "The properties conduit and register_map cannot be " "specified at the same time."); @@ -447,13 +447,13 @@ __SYCL_TYPE(annotated_arg) annotated_arg> { "The property list contains invalid property."); // check the set if FPGA specificed properties are used static constexpr bool hasValidFPGAProperties = - detail::checkValidFPGAPropertySet::value; + detail::checkValidFPGAPropertySet::value; static_assert(hasValidFPGAProperties, "FPGA Interface properties (i.e. awidth, dwidth, etc.) " "can only be set with BufferLocation together."); // check if conduit and register_map properties are specified together static constexpr bool hasConduitAndRegisterMapProperties = - detail::checkHasConduitAndRegisterMap::value; + detail::checkHasConduitAndRegisterMap::value; static_assert(hasConduitAndRegisterMapProperties, "The properties conduit and register_map cannot be " "specified at the same time."); diff --git a/sycl/include/sycl/ext/oneapi/experimental/annotated_ptr/annotated_ptr.hpp b/sycl/include/sycl/ext/oneapi/experimental/annotated_ptr/annotated_ptr.hpp index c9a59a8d85c0c..13db0b377aecc 100644 --- a/sycl/include/sycl/ext/oneapi/experimental/annotated_ptr/annotated_ptr.hpp +++ b/sycl/include/sycl/ext/oneapi/experimental/annotated_ptr/annotated_ptr.hpp @@ -50,10 +50,6 @@ template constexpr bool is_ann_ref_v = is_ann_ref_impl>::value; -template -using contains_alignment = - detail::ContainsProperty>; - // filter properties that are applied on annotations template using annotation_filter = decltype(filter_properties( @@ -392,38 +388,38 @@ __SYCL_TYPE(annotated_ptr) annotated_ptr> { // turned off for these operators to make sure the complete error notes are // printed // clang-format off - template ::value, + template (), class = std::enable_if_t> reference operator[](std::ptrdiff_t idx) const noexcept { return reference(m_Ptr + idx); } - template ::value, + template (), class = std::enable_if_t> auto operator[](std::ptrdiff_t idx) const noexcept -> decltype("operator[] is not available when alignment is specified!") = delete; - template ::value, + template (), class = std::enable_if_t> annotated_ptr operator+(size_t offset) const noexcept { return annotated_ptr(m_Ptr + offset); } - template ::value, + template (), class = std::enable_if_t> auto operator+(size_t offset) const noexcept -> decltype("operator+ is not available when alignment is specified!") = delete; - template ::value, + template (), class = std::enable_if_t> annotated_ptr &operator++() noexcept { m_Ptr += 1; return *this; } - template ::value, + template (), class = std::enable_if_t> auto operator++() noexcept -> decltype("operator++ is not available when alignment is specified!") = delete; - template ::value, + template (), class = std::enable_if_t> annotated_ptr operator++(int) noexcept { auto tmp = *this; @@ -431,22 +427,22 @@ __SYCL_TYPE(annotated_ptr) annotated_ptr> { return tmp; } - template ::value, + template (), class = std::enable_if_t> auto operator++(int) noexcept -> decltype("operator++ is not available when alignment is specified!") = delete; - template ::value, + template (), class = std::enable_if_t> annotated_ptr &operator--() noexcept { m_Ptr -= 1; return *this; } - template ::value, + template (), class = std::enable_if_t> auto operator--() noexcept -> decltype("operator-- is not available when alignment is specified!") = delete; - template ::value, + template (), class = std::enable_if_t> annotated_ptr operator--(int) noexcept { auto tmp = *this; @@ -454,7 +450,7 @@ __SYCL_TYPE(annotated_ptr) annotated_ptr> { return tmp; } - template ::value, + template (), class = std::enable_if_t> auto operator--(int) noexcept -> decltype("operator-- is not available when alignment is specified!") = delete; @@ -485,13 +481,13 @@ __SYCL_TYPE(annotated_ptr) annotated_ptr> { "The property list contains invalid property."); // check the set if FPGA specificed properties are used static constexpr bool hasValidFPGAProperties = - detail::checkValidFPGAPropertySet::value; + detail::checkValidFPGAPropertySet::value; static_assert(hasValidFPGAProperties, "FPGA Interface properties (i.e. awidth, dwidth, etc.) " "can only be set with BufferLocation together."); // check if conduit and register_map properties are specified together static constexpr bool hasConduitAndRegisterMapProperties = - detail::checkHasConduitAndRegisterMap::value; + detail::checkHasConduitAndRegisterMap::value; static_assert(hasConduitAndRegisterMapProperties, "The properties conduit and register_map cannot be " "specified at the same time."); diff --git a/sycl/include/sycl/ext/oneapi/experimental/annotated_ptr/annotated_ptr_properties.hpp b/sycl/include/sycl/ext/oneapi/experimental/annotated_ptr/annotated_ptr_properties.hpp index fcdd05f3a497e..55dfa02fef68f 100644 --- a/sycl/include/sycl/ext/oneapi/experimental/annotated_ptr/annotated_ptr_properties.hpp +++ b/sycl/include/sycl/ext/oneapi/experimental/annotated_ptr/annotated_ptr_properties.hpp @@ -55,24 +55,26 @@ struct PropertyMetaInfo> { static constexpr sycl::usm::alloc value = Kind; }; -template struct IsUsmKindDevice : std::false_type {}; -template -struct IsUsmKindDevice> - : detail::ContainsProperty, - std::tuple> {}; - -template struct IsUsmKindHost : std::false_type {}; -template -struct IsUsmKindHost> - : detail::ContainsProperty, - std::tuple> {}; - -template struct IsUsmKindShared : std::false_type {}; -template -struct IsUsmKindShared> - : detail::ContainsProperty, - std::tuple> {}; +template +inline constexpr bool is_usm_kind = []() constexpr { + if constexpr (PropertyListT::template has_property()) + return PropertyListT::template get_property() == + usm_kind; + else + return false; +}(); +template +struct IsUsmKindDevice + : std::bool_constant> { +}; +template +struct IsUsmKindHost + : std::bool_constant> {}; +template +struct IsUsmKindShared + : std::bool_constant> { +}; } // namespace detail } // namespace experimental diff --git a/sycl/include/sycl/ext/oneapi/experimental/annotated_usm/alloc_util.hpp b/sycl/include/sycl/ext/oneapi/experimental/annotated_usm/alloc_util.hpp index 6548f3d3c3673..cb8dc3bbb7376 100644 --- a/sycl/include/sycl/ext/oneapi/experimental/annotated_usm/alloc_util.hpp +++ b/sycl/include/sycl/ext/oneapi/experimental/annotated_usm/alloc_util.hpp @@ -32,11 +32,9 @@ using MergeUsmKind = decltype(properties{usm_kind})>; // Check if a property list contains the a certain property -template struct HasProperty {}; - -template -struct HasProperty> - : detail::ContainsProperty> {}; +template +struct HasProperty + : std::bool_constant()> {}; template using HasAlign = HasProperty; From b17682644227ebb77a0372e2f236ba9b29f0af14 Mon Sep 17 00:00:00 2001 From: Andrei Elovikov Date: Mon, 18 Nov 2024 07:26:15 -0800 Subject: [PATCH 2/2] Revert copy-paste error --- .../sycl/ext/intel/experimental/fpga_annotated_properties.hpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sycl/include/sycl/ext/intel/experimental/fpga_annotated_properties.hpp b/sycl/include/sycl/ext/intel/experimental/fpga_annotated_properties.hpp index 0b12e063ebde2..bbf55d469809a 100644 --- a/sycl/include/sycl/ext/intel/experimental/fpga_annotated_properties.hpp +++ b/sycl/include/sycl/ext/intel/experimental/fpga_annotated_properties.hpp @@ -327,8 +327,8 @@ template struct checkValidFPGAPropertySet { static constexpr bool has_BufferLocation = has_one_of; static constexpr bool has_InterfaceConfig = - has_one_of; + has_one_of; static constexpr bool value = !(!has_BufferLocation && has_InterfaceConfig); };