Skip to content

Commit c2a3cf7

Browse files
author
Hugh Delaney
committed
Move base event into device
1 parent 0de2831 commit c2a3cf7

File tree

4 files changed

+31
-42
lines changed

4 files changed

+31
-42
lines changed

sycl/plugins/unified_runtime/ur/adapters/hip/device.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,18 @@ int getAttribute(ur_device_handle_t Device, hipDeviceAttribute_t Attribute) {
1818
return Value;
1919
}
2020

21+
uint64_t ur_device_handle_t_::getElapsedTime(hipEvent_t Event) const {
22+
float MilliSeconds = 0.0f;
23+
24+
// hipEventSynchronize waits till the event is ready for call to
25+
// hipEventElapsedTime.
26+
UR_CHECK_ERROR(hipEventSynchronize(EvBase));
27+
UR_CHECK_ERROR(hipEventSynchronize(Event));
28+
UR_CHECK_ERROR(hipEventElapsedTime(&MilliSeconds, EvBase, Event));
29+
30+
return static_cast<uint64_t>(MilliSeconds * 1.0e6);
31+
}
32+
2133
UR_APIEXPORT ur_result_t UR_APICALL urDeviceGetInfo(ur_device_handle_t hDevice,
2234
ur_device_info_t propName,
2335
size_t propSize,

sycl/plugins/unified_runtime/ur/adapters/hip/device.hpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,15 @@ struct ur_device_handle_t_ {
2323
std::atomic_uint32_t RefCount;
2424
ur_platform_handle_t Platform;
2525
hipCtx_t HIPContext;
26+
hipEvent_t EvBase;
2627
size_t DeviceIndex; // The index of the device in the UR context
2728

2829
public:
2930
ur_device_handle_t_(native_type HipDevice, hipCtx_t Context,
30-
ur_platform_handle_t Platform, size_t DeviceIndex)
31+
ur_platform_handle_t Platform, size_t DeviceIndex,
32+
hipEvent_t EvBase)
3133
: HIPDevice(HipDevice), RefCount{1}, Platform(Platform),
32-
HIPContext(Context), DeviceIndex(DeviceIndex) {}
34+
HIPContext(Context), EvBase(EvBase), DeviceIndex(DeviceIndex) {}
3335

3436
~ur_device_handle_t_() {
3537
UR_CHECK_ERROR(hipDevicePrimaryCtxRelease(HIPDevice));
@@ -41,7 +43,9 @@ struct ur_device_handle_t_ {
4143

4244
ur_platform_handle_t getPlatform() const noexcept { return Platform; };
4345

44-
hipCtx_t getNativeContext() { return HIPContext; };
46+
uint64_t getElapsedTime(hipEvent_t) const;
47+
48+
hipCtx_t getNativeContext() const { return HIPContext; };
4549

4650
// Returns the index of the device in question relative to the other devices
4751
// in the platform

sycl/plugins/unified_runtime/ur/adapters/hip/event.cpp

Lines changed: 4 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -88,44 +88,13 @@ bool ur_event_handle_t_::isCompleted() const noexcept {
8888
}
8989

9090
uint64_t ur_event_handle_t_::getQueuedTime() const {
91-
float MilliSeconds = 0.0f;
9291
assert(isStarted());
93-
94-
// hipEventSynchronize waits till the event is ready for call to
95-
// hipEventElapsedTime.
96-
UR_CHECK_ERROR(hipEventSynchronize(EvStart));
97-
UR_CHECK_ERROR(hipEventSynchronize(EvEnd));
98-
99-
UR_CHECK_ERROR(hipEventElapsedTime(&MilliSeconds, EvStart, EvEnd));
100-
return static_cast<uint64_t>(MilliSeconds * 1.0e6);
101-
}
102-
103-
uint64_t ur_event_handle_t_::getStartTime() const {
104-
float MiliSeconds = 0.0f;
105-
assert(isStarted());
106-
107-
// hipEventSynchronize waits till the event is ready for call to
108-
// hipEventElapsedTime.
109-
UR_CHECK_ERROR(hipEventSynchronize(ur_platform_handle_t_::EvBase));
110-
UR_CHECK_ERROR(hipEventSynchronize(EvStart));
111-
112-
UR_CHECK_ERROR(hipEventElapsedTime(&MiliSeconds,
113-
ur_platform_handle_t_::EvBase, EvStart));
114-
return static_cast<uint64_t>(MiliSeconds * 1.0e6);
92+
return Queue->getDevice()->getElapsedTime(EvStart);
11593
}
11694

11795
uint64_t ur_event_handle_t_::getEndTime() const {
118-
float MiliSeconds = 0.0f;
11996
assert(isStarted() && isRecorded());
120-
121-
// hipEventSynchronize waits till the event is ready for call to
122-
// hipEventElapsedTime.
123-
UR_CHECK_ERROR(hipEventSynchronize(ur_platform_handle_t_::EvBase));
124-
UR_CHECK_ERROR(hipEventSynchronize(EvEnd));
125-
126-
UR_CHECK_ERROR(
127-
hipEventElapsedTime(&MiliSeconds, ur_platform_handle_t_::EvBase, EvEnd));
128-
return static_cast<uint64_t>(MiliSeconds * 1.0e6);
97+
return Queue->getDevice()->getElapsedTime(EvEnd);
12998
}
13099

131100
ur_result_t ur_event_handle_t_::record() {
@@ -249,11 +218,10 @@ UR_APIEXPORT ur_result_t UR_APICALL urEventGetProfilingInfo(
249218
UrReturnHelper ReturnValue(propValueSize, pPropValue, pPropValueSizeRet);
250219
switch (propName) {
251220
case UR_PROFILING_INFO_COMMAND_QUEUED:
252-
case UR_PROFILING_INFO_COMMAND_SUBMIT:
253221
// Note: No user for this case
254-
return ReturnValue(static_cast<uint64_t>(hEvent->getQueuedTime()));
222+
case UR_PROFILING_INFO_COMMAND_SUBMIT:
255223
case UR_PROFILING_INFO_COMMAND_START:
256-
return ReturnValue(static_cast<uint64_t>(hEvent->getStartTime()));
224+
return ReturnValue(static_cast<uint64_t>(hEvent->getQueuedTime()));
257225
case UR_PROFILING_INFO_COMMAND_END:
258226
return ReturnValue(static_cast<uint64_t>(hEvent->getEndTime()));
259227
default:

sycl/plugins/unified_runtime/ur/adapters/hip/platform.cpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,12 +74,17 @@ urPlatformGet(ur_adapter_handle_t *, uint32_t, uint32_t NumEntries,
7474
try {
7575
for (int i = 0; i < NumDevices; ++i) {
7676
hipDevice_t Device;
77-
Err = UR_CHECK_ERROR(hipDeviceGet(&Device, i));
77+
UR_CHECK_ERROR(hipDeviceGet(&Device, i));
7878
hipCtx_t Context;
79-
Err = UR_CHECK_ERROR(hipDevicePrimaryCtxRetain(&Context, Device));
79+
UR_CHECK_ERROR(hipDevicePrimaryCtxRetain(&Context, Device));
80+
UR_CHECK_ERROR(hipCtxSetCurrent(Context));
81+
hipEvent_t EvBase;
82+
UR_CHECK_ERROR(hipEventCreateWithFlags(&EvBase, hipEventDefault));
83+
UR_CHECK_ERROR(hipEventRecord(EvBase, 0));
84+
8085
Platform.Devices.emplace_back(
8186
std::make_unique<ur_device_handle_t_>(Device, Context,
82-
&Platform, i));
87+
&Platform, i, EvBase));
8388
}
8489
} catch (const std::bad_alloc &) {
8590
Platform.Devices.clear();

0 commit comments

Comments
 (0)