From b529941f70e47ea02f97e0664e89daf32eaaaf7c Mon Sep 17 00:00:00 2001 From: Ben Sander Date: Thu, 3 Mar 2016 10:49:25 -0600 Subject: [PATCH] Add define to disable STREAM thread-safety --- hipamd/src/hip_hcc.cpp | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/hipamd/src/hip_hcc.cpp b/hipamd/src/hip_hcc.cpp index 1cf8745c0b..49e71f6262 100644 --- a/hipamd/src/hip_hcc.cpp +++ b/hipamd/src/hip_hcc.cpp @@ -58,6 +58,11 @@ THE SOFTWARE. #endif +// If defined, thread-safety is enforced on all stream functions. +// Stream functions will acquire a mutex before entering critical sections. +#define STREAM_THREAD_SAFE + + #define INLINE static inline //--- @@ -113,6 +118,7 @@ enum ihipCommand_t { ihipCommandKernel, ihipCommandCopyH2D, ihipCommandCopyD2H, + ihipCommandCopyGeneric, }; const char* ihipCommandName[] = { @@ -150,6 +156,13 @@ class FakeMutex }; +#ifdef STREAM_THREAD_SAFE +typedef std::mutex StreamMutex; +#else +typedef FakeMutex StreamMutex; +#endif + + // Internal stream structure. class ihipStream_t { @@ -173,7 +186,7 @@ public: inline void resetToEmpty(); inline SIGSEQNUM lastCopySeqId() { return _last_copy_signal ? _last_copy_signal->_sig_id : 0; }; - std::mutex & mutex() {return _mutex;}; + StreamMutex & mutex() {return _mutex;}; //--- hc::accelerator_view _av; @@ -196,7 +209,7 @@ private: SIGSEQNUM _oldest_live_sig_id; // oldest live seq_id, anything < this can be allocated. std::deque _signalPool; // Pool of signals for use by this stream. - std::mutex _mutex; + StreamMutex _mutex; };