Skip to content

Commit 880d8d8

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 b2ac58f commit 880d8d8

15 files changed

+89
-80
lines changed

include/ur_api.h

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

scripts/core/event.yml

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

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
@@ -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;

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
@@ -4703,6 +4703,8 @@ ur_result_t UR_APICALL urEventGetInfo(
47034703
/// - ::UR_RESULT_ERROR_INVALID_EVENT
47044704
/// - ::UR_RESULT_ERROR_OUT_OF_RESOURCES
47054705
/// - ::UR_RESULT_ERROR_OUT_OF_HOST_MEMORY
4706+
/// - ::UR_RESULT_ERROR_UNSUPPORTED_ENUMERATION
4707+
/// + If `propName` is not supported by the adapter.
47064708
ur_result_t UR_APICALL urEventGetProfilingInfo(
47074709
ur_event_handle_t hEvent, ///< [in] handle of the event object
47084710
ur_profiling_info_t

source/ur_api.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3999,6 +3999,8 @@ ur_result_t UR_APICALL urEventGetInfo(
39993999
/// - ::UR_RESULT_ERROR_INVALID_EVENT
40004000
/// - ::UR_RESULT_ERROR_OUT_OF_RESOURCES
40014001
/// - ::UR_RESULT_ERROR_OUT_OF_HOST_MEMORY
4002+
/// - ::UR_RESULT_ERROR_UNSUPPORTED_ENUMERATION
4003+
/// + If `propName` is not supported by the adapter.
40024004
ur_result_t UR_APICALL urEventGetProfilingInfo(
40034005
ur_event_handle_t hEvent, ///< [in] handle of the event object
40044006
ur_profiling_info_t

test/conformance/event/event_adapter_cuda.match

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
urEventGetProfilingInfoTest.Success/*__UR_PROFILING_INFO_COMMAND_COMPLETE
2-
urEventGetProfilingInfoWithTimingComparisonTest.Success/*
31
urEventSetCallbackTest.Success/*
42
urEventSetCallbackTest.ValidateParameters/*
53
urEventSetCallbackTest.AllStates/*

test/conformance/event/event_adapter_hip.match

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
urEventGetProfilingInfoTest.Success/*__UR_PROFILING_INFO_COMMAND_COMPLETE
2-
urEventGetProfilingInfoWithTimingComparisonTest.Success/*
31
urEventSetCallbackTest.Success/*
42
urEventSetCallbackTest.ValidateParameters/*
53
urEventSetCallbackTest.AllStates/*

test/conformance/event/event_adapter_level_zero.match

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,3 @@
1-
{{OPT}}urEventGetInfoTest.Success/*__UR_EVENT_INFO_COMMAND_TYPE
2-
{{OPT}}urEventGetProfilingInfoTest.Success/*__UR_PROFILING_INFO_COMMAND_QUEUED
3-
{{OPT}}urEventGetProfilingInfoTest.Success/*__UR_PROFILING_INFO_COMMAND_SUBMIT
4-
{{OPT}}urEventGetProfilingInfoTest.Success/*__UR_PROFILING_INFO_COMMAND_COMPLETE
5-
{{OPT}}urEventGetProfilingInfoWithTimingComparisonTest.Success/*
61
urEventCreateWithNativeHandleTest.Success/*
72
urEventSetCallbackTest.AllStates/*
83
urEventSetCallbackTest.EventAlreadyCompleted/*

test/conformance/event/event_adapter_level_zero_v2.match

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
urEventGetProfilingInfoTest.Success/*__UR_PROFILING_INFO_COMMAND_QUEUED
2-
urEventGetProfilingInfoTest.Success/*__UR_PROFILING_INFO_COMMAND_SUBMIT
3-
urEventGetProfilingInfoWithTimingComparisonTest.Success/*
41
urEventSetCallbackTest.Success/*
52
urEventSetCallbackTest.ValidateParameters/*
63
urEventSetCallbackTest.AllStates/*

test/conformance/event/event_adapter_native_cpu.match

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
1-
urEventGetProfilingInfoTest.Success/*__UR_PROFILING_INFO_COMMAND_QUEUED
2-
urEventGetProfilingInfoTest.Success/*__UR_PROFILING_INFO_COMMAND_SUBMIT
3-
urEventGetProfilingInfoTest.Success/*__UR_PROFILING_INFO_COMMAND_COMPLETE
4-
urEventGetProfilingInfoWithTimingComparisonTest.Success/*
51
urEventGetProfilingInfoNegativeTest.InvalidNullHandle/*
62
urEventGetProfilingInfoNegativeTest.InvalidValue/*
73
urEventWaitTest.Success/*

test/conformance/event/urEventGetProfilingInfo.cpp

Lines changed: 36 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -4,27 +4,26 @@
44
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
55

66
#include "fixtures.h"
7+
#include "ur_api.h"
78

89
using urEventGetProfilingInfoTest =
910
uur::event::urEventTestWithParam<ur_profiling_info_t>;
1011

1112
TEST_P(urEventGetProfilingInfoTest, Success) {
12-
13-
ur_profiling_info_t info_type = getParam();
1413
size_t size;
14+
ur_profiling_info_t info_type = getParam();
1515
ASSERT_SUCCESS_OR_OPTIONAL_QUERY(
1616
urEventGetProfilingInfo(event, info_type, 0, nullptr, &size),
1717
info_type);
1818
ASSERT_EQ(size, 8);
1919

20-
std::vector<uint8_t> data(size);
20+
uint64_t time = 0x12341234;
2121
ASSERT_SUCCESS(
22-
urEventGetProfilingInfo(event, info_type, size, data.data(), nullptr));
22+
urEventGetProfilingInfo(event, info_type, size, &time, nullptr));
2323

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

3029
UUR_TEST_SUITE_P(urEventGetProfilingInfoTest,
@@ -38,46 +37,35 @@ UUR_TEST_SUITE_P(urEventGetProfilingInfoTest,
3837
using urEventGetProfilingInfoWithTimingComparisonTest = uur::event::urEventTest;
3938

4039
TEST_P(urEventGetProfilingInfoWithTimingComparisonTest, Success) {
41-
uint8_t size = 8;
42-
43-
std::vector<uint8_t> queued_data(size);
44-
ASSERT_SUCCESS(urEventGetProfilingInfo(event,
45-
UR_PROFILING_INFO_COMMAND_QUEUED,
46-
size, queued_data.data(), nullptr));
47-
auto queued_timing = reinterpret_cast<size_t *>(queued_data.data());
48-
ASSERT_NE(*queued_timing, 0);
49-
50-
std::vector<uint8_t> submit_data(size);
51-
ASSERT_SUCCESS(urEventGetProfilingInfo(event,
52-
UR_PROFILING_INFO_COMMAND_SUBMIT,
53-
size, submit_data.data(), nullptr));
54-
auto submit_timing = reinterpret_cast<size_t *>(submit_data.data());
55-
ASSERT_NE(*submit_timing, 0);
56-
57-
std::vector<uint8_t> start_data(size);
58-
ASSERT_SUCCESS(urEventGetProfilingInfo(event,
59-
UR_PROFILING_INFO_COMMAND_START,
60-
size, start_data.data(), nullptr));
61-
auto start_timing = reinterpret_cast<size_t *>(start_data.data());
62-
ASSERT_NE(*start_timing, 0);
63-
64-
std::vector<uint8_t> end_data(size);
65-
ASSERT_SUCCESS(urEventGetProfilingInfo(event, UR_PROFILING_INFO_COMMAND_END,
66-
size, end_data.data(), nullptr));
67-
auto end_timing = reinterpret_cast<size_t *>(end_data.data());
68-
ASSERT_NE(*end_timing, 0);
69-
70-
std::vector<uint8_t> complete_data(size);
71-
ASSERT_SUCCESS(
72-
urEventGetProfilingInfo(event, UR_PROFILING_INFO_COMMAND_COMPLETE, size,
73-
complete_data.data(), nullptr));
74-
auto complete_timing = reinterpret_cast<size_t *>(complete_data.data());
75-
ASSERT_NE(*complete_timing, 0);
76-
77-
ASSERT_LE(*queued_timing, *submit_timing);
78-
ASSERT_LT(*submit_timing, *start_timing);
79-
ASSERT_LT(*start_timing, *end_timing);
80-
ASSERT_LE(*end_timing, *complete_timing);
40+
// If a and b are supported, asserts that a <= b
41+
auto test_timing = [=](ur_profiling_info_t a, ur_profiling_info_t b) {
42+
uint64_t a_time;
43+
auto result =
44+
urEventGetProfilingInfo(event, a, sizeof(a_time), &a_time, nullptr);
45+
if (result == UR_RESULT_ERROR_UNSUPPORTED_ENUMERATION) {
46+
return;
47+
}
48+
ASSERT_SUCCESS(result);
49+
50+
uint64_t b_time;
51+
result =
52+
urEventGetProfilingInfo(event, b, sizeof(b_time), &b_time, nullptr);
53+
if (result == UR_RESULT_ERROR_UNSUPPORTED_ENUMERATION) {
54+
return;
55+
}
56+
ASSERT_SUCCESS(result);
57+
58+
// Note: This assumes that the counter doesn't overflow
59+
ASSERT_LE(a_time, b_time);
60+
};
61+
62+
test_timing(UR_PROFILING_INFO_COMMAND_QUEUED,
63+
UR_PROFILING_INFO_COMMAND_SUBMIT);
64+
test_timing(UR_PROFILING_INFO_COMMAND_SUBMIT,
65+
UR_PROFILING_INFO_COMMAND_START);
66+
test_timing(UR_PROFILING_INFO_COMMAND_START, UR_PROFILING_INFO_COMMAND_END);
67+
test_timing(UR_PROFILING_INFO_COMMAND_END,
68+
UR_PROFILING_INFO_COMMAND_COMPLETE);
8169
}
8270

8371
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
@@ -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)