Skip to content

Commit 56bc47d

Browse files
committed
Make profiling info optional and update tests
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 4347037 commit 56bc47d

File tree

10 files changed

+94
-80
lines changed

10 files changed

+94
-80
lines changed

include/ur_api.h

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7089,21 +7089,21 @@ typedef enum ur_event_info_t {
70897089
///////////////////////////////////////////////////////////////////////////////
70907090
/// @brief Profiling query information type
70917091
typedef enum ur_profiling_info_t {
7092-
/// [uint64_t] A 64-bit value of current device counter in nanoseconds
7093-
/// when the event is enqueued
7092+
/// [uint64_t][optional-query] A 64-bit value of current device counter in
7093+
/// nanoseconds when the event is enqueued
70947094
UR_PROFILING_INFO_COMMAND_QUEUED = 0,
7095-
/// [uint64_t] A 64-bit value of current device counter in nanoseconds
7096-
/// when the event is submitted
7095+
/// [uint64_t][optional-query] A 64-bit value of current device counter in
7096+
/// nanoseconds when the event is submitted
70977097
UR_PROFILING_INFO_COMMAND_SUBMIT = 1,
7098-
/// [uint64_t] A 64-bit value of current device counter in nanoseconds
7099-
/// when the event starts execution
7098+
/// [uint64_t][optional-query] A 64-bit value of current device counter in
7099+
/// nanoseconds when the event starts execution
71007100
UR_PROFILING_INFO_COMMAND_START = 2,
7101-
/// [uint64_t] A 64-bit value of current device counter in nanoseconds
7102-
/// when the event has finished execution
7101+
/// [uint64_t][optional-query] A 64-bit value of current device counter in
7102+
/// nanoseconds when the event has finished execution
71037103
UR_PROFILING_INFO_COMMAND_END = 3,
7104-
/// [uint64_t] A 64-bit value of current device counter in nanoseconds
7105-
/// when the event and any child events enqueued by this event on the
7106-
/// device have finished execution
7104+
/// [uint64_t][optional-query] A 64-bit value of current device counter in
7105+
/// nanoseconds when the event and any child events enqueued by this event
7106+
/// on the device have finished execution
71077107
UR_PROFILING_INFO_COMMAND_COMPLETE = 4,
71087108
/// @cond
71097109
UR_PROFILING_INFO_FORCE_UINT32 = 0x7fffffff
@@ -7177,6 +7177,8 @@ UR_APIEXPORT ur_result_t UR_APICALL urEventGetInfo(
71777177
/// - ::UR_RESULT_ERROR_INVALID_EVENT
71787178
/// - ::UR_RESULT_ERROR_OUT_OF_RESOURCES
71797179
/// - ::UR_RESULT_ERROR_OUT_OF_HOST_MEMORY
7180+
/// - ::UR_RESULT_ERROR_UNSUPPORTED_ENUMERATION
7181+
/// + If `propName` is not supported by the adapter.
71807182
UR_APIEXPORT ur_result_t UR_APICALL urEventGetProfilingInfo(
71817183
/// [in] handle of the event object
71827184
ur_event_handle_t hEvent,

scripts/core/event.yml

Lines changed: 7 additions & 5 deletions
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."

source/adapters/cuda/event.cpp

Lines changed: 2 additions & 0 deletions
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
}

source/adapters/hip/event.cpp

Lines changed: 2 additions & 0 deletions
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
}

source/adapters/level_zero/event.cpp

Lines changed: 12 additions & 0 deletions
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;

source/adapters/native_cpu/event.cpp

Lines changed: 1 addition & 0 deletions
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
}

source/loader/ur_libapi.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4725,6 +4725,8 @@ ur_result_t UR_APICALL urEventGetInfo(
47254725
/// - ::UR_RESULT_ERROR_INVALID_EVENT
47264726
/// - ::UR_RESULT_ERROR_OUT_OF_RESOURCES
47274727
/// - ::UR_RESULT_ERROR_OUT_OF_HOST_MEMORY
4728+
/// - ::UR_RESULT_ERROR_UNSUPPORTED_ENUMERATION
4729+
/// + If `propName` is not supported by the adapter.
47284730
ur_result_t UR_APICALL urEventGetProfilingInfo(
47294731
/// [in] handle of the event object
47304732
ur_event_handle_t hEvent,

source/ur_api.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4130,6 +4130,8 @@ ur_result_t UR_APICALL urEventGetInfo(
41304130
/// - ::UR_RESULT_ERROR_INVALID_EVENT
41314131
/// - ::UR_RESULT_ERROR_OUT_OF_RESOURCES
41324132
/// - ::UR_RESULT_ERROR_OUT_OF_HOST_MEMORY
4133+
/// - ::UR_RESULT_ERROR_UNSUPPORTED_ENUMERATION
4134+
/// + If `propName` is not supported by the adapter.
41334135
ur_result_t UR_APICALL urEventGetProfilingInfo(
41344136
/// [in] handle of the event object
41354137
ur_event_handle_t hEvent,

test/conformance/event/urEventGetProfilingInfo.cpp

Lines changed: 41 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -13,35 +13,19 @@ using urEventGetProfilingInfoTest =
1313
TEST_P(urEventGetProfilingInfoTest, Success) {
1414

1515
ur_profiling_info_t info_type = getParam();
16-
17-
if (info_type == UR_PROFILING_INFO_COMMAND_COMPLETE) {
18-
UUR_KNOWN_FAILURE_ON(uur::CUDA{}, uur::HIP{}, uur::LevelZero{},
19-
uur::NativeCPU{});
20-
}
21-
22-
if (info_type == UR_PROFILING_INFO_COMMAND_QUEUED) {
23-
UUR_KNOWN_FAILURE_ON(uur::LevelZero{}, uur::LevelZeroV2{},
24-
uur::NativeCPU{});
25-
}
26-
27-
if (info_type == UR_PROFILING_INFO_COMMAND_SUBMIT) {
28-
UUR_KNOWN_FAILURE_ON(uur::LevelZero{}, uur::LevelZeroV2{},
29-
uur::NativeCPU{});
30-
}
31-
3216
size_t size;
3317
ASSERT_SUCCESS_OR_OPTIONAL_QUERY(
3418
urEventGetProfilingInfo(event, info_type, 0, nullptr, &size), info_type);
3519
ASSERT_EQ(size, 8);
3620

37-
std::vector<uint8_t> data(size);
21+
uint64_t time = 0x12341234;
3822
ASSERT_SUCCESS(
39-
urEventGetProfilingInfo(event, info_type, size, data.data(), nullptr));
23+
urEventGetProfilingInfo(event, info_type, size, &time, nullptr));
4024

41-
if (sizeof(size_t) == size) {
42-
auto returned_value = reinterpret_cast<size_t *>(data.data());
43-
ASSERT_NE(*returned_value, 0);
44-
}
25+
// Note: In theory it's possible for this test to run when the counter happens
26+
// to equal this value, but I assume that's so unlikely as to not worry about
27+
// it
28+
ASSERT_NE(time, 0x12341234);
4529
}
4630

4731
UUR_DEVICE_TEST_SUITE_P(urEventGetProfilingInfoTest,
@@ -55,48 +39,41 @@ UUR_DEVICE_TEST_SUITE_P(urEventGetProfilingInfoTest,
5539
using urEventGetProfilingInfoWithTimingComparisonTest = uur::event::urEventTest;
5640

5741
TEST_P(urEventGetProfilingInfoWithTimingComparisonTest, Success) {
58-
UUR_KNOWN_FAILURE_ON(uur::CUDA{}, uur::HIP{}, uur::LevelZero{},
59-
uur::LevelZeroV2{}, uur::NativeCPU{});
60-
61-
uint8_t size = 8;
62-
63-
std::vector<uint8_t> queued_data(size);
64-
ASSERT_SUCCESS(urEventGetProfilingInfo(event,
65-
UR_PROFILING_INFO_COMMAND_QUEUED, size,
66-
queued_data.data(), nullptr));
67-
auto queued_timing = reinterpret_cast<size_t *>(queued_data.data());
68-
ASSERT_NE(*queued_timing, 0);
69-
70-
std::vector<uint8_t> submit_data(size);
71-
ASSERT_SUCCESS(urEventGetProfilingInfo(event,
72-
UR_PROFILING_INFO_COMMAND_SUBMIT, size,
73-
submit_data.data(), nullptr));
74-
auto submit_timing = reinterpret_cast<size_t *>(submit_data.data());
75-
ASSERT_NE(*submit_timing, 0);
76-
77-
std::vector<uint8_t> start_data(size);
78-
ASSERT_SUCCESS(urEventGetProfilingInfo(event, UR_PROFILING_INFO_COMMAND_START,
79-
size, start_data.data(), nullptr));
80-
auto start_timing = reinterpret_cast<size_t *>(start_data.data());
81-
ASSERT_NE(*start_timing, 0);
82-
83-
std::vector<uint8_t> end_data(size);
84-
ASSERT_SUCCESS(urEventGetProfilingInfo(event, UR_PROFILING_INFO_COMMAND_END,
85-
size, end_data.data(), nullptr));
86-
auto end_timing = reinterpret_cast<size_t *>(end_data.data());
87-
ASSERT_NE(*end_timing, 0);
88-
89-
std::vector<uint8_t> complete_data(size);
90-
ASSERT_SUCCESS(urEventGetProfilingInfo(event,
91-
UR_PROFILING_INFO_COMMAND_COMPLETE,
92-
size, complete_data.data(), nullptr));
93-
auto complete_timing = reinterpret_cast<size_t *>(complete_data.data());
94-
ASSERT_NE(*complete_timing, 0);
95-
96-
ASSERT_LE(*queued_timing, *submit_timing);
97-
ASSERT_LT(*submit_timing, *start_timing);
98-
ASSERT_LT(*start_timing, *end_timing);
99-
ASSERT_LE(*end_timing, *complete_timing);
42+
// AMD devices may report a "start" time before the "submit" time
43+
UUR_KNOWN_FAILURE_ON(uur::HIP{});
44+
45+
// If a and b are supported, asserts that a <= b
46+
auto test_timing = [=](ur_profiling_info_t a, ur_profiling_info_t b) {
47+
std::stringstream trace{"Profiling Info: "};
48+
trace << a << " <= " << b;
49+
SCOPED_TRACE(trace.str());
50+
uint64_t a_time;
51+
auto result =
52+
urEventGetProfilingInfo(event, a, sizeof(a_time), &a_time, nullptr);
53+
if (result == UR_RESULT_ERROR_UNSUPPORTED_ENUMERATION) {
54+
return;
55+
}
56+
ASSERT_SUCCESS(result);
57+
58+
uint64_t b_time;
59+
result =
60+
urEventGetProfilingInfo(event, b, sizeof(b_time), &b_time, nullptr);
61+
if (result == UR_RESULT_ERROR_UNSUPPORTED_ENUMERATION) {
62+
return;
63+
}
64+
ASSERT_SUCCESS(result);
65+
66+
// Note: This assumes that the counter doesn't overflow
67+
ASSERT_LE(a_time, b_time);
68+
};
69+
70+
test_timing(UR_PROFILING_INFO_COMMAND_QUEUED,
71+
UR_PROFILING_INFO_COMMAND_SUBMIT);
72+
test_timing(UR_PROFILING_INFO_COMMAND_SUBMIT,
73+
UR_PROFILING_INFO_COMMAND_START);
74+
test_timing(UR_PROFILING_INFO_COMMAND_START, UR_PROFILING_INFO_COMMAND_END);
75+
test_timing(UR_PROFILING_INFO_COMMAND_END,
76+
UR_PROFILING_INFO_COMMAND_COMPLETE);
10077
}
10178

10279
UUR_INSTANTIATE_DEVICE_TEST_SUITE_P(

test/conformance/testing/include/uur/optional_queries.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,4 +116,16 @@ template <> inline bool isQueryOptional(ur_queue_info_t query) {
116116
query) != optional_ur_queue_info_t.end();
117117
}
118118

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

0 commit comments

Comments
 (0)