diff --git a/DataFormats/Portable/interface/PortableCollection.h b/DataFormats/Portable/interface/PortableCollection.h index 3f69ffdd95491..abfffff6ed1d2 100644 --- a/DataFormats/Portable/interface/PortableCollection.h +++ b/DataFormats/Portable/interface/PortableCollection.h @@ -22,8 +22,18 @@ namespace traits { using CollectionType = PortableHostCollection; }; + // trait for a generic multi-SoA-based product template - class PortableMultiCollectionTrait; + struct PortableMultiCollectionTrait { + using CollectionType = PortableDeviceMultiCollection; + }; + + // specialise for host device + template + struct PortableMultiCollectionTrait { + using CollectionType = PortableHostMultiCollection; + }; + } // namespace traits // type alias for a generic SoA-based product diff --git a/DataFormats/Portable/interface/alpaka/PortableCollection.h b/DataFormats/Portable/interface/alpaka/PortableCollection.h index e7bd78e4c0023..8a081ea53e651 100644 --- a/DataFormats/Portable/interface/alpaka/PortableCollection.h +++ b/DataFormats/Portable/interface/alpaka/PortableCollection.h @@ -16,58 +16,21 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE { template using PortableCollection = ::PortableCollection; -} // namespace ALPAKA_ACCELERATOR_NAMESPACE - -namespace ALPAKA_ACCELERATOR_NAMESPACE { - -#if defined ALPAKA_ACC_CPU_B_SEQ_T_SEQ_ENABLED // Singleton case does not need to be aliased. A special template covers it. - + // // This aliasing is needed to work with ROOT serialization. Bare templates make dictionary compilation fail. template - using PortableCollection2 = ::PortableHostMultiCollection; + using PortableCollection2 = ::PortableMultiCollection; template - using PortableCollection3 = ::PortableHostMultiCollection; + using PortableCollection3 = ::PortableMultiCollection; template - using PortableCollection4 = ::PortableHostMultiCollection; + using PortableCollection4 = ::PortableMultiCollection; template - using PortableCollection5 = ::PortableHostMultiCollection; -#else - // Singleton case does not need to be aliased. A special template covers it. - - // This aliasing is needed to work with ROOT serialization. Bare templates make dictionary compilation fail. - template - using PortableCollection2 = ::PortableDeviceMultiCollection; - - template - using PortableCollection3 = ::PortableDeviceMultiCollection; - - template - using PortableCollection4 = ::PortableDeviceMultiCollection; - - template - using PortableCollection5 = ::PortableDeviceMultiCollection; -#endif // ALPAKA_ACC_CPU_B_SEQ_T_SEQ_ENABLED + using PortableCollection5 = ::PortableMultiCollection; } // namespace ALPAKA_ACCELERATOR_NAMESPACE -namespace traits { -// specialise the trait for the device provided by the ALPAKA_ACCELERATOR_NAMESPACE -#if defined ALPAKA_ACC_CPU_B_SEQ_T_SEQ_ENABLED - template - class PortableMultiCollectionTrait { - using CollectionType = ::PortableHostMultiCollection; - }; -#else - template - class PortableMultiCollectionTrait { - using CollectionType = ::PortableDeviceMultiCollection; - }; -#endif - -} // namespace traits - -#endif // DataFormats_Portable_interface_alpaka_PortableCollection_h \ No newline at end of file +#endif // DataFormats_Portable_interface_alpaka_PortableCollection_h diff --git a/DataFormats/Portable/test/BuildFile.xml b/DataFormats/Portable/test/BuildFile.xml index ef2f6603f62cc..25a83ba4eebe0 100644 --- a/DataFormats/Portable/test/BuildFile.xml +++ b/DataFormats/Portable/test/BuildFile.xml @@ -1,4 +1,4 @@ - + diff --git a/DataFormats/Portable/test/portableCollectionOnHost.cc b/DataFormats/Portable/test/test_catch2_portableCollectionOnHost.cc similarity index 100% rename from DataFormats/Portable/test/portableCollectionOnHost.cc rename to DataFormats/Portable/test/test_catch2_portableCollectionOnHost.cc diff --git a/DataFormats/Portable/test/test_catch2_portableMultiCollectionOnHost.cc b/DataFormats/Portable/test/test_catch2_portableMultiCollectionOnHost.cc new file mode 100644 index 0000000000000..90192eb9e2bd5 --- /dev/null +++ b/DataFormats/Portable/test/test_catch2_portableMultiCollectionOnHost.cc @@ -0,0 +1,29 @@ +#include + +#include "DataFormats/Portable/interface/PortableCollection.h" +#include "DataFormats/Portable/interface/PortableHostCollection.h" +#include "DataFormats/SoATemplate/interface/SoACommon.h" +#include "DataFormats/SoATemplate/interface/SoALayout.h" +#include "DataFormats/SoATemplate/interface/SoAView.h" + +namespace { + GENERATE_SOA_LAYOUT(TestLayout1, SOA_COLUMN(double, x), SOA_COLUMN(int32_t, id)) + GENERATE_SOA_LAYOUT(TestLayout2, SOA_COLUMN(float, y), SOA_COLUMN(int32_t, z)) + + using TestSoA1 = TestLayout1<>; + using TestSoA2 = TestLayout2<>; + + constexpr auto s_tag = "[PortableMultiCollection]"; +} // namespace + +// This test is currently mostly about the code compiling +TEST_CASE("Use of PortableMultiCollection on host code", s_tag) { + std::array const sizes{{10, 5}}; + + PortableMultiCollection coll(sizes, cms::alpakatools::host()); + + SECTION("Tests") { REQUIRE(coll.sizes() == sizes); } + + static_assert(std::is_same_v, + PortableHostMultiCollection>); +} diff --git a/DataFormats/Portable/test/portableObjectOnHost.cc b/DataFormats/Portable/test/test_catch2_portableObjectOnHost.cc similarity index 100% rename from DataFormats/Portable/test/portableObjectOnHost.cc rename to DataFormats/Portable/test/test_catch2_portableObjectOnHost.cc