Skip to content

Commit

Permalink
Merge pull request #2390 from pbalcer/low-power-events-tests
Browse files Browse the repository at this point in the history
add tests for low-power events extension
  • Loading branch information
kbenzie authored Nov 29, 2024
2 parents eb076da + d08ee7e commit 7a4902d
Show file tree
Hide file tree
Showing 7 changed files with 83 additions and 21 deletions.
1 change: 1 addition & 0 deletions source/adapters/cuda/ur_interface_loader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ UR_DLLEXPORT ur_result_t UR_APICALL urGetEnqueueProcAddrTable(
pDdiTable->pfnDeviceGlobalVariableWrite = urEnqueueDeviceGlobalVariableWrite;
pDdiTable->pfnEventsWait = urEnqueueEventsWait;
pDdiTable->pfnEventsWaitWithBarrier = urEnqueueEventsWaitWithBarrier;
pDdiTable->pfnEventsWaitWithBarrierExt = urEnqueueEventsWaitWithBarrierExt;
pDdiTable->pfnKernelLaunch = urEnqueueKernelLaunch;
pDdiTable->pfnMemBufferCopy = urEnqueueMemBufferCopy;
pDdiTable->pfnMemBufferCopyRect = urEnqueueMemBufferCopyRect;
Expand Down
1 change: 1 addition & 0 deletions source/adapters/hip/ur_interface_loader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ UR_DLLEXPORT ur_result_t UR_APICALL urGetEnqueueProcAddrTable(
pDdiTable->pfnDeviceGlobalVariableWrite = urEnqueueDeviceGlobalVariableWrite;
pDdiTable->pfnEventsWait = urEnqueueEventsWait;
pDdiTable->pfnEventsWaitWithBarrier = urEnqueueEventsWaitWithBarrier;
pDdiTable->pfnEventsWaitWithBarrierExt = urEnqueueEventsWaitWithBarrierExt;
pDdiTable->pfnKernelLaunch = urEnqueueKernelLaunch;
pDdiTable->pfnMemBufferCopy = urEnqueueMemBufferCopy;
pDdiTable->pfnMemBufferCopyRect = urEnqueueMemBufferCopyRect;
Expand Down
1 change: 1 addition & 0 deletions source/adapters/native_cpu/ur_interface_loader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ UR_DLLEXPORT ur_result_t UR_APICALL urGetEnqueueProcAddrTable(
pDdiTable->pfnDeviceGlobalVariableWrite = urEnqueueDeviceGlobalVariableWrite;
pDdiTable->pfnEventsWait = urEnqueueEventsWait;
pDdiTable->pfnEventsWaitWithBarrier = urEnqueueEventsWaitWithBarrier;
pDdiTable->pfnEventsWaitWithBarrierExt = urEnqueueEventsWaitWithBarrierExt;
pDdiTable->pfnKernelLaunch = urEnqueueKernelLaunch;
pDdiTable->pfnMemBufferCopy = urEnqueueMemBufferCopy;
pDdiTable->pfnMemBufferCopyRect = urEnqueueMemBufferCopyRect;
Expand Down
1 change: 1 addition & 0 deletions source/adapters/opencl/ur_interface_loader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ UR_DLLEXPORT ur_result_t UR_APICALL urGetEnqueueProcAddrTable(
pDdiTable->pfnDeviceGlobalVariableWrite = urEnqueueDeviceGlobalVariableWrite;
pDdiTable->pfnEventsWait = urEnqueueEventsWait;
pDdiTable->pfnEventsWaitWithBarrier = urEnqueueEventsWaitWithBarrier;
pDdiTable->pfnEventsWaitWithBarrierExt = urEnqueueEventsWaitWithBarrierExt;
pDdiTable->pfnKernelLaunch = urEnqueueKernelLaunch;
pDdiTable->pfnMemBufferCopy = urEnqueueMemBufferCopy;
pDdiTable->pfnMemBufferCopyRect = urEnqueueMemBufferCopyRect;
Expand Down
74 changes: 54 additions & 20 deletions test/conformance/enqueue/urEnqueueEventsWaitWithBarrier.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,30 @@
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
#include <uur/fixtures.h>

struct urEnqueueEventsWaitWithBarrierTest : uur::urMultiQueueTest {
enum class BarrierType {
Normal,
ExtLowPower,
};

std::ostream &operator<<(std::ostream &os, BarrierType barrierType) {
switch (barrierType) {
case BarrierType::Normal:
os << "Normal";
break;
case BarrierType::ExtLowPower:
os << "ExtLowPower";
break;
default:
os << "Unknown";
break;
}
return os;
}

struct urEnqueueEventsWaitWithBarrierTest
: uur::urMultiQueueTestWithParam<BarrierType> {
void SetUp() override {
UUR_RETURN_ON_FATAL_FAILURE(urMultiQueueTest::SetUp());
UUR_RETURN_ON_FATAL_FAILURE(urMultiQueueTestWithParam::SetUp());
ASSERT_SUCCESS(urMemBufferCreate(context, UR_MEM_FLAG_WRITE_ONLY, size,
nullptr, &src_buffer));
ASSERT_SUCCESS(urMemBufferCreate(context, UR_MEM_FLAG_READ_ONLY, size,
Expand All @@ -24,7 +45,23 @@ struct urEnqueueEventsWaitWithBarrierTest : uur::urMultiQueueTest {
if (dst_buffer) {
EXPECT_SUCCESS(urMemRelease(dst_buffer));
}
urMultiQueueTest::TearDown();
urMultiQueueTestWithParam::TearDown();
}

ur_result_t EnqueueBarrier(ur_queue_handle_t queue, uint32_t num_events,
const ur_event_handle_t *event_list,
ur_event_handle_t *wait_event) {
BarrierType barrier = getParam();
if (barrier == BarrierType::ExtLowPower) {
struct ur_exp_enqueue_ext_properties_t props = {
UR_STRUCTURE_TYPE_EXP_ENQUEUE_EXT_PROPERTIES, nullptr,
UR_EXP_ENQUEUE_EXT_FLAG_LOW_POWER_EVENTS};
return urEnqueueEventsWaitWithBarrierExt(queue, &props, num_events,
event_list, wait_event);
}

return urEnqueueEventsWaitWithBarrier(queue, num_events, event_list,
wait_event);
}

const size_t count = 1024;
Expand All @@ -34,7 +71,10 @@ struct urEnqueueEventsWaitWithBarrierTest : uur::urMultiQueueTest {
std::vector<uint32_t> input;
};

UUR_INSTANTIATE_DEVICE_TEST_SUITE_P(urEnqueueEventsWaitWithBarrierTest);
UUR_TEST_SUITE_P(urEnqueueEventsWaitWithBarrierTest,
::testing::Values(BarrierType::Normal,
BarrierType::ExtLowPower),
uur::deviceTestWithParamPrinter<BarrierType>);

struct urEnqueueEventsWaitWithBarrierOrderingTest : uur::urProgramTest {
void SetUp() override {
Expand Down Expand Up @@ -67,8 +107,7 @@ TEST_P(urEnqueueEventsWaitWithBarrierTest, Success) {
ur_event_handle_t waitEvent = nullptr;
ASSERT_SUCCESS(urEnqueueMemBufferCopy(queue1, src_buffer, dst_buffer, 0, 0,
size, 0, nullptr, &event1));
EXPECT_SUCCESS(
urEnqueueEventsWaitWithBarrier(queue2, 1, &event1, &waitEvent));
EXPECT_SUCCESS(EnqueueBarrier(queue2, 1, &event1, &waitEvent));
EXPECT_SUCCESS(urQueueFlush(queue2));
EXPECT_SUCCESS(urQueueFlush(queue1));
EXPECT_SUCCESS(urEventWait(1, &waitEvent));
Expand All @@ -86,8 +125,7 @@ TEST_P(urEnqueueEventsWaitWithBarrierTest, Success) {
input.data(), 0, nullptr, nullptr));
EXPECT_SUCCESS(urEnqueueMemBufferCopy(queue2, src_buffer, dst_buffer, 0, 0,
size, 0, nullptr, &event2));
EXPECT_SUCCESS(
urEnqueueEventsWaitWithBarrier(queue1, 1, &event2, &waitEvent));
EXPECT_SUCCESS(EnqueueBarrier(queue1, 1, &event2, &waitEvent));
EXPECT_SUCCESS(urQueueFlush(queue2));
EXPECT_SUCCESS(urQueueFlush(queue1));
EXPECT_SUCCESS(urEventWait(1, &waitEvent));
Expand All @@ -99,27 +137,23 @@ TEST_P(urEnqueueEventsWaitWithBarrierTest, Success) {
}

TEST_P(urEnqueueEventsWaitWithBarrierTest, InvalidNullHandleQueue) {
ASSERT_EQ_RESULT(
UR_RESULT_ERROR_INVALID_NULL_HANDLE,
urEnqueueEventsWaitWithBarrier(nullptr, 0, nullptr, nullptr));
ASSERT_EQ_RESULT(UR_RESULT_ERROR_INVALID_NULL_HANDLE,
EnqueueBarrier(nullptr, 0, nullptr, nullptr));
}

TEST_P(urEnqueueEventsWaitWithBarrierTest, InvalidNullPtrEventWaitList) {
ASSERT_EQ_RESULT(
urEnqueueEventsWaitWithBarrier(queue1, 1, nullptr, nullptr),
UR_RESULT_ERROR_INVALID_EVENT_WAIT_LIST);
ASSERT_EQ_RESULT(EnqueueBarrier(queue1, 1, nullptr, nullptr),
UR_RESULT_ERROR_INVALID_EVENT_WAIT_LIST);

ur_event_handle_t validEvent;
ASSERT_SUCCESS(urEnqueueEventsWait(queue1, 0, nullptr, &validEvent));

ASSERT_EQ_RESULT(
urEnqueueEventsWaitWithBarrier(queue1, 0, &validEvent, nullptr),
UR_RESULT_ERROR_INVALID_EVENT_WAIT_LIST);
ASSERT_EQ_RESULT(EnqueueBarrier(queue1, 0, &validEvent, nullptr),
UR_RESULT_ERROR_INVALID_EVENT_WAIT_LIST);

ur_event_handle_t inv_evt = nullptr;
ASSERT_EQ_RESULT(
urEnqueueEventsWaitWithBarrier(queue1, 1, &inv_evt, nullptr),
UR_RESULT_ERROR_INVALID_EVENT_WAIT_LIST);
ASSERT_EQ_RESULT(EnqueueBarrier(queue1, 1, &inv_evt, nullptr),
UR_RESULT_ERROR_INVALID_EVENT_WAIT_LIST);

ASSERT_SUCCESS(urEventRelease(validEvent));
}
Expand Down
4 changes: 3 additions & 1 deletion test/conformance/queue/urQueueCreate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Part of the Unified-Runtime Project, under the Apache License v2.0 with LLVM Exceptions.
// See LICENSE.TXT
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
#include "ur_api.h"
#include "uur/raii.h"
#include <uur/fixtures.h>

Expand Down Expand Up @@ -34,7 +35,8 @@ UUR_TEST_SUITE_P(urQueueCreateWithParamTest,
UR_QUEUE_FLAG_SUBMISSION_BATCHED,
UR_QUEUE_FLAG_SUBMISSION_IMMEDIATE,
UR_QUEUE_FLAG_USE_DEFAULT_STREAM,
UR_QUEUE_FLAG_SYNC_WITH_DEFAULT_STREAM),
UR_QUEUE_FLAG_SYNC_WITH_DEFAULT_STREAM,
UR_QUEUE_FLAG_LOW_POWER_EVENTS_EXP),
uur::deviceTestWithParamPrinter<ur_queue_flag_t>);

TEST_P(urQueueCreateWithParamTest, SuccessWithProperties) {
Expand Down
22 changes: 22 additions & 0 deletions test/conformance/testing/include/uur/fixtures.h
Original file line number Diff line number Diff line change
Expand Up @@ -519,6 +519,28 @@ struct urMultiQueueTest : urContextTest {
ur_queue_handle_t queue2 = nullptr;
};

template <class T>
struct urMultiQueueTestWithParam : urContextTestWithParam<T> {
void SetUp() override {
UUR_RETURN_ON_FATAL_FAILURE(urContextTestWithParam<T>::SetUp());
ASSERT_SUCCESS(urQueueCreate(this->context, this->device, 0, &queue1));
ASSERT_SUCCESS(urQueueCreate(this->context, this->device, 0, &queue2));
}

void TearDown() override {
if (queue1 != nullptr) {
EXPECT_SUCCESS(urQueueRelease(queue1));
}
if (queue2 != nullptr) {
EXPECT_SUCCESS(urQueueRelease(queue2));
}
UUR_RETURN_ON_FATAL_FAILURE(urContextTestWithParam<T>::TearDown());
}

ur_queue_handle_t queue1 = nullptr;
ur_queue_handle_t queue2 = nullptr;
};

template <size_t MinDevices = 2>
struct urMultiDeviceContextTestTemplate : urPlatformTest {
void SetUp() override {
Expand Down

0 comments on commit 7a4902d

Please sign in to comment.