SWDEV-313905 - Fix for hipLaunchCooperativeKernel crash

Change-Id: I41205171a9607962ab6b66f2ebc6f8dc9db7f158
Šī revīzija ir iekļauta:
Sarbojit Sarkar
2021-12-02 12:00:03 +00:00
revīziju iesūtīja Sarbojit Sarkar
vecāks 9a3cb1608b
revīzija 9a51909058
+25 -19
Parādīt failu
@@ -114,6 +114,25 @@ bool Stream::Create() {
return result;
}
// ================================================================================================
bool isValid(hipStream_t& stream) {
// NULL stream is always valid
if (stream == nullptr) {
return true;
}
if (hipStreamPerThread == stream) {
getStreamPerThread(stream);
}
hip::Stream* s = reinterpret_cast<hip::Stream*>(stream);
amd::ScopedLock lock(streamSetLock);
if (streamSet.find(s) == streamSet.end()) {
return false;
}
return true;
}
// ================================================================================================
amd::HostQueue* Stream::asHostQueue(bool skip_alloc) {
if (queue_ != nullptr) {
@@ -143,6 +162,12 @@ int Stream::DeviceId() const {
}
int Stream::DeviceId(const hipStream_t hStream) {
// Copying locally into non-const variable just to get const away
hipStream_t inputStream = hStream;
if (!hip::isValid(inputStream)) {
//return invalid device id
return -1;
}
hip::Stream* s = reinterpret_cast<hip::Stream*>(hStream);
int deviceId = (s != nullptr)? s->DeviceId() : ihipGetDevice();
assert(deviceId >= 0 && deviceId < static_cast<int>(g_devices.size()));
@@ -175,25 +200,6 @@ void Stream::destroyAllStreams(int deviceId) {
}
}
// ================================================================================================
bool isValid(hipStream_t& stream) {
// NULL stream is always valid
if (stream == nullptr) {
return true;
}
if (hipStreamPerThread == stream) {
getStreamPerThread(stream);
}
hip::Stream* s = reinterpret_cast<hip::Stream*>(stream);
amd::ScopedLock lock(streamSetLock);
if (streamSet.find(s) == streamSet.end()) {
return false;
}
return true;
}
};// hip namespace
// ================================================================================================