diff --git a/projects/rocr-runtime/runtime/hsa-runtime/core/runtime/amd_blit_sdma.cpp b/projects/rocr-runtime/runtime/hsa-runtime/core/runtime/amd_blit_sdma.cpp index 3740702c46..064c4cd27e 100644 --- a/projects/rocr-runtime/runtime/hsa-runtime/core/runtime/amd_blit_sdma.cpp +++ b/projects/rocr-runtime/runtime/hsa-runtime/core/runtime/amd_blit_sdma.cpp @@ -278,10 +278,23 @@ hsa_status_t BlitSdma: const void* cmd, size_t cmd_size, uint64_t size, const std::vector& dep_signals, core::Signal& out_signal, std::vector& gang_signals) { - // The signal is 64 bit value, and poll checks for 32 bit value. So we - // need to use two poll operations per dependent signal. - const uint32_t num_poll_command = - static_cast(2 * dep_signals.size()); + uint32_t num_poll_command = 0; + + // Cached copy of dep_signals[i]->LoadRelaxed + uint64_t dep_signals_value[dep_signals.size()]; + + for (size_t i = 0; i < dep_signals.size(); ++i) { + // The signal is 64 bit value, and poll checks for 32 bit value. + // If the signal is already 0, then we do not need to poll. + // If the upper 32-bits of the signal is 0, then we only need to poll the + // lower 32-bits + dep_signals_value[i] = dep_signals[i]->LoadRelaxed(); + if (dep_signals_value[i]) { + num_poll_command++; + if (dep_signals_value[i] >> 32) + num_poll_command++; + } + } const uint32_t total_poll_command_size = (num_poll_command * poll_command_size_); @@ -357,18 +370,23 @@ hsa_status_t BlitSdma: uint32_t wrapped_index = WrapIntoRing(curr_index); for (size_t i = 0; i < dep_signals.size(); ++i) { - uint32_t* signal_addr = - reinterpret_cast(dep_signals[i]->ValueLocation()); - // Wait for the higher 64 bit to 0. - BuildPollCommand(command_addr, &signal_addr[1], 0); - command_addr += poll_command_size_; - bytes_written_[wrapped_index] = prior_bytes; - wrapped_index += poll_command_size_; - // Then wait for the lower 64 bit to 0. - BuildPollCommand(command_addr, &signal_addr[0], 0); - command_addr += poll_command_size_; - bytes_written_[wrapped_index] = prior_bytes; - wrapped_index += poll_command_size_; + if (dep_signals_value[i]) { + uint32_t* signal_addr = + reinterpret_cast(dep_signals[i]->ValueLocation()); + + if (dep_signals_value[i] >> 32) { + // Wait for the higher 32 bits to 0. + BuildPollCommand(command_addr, &signal_addr[1], 0); + command_addr += poll_command_size_; + bytes_written_[wrapped_index] = prior_bytes; + wrapped_index += poll_command_size_; + } + // Then wait for the lower 32 bits to 0. + BuildPollCommand(command_addr, &signal_addr[0], 0); + command_addr += poll_command_size_; + bytes_written_[wrapped_index] = prior_bytes; + wrapped_index += poll_command_size_; + } } if (profiling_enabled && (gang_leader_ || gang_signals.empty())) {