/
githubmirror
/
cmssw
Обзор
Документация
Войти
/
githubmirror
/
cmssw
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
DataFormats/Portable/interface/PortableObject.h
60 строк
2 KB
markus
Refactor of the PortableCollections
29 янв 2026, 12:11
29 янв 2026, 12:11
75c03aa
Код
Авторство
О чём код?
#ifndef DataFormats_Portable_interface_PortableObject_h #define DataFormats_Portable_interface_PortableObject_h #include <type_traits> #include <alpaka/alpaka.hpp> #include "DataFormats/Portable/interface/PortableDeviceObject.h" #include "DataFormats/Portable/interface/PortableHostObject.h" #include "HeterogeneousCore/AlpakaInterface/interface/CopyToDevice.h" #include "HeterogeneousCore/AlpakaInterface/interface/CopyToHost.h" #include "HeterogeneousCore/AlpakaInterface/interface/concepts.h" namespace traits { // trait for a generic struct-based product template <typename TDev, typename T, typename = std::enable_if_t<alpaka::isDevice<TDev>>> struct PortableObjectTrait { using ProductType = PortableDeviceObject<TDev, T>; }; // specialise for host device template <typename T> struct PortableObjectTrait<alpaka_common::DevHost, T> { using ProductType = PortableHostObject<T>; }; } // namespace traits // type alias for a generic struct-based product template <typename TDev, typename T, typename = std::enable_if_t<alpaka::isDevice<TDev>>> using PortableObject = typename traits::PortableObjectTrait<TDev, T>::ProductType; // define how to copy PortableObject between host and device namespace cms::alpakatools { template <typename TDevice, typename TProduct> requires alpaka::isDevice<TDevice> struct CopyToHost<PortableDeviceObject<TDevice, TProduct>> { template <typename TQueue> requires alpaka::isQueue<TQueue> static auto copyAsync(TQueue& queue, PortableDeviceObject<TDevice, TProduct> const& srcData) { PortableHostObject<TProduct> dstData(queue); alpaka::memcpy(queue, dstData.buffer(), srcData.buffer()); return dstData; } }; template <typename TProduct> struct CopyToDevice<PortableHostObject<TProduct>> { template <cms::alpakatools::NonCPUQueue TQueue> static auto copyAsync(TQueue& queue, PortableHostObject<TProduct> const& srcData) { using TDevice = typename alpaka::trait::DevType<TQueue>::type; PortableDeviceObject<TDevice, TProduct> dstData(queue); alpaka::memcpy(queue, dstData.buffer(), srcData.buffer()); return dstData; } }; } // namespace cms::alpakatools #endif // DataFormats_Portable_interface_PortableObject_h