diff --git a/hipamd/include/hcc_detail/hip_hcc.h b/hipamd/include/hcc_detail/hip_hcc.h index f19e5fd361..38f279a2d3 100644 --- a/hipamd/include/hcc_detail/hip_hcc.h +++ b/hipamd/include/hcc_detail/hip_hcc.h @@ -306,10 +306,29 @@ private: }; +template +struct LockedBase { + + // Experts-only interface for explicit locking. + // Most uses should use the lock-accessor. + void lock() { _mutex.lock(); } + void unlock() { _mutex.unlock(); } + + MUTEX_TYPE _mutex; +}; + + +template +class ihipStreamCriticalBase_t : public LockedBase +{ +private: +}; +typedef ihipStreamCriticalBase_t ihipStreamCritical_t; + +typedef LockedAccessor Locked_ihipStreamCritical_t; + -// TODO - move async copy code into stream? Stream->async-copy. -// Add PreCopy / PostCopy to manage locks? // Internal stream structure. class ihipStream_t { public: @@ -342,13 +361,15 @@ typedef uint64_t SeqNum_t ; //-- Non-racy accessors: // These functions access fields set at initialization time and are non-racy (so do not acquire mutex) ihipDevice_t * getDevice() const; - StreamMutex & mutex() {return _mutex;}; //--- //Member vars - these are set at initialization: SeqNum_t _id; // monotonic sequence ID hc::accelerator_view _av; unsigned _flags; +private: + ihipStreamCritical_t _criticalData; + private: void enqueueBarrier(hsa_queue_t* queue, ihipSignal_t *depSignal); void waitCopy(ihipSignal_t *signal); @@ -360,6 +381,8 @@ private: //--- unsigned _device_index; + + // Critical Data: ihipCommand_t _last_command_type; // type of the last command // signal of last copy command sent to the stream. @@ -374,7 +397,6 @@ 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. - StreamMutex _mutex; friend std::ostream& operator<<(std::ostream& os, const ihipStream_t& s); }; @@ -424,7 +446,7 @@ struct ihipEvent_t { // // MUTEX_TYPE is template argument so can easily convert to FakeMutex for performance or stress testing. template -class ihipDeviceCriticalBase_t +class ihipDeviceCriticalBase_t : LockedBase { public: ihipDeviceCriticalBase_t() : _stream_id(0) {}; @@ -440,7 +462,6 @@ public: private: std::list _streams; // streams associated with this device. ihipStream_t::SeqNum_t _stream_id; - MUTEX_TYPE _mutex; }; #if DEVICE_THREAD_SAFE diff --git a/hipamd/src/hip_hcc.cpp b/hipamd/src/hip_hcc.cpp index ce136addd9..5662e90cc3 100644 --- a/hipamd/src/hip_hcc.cpp +++ b/hipamd/src/hip_hcc.cpp @@ -288,7 +288,7 @@ void ihipStream_t::enqueueBarrier(hsa_queue_t* queue, ihipSignal_t *depSignal) // bool ihipStream_t::preKernelCommand() { - _mutex.lock(); // will be unlocked in postKernelCommand + _criticalData.lock();// will be unlocked in postKernelCommand bool addedSync = false; // If switching command types, we need to add a barrier packet to synchronize things. @@ -323,7 +323,7 @@ void ihipStream_t::postKernelCommand(hc::completion_future &kernelFuture) { _last_kernel_future = kernelFuture; - _mutex.unlock(); + _criticalData.unlock(); // paired with lock from preKernelCommand };