Add FORCE_SAMEDIR_DEP for copies.

This commit is contained in:
Ben Sander committed 2016-03-04 08:21:15 -06:00
1 parent 5e51ff177a
commit ed71cded1c
1 file changed
+16 -13
+16 -13
View File
@@ -58,10 +58,16 @@ THE SOFTWARE.
#endif #endif
// If defined, thread-safety is enforced on all stream functions. // If set, thread-safety is enforced on all stream functions.
// Stream functions will acquire a mutex before entering critical sections. // Stream functions will acquire a mutex before entering critical sections.
#define STREAM_THREAD_SAFE #define STREAM_THREAD_SAFE 1
// If FORCE_SAMEDIR_DEP=1 , HIP runtime will add
// synchronization for sequential commands in the same stream.
// If FORCE_SAMEDIR_DEP=0 data copies in the same direction are assumed to be correctly ordered.
// ROCR runtime implementation currently provides this guarantee when using SDMA queues but not
// when using shader queues.
#define FORCE_SAMEDIR_DEP 1
#define INLINE static inline #define INLINE static inline
@@ -118,7 +124,6 @@ enum ihipCommand_t {
ihipCommandKernel, ihipCommandKernel,
ihipCommandCopyH2D, ihipCommandCopyH2D,
ihipCommandCopyD2H, ihipCommandCopyD2H,
ihipCommandCopyGeneric,
}; };
const char* ihipCommandName[] = { const char* ihipCommandName[] = {
@@ -156,7 +161,7 @@ class FakeMutex
}; };
#ifdef STREAM_THREAD_SAFE #if STREAM_THREAD_SAFE
typedef std::mutex StreamMutex; typedef std::mutex StreamMutex;
#else #else
typedef FakeMutex StreamMutex; typedef FakeMutex StreamMutex;
@@ -505,20 +510,18 @@ inline bool ihipStream_t::preKernelCommand()
addedSync = true; addedSync = true;
hsa_queue_t * q = (hsa_queue_t*)_av.get_hsa_queue(); hsa_queue_t * q = (hsa_queue_t*)_av.get_hsa_queue();
if (! HIP_DISABLE_HW_KERNEL_DEP) { if (HIP_DISABLE_HW_KERNEL_DEP == 0) {
this->enqueueBarrier(q, _last_copy_signal); this->enqueueBarrier(q, _last_copy_signal);
tprintf (TRACE_SYNC, "stream %p switch %s to %s (barrier pkt inserted with wait on #%lu)\n", tprintf (TRACE_SYNC, "stream %p switch %s to %s (barrier pkt inserted with wait on #%lu)\n",
this, ihipCommandName[_last_command_type], ihipCommandName[ihipCommandKernel], _last_copy_signal->_sig_id) this, ihipCommandName[_last_command_type], ihipCommandName[ihipCommandKernel], _last_copy_signal->_sig_id)
} else { } else if (HIP_DISABLE_HW_KERNEL_DEP>0) {
if (HIP_DISABLE_HW_KERNEL_DEP != -1) { tprintf (TRACE_SYNC, "stream %p switch %s to %s (HOST wait for previous...)\n",
tprintf (TRACE_SYNC, "stream %p switch %s to %s (wait for previous...)\n",
this, ihipCommandName[_last_command_type], ihipCommandName[ihipCommandKernel]); this, ihipCommandName[_last_command_type], ihipCommandName[ihipCommandKernel]);
this->waitAndReclaimOlder(_last_copy_signal); this->waitAndReclaimOlder(_last_copy_signal);
} else { } else if (HIP_DISABLE_HW_KERNEL_DEP==-1) {
tprintf (TRACE_SYNC, "stream %p switch %s to %s (IGNORE dependency)\n", tprintf (TRACE_SYNC, "stream %p switch %s to %s (IGNORE dependency)\n",
this, ihipCommandName[_last_command_type], ihipCommandName[ihipCommandKernel]); this, ihipCommandName[_last_command_type], ihipCommandName[ihipCommandKernel]);
}
} }
} }
_last_command_type = ihipCommandKernel; _last_command_type = ihipCommandKernel;
@@ -547,7 +550,7 @@ inline int ihipStream_t::copyCommand(ihipSignal_t *lastCopy, hsa_signal_t *waitS
waitSignal->handle = 0; waitSignal->handle = 0;
// If switching command types, we need to add a barrier packet to synchronize things. // If switching command types, we need to add a barrier packet to synchronize things.
if (_last_command_type != copyType) { if (FORCE_SAMEDIR_DEP || (_last_command_type != copyType)) {
if (_last_command_type == ihipCommandKernel) { if (_last_command_type == ihipCommandKernel) {