SWDEV-300471 - updated hipFree to wait for all streams to finish

Change-Id: I4983ef48a9e720ed03128d83a8d23ad11024fd8f


[ROCm/clr commit: c9d9fd992a]
Dieser Commit ist enthalten in:
anusha GodavarthySurya
2021-08-25 08:16:52 -07:00
committet von Anusha Godavarthy Surya
Ursprung 00bce2cfc2
Commit 64799f183f
5 geänderte Dateien mit 21 neuen und 5 gelöschten Zeilen
+10
Datei anzeigen
@@ -115,6 +115,16 @@ amd::HostQueue* getNullStream(amd::Context& ctx) {
return nullptr;
}
// ================================================================================================
int getDeviceID(amd::Context& ctx) {
for (auto& it : g_devices) {
if (it->asContext() == &ctx) {
return it->deviceId();
}
}
return -1;
}
// ================================================================================================
amd::HostQueue* getNullStream() {
Device* device = getCurrentDevice();
@@ -467,7 +467,7 @@ hipError_t hipDeviceSynchronize ( void ) {
queue->finish();
hip::Stream::syncNonBlockingStreams();
hip::Stream::syncNonBlockingStreams(hip::getCurrentDevice()->deviceId());
HIP_RETURN(hipSuccess);
}
+3 -1
Datei anzeigen
@@ -210,7 +210,7 @@ namespace hip {
const std::vector<uint32_t> GetCUMask() const { return cuMask_; }
/// Sync all non-blocking streams
static void syncNonBlockingStreams();
static void syncNonBlockingStreams(int deviceId = -1);
/// Destroy all streams on a given device
static void destroyAllStreams(int deviceId);
@@ -325,6 +325,8 @@ namespace hip {
extern amd::HostQueue* getNullStream(amd::Context&);
/// Get default stream of the thread
extern amd::HostQueue* getNullStream();
/// Get device ID associated with the ROCclr context
int getDeviceID(amd::Context& ctx);
/// Check if stream is valid
extern bool isValid(hipStream_t& stream);
};
+3 -1
Datei anzeigen
@@ -86,7 +86,7 @@ hipError_t ihipFree(void *ptr)
size_t offset = 0;
amd::Memory* memory_object = getMemoryObject(ptr, offset);
int deviceID = -1;
if (memory_object != nullptr) {
// Check if it's an allocation in system memory and can be shared across all devices
if (memory_object->getMemFlags() & CL_MEM_SVM_FINE_GRAIN_BUFFER) {
@@ -102,7 +102,9 @@ hipError_t ihipFree(void *ptr)
} else {
// Wait on the device, associated with the current memory object
hip::getNullStream(memory_object->getContext())->finish();
deviceID = hip::getDeviceID(memory_object->getContext());
}
hip::Stream::syncNonBlockingStreams(deviceID);
amd::SvmBuffer::free(memory_object->getContext(), ptr);
return hipSuccess;
}
+4 -2
Datei anzeigen
@@ -148,11 +148,13 @@ int Stream::DeviceId(const hipStream_t hStream) {
return deviceId;
}
void Stream::syncNonBlockingStreams() {
void Stream::syncNonBlockingStreams(int deviceId) {
amd::ScopedLock lock(streamSetLock);
for (auto& it : streamSet) {
if (it->Flags() & hipStreamNonBlocking) {
it->asHostQueue()->finish();
if (deviceId == -1 || it->DeviceId() == deviceId) {
it->asHostQueue()->finish();
}
}
}
}