Skip to content

Commit

Permalink
Merge pull request oneapi-src#1666 from igchor/fix_l0_test
Browse files Browse the repository at this point in the history
Fix level zero specific test
  • Loading branch information
omarahmed1111 authored May 29, 2024
2 parents 3fca424 + 54a2173 commit e18c691
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 10 deletions.
8 changes: 4 additions & 4 deletions test/adapters/level_zero/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ if(NOT UR_DPCXX)
# Tests that require kernels can't be used if we aren't generating
# device binaries
message(WARNING
"UR_DPCXX is not defined, skipping adapter tests for level_zero")
"UR_DPCXX is not defined, skipping some adapter tests for level_zero")
else()
add_adapter_test(level_zero
FIXTURE KERNELS
Expand Down Expand Up @@ -39,14 +39,14 @@ else()
generate_device_binaries kernel_names_header)
endif()

if(LINUX)
if(NOT WIN32)
# Make L0 use CallMap from a seprate shared lib so that we can access the map
# from the tests. This only seems to work on linux
add_library(zeCallMap SHARED zeCallMap.cpp)
target_compile_definitions(ur_adapter_level_zero PRIVATE UR_L0_CALL_COUNT_IN_TESTS)
target_link_libraries(ur_adapter_level_zero PRIVATE zeCallMap)

add_adapter_test(level_zero
add_adapter_test(level_zero_ze_calls
FIXTURE DEVICES
SOURCES
event_cache_tests.cpp
Expand All @@ -55,5 +55,5 @@ if(LINUX)
"UR_L0_LEAKS_DEBUG=1"
)

target_link_libraries(test-adapter-level_zero PRIVATE zeCallMap)
target_link_libraries(test-adapter-level_zero_ze_calls PRIVATE zeCallMap)
endif()
22 changes: 16 additions & 6 deletions test/adapters/level_zero/event_cache_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,16 @@ extern std::map<std::string, int> *ZeCallCount;
using FlagsTupleType = std::tuple<ur_queue_flags_t, ur_queue_flags_t,
ur_queue_flags_t, ur_queue_flags_t>;

// TODO: get rid of this, this is a workaround for fails on older driver
// where for some reason continuing the test leads to a segfault
#define UUR_ASSERT_SUCCESS_OR_EXIT_IF_UNSUPPORTED(ret) \
auto status = ret; \
if (status == UR_RESULT_ERROR_UNSUPPORTED_FEATURE) { \
exit(0); \
} else { \
ASSERT_EQ(status, UR_RESULT_SUCCESS); \
}

struct urEventCacheTest : uur::urContextTestWithParam<FlagsTupleType> {
void SetUp() override {
UUR_RETURN_ON_FATAL_FAILURE(urContextTestWithParam::SetUp());
Expand All @@ -42,20 +52,20 @@ struct urEventCacheTest : uur::urContextTestWithParam<FlagsTupleType> {
EXPECT_SUCCESS(urMemRelease(buffer));
}
if (queue) {
UUR_ASSERT_SUCCESS_OR_UNSUPPORTED(urQueueRelease(queue));
UUR_ASSERT_SUCCESS_OR_EXIT_IF_UNSUPPORTED(urQueueRelease(queue));
}
UUR_RETURN_ON_FATAL_FAILURE(urContextTestWithParam::TearDown());
}

auto enqueueWork(ur_event_handle_t *hEvent, int data) {
input.assign(count, data);
UUR_ASSERT_SUCCESS_OR_UNSUPPORTED(urEnqueueMemBufferWrite(
UUR_ASSERT_SUCCESS_OR_EXIT_IF_UNSUPPORTED(urEnqueueMemBufferWrite(
queue, buffer, false, 0, size, input.data(), 0, nullptr, hEvent));
}

void verifyData() {
std::vector<uint32_t> output(count, 1);
UUR_ASSERT_SUCCESS_OR_UNSUPPORTED(urEnqueueMemBufferRead(
UUR_ASSERT_SUCCESS_OR_EXIT_IF_UNSUPPORTED(urEnqueueMemBufferRead(
queue, buffer, true, 0, size, output.data(), 0, nullptr, nullptr));

if (!(flags & UR_QUEUE_FLAG_OUT_OF_ORDER_EXEC_MODE_ENABLE)) {
Expand All @@ -79,7 +89,7 @@ TEST_P(urEventCacheTest, eventsReuseNoVisibleEvent) {
for (int j = 0; j < numEnqueues; j++) {
enqueueWork(nullptr, i * numEnqueues + j);
}
UUR_ASSERT_SUCCESS_OR_UNSUPPORTED(urQueueFinish(queue));
UUR_ASSERT_SUCCESS_OR_EXIT_IF_UNSUPPORTED(urQueueFinish(queue));
verifyData();
}

Expand All @@ -101,7 +111,7 @@ TEST_P(urEventCacheTest, eventsReuseWithVisibleEvent) {
for (int j = 0; j < numEnqueues; j++) {
enqueueWork(events[j].ptr(), i * numEnqueues + j);
}
UUR_ASSERT_SUCCESS_OR_UNSUPPORTED(urQueueFinish(queue));
UUR_ASSERT_SUCCESS_OR_EXIT_IF_UNSUPPORTED(urQueueFinish(queue));
verifyData();
}

Expand All @@ -126,7 +136,7 @@ TEST_P(urEventCacheTest, eventsReuseWithVisibleEventAndWait) {
events.clear();
}
}
UUR_ASSERT_SUCCESS_OR_UNSUPPORTED(urQueueFinish(queue));
UUR_ASSERT_SUCCESS_OR_EXIT_IF_UNSUPPORTED(urQueueFinish(queue));
}

ASSERT_GE((*ZeCallCount)["zeEventCreate"], waitEveryN);
Expand Down

0 comments on commit e18c691

Please sign in to comment.