2022-04-27 11:14:59 -07:00
|
|
|
/* Copyright (c) 2015 - 2022 Advanced Micro Devices, Inc.
|
2020-02-04 08:45:01 -08:00
|
|
|
|
|
|
|
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
|
of this software and associated documentation files (the "Software"), to deal
|
|
|
|
|
in the Software without restriction, including without limitation the rights
|
|
|
|
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
|
copies of the Software, and to permit persons to whom the Software is
|
|
|
|
|
furnished to do so, subject to the following conditions:
|
|
|
|
|
|
|
|
|
|
The above copyright notice and this permission notice shall be included in
|
|
|
|
|
all copies or substantial portions of the Software.
|
|
|
|
|
|
|
|
|
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
|
THE SOFTWARE. */
|
2018-03-01 22:57:20 -05:00
|
|
|
|
|
|
|
|
#include <hip/hip_runtime.h>
|
|
|
|
|
|
2018-05-01 18:10:09 -04:00
|
|
|
#include "hip_event.hpp"
|
2021-07-28 00:03:29 -04:00
|
|
|
#if !defined(_MSC_VER)
|
|
|
|
|
#include <unistd.h>
|
|
|
|
|
#endif
|
2020-07-10 06:24:35 +00:00
|
|
|
|
2019-05-06 17:43:06 -04:00
|
|
|
namespace hip {
|
|
|
|
|
|
2022-07-11 15:19:09 -04:00
|
|
|
static amd::Monitor eventSetLock{"Guards global event set"};
|
|
|
|
|
static std::unordered_set<hipEvent_t> eventSet;
|
|
|
|
|
|
2022-12-01 13:22:06 +00:00
|
|
|
bool Event::ready(eventType type) {
|
2020-03-27 11:32:46 -07:00
|
|
|
if (event_->status() != CL_COMPLETE) {
|
|
|
|
|
event_->notifyCmdQueue();
|
|
|
|
|
}
|
2021-06-10 20:30:32 -04:00
|
|
|
// Check HW status of the ROCcrl event. Note: not all ROCclr modes support HW status
|
2022-12-01 13:22:06 +00:00
|
|
|
bool ready = CheckHwEvent(type);
|
2021-06-10 20:30:32 -04:00
|
|
|
if (!ready) {
|
|
|
|
|
ready = (event_->status() == CL_COMPLETE);
|
|
|
|
|
}
|
|
|
|
|
return ready;
|
2019-05-06 17:43:06 -04:00
|
|
|
}
|
|
|
|
|
|
2022-12-01 13:22:06 +00:00
|
|
|
bool EventDD::ready(eventType type) {
|
2022-03-08 14:26:32 -08:00
|
|
|
// Check HW status of the ROCcrl event. Note: not all ROCclr modes support HW status
|
2022-12-01 13:22:06 +00:00
|
|
|
bool ready = CheckHwEvent(type);
|
2022-03-08 14:26:32 -08:00
|
|
|
// FIXME: Remove status check entirely
|
|
|
|
|
if (!ready) {
|
|
|
|
|
ready = (event_->status() == CL_COMPLETE);
|
|
|
|
|
}
|
|
|
|
|
return ready;
|
|
|
|
|
}
|
|
|
|
|
|
2019-05-06 17:43:06 -04:00
|
|
|
hipError_t Event::query() {
|
|
|
|
|
amd::ScopedLock lock(lock_);
|
|
|
|
|
|
2020-04-28 14:17:58 -07:00
|
|
|
// If event is not recorded, event_ is null, hence return hipSuccess
|
2019-05-06 17:43:06 -04:00
|
|
|
if (event_ == nullptr) {
|
2020-04-28 14:17:58 -07:00
|
|
|
return hipSuccess;
|
2019-05-06 17:43:06 -04:00
|
|
|
}
|
|
|
|
|
|
2022-12-01 13:22:06 +00:00
|
|
|
return ready(Query) ? hipSuccess : hipErrorNotReady;
|
2019-05-06 17:43:06 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
hipError_t Event::synchronize() {
|
|
|
|
|
amd::ScopedLock lock(lock_);
|
|
|
|
|
|
2020-04-28 14:17:58 -07:00
|
|
|
// If event is not recorded, event_ is null, hence return hipSuccess
|
2019-05-06 17:43:06 -04:00
|
|
|
if (event_ == nullptr) {
|
2020-04-28 14:17:58 -07:00
|
|
|
return hipSuccess;
|
2019-05-06 17:43:06 -04:00
|
|
|
}
|
|
|
|
|
|
2023-12-19 11:54:29 -05:00
|
|
|
auto hip_device = g_devices[deviceId()];
|
2021-06-10 20:30:32 -04:00
|
|
|
// Check HW status of the ROCcrl event. Note: not all ROCclr modes support HW status
|
|
|
|
|
static constexpr bool kWaitCompletion = true;
|
2023-12-19 11:54:29 -05:00
|
|
|
if (!hip_device->devices()[0]->IsHwEventReady(*event_, kWaitCompletion)) {
|
2022-04-27 04:45:39 +00:00
|
|
|
if (event_->HwEvent() != nullptr) {
|
|
|
|
|
amd::Command* command = nullptr;
|
|
|
|
|
hipError_t status = recordCommand(command, event_->command().queue(), flags);
|
|
|
|
|
command->enqueue();
|
2023-12-19 11:54:29 -05:00
|
|
|
hip_device->devices()[0]->IsHwEventReady(command->event(), kWaitCompletion);
|
2022-04-27 04:45:39 +00:00
|
|
|
command->release();
|
|
|
|
|
} else {
|
|
|
|
|
event_->awaitCompletion();
|
|
|
|
|
}
|
2021-06-10 20:30:32 -04:00
|
|
|
}
|
2019-05-06 17:43:06 -04:00
|
|
|
return hipSuccess;
|
|
|
|
|
}
|
|
|
|
|
|
2022-03-08 14:26:32 -08:00
|
|
|
bool Event::awaitEventCompletion() {
|
|
|
|
|
return event_->awaitCompletion();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool EventDD::awaitEventCompletion() {
|
|
|
|
|
return g_devices[deviceId()]->devices()[0]->IsHwEventReady(*event_, true);
|
|
|
|
|
}
|
|
|
|
|
|
2019-05-06 17:43:06 -04:00
|
|
|
hipError_t Event::elapsedTime(Event& eStop, float& ms) {
|
|
|
|
|
amd::ScopedLock startLock(lock_);
|
2019-06-13 15:40:39 -04:00
|
|
|
if (this == &eStop) {
|
2022-03-08 14:26:32 -08:00
|
|
|
ms = 0.f;
|
2019-06-13 15:40:39 -04:00
|
|
|
if (event_ == nullptr) {
|
2019-12-30 16:46:39 -05:00
|
|
|
return hipErrorInvalidHandle;
|
2019-06-13 15:40:39 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (flags & hipEventDisableTiming) {
|
2019-12-30 16:46:39 -05:00
|
|
|
return hipErrorInvalidHandle;
|
2019-06-13 15:40:39 -04:00
|
|
|
}
|
|
|
|
|
|
2022-12-01 13:22:06 +00:00
|
|
|
if (!ready(ElapsedTime)) {
|
2019-06-13 15:40:39 -04:00
|
|
|
return hipErrorNotReady;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return hipSuccess;
|
|
|
|
|
}
|
2022-03-08 14:26:32 -08:00
|
|
|
amd::ScopedLock stopLock(eStop.lock());
|
2019-05-06 17:43:06 -04:00
|
|
|
|
2022-03-08 14:26:32 -08:00
|
|
|
if (event_ == nullptr || eStop.event() == nullptr) {
|
2019-12-30 16:46:39 -05:00
|
|
|
return hipErrorInvalidHandle;
|
2019-05-06 17:43:06 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ((flags | eStop.flags) & hipEventDisableTiming) {
|
2019-12-30 16:46:39 -05:00
|
|
|
return hipErrorInvalidHandle;
|
2019-05-06 17:43:06 -04:00
|
|
|
}
|
|
|
|
|
|
2022-12-01 13:22:06 +00:00
|
|
|
if (!ready(ElapsedTime) || !eStop.ready(ElapsedTime)) {
|
2019-05-06 17:43:06 -04:00
|
|
|
return hipErrorNotReady;
|
|
|
|
|
}
|
|
|
|
|
|
2022-10-27 18:42:04 +00:00
|
|
|
if (event_ == eStop.event_) {
|
2020-05-27 00:36:27 -07:00
|
|
|
// Events are the same, which indicates the stream is empty and likely
|
|
|
|
|
// eventRecord is called on another stream. For such cases insert and measure a
|
|
|
|
|
// marker.
|
2020-06-19 18:04:25 -04:00
|
|
|
amd::Command* command = new amd::Marker(*event_->command().queue(), kMarkerDisableFlush);
|
2020-05-27 00:36:27 -07:00
|
|
|
command->enqueue();
|
|
|
|
|
command->awaitCompletion();
|
2022-10-27 18:42:04 +00:00
|
|
|
ms = static_cast<float>(static_cast<int64_t>(command->event().profilingInfo().end_) - time(false)) /
|
2021-12-01 17:40:49 -08:00
|
|
|
1000000.f;
|
2020-05-27 00:36:27 -07:00
|
|
|
command->release();
|
2020-05-20 10:54:57 -07:00
|
|
|
} else {
|
2021-06-10 20:30:32 -04:00
|
|
|
// Note: with direct dispatch eStop.ready() relies on HW event, but CPU status can be delayed.
|
|
|
|
|
// Hence for now make sure CPU status is updated by calling awaitCompletion();
|
2022-03-08 14:26:32 -08:00
|
|
|
awaitEventCompletion();
|
|
|
|
|
eStop.awaitEventCompletion();
|
2022-10-27 18:42:04 +00:00
|
|
|
if (unrecorded_ && eStop.isUnRecorded()) {
|
|
|
|
|
// Both the events are not recorded, just need the end and start of stop event
|
|
|
|
|
ms = static_cast<float>(eStop.time(false) - eStop.time(true)) / 1000000.f;
|
|
|
|
|
} else {
|
|
|
|
|
ms = static_cast<float>(eStop.time(false) - time(false)) / 1000000.f;
|
|
|
|
|
}
|
2020-05-20 10:54:57 -07:00
|
|
|
}
|
2019-05-06 17:43:06 -04:00
|
|
|
return hipSuccess;
|
|
|
|
|
}
|
|
|
|
|
|
2022-10-27 18:42:04 +00:00
|
|
|
int64_t Event::time(bool getStartTs) const {
|
2021-05-03 12:55:37 -07:00
|
|
|
assert(event_ != nullptr);
|
2022-10-27 18:42:04 +00:00
|
|
|
if (getStartTs) {
|
2021-05-03 12:55:37 -07:00
|
|
|
return static_cast<int64_t>(event_->profilingInfo().start_);
|
2022-10-27 18:42:04 +00:00
|
|
|
} else {
|
|
|
|
|
return static_cast<int64_t>(event_->profilingInfo().end_);
|
2021-05-03 12:55:37 -07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-10-27 18:42:04 +00:00
|
|
|
int64_t EventDD::time(bool getStartTs) const {
|
2022-03-08 14:26:32 -08:00
|
|
|
uint64_t start = 0, end = 0;
|
|
|
|
|
assert(event_ != nullptr);
|
|
|
|
|
g_devices[deviceId()]->devices()[0]->getHwEventTime(*event_, &start, &end);
|
|
|
|
|
// FIXME: This is only needed if the command had to wait CL_COMPLETE status
|
|
|
|
|
if (start == 0 || end == 0) {
|
2022-10-27 18:42:04 +00:00
|
|
|
return Event::time(getStartTs);
|
2022-03-08 14:26:32 -08:00
|
|
|
}
|
2022-10-27 18:42:04 +00:00
|
|
|
if (getStartTs) {
|
2022-03-08 14:26:32 -08:00
|
|
|
return static_cast<int64_t>(start);
|
2022-10-27 18:42:04 +00:00
|
|
|
} else {
|
|
|
|
|
return static_cast<int64_t>(end);
|
2022-03-08 14:26:32 -08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-02-08 20:18:11 +00:00
|
|
|
hipError_t Event::streamWaitCommand(amd::Command*& command, hip::Stream* stream) {
|
2021-12-01 17:40:49 -08:00
|
|
|
amd::Command::EventWaitList eventWaitList;
|
2022-03-15 11:50:00 +00:00
|
|
|
if (event_ != nullptr) {
|
|
|
|
|
eventWaitList.push_back(event_);
|
|
|
|
|
}
|
2023-02-08 20:18:11 +00:00
|
|
|
command = new amd::Marker(*stream, kMarkerDisableFlush, eventWaitList);
|
2023-11-13 13:10:58 -08:00
|
|
|
// Since we only need to have a dependency on an existing event,
|
|
|
|
|
// we may not need to flush any caches.
|
|
|
|
|
command->setEventScope(amd::Device::kCacheStateIgnore);
|
2021-12-01 17:40:49 -08:00
|
|
|
|
2019-05-06 17:43:06 -04:00
|
|
|
if (command == NULL) {
|
|
|
|
|
return hipErrorOutOfMemory;
|
|
|
|
|
}
|
|
|
|
|
return hipSuccess;
|
|
|
|
|
}
|
|
|
|
|
|
2021-10-05 10:06:40 -07:00
|
|
|
hipError_t Event::enqueueStreamWaitCommand(hipStream_t stream, amd::Command* command) {
|
2021-12-01 17:40:49 -08:00
|
|
|
command->enqueue();
|
2021-10-07 10:05:17 -07:00
|
|
|
return hipSuccess;
|
2021-10-05 10:06:40 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
hipError_t Event::streamWait(hipStream_t stream, uint flags) {
|
2023-02-08 20:18:11 +00:00
|
|
|
hip::Stream* hip_stream = hip::getStream(stream);
|
2021-11-01 09:52:38 -04:00
|
|
|
// Access to event_ object must be lock protected
|
|
|
|
|
amd::ScopedLock lock(lock_);
|
2022-12-01 13:22:06 +00:00
|
|
|
if ((event_ == nullptr) || (event_->command().queue() == hip_stream) || ready(StreamWait)) {
|
2021-10-05 10:06:40 -07:00
|
|
|
return hipSuccess;
|
|
|
|
|
}
|
2021-12-01 17:40:49 -08:00
|
|
|
if (!event_->notifyCmdQueue()) {
|
|
|
|
|
return hipErrorLaunchOutOfResources;
|
2021-10-05 10:06:40 -07:00
|
|
|
}
|
|
|
|
|
amd::Command* command;
|
2023-02-08 20:18:11 +00:00
|
|
|
hipError_t status = streamWaitCommand(command, hip_stream);
|
2021-12-01 17:40:49 -08:00
|
|
|
if (status != hipSuccess) {
|
|
|
|
|
return status;
|
|
|
|
|
}
|
|
|
|
|
status = enqueueStreamWaitCommand(stream, command);
|
|
|
|
|
if (status != hipSuccess) {
|
|
|
|
|
return status;
|
2021-10-05 10:06:40 -07:00
|
|
|
}
|
2021-12-01 17:40:49 -08:00
|
|
|
command->release();
|
2021-10-05 10:06:40 -07:00
|
|
|
return hipSuccess;
|
|
|
|
|
}
|
2021-03-19 14:47:08 -07:00
|
|
|
|
2023-02-08 20:18:11 +00:00
|
|
|
hipError_t Event::recordCommand(amd::Command*& command, amd::HostQueue* stream,
|
2022-04-01 15:16:13 -07:00
|
|
|
uint32_t ext_flags ) {
|
2021-12-01 17:40:49 -08:00
|
|
|
if (command == nullptr) {
|
2022-04-16 16:18:16 -07:00
|
|
|
int32_t releaseFlags = ((ext_flags == 0) ? flags : ext_flags) &
|
2023-01-20 15:35:25 -08:00
|
|
|
(hipEventReleaseToDevice | hipEventReleaseToSystem |
|
|
|
|
|
hipEventDisableSystemFence);
|
|
|
|
|
if (releaseFlags & hipEventDisableSystemFence) {
|
2022-04-01 15:16:13 -07:00
|
|
|
releaseFlags = amd::Device::kCacheStateIgnore;
|
2023-01-20 15:35:25 -08:00
|
|
|
} else {
|
|
|
|
|
releaseFlags = amd::Device::kCacheStateInvalid;
|
2022-04-01 15:16:13 -07:00
|
|
|
}
|
2021-06-10 12:43:24 -07:00
|
|
|
// Always submit a EventMarker.
|
2023-02-08 20:18:11 +00:00
|
|
|
command = new hip::EventMarker(*stream, !kMarkerDisableFlush, true, releaseFlags);
|
2020-07-22 11:35:15 -07:00
|
|
|
}
|
2021-10-05 10:06:40 -07:00
|
|
|
return hipSuccess;
|
|
|
|
|
}
|
2020-07-22 11:35:15 -07:00
|
|
|
|
2021-10-05 10:06:40 -07:00
|
|
|
hipError_t Event::enqueueRecordCommand(hipStream_t stream, amd::Command* command, bool record) {
|
2021-12-01 17:40:49 -08:00
|
|
|
command->enqueue();
|
|
|
|
|
if (event_ == &command->event()) return hipSuccess;
|
|
|
|
|
if (event_ != nullptr) {
|
|
|
|
|
event_->release();
|
2021-10-05 10:06:40 -07:00
|
|
|
}
|
2021-12-01 17:40:49 -08:00
|
|
|
event_ = &command->event();
|
2022-10-27 18:42:04 +00:00
|
|
|
unrecorded_ = !record;
|
2021-12-01 17:40:49 -08:00
|
|
|
|
2021-10-05 10:06:40 -07:00
|
|
|
return hipSuccess;
|
2019-05-06 17:43:06 -04:00
|
|
|
}
|
|
|
|
|
|
2021-10-05 10:06:40 -07:00
|
|
|
hipError_t Event::addMarker(hipStream_t stream, amd::Command* command, bool record) {
|
2023-02-08 20:18:11 +00:00
|
|
|
hip::Stream* hip_stream = hip::getStream(stream);
|
2021-10-05 10:06:40 -07:00
|
|
|
// Keep the lock always at the beginning of this to avoid a race. SWDEV-277847
|
|
|
|
|
amd::ScopedLock lock(lock_);
|
2023-02-08 20:18:11 +00:00
|
|
|
hipError_t status = recordCommand(command, hip_stream);
|
2021-10-05 10:06:40 -07:00
|
|
|
if (status != hipSuccess) {
|
|
|
|
|
return hipSuccess;
|
|
|
|
|
}
|
|
|
|
|
status = enqueueRecordCommand(stream, command, record);
|
|
|
|
|
return status;
|
2019-05-06 17:43:06 -04:00
|
|
|
}
|
|
|
|
|
|
2022-12-20 17:38:26 +00:00
|
|
|
// ================================================================================================
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
2021-12-01 17:40:49 -08:00
|
|
|
// ================================================================================================
|
2018-05-15 16:26:16 -04:00
|
|
|
hipError_t ihipEventCreateWithFlags(hipEvent_t* event, unsigned flags) {
|
2020-07-10 06:24:35 +00:00
|
|
|
unsigned supportedFlags = hipEventDefault | hipEventBlockingSync | hipEventDisableTiming |
|
2023-01-20 15:35:25 -08:00
|
|
|
hipEventReleaseToDevice | hipEventReleaseToSystem |
|
|
|
|
|
hipEventInterprocess | hipEventDisableSystemFence;
|
2022-04-27 11:14:59 -07:00
|
|
|
|
2023-01-20 15:35:25 -08:00
|
|
|
const unsigned releaseFlags = (hipEventReleaseToDevice | hipEventReleaseToSystem |
|
|
|
|
|
hipEventDisableSystemFence);
|
2021-12-01 17:40:49 -08:00
|
|
|
// can't set any unsupported flags.
|
2023-01-20 15:35:25 -08:00
|
|
|
// can set only one of the release flags.
|
2022-06-20 21:33:24 +05:30
|
|
|
// if hipEventInterprocess flag is set, then hipEventDisableTiming flag also must be set
|
|
|
|
|
const bool illegalFlags = (flags & ~supportedFlags) ||
|
2023-01-20 15:35:25 -08:00
|
|
|
([](unsigned int num){
|
|
|
|
|
unsigned int bitcount;
|
|
|
|
|
for (bitcount = 0; num; bitcount++) {
|
|
|
|
|
num &= num - 1;
|
|
|
|
|
}
|
|
|
|
|
return bitcount; } (flags & releaseFlags) > 1) ||
|
2022-06-20 21:33:24 +05:30
|
|
|
((flags & hipEventInterprocess) && !(flags & hipEventDisableTiming));
|
2018-05-15 16:26:16 -04:00
|
|
|
if (!illegalFlags) {
|
2021-12-01 17:40:49 -08:00
|
|
|
hip::Event* e = nullptr;
|
|
|
|
|
if (flags & hipEventInterprocess) {
|
|
|
|
|
e = new hip::IPCEvent();
|
|
|
|
|
} else {
|
2022-03-08 14:26:32 -08:00
|
|
|
if (AMD_DIRECT_DISPATCH) {
|
|
|
|
|
e = new hip::EventDD(flags);
|
|
|
|
|
} else {
|
|
|
|
|
e = new hip::Event(flags);
|
|
|
|
|
}
|
2021-12-01 17:40:49 -08:00
|
|
|
}
|
2018-05-15 16:26:16 -04:00
|
|
|
if (e == nullptr) {
|
|
|
|
|
return hipErrorOutOfMemory;
|
|
|
|
|
}
|
|
|
|
|
*event = reinterpret_cast<hipEvent_t>(e);
|
2022-07-11 15:19:09 -04:00
|
|
|
amd::ScopedLock lock(hip::eventSetLock);
|
|
|
|
|
hip::eventSet.insert(*event);
|
2018-05-15 16:26:16 -04:00
|
|
|
} else {
|
|
|
|
|
return hipErrorInvalidValue;
|
|
|
|
|
}
|
2018-05-01 18:10:09 -04:00
|
|
|
return hipSuccess;
|
2018-03-01 22:57:20 -05:00
|
|
|
}
|
|
|
|
|
|
2018-05-15 16:26:16 -04:00
|
|
|
hipError_t hipEventCreateWithFlags(hipEvent_t* event, unsigned flags) {
|
2019-10-07 11:55:30 -04:00
|
|
|
HIP_INIT_API(hipEventCreateWithFlags, event, flags);
|
2022-04-13 13:00:38 +00:00
|
|
|
|
|
|
|
|
if (event == nullptr) {
|
|
|
|
|
return hipErrorInvalidValue;
|
|
|
|
|
}
|
|
|
|
|
|
2020-06-05 10:45:28 -07:00
|
|
|
HIP_RETURN(ihipEventCreateWithFlags(event, flags), *event);
|
2019-10-07 11:55:30 -04:00
|
|
|
}
|
2018-05-15 16:26:16 -04:00
|
|
|
|
|
|
|
|
hipError_t hipEventCreate(hipEvent_t* event) {
|
2019-10-07 11:55:30 -04:00
|
|
|
HIP_INIT_API(hipEventCreate, event);
|
2022-04-13 13:00:38 +00:00
|
|
|
|
|
|
|
|
if (event == nullptr) {
|
|
|
|
|
return hipErrorInvalidValue;
|
|
|
|
|
}
|
|
|
|
|
|
2020-06-05 10:45:28 -07:00
|
|
|
HIP_RETURN(ihipEventCreateWithFlags(event, 0), *event);
|
2018-03-01 22:57:20 -05:00
|
|
|
}
|
|
|
|
|
|
2018-04-05 15:02:43 -04:00
|
|
|
hipError_t hipEventDestroy(hipEvent_t event) {
|
2019-10-07 11:55:30 -04:00
|
|
|
HIP_INIT_API(hipEventDestroy, event);
|
2018-03-01 22:57:20 -05:00
|
|
|
|
2018-05-15 16:26:16 -04:00
|
|
|
if (event == nullptr) {
|
2019-12-30 16:46:39 -05:00
|
|
|
HIP_RETURN(hipErrorInvalidHandle);
|
2018-05-15 16:26:16 -04:00
|
|
|
}
|
|
|
|
|
|
2022-07-11 15:19:09 -04:00
|
|
|
amd::ScopedLock lock(hip::eventSetLock);
|
|
|
|
|
if (hip::eventSet.erase(event) == 0 ) {
|
|
|
|
|
return hipErrorContextIsDestroyed;
|
|
|
|
|
}
|
|
|
|
|
|
2020-07-10 06:24:35 +00:00
|
|
|
hip::Event* e = reinterpret_cast<hip::Event*>(event);
|
2023-02-22 16:16:13 -05:00
|
|
|
// There is a possibility that stream destroy be called first
|
|
|
|
|
hipStream_t s = e->GetCaptureStream();
|
|
|
|
|
if (hip::isValid(s)) {
|
|
|
|
|
if (e->GetCaptureStream() != nullptr) {
|
|
|
|
|
reinterpret_cast<hip::Stream*>(e->GetCaptureStream())->EraseCaptureEvent(event);
|
|
|
|
|
}
|
2022-12-14 12:13:32 -05:00
|
|
|
}
|
2021-03-09 12:00:16 -05:00
|
|
|
delete e;
|
2018-08-14 18:54:13 -04:00
|
|
|
HIP_RETURN(hipSuccess);
|
2018-03-01 22:57:20 -05:00
|
|
|
}
|
|
|
|
|
|
2021-12-01 17:40:49 -08:00
|
|
|
hipError_t hipEventElapsedTime(float* ms, hipEvent_t start, hipEvent_t stop) {
|
2019-10-07 11:55:30 -04:00
|
|
|
HIP_INIT_API(hipEventElapsedTime, ms, start, stop);
|
2018-03-01 22:57:20 -05:00
|
|
|
|
2018-05-15 16:26:16 -04:00
|
|
|
if (ms == nullptr) {
|
2018-08-14 18:54:13 -04:00
|
|
|
HIP_RETURN(hipErrorInvalidValue);
|
2018-05-15 16:26:16 -04:00
|
|
|
}
|
|
|
|
|
|
2021-07-08 02:13:50 -04:00
|
|
|
if (start == nullptr || stop == nullptr) {
|
|
|
|
|
HIP_RETURN(hipErrorInvalidHandle);
|
|
|
|
|
}
|
|
|
|
|
|
2019-05-06 17:43:06 -04:00
|
|
|
hip::Event* eStart = reinterpret_cast<hip::Event*>(start);
|
2021-12-01 17:40:49 -08:00
|
|
|
hip::Event* eStop = reinterpret_cast<hip::Event*>(stop);
|
2018-05-15 16:26:16 -04:00
|
|
|
|
2021-03-09 12:00:16 -05:00
|
|
|
if (eStart->deviceId() != eStop->deviceId()) {
|
|
|
|
|
HIP_RETURN(hipErrorInvalidHandle);
|
|
|
|
|
}
|
|
|
|
|
|
2020-06-05 10:45:28 -07:00
|
|
|
HIP_RETURN(eStart->elapsedTime(*eStop, *ms), "Elapsed Time = ", *ms);
|
2018-03-01 22:57:20 -05:00
|
|
|
}
|
|
|
|
|
|
2022-04-13 06:35:25 +00:00
|
|
|
hipError_t hipEventRecord_common(hipEvent_t event, hipStream_t stream) {
|
2023-05-04 10:25:50 -04:00
|
|
|
hipError_t status = hipSuccess;
|
2018-05-15 16:26:16 -04:00
|
|
|
if (event == nullptr) {
|
2022-04-13 06:35:25 +00:00
|
|
|
return hipErrorInvalidHandle;
|
2018-05-15 16:26:16 -04:00
|
|
|
}
|
2023-06-21 14:43:57 -04:00
|
|
|
getStreamPerThread(stream);
|
2023-05-04 10:25:50 -04:00
|
|
|
if (!hip::isValid(stream)) {
|
|
|
|
|
return hipErrorContextIsDestroyed;
|
|
|
|
|
}
|
2020-07-15 15:11:59 -04:00
|
|
|
hip::Event* e = reinterpret_cast<hip::Event*>(event);
|
2023-05-04 10:25:50 -04:00
|
|
|
hip::Stream* s = reinterpret_cast<hip::Stream*>(stream);
|
2023-02-08 20:18:11 +00:00
|
|
|
hip::Stream* hip_stream = hip::getStream(stream);
|
2023-02-22 16:16:13 -05:00
|
|
|
e->SetCaptureStream(stream);
|
2023-05-04 10:25:50 -04:00
|
|
|
if ((s != nullptr) && (s->GetCaptureStatus() == hipStreamCaptureStatusActive)) {
|
2023-08-22 09:58:48 -07:00
|
|
|
ClPrint(amd::LOG_INFO, amd::LOG_API,
|
|
|
|
|
"[hipGraph] Current capture node EventRecord on stream : %p, Event %p", stream, event);
|
2023-05-04 10:25:50 -04:00
|
|
|
s->SetCaptureEvent(event);
|
2023-07-25 12:54:23 +00:00
|
|
|
std::vector<hip::GraphNode*> lastCapturedNodes = s->GetLastCapturedNodes();
|
2023-05-04 10:25:50 -04:00
|
|
|
if (!lastCapturedNodes.empty()) {
|
|
|
|
|
e->SetNodesPrevToRecorded(lastCapturedNodes);
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
if (g_devices[e->deviceId()]->devices()[0] != &hip_stream->device()) {
|
|
|
|
|
return hipErrorInvalidHandle;
|
|
|
|
|
}
|
|
|
|
|
status = e->addMarker(stream, nullptr, true);
|
2021-03-09 12:00:16 -05:00
|
|
|
}
|
2023-05-04 10:25:50 -04:00
|
|
|
return status;
|
2022-04-13 06:35:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
hipError_t hipEventRecord(hipEvent_t event, hipStream_t stream) {
|
|
|
|
|
HIP_INIT_API(hipEventRecord, event, stream);
|
|
|
|
|
HIP_RETURN(hipEventRecord_common(event, stream));
|
|
|
|
|
}
|
2021-03-09 12:00:16 -05:00
|
|
|
|
2022-04-13 06:35:25 +00:00
|
|
|
hipError_t hipEventRecord_spt(hipEvent_t event, hipStream_t stream) {
|
|
|
|
|
HIP_INIT_API(hipEventRecord, event, stream);
|
|
|
|
|
PER_THREAD_DEFAULT_STREAM(stream);
|
|
|
|
|
HIP_RETURN(hipEventRecord_common(event, stream));
|
2018-03-01 22:57:20 -05:00
|
|
|
}
|
|
|
|
|
|
2018-04-05 15:02:43 -04:00
|
|
|
hipError_t hipEventSynchronize(hipEvent_t event) {
|
2019-10-07 11:55:30 -04:00
|
|
|
HIP_INIT_API(hipEventSynchronize, event);
|
2018-03-01 22:57:20 -05:00
|
|
|
|
2018-05-15 16:26:16 -04:00
|
|
|
if (event == nullptr) {
|
2019-12-30 16:46:39 -05:00
|
|
|
HIP_RETURN(hipErrorInvalidHandle);
|
2018-05-15 16:26:16 -04:00
|
|
|
}
|
|
|
|
|
hip::Event* e = reinterpret_cast<hip::Event*>(event);
|
2023-02-22 16:16:13 -05:00
|
|
|
hip::Stream* s = reinterpret_cast<hip::Stream*>(e->GetCaptureStream());
|
|
|
|
|
if ((s != nullptr) && (s->GetCaptureStatus() == hipStreamCaptureStatusActive)) {
|
2023-05-04 10:25:50 -04:00
|
|
|
if (s->IsEventCaptured(event) == false) {
|
2023-02-22 16:16:13 -05:00
|
|
|
return HIP_RETURN(hipErrorStreamCaptureUnsupported);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (hip::Stream::StreamCaptureOngoing(e->GetCaptureStream()) == true) {
|
|
|
|
|
HIP_RETURN(hipErrorStreamCaptureUnsupported);
|
|
|
|
|
}
|
2024-01-22 18:12:33 -05:00
|
|
|
|
|
|
|
|
hipError_t status = e->synchronize();
|
|
|
|
|
// Release freed memory for all memory pools on the device
|
|
|
|
|
g_devices[e->deviceId()]->ReleaseFreedMemory();
|
|
|
|
|
|
|
|
|
|
HIP_RETURN(status);
|
2018-03-01 22:57:20 -05:00
|
|
|
}
|
2020-07-10 06:24:35 +00:00
|
|
|
|
2021-12-01 17:40:49 -08:00
|
|
|
hipError_t ihipEventQuery(hipEvent_t event) {
|
2020-07-10 06:24:35 +00:00
|
|
|
if (event == nullptr) {
|
2021-12-01 17:40:49 -08:00
|
|
|
return hipErrorInvalidHandle;
|
2021-07-28 00:03:29 -04:00
|
|
|
}
|
|
|
|
|
|
2021-12-01 17:40:49 -08:00
|
|
|
hip::Event* e = reinterpret_cast<hip::Event*>(event);
|
|
|
|
|
return e->query();
|
|
|
|
|
}
|
2021-03-09 12:00:16 -05:00
|
|
|
|
2021-12-01 17:40:49 -08:00
|
|
|
hipError_t hipEventQuery(hipEvent_t event) {
|
|
|
|
|
HIP_INIT_API(hipEventQuery, event);
|
|
|
|
|
HIP_RETURN(ihipEventQuery(event));
|
2020-07-10 06:24:35 +00:00
|
|
|
}
|
2023-04-21 10:46:05 +00:00
|
|
|
} // namespace hip
|