Skip to content

Commit de7c66e

Browse files
author
Konrad Kusiak
committed
Moved creating events to makeNative instead of the constructor
1 parent e5827d4 commit de7c66e

File tree

2 files changed

+20
-18
lines changed

2 files changed

+20
-18
lines changed

source/adapters/hip/event.cpp

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -16,23 +16,13 @@
1616
ur_event_handle_t_::ur_event_handle_t_(ur_command_t Type,
1717
ur_context_handle_t Context,
1818
ur_queue_handle_t Queue,
19-
hipStream_t Stream, uint32_t StreamToken)
19+
hipEvent_t EvEnd, hipEvent_t EvQueued,
20+
hipEvent_t EvStart, hipStream_t Stream,
21+
uint32_t StreamToken)
2022
: CommandType{Type}, RefCount{1}, HasOwnership{true},
2123
HasBeenWaitedOn{false}, IsRecorded{false}, IsStarted{false},
22-
StreamToken{StreamToken}, EventId{0}, EvEnd{nullptr}, EvStart{nullptr},
23-
EvQueued{nullptr}, Queue{Queue}, Stream{Stream}, Context{Context} {
24-
25-
bool ProfilingEnabled =
26-
Queue->URFlags & UR_QUEUE_FLAG_PROFILING_ENABLE || isTimestampEvent();
27-
28-
UR_CHECK_ERROR(hipEventCreateWithFlags(
29-
&EvEnd, ProfilingEnabled ? hipEventDefault : hipEventDisableTiming));
30-
31-
if (ProfilingEnabled) {
32-
UR_CHECK_ERROR(hipEventCreateWithFlags(&EvQueued, hipEventDefault));
33-
UR_CHECK_ERROR(hipEventCreateWithFlags(&EvStart, hipEventDefault));
34-
}
35-
24+
StreamToken{StreamToken}, EventId{0}, EvEnd{EvEnd}, EvQueued{EvQueued},
25+
EvStart{EvStart}, Queue{Queue}, Stream{Stream}, Context{Context} {
3626
urQueueRetain(Queue);
3727
urContextRetain(Context);
3828
}
@@ -62,7 +52,7 @@ ur_result_t ur_event_handle_t_::start() {
6252
if (Queue->URFlags & UR_QUEUE_FLAG_PROFILING_ENABLE || isTimestampEvent()) {
6353
// NOTE: This relies on the default stream to be unused.
6454
UR_CHECK_ERROR(hipEventRecord(EvQueued, 0));
65-
UR_CHECK_ERROR(hipEventRecord(EvStart, Queue->get()));
55+
UR_CHECK_ERROR(hipEventRecord(EvStart, Stream));
6656
}
6757
} catch (ur_result_t Error) {
6858
Result = Error;

source/adapters/hip/event.hpp

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,20 @@ struct ur_event_handle_t_ {
8080
static ur_event_handle_t
8181
makeNative(ur_command_t Type, ur_queue_handle_t Queue, hipStream_t Stream,
8282
uint32_t StreamToken = std::numeric_limits<uint32_t>::max()) {
83-
return new ur_event_handle_t_(Type, Queue->getContext(), Queue, Stream,
84-
StreamToken);
83+
const bool RequiresTimings =
84+
Queue->URFlags & UR_QUEUE_FLAG_PROFILING_ENABLE ||
85+
Type == UR_COMMAND_TIMESTAMP_RECORDING_EXP;
86+
native_type EvEnd{nullptr}, EvQueued{nullptr}, EvStart{nullptr};
87+
UR_CHECK_ERROR(hipEventCreateWithFlags(
88+
&EvEnd, RequiresTimings ? hipEventDefault : hipEventDisableTiming));
89+
90+
if (RequiresTimings) {
91+
UR_CHECK_ERROR(hipEventCreateWithFlags(&EvQueued, hipEventDefault));
92+
UR_CHECK_ERROR(hipEventCreateWithFlags(&EvStart, hipEventDefault));
93+
}
94+
95+
return new ur_event_handle_t_(Type, Queue->getContext(), Queue, EvEnd,
96+
EvQueued, EvStart, Stream, StreamToken);
8597
}
8698

8799
static ur_event_handle_t makeWithNative(ur_context_handle_t context,

0 commit comments

Comments
 (0)