CMS 3D CMS Logo

ESDeviceProduct.h
Go to the documentation of this file.
1 #ifndef HeterogeneousCore_AlpakaCore_interface_alpaka_ESDeviceProduct_h
2 #define HeterogeneousCore_AlpakaCore_interface_alpaka_ESDeviceProduct_h
3 
4 #include <memory>
5 #include <optional>
6 #include <vector>
7 
9 
19  template <typename T>
21  public:
22  virtual ~ESDeviceProduct() {}
23 
24  T const& get(Device const& dev) const { return *cache_[alpaka::getNativeHandle(dev)]; }
25 
26  protected:
27  explicit ESDeviceProduct(size_t ndevices) : cache_(ndevices, nullptr) {}
28 
29  void setCache(size_t idev, T const* data) { cache_[idev] = data; }
30 
31  private:
32  // trading memory to avoid virtual function
33  std::vector<T const*> cache_;
34  };
35 
36  namespace detail {
44  template <typename TProduct, typename TStorage>
45  class ESDeviceProductWithStorage : public ESDeviceProduct<TProduct> {
47 
48  public:
49  explicit ESDeviceProductWithStorage(size_t ndevices) : Base(ndevices), data_(ndevices) {}
50 
51  void insert(Device const& dev, TStorage data) {
52  auto const idev = alpaka::getNativeHandle(dev);
53  data_[idev] = std::move(data);
54  this->setCache(idev, &*data_[idev]);
55  }
56 
57  private:
58  std::vector<TStorage> data_;
59  };
60  } // namespace detail
61 } // namespace ALPAKA_ACCELERATOR_NAMESPACE
62 
63 #endif
void setCache(size_t idev, T const *data)
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:80
long double T
def move(src, dest)
Definition: eostools.py:511