CMS 3D CMS Logo

DeviceProduct.h
Go to the documentation of this file.
1 #ifndef DataFormats_Common_interface_DeviceProduct_h
2 #define DataFormats_Common_interface_DeviceProduct_h
3 
4 #include <cassert>
5 #include <memory>
6 
7 namespace edm {
9  public:
10  DeviceProductBase() = default;
11  ~DeviceProductBase() = default;
12 
13  // TODO: in principle this function is an implementation detail
14  template <typename M>
15  M const& metadata() const {
16  // TODO: I believe the assertion could be removed safely after
17  // the data dependence and scheduling systems would guarantee
18  // that the an EDModule in a given execution space can access
19  // only to the EDProducts in a memory space compatible with the
20  // execution space.
21  //
22  // On the other hand, with Alpaka (likely with others) the
23  // getSynchronized() does additional checks so the added cost is
24  // probably not that much?
25  assert(typeid(M) == *metadataType_);
26  return *static_cast<M const*>(metadata_.get());
27  }
28 
29  protected:
30  template <typename M>
31  explicit DeviceProductBase(std::shared_ptr<M> metadata)
32  : metadata_(std::move(metadata)), metadataType_(&typeid(M)) {}
33 
34  private:
35  std::shared_ptr<void const> metadata_;
36  std::type_info const* metadataType_;
37  };
38 
45  template <typename T>
47  public:
48  DeviceProduct() = default;
49 
50  template <typename M, typename... Args>
51  explicit DeviceProduct(std::shared_ptr<M> metadata, Args&&... args)
52  : DeviceProductBase(std::move(metadata)), data_(std::forward<Args>(args)...) {}
53 
54  DeviceProduct(const DeviceProduct&) = delete;
55  DeviceProduct& operator=(const DeviceProduct&) = delete;
56  DeviceProduct(DeviceProduct&&) = default;
58 
65  template <typename M, typename... Args>
66  T const& getSynchronized(Args&&... args) const {
67  auto const& md = metadata<M>();
68  md.synchronize(std::forward<Args>(args)...);
69  return data_;
70  }
71 
72  private:
73  T data_;
74  };
75 } // namespace edm
76 #endif
std::shared_ptr< void const > metadata_
Definition: DeviceProduct.h:35
assert(be >=bs)
std::type_info const * metadataType_
Definition: DeviceProduct.h:36
M const & metadata() const
Definition: DeviceProduct.h:15
DeviceProduct(std::shared_ptr< M > metadata, Args &&... args)
Definition: DeviceProduct.h:51
DeviceProduct & operator=(const DeviceProduct &)=delete
HLT enums.
~DeviceProductBase()=default
T const & getSynchronized(Args &&... args) const
Definition: DeviceProduct.h:66
DeviceProduct()=default
long double T
DeviceProductBase(std::shared_ptr< M > metadata)
Definition: DeviceProduct.h:31
def move(src, dest)
Definition: eostools.py:511