Skip to content

Commit 431e7dc

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 78e1b33 commit 431e7dc

File tree

10 files changed

+94
-80
lines changed

10 files changed

+94
-80
lines changed

include/ur_api.h

+13-11
Original file line numberDiff line numberDiff line change
@@ -7101,21 +7101,21 @@ typedef enum ur_event_info_t {
71017101
///////////////////////////////////////////////////////////////////////////////
71027102
/// @brief Profiling query information type
71037103
typedef enum ur_profiling_info_t {
7104-
/// [uint64_t] A 64-bit value of current device counter in nanoseconds
7105-
/// when the event is enqueued
7104+
/// [uint64_t][optional-query] A 64-bit value of current device counter in
7105+
/// nanoseconds when the event is enqueued
71067106
UR_PROFILING_INFO_COMMAND_QUEUED = 0,
7107-
/// [uint64_t] A 64-bit value of current device counter in nanoseconds
7108-
/// when the event is submitted
7107+
/// [uint64_t][optional-query] A 64-bit value of current device counter in
7108+
/// nanoseconds when the event is submitted
71097109
UR_PROFILING_INFO_COMMAND_SUBMIT = 1,
7110-
/// [uint64_t] A 64-bit value of current device counter in nanoseconds
7111-
/// when the event starts execution
7110+
/// [uint64_t][optional-query] A 64-bit value of current device counter in
7111+
/// nanoseconds when the event starts execution
71127112
UR_PROFILING_INFO_COMMAND_START = 2,
7113-
/// [uint64_t] A 64-bit value of current device counter in nanoseconds
7114-
/// when the event has finished execution
7113+
/// [uint64_t][optional-query] A 64-bit value of current device counter in
7114+
/// nanoseconds when the event has finished execution
71157115
UR_PROFILING_INFO_COMMAND_END = 3,
7116-
/// [uint64_t] A 64-bit value of current device counter in nanoseconds
7117-
/// when the event and any child events enqueued by this event on the
7118-
/// device have finished execution
7116+
/// [uint64_t][optional-query] A 64-bit value of current device counter in
7117+
/// nanoseconds when the event and any child events enqueued by this event
7118+
/// on the device have finished execution
71197119
UR_PROFILING_INFO_COMMAND_COMPLETE = 4,
71207120
/// @cond
71217121
UR_PROFILING_INFO_FORCE_UINT32 = 0x7fffffff
@@ -7189,6 +7189,8 @@ UR_APIEXPORT ur_result_t UR_APICALL urEventGetInfo(
71897189
/// - ::UR_RESULT_ERROR_INVALID_EVENT
71907190
/// - ::UR_RESULT_ERROR_OUT_OF_RESOURCES
71917191
/// - ::UR_RESULT_ERROR_OUT_OF_HOST_MEMORY
7192+
/// - ::UR_RESULT_ERROR_UNSUPPORTED_ENUMERATION
7193+
/// + If `propName` is not supported by the adapter.
71927194
UR_APIEXPORT ur_result_t UR_APICALL urEventGetProfilingInfo(
71937195
/// [in] handle of the event object
71947196
ur_event_handle_t hEvent,

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."

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
}

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
}

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;

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
}

source/loader/ur_libapi.cpp

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

source/ur_api.cpp

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

test/conformance/event/urEventGetProfilingInfo.cpp

+41-64
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

+12
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)