LAMA
/home/brandes/workspace/LAMA/src/lama/cuda/CUDAStreamSyncToken.hpp
Go to the documentation of this file.
00001 
00033 #ifndef LAMA_CUDA_STREAM_SYNC_TOKEN_HPP_
00034 #define LAMA_CUDA_STREAM_SYNC_TOKEN_HPP_
00035 
00036 // boost
00037 #include <boost/shared_ptr.hpp>
00038 
00039 #include <list>
00040 #include <memory>
00041 
00042 #include <cuda.h>
00043 #if __GNUC__ >= 4 &&  __GNUC_MINOR__ > 6
00044 #pragma GCC diagnostic push
00045 #pragma GCC diagnostic ignored "-Wunused-parameter"
00046 #endif //__GNUC__ >= 4 &&  __GNUC_MINOR__ > 6
00047 #include <cuda_runtime.h> /* no diagnostic for this one */
00048 #if __GNUC__ >= 4 &&  __GNUC_MINOR__ > 6
00049 #pragma GCC diagnostic pop
00050 #endif //__GNUC__ >= 4&&  __GNUC_MINOR__ > 6
00051 
00052 #include <lama/config.hpp>
00053 #include <lama/SyncToken.hpp>
00054 
00055 namespace lama
00056 {
00057 
00058 class CUDAContext;
00059 
00060 typedef boost::shared_ptr<const CUDAContext> CUDAContextPtr;
00061 
00064 class LAMA_DLL_IMPORTEXPORT CUDAStreamSyncToken: public lama::SyncToken
00065 
00066 {
00067 
00068 public:
00069 
00070     friend class CUDAStreamSyncTokenPtr;
00071 
00080     CUDAStreamSyncToken( CUDAContextPtr context, CUstream stream );
00081 
00082     virtual ~CUDAStreamSyncToken();
00083 
00084     virtual void wait();
00085 
00086     virtual bool probe() const;
00087 
00088     cudaStream_t getCUDAStream() const;
00089 
00090     void createTimingEvent( CUevent& event ) const;
00091 
00092     void createEvent( CUevent& event ) const;
00093 
00094     void getTime( float* time, CUevent& startEvent, CUevent& stopEvent ) const ;
00095 
00096     bool probeEvent( const CUevent& stopEvent ) const;
00097 
00098     void recordEvent( const CUevent event );
00099 
00100     bool queryEvent( const CUevent event ) const;
00101 
00102     void synchronizeEvent( const CUevent event ) const;
00103 
00104 private:
00105 
00106     CUDAContextPtr mCUDAContext;  // needed for synchronization
00107 
00108     const CUstream mStream;
00109     CUevent        mEvent;
00110 };
00111 
00112 class LAMA_DLL_IMPORTEXPORT CUDAStreamSyncTokenPtr
00113 {
00114 public:
00115 
00116     CUDAStreamSyncTokenPtr() throw();
00117 
00118     CUDAStreamSyncTokenPtr( CUDAStreamSyncTokenPtr& other ) throw();
00119 
00120     CUDAStreamSyncTokenPtr( std::auto_ptr<CUDAStreamSyncToken> other ) throw();
00121 
00122     CUDAStreamSyncTokenPtr( CUDAStreamSyncToken* pointer ) throw();
00123 
00124     ~CUDAStreamSyncTokenPtr();
00125 
00126     CUDAStreamSyncTokenPtr& operator=( std::auto_ptr<CUDAStreamSyncToken> other ) throw();
00127 
00128     CUDAStreamSyncTokenPtr& operator=( CUDAStreamSyncTokenPtr& other ) throw();
00129 
00130     operator std::auto_ptr<SyncToken>& ();
00131 
00132     CUDAStreamSyncToken* operator->() const throw();
00133 
00134     CUDAStreamSyncToken& operator*() const throw();
00135 
00136     CUDAStreamSyncToken* release() throw();
00137 
00138 private:
00139     std::auto_ptr<CUDAStreamSyncToken> mCUDAStreamSyncToken;
00140     std::auto_ptr<SyncToken> mSyncToken;
00141 };
00142 
00143 }
00144 
00145 #endif // LAMA_CUDA_STREAM_SYNC_TOKEN_HPP_