Skip to content

Commit

Permalink
Make profiling info optional and update tests
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
RossBrunton committed Jan 20, 2025
1 parent 4347037 commit 56bc47d
Show file tree
Hide file tree
Showing 10 changed files with 94 additions and 80 deletions.
24 changes: 13 additions & 11 deletions include/ur_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -7089,21 +7089,21 @@ typedef enum ur_event_info_t {
///////////////////////////////////////////////////////////////////////////////
/// @brief Profiling query information type
typedef enum ur_profiling_info_t {
/// [uint64_t] A 64-bit value of current device counter in nanoseconds
/// when the event is enqueued
/// [uint64_t][optional-query] A 64-bit value of current device counter in
/// nanoseconds when the event is enqueued
UR_PROFILING_INFO_COMMAND_QUEUED = 0,
/// [uint64_t] A 64-bit value of current device counter in nanoseconds
/// when the event is submitted
/// [uint64_t][optional-query] A 64-bit value of current device counter in
/// nanoseconds when the event is submitted
UR_PROFILING_INFO_COMMAND_SUBMIT = 1,
/// [uint64_t] A 64-bit value of current device counter in nanoseconds
/// when the event starts execution
/// [uint64_t][optional-query] A 64-bit value of current device counter in
/// nanoseconds when the event starts execution
UR_PROFILING_INFO_COMMAND_START = 2,
/// [uint64_t] A 64-bit value of current device counter in nanoseconds
/// when the event has finished execution
/// [uint64_t][optional-query] A 64-bit value of current device counter in
/// nanoseconds when the event has finished execution
UR_PROFILING_INFO_COMMAND_END = 3,
/// [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
/// [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
UR_PROFILING_INFO_COMMAND_COMPLETE = 4,
/// @cond
UR_PROFILING_INFO_FORCE_UINT32 = 0x7fffffff
Expand Down Expand Up @@ -7177,6 +7177,8 @@ UR_APIEXPORT ur_result_t UR_APICALL urEventGetInfo(
/// - ::UR_RESULT_ERROR_INVALID_EVENT
/// - ::UR_RESULT_ERROR_OUT_OF_RESOURCES
/// - ::UR_RESULT_ERROR_OUT_OF_HOST_MEMORY
/// - ::UR_RESULT_ERROR_UNSUPPORTED_ENUMERATION
/// + If `propName` is not supported by the adapter.
UR_APIEXPORT ur_result_t UR_APICALL urEventGetProfilingInfo(
/// [in] handle of the event object
ur_event_handle_t hEvent,
Expand Down
12 changes: 7 additions & 5 deletions scripts/core/event.yml
Original file line number Diff line number Diff line change
Expand Up @@ -121,15 +121,15 @@ name: $x_profiling_info_t
typed_etors: True
etors:
- name: COMMAND_QUEUED
desc: "[uint64_t] A 64-bit value of current device counter in nanoseconds when the event is enqueued"
desc: "[uint64_t][optional-query] A 64-bit value of current device counter in nanoseconds when the event is enqueued"
- name: COMMAND_SUBMIT
desc: "[uint64_t] A 64-bit value of current device counter in nanoseconds when the event is submitted"
desc: "[uint64_t][optional-query] A 64-bit value of current device counter in nanoseconds when the event is submitted"
- name: COMMAND_START
desc: "[uint64_t] A 64-bit value of current device counter in nanoseconds when the event starts execution"
desc: "[uint64_t][optional-query] A 64-bit value of current device counter in nanoseconds when the event starts execution"
- name: COMMAND_END
desc: "[uint64_t] A 64-bit value of current device counter in nanoseconds when the event has finished execution"
desc: "[uint64_t][optional-query] A 64-bit value of current device counter in nanoseconds when the event has finished execution"
- name: COMMAND_COMPLETE
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"
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"
--- #--------------------------------------------------------------------------
type: function
desc: "Get event object information"
Expand Down Expand Up @@ -198,6 +198,8 @@ returns:
- $X_RESULT_ERROR_INVALID_EVENT
- $X_RESULT_ERROR_OUT_OF_RESOURCES
- $X_RESULT_ERROR_OUT_OF_HOST_MEMORY
- $X_RESULT_ERROR_UNSUPPORTED_ENUMERATION:
- "If `propName` is not supported by the adapter."
--- #--------------------------------------------------------------------------
type: function
desc: "Wait for a list of events to finish."
Expand Down
2 changes: 2 additions & 0 deletions source/adapters/cuda/event.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,8 @@ UR_APIEXPORT ur_result_t UR_APICALL urEventGetProfilingInfo(
return ReturnValue(static_cast<uint64_t>(hEvent->getStartTime()));
case UR_PROFILING_INFO_COMMAND_END:
return ReturnValue(static_cast<uint64_t>(hEvent->getEndTime()));
case UR_PROFILING_INFO_COMMAND_COMPLETE:
return UR_RESULT_ERROR_UNSUPPORTED_ENUMERATION;
default:
break;
}
Expand Down
2 changes: 2 additions & 0 deletions source/adapters/hip/event.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,8 @@ UR_APIEXPORT ur_result_t UR_APICALL urEventGetProfilingInfo(
return ReturnValue(static_cast<uint64_t>(hEvent->getStartTime()));
case UR_PROFILING_INFO_COMMAND_END:
return ReturnValue(static_cast<uint64_t>(hEvent->getEndTime()));
case UR_PROFILING_INFO_COMMAND_COMPLETE:
return UR_RESULT_ERROR_UNSUPPORTED_ENUMERATION;
default:
break;
}
Expand Down
12 changes: 12 additions & 0 deletions source/adapters/level_zero/event.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -609,6 +609,10 @@ ur_result_t urEventGetProfilingInfo(

return ReturnValue(ContextEndTime);
}
case UR_PROFILING_INFO_COMMAND_COMPLETE:
logger::error("urEventGetProfilingInfo: "
"UR_PROFILING_INFO_COMMAND_COMPLETE not supported");
return UR_RESULT_ERROR_UNSUPPORTED_ENUMERATION;
default:
logger::error("urEventGetProfilingInfo: not supported ParamName");
return UR_RESULT_ERROR_INVALID_VALUE;
Expand Down Expand Up @@ -672,6 +676,10 @@ ur_result_t urEventGetProfilingInfo(
ContextEndTime *= ZeTimerResolution;
return ReturnValue(ContextEndTime);
}
case UR_PROFILING_INFO_COMMAND_COMPLETE:
logger::error("urEventGetProfilingInfo: "
"UR_PROFILING_INFO_COMMAND_COMPLETE not supported");
return UR_RESULT_ERROR_UNSUPPORTED_ENUMERATION;
default:
logger::error("urEventGetProfilingInfo: not supported ParamName");
return UR_RESULT_ERROR_INVALID_VALUE;
Expand Down Expand Up @@ -715,6 +723,10 @@ ur_result_t urEventGetProfilingInfo(
// enqueue.
//
return ReturnValue(uint64_t{0});
case UR_PROFILING_INFO_COMMAND_COMPLETE:
logger::error("urEventGetProfilingInfo: UR_PROFILING_INFO_COMMAND_COMPLETE "
"not supported");
return UR_RESULT_ERROR_UNSUPPORTED_ENUMERATION;
default:
logger::error("urEventGetProfilingInfo: not supported ParamName");
return UR_RESULT_ERROR_INVALID_VALUE;
Expand Down
1 change: 1 addition & 0 deletions source/adapters/native_cpu/event.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ UR_APIEXPORT ur_result_t UR_APICALL urEventGetProfilingInfo(
case UR_PROFILING_INFO_COMMAND_QUEUED:
case UR_PROFILING_INFO_COMMAND_SUBMIT:
case UR_PROFILING_INFO_COMMAND_COMPLETE:
return UR_RESULT_ERROR_UNSUPPORTED_ENUMERATION;
default:
break;
}
Expand Down
2 changes: 2 additions & 0 deletions source/loader/ur_libapi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4725,6 +4725,8 @@ ur_result_t UR_APICALL urEventGetInfo(
/// - ::UR_RESULT_ERROR_INVALID_EVENT
/// - ::UR_RESULT_ERROR_OUT_OF_RESOURCES
/// - ::UR_RESULT_ERROR_OUT_OF_HOST_MEMORY
/// - ::UR_RESULT_ERROR_UNSUPPORTED_ENUMERATION
/// + If `propName` is not supported by the adapter.
ur_result_t UR_APICALL urEventGetProfilingInfo(
/// [in] handle of the event object
ur_event_handle_t hEvent,
Expand Down
2 changes: 2 additions & 0 deletions source/ur_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4130,6 +4130,8 @@ ur_result_t UR_APICALL urEventGetInfo(
/// - ::UR_RESULT_ERROR_INVALID_EVENT
/// - ::UR_RESULT_ERROR_OUT_OF_RESOURCES
/// - ::UR_RESULT_ERROR_OUT_OF_HOST_MEMORY
/// - ::UR_RESULT_ERROR_UNSUPPORTED_ENUMERATION
/// + If `propName` is not supported by the adapter.
ur_result_t UR_APICALL urEventGetProfilingInfo(
/// [in] handle of the event object
ur_event_handle_t hEvent,
Expand Down
105 changes: 41 additions & 64 deletions test/conformance/event/urEventGetProfilingInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,35 +13,19 @@ using urEventGetProfilingInfoTest =
TEST_P(urEventGetProfilingInfoTest, Success) {

ur_profiling_info_t info_type = getParam();

if (info_type == UR_PROFILING_INFO_COMMAND_COMPLETE) {
UUR_KNOWN_FAILURE_ON(uur::CUDA{}, uur::HIP{}, uur::LevelZero{},
uur::NativeCPU{});
}

if (info_type == UR_PROFILING_INFO_COMMAND_QUEUED) {
UUR_KNOWN_FAILURE_ON(uur::LevelZero{}, uur::LevelZeroV2{},
uur::NativeCPU{});
}

if (info_type == UR_PROFILING_INFO_COMMAND_SUBMIT) {
UUR_KNOWN_FAILURE_ON(uur::LevelZero{}, uur::LevelZeroV2{},
uur::NativeCPU{});
}

size_t size;
ASSERT_SUCCESS_OR_OPTIONAL_QUERY(
urEventGetProfilingInfo(event, info_type, 0, nullptr, &size), info_type);
ASSERT_EQ(size, 8);

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

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

UUR_DEVICE_TEST_SUITE_P(urEventGetProfilingInfoTest,
Expand All @@ -55,48 +39,41 @@ UUR_DEVICE_TEST_SUITE_P(urEventGetProfilingInfoTest,
using urEventGetProfilingInfoWithTimingComparisonTest = uur::event::urEventTest;

TEST_P(urEventGetProfilingInfoWithTimingComparisonTest, Success) {
UUR_KNOWN_FAILURE_ON(uur::CUDA{}, uur::HIP{}, uur::LevelZero{},
uur::LevelZeroV2{}, uur::NativeCPU{});

uint8_t size = 8;

std::vector<uint8_t> queued_data(size);
ASSERT_SUCCESS(urEventGetProfilingInfo(event,
UR_PROFILING_INFO_COMMAND_QUEUED, size,
queued_data.data(), nullptr));
auto queued_timing = reinterpret_cast<size_t *>(queued_data.data());
ASSERT_NE(*queued_timing, 0);

std::vector<uint8_t> submit_data(size);
ASSERT_SUCCESS(urEventGetProfilingInfo(event,
UR_PROFILING_INFO_COMMAND_SUBMIT, size,
submit_data.data(), nullptr));
auto submit_timing = reinterpret_cast<size_t *>(submit_data.data());
ASSERT_NE(*submit_timing, 0);

std::vector<uint8_t> start_data(size);
ASSERT_SUCCESS(urEventGetProfilingInfo(event, UR_PROFILING_INFO_COMMAND_START,
size, start_data.data(), nullptr));
auto start_timing = reinterpret_cast<size_t *>(start_data.data());
ASSERT_NE(*start_timing, 0);

std::vector<uint8_t> end_data(size);
ASSERT_SUCCESS(urEventGetProfilingInfo(event, UR_PROFILING_INFO_COMMAND_END,
size, end_data.data(), nullptr));
auto end_timing = reinterpret_cast<size_t *>(end_data.data());
ASSERT_NE(*end_timing, 0);

std::vector<uint8_t> complete_data(size);
ASSERT_SUCCESS(urEventGetProfilingInfo(event,
UR_PROFILING_INFO_COMMAND_COMPLETE,
size, complete_data.data(), nullptr));
auto complete_timing = reinterpret_cast<size_t *>(complete_data.data());
ASSERT_NE(*complete_timing, 0);

ASSERT_LE(*queued_timing, *submit_timing);
ASSERT_LT(*submit_timing, *start_timing);
ASSERT_LT(*start_timing, *end_timing);
ASSERT_LE(*end_timing, *complete_timing);
// AMD devices may report a "start" time before the "submit" time
UUR_KNOWN_FAILURE_ON(uur::HIP{});

// If a and b are supported, asserts that a <= b
auto test_timing = [=](ur_profiling_info_t a, ur_profiling_info_t b) {
std::stringstream trace{"Profiling Info: "};
trace << a << " <= " << b;
SCOPED_TRACE(trace.str());
uint64_t a_time;
auto result =
urEventGetProfilingInfo(event, a, sizeof(a_time), &a_time, nullptr);
if (result == UR_RESULT_ERROR_UNSUPPORTED_ENUMERATION) {
return;
}
ASSERT_SUCCESS(result);

uint64_t b_time;
result =
urEventGetProfilingInfo(event, b, sizeof(b_time), &b_time, nullptr);
if (result == UR_RESULT_ERROR_UNSUPPORTED_ENUMERATION) {
return;
}
ASSERT_SUCCESS(result);

// Note: This assumes that the counter doesn't overflow
ASSERT_LE(a_time, b_time);
};

test_timing(UR_PROFILING_INFO_COMMAND_QUEUED,
UR_PROFILING_INFO_COMMAND_SUBMIT);
test_timing(UR_PROFILING_INFO_COMMAND_SUBMIT,
UR_PROFILING_INFO_COMMAND_START);
test_timing(UR_PROFILING_INFO_COMMAND_START, UR_PROFILING_INFO_COMMAND_END);
test_timing(UR_PROFILING_INFO_COMMAND_END,
UR_PROFILING_INFO_COMMAND_COMPLETE);
}

UUR_INSTANTIATE_DEVICE_TEST_SUITE_P(
Expand Down
12 changes: 12 additions & 0 deletions test/conformance/testing/include/uur/optional_queries.h
Original file line number Diff line number Diff line change
Expand Up @@ -116,4 +116,16 @@ template <> inline bool isQueryOptional(ur_queue_info_t query) {
query) != optional_ur_queue_info_t.end();
}

constexpr std::array optional_ur_profiling_info_t = {
UR_PROFILING_INFO_COMMAND_QUEUED, UR_PROFILING_INFO_COMMAND_SUBMIT,
UR_PROFILING_INFO_COMMAND_START, UR_PROFILING_INFO_COMMAND_END,
UR_PROFILING_INFO_COMMAND_COMPLETE,
};

template <> inline bool isQueryOptional(ur_profiling_info_t query) {
return std::find(optional_ur_profiling_info_t.begin(),
optional_ur_profiling_info_t.end(),
query) != optional_ur_profiling_info_t.end();
}

} // namespace uur

0 comments on commit 56bc47d

Please sign in to comment.