hipEventElapsedTime should respect device (#1992)

Fixes SWDEV-228636.
Also added a unit test to verify this.

[ROCm/clr commit: 3523219b43]
This commit is contained in:
Sarbojit2019
2020-04-06 15:38:25 +05:30
کامیت شده توسط GitHub
والد 318fbce04d
کامیت 77fd519260
3فایلهای تغییر یافته به همراه113 افزوده شده و 2 حذف شده
@@ -30,7 +30,12 @@ THE SOFTWARE.
//---
ihipEvent_t::ihipEvent_t(unsigned flags) : _criticalData(this) { _flags = flags; };
ihipEvent_t::ihipEvent_t(unsigned flags) : _criticalData(this) {
_flags = flags;
GET_TLS();
auto ctx = ihipGetTlsDefaultCtx();
_deviceId = ctx == nullptr ? -1 : ctx->getDevice()->_deviceId;
};
// Attach to an existing completion future:
@@ -175,7 +180,9 @@ hipError_t hipEventElapsedTime(float* ms, hipEvent_t start, hipEvent_t stop) {
HIP_INIT_API(hipEventElapsedTime, ms, start, stop);
if (ms == nullptr) return ihipLogStatus(hipErrorInvalidValue);
if ((start == nullptr) || (stop == nullptr)) return ihipLogStatus(hipErrorInvalidHandle);
if ((start == nullptr) || (stop == nullptr) ||
(start->_deviceId != stop->_deviceId))
return ihipLogStatus(hipErrorInvalidHandle);
*ms = 0.0f;
auto startEcd = start->locked_copyCrit();
@@ -732,6 +732,7 @@ class ihipEvent_t {
public:
unsigned _flags;
int _deviceId;
private:
ihipEventCritical_t _criticalData;
@@ -0,0 +1,103 @@
/*
Copyright (c) 2020-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.
*/
/* HIT_START
* BUILD: %t %s ../../test_common.cpp NVCC_OPTIONS -std=c++11
* TEST: %t
* HIT_END
*/
#include "test_common.h"
void NegativeTests(){
// Null pointers
{
hipEvent_t start,end;
float tms = 1.0f;
HIPASSERT(hipEventElapsedTime(nullptr,start,end) == hipErrorInvalidValue);
#ifndef __HIP_PLATFORM_NVCC__
// On NVCC platform API throws seg fault hence skipping
HIPASSERT(hipEventElapsedTime(&tms,nullptr,end) == hipErrorInvalidHandle);
HIPASSERT(hipEventElapsedTime(&tms,start,nullptr) == hipErrorInvalidHandle);
#endif
}
// Event created using disabled timing
{
float timeElapsed = 1.0f;
hipEvent_t start, stop;
HIPCHECK(hipEventCreateWithFlags(&start,hipEventDisableTiming));
HIPCHECK(hipEventCreateWithFlags(&stop,hipEventDisableTiming));
HIPASSERT(hipEventElapsedTime(&timeElapsed, start, stop) == hipErrorInvalidHandle);
}
// events created different devices
{
int devCount = 0;
HIPCHECK(hipGetDeviceCount(&devCount));
if (devCount > 1){
// create event on dev=0
HIPCHECK(hipSetDevice(0));
hipEvent_t start;
HIPCHECK(hipEventCreate(&start));
// create event on dev=1
HIPCHECK(hipSetDevice(1));
hipEvent_t stop;
HIPCHECK(hipEventCreate(&stop));
HIPCHECK(hipEventRecord(start, nullptr));
HIPCHECK(hipEventSynchronize(start));
HIPCHECK(hipEventRecord(stop, nullptr));
HIPCHECK(hipEventSynchronize(stop));
float tElapsed = 1.0f;
HIPASSERT(hipEventElapsedTime(&tElapsed,start,stop) == hipErrorInvalidHandle);
}
}
}
void PositiveTest(){
hipEvent_t start;
HIPCHECK(hipEventCreate(&start));
hipEvent_t stop;
HIPCHECK(hipEventCreate(&stop));
HIPCHECK(hipEventRecord(start, nullptr));
HIPCHECK(hipEventSynchronize(start));
HIPCHECK(hipEventRecord(stop, nullptr));
HIPCHECK(hipEventSynchronize(stop));
float tElapsed = 1.0f;
HIPCHECK(hipEventElapsedTime(&tElapsed,start,stop));
}
int main(){
NegativeTests();
PositiveTest();
passed();
}