Skip to content

Commit a739d34

Browse files
authored
[UR] Make each profiling info variant for urEventGetProfilingInfo optional and improve its conformance test (#17067)
Migrated from oneapi-src/unified-runtime#2533 This patch turns all of the values returned by urEventGetProfilingInfo to be optional and updates adapters to handle this by returning the appropriate enum when it is not supported. The tests have also been updated, to ensure that returning a counter of "0" or values equal to the previous profiling event is no longer considered a failure.
1 parent 300059b commit a739d34

File tree

10 files changed

+85
-55
lines changed

10 files changed

+85
-55
lines changed

unified-runtime/include/ur_api.h

+13-11
Original file line numberDiff line numberDiff line change
@@ -7105,21 +7105,21 @@ typedef enum ur_event_info_t {
71057105
///////////////////////////////////////////////////////////////////////////////
71067106
/// @brief Profiling query information type
71077107
typedef enum ur_profiling_info_t {
7108-
/// [uint64_t] A 64-bit value of current device counter in nanoseconds
7109-
/// when the event is enqueued
7108+
/// [uint64_t][optional-query] A 64-bit value of current device counter in
7109+
/// nanoseconds when the event is enqueued
71107110
UR_PROFILING_INFO_COMMAND_QUEUED = 0,
7111-
/// [uint64_t] A 64-bit value of current device counter in nanoseconds
7112-
/// when the event is submitted
7111+
/// [uint64_t][optional-query] A 64-bit value of current device counter in
7112+
/// nanoseconds when the event is submitted
71137113
UR_PROFILING_INFO_COMMAND_SUBMIT = 1,
7114-
/// [uint64_t] A 64-bit value of current device counter in nanoseconds
7115-
/// when the event starts execution
7114+
/// [uint64_t][optional-query] A 64-bit value of current device counter in
7115+
/// nanoseconds when the event starts execution
71167116
UR_PROFILING_INFO_COMMAND_START = 2,
7117-
/// [uint64_t] A 64-bit value of current device counter in nanoseconds
7118-
/// when the event has finished execution
7117+
/// [uint64_t][optional-query] A 64-bit value of current device counter in
7118+
/// nanoseconds when the event has finished execution
71197119
UR_PROFILING_INFO_COMMAND_END = 3,
7120-
/// [uint64_t] A 64-bit value of current device counter in nanoseconds
7121-
/// when the event and any child events enqueued by this event on the
7122-
/// device have finished execution
7120+
/// [uint64_t][optional-query] A 64-bit value of current device counter in
7121+
/// nanoseconds when the event and any child events enqueued by this event
7122+
/// on the device have finished execution
71237123
UR_PROFILING_INFO_COMMAND_COMPLETE = 4,
71247124
/// @cond
71257125
UR_PROFILING_INFO_FORCE_UINT32 = 0x7fffffff
@@ -7193,6 +7193,8 @@ UR_APIEXPORT ur_result_t UR_APICALL urEventGetInfo(
71937193
/// - ::UR_RESULT_ERROR_INVALID_EVENT
71947194
/// - ::UR_RESULT_ERROR_OUT_OF_RESOURCES
71957195
/// - ::UR_RESULT_ERROR_OUT_OF_HOST_MEMORY
7196+
/// - ::UR_RESULT_ERROR_UNSUPPORTED_ENUMERATION
7197+
/// + If `propName` is not supported by the adapter.
71967198
UR_APIEXPORT ur_result_t UR_APICALL urEventGetProfilingInfo(
71977199
/// [in] handle of the event object
71987200
ur_event_handle_t hEvent,

unified-runtime/scripts/core/event.yml

+7-5
Original file line numberDiff line numberDiff line change
@@ -121,15 +121,15 @@ name: $x_profiling_info_t
121121
typed_etors: True
122122
etors:
123123
- name: COMMAND_QUEUED
124-
desc: "[uint64_t] A 64-bit value of current device counter in nanoseconds when the event is enqueued"
124+
desc: "[uint64_t][optional-query] A 64-bit value of current device counter in nanoseconds when the event is enqueued"
125125
- name: COMMAND_SUBMIT
126-
desc: "[uint64_t] A 64-bit value of current device counter in nanoseconds when the event is submitted"
126+
desc: "[uint64_t][optional-query] A 64-bit value of current device counter in nanoseconds when the event is submitted"
127127
- name: COMMAND_START
128-
desc: "[uint64_t] A 64-bit value of current device counter in nanoseconds when the event starts execution"
128+
desc: "[uint64_t][optional-query] A 64-bit value of current device counter in nanoseconds when the event starts execution"
129129
- name: COMMAND_END
130-
desc: "[uint64_t] A 64-bit value of current device counter in nanoseconds when the event has finished execution"
130+
desc: "[uint64_t][optional-query] A 64-bit value of current device counter in nanoseconds when the event has finished execution"
131131
- name: COMMAND_COMPLETE
132-
desc: "[uint64_t] A 64-bit value of current device counter in nanoseconds when the event and any child events enqueued by this event on the device have finished execution"
132+
desc: "[uint64_t][optional-query] A 64-bit value of current device counter in nanoseconds when the event and any child events enqueued by this event on the device have finished execution"
133133
--- #--------------------------------------------------------------------------
134134
type: function
135135
desc: "Get event object information"
@@ -198,6 +198,8 @@ returns:
198198
- $X_RESULT_ERROR_INVALID_EVENT
199199
- $X_RESULT_ERROR_OUT_OF_RESOURCES
200200
- $X_RESULT_ERROR_OUT_OF_HOST_MEMORY
201+
- $X_RESULT_ERROR_UNSUPPORTED_ENUMERATION:
202+
- "If `propName` is not supported by the adapter."
201203
--- #--------------------------------------------------------------------------
202204
type: function
203205
desc: "Wait for a list of events to finish."

unified-runtime/source/adapters/cuda/event.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,8 @@ UR_APIEXPORT ur_result_t UR_APICALL urEventGetProfilingInfo(
213213
return ReturnValue(static_cast<uint64_t>(hEvent->getStartTime()));
214214
case UR_PROFILING_INFO_COMMAND_END:
215215
return ReturnValue(static_cast<uint64_t>(hEvent->getEndTime()));
216+
case UR_PROFILING_INFO_COMMAND_COMPLETE:
217+
return UR_RESULT_ERROR_UNSUPPORTED_ENUMERATION;
216218
default:
217219
break;
218220
}

unified-runtime/source/adapters/hip/event.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,8 @@ UR_APIEXPORT ur_result_t UR_APICALL urEventGetProfilingInfo(
234234
return ReturnValue(static_cast<uint64_t>(hEvent->getStartTime()));
235235
case UR_PROFILING_INFO_COMMAND_END:
236236
return ReturnValue(static_cast<uint64_t>(hEvent->getEndTime()));
237+
case UR_PROFILING_INFO_COMMAND_COMPLETE:
238+
return UR_RESULT_ERROR_UNSUPPORTED_ENUMERATION;
237239
default:
238240
break;
239241
}

unified-runtime/source/adapters/level_zero/event.cpp

+12
Original file line numberDiff line numberDiff line change
@@ -609,6 +609,10 @@ ur_result_t urEventGetProfilingInfo(
609609

610610
return ReturnValue(ContextEndTime);
611611
}
612+
case UR_PROFILING_INFO_COMMAND_COMPLETE:
613+
logger::error("urEventGetProfilingInfo: "
614+
"UR_PROFILING_INFO_COMMAND_COMPLETE not supported");
615+
return UR_RESULT_ERROR_UNSUPPORTED_ENUMERATION;
612616
default:
613617
logger::error("urEventGetProfilingInfo: not supported ParamName");
614618
return UR_RESULT_ERROR_INVALID_VALUE;
@@ -672,6 +676,10 @@ ur_result_t urEventGetProfilingInfo(
672676
ContextEndTime *= ZeTimerResolution;
673677
return ReturnValue(ContextEndTime);
674678
}
679+
case UR_PROFILING_INFO_COMMAND_COMPLETE:
680+
logger::error("urEventGetProfilingInfo: "
681+
"UR_PROFILING_INFO_COMMAND_COMPLETE not supported");
682+
return UR_RESULT_ERROR_UNSUPPORTED_ENUMERATION;
675683
default:
676684
logger::error("urEventGetProfilingInfo: not supported ParamName");
677685
return UR_RESULT_ERROR_INVALID_VALUE;
@@ -715,6 +723,10 @@ ur_result_t urEventGetProfilingInfo(
715723
// enqueue.
716724
//
717725
return ReturnValue(uint64_t{0});
726+
case UR_PROFILING_INFO_COMMAND_COMPLETE:
727+
logger::error("urEventGetProfilingInfo: UR_PROFILING_INFO_COMMAND_COMPLETE "
728+
"not supported");
729+
return UR_RESULT_ERROR_UNSUPPORTED_ENUMERATION;
718730
default:
719731
logger::error("urEventGetProfilingInfo: not supported ParamName");
720732
return UR_RESULT_ERROR_INVALID_VALUE;

unified-runtime/source/adapters/native_cpu/event.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ UR_APIEXPORT ur_result_t UR_APICALL urEventGetProfilingInfo(
5252
case UR_PROFILING_INFO_COMMAND_QUEUED:
5353
case UR_PROFILING_INFO_COMMAND_SUBMIT:
5454
case UR_PROFILING_INFO_COMMAND_COMPLETE:
55+
return UR_RESULT_ERROR_UNSUPPORTED_ENUMERATION;
5556
default:
5657
break;
5758
}

unified-runtime/source/loader/ur_libapi.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -4733,6 +4733,8 @@ ur_result_t UR_APICALL urEventGetInfo(
47334733
/// - ::UR_RESULT_ERROR_INVALID_EVENT
47344734
/// - ::UR_RESULT_ERROR_OUT_OF_RESOURCES
47354735
/// - ::UR_RESULT_ERROR_OUT_OF_HOST_MEMORY
4736+
/// - ::UR_RESULT_ERROR_UNSUPPORTED_ENUMERATION
4737+
/// + If `propName` is not supported by the adapter.
47364738
ur_result_t UR_APICALL urEventGetProfilingInfo(
47374739
/// [in] handle of the event object
47384740
ur_event_handle_t hEvent,

unified-runtime/source/ur_api.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -4138,6 +4138,8 @@ ur_result_t UR_APICALL urEventGetInfo(
41384138
/// - ::UR_RESULT_ERROR_INVALID_EVENT
41394139
/// - ::UR_RESULT_ERROR_OUT_OF_RESOURCES
41404140
/// - ::UR_RESULT_ERROR_OUT_OF_HOST_MEMORY
4141+
/// - ::UR_RESULT_ERROR_UNSUPPORTED_ENUMERATION
4142+
/// + If `propName` is not supported by the adapter.
41414143
ur_result_t UR_APICALL urEventGetProfilingInfo(
41424144
/// [in] handle of the event object
41434145
ur_event_handle_t hEvent,

unified-runtime/test/conformance/event/urEventGetProfilingInfo.cpp

+32-39
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@ using urEventGetProfilingInfoTest = uur::event::urEventTest;
1111
UUR_INSTANTIATE_DEVICE_TEST_SUITE(urEventGetProfilingInfoTest);
1212

1313
TEST_P(urEventGetProfilingInfoTest, SuccessCommandQueued) {
14-
UUR_KNOWN_FAILURE_ON(uur::LevelZero{}, uur::LevelZeroV2{}, uur::NativeCPU{});
15-
1614
const ur_profiling_info_t property_name = UR_PROFILING_INFO_COMMAND_QUEUED;
1715
size_t property_size = 0;
1816

@@ -29,8 +27,6 @@ TEST_P(urEventGetProfilingInfoTest, SuccessCommandQueued) {
2927
}
3028

3129
TEST_P(urEventGetProfilingInfoTest, SuccessCommandSubmit) {
32-
UUR_KNOWN_FAILURE_ON(uur::LevelZero{}, uur::LevelZeroV2{}, uur::NativeCPU{});
33-
3430
const ur_profiling_info_t property_name = UR_PROFILING_INFO_COMMAND_SUBMIT;
3531
size_t property_size = 0;
3632

@@ -79,9 +75,6 @@ TEST_P(urEventGetProfilingInfoTest, SuccessCommandEnd) {
7975
}
8076

8177
TEST_P(urEventGetProfilingInfoTest, SuccessCommandComplete) {
82-
UUR_KNOWN_FAILURE_ON(uur::CUDA{}, uur::HIP{}, uur::LevelZero{},
83-
uur::NativeCPU{});
84-
8578
const ur_profiling_info_t property_name = UR_PROFILING_INFO_COMMAND_COMPLETE;
8679
size_t property_size = 0;
8780

@@ -98,41 +91,41 @@ TEST_P(urEventGetProfilingInfoTest, SuccessCommandComplete) {
9891
}
9992

10093
TEST_P(urEventGetProfilingInfoTest, Success) {
101-
UUR_KNOWN_FAILURE_ON(uur::CUDA{}, uur::HIP{}, uur::LevelZero{},
102-
uur::LevelZeroV2{}, uur::NativeCPU{});
103-
104-
uint8_t size = 8;
105-
106-
uint64_t queued_value = 0;
107-
ASSERT_SUCCESS(urEventGetProfilingInfo(
108-
event, UR_PROFILING_INFO_COMMAND_QUEUED, size, &queued_value, nullptr));
109-
ASSERT_NE(queued_value, 0);
110-
111-
uint64_t submit_value = 0;
112-
ASSERT_SUCCESS(urEventGetProfilingInfo(
113-
event, UR_PROFILING_INFO_COMMAND_SUBMIT, size, &submit_value, nullptr));
114-
ASSERT_NE(submit_value, 0);
115-
116-
uint64_t start_value = 0;
117-
ASSERT_SUCCESS(urEventGetProfilingInfo(event, UR_PROFILING_INFO_COMMAND_START,
118-
size, &start_value, nullptr));
119-
ASSERT_NE(start_value, 0);
94+
// AMD devices may report a "start" time before the "submit" time
95+
UUR_KNOWN_FAILURE_ON(uur::HIP{});
96+
97+
// If a and b are supported, asserts that a <= b
98+
auto test_timing = [=](ur_profiling_info_t a, ur_profiling_info_t b) {
99+
std::stringstream trace{"Profiling Info: "};
100+
trace << a << " <= " << b;
101+
SCOPED_TRACE(trace.str());
102+
uint64_t a_time;
103+
auto result =
104+
urEventGetProfilingInfo(event, a, sizeof(a_time), &a_time, nullptr);
105+
if (result == UR_RESULT_ERROR_UNSUPPORTED_ENUMERATION) {
106+
return;
107+
}
108+
ASSERT_SUCCESS(result);
120109

121-
uint64_t end_value = 0;
122-
ASSERT_SUCCESS(urEventGetProfilingInfo(event, UR_PROFILING_INFO_COMMAND_END,
123-
size, &end_value, nullptr));
124-
ASSERT_NE(end_value, 0);
110+
uint64_t b_time;
111+
result =
112+
urEventGetProfilingInfo(event, b, sizeof(b_time), &b_time, nullptr);
113+
if (result == UR_RESULT_ERROR_UNSUPPORTED_ENUMERATION) {
114+
return;
115+
}
116+
ASSERT_SUCCESS(result);
125117

126-
uint64_t complete_value = 0;
127-
ASSERT_SUCCESS(urEventGetProfilingInfo(event,
128-
UR_PROFILING_INFO_COMMAND_COMPLETE,
129-
size, &complete_value, nullptr));
130-
ASSERT_NE(complete_value, 0);
118+
// Note: This assumes that the counter doesn't overflow
119+
ASSERT_LE(a_time, b_time);
120+
};
131121

132-
ASSERT_LE(queued_value, submit_value);
133-
ASSERT_LT(submit_value, start_value);
134-
ASSERT_LT(start_value, end_value);
135-
ASSERT_LE(end_value, complete_value);
122+
test_timing(UR_PROFILING_INFO_COMMAND_QUEUED,
123+
UR_PROFILING_INFO_COMMAND_SUBMIT);
124+
test_timing(UR_PROFILING_INFO_COMMAND_SUBMIT,
125+
UR_PROFILING_INFO_COMMAND_START);
126+
test_timing(UR_PROFILING_INFO_COMMAND_START, UR_PROFILING_INFO_COMMAND_END);
127+
test_timing(UR_PROFILING_INFO_COMMAND_END,
128+
UR_PROFILING_INFO_COMMAND_COMPLETE);
136129
}
137130

138131
TEST_P(urEventGetProfilingInfoTest, InvalidNullHandle) {

unified-runtime/test/conformance/testing/include/uur/optional_queries.h

+12
Original file line numberDiff line numberDiff line change
@@ -117,4 +117,16 @@ template <> inline bool isQueryOptional(ur_queue_info_t query) {
117117
query) != optional_ur_queue_info_t.end();
118118
}
119119

120+
constexpr std::array optional_ur_profiling_info_t = {
121+
UR_PROFILING_INFO_COMMAND_QUEUED, UR_PROFILING_INFO_COMMAND_SUBMIT,
122+
UR_PROFILING_INFO_COMMAND_START, UR_PROFILING_INFO_COMMAND_END,
123+
UR_PROFILING_INFO_COMMAND_COMPLETE,
124+
};
125+
126+
template <> inline bool isQueryOptional(ur_profiling_info_t query) {
127+
return std::find(optional_ur_profiling_info_t.begin(),
128+
optional_ur_profiling_info_t.end(),
129+
query) != optional_ur_profiling_info_t.end();
130+
}
131+
120132
} // namespace uur

0 commit comments

Comments
 (0)