Skip to content

Commit 4b9b724

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 778085f commit 4b9b724

File tree

10 files changed

+93
-81
lines changed

10 files changed

+93
-81
lines changed

Diff for: include/ur_api.h

+13-11
Original file line numberDiff line numberDiff line change
@@ -5904,17 +5904,17 @@ typedef enum ur_event_info_t {
59045904
///////////////////////////////////////////////////////////////////////////////
59055905
/// @brief Profiling query information type
59065906
typedef enum ur_profiling_info_t {
5907-
UR_PROFILING_INFO_COMMAND_QUEUED = 0, ///< [uint64_t] A 64-bit value of current device counter in nanoseconds
5908-
///< when the event is enqueued
5909-
UR_PROFILING_INFO_COMMAND_SUBMIT = 1, ///< [uint64_t] A 64-bit value of current device counter in nanoseconds
5910-
///< when the event is submitted
5911-
UR_PROFILING_INFO_COMMAND_START = 2, ///< [uint64_t] A 64-bit value of current device counter in nanoseconds
5912-
///< when the event starts execution
5913-
UR_PROFILING_INFO_COMMAND_END = 3, ///< [uint64_t] A 64-bit value of current device counter in nanoseconds
5914-
///< when the event has finished execution
5915-
UR_PROFILING_INFO_COMMAND_COMPLETE = 4, ///< [uint64_t] A 64-bit value of current device counter in nanoseconds
5916-
///< when the event and any child events enqueued by this event on the
5917-
///< device have finished execution
5907+
UR_PROFILING_INFO_COMMAND_QUEUED = 0, ///< [uint64_t][optional-query] A 64-bit value of current device counter in
5908+
///< nanoseconds when the event is enqueued
5909+
UR_PROFILING_INFO_COMMAND_SUBMIT = 1, ///< [uint64_t][optional-query] A 64-bit value of current device counter in
5910+
///< nanoseconds when the event is submitted
5911+
UR_PROFILING_INFO_COMMAND_START = 2, ///< [uint64_t][optional-query] A 64-bit value of current device counter in
5912+
///< nanoseconds when the event starts execution
5913+
UR_PROFILING_INFO_COMMAND_END = 3, ///< [uint64_t][optional-query] A 64-bit value of current device counter in
5914+
///< nanoseconds when the event has finished execution
5915+
UR_PROFILING_INFO_COMMAND_COMPLETE = 4, ///< [uint64_t][optional-query] A 64-bit value of current device counter in
5916+
///< nanoseconds when the event and any child events enqueued by this event
5917+
///< on the device have finished execution
59185918
/// @cond
59195919
UR_PROFILING_INFO_FORCE_UINT32 = 0x7fffffff
59205920
/// @endcond
@@ -5982,6 +5982,8 @@ urEventGetInfo(
59825982
/// - ::UR_RESULT_ERROR_INVALID_EVENT
59835983
/// - ::UR_RESULT_ERROR_OUT_OF_RESOURCES
59845984
/// - ::UR_RESULT_ERROR_OUT_OF_HOST_MEMORY
5985+
/// - ::UR_RESULT_ERROR_UNSUPPORTED_ENUMERATION
5986+
/// + If `propName` is not supported by the adapter.
59855987
UR_APIEXPORT ur_result_t UR_APICALL
59865988
urEventGetProfilingInfo(
59875989
ur_event_handle_t hEvent, ///< [in] handle of the event object

Diff for: scripts/core/event.yml

+7-5
Original file line numberDiff line numberDiff line change
@@ -117,15 +117,15 @@ name: $x_profiling_info_t
117117
typed_etors: True
118118
etors:
119119
- name: COMMAND_QUEUED
120-
desc: "[uint64_t] A 64-bit value of current device counter in nanoseconds when the event is enqueued"
120+
desc: "[uint64_t][optional-query] A 64-bit value of current device counter in nanoseconds when the event is enqueued"
121121
- name: COMMAND_SUBMIT
122-
desc: "[uint64_t] A 64-bit value of current device counter in nanoseconds when the event is submitted"
122+
desc: "[uint64_t][optional-query] A 64-bit value of current device counter in nanoseconds when the event is submitted"
123123
- name: COMMAND_START
124-
desc: "[uint64_t] A 64-bit value of current device counter in nanoseconds when the event starts execution"
124+
desc: "[uint64_t][optional-query] A 64-bit value of current device counter in nanoseconds when the event starts execution"
125125
- name: COMMAND_END
126-
desc: "[uint64_t] A 64-bit value of current device counter in nanoseconds when the event has finished execution"
126+
desc: "[uint64_t][optional-query] A 64-bit value of current device counter in nanoseconds when the event has finished execution"
127127
- name: COMMAND_COMPLETE
128-
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"
128+
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"
129129
--- #--------------------------------------------------------------------------
130130
type: function
131131
desc: "Get event object information"
@@ -194,6 +194,8 @@ returns:
194194
- $X_RESULT_ERROR_INVALID_EVENT
195195
- $X_RESULT_ERROR_OUT_OF_RESOURCES
196196
- $X_RESULT_ERROR_OUT_OF_HOST_MEMORY
197+
- $X_RESULT_ERROR_UNSUPPORTED_ENUMERATION:
198+
- "If `propName` is not supported by the adapter."
197199
--- #--------------------------------------------------------------------------
198200
type: function
199201
desc: "Wait for a list of events to finish."

Diff for: 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
}

Diff for: 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
}

Diff for: source/adapters/level_zero/event.cpp

+12
Original file line numberDiff line numberDiff line change
@@ -603,6 +603,10 @@ ur_result_t urEventGetProfilingInfo(
603603

604604
return ReturnValue(ContextEndTime);
605605
}
606+
case UR_PROFILING_INFO_COMMAND_COMPLETE:
607+
logger::error("urEventGetProfilingInfo: "
608+
"UR_PROFILING_INFO_COMMAND_COMPLETE not supported");
609+
return UR_RESULT_ERROR_UNSUPPORTED_ENUMERATION;
606610
default:
607611
logger::error("urEventGetProfilingInfo: not supported ParamName");
608612
return UR_RESULT_ERROR_INVALID_VALUE;
@@ -666,6 +670,10 @@ ur_result_t urEventGetProfilingInfo(
666670
ContextEndTime *= ZeTimerResolution;
667671
return ReturnValue(ContextEndTime);
668672
}
673+
case UR_PROFILING_INFO_COMMAND_COMPLETE:
674+
logger::error("urEventGetProfilingInfo: "
675+
"UR_PROFILING_INFO_COMMAND_COMPLETE not supported");
676+
return UR_RESULT_ERROR_UNSUPPORTED_ENUMERATION;
669677
default:
670678
logger::error("urEventGetProfilingInfo: not supported ParamName");
671679
return UR_RESULT_ERROR_INVALID_VALUE;
@@ -709,6 +717,10 @@ ur_result_t urEventGetProfilingInfo(
709717
// enqueue.
710718
//
711719
return ReturnValue(uint64_t{0});
720+
case UR_PROFILING_INFO_COMMAND_COMPLETE:
721+
logger::error("urEventGetProfilingInfo: UR_PROFILING_INFO_COMMAND_COMPLETE "
722+
"not supported");
723+
return UR_RESULT_ERROR_UNSUPPORTED_ENUMERATION;
712724
default:
713725
logger::error("urEventGetProfilingInfo: not supported ParamName");
714726
return UR_RESULT_ERROR_INVALID_VALUE;

Diff for: 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
}

Diff for: source/loader/ur_libapi.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -4702,6 +4702,8 @@ ur_result_t UR_APICALL urEventGetInfo(
47024702
/// - ::UR_RESULT_ERROR_INVALID_EVENT
47034703
/// - ::UR_RESULT_ERROR_OUT_OF_RESOURCES
47044704
/// - ::UR_RESULT_ERROR_OUT_OF_HOST_MEMORY
4705+
/// - ::UR_RESULT_ERROR_UNSUPPORTED_ENUMERATION
4706+
/// + If `propName` is not supported by the adapter.
47054707
ur_result_t UR_APICALL urEventGetProfilingInfo(
47064708
ur_event_handle_t hEvent, ///< [in] handle of the event object
47074709
ur_profiling_info_t

Diff for: source/ur_api.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -3998,6 +3998,8 @@ ur_result_t UR_APICALL urEventGetInfo(
39983998
/// - ::UR_RESULT_ERROR_INVALID_EVENT
39993999
/// - ::UR_RESULT_ERROR_OUT_OF_RESOURCES
40004000
/// - ::UR_RESULT_ERROR_OUT_OF_HOST_MEMORY
4001+
/// - ::UR_RESULT_ERROR_UNSUPPORTED_ENUMERATION
4002+
/// + If `propName` is not supported by the adapter.
40014003
ur_result_t UR_APICALL urEventGetProfilingInfo(
40024004
ur_event_handle_t hEvent, ///< [in] handle of the event object
40034005
ur_profiling_info_t

Diff for: test/conformance/event/urEventGetProfilingInfo.cpp

+40-65
Original file line numberDiff line numberDiff line change
@@ -12,36 +12,19 @@ using urEventGetProfilingInfoTest =
1212
TEST_P(urEventGetProfilingInfoTest, Success) {
1313

1414
ur_profiling_info_t info_type = getParam();
15-
16-
if (info_type == UR_PROFILING_INFO_COMMAND_COMPLETE) {
17-
UUR_KNOWN_FAILURE_ON(uur::CUDA{}, uur::HIP{}, uur::LevelZero{},
18-
uur::NativeCPU{});
19-
}
20-
21-
if (info_type == UR_PROFILING_INFO_COMMAND_QUEUED) {
22-
UUR_KNOWN_FAILURE_ON(uur::LevelZero{}, uur::LevelZeroV2{},
23-
uur::NativeCPU{});
24-
}
25-
26-
if (info_type == UR_PROFILING_INFO_COMMAND_SUBMIT) {
27-
UUR_KNOWN_FAILURE_ON(uur::LevelZero{}, uur::LevelZeroV2{},
28-
uur::NativeCPU{});
29-
}
30-
3115
size_t size;
3216
ASSERT_SUCCESS_OR_OPTIONAL_QUERY(
3317
urEventGetProfilingInfo(event, info_type, 0, nullptr, &size),
3418
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 to equal
26+
// this value, but I assume that's so unlikely as to not worry about it
27+
ASSERT_NE(time, 0x12341234);
4528
}
4629

4730
UUR_DEVICE_TEST_SUITE_P(urEventGetProfilingInfoTest,
@@ -55,49 +38,41 @@ UUR_DEVICE_TEST_SUITE_P(urEventGetProfilingInfoTest,
5538
using urEventGetProfilingInfoWithTimingComparisonTest = uur::event::urEventTest;
5639

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

10378
UUR_INSTANTIATE_DEVICE_TEST_SUITE_P(

Diff for: test/conformance/testing/include/uur/optional_queries.h

+12
Original file line numberDiff line numberDiff line change
@@ -114,4 +114,16 @@ template <> inline bool isQueryOptional(ur_queue_info_t query) {
114114
query) != optional_ur_queue_info_t.end();
115115
}
116116

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

0 commit comments

Comments
 (0)