Skip to content
Merged
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
51 changes: 51 additions & 0 deletions sycl/unittests/helpers/CommandSubmitWrappers.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
//==-- CommandSubmitWrappers.hpp ----- Wrappers for command submission -----==//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

#pragma once

#include <sycl/event.hpp>
#include <sycl/handler.hpp>

namespace sycl {

inline namespace _V1 {
namespace unittest {

// Wrappers introduced in this file allow for running unit tests
// with two command submission types: Using a handler and handler-less
// shortcut functions.
// This increases the test coverage, especially for the cases,
// where the command submission path implementation differes significantly
// between those two models.

template <typename KernelName, typename KernelType>
event single_task_wrapper(bool UseShortcutFunction, queue &Q,
const KernelType &KernelFunc) {
if (UseShortcutFunction) {
return Q.single_task<KernelName>(KernelFunc);
} else {
return Q.submit(
[&](handler &cgh) { cgh.single_task<KernelName>(KernelFunc); });
}
}

template <typename KernelName, typename KernelType>
event single_task_wrapper(bool UseShortcutFunction, queue &Q, event &DepEvent,
const KernelType &KernelFunc) {
if (UseShortcutFunction) {
return Q.single_task<KernelName>(DepEvent, KernelFunc);
} else {
return Q.submit([&](handler &cgh) {
cgh.depends_on(DepEvent);
cgh.single_task<KernelName>(KernelFunc);
});
}
}
} // namespace unittest
} // namespace _V1
} // namespace sycl
51 changes: 28 additions & 23 deletions sycl/unittests/scheduler/InOrderQueueDeps.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "SchedulerTest.hpp"
#include "SchedulerTestUtils.hpp"

#include <helpers/CommandSubmitWrappers.hpp>
#include <helpers/TestKernel.hpp>
#include <helpers/UrMock.hpp>
#include <sycl/usm.hpp>
Expand Down Expand Up @@ -44,7 +45,7 @@ ur_result_t redefinedEnqueueMemUnmap(void *pParams) {
return UR_RESULT_SUCCESS;
}

TEST_F(SchedulerTest, InOrderQueueDeps) {
TEST_P(SchedulerTest, InOrderQueueDeps) {
sycl::unittest::UrMock<> Mock;
sycl::platform Plt = sycl::platform();
mock::getCallbacks().set_before_callback("urEnqueueMemBufferReadRect",
Expand Down Expand Up @@ -95,15 +96,12 @@ ur_result_t redefinedEnqueueEventsWaitWithBarrierExt(void *pParams) {
return UR_RESULT_SUCCESS;
}

sycl::event submitKernel(sycl::queue &Q) {
return Q.submit([&](handler &cgh) { cgh.single_task<TestKernel>([]() {}); });
}

TEST_F(SchedulerTest, InOrderQueueIsolatedDeps) {
TEST_P(SchedulerTest, InOrderQueueIsolatedDeps) {
// Check that isolated kernels (i.e. those that don't modify the graph)
// are handled properly during filtering.
sycl::unittest::UrMock<> Mock;
sycl::platform Plt = sycl::platform();
bool UseShortcutFunction = GetParam();
mock::getCallbacks().set_before_callback(
"urEnqueueEventsWaitWithBarrierExt",
&redefinedEnqueueEventsWaitWithBarrierExt);
Expand All @@ -112,14 +110,17 @@ TEST_F(SchedulerTest, InOrderQueueIsolatedDeps) {
context Ctx{Plt.get_devices()[0]};
queue Q1{Ctx, default_selector_v, property::queue::in_order()};
{
event E = submitKernel(Q1);
event E = sycl::unittest::single_task_wrapper<TestKernel>(
UseShortcutFunction, Q1, []() {});
Q1.ext_oneapi_submit_barrier({E});
EXPECT_FALSE(BarrierCalled);
}
queue Q2{Ctx, default_selector_v, property::queue::in_order()};
{
event E1 = submitKernel(Q1);
event E2 = submitKernel(Q2);
event E1 = sycl::unittest::single_task_wrapper<TestKernel>(
UseShortcutFunction, Q1, []() {});
event E2 = sycl::unittest::single_task_wrapper<TestKernel>(
UseShortcutFunction, Q2, []() {});
ExpectedEvent = detail::getSyclObjImpl(E2)->getHandle();
Q1.ext_oneapi_submit_barrier({E1, E2});
EXPECT_TRUE(BarrierCalled);
Expand All @@ -134,9 +135,10 @@ inline ur_result_t customEnqueueKernelLaunch(void *pParams) {
return UR_RESULT_SUCCESS;
}

TEST_F(SchedulerTest, TwoInOrderQueuesOnSameContext) {
TEST_P(SchedulerTest, TwoInOrderQueuesOnSameContext) {
KernelEventListSize.clear();
sycl::unittest::UrMock<> Mock;
bool UseShortcutFunction = GetParam();
mock::getCallbacks().set_before_callback("urEnqueueKernelLaunch",
&customEnqueueKernelLaunch);

Expand All @@ -147,12 +149,10 @@ TEST_F(SchedulerTest, TwoInOrderQueuesOnSameContext) {
queue InOrderQueueSecond{Ctx, default_selector_v,
property::queue::in_order()};

event EvFirst = InOrderQueueFirst.submit(
[&](sycl::handler &CGH) { CGH.single_task<TestKernel>([] {}); });
std::ignore = InOrderQueueSecond.submit([&](sycl::handler &CGH) {
CGH.depends_on(EvFirst);
CGH.single_task<TestKernel>([] {});
});
event EvFirst = sycl::unittest::single_task_wrapper<TestKernel>(
UseShortcutFunction, InOrderQueueFirst, []() {});
std::ignore = sycl::unittest::single_task_wrapper<TestKernel>(
UseShortcutFunction, InOrderQueueSecond, EvFirst, []() {});

InOrderQueueFirst.wait();
InOrderQueueSecond.wait();
Expand All @@ -162,9 +162,10 @@ TEST_F(SchedulerTest, TwoInOrderQueuesOnSameContext) {
EXPECT_EQ(KernelEventListSize[1] /*EventsCount*/, 1u);
}

TEST_F(SchedulerTest, InOrderQueueNoSchedulerPath) {
TEST_P(SchedulerTest, InOrderQueueNoSchedulerPath) {
KernelEventListSize.clear();
sycl::unittest::UrMock<> Mock;
bool UseShortcutFunction = GetParam();
mock::getCallbacks().set_before_callback("urEnqueueKernelLaunch",
&customEnqueueKernelLaunch);

Expand All @@ -173,12 +174,10 @@ TEST_F(SchedulerTest, InOrderQueueNoSchedulerPath) {
context Ctx{Plt};
queue InOrderQueue{Ctx, default_selector_v, property::queue::in_order()};

event EvFirst = InOrderQueue.submit(
[&](sycl::handler &CGH) { CGH.single_task<TestKernel>([] {}); });
std::ignore = InOrderQueue.submit([&](sycl::handler &CGH) {
CGH.depends_on(EvFirst);
CGH.single_task<TestKernel>([] {});
});
event EvFirst = sycl::unittest::single_task_wrapper<TestKernel>(
UseShortcutFunction, InOrderQueue, []() {});
std::ignore = sycl::unittest::single_task_wrapper<TestKernel>(
UseShortcutFunction, InOrderQueue, EvFirst, []() {});

InOrderQueue.wait();

Expand All @@ -190,3 +189,9 @@ TEST_F(SchedulerTest, InOrderQueueNoSchedulerPath) {
}

} // anonymous namespace

INSTANTIATE_TEST_SUITE_P(
SchedulerTestInstance, SchedulerTest,
testing::Values(
true,
false)); /* Whether to use the shortcut command submission function */
2 changes: 1 addition & 1 deletion sycl/unittests/scheduler/SchedulerTest.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

#include <gtest/gtest.h>

class SchedulerTest : public ::testing::Test {
class SchedulerTest : public testing::TestWithParam<bool> {
protected:
sycl::async_handler MAsyncHandler = [](sycl::exception_list ExceptionList) {
for (std::exception_ptr ExceptionPtr : ExceptionList) {
Expand Down