Skip to content

Commit

Permalink
Simplify definitions of PortableMultiCollection<TDev, ...>, and allow…
Browse files Browse the repository at this point in the history
… it to be used outside of ALPAKA_ACCELERATOR_NAMESPACE

I.e. repeat cms-sw#43310 on PortableMultiCollection.
  • Loading branch information
makortel committed Feb 15, 2024
1 parent c4e1915 commit 9dc4cd5
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 45 deletions.
12 changes: 11 additions & 1 deletion DataFormats/Portable/interface/PortableCollection.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,18 @@ namespace traits {
using CollectionType = PortableHostCollection<T>;
};

// trait for a generic multi-SoA-based product
template <typename TDev, typename T0, typename... Args>
class PortableMultiCollectionTrait;
struct PortableMultiCollectionTrait {
using CollectionType = PortableDeviceMultiCollection<TDev, T0, Args...>;
};

// specialise for host device
template <typename T0, typename... Args>
struct PortableMultiCollectionTrait<alpaka_common::DevHost, T0, Args...> {
using CollectionType = PortableHostMultiCollection<T0, Args...>;
};

} // namespace traits

// type alias for a generic SoA-based product
Expand Down
49 changes: 6 additions & 43 deletions DataFormats/Portable/interface/alpaka/PortableCollection.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,58 +16,21 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE {
template <typename T>
using PortableCollection = ::PortableCollection<T, Device>;

} // 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 <typename T0, typename T1>
using PortableCollection2 = ::PortableHostMultiCollection<T0, T1>;
using PortableCollection2 = ::PortableMultiCollection<Device, T0, T1>;

template <typename T0, typename T1, typename T2>
using PortableCollection3 = ::PortableHostMultiCollection<T0, T1, T2>;
using PortableCollection3 = ::PortableMultiCollection<Device, T0, T1, T2>;

template <typename T0, typename T1, typename T2, typename T3>
using PortableCollection4 = ::PortableHostMultiCollection<T0, T1, T2, T3>;
using PortableCollection4 = ::PortableMultiCollection<Device, T0, T1, T2, T3>;

template <typename T0, typename T1, typename T2, typename T3, typename T4>
using PortableCollection5 = ::PortableHostMultiCollection<T0, T1, T2, T3, T4>;
#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 <typename T0, typename T1>
using PortableCollection2 = ::PortableDeviceMultiCollection<Device, T0, T1>;

template <typename T0, typename T1, typename T2>
using PortableCollection3 = ::PortableDeviceMultiCollection<Device, T0, T1, T2>;

template <typename T0, typename T1, typename T2, typename T3>
using PortableCollection4 = ::PortableDeviceMultiCollection<Device, T0, T1, T2, T3>;

template <typename T0, typename T1, typename T2, typename T3, typename T4>
using PortableCollection5 = ::PortableDeviceMultiCollection<Device, T0, T1, T2, T3, T4>;
#endif // ALPAKA_ACC_CPU_B_SEQ_T_SEQ_ENABLED
using PortableCollection5 = ::PortableMultiCollection<Device, T0, T1, T2, T3, T4>;

} // 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 <typename T0, typename... Args>
class PortableMultiCollectionTrait<ALPAKA_ACCELERATOR_NAMESPACE::Device, T0, Args...> {
using CollectionType = ::PortableHostMultiCollection<T0, Args...>;
};
#else
template <typename T0, typename... Args>
class PortableMultiCollectionTrait<ALPAKA_ACCELERATOR_NAMESPACE::Device, T0, Args...> {
using CollectionType = ::PortableDeviceMultiCollection<ALPAKA_ACCELERATOR_NAMESPACE::Device, T0, Args...>;
};
#endif

} // namespace traits

#endif // DataFormats_Portable_interface_alpaka_PortableCollection_h
#endif // DataFormats_Portable_interface_alpaka_PortableCollection_h
2 changes: 1 addition & 1 deletion DataFormats/Portable/test/BuildFile.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<bin name="TestDataFormatsPortableOnHost" file="test_catch2_main.cc,portableCollectionOnHost.cc,portableObjectOnHost.cc">
<bin name="TestDataFormatsPortableOnHost" file="test_catch2_*.cc">
<use name="DataFormats/Portable"/>
<use name="DataFormats/SoATemplate"/>
<use name="catch2"/>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#include <catch.hpp>

#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<T, TDev> on host code", s_tag) {
std::array<int, 2> const sizes{{10, 5}};

PortableMultiCollection<alpaka::DevCpu, TestSoA1, TestSoA2> coll(sizes, cms::alpakatools::host());

SECTION("Tests") { REQUIRE(coll.sizes() == sizes); }

static_assert(std::is_same_v<PortableMultiCollection<alpaka::DevCpu, TestSoA1, TestSoA2>,
PortableHostMultiCollection<TestSoA1, TestSoA2>>);
}

0 comments on commit 9dc4cd5

Please sign in to comment.