Skip to content

Commit

Permalink
Move ASSERT_DEVICE_MATCHES_HOST_COLLECTION to a separate file
Browse files Browse the repository at this point in the history
  • Loading branch information
fwyzard committed Oct 17, 2023
1 parent 963c011 commit f0cc419
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 8 deletions.
12 changes: 4 additions & 8 deletions DataFormats/Portable/interface/alpaka/PortableCollection.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@
#include "HeterogeneousCore/AlpakaInterface/interface/CopyToDevice.h"
#include "HeterogeneousCore/AlpakaInterface/interface/CopyToHost.h"

// This header is not used by PortableCollection, but is included here to automatically
// provide its content to users of ALPAKA_ACCELERATOR_NAMESPACE::PortableCollection.
#include "HeterogeneousCore/AlpakaInterface/interface/AssertDeviceMatchesHostCollection.h"

namespace ALPAKA_ACCELERATOR_NAMESPACE {

#if defined ALPAKA_ACC_CPU_B_SEQ_T_SEQ_ENABLED
Expand All @@ -21,20 +25,12 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE {
template <typename T>
using PortableCollection = ::PortableHostCollection<T>;

// check that the portable device collection for the host device is the same as the portable host collection
#define ASSERT_DEVICE_MATCHES_HOST_COLLECTION(DEVICE_COLLECTION, HOST_COLLECTION) \
static_assert(std::is_same_v<alpaka_serial_sync::DEVICE_COLLECTION, HOST_COLLECTION>, \
"The device collection for the host device and the host collection must be the same type!");

#else

// generic SoA-based product in device memory
template <typename T>
using PortableCollection = ::PortableDeviceCollection<T, Device>;

// the portable device collections for the non-host devices do not require any checks
#define ASSERT_DEVICE_MATCHES_HOST_COLLECTION(DEVICE_COLLECTION, HOST_COLLECTION)

#endif // ALPAKA_ACC_CPU_B_SEQ_T_SEQ_ENABLED

} // namespace ALPAKA_ACCELERATOR_NAMESPACE
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#ifndef HeterogeneousCore_AlpakaInterface_interface_AssertDeviceMatchesHostCollection_h
#define HeterogeneousCore_AlpakaInterface_interface_AssertDeviceMatchesHostCollection_h

#include <type_traits>

#include "HeterogeneousCore/AlpakaInterface/interface/config.h"

#if defined ALPAKA_ACC_CPU_B_SEQ_T_SEQ_ENABLED

// check that the portable device collection for the host device is the same as the portable host collection
#define ASSERT_DEVICE_MATCHES_HOST_COLLECTION(DEVICE_COLLECTION, HOST_COLLECTION) \
static_assert(std::is_same_v<alpaka_serial_sync::DEVICE_COLLECTION, HOST_COLLECTION>, \
"The device collection for the host device and the host collection must be the same type!");

#else

// the portable device collections for the non-host devices do not require any checks
#define ASSERT_DEVICE_MATCHES_HOST_COLLECTION(DEVICE_COLLECTION, HOST_COLLECTION)

#endif // ALPAKA_ACC_CPU_B_SEQ_T_SEQ_ENABLED

#endif // HeterogeneousCore_AlpakaInterface_interface_AssertDeviceMatchesHostCollection_h

0 comments on commit f0cc419

Please sign in to comment.