|
| 1 | +#ifndef DataFormats_PortableTest_interface_TestProductWithPtr_h |
| 2 | +#define DataFormats_PortableTest_interface_TestProductWithPtr_h |
| 3 | + |
| 4 | +#include "DataFormats/Portable/interface/PortableCollection.h" |
| 5 | +#include "DataFormats/SoATemplate/interface/SoACommon.h" |
| 6 | +#include "DataFormats/SoATemplate/interface/SoALayout.h" |
| 7 | +#include "DataFormats/SoATemplate/interface/SoAView.h" |
| 8 | +#include "HeterogeneousCore/AlpakaInterface/interface/CopyToHost.h" |
| 9 | +#include "HeterogeneousCore/AlpakaInterface/interface/CopyToDevice.h" |
| 10 | + |
| 11 | +#include <alpaka/alpaka.hpp> |
| 12 | + |
| 13 | +/** |
| 14 | + * This data product is part of a test for CopyToHost::postCopy() |
| 15 | + * (i.e. updating a data product after the device-to-host copy). For |
| 16 | + * any practical purposes the indirection to 'buffer' array via the |
| 17 | + * 'ptr' pointer scalar is completely unnecessary. Do not take this |
| 18 | + * case as an example for good design of a data product. |
| 19 | + */ |
| 20 | +namespace portabletest { |
| 21 | + GENERATE_SOA_LAYOUT(TestSoALayoutWithPtr, SOA_COLUMN(int, buffer), SOA_SCALAR(int*, ptr)); |
| 22 | + using TestSoAWithPtr = TestSoALayoutWithPtr<>; |
| 23 | + |
| 24 | + template <typename TDev> |
| 25 | + using TestProductWithPtr = PortableCollection<TestSoAWithPtr, TDev>; |
| 26 | + |
| 27 | + ALPAKA_FN_HOST_ACC ALPAKA_FN_INLINE void setPtrInTestProductWithPtr(TestSoAWithPtr::View view) { |
| 28 | + view.ptr() = &view.buffer(0); |
| 29 | + } |
| 30 | +} // namespace portabletest |
| 31 | + |
| 32 | +namespace cms::alpakatools { |
| 33 | + template <typename TDev> |
| 34 | + struct CopyToHost<PortableDeviceCollection<portabletest::TestSoAWithPtr, TDev>> { |
| 35 | + template <typename TQueue> |
| 36 | + static auto copyAsync(TQueue& queue, PortableDeviceCollection<portabletest::TestSoAWithPtr, TDev> const& src) { |
| 37 | + PortableHostCollection<portabletest::TestSoAWithPtr> dst(src->metadata().size(), queue); |
| 38 | + alpaka::memcpy(queue, dst.buffer(), src.buffer()); |
| 39 | + return dst; |
| 40 | + } |
| 41 | + |
| 42 | + static void postCopy(PortableHostCollection<portabletest::TestSoAWithPtr>& dst) { |
| 43 | + portabletest::setPtrInTestProductWithPtr(dst.view()); |
| 44 | + } |
| 45 | + }; |
| 46 | +} // namespace cms::alpakatools |
| 47 | + |
| 48 | +#endif |
0 commit comments