Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 12:52:49

0001 #ifndef CUDADataFormats_Common_Product_h
0002 #define CUDADataFormats_Common_Product_h
0003 
0004 #include <memory>
0005 
0006 #include "CUDADataFormats/Common/interface/ProductBase.h"
0007 
0008 namespace edm {
0009   template <typename T>
0010   class Wrapper;
0011 }
0012 
0013 namespace cms {
0014   namespace cuda {
0015     namespace impl {
0016       class ScopedContextGetterBase;
0017     }
0018 
0019     /**
0020      * The purpose of this class is to wrap CUDA data to edm::Event in a
0021      * way which forces correct use of various utilities.
0022      *
0023      * The non-default construction has to be done with cms::cuda::ScopedContext
0024      * (in order to properly register the CUDA event).
0025      *
0026      * The default constructor is needed only for the ROOT dictionary generation.
0027      *
0028      * The CUDA event is in practice needed only for stream-stream
0029      * synchronization, but someone with long-enough lifetime has to own
0030      * it. Here is a somewhat natural place. If overhead is too much, we
0031      * can use them only where synchronization between streams is needed.
0032      */
0033     template <typename T>
0034     class Product : public ProductBase {
0035     public:
0036       Product() = default;  // Needed only for ROOT dictionary generation
0037 
0038       Product(const Product&) = delete;
0039       Product& operator=(const Product&) = delete;
0040       Product(Product&&) = default;
0041       Product& operator=(Product&&) = default;
0042 
0043     private:
0044       friend class impl::ScopedContextGetterBase;
0045       friend class ScopedContextProduce;
0046       friend class edm::Wrapper<Product<T>>;
0047 
0048       explicit Product(int device, SharedStreamPtr stream, SharedEventPtr event, T data)
0049           : ProductBase(device, std::move(stream), std::move(event)), data_(std::move(data)) {}
0050 
0051       template <typename... Args>
0052       explicit Product(int device, SharedStreamPtr stream, SharedEventPtr event, Args&&... args)
0053           : ProductBase(device, std::move(stream), std::move(event)), data_(std::forward<Args>(args)...) {}
0054 
0055       T data_;  //!
0056     };
0057   }  // namespace cuda
0058 }  // namespace cms
0059 
0060 #endif