diff --git a/hipamd/src/hip_graph.cpp b/hipamd/src/hip_graph.cpp index fcd7cfd02e..fa0b56087e 100644 --- a/hipamd/src/hip_graph.cpp +++ b/hipamd/src/hip_graph.cpp @@ -42,7 +42,9 @@ inline hipError_t ihipGraphUpload(hipGraphExec_t graphExec, hipStream_t stream) if (!hip::isValid(stream)) { return hipErrorContextIsDestroyed; } - + if (!hip::GraphExec::isGraphExecValid(reinterpret_cast(graphExec))) { + return hipErrorInvalidValue; + } return hipSuccess; } diff --git a/hipamd/src/hip_graph_internal.cpp b/hipamd/src/hip_graph_internal.cpp index eac63876f2..eb627b90f3 100644 --- a/hipamd/src/hip_graph_internal.cpp +++ b/hipamd/src/hip_graph_internal.cpp @@ -356,6 +356,7 @@ hipError_t GraphExec::Init() { // For graph nodes capture AQL packets to dispatch them directly during graph launch. status = CaptureAQLPackets(); } + instantiateDeviceId_ = hip::getCurrentDevice()->deviceId(); return status; } @@ -589,7 +590,8 @@ hipError_t GraphExec::Run(hipStream_t stream) { repeatLaunch_ = true; } - if (parallelLists_.size() == 1) { + if (parallelLists_.size() == 1 && + instantiateDeviceId_ == hip_stream->DeviceId()) { amd::AccumulateCommand* accumulate = nullptr; bool isLastPacketKernel = false; if (DEBUG_CLR_GRAPH_PACKET_CAPTURE) { @@ -631,6 +633,13 @@ hipError_t GraphExec::Run(hipStream_t stream) { accumulate->enqueue(); accumulate->release(); } + } else if (parallelLists_.size() == 1 && + instantiateDeviceId_ != hip_stream->DeviceId()) { + for (int i = 0; i < topoOrder_.size(); i++) { + topoOrder_[i]->SetStream(hip_stream, this); + status = topoOrder_[i]->CreateCommand(topoOrder_[i]->GetQueue()); + topoOrder_[i]->EnqueueCommands(stream); + } } else { UpdateStream(parallelLists_, hip_stream, this); amd::Command* rootCommand = nullptr; diff --git a/hipamd/src/hip_graph_internal.hpp b/hipamd/src/hip_graph_internal.hpp index e14ce6b6b2..ac9f775069 100644 --- a/hipamd/src/hip_graph_internal.hpp +++ b/hipamd/src/hip_graph_internal.hpp @@ -569,6 +569,7 @@ struct GraphExec { std::vector
kernarg_graph_; uint32_t kernarg_graph_cur_offset_ = 0; uint32_t kernarg_graph_size_ = 128 * Ki; + int instantiateDeviceId_ = -1; public: GraphExec(std::vector& topoOrder, std::vector>& lists,