From 213623506f7ae12f2aa73e5e548e801d3395a19c Mon Sep 17 00:00:00 2001 From: "Xie, Pengda" Date: Tue, 5 Aug 2025 10:39:37 -0700 Subject: [PATCH] SWDEV-534394 - Kernel launch stream check (#533) hipErrorInvalidResourceHandle is returned if stream is not on the launching device [ROCm/clr commit: 7e777d37551fba2961a470e916ecf7129e1383a1] --- projects/clr/hipamd/src/hip_event.cpp | 6 +++--- projects/clr/hipamd/src/hip_module.cpp | 3 +++ 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/projects/clr/hipamd/src/hip_event.cpp b/projects/clr/hipamd/src/hip_event.cpp index 5b850721b7..786fac7edc 100644 --- a/projects/clr/hipamd/src/hip_event.cpp +++ b/projects/clr/hipamd/src/hip_event.cpp @@ -374,7 +374,7 @@ hipError_t hipEventElapsedTime(float* ms, hipEvent_t start, hipEvent_t stop) { hip::Event* eStop = reinterpret_cast(stop); if (eStart->deviceId() != eStop->deviceId()) { - HIP_RETURN(hipErrorInvalidHandle); + HIP_RETURN(hipErrorInvalidResourceHandle); } HIP_RETURN(eStart->elapsedTime(*eStop, *ms), "Elapsed Time = ", *ms); @@ -414,8 +414,8 @@ hipError_t hipEventRecord_common(hipEvent_t event, hipStream_t stream, unsigned s->SetLastCapturedNode(pGraphNode); } } else { - if (g_devices[e->deviceId()]->devices()[0] != &hip_stream->device()) { - return hipErrorInvalidHandle; + if (e->deviceId() != hip_stream->DeviceId()) { + return hipErrorInvalidResourceHandle; } status = e->addMarker(hip_stream, nullptr, !hip::Event::kBatchFlush); } diff --git a/projects/clr/hipamd/src/hip_module.cpp b/projects/clr/hipamd/src/hip_module.cpp index 3f818f2579..4c2bb738bb 100644 --- a/projects/clr/hipamd/src/hip_module.cpp +++ b/projects/clr/hipamd/src/hip_module.cpp @@ -429,6 +429,9 @@ hipError_t ihipModuleLaunchKernel(hipFunction_t f, amd::LaunchParams& launch_par uint64_t prevGridSum = 0, uint64_t allGridSum = 0, uint32_t firstDevice = 0) { int deviceId = hip::Stream::DeviceId(hStream); + if (deviceId != ihipGetDevice()) { + return hipErrorInvalidResourceHandle; + } HIP_RETURN_ONFAIL(PlatformState::instance().initStatManagedVarDevicePtr(deviceId)); if (f == nullptr) {