diff --git a/source/adapters/hip/device.cpp b/source/adapters/hip/device.cpp index 7cec6def8b..e2a54e8a66 100644 --- a/source/adapters/hip/device.cpp +++ b/source/adapters/hip/device.cpp @@ -939,15 +939,6 @@ ur_result_t UR_APICALL urDeviceGetGlobalTimestamps(ur_device_handle_t hDevice, if (pDeviceTimestamp) { UR_CHECK_ERROR(hipEventCreateWithFlags(&Event, hipEventDefault)); UR_CHECK_ERROR(hipEventRecord(Event)); - } - if (pHostTimestamp) { - using namespace std::chrono; - *pHostTimestamp = - duration_cast(steady_clock::now().time_since_epoch()) - .count(); - } - - if (pDeviceTimestamp) { UR_CHECK_ERROR(hipEventSynchronize(Event)); float ElapsedTime = 0.0f; UR_CHECK_ERROR(hipEventElapsedTime(&ElapsedTime, @@ -955,5 +946,11 @@ ur_result_t UR_APICALL urDeviceGetGlobalTimestamps(ur_device_handle_t hDevice, *pDeviceTimestamp = (uint64_t)(ElapsedTime * (double)1e6); } + if (pHostTimestamp) { + using namespace std::chrono; + *pHostTimestamp = + duration_cast(steady_clock::now().time_since_epoch()) + .count(); + } return UR_RESULT_SUCCESS; } diff --git a/source/adapters/hip/platform.cpp b/source/adapters/hip/platform.cpp index 139c59b89c..5f35b55f1f 100644 --- a/source/adapters/hip/platform.cpp +++ b/source/adapters/hip/platform.cpp @@ -9,6 +9,7 @@ //===----------------------------------------------------------------------===// #include "platform.hpp" +#include "context.hpp" hipEvent_t ur_platform_handle_t_::EvBase{nullptr}; @@ -90,6 +91,16 @@ urPlatformGet(ur_adapter_handle_t *, uint32_t, uint32_t NumEntries, PlatformIds[i].Devices.emplace_back( new ur_device_handle_t_{Device, Context, &PlatformIds[i]}); } + + // Setup EvBase + { + ScopedContext Active(PlatformIds.front().Devices.front().get()); + hipEvent_t EvBase; + UR_CHECK_ERROR(hipEventCreate(&EvBase)); + UR_CHECK_ERROR(hipEventRecord(EvBase, 0)); + + ur_platform_handle_t_::EvBase = EvBase; + } } catch (const std::bad_alloc &) { // Signal out-of-memory situation for (int i = 0; i < NumDevices; ++i) { diff --git a/test/conformance/device/device_adapter_hip.match b/test/conformance/device/device_adapter_hip.match index 478659b4e9..2e3deda8bc 100644 --- a/test/conformance/device/device_adapter_hip.match +++ b/test/conformance/device/device_adapter_hip.match @@ -1,6 +1,5 @@ {{OPT}}urDeviceCreateWithNativeHandleTest.Success {{OPT}}urDeviceGetTest.InvalidValueNumEntries -{{OPT}}urDeviceGetGlobalTimestampTest.Success {{OPT}}urDeviceGetGlobalTimestampTest.SuccessSynchronizedTime {{OPT}}urDeviceGetInfoTest.Success/UR_DEVICE_INFO_SINGLE_FP_CONFIG {{OPT}}urDeviceGetInfoTest.Success/UR_DEVICE_INFO_DOUBLE_FP_CONFIG