Skip to content

Make profiling info optional and update tests #2533

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 13 additions & 11 deletions include/ur_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -7105,21 +7105,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 @@ -7193,6 +7193,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 @@ -4733,6 +4733,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 @@ -4138,6 +4138,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
71 changes: 32 additions & 39 deletions test/conformance/event/urEventGetProfilingInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ using urEventGetProfilingInfoTest = uur::event::urEventTest;
UUR_INSTANTIATE_DEVICE_TEST_SUITE(urEventGetProfilingInfoTest);

TEST_P(urEventGetProfilingInfoTest, SuccessCommandQueued) {
UUR_KNOWN_FAILURE_ON(uur::LevelZero{}, uur::LevelZeroV2{}, uur::NativeCPU{});

const ur_profiling_info_t property_name = UR_PROFILING_INFO_COMMAND_QUEUED;
size_t property_size = 0;

Expand All @@ -29,8 +27,6 @@ TEST_P(urEventGetProfilingInfoTest, SuccessCommandQueued) {
}

TEST_P(urEventGetProfilingInfoTest, SuccessCommandSubmit) {
UUR_KNOWN_FAILURE_ON(uur::LevelZero{}, uur::LevelZeroV2{}, uur::NativeCPU{});

const ur_profiling_info_t property_name = UR_PROFILING_INFO_COMMAND_SUBMIT;
size_t property_size = 0;

Expand Down Expand Up @@ -79,9 +75,6 @@ TEST_P(urEventGetProfilingInfoTest, SuccessCommandEnd) {
}

TEST_P(urEventGetProfilingInfoTest, SuccessCommandComplete) {
UUR_KNOWN_FAILURE_ON(uur::CUDA{}, uur::HIP{}, uur::LevelZero{},
uur::NativeCPU{});

const ur_profiling_info_t property_name = UR_PROFILING_INFO_COMMAND_COMPLETE;
size_t property_size = 0;

Expand All @@ -98,41 +91,41 @@ TEST_P(urEventGetProfilingInfoTest, SuccessCommandComplete) {
}

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

uint8_t size = 8;

uint64_t queued_value = 0;
ASSERT_SUCCESS(urEventGetProfilingInfo(
event, UR_PROFILING_INFO_COMMAND_QUEUED, size, &queued_value, nullptr));
ASSERT_NE(queued_value, 0);

uint64_t submit_value = 0;
ASSERT_SUCCESS(urEventGetProfilingInfo(
event, UR_PROFILING_INFO_COMMAND_SUBMIT, size, &submit_value, nullptr));
ASSERT_NE(submit_value, 0);

uint64_t start_value = 0;
ASSERT_SUCCESS(urEventGetProfilingInfo(event, UR_PROFILING_INFO_COMMAND_START,
size, &start_value, nullptr));
ASSERT_NE(start_value, 0);
// 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 end_value = 0;
ASSERT_SUCCESS(urEventGetProfilingInfo(event, UR_PROFILING_INFO_COMMAND_END,
size, &end_value, nullptr));
ASSERT_NE(end_value, 0);
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);

uint64_t complete_value = 0;
ASSERT_SUCCESS(urEventGetProfilingInfo(event,
UR_PROFILING_INFO_COMMAND_COMPLETE,
size, &complete_value, nullptr));
ASSERT_NE(complete_value, 0);
// Note: This assumes that the counter doesn't overflow
ASSERT_LE(a_time, b_time);
};

ASSERT_LE(queued_value, submit_value);
ASSERT_LT(submit_value, start_value);
ASSERT_LT(start_value, end_value);
ASSERT_LE(end_value, complete_value);
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);
}

TEST_P(urEventGetProfilingInfoTest, InvalidNullHandle) {
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 @@ -117,4 +117,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