2018-03-01 22:57:20 -05:00
|
|
|
/*
|
|
|
|
|
Copyright (c) 2015 - present Advanced Micro Devices, Inc. All rights reserved.
|
|
|
|
|
|
|
|
|
|
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.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include <hip/hip_runtime.h>
|
|
|
|
|
|
2018-05-01 18:10:09 -04:00
|
|
|
#include "hip_event.hpp"
|
2018-03-01 22:57:20 -05:00
|
|
|
|
2018-05-15 16:26:16 -04:00
|
|
|
hipError_t ihipEventCreateWithFlags(hipEvent_t* event, unsigned flags) {
|
|
|
|
|
if (event == nullptr) {
|
|
|
|
|
return hipErrorInvalidValue;
|
|
|
|
|
}
|
2018-03-01 22:57:20 -05:00
|
|
|
|
2018-05-15 16:26:16 -04:00
|
|
|
unsigned supportedFlags = hipEventDefault | hipEventBlockingSync | hipEventDisableTiming |
|
|
|
|
|
hipEventReleaseToDevice | hipEventReleaseToSystem;
|
|
|
|
|
const unsigned releaseFlags = (hipEventReleaseToDevice | hipEventReleaseToSystem);
|
2018-04-05 15:02:43 -04:00
|
|
|
|
2018-05-15 16:26:16 -04:00
|
|
|
const bool illegalFlags =
|
|
|
|
|
(flags & ~supportedFlags) || // can't set any unsupported flags.
|
|
|
|
|
(flags & releaseFlags) == releaseFlags; // can't set both release flags
|
2018-05-01 18:10:09 -04:00
|
|
|
|
2018-05-15 16:26:16 -04:00
|
|
|
if (!illegalFlags) {
|
|
|
|
|
hip::Event* e = new hip::Event(flags);
|
2018-05-01 18:10:09 -04:00
|
|
|
|
2018-05-15 16:26:16 -04:00
|
|
|
if (e == nullptr) {
|
|
|
|
|
return hipErrorOutOfMemory;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
*event = reinterpret_cast<hipEvent_t>(e);
|
|
|
|
|
} 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 ihipEventQuery(hipEvent_t event) {
|
|
|
|
|
if (event == nullptr) {
|
|
|
|
|
return hipErrorInvalidResourceHandle;
|
|
|
|
|
}
|
2018-03-01 22:57:20 -05:00
|
|
|
|
2018-05-15 16:26:16 -04:00
|
|
|
hip::Event* e = reinterpret_cast<hip::Event*>(event);
|
2018-04-05 15:02:43 -04:00
|
|
|
|
2018-05-15 16:26:16 -04:00
|
|
|
if (e->event_ == nullptr) {
|
|
|
|
|
return hipErrorInvalidResourceHandle;
|
2018-05-01 18:10:09 -04:00
|
|
|
}
|
|
|
|
|
|
2018-05-15 16:26:16 -04:00
|
|
|
e->event_->notifyCmdQueue();
|
2018-05-01 18:10:09 -04:00
|
|
|
|
2018-08-14 18:54:13 -04:00
|
|
|
return (e->event_->status() == CL_COMPLETE) ? hipSuccess : hipErrorNotReady;
|
2018-05-15 16:26:16 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
hipError_t hipEventCreateWithFlags(hipEvent_t* event, unsigned flags) {
|
|
|
|
|
HIP_INIT_API(event, flags);
|
|
|
|
|
|
2018-08-14 18:54:13 -04:00
|
|
|
HIP_RETURN(ihipEventCreateWithFlags(event, flags));
|
2018-05-15 16:26:16 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
hipError_t hipEventCreate(hipEvent_t* event) {
|
|
|
|
|
HIP_INIT_API(event);
|
|
|
|
|
|
2018-08-14 18:54:13 -04:00
|
|
|
HIP_RETURN(ihipEventCreateWithFlags(event, 0));
|
2018-03-01 22:57:20 -05:00
|
|
|
}
|
|
|
|
|
|
2018-04-05 15:02:43 -04:00
|
|
|
hipError_t hipEventDestroy(hipEvent_t event) {
|
2018-03-01 22:57:20 -05:00
|
|
|
HIP_INIT_API(event);
|
|
|
|
|
|
2018-05-15 16:26:16 -04:00
|
|
|
if (event == nullptr) {
|
2018-08-14 18:54:13 -04:00
|
|
|
HIP_RETURN(hipErrorInvalidResourceHandle);
|
2018-05-15 16:26:16 -04:00
|
|
|
}
|
|
|
|
|
|
2018-05-01 18:10:09 -04:00
|
|
|
delete reinterpret_cast<hip::Event*>(event);
|
2018-04-05 15:02:43 -04:00
|
|
|
|
2018-08-14 18:54:13 -04:00
|
|
|
HIP_RETURN(hipSuccess);
|
2018-03-01 22:57:20 -05:00
|
|
|
}
|
|
|
|
|
|
2018-04-05 15:02:43 -04:00
|
|
|
hipError_t hipEventElapsedTime(float *ms, hipEvent_t start, hipEvent_t stop) {
|
2018-03-01 22:57:20 -05:00
|
|
|
HIP_INIT_API(ms, start, stop);
|
|
|
|
|
|
2018-05-15 16:26:16 -04:00
|
|
|
if (start == nullptr || stop == nullptr) {
|
2018-08-14 18:54:13 -04:00
|
|
|
HIP_RETURN(hipErrorInvalidResourceHandle);
|
2018-05-15 16:26:16 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
hip::Event* eStart = reinterpret_cast<hip::Event*>(start);
|
|
|
|
|
hip::Event* eStop = reinterpret_cast<hip::Event*>(stop);
|
|
|
|
|
|
|
|
|
|
if (eStart->event_ == nullptr ||
|
|
|
|
|
eStop->event_ == nullptr) {
|
2018-08-14 18:54:13 -04:00
|
|
|
HIP_RETURN(hipErrorInvalidResourceHandle);
|
2018-05-15 16:26:16 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ((eStart->flags | eStop->flags) & hipEventDisableTiming) {
|
2018-08-14 18:54:13 -04:00
|
|
|
HIP_RETURN(hipErrorInvalidResourceHandle);
|
2018-05-15 16:26:16 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (ihipEventQuery(start) == hipErrorNotReady ||
|
|
|
|
|
ihipEventQuery(stop) == hipErrorNotReady) {
|
2018-08-14 18:54:13 -04:00
|
|
|
HIP_RETURN(hipErrorNotReady);
|
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
|
|
|
}
|
|
|
|
|
|
2018-08-30 12:17:57 -04:00
|
|
|
*ms = static_cast<float>(static_cast<int64_t>(eStop->event_->profilingInfo().submitted_ -
|
|
|
|
|
eStart->event_->profilingInfo().submitted_))/1000000.f;
|
2018-05-15 16:26:16 -04:00
|
|
|
|
2018-08-14 18:54:13 -04:00
|
|
|
HIP_RETURN(hipSuccess);
|
2018-03-01 22:57:20 -05:00
|
|
|
}
|
|
|
|
|
|
2018-04-05 15:02:43 -04:00
|
|
|
hipError_t hipEventRecord(hipEvent_t event, hipStream_t stream) {
|
2018-03-01 22:57:20 -05:00
|
|
|
HIP_INIT_API(event, stream);
|
|
|
|
|
|
2018-05-15 16:26:16 -04:00
|
|
|
if (event == nullptr) {
|
2018-08-14 18:54:13 -04:00
|
|
|
HIP_RETURN(hipErrorInvalidResourceHandle);
|
2018-05-15 16:26:16 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
hip::Event* e = reinterpret_cast<hip::Event*>(event);
|
|
|
|
|
|
|
|
|
|
if (stream == nullptr) {
|
|
|
|
|
e->stream_ = hip::getNullStream();
|
|
|
|
|
} else {
|
|
|
|
|
e->stream_ = as_amd(reinterpret_cast<cl_command_queue>(stream))->asHostQueue();
|
|
|
|
|
}
|
2018-10-18 13:41:32 -04:00
|
|
|
|
|
|
|
|
amd::Command* command = e->stream_->getLastQueuedCommand(true);
|
2018-05-15 16:26:16 -04:00
|
|
|
|
2018-11-19 15:46:09 -05:00
|
|
|
if (command == nullptr) {
|
|
|
|
|
command = new amd::Marker(*e->stream_, true);
|
|
|
|
|
command->enqueue();
|
|
|
|
|
}
|
|
|
|
|
|
2018-05-15 16:26:16 -04:00
|
|
|
if (e->event_ != nullptr) {
|
|
|
|
|
e->event_->release();
|
|
|
|
|
}
|
2018-04-05 15:02:43 -04:00
|
|
|
|
2018-05-15 16:26:16 -04:00
|
|
|
e->event_ = &command->event();
|
|
|
|
|
|
2018-08-14 18:54:13 -04:00
|
|
|
HIP_RETURN(hipSuccess);
|
2018-03-01 22:57:20 -05:00
|
|
|
}
|
|
|
|
|
|
2018-04-05 15:02:43 -04:00
|
|
|
hipError_t hipEventSynchronize(hipEvent_t event) {
|
2018-03-01 22:57:20 -05:00
|
|
|
HIP_INIT_API(event);
|
|
|
|
|
|
2018-05-15 16:26:16 -04:00
|
|
|
if (event == nullptr) {
|
2018-08-14 18:54:13 -04:00
|
|
|
HIP_RETURN(hipErrorInvalidResourceHandle);
|
2018-05-15 16:26:16 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
hip::Event* e = reinterpret_cast<hip::Event*>(event);
|
|
|
|
|
|
|
|
|
|
if (e->event_ == nullptr) {
|
2018-08-14 18:54:13 -04:00
|
|
|
HIP_RETURN(hipErrorInvalidResourceHandle);
|
2018-05-15 16:26:16 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
e->event_->awaitCompletion();
|
2018-04-05 15:02:43 -04:00
|
|
|
|
2018-08-14 18:54:13 -04:00
|
|
|
HIP_RETURN(hipSuccess);
|
2018-04-05 15:02:43 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
hipError_t hipEventQuery(hipEvent_t event) {
|
|
|
|
|
HIP_INIT_API(event);
|
|
|
|
|
|
2018-08-14 18:54:13 -04:00
|
|
|
HIP_RETURN(ihipEventQuery(event));
|
2018-03-01 22:57:20 -05:00
|
|
|
}
|