Make ihipDevice_t thread-safe.

Move critical data into separate class and protect with LockAccessor
wrapper class.

For device, the streams list is the critical data since it is modified when
streams are created or destroyed.   The streams list is accessed in
several places including when synchronizing across all streams on the
device (ie from the default stream).
Other device data is set once by the device cosntructor and is not critical
so

All functions which acquire the LockAccessor now named with "locked_" prefix.
This commit is contained in:
Ben Sander
2016-03-26 10:46:20 -05:00
parent 581b884274
commit 530ab9434a
8 changed files with 279 additions and 39 deletions
+5 -9
View File
@@ -150,8 +150,7 @@ hipError_t hipDeviceSynchronize(void)
{
HIP_INIT_API();
ihipGetTlsDefaultDevice()->waitAllStreams(); // ignores non-blocking streams, this waits for all activity to finish.
ihipGetTlsDefaultDevice()->locked_waitAllStreams(); // ignores non-blocking streams, this waits for all activity to finish.
return ihipLogStatus(hipSuccess);
}
@@ -174,15 +173,12 @@ hipError_t hipDeviceReset(void)
if (device) {
//---
//Wait for pending activity to complete?
//TODO - check if this is required behavior:
for (auto streamI=device->_streams.begin(); streamI!=device->_streams.end(); streamI++) {
ihipStream_t *stream = *streamI;
stream->wait();
}
//Wait for pending activity to complete? TODO - check if this is required behavior:
device->locked_waitAllStreams();
// Release device resources (streams and memory):
device->reset();
device->locked_reset();
}
return ihipLogStatus(hipSuccess);