diff --git a/hipamd/src/hip_event.cpp b/hipamd/src/hip_event.cpp index b53a00fe5e..99603557b8 100644 --- a/hipamd/src/hip_event.cpp +++ b/hipamd/src/hip_event.cpp @@ -260,6 +260,21 @@ hipError_t Event::addMarker(hipStream_t stream, amd::Command* command, bool reco return status; } +// ================================================================================================ +bool isValid(hipEvent_t event) { + // NULL event is always valid + if (event == nullptr) { + return true; + } + + amd::ScopedLock lock(eventSetLock); + if (eventSet.find(event) == eventSet.end()) { + return false; + } + + return true; +} + } // namespace hip // ================================================================================================ hipError_t ihipEventCreateWithFlags(hipEvent_t* event, unsigned flags) { diff --git a/hipamd/src/hip_internal.hpp b/hipamd/src/hip_internal.hpp index 7d9e9dbaaf..ff8eecbbc1 100644 --- a/hipamd/src/hip_internal.hpp +++ b/hipamd/src/hip_internal.hpp @@ -516,6 +516,7 @@ namespace hip { int getDeviceID(amd::Context& ctx); /// Check if stream is valid extern bool isValid(hipStream_t& stream); + extern bool isValid(hipEvent_t event); extern amd::Monitor hipArraySetLock; extern std::unordered_set hipArraySet; }; // namespace hip diff --git a/hipamd/src/hip_module.cpp b/hipamd/src/hip_module.cpp index a3267249a5..b63b1f2ccf 100644 --- a/hipamd/src/hip_module.cpp +++ b/hipamd/src/hip_module.cpp @@ -497,7 +497,7 @@ extern "C" hipError_t hipExtLaunchKernel(const void* hostFunction, dim3 gridDim, HIP_INIT_API(hipExtLaunchKernel, hostFunction, gridDim, blockDim, args, sharedMemBytes, stream, startEvent, stopEvent, flags); - if (!hip::isValid(stream)) { + if (!hip::isValid(stream) || !hip::isValid(startEvent) || !hip::isValid(stopEvent)) { HIP_RETURN(hipErrorInvalidValue); }