File indexing completed on 2024-04-06 12:15:39
0001 #ifndef HeterogeneousCore_AlpakaCore_interface_alpaka_ESDeviceProduct_h
0002 #define HeterogeneousCore_AlpakaCore_interface_alpaka_ESDeviceProduct_h
0003
0004 #include <memory>
0005 #include <optional>
0006 #include <vector>
0007
0008 #include "HeterogeneousCore/AlpakaInterface/interface/config.h"
0009
0010 namespace ALPAKA_ACCELERATOR_NAMESPACE {
0011
0012
0013
0014
0015
0016
0017
0018
0019 template <typename T>
0020 class ESDeviceProduct {
0021 public:
0022 virtual ~ESDeviceProduct() {}
0023
0024 T const& get(Device const& dev) const { return *cache_[alpaka::getNativeHandle(dev)]; }
0025
0026 protected:
0027 explicit ESDeviceProduct(size_t ndevices) : cache_(ndevices, nullptr) {}
0028
0029 void setCache(size_t idev, T const* data) { cache_[idev] = data; }
0030
0031 private:
0032
0033 std::vector<T const*> cache_;
0034 };
0035
0036 namespace detail {
0037
0038
0039
0040
0041
0042
0043
0044 template <typename TProduct, typename TStorage>
0045 class ESDeviceProductWithStorage : public ESDeviceProduct<TProduct> {
0046 using Base = ESDeviceProduct<TProduct>;
0047
0048 public:
0049 explicit ESDeviceProductWithStorage(size_t ndevices) : Base(ndevices), data_(ndevices) {}
0050
0051 void insert(Device const& dev, TStorage data) {
0052 auto const idev = alpaka::getNativeHandle(dev);
0053 data_[idev] = std::move(data);
0054 this->setCache(idev, &*data_[idev]);
0055 }
0056
0057 private:
0058 std::vector<TStorage> data_;
0059 };
0060 }
0061 }
0062
0063 #endif